/* Merge Spears — mobile-first, portrait & landscape & desktop.
   All state is class-based; the only inline styles are CSS custom properties
   for hand-fan geometry and the geometry the animation layer sets on its own
   fx sprites (plus the timer ring's dash offset). */

:root {
  --p0: #3b82f6;            /* seat 0 — blue */
  --p1: #ef4444;            /* seat 1 — red  */
  --bg: #0e1420;
  --panel: #17202f;
  --line: #2c3950;
  --gold: #d9a441;
  --text: #e8ecf4;
  --muted: #8fa0b8;
  --ok: #7fd18c;
  --warn: #f59e0b;
  --danger: #ef4444;
  --card-w: clamp(80px, 23vw, 112px);
  --hand-h: 158px;
  --slot-h: clamp(40px, 7vh, 82px);
}

/* your own colour depends on your seat */
body.seat-0 { --mine: var(--p0); --theirs: var(--p1); }
body.seat-1 { --mine: var(--p1); --theirs: var(--p0); }

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, 'Segoe UI', Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

body {
  background:
    radial-gradient(120% 90% at 50% 0%, #16203a 0%, var(--bg) 60%),
    var(--bg);
}

.hidden { display: none !important; }
.fx-hidden { visibility: hidden !important; } /* animation layer hides originals */

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

/* ------------------------------------------------------------- screens */

#app { height: 100dvh; }

.screen { display: none; height: 100dvh; }
.screen.active { display: flex; }

#screen-title, #screen-connect {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 16px;
  position: relative;
}

#title-audio {
  position: absolute;
  top: 14px;
  right: 14px;
  display: flex;
  gap: 10px;
}

#copyright {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 10px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  opacity: .8;
}

#logo svg { width: min(80vw, 400px); height: auto; display: block; }

#title-buttons { display: flex; flex-direction: column; gap: 14px; }

/* ------------------------------------------------------------- buttons */

/* Arcade-style buttons: black outer bezel, neon accent edge, hard two-tone
   glossy panel, punchy uppercase text. Variants swap four custom properties. */

.btn {
  --b-top: #46608c;               /* panel gradient, split hard at the middle */
  --b-bot: #24344f;
  --b-accent: #7d99c4;            /* neon edge */
  --b-glow: rgba(125, 153, 196, .35);
  background: linear-gradient(180deg, var(--b-top) 0%, var(--b-top) 46%, var(--b-bot) 54%, var(--b-bot) 100%);
  border: 2px solid var(--b-accent);
  outline: 3px solid #080c13;     /* the black bezel */
  border-radius: 10px;
  padding: 12px 20px;
  color: #f2f6fc;
  font-weight: 900;
  font-size: 15px;
  letter-spacing: .07em;
  text-transform: uppercase;
  text-shadow: 0 2px 2px rgba(0, 0, 0, .65);
  box-shadow: 0 0 12px var(--b-glow), inset 0 1px 0 rgba(255, 255, 255, .25);
  transition: filter .1s, transform .08s, box-shadow .1s;
}
.btn:hover { filter: brightness(1.09); }
.btn:active { transform: translateY(1px); filter: brightness(1.14); }
.btn.primary { --b-top: #3f74d8; --b-bot: #1c3f8f; --b-accent: #4aa8ff; --b-glow: rgba(74, 168, 255, .5); }
.btn.danger { --b-top: #d84a3a; --b-bot: #8c1d12; --b-accent: #ff6a5a; --b-glow: rgba(255, 106, 90, .45); }
.btn.big { width: min(84vw, 340px); padding: 16px 24px; font-size: 17px; border-radius: 12px; }
.btn.small { padding: 8px 15px; font-size: 13px; border-radius: 9px; outline-width: 2px; }
.btn.ghost {
  --b-top: #232f44;
  --b-bot: #161f30;
  --b-accent: #3a4a63;
  --b-glow: transparent;
  color: var(--muted);
}
/* the End turn treasure button (blocked/ready variants below override) */
.btn.gold {
  --b-top: #edbd50;
  --b-bot: #a2701d;
  --b-accent: #ffd166;
  --b-glow: rgba(255, 209, 102, .5);
  color: #241a05;
  text-shadow: 0 1px 0 rgba(255, 255, 255, .35);
}
/* nothing left to play: End turn invites the pass */
.btn.ready {
  --b-top: #2fae62;
  --b-bot: #146c39;
  --b-accent: #4ae08a;
  --b-glow: rgba(74, 224, 138, .55);
  color: #eafff2;
  text-shadow: 0 2px 2px rgba(0, 0, 0, .5);
  animation: readyPulse 1.5s ease-in-out infinite;
}
@keyframes readyPulse {
  50% {
    box-shadow: 0 0 22px rgba(74, 224, 138, .85), inset 0 1px 0 rgba(255, 255, 255, .25);
    filter: brightness(1.18);
  }
}
.btn.disabled { opacity: .45; }
.btn.blocked { --b-top: #a6472f; --b-bot: #6e2214; --b-accent: #ff8a75; --b-glow: rgba(255, 138, 117, .4); color: #ffe2dc; }
.btn.off { opacity: .35; pointer-events: none; }

.icon-btn {
  width: 34px; height: 34px;
  background: linear-gradient(180deg, #232f44 0%, #232f44 46%, #161f30 54%);
  border: 2px solid #3a4a63;
  outline: 2px solid #080c13;
  border-radius: 8px;
  color: var(--muted);
  display: grid; place-items: center;
  flex: 0 0 auto;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .16);
  transition: transform .08s, filter .1s;
}
.icon-btn:active { transform: translateY(1px); filter: brightness(1.15); }
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn.off { opacity: .5; }

/* ------------------------------------------------------- connect panel */

.panel, .sub {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: min(92vw, 420px);
  text-align: center;
}
.panel h2 { font-size: 20px; }
#connect-status { min-height: 18px; font-size: 14px; color: var(--muted); }
#connect-status.err, .err { color: #ff8a80; min-height: 18px; font-size: 14px; }
#connect-choice { display: flex; flex-direction: column; gap: 12px; width: min(84vw, 300px); }
#connect-choice .btn { width: 100%; }
.sub-hint { color: var(--muted); font-size: 14px; }
.row { display: flex; gap: 10px; justify-content: center; }

#host-code {
  font-size: clamp(56px, 17vw, 92px);
  font-weight: 900;
  letter-spacing: .06em;
  font-variant-numeric: tabular-nums;
  line-height: 1.05;
}
#host-expiry { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
#host-qr svg {
  width: min(44vw, 190px); height: auto;
  background: #fff; padding: 8px; border-radius: 10px; display: block;
}
#host-status { color: var(--muted); }

#join-input {
  width: 7ch;
  font-size: clamp(36px, 11vw, 52px);
  font-weight: 800;
  text-align: center;
  letter-spacing: .28em;
  text-indent: .28em;
  background: #0b1120;
  border: 2px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  padding: 8px 4px;
  font-variant-numeric: tabular-nums;
}
#join-input:focus { outline: none; border-color: var(--p0); }
#panel-join label { color: var(--muted); font-size: 14px; }

/* ------------------------------------------------------- game layout */

#screen-game.active {
  flex-direction: column;
  overflow: hidden;
  position: relative;
  isolation: isolate;
}

#top-bar, #my-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 10px;
  flex: 0 0 auto;
}
.spacer { flex: 1; }

/* The opponent's hand is the player fan, flipped: identical per-card fan
   variables, whole container rotated 180deg. Rendered from handCount only —
   the actual cards never reach this client. */
#top-bar { position: relative; }
#opp-hand {
  position: absolute;
  left: 50%;
  top: -12px;
  transform: translateX(-50%) rotate(180deg);
  width: 180px;
  height: 48px;
  pointer-events: none;
  z-index: 20;
}
.mini-back {
  position: absolute;
  left: 50%;
  bottom: 2px;
  width: 27px;
  aspect-ratio: 5 / 7;
  transform-origin: 50% 100%;
  transform:
    translateX(calc(-50% + var(--tx, 0px)))
    translateY(var(--ty, 0px))
    rotate(var(--rot, 0deg));
}
.mini-back svg { width: 100%; height: 100%; display: block; }
.opp-count {
  position: absolute;
  left: -30px;
  bottom: 12px;
  transform: rotate(180deg); /* stay upright inside the flipped container */
  font-weight: 800;
  color: var(--muted);
  font-size: 14px;
}

/* mobile: music/sound/concede fold behind the burger */
#top-actions { display: none; }
#top-actions.open {
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: absolute;
  top: 46px;
  right: 8px;
  background: #101a2c;
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  z-index: 60;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .55);
}

.pile { display: flex; align-items: center; gap: 5px; }
.pile-card { width: 25px; height: 35px; border-radius: 4px; flex: 0 0 auto; }
.pile-card svg { width: 100%; height: 100%; display: block; }
/* the discard pile is the same back art, tinted spent-sepia */
.pile-card.face svg { filter: sepia(.55) saturate(.75) brightness(.8); }
.pile-count { font-weight: 800; font-size: 14px; font-variant-numeric: tabular-nums; }
.pile-name { font-size: 11px; color: var(--muted); }
.pile.empty .pile-card { opacity: .3; }
.pile.mini .pile-card { width: 20px; height: 28px; }
.pile.mini .pile-count { font-size: 12px; }

#opp-status {
  text-align: center;
  font-size: 13px;
  color: var(--warn);
  padding: 2px 8px;
  flex: 0 0 auto;
}

/* both spear fields are always visible (spec §10); the two field rows soak
   up spare height so the board stays vertically centred on every screen */
.field {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  flex: 1 1 auto;
  min-height: calc(var(--slot-h) + 10px);
}
.slot {
  height: var(--slot-h);
  aspect-ratio: 1 / 2;
  border: 1.5px dashed rgba(255, 255, 255, .1);
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 1 auto;
  min-width: 0;
}
.slot.filled {
  border-style: solid;
  border-color: rgba(255, 255, 255, .18);
  background: rgba(255, 255, 255, .04);
}
.slot.filled.p0 { color: var(--p0); }
.slot.filled.p1 { color: var(--p1); }
.slot-spear { height: 96%; }
.slot-spear svg, .spear-svg { height: 100%; width: auto; display: block; }
.field.mine .slot.filled { box-shadow: 0 0 8px -2px var(--mine); }
.field.theirs .slot.filled { box-shadow: 0 0 8px -2px var(--theirs); }

.my-turn #opp-field .slot.filled { cursor: pointer; }

/* ---------------------------------------------------------------- shop */

#mid {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 3px 8px;
  flex: 0 0 auto;
}
#shop { display: flex; gap: 8px; }

.shop-pile {
  width: clamp(58px, 16vw, 88px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 6px 4px 7px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  color: #9aa6b5; /* supply spears are neutral until owned */
}
.pile-spears { height: clamp(38px, 6.5vh, 62px); }
.pile-spears svg { height: 100%; width: auto; display: block; }
.pile-label { font-size: 11px; font-weight: 700; color: var(--muted); }
.price {
  background: var(--gold);
  color: #241a05;
  font-weight: 800;
  font-size: 12px;
  border-radius: 999px;
  padding: 2px 9px;
  white-space: nowrap;
}
/* T2/T3 are merge-only supply piles: no price tag, ever (spec §4) */
.merge-tag {
  font-size: 9.5px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}

.target-glow {
  border-color: var(--gold) !important;
  box-shadow: 0 0 0 2px var(--gold), 0 0 16px rgba(217, 164, 65, .55);
  animation: glowPulse 1.1s ease-in-out infinite;
}
@keyframes glowPulse {
  0%, 100% { box-shadow: 0 0 0 2px var(--gold), 0 0 10px rgba(217, 164, 65, .4); }
  50% { box-shadow: 0 0 0 2px var(--gold), 0 0 20px rgba(217, 164, 65, .8); }
}

/* --------------------------------------------------------------- timer */

#timer-wrap { flex: 0 0 auto; }
#timer-svg { width: clamp(48px, 13vw, 64px); height: auto; display: block; }
#timer-svg .ring-bg { fill: none; stroke: #243048; stroke-width: 6; }
#timer-svg .ring-fg {
  fill: none;
  stroke: var(--ok);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 188.5;
  transform: rotate(-90deg);
  transform-origin: center;
}
#timer-svg text { fill: var(--text); font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
#timer-svg.warn .ring-fg { stroke: var(--warn); }
#timer-svg.warn text { fill: var(--warn); }
#timer-svg.danger .ring-fg { stroke: var(--danger); }
#timer-svg.danger text { fill: var(--danger); }
#timer-svg.danger { animation: dangerPulse .8s ease-in-out infinite; }
#timer-svg.idle { opacity: .28; }
#timer-svg.paused .ring-fg { stroke: var(--muted); }
#ring-pause rect { fill: #c8d2e0; }
@keyframes dangerPulse { 50% { transform: scale(1.07); } }

/* -------------------------------------------------------------- prompt */

#prompt {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 110px;
  max-width: 40vw;
}
#prompt-total {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 800;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  visibility: hidden; /* box is always reserved - no layout jump */
}
#prompt-total.shown { visibility: visible; }
#prompt-total svg { width: 20px; height: 20px; display: block; }
#prompt-total.enough { color: var(--ok); }
#prompt-total.over { color: var(--warn); }
#prompt-hint { font-size: 12.5px; color: var(--muted); min-height: 17px; line-height: 1.25; }

/* ---------------------------------------------------------------- chips */

/* Action chips float above the hand, outside the layout flow - appearing or
   wrapping can never move the board. */
#chips {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(var(--hand-h) + 6px);
  display: flex;
  gap: 8px;
  justify-content: center;
  align-items: flex-end;
  flex-wrap: wrap;
  padding: 2px 8px;
  z-index: 55;
  pointer-events: none; /* the strip is transparent to taps... */
}
#chips .chip { pointer-events: auto; } /* ...the chips themselves are not */
.chip {
  --b-top: #46608c;
  --b-bot: #24344f;
  --b-accent: #7d99c4;
  --b-glow: rgba(125, 153, 196, .3);
  background: linear-gradient(180deg, var(--b-top) 0%, var(--b-top) 46%, var(--b-bot) 54%, var(--b-bot) 100%);
  border: 2px solid var(--b-accent);
  outline: 2px solid #080c13;
  border-radius: 999px;
  padding: 8px 16px;
  font-weight: 900;
  font-size: 12.5px;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: #f2f6fc;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .6);
  box-shadow: 0 0 10px var(--b-glow), inset 0 1px 0 rgba(255, 255, 255, .22);
  transition: filter .1s, transform .08s;
}
.chip:hover { filter: brightness(1.09); }
.chip:active { transform: translateY(1px); filter: brightness(1.14); }
.chip.primary { --b-top: #3f74d8; --b-bot: #1c3f8f; --b-accent: #4aa8ff; --b-glow: rgba(74, 168, 255, .45); }
.chip.danger { --b-top: #d84a3a; --b-bot: #8c1d12; --b-accent: #ff6a5a; --b-glow: rgba(255, 106, 90, .4); }
.chip.ghost { --b-top: #232f44; --b-bot: #161f30; --b-accent: #3a4a63; --b-glow: transparent; color: var(--muted); }
.chip.disabled { opacity: .45; }

/* ----------------------------------------------------------------- hand */

#hand-area {
  flex: 0 0 auto;
  position: relative;
  min-height: var(--hand-h);
}
#hand {
  position: absolute;
  inset: 0;
  touch-action: none;
}

.hand-card {
  position: absolute;
  left: 50%;
  bottom: 4px;
  width: var(--card-w);
  aspect-ratio: 5 / 7;
  transform-origin: 50% 100%;
  transform:
    translateX(calc(-50% + var(--tx, 0px) + var(--shift, 0px)))
    translateY(var(--ty, 0px))
    rotate(var(--rot, 0deg));
  transition: transform .16s cubic-bezier(.34, 1.56, .64, 1), opacity .2s, filter .2s;
  border-radius: 8px;
  cursor: pointer;
}
.hand-card .card-face { width: 100%; height: 100%; pointer-events: none; }
.hand-card .card-face svg {
  width: 100%; height: 100%; display: block;
  filter: drop-shadow(0 3px 6px rgba(0, 0, 0, .5));
}

.hand-card.shift-l { --shift: -16px; }
.hand-card.shift-r { --shift: 16px; }

/* selected: lifted + glowing (spec §12) */
.hand-card.selected {
  transform:
    translateX(calc(-50% + var(--tx, 0px) + var(--shift, 0px)))
    translateY(calc(var(--ty, 0px) - 30px))
    rotate(var(--rot, 0deg));
  z-index: 20;
}
.hand-card.selected .card-face svg {
  filter: drop-shadow(0 0 8px var(--gold)) drop-shadow(0 4px 10px rgba(0, 0, 0, .5));
}

/* desktop hover: lift, straighten, scale ~1.15 (spec §12) */
@media (hover: hover) {
  .hand-card:hover {
    transform:
      translateX(calc(-50% + var(--tx, 0px) + var(--shift, 0px)))
      translateY(calc(var(--ty, 0px) - 46px))
      rotate(0deg)
      scale(1.15);
    z-index: 40;
  }
  .hand-card.selected:hover {
    transform:
      translateX(calc(-50% + var(--tx, 0px) + var(--shift, 0px)))
      translateY(calc(var(--ty, 0px) - 56px))
      rotate(0deg)
      scale(1.15);
  }
}

/* not our turn (including the banner phase): the whole hand reads disabled */
#hand.waiting .hand-card { opacity: .6; }
#hand.waiting .hand-card .card-face svg { filter: grayscale(.55) brightness(.72); }

/* unplayable: dimmed & desaturated */
.hand-card.dimmed .card-face svg { filter: grayscale(.75) brightness(.62); }
.hand-card.dimmed.selected .card-face svg {
  filter: grayscale(.6) brightness(.75) drop-shadow(0 0 8px var(--gold));
}

/* everything not part of a valid selected combination */
.hand-card.rest-dimmed { opacity: .42; }

/* an armed target wants this card */
.hand-card.wanted .card-face svg { animation: wantGlow 1s ease-in-out infinite alternate; }
@keyframes wantGlow {
  from { filter: drop-shadow(0 0 2px rgba(217, 164, 65, .3)) drop-shadow(0 3px 6px rgba(0, 0, 0, .5)); }
  to { filter: drop-shadow(0 0 10px rgba(217, 164, 65, .95)) drop-shadow(0 3px 6px rgba(0, 0, 0, .5)); }
}

/* over-limit telegraph: this card auto-discards on timeout (spec §7) */
.hand-card.at-risk::after {
  content: '!';
  position: absolute;
  top: 3px;
  right: 3px;
  width: 19px;
  height: 19px;
  background: var(--warn);
  color: #1a1206;
  font-weight: 900;
  font-size: 14px;
  border-radius: 50%;
  border: 1.5px solid #1a1206;
  display: grid;
  place-items: center;
  z-index: 5;
}

.shake { animation: shakeX .32s ease-in-out; }
@keyframes shakeX {
  0%, 100% { translate: 0 0; }
  20% { translate: -7px 0; }
  40% { translate: 7px 0; }
  60% { translate: -5px 0; }
  80% { translate: 5px 0; }
}

/* ------------------------------------------------------------ fx layer */

#fx-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 65;
  overflow: hidden;
}
.fx-sprite {
  position: fixed;
  pointer-events: none;
  will-change: transform;
  transition: color .28s ease;
}
.fx-sprite svg { width: 100%; height: 100%; display: block; }
.fx-sprite.p0 { color: var(--p0); }
.fx-sprite.p1 { color: var(--p1); }
.fx-sprite.neutral { color: #98a2ae; }
.fx-sprite.fx-card svg { filter: drop-shadow(0 6px 14px rgba(0, 0, 0, .55)); }
.fx-sprite.fx-steal svg { filter: drop-shadow(0 6px 18px rgba(0, 0, 0, .6)); }
.fx-sprite.fx-auto svg { filter: drop-shadow(0 0 6px var(--warn)); }

.fx-flash {
  position: fixed;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff 0%, rgba(255, 240, 190, .65) 40%, transparent 70%);
  pointer-events: none;
}
.fx-flash.small { width: 88px; height: 88px; }
.fx-particle {
  position: fixed;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #ffd873;
  pointer-events: none;
}
.fx-ring {
  position: fixed;
  border: 3px solid currentColor;
  border-radius: 50%;
  color: #ffd873;
  pointer-events: none;
}
.fx-rays {
  position: fixed;
  border-radius: 50%;
  pointer-events: none;
  background: repeating-conic-gradient(
    rgba(255, 232, 160, .45) 0deg 9deg,
    transparent 9deg 26deg
  );
  -webkit-mask: radial-gradient(circle, #000 0%, transparent 70%);
  mask: radial-gradient(circle, #000 0%, transparent 70%);
}

/* --------------------------------------------------- history feed (§HS) */

#history {
  position: absolute;
  left: 6px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 45;
  max-height: 62vh;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 2px;
  scrollbar-width: thin;
  scrollbar-color: #33445f transparent;
}
/* when the rail has a fixed height, keep entries bottom-anchored until full */
#history::before { content: ''; margin-top: auto; }
.h-entry { position: relative; width: 34px; height: 34px; flex: 0 0 auto; }
.h-icon {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: #0d1526;
  overflow: hidden;
  display: grid;
  place-items: center;
  cursor: pointer;
  animation: hIn .25s ease-out;
}
.h-entry.p0 .h-icon { border-color: var(--p0); color: var(--p0); }
.h-entry.p1 .h-icon { border-color: var(--p1); color: var(--p1); }
.h-icon svg { width: 88%; height: 88%; display: block; }
.h-icon .spear-svg { width: auto; height: 96%; }
.h-time { font-size: 18px; }
@keyframes hIn { from { transform: translateX(-18px); opacity: 0; } }

/* single fixed detail panel beside the rail — the rail scrolls, this never clips */
/* volume slider popover, anchored under the audio buttons */
#vol-pop {
  position: fixed;
  z-index: 79;
  background: #101a2c;
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .55);
}
#vol-slider {
  width: 150px;
  display: block;
  accent-color: var(--gold);
  cursor: pointer;
}

#history-pop {
  position: fixed;
  transform: translateY(-50%);
  background: #101a2c;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  width: max-content;
  max-width: min(64vw, 260px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .55);
  pointer-events: none;
  text-align: left;
  z-index: 78;
}
.h-entry.open .h-icon { box-shadow: 0 0 0 2px var(--gold); }
.h-title { font-weight: 700; font-size: 13.5px; }
.h-sub { color: var(--muted); font-size: 12px; margin-top: 3px; }
.h-cards { display: flex; gap: 5px; margin-top: 8px; }
.h-cards svg { width: 54px; height: auto; display: block; }
.h-turn { display: none; flex: 0 0 auto; } /* turn separators are desktop-only */

/* --------------------------------------------------------- turn banner */

#turn-banner {
  position: fixed;
  top: 44%;
  left: 0;
  right: 0;
  text-align: center;
  font-size: clamp(30px, 8vw, 58px);
  font-weight: 900;
  letter-spacing: .12em;
  pointer-events: none;
  z-index: 70;
  opacity: 0;
  text-shadow: 0 2px 18px rgba(0, 0, 0, .9);
}
#turn-banner.mine { color: var(--mine); }
#turn-banner.theirs { color: var(--theirs); }
#turn-banner.flash { color: var(--warn); }

/* ---------------------------------------------------- toast & overlays */

#toast {
  position: fixed;
  left: 50%;
  bottom: 36vh;
  transform: translateX(-50%);
  background: rgba(11, 17, 32, .95);
  border: 1px solid #33415c;
  border-radius: 10px;
  padding: 9px 15px;
  font-size: 14px;
  max-width: 88vw;
  text-align: center;
  z-index: 75;
  opacity: 0;
  transition: opacity .18s;
  pointer-events: none;
}
#toast.show { opacity: 1; }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(4, 8, 16, .74);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

/* sized from the viewport HEIGHT so it can never overflow in landscape */
#zoom-card {
  height: min(70dvh, 470px);
  aspect-ratio: 5 / 7;
  width: auto;
  max-width: 86vw;
}
#zoom-card svg { width: 100%; height: 100%; display: block; filter: drop-shadow(0 10px 30px rgba(0, 0, 0, .8)); }
#zoom-hint { color: var(--muted); font-size: 13px; }

.dialog {
  background: #141d2e;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: min(90vw, 380px);
  text-align: center;
  font-size: 15.5px;
  line-height: 1.4;
}
.dialog-row { display: flex; gap: 10px; justify-content: center; }
.dialog.go { max-width: min(92vw, 560px); padding: 26px 36px; }

/* ---- how to play */
.dialog.help {
  max-width: min(94vw, 560px);
  max-height: 92dvh;
  overflow-y: auto;
  gap: 14px;
}
.dialog.help h3 { font-size: 19px; letter-spacing: .03em; color: var(--gold); }
#help-flow {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 6px;
}
.hf-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 96px;
  color: var(--p0); /* spears preview in blue */
}
.hf-step .spear-svg { height: 62px; width: auto; }
.hf-label { font-size: 11.5px; color: var(--muted); line-height: 1.3; }
.hf-arrow { color: var(--gold); font-size: 24px; font-weight: 900; margin-top: 18px; }
#help-cards {
  display: flex;
  justify-content: center;
  gap: 8px;
}
.help-card {
  width: clamp(50px, 13vw, 78px);
  cursor: pointer;
  transition: transform .12s, filter .12s;
}
.help-card svg { width: 100%; height: auto; display: block; }
.help-card:hover { transform: translateY(-4px); }
.help-card.active {
  transform: translateY(-6px) scale(1.06);
  filter: drop-shadow(0 0 8px var(--gold));
}
#help-card-info {
  font-size: 12.5px;
  color: var(--muted);
}
#zoom-desc {
  max-width: min(80vw, 340px);
  background: rgba(11, 17, 32, .95);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 15px;
  font-size: 16px;
  line-height: 1.45;
  text-align: center;
}
#help-rules {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
  color: var(--muted);
  text-align: left;
  padding: 0 8px;
}
#help-rules li::before { content: '\2022  '; color: var(--gold); }

#go-title { font-size: clamp(36px, 9vw, 62px); font-weight: 900; letter-spacing: .1em; line-height: 1.15; }
#go-title.win { color: var(--gold); text-shadow: 0 0 26px rgba(217, 164, 65, .5); }
#go-title.loss { color: var(--danger); text-shadow: 0 0 26px rgba(239, 68, 68, .45); }
#go-reason { color: var(--text); font-size: 16px; }

#conn-overlay { z-index: 90; }

/* ----------------------------------------------------- responsiveness */

/* wide desktop: Hearthstone-style board filling the whole viewport —
   big fields as the two halves of a table, shop strip across the middle,
   end-turn on the right edge, history rail on the left, large fanned hand */
@media (min-width: 820px) and (min-height: 640px) {
  :root {
    --card-w: clamp(120px, 11vw, 168px);
    --hand-h: clamp(190px, 28vh, 260px);
    --slot-h: clamp(84px, 17vh, 152px);
  }
  /* a real control gutter on the right: timer, end turn, hint and the icon
     buttons all live fully outside the board frame — nothing straddles it */
  #screen-game.active { padding: 0 200px 0 96px; }

  /* the table */
  #screen-game.active::before {
    content: '';
    position: absolute;
    inset: 10px 190px 10px 78px;
    border-radius: 28px;
    background: radial-gradient(85% 70% at 50% 50%, #1c2a45 0%, #14203a 55%, #101a2e 100%);
    border: 1px solid #2c3d5e;
    box-shadow: inset 0 0 70px rgba(0, 0, 0, .5), 0 0 0 6px rgba(0, 0, 0, .25);
    z-index: -1;
  }
  /* burger only exists on mobile; the actions sit as a row at the top of
     the control gutter (top-bar ends 200px short of the viewport edge) */
  #btn-menu { display: none; }
  #top-actions {
    display: flex;
    flex-direction: row;
    gap: 12px;
    position: absolute;
    top: 14px;
    right: -186px;
    z-index: 46;
  }

  /* the two board halves grow to fill the space */
  .field {
    flex: 1 1 auto;
    gap: 10px;
    margin: 4px 0;
  }
  .field .slot { border-radius: 12px; border-width: 2px; }
  .field.theirs { background: radial-gradient(70% 90% at 50% 0%, rgba(239, 68, 68, .05), transparent 70%); }
  .field.mine { background: radial-gradient(70% 90% at 50% 100%, rgba(59, 130, 246, .05), transparent 70%); }
  body.seat-1 .field.theirs { background: radial-gradient(70% 90% at 50% 0%, rgba(59, 130, 246, .05), transparent 70%); }
  body.seat-1 .field.mine { background: radial-gradient(70% 90% at 50% 100%, rgba(239, 68, 68, .05), transparent 70%); }

  /* middle strip: the shop sits dead centre; the timer stacks above the
     End turn button and the hint/total below it, on the right edge */
  #mid { gap: 24px; padding: 6px 0; justify-content: center; }
  #shop { gap: 14px; }
  .shop-pile { width: 128px; border-radius: 16px; padding: 10px 8px; gap: 6px; }
  .pile-spears { height: 96px; }
  .pile-label { font-size: 13px; }
  .price { font-size: 14px; padding: 3px 12px; }
  .merge-tag { font-size: 11px; }
  #timer-wrap {
    position: absolute;
    right: 55px;
    top: calc(46% - 132px);
    z-index: 46;
  }
  #timer-svg { width: 84px; }
  #prompt {
    position: absolute;
    right: 22px;
    top: calc(46% + 64px); /* well clear of the End turn button above */
    z-index: 46;
    width: 158px;
    max-width: 158px;
    align-items: flex-start;
    text-align: left;
  }
  #prompt-hint { font-size: 14.5px; }
  #prompt-total { font-size: 20px; }
  #prompt-total svg { width: 25px; height: 25px; }

  /* deck & discard: real card piles with a Hearthstone-style count badge,
     sitting inside the board frame */
  .pile { gap: 0; position: relative; }
  .pile-card { width: 88px; height: 123px; border-radius: 8px; }
  .pile.mini .pile-card { width: 64px; height: 90px; }
  .pile-count {
    position: absolute;
    top: -9px;
    right: -9px;
    z-index: 2;
    min-width: 30px;
    height: 30px;
    padding: 0 7px;
    display: grid;
    place-items: center;
    background: #0d1526;
    border: 2px solid var(--gold);
    border-radius: 999px;
    font-size: 15px;
  }
  .pile.mini .pile-count { min-width: 25px; height: 25px; font-size: 13px; top: -7px; right: -7px; }
  .pile-name {
    position: absolute;
    left: 0;
    right: 0;
    bottom: -20px;
    text-align: center;
    font-size: 13px;
  }
  #top-bar { padding: 16px 110px 6px; align-items: flex-start; }
  #my-row { padding: 6px 110px 26px; align-items: flex-end; }

  /* opponent hand: the flipped fan, at full Hearthstone scale */
  #opp-hand {
    width: min(38vw, 480px);
    height: 104px;
    top: -34px;
  }
  .mini-back { width: 62px; }
  .opp-count { font-size: 17px; left: -42px; bottom: 38px; }

  .icon-btn { width: 40px; height: 40px; }
  .icon-btn svg { width: 22px; height: 22px; }
  #zoom-card { height: min(78dvh, 600px); }

  #chips { gap: 10px; }
  .chip { font-size: 15px; padding: 10px 18px; }

  /* turn separators in the history rail */
  .h-turn {
    display: block;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .04em;
    color: var(--muted);
    padding: 2px 0 0 3px;
  }

  /* End-turn button geometry in the control gutter (colours come from the
     .btn.gold / .blocked / .ready variants) */
  #btn-endturn {
    position: absolute;
    right: 25px;
    top: 46%;
    transform: translateY(-50%);
    z-index: 46;
    font-size: 16px;
    padding: 14px 8px;
    width: 145px;
    text-align: center;
  }
  #btn-endturn:active { transform: translateY(calc(-50% + 1px)); }

  /* history rail: a fixed scrollable band in the left gutter, bigger icons */
  #history {
    left: 16px;
    gap: 8px;
    top: 110px;
    bottom: 240px;
    max-height: none;
    transform: none;
  }
  .h-entry { width: 46px; height: 46px; }
  .h-title { font-size: 14.5px; }
  .h-sub { font-size: 13px; }
  .h-cards svg { width: 64px; }
}

/* landscape phones (the only supported phone orientation): big readable
   cards, compressed board rows, compact history rail on the left */
@media (max-height: 500px) {
  :root {
    --card-w: clamp(96px, 13vw, 118px);
    --hand-h: 122px;
    --slot-h: 36px;
  }
  #top-bar, #my-row { padding: 2px 8px; }
  .field { padding: 2px 6px; gap: 3px; }
  .slot { border-radius: 4px; }
  #mid { gap: 8px; }
  .pile-spears { height: 34px; }
  .shop-pile { width: 64px; padding: 4px 3px 5px; border-radius: 9px; }
  .pile-label { display: none; }
  .pile-name { display: none; }
  #timer-svg { width: 42px; }
  .chip { padding: 5px 11px; font-size: 12.5px; }
  #prompt-hint { min-height: 0; }
  #turn-banner { top: 40%; }
  #history { top: 52px; bottom: 96px; left: 4px; gap: 4px; max-height: none; transform: none; }
  .h-entry { width: 30px; height: 30px; }
}

/* phones: declutter the labels (portrait itself is gated by the rotate
   overlay below) */
@media (max-width: 700px) {
  .price-word { display: none; }
  .pile-name { display: none; }
}

/* portrait phones: landscape-only game - ask for a rotation instead of
   squeezing everything into a column */
#rotate-overlay { display: none; }
@media (orientation: portrait) and (max-width: 820px) {
  #rotate-overlay {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 200;
    background: var(--bg);
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    text-align: center;
  }
}
.rotate-icon { width: 84px; height: 84px; animation: rotateNudge 2.2s ease-in-out infinite; }
.rotate-title { font-size: 22px; font-weight: 800; }
.rotate-sub { color: var(--muted); font-size: 14px; }
@keyframes rotateNudge {
  0%, 55%, 100% { transform: rotate(0deg); }
  70%, 85% { transform: rotate(90deg); }
}

/* short screens: title / connect / help shrink to fit landscape phones */
@media (max-height: 520px) {
  #screen-title, #screen-connect { gap: 10px; overflow-y: auto; }
  #logo svg { width: min(34vh, 240px); }
  .btn.big { width: min(56vw, 300px); padding: 10px 16px; font-size: 14px; }
  .panel h2 { font-size: 16px; }
  #host-code { font-size: 44px; }
  #host-qr svg { width: min(26vh, 130px); }
  .dialog.help { max-height: 96dvh; gap: 8px; }
  .hf-step .spear-svg { height: 44px; }
  .help-card { width: clamp(42px, 9vw, 58px); }
}

/* very narrow phones */
@media (max-width: 370px) {
  :root { --card-w: 72px; }
  .shop-pile { width: 56px; }
  #prompt { min-width: 90px; }
  #mid { gap: 7px; }
}

@media (prefers-reduced-motion: reduce) {
  .target-glow, .hand-card.wanted .card-face svg, #timer-svg.danger, .btn.ready { animation: none; }
  .hand-card { transition: none; }
}
