/* Match-only composition and surface. Keep all selectors beneath .match-screen. */
body.is-match .app-shell { max-width: none; padding: 0; }
body.is-match .topbar,
body.is-match .footnote { display: none; }
body.is-match .main-area { min-height: 100svh; }
body.is-match .notice { position: relative; top: 0; margin: 0; max-width: none; border-radius: 0; }

.match-screen {
  --match-ink: #f6edff;
  --match-muted: #c7b8db;
  --match-gold: #f5d889;
  --match-purple: #9d6de0;
  --match-deep-purple: #321c59;
  --match-line: rgb(192 151 255 / 28%);
  --match-card-width: clamp(5.625rem, 6.25vw, 6.5rem);
  position: relative;
  isolation: isolate;
  box-sizing: border-box;
  min-height: 100svh;
  padding: clamp(.65rem, 1.7vh, 1.2rem) clamp(.75rem, 2vw, 1.75rem) .75rem;
  overflow: auto;
  color: var(--match-ink);
  color-scheme: dark;
  background:
    radial-gradient(ellipse at 50% 47%, rgb(37 85 150 / 55%), transparent 53%),
    radial-gradient(ellipse at 50% 49%, transparent 34%, rgb(6 9 29 / 35%) 82%),
    linear-gradient(145deg, #0c102c, #111735 53%, #170e2a);
  font-family: Georgia, "Palatino Linotype", serif;
}

.match-screen *,
.match-screen *::before,
.match-screen *::after { box-sizing: border-box; }

.match-screen::before {
  position: absolute;
  z-index: -1;
  inset: 0;
  pointer-events: none;
  content: "";
  opacity: .28;
  background:
    radial-gradient(circle at 50% 50%, transparent 0 19%, rgb(141 116 235 / 9%) 19.2% 19.4%, transparent 19.7%),
    repeating-radial-gradient(circle at 50% 50%, transparent 0 5.2rem, rgb(151 130 241 / 7%) 5.25rem 5.32rem, transparent 5.4rem 9rem);
  mask-image: linear-gradient(transparent, #000 16%, #000 86%, transparent);
}

.match-screen :is(h1, h2, h3, p) { margin: 0; }
.match-screen :is(button, [role="button"], a):focus-visible {
  outline: 3px solid #fff1a9;
  outline-offset: 3px;
}

.match-screen .match-status,
.match-screen .match-utilities,
.match-screen .action-dock,
.match-screen .effect-panel,
.match-screen .match-history {
  border: 1px solid var(--match-line);
  border-radius: .85rem;
  background: linear-gradient(135deg, rgb(24 24 61 / 92%), rgb(46 26 76 / 88%));
  box-shadow: 0 .55rem 1.5rem rgb(4 5 19 / 25%), inset 0 1px rgb(255 255 255 / 5%);
}

.match-screen .match-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 3.1rem;
  padding: .45rem .75rem .45rem 1rem;
  border-color: rgb(195 159 255 / 35%);
}

.match-screen .match-status__facts,
.match-screen .match-utilities {
  display: flex;
  align-items: center;
  gap: .65rem;
}

.match-screen .match-status__facts { flex-wrap: wrap; }
.match-screen .match-status__label { color: var(--match-muted); font: 600 .7rem/1.2 system-ui, sans-serif; letter-spacing: .09em; text-transform: uppercase; }
.match-screen .match-status__value { color: var(--match-gold); font-size: .98rem; }
.match-screen .match-status__divider { width: 1px; height: 1.55rem; background: var(--match-line); }

.match-screen .match-utilities { gap: .35rem; padding: .25rem; background: rgb(12 13 37 / 35%); }
.match-screen .match-utilities > * {
  padding: .45rem .65rem;
  border: 0;
  border-radius: .55rem;
  color: var(--match-ink);
  background: transparent;
  font: 600 .75rem/1 system-ui, sans-serif;
  white-space: nowrap;
}

.match-screen .match-utilities > *:hover { background: rgb(179 137 247 / 17%); }

.match-screen .match-table {
  display: grid;
  grid-template-rows: minmax(9.7rem, 1fr) auto minmax(9.7rem, 1fr);
  gap: .15rem;
  min-height: 22rem;
  padding-block: .55rem;
}

.match-screen .match-row {
  display: grid;
  grid-template-columns: minmax(7.5rem, 10rem) minmax(0, 1fr) minmax(7rem, 9.5rem);
  align-items: center;
  gap: clamp(.65rem, 1.7vw, 1.5rem);
  min-width: 0;
  padding-inline: clamp(.1rem, 1.25vw, 1rem);
}

.match-screen .match-identity {
  position: relative;
  display: grid;
  grid-template-columns: 3rem minmax(0, 1fr);
  align-items: center;
  gap: .55rem;
  min-width: 0;
  padding: .65rem .55rem;
  border: 1px solid rgb(196 166 255 / 36%);
  border-radius: .9rem;
  background: linear-gradient(145deg, rgb(43 31 77 / 89%), rgb(20 23 54 / 91%));
  box-shadow: inset 0 0 0 2px rgb(105 68 160 / 22%), 0 .6rem 1.5rem rgb(4 6 23 / 22%);
}

.match-screen .match-identity__avatar {
  display: grid;
  place-items: center;
  width: 2.8rem;
  aspect-ratio: 1;
  border: 2px solid #bd9bfb;
  border-radius: 50%;
  color: #fff3bc;
  background: radial-gradient(circle at 35% 30%, #8062b4, #31204f 70%);
  box-shadow: 0 0 .9rem rgb(172 127 255 / 26%);
  font: 700 1.05rem/1 system-ui, sans-serif;
}

.match-screen .match-identity__copy { min-width: 0; }
.match-screen .match-identity__state { display: block; margin-top: .2rem; color: var(--match-muted); font: .62rem/1.3 system-ui, sans-serif; }
.match-screen .match-identity__name { color: #fff4ca; font-size: .95rem; white-space: normal; overflow-wrap: anywhere; }
.match-screen .match-identity__score { display: block; margin-top: .25rem; color: var(--match-ink); font-size: 1.15rem; font-weight: 700; }
.match-screen .match-identity__stats { grid-column: 1 / -1; display: flex; justify-content: space-between; gap: .5rem; padding-top: .45rem; border-top: 1px solid var(--match-line); color: var(--match-muted); font: 600 .65rem/1.35 system-ui, sans-serif; }
.match-screen .match-identity__stats strong { display: block; margin-top: .1rem; color: var(--match-gold); font-size: .83rem; }

.match-screen .match-board {
  display: flex;
  align-items: center;
  justify-content: safe center;
  gap: clamp(.4rem, 1.25vw, 1.1rem);
  min-width: 0;
  min-height: 8.8rem;
  padding: .35rem;
  overflow: auto hidden;
  scrollbar-color: #71529b transparent;
  scrollbar-width: thin;
}

.match-screen .match-board > .match-card { flex: 0 0 var(--match-card-width); }

.match-screen .match-piles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .5rem;
  align-items: center;
  min-width: 0;
}

.match-screen .match-pile {
  display: grid;
  justify-items: center;
  gap: .32rem;
  min-width: 0;
  color: var(--match-muted);
  font: 600 .65rem/1.2 system-ui, sans-serif;
  text-align: center;
}

.match-screen .match-pile__stack {
  position: relative;
  display: grid;
  place-items: center;
  width: 3.2rem;
  height: 4.45rem;
  border: 1px solid #d0a6ff;
  border-radius: .6rem;
  color: #f9e6a2;
  background:
    radial-gradient(circle at 50% 45%, rgb(229 191 255 / 27%) 0 23%, transparent 24%),
    repeating-linear-gradient(135deg, transparent 0 5px, rgb(213 179 255 / 15%) 5px 6px),
    linear-gradient(150deg, #643c98, #291c58);
  box-shadow: .18rem .18rem 0 #171234, .35rem .35rem 0 #35205d, 0 .45rem .8rem rgb(2 3 14 / 35%);
  font-size: 1.1rem;
}

.match-screen .match-pile--empty .match-pile__stack { border-style: dashed; color: #9c8bad; background: rgb(13 15 39 / 55%); box-shadow: none; }
.match-screen .match-pile__count { color: var(--match-gold); font: 700 .78rem/1 system-ui, sans-serif; }

.match-screen .match-center {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
  min-height: 4rem;
  padding-inline: 1rem;
}

.match-screen .match-center::before,
.match-screen .match-center::after { height: 1px; content: ""; background: linear-gradient(90deg, transparent, #7442ab 25%, #a176df 50%, #7442ab 75%, transparent); }
.match-screen .match-center::before { grid-column: 1 / -1; grid-row: 1; }
.match-screen .match-center::after { display: none; }
.match-screen .play-progress { grid-column: 2; grid-row: 1; display: flex; align-items: center; gap: .7rem; }
.match-screen .play-progress__step { display: grid; place-items: center; width: 1.7rem; aspect-ratio: 1; transform: rotate(45deg); border: 1px solid #704c9a; border-radius: .25rem; color: #d9c4fb; background: #211746; font: 700 .72rem/1 system-ui, sans-serif; }
.match-screen .play-progress__step > span { transform: rotate(-45deg); }
.match-screen .play-progress__step[aria-current="step"] { border-color: #f0d88e; color: #fff1ad; background: #51387d; box-shadow: 0 0 .8rem rgb(191 150 255 / 35%); }
.match-screen .shared-location { grid-column: 3; grid-row: 1; display: flex; align-items: center; justify-self: end; gap: .5rem; min-width: 0; color: var(--match-muted); font: 600 .7rem/1.2 system-ui, sans-serif; }
.match-screen .shared-location:empty { display: none; }
.match-screen .shared-location .match-card { --match-card-width: 3.5rem; display: flex; align-items: center; flex: 0 0 auto; inline-size: auto; }
.match-screen .shared-location .match-card__stage { flex: 0 0 var(--match-card-width); inline-size: var(--match-card-width); }
.match-screen .shared-location .match-card__inspect { inline-size: auto; min-inline-size: 3.5rem; padding-inline: .4rem; }
.match-screen .shared-location .match-card__metadata:not(:has(.match-card__flipped)) { display: none; }
.match-screen .shared-location :is(.match-card__name, .match-card__type) { display: none; }

.match-screen .match-hand-zone {
  position: relative;
  min-width: 0;
  padding: .2rem 1rem 0;
  border-top: 1px solid rgb(152 106 211 / 28%);
  background: linear-gradient(180deg, rgb(30 26 68 / 20%), transparent 78%);
}

.match-screen .opponent-hand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .25rem;
  min-height: 2.15rem;
  color: var(--match-muted);
  font: 600 .72rem/1.2 system-ui, sans-serif;
}

.match-screen > .opponent-hand { min-height: 2.15rem; }

.match-screen .opponent-hand__backs { display: flex; align-items: center; padding-left: .5rem; }
.match-screen .opponent-hand__back {
  width: 1rem;
  height: 1.5rem;
  margin-left: -.45rem;
  border: 1px solid #9e75d0;
  border-radius: .22rem;
  background: repeating-linear-gradient(135deg, #533983 0 4px, #35235f 4px 8px);
  box-shadow: 0 1px 3px #090817;
}
.match-screen .opponent-hand__count { margin-left: .3rem; }

.match-screen .local-hand { min-width: 0; }
.match-screen .local-hand:has(.private-pending) { display: grid; grid-template-columns: minmax(0, 1fr) 7rem; gap: 0 .5rem; }
.match-screen .local-hand:has(.private-pending) > :is(.local-hand__header, .hand-fan) { grid-column: 1; }
.match-screen .private-pending { grid-column: 2; grid-row: 1 / span 2; display: grid; justify-items: center; align-self: center; gap: .35rem; }
.match-screen .private-pending__label { color: var(--match-muted); text-align: center; font: .65rem/1.3 system-ui, sans-serif; }
.match-screen .private-pending .match-card { --match-card-width: 3.5rem; }
.match-screen .local-hand__header { display: flex; justify-content: center; align-items: center; gap: .6rem; min-height: 1.1rem; color: var(--match-muted); font: .7rem/1.2 system-ui, sans-serif; }
.match-screen .local-hand__header h2 { font: inherit; color: var(--match-gold); }
.match-screen .local-hand__empty,
.match-screen .match-board__empty { color: var(--match-muted); font: .8rem/1.5 system-ui, sans-serif; }
.match-screen .action-dock__note { color: var(--match-muted); font: .65rem/1.4 system-ui, sans-serif; }
.match-screen .match-history__events { display: grid; gap: .4rem; padding-left: 1.2rem; }
.match-screen .hand-fan {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  min-width: 0;
  min-height: clamp(8.1rem, 19vh, 10.2rem);
  padding: 1.2rem 1rem .3rem;
  overflow: visible;
}

.match-screen .hand-fan > .match-card {
  position: relative;
  z-index: calc(var(--hand-index, 0) + 1);
  flex: 0 0 var(--match-card-width);
  margin-inline: calc(var(--match-card-width) * -.13);
  transform-origin: 50% 100%;
  transition: transform 160ms ease, filter 160ms ease;
}

.match-screen .hand-fan > .match-card:nth-child(1) { transform: rotate(-10deg) translateY(.15rem); }
.match-screen .hand-fan > .match-card:nth-child(2) { transform: rotate(-6deg) translateY(-.05rem); }
.match-screen .hand-fan > .match-card:nth-child(3) { transform: rotate(-2deg); }
.match-screen .hand-fan > .match-card:nth-child(4) { transform: rotate(2deg); }
.match-screen .hand-fan > .match-card:nth-child(5) { transform: rotate(6deg) translateY(-.05rem); }
.match-screen .hand-fan > .match-card:nth-child(6) { transform: rotate(10deg) translateY(.15rem); }
.match-screen .hand-fan > .match-card:nth-child(7) { transform: rotate(12deg) translateY(.25rem); }
.match-screen .hand-fan > .match-card:nth-child(8) { transform: rotate(14deg) translateY(.35rem); }
.match-screen .hand-fan > .match-card:hover,
.match-screen .hand-fan > .match-card:focus-within,
.match-screen .hand-fan > .match-card.is-selected { z-index: 20; transform: translateY(-.8rem) scale(1.04); }

@media (min-width: 1101px) and (min-height: 781px) {
  .match-screen .local-hand { --match-card-width: clamp(6.25rem, 7.3vw, 7rem); }
}

.match-screen .hand-strip,
.match-screen .hand-fan:has(> .match-card:nth-child(9)) {
  display: flex;
  justify-content: flex-start;
  gap: .75rem;
  padding: .5rem .65rem .75rem;
  overflow: auto hidden;
  scroll-padding-inline: .75rem;
}

.match-screen .hand-strip > .match-card,
.match-screen .hand-fan:has(> .match-card:nth-child(9)) > .match-card {
  flex: 0 0 var(--match-card-width);
  margin: 0;
  transform: none;
}

.match-screen .action-dock {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .75rem;
  min-height: 3.35rem;
  padding: .4rem .75rem;
}

.match-screen .action-dock__selection { min-width: 0; overflow: hidden; color: var(--match-muted); text-overflow: ellipsis; white-space: nowrap; }
.match-screen .match-control {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.3rem;
  padding: .5rem .9rem;
  border: 1px solid #a47ad6;
  border-radius: .6rem;
  color: var(--match-ink);
  background: #38255d;
  font: 700 .78rem/1 system-ui, sans-serif;
  text-decoration: none;
}

.match-screen .match-control--primary { border-color: #f3d889; color: #231638; background: linear-gradient(#ffe7a5, #d7ab57); box-shadow: 0 0 .9rem rgb(245 213 131 / 18%); }
.match-screen .match-control[aria-disabled="true"],
.match-screen .match-control:disabled { opacity: .48; }

.match-screen .match-history { margin-top: .5rem; padding: .55rem .8rem; color: var(--match-muted); font: .75rem/1.45 system-ui, sans-serif; }
.match-screen .match-history summary { color: #e8d4ff; cursor: pointer; }
.match-screen .effect-panel { margin: .55rem auto; max-width: 56rem; padding: .8rem 1rem; }
.match-screen .effect-panel h2 { margin-bottom: .35rem; color: var(--match-gold); font-size: 1rem; }
.match-screen .effect-panel p { color: var(--match-muted); font: .8rem/1.45 system-ui, sans-serif; }
.match-screen .effect-panel .choice-cards { justify-content: center; gap: 1rem; }
.match-screen .effect-panel .match-card { --match-card-width: 8rem; flex: 0 0 var(--match-card-width); }
.match-screen .effect-panel .match-card--inspection { --match-card-width: 9rem; }
.match-screen .effect-panel .choice-continue { display: block; margin-inline: auto; }

/* Native dialogs live beside the shell so polling cannot remove their focus. */
.match-outcome-dialog {
  position: fixed;
  inset: 0;
  width: min(650px, calc(100% - 28px));
  max-width: 650px;
  max-height: 90svh;
  margin: auto;
  padding: 1.75rem;
  overflow: auto;
  border: 1px solid #b68adf;
  border-radius: 1rem;
  color: #f6edff;
  background: linear-gradient(145deg, #30204c, #111a34);
  box-shadow: 0 2rem 7rem #0009;
}
.match-outcome-dialog::backdrop { background: #080a1cba; backdrop-filter: blur(5px); }
.match-outcome-dialog h2 { color: #ffe2a2; }
.match-outcome-scores { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; margin: 1.1rem 0; }
.match-outcome-score { min-width: 0; padding: .9rem; border: 1px solid #70568c; border-radius: .65rem; background: #131b32; font: .8rem/1.6 system-ui, sans-serif; overflow-wrap: anywhere; }
.match-outcome-score__name,
.match-outcome-score__totals { display: block; }
.match-outcome-score__totals { margin-top: .35rem; color: #d1bfdc; }
.card-details-meta { display: flex; flex-wrap: wrap; gap: .5rem; margin: .8rem 0; }
.card-details-value,
.card-details-status { padding: .35rem .55rem; border: 1px solid #70568c; border-radius: .45rem; color: #ffe2a2; font-size: .75rem; }
.card-details-dialog .ability-tag { font-size: .7rem; }

@media (max-height: 780px) and (min-width: 761px) {
  .match-screen { --match-card-width: clamp(4.4rem, 5.4vw, 5rem); padding-top: .35rem; padding-bottom: .35rem; }
  .match-screen .match-status { min-height: 2.65rem; padding-block: .3rem; }
  .match-screen .match-table { grid-template-rows: minmax(7.2rem, 1fr) auto minmax(7.2rem, 1fr); min-height: 17rem; padding-block: .1rem; }
  .match-screen .match-row { gap: .65rem; }
  .match-screen .match-identity { padding-block: .42rem; }
  .match-screen .match-identity__score { font-size: 1rem; }
  .match-screen .match-board { min-height: 6.5rem; }
  .match-screen .match-center { min-height: 2.7rem; }
  .match-screen .shared-location .match-card { --match-card-width: 2.4rem; }
  .match-screen .match-hand-zone { padding-top: 0; }
  .match-screen > .opponent-hand { min-height: 1.55rem; }
  .match-screen .hand-fan { min-height: 6.4rem; padding: .2rem .65rem .2rem; }
  .match-screen .action-dock { min-height: 2.8rem; }
  .match-screen .match-history { margin-top: .25rem; padding-block: .35rem; }
}

@media (max-width: 1100px) {
  .match-screen { --match-card-width: clamp(5rem, 8vw, 6.25rem); }
  .match-screen .match-row { grid-template-columns: minmax(6.8rem, 8rem) minmax(0, 1fr) minmax(6rem, 7.4rem); gap: .6rem; padding-inline: 0; }
  .match-screen .match-identity { grid-template-columns: 2.3rem minmax(0, 1fr); gap: .35rem; padding: .5rem .4rem; }
  .match-screen .match-identity__avatar { width: 2.2rem; }
  .match-screen .match-pile__stack { width: 2.65rem; height: 3.7rem; }
  .match-screen .hand-fan { justify-content: flex-start; gap: .65rem; padding: .5rem .65rem .75rem; overflow: auto hidden; }
  .match-screen .hand-fan > .match-card { flex: 0 0 var(--match-card-width); margin: 0; transform: none; }
}

@media (max-width: 760px) {
  .match-screen { min-height: 100svh; padding: .55rem; }
  .match-screen .match-status { align-items: flex-start; flex-direction: column; gap: .5rem; }
  .match-screen .match-utilities { max-width: 100%; overflow: auto hidden; }
  .match-screen .match-status__facts { gap: .45rem; }
  .match-screen .match-status__divider { height: 1.1rem; }
  .match-screen .match-table { grid-template-rows: auto auto auto; gap: .35rem; min-height: unset; padding-block: .65rem; }
  .match-screen .match-row { grid-template-columns: minmax(0, 1fr) auto; gap: .45rem; padding: 0; }
  .match-screen .match-identity { grid-column: 1 / -1; grid-template-columns: 2.2rem minmax(0, 1fr) auto; padding: .4rem .55rem; }
  .match-screen .match-identity__avatar { width: 2rem; }
  .match-screen .match-identity__score { margin: 0; }
  .match-screen .match-identity__stats { grid-column: 3; grid-row: 1; align-self: center; border: 0; padding: 0; gap: .8rem; }
  .match-screen .match-identity__stats > span { text-align: right; }
  .match-screen .match-board { grid-column: 1; justify-content: flex-start; min-height: 7.4rem; padding-inline: .35rem; }
  .match-screen .match-piles { grid-column: 2; grid-row: 2; grid-template-columns: 1fr; gap: .3rem; }
  .match-screen .match-pile { display: flex; flex-direction: row-reverse; justify-content: flex-end; font-size: .6rem; }
  .match-screen .match-pile__stack { width: 2rem; height: 2.75rem; }
  .match-screen .match-center { grid-template-columns: 1fr; gap: .6rem; min-height: 3.2rem; padding: .3rem; }
  .match-screen .match-center::before,
  .match-screen .match-center::after { display: none; }
  .match-screen .play-progress { grid-column: 1; grid-row: 1; justify-self: center; }
  .match-screen .shared-location { grid-column: 1; grid-row: 2; justify-self: center; }
  .match-screen .match-hand-zone { padding-inline: .2rem; }
  .match-screen .action-dock { flex-wrap: wrap; gap: .45rem; }
  .match-screen .action-dock__selection { flex-basis: 100%; text-align: center; }
}

@media (prefers-reduced-motion: reduce) {
  .match-screen *, .match-screen *::before, .match-screen *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
