/* ==========================================================================
   ESA ARCADE - mobile / tablet presentation layer
   Desktop and touch are mutually exclusive presentations: every rule that
   changes the look is scoped to body.is-touch (set by js/touch.js), except
   the short-window menu scroll fix. Desktop with mouse + keyboard renders
   exactly as before.

   Orientation model (native - nothing is rotated with CSS)
     Menus     follow the device; portrait is the home orientation.
     Gameplay  always a FULL-SCREEN LANDSCAPE game. Phone held upright (or
               rotation locked): body.vland rotates ONLY the gameplay layers
               into a virtual landscape box that covers the whole screen (see
               VIRTUAL LANDSCAPE below and the header of js/touch.js - touch
               input is inverse-mapped there). Phone turned: the real
               landscape viewport is used and nothing is rotated.
   ========================================================================== */

:root {
  /* Safe areas (notch, Dynamic Island, home indicator). --fake-sa-* lets
     tooling simulate insets on devices without them. */
  --sa-t: max(env(safe-area-inset-top, 0px), var(--fake-sa-t, 0px));
  --sa-r: max(env(safe-area-inset-right, 0px), var(--fake-sa-r, 0px));
  --sa-b: max(env(safe-area-inset-bottom, 0px), var(--fake-sa-b, 0px));
  --sa-l: max(env(safe-area-inset-left, 0px), var(--fake-sa-l, 0px));
  --view-w: 100vw;
  --view-h: 100dvh;
}

/* --------------------------------------------------------------------------
   VIRTUAL LANDSCAPE (body.vland - touch play screen, portrait viewport)
   The gameplay layers become a landscape box W' x H' = viewport height x
   viewport width, rotated 90deg clockwise about their top-left corner,
   which sits at the viewport's right edge: the box covers the screen
   exactly. --app-w / --app-h are measured live by js/touch.js (Safari bars
   included). Safe-area insets are remapped into the rotated frame:
   local top = screen right, local right = screen bottom, local bottom =
   screen left, local left = screen top.
   -------------------------------------------------------------------------- */
body.vland {
  --sa-t: max(env(safe-area-inset-right, 0px), var(--fake-sa-r, 0px));
  --sa-r: max(env(safe-area-inset-bottom, 0px), var(--fake-sa-b, 0px));
  --sa-b: max(env(safe-area-inset-left, 0px), var(--fake-sa-l, 0px));
  --sa-l: max(env(safe-area-inset-top, 0px), var(--fake-sa-t, 0px));
  --view-w: var(--app-h, 100dvh);
  --view-h: var(--app-w, 100vw);
}
body.vland #playScreen,
body.vland #touchLayer,
body.vland #modalLayer,
body.vland #touchPreroll {
  position: fixed;
  inset: auto;
  top: 0;
  left: var(--app-w, 100vw);
  width: var(--app-h, 100dvh);
  height: var(--app-w, 100vw);
  transform-origin: 0 0;
  transform: rotate(90deg);
}
/* No page scroll / rubber-band while the game shell is up. */
html.vland, html.vland body { overflow: hidden; overscroll-behavior: none; height: 100%; }
body.vland #playScreen { animation: vlandIn .32s var(--ease-out, ease-out); }
@keyframes vlandIn { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { body.vland #playScreen { animation: none; } }

/* --------------------------------------------------------------------------
   Desktop-only / touch-only content
   -------------------------------------------------------------------------- */
body:not(.is-touch) .touch-only { display: none !important; }
body.is-touch .desk-only { display: none !important; }

body.is-touch .kbd-hint,
body.is-touch .nav-hint,
body.is-touch .hud-keys,
body.is-touch .modal-hint,
body.is-touch .press-start .keycap,
body.is-touch .back-btn .keycap,
body.is-touch .cs-keys,
body.is-touch .topbar-crumb { display: none !important; }

body.is-touch button,
body.is-touch .cabinet,
body.is-touch .cs-tile,
body.is-touch .ps-tile { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

.touch-hint {
  margin: 4px 0 0;
  text-align: center;
  font-size: 13px;
  letter-spacing: .04em;
  color: var(--x-fdeec4-a78);
}
.touch-hint b { font-family: var(--font-display); letter-spacing: .1em; color: var(--gold-300, var(--gold-400)); }
.touch-hint .t-p1 { color: var(--p1); }
.touch-hint .t-p2 { color: var(--p2); }

/* --------------------------------------------------------------------------
   Menus on short screens (phones in landscape, small windows): scroll
   instead of clipping. Auto margins keep content centred when it fits.
   -------------------------------------------------------------------------- */
@media (max-height: 560px) {
  .screen:not(#playScreen) {
    overflow-y: auto;
    overflow-x: hidden;
    align-items: flex-start;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
  .screen:not(#playScreen) > * { margin-top: auto; margin-bottom: auto; flex-shrink: 0; }
  .screen.has-topbar { padding-top: 58px; padding-bottom: 14px; }
  #topbar { top: 10px; }
  .mode-inner, .cs-inner, .ps-inner, .so-inner { height: auto; min-height: 100%; }
  .intro-inner { max-height: none; }
  .mode-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .cs-stage { flex: none; grid-template-columns: 1fr 1fr; grid-template-rows: auto auto; }
  .cs-side { grid-row: 1; height: 168px; }
  .cs-roster-wrap { grid-column: 1 / -1; grid-row: 2; min-height: 250px; overflow: visible; }
  .ps-roster-wrap { flex: none; min-height: 230px; }
  .screen-title { font-size: clamp(20px, 5vh, 30px); }
}

/* ==========================================================================
   TOUCH CHROME - top bar, bezel, screen padding (safe-area aware)
   ========================================================================== */
body.is-touch #topbar {
  top: calc(var(--sa-t) + 8px);
  left: calc(var(--sa-l) + 12px);
  right: calc(var(--sa-r) + 12px);
}
body.is-touch .back-btn { height: 38px; padding: 0 14px 0 10px; font-size: 13px; }
body.is-touch .sound-btn { width: 38px; height: 38px; }
body.is-touch #bezel {
  top: calc(var(--sa-t) + 3px);
  right: calc(var(--sa-r) + 3px);
  bottom: calc(var(--sa-b) + 3px);
  left: calc(var(--sa-l) + 3px);
  inset: calc(var(--sa-t) + 3px) calc(var(--sa-r) + 3px) calc(var(--sa-b) + 3px) calc(var(--sa-l) + 3px);
  border-radius: 24px;
  border-color: var(--x-f3c35a-a16);
}
body.is-touch .bz-corner,
body.is-touch .bezel-bulbs { display: none; }
body.is-touch .screen {
  padding: calc(var(--sa-t) + 14px) max(14px, calc(var(--sa-r) + 10px)) max(14px, calc(var(--sa-b) + 10px)) max(14px, calc(var(--sa-l) + 10px));
}
body.is-touch .screen.has-topbar { padding-top: calc(var(--sa-t) + 60px); }
body.is-touch #mascot { display: none !important; }
/* The header owns its band: scrolled content slides UNDER a solid strip,
   never up against BACK / volume, and the buttons stay in the safe area. */
body.is-touch #topbar::before {
  content: "";
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  height: calc(var(--sa-t) + 56px);
  background: linear-gradient(180deg, var(--x-030b16-a97) 0 72%, var(--x-030b16-a0));
  pointer-events: none;
  z-index: -1;
}
body.is-touch[data-state="play"] #topbar::before { display: none; }

/* Every touch menu is a scroll container anchored at the top: content that
   fits stays centred (auto margins), taller content scrolls - it can never
   slide up under the Back button. */
body.is-touch .screen:not(#playScreen) {
  overflow-y: auto;
  overflow-x: hidden;
  align-items: flex-start;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
body.is-touch .screen:not(#playScreen) > * { margin-top: auto; margin-bottom: auto; flex-shrink: 0; }
body.is-touch .mode-inner,
body.is-touch .cs-inner,
body.is-touch .ps-inner { height: auto; min-height: 100%; }
body.is-touch .cs-stage { flex: none; }
body.is-touch .intro-inner { max-height: none; }
body.is-touch .ctrl { flex-wrap: wrap; }
body.is-touch .ctrl-touch { flex: 1 1 100%; justify-content: flex-start; }

/* Character select confirm step: thumb-sized buttons, whose turn it is. */
body.is-touch .cs-confirm { left: 6px; right: 6px; bottom: 8px; padding: 8px 6px 7px; gap: 6px; }
body.is-touch .cs-confirm-row { flex-wrap: nowrap; gap: 5px; }
body.is-touch .cs-confirm-row .btn { min-height: 44px; padding: 0 6px; font-size: 12px; letter-spacing: .04em; white-space: nowrap; }
body.is-touch .cs-ok { flex: 1.5 1 0; }
body.is-touch .cs-no { flex: 1 1 0; }
body.is-touch .cs-ask { font-size: 11px; }
body.is-touch .cs-ask b { font-size: 14px; }
body.is-touch .cs-change { min-height: 40px; }
body.is-touch .cs-side.is-turn:not(.is-pending):not(.is-locked) { border-color: var(--slot); box-shadow: 0 8px 0 var(--x-020810), 0 0 22px color-mix(in srgb, var(--slot) 45%, transparent); }

/* --- Portrait menus: designed for a phone held upright ------------------ */
@media (orientation: portrait) {
  body.is-touch .screen-title { font-size: clamp(22px, 6.6vw, 32px); letter-spacing: .12em; }
  body.is-touch .screen-head { gap: 10px; max-width: 100%; }
  body.is-touch .screen-head .px-arrow { flex: none; }

  /* Welcome */
  body.is-touch .welcome-wordmark { font-size: clamp(54px, 17vw, 92px); }
  body.is-touch .press-start { padding: 16px 30px; }
  body.is-touch .welcome-foot { bottom: calc(var(--sa-b) + 16px); }

  /* Mode select: stacked cards; the ACTIVE one follows the scroll
     (js/menus.js). Active vs inactive never changes a card's geometry:
     no scale, only a 3px lift, border, glow and brightness. */
  body.is-touch .mode-inner { gap: 16px; }
  body.is-touch .mode-grid { grid-template-columns: 1fr; gap: 14px; padding-bottom: 4px; }
  body.is-touch .mc-screen { height: clamp(70px, 11vh, 120px); }
  body.is-touch #modeScreen { scroll-snap-type: y proximity; scroll-padding: calc(var(--sa-t) + 60px) 0 calc(var(--sa-b) + 12px); }
  body.is-touch .mode-card { scroll-snap-align: center; transform: none; opacity: .9; filter: saturate(.8) brightness(.9); }
  body.is-touch .mode-card.is-focus {
    transform: translateY(-3px);
    opacity: 1;
    filter: none;
    border-color: var(--gold-300, var(--gold-400));
    box-shadow: 0 10px 0 var(--x-020810), 0 0 0 2px var(--x-f3c35a-a45), 0 0 34px var(--x-f3c35a-a38);
  }
  body.is-touch .mc-cta { opacity: .55; color: var(--gold-300, var(--gold-400)); animation: none; }
  body.is-touch .mode-card.is-focus .mc-cta { opacity: 1; animation: none; }

  /* Character select: P1 / P2 cards on top, big roster below */
  body.is-touch .cs-stage { grid-template-columns: 1fr 1fr; grid-template-rows: auto 1fr; gap: 10px; }
  body.is-touch .cs-side { grid-row: 1; height: clamp(150px, 24vh, 230px); padding: 10px 8px 10px; }
  body.is-touch .cs-roster-wrap { grid-column: 1 / -1; grid-row: 2; }
  body.is-touch .cs-name { font-size: 15px; }
  body.is-touch .cs-side { height: clamp(170px, 26vh, 240px); }

  /* Library: one machine at a time, swipe for the next */
  body.is-touch .lib-top { flex-direction: column; gap: 8px; }
  body.is-touch .px-nav { width: 40px; height: 56px; }

  /* Intro / briefing */
  body.is-touch .intro-inner { padding: 18px 16px; gap: 9px; }
  body.is-touch .intro-controls { grid-template-columns: 1fr; gap: 8px; }

  /* Participants: the action bar stacks so Start is never cut off */
  body.is-touch .ps-bar { flex-wrap: wrap; gap: 10px; padding: 10px 12px; }
  body.is-touch .ps-format { flex: 1 1 100%; order: 3; }
  body.is-touch .ps-actions { flex: 1 1 100%; }
  body.is-touch .ps-actions .btn { flex: 1; }
}

/* Touch control chips (library cards, intro). */
.cab-touch, .ctrl-touch { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; align-items: center; }
.tchip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 10px;
  border-radius: 12px;
  font: 700 11px/1 var(--font-display, sans-serif);
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--x-2a1a03);
  background: linear-gradient(180deg, var(--gold-100), var(--gold-400));
  border: 1px solid var(--gold-600);
}
.tchip:first-child { color: var(--cream); background: var(--x-15406c-a90); border-color: var(--x-f3c35a-a55); }
.tside { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--x-fff6e4-a60); }

/* ==========================================================================
   GAMEPLAY - a real landscape game: slim HUD bar, maximal arena
   ========================================================================== */
body.is-touch #playScreen {
  padding: max(4px, var(--sa-t)) max(6px, var(--sa-r)) max(4px, var(--sa-b)) max(6px, var(--sa-l));
  align-items: center;
  justify-content: center;
}
body.is-touch #playScreen .stage {
  --hud-h: clamp(30px, calc(var(--view-h) * .082), 44px);
  display: grid;
  grid-template-columns: var(--hud-h) minmax(0, 1fr) var(--hud-h);
  grid-template-rows: var(--hud-h) auto;
  gap: 5px 6px;
  width: min(
    calc(var(--view-w) - var(--sa-l) - var(--sa-r) - 12px - 2 * var(--touch-gutter, 0px)),
    calc((var(--view-h) - var(--sa-t) - var(--sa-b) - var(--hud-h) - 14px) * 16 / 9));
}
body.is-touch .play-bar { display: contents; }
body.is-touch .play-bar .game-name,
body.is-touch .play-bar .game-mode,
body.is-touch .play-bar .spacer,
body.is-touch .play-bar .play-tag,
body.is-touch .pause-btn .pb-word { display: none; }
/* One HUD bar, every block exactly --hud-h tall:
   [pause] [ YOU face name ... score | FIRST TO 5 | score ... name face CPU ] [gear]
   Pause and the controls gear are equal squares at the two ends, so they
   never crowd the scores. The gear's column stays reserved even when a
   game has no controls to customise, so the bar never shifts. */
body.is-touch .pause-btn,
body.is-touch .ctl-btn {
  grid-row: 1;
  width: var(--hud-h);
  height: var(--hud-h);
  min-width: 0;
  min-height: 0;
  padding: 0;
  border-radius: 10px;
  font-size: calc(var(--hud-h) * .36);
  display: grid;
  place-items: center;
}
body.is-touch .pause-btn { grid-column: 1; }
body.is-touch .ctl-btn { grid-column: 3; font-size: calc(var(--hud-h) * .5); }
body.is-touch .ctl-btn.hidden { display: grid !important; visibility: hidden; }
body.is-touch .hud {
  grid-column: 2;
  grid-row: 1;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 5px;
  height: var(--hud-h);
  align-items: stretch;
}
body.is-touch .hud > * { box-sizing: border-box; height: var(--hud-h); min-height: 0; }
body.is-touch .hud-player { padding: 0 8px 0 4px; gap: 7px; border-radius: 10px; }
body.is-touch .hud-player.is-right { padding: 0 4px 0 8px; }
body.is-touch .hud-face { width: calc(var(--hud-h) - 10px); height: calc(var(--hud-h) - 10px); border-width: 1.5px; }
body.is-touch .hud-meta { flex: 1 1 auto; display: flex; align-items: center; overflow: hidden; }
body.is-touch .hud-player.is-right .hud-meta { justify-content: flex-end; }
body.is-touch .hud-name { font-size: clamp(10px, calc(var(--hud-h) * .3), 14px); letter-spacing: .08em; line-height: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
body.is-touch .hud-tail { flex: none; margin: 0; gap: 5px; }
body.is-touch .hud-player.is-right .hud-tail { margin: 0; }
body.is-touch .hud-score { font-size: calc(var(--hud-h) * .62); min-width: calc(var(--hud-h) * .7); }
body.is-touch .pip { width: 7px; height: 7px; }
body.is-touch .hud-center { min-width: calc(var(--hud-h) * 2.3); padding: 0 8px; border-radius: 10px; gap: 0; }
body.is-touch .hud-label { font-size: clamp(7px, calc(var(--hud-h) * .2), 9px); letter-spacing: .16em; line-height: 1.1; white-space: nowrap; }
body.is-touch .hud-value { font-size: calc(var(--hud-h) * .46); line-height: 1; }
/* Solo: a tiny role line under each name (YOU / CPU - HARD). */
body.is-touch .hud.is-solo .hud-meta { flex-direction: column; justify-content: center; align-items: flex-start; gap: 1px; }
body.is-touch .hud.is-solo .hud-player.is-right .hud-meta { align-items: flex-end; }
body.is-touch .hud.is-solo .hud-keys { display: block !important; font-size: clamp(7px, calc(var(--hud-h) * .19), 9px); letter-spacing: .14em; line-height: 1; max-width: 100%; }
body.is-touch .hud.is-solo .hud-keys:empty { display: none !important; }
/* Score Attack: the right block is the SESSION BEST, not a rival. */
.hud-player.is-best .hud-face { display: none; }
.hud-player.is-best .hud-name { color: var(--gold-300, var(--gold-400)); }
.hud-player.is-best .hud-score { color: var(--cream, var(--cream)); opacity: .85; }
body.is-touch #playScreen .canvas-frame { grid-column: 1 / -1; grid-row: 2; border-radius: 12px; }
body.is-touch .banner { padding: 10px 26px; }

/* While controls are live: no scrolling, selection, callouts or zoom. */
body.touch-play { overscroll-behavior: none; }
body.touch-play #playScreen,
body.touch-play #touchLayer {
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
body.touch-play #gameCanvas { touch-action: none; }
/* The game canvases and the control layer only, never the menus: no scroll, zoom, selection, callout or tap flash. (.hs-canvas has its own in hs.css.) */
#gameCanvas, .touch-layer { touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
body.touch-play #playScreen img { -webkit-user-drag: none; pointer-events: none; }

/* --- Pause menu sized for a landscape phone ----------------------------- */
body.is-touch[data-state="play"] #modalLayer { padding: 10px; }
body.is-touch[data-state="play"] .modal-card {
  width: min(460px, 100%);
  max-height: calc(var(--view-h) - 20px);
  padding: 14px 16px 12px;
  gap: 6px;
}
body.is-touch[data-state="play"] .modal-title { font-size: 24px; }
body.is-touch[data-state="play"] .modal-card > .modal-menu { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
body.is-touch[data-state="play"] .modal-card > .modal-menu .modal-btn:first-child { grid-column: 1 / -1; }
body.is-touch[data-state="play"] .modal-btn { min-height: 40px; font-size: 13px; padding: 0 10px; }

/* --- Result card: horizontal so it fits a landscape phone --------------- */
body.touch-play .result-overlay { position: fixed; inset: 0; padding: max(8px, var(--sa-t)) max(10px, var(--sa-r)) max(8px, var(--sa-b)) max(10px, var(--sa-l)); }
body.touch-play .result-card {
  width: min(640px, 100%);
  max-height: 100%;
  overflow: auto;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  column-gap: 18px;
  row-gap: 4px;
  align-items: center;
  text-align: left;
  padding: 16px 20px;
}
body.touch-play .result-card > * { grid-column: 2; }
body.touch-play .result-portrait { grid-column: 1; grid-row: 1 / span 5; width: clamp(72px, 20vmin, 110px); height: clamp(72px, 20vmin, 110px); }
body.touch-play .result-card h2 { font-size: clamp(24px, 7vmin, 38px); }
body.touch-play .result-score { justify-content: flex-start; }
body.touch-play .result-actions { justify-content: flex-start; }
body.touch-play .result-actions .btn { min-height: 42px; }

/* ==========================================================================
   TOUCH CONTROLS - translucent arcade overlay
   ========================================================================== */
.touch-layer { position: fixed; inset: 0; z-index: 30; pointer-events: none; }
.tc-safe { position: absolute; top: var(--sa-t); right: var(--sa-r); bottom: var(--sa-b); left: var(--sa-l); }
.touch-layer.hidden,
.touch-layer .hidden,
.touch-layer.is-result .tc-joy,
.touch-layer.is-result .tc-btn,
.touch-layer.is-result .tc-capture { display: none !important; }

/* Your half of the screen grabs the joystick wherever your thumb lands. */
.tc-capture { position: absolute; pointer-events: auto; touch-action: none; }
.touch-layer.is-editing .tc-capture { pointer-events: none; }

.tc-joy, .tc-btn {
  position: absolute;
  pointer-events: auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: opacity .2s, filter .2s, left .16s cubic-bezier(.2, .8, .2, 1), top .16s cubic-bezier(.2, .8, .2, 1);
  z-index: 2;
}
/* A held or floating pad never animates its position: the joystick centre
   used for the vector is always where the pad really is (no lag). */
.tc-joy.is-active, .tc-joy.is-floating, .tc-joy.is-dragging, .tc-btn.is-dragging { transition: opacity .2s, filter .2s; }
.tc-joy::before, .tc-btn::before { content: ""; position: absolute; inset: -22%; border-radius: 50%; }

.tc-joy-base {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, var(--x-081a30-a28) 0 52%, var(--x-081a30-a50) 100%);
  border: 2px solid var(--slot, var(--gold-400));
  box-shadow: 0 0 0 1px var(--x-030b16-a50), 0 0 18px var(--x-000000-a35), inset 0 0 16px var(--x-f3c35a-a12);
}
.tc-ticks { position: absolute; inset: 14%; border-radius: 50%; border: 1px dashed var(--x-fdeec4-a28); }
.tc-joy-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 42%;
  height: 42%;
  margin: -21% 0 0 -21%;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, var(--x-fff4d6), var(--gold-400) 46%, var(--x-b57d19));
  border: 2px solid var(--x-5c400c-a80);
  box-shadow: 0 4px 10px var(--x-000000-a45), 0 0 14px var(--x-f3c35a-a35);
  transition: transform .12s cubic-bezier(.2, .8, .2, 1);
}
.tc-joy.is-active .tc-joy-knob { transition: none; }
.tc-joy.is-active .tc-joy-base { border-color: var(--cream); box-shadow: 0 0 0 1px var(--x-030b16-a50), 0 0 24px var(--slot, var(--gold-400)); }

.tc-btn {
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 30%, var(--x-ffecb8-a92), var(--x-f3c35a-a85) 48%, var(--x-b07816-a88));
  border: 2px solid var(--x-fff6e4-a70);
  box-shadow: 0 0 0 2px var(--x-030b16-a45), 0 5px 0 var(--x-5c400c-a70), 0 8px 18px var(--x-000000-a40);
}
.tc-btn-label {
  font-family: var(--font-display, sans-serif);
  font-weight: 800;
  font-size: clamp(11px, 2.4vmin, 16px);
  letter-spacing: .12em;
  color: var(--x-2a1a03);
  text-shadow: 0 1px 0 var(--x-fff6e4-a55);
}
.tc-btn.is-down {
  transform: translateY(4px) scale(.94);
  box-shadow: 0 0 0 2px var(--x-030b16-a45), 0 1px 0 var(--x-5c400c-a70), 0 0 22px var(--x-f3c35a-a75);
  filter: brightness(1.12);
}

.tc-tag {
  position: absolute;
  left: 50%;
  top: -9px;
  transform: translateX(-50%);
  padding: 0 6px;
  border-radius: 5px;
  font: 800 9px/1.5 var(--font-display, sans-serif);
  letter-spacing: .1em;
  color: var(--x-ffffff);
  background: var(--slot, var(--p1));
  pointer-events: none;
}
.tc-stun {
  display: none;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 2px 7px;
  border-radius: 6px;
  font: 800 10px/1.4 var(--font-display, sans-serif);
  letter-spacing: .14em;
  color: var(--x-ffd766);
  background: var(--x-040e1a-a90);
  border: 1px solid var(--x-ffd766);
  pointer-events: none;
}
.tc-joy.is-disabled, .tc-btn.is-disabled { filter: grayscale(1) brightness(.6); }
.tc-joy.is-disabled .tc-stun { display: block; }

/* --- Edit mode ---------------------------------------------------------- */
.tc-zones { position: absolute; inset: 0; display: none; pointer-events: none; }
.touch-layer.is-editing .tc-zones { display: grid; grid-template-columns: 1fr; }
.touch-layer.is-editing .tc-zones.is-duo { grid-template-columns: 1fr 1fr; }
.tc-zones:not(.is-duo) .tc-zone.p2 { display: none; }
.tc-zone { position: relative; margin: 4px; border: 2px dashed var(--x-4aa3ff-a50); border-radius: 16px; background: var(--x-4aa3ff-a6); }
.tc-zone.p2 { border-color: var(--x-ff6a5c-a50); background: var(--x-ff6a5c-a6); }
.tc-zone span {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  font: 800 11px var(--font-display, sans-serif);
  letter-spacing: .2em;
  color: var(--x-fff6e4-a60);
  white-space: nowrap;
}
.touch-layer.is-editing { background: var(--x-020810-a50); }
.touch-layer.is-editing .tc-joy,
.touch-layer.is-editing .tc-btn { cursor: grab; outline: 2px dashed var(--x-fff6e4-a55); outline-offset: 5px; border-radius: 50%; animation: tcWiggle 1.6s ease-in-out infinite; }
.touch-layer.is-editing .is-dragging { cursor: grabbing; outline-color: var(--gold-400); animation: none; filter: brightness(1.15); }
@keyframes tcWiggle { 0%, 100% { rotate: 0deg; } 25% { rotate: -2deg; } 75% { rotate: 2deg; } }

/* ==========================================================================
   ROTATE TO PLAY + briefing
   ========================================================================== */
.tp {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: calc(var(--sa-t) + 12px) calc(var(--sa-r) + 14px) calc(var(--sa-b) + 12px) calc(var(--sa-l) + 14px);
  background: radial-gradient(120% 90% at 50% 40%, var(--x-103054-a98), var(--x-030b16-a99));
  color: var(--cream, var(--cream));
  text-align: center;
  touch-action: manipulation;
}
.tp.hidden { display: none; }

.tp.is-help { background: var(--x-030b16-a78); }
.tp.is-under-editor { visibility: hidden; }
.tp .tp-rotate, .tp .tp-help { display: none; }
.tp.is-rotate .tp-rotate, .tp.is-help .tp-help { display: flex; flex-direction: column; align-items: center; gap: 8px; }

.tp-kicker { font: 800 11px var(--font-display, sans-serif); letter-spacing: .34em; color: var(--gold-500); }
.tp-head { font: 800 clamp(26px, 8vmin, 44px) var(--font-display, sans-serif); letter-spacing: .12em; color: var(--gold-400); text-shadow: 0 0 24px var(--x-f3c35a-a35); }
.tp-sub { font-size: 14px; color: var(--x-fff6e4-a72); }
.tp-count {
  margin-top: 8px;
  width: 68px;
  height: 68px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 2px solid var(--x-f3c35a-a60);
  font: 800 34px/1 var(--font-display, sans-serif);
  color: var(--cream);
  box-shadow: 0 0 26px var(--x-f3c35a-a25), inset 0 0 18px var(--x-f3c35a-a15);
}
.tp-count.is-beat { animation: tpBeat .6s cubic-bezier(.2, .8, .2, 1); }
@keyframes tpBeat { from { transform: scale(1.35); opacity: .2; } to { transform: none; opacity: 1; } }

.tp-phone {
  width: 58px;
  height: 100px;
  border: 4px solid var(--gold-400);
  border-radius: 14px;
  position: relative;
  margin-bottom: 16px;
  box-shadow: 0 0 26px var(--x-f3c35a-a35);
  animation: tpRotate 1.6s cubic-bezier(.6, 0, .3, 1) infinite;
}
.tp-phone-screen { position: absolute; inset: 8px 5px 13px; border-radius: 4px; background: linear-gradient(135deg, var(--x-15406c), var(--x-071a30)); overflow: hidden; }
.tp-phone-screen i { position: absolute; left: 50%; top: 50%; width: 18px; height: 18px; margin: -9px 0 0 -9px; border-radius: 50%; background: var(--gold-400); opacity: .8; }
.tp-phone::after { content: ""; position: absolute; left: 50%; bottom: 3px; width: 12px; height: 3px; margin-left: -6px; border-radius: 2px; background: var(--gold-400); }
@keyframes tpRotate {
  0%, 18% { transform: rotate(0deg); }
  55%, 88% { transform: rotate(-90deg); }
  100% { transform: rotate(-90deg); }
}

.tp-help {
  width: min(500px, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 16px 18px 12px;
  border-radius: 18px;
  border: 1px solid var(--x-f3c35a-a50);
  background: linear-gradient(180deg, var(--x-15406c-a96), var(--x-071a30-a97));
  box-shadow: 0 20px 50px var(--x-000000-a60);
}
.tp-title { font: 800 clamp(22px, 5vmin, 30px) var(--font-display, sans-serif); letter-spacing: .16em; color: var(--gold-400); text-transform: uppercase; }
.tp-lines { list-style: none; margin: 2px 0 4px; padding: 0; display: grid; gap: 5px; width: 100%; }
.tp-lines li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 12px;
  border-radius: 10px;
  background: var(--x-030b16-a45);
  font-size: 13px;
  text-align: left;
}
.tp-lines b { font-family: var(--font-display, sans-serif); letter-spacing: .12em; color: var(--cream); white-space: nowrap; }
.tp-lines span { color: var(--x-fff6e4-a75); text-align: right; }
.tp-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 4px; }
.tp-actions .btn { min-height: 44px; }
.tp-bar { width: 100%; height: 3px; margin-top: 6px; border-radius: 2px; background: var(--x-ffffff-a10); overflow: hidden; }
.tp-bar i { display: block; height: 100%; width: 0; background: var(--gold-400); }
.tp-bar i.is-running { animation: tpBar 6s linear forwards; }
@keyframes tpBar { from { width: 0; } to { width: 100%; } }

/* ==========================================================================
   CONTROLS EDITOR (lives in the control layer, above the game)
   ========================================================================== */
#modalLayer.is-under-editor { visibility: hidden; }
.te {
  position: absolute;
  z-index: 5;
  left: 50%;
  top: calc(var(--sa-t) + 8px);
  transform: translateX(-50%);
  width: min(300px, calc(100% - 24px));
  max-height: calc(100% - 16px);
  overflow-y: auto;
  border-radius: 16px;
  border: 1px solid var(--x-f3c35a-a55);
  background: linear-gradient(180deg, var(--x-15406c-a96), var(--x-071a30-a96));
  box-shadow: 0 16px 40px var(--x-000000-a60);
  color: var(--cream);
  pointer-events: auto;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}
.te.hidden { display: none; }
.te-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  font: 800 13px var(--font-display, sans-serif);
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--gold-400);
}
.te-collapse { width: 38px; height: 30px; border-radius: 8px; border: 1px solid var(--x-f3c35a-a40); background: var(--x-030b16-a50); color: var(--gold-400); font-size: 15px; }
.te.is-collapsed .te-body { display: none; }
.te.is-collapsed .te-collapse { transform: rotate(180deg); }
.te-body { padding: 0 12px 12px; display: grid; gap: 7px; }
.te-tip { margin: 0; font-size: 12px; color: var(--x-fff6e4-a70); }
.te-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.te-tabs.hidden, .te-row.hidden { display: none; }
.te-tabs button {
  min-height: 34px;
  border-radius: 9px;
  border: 1px solid var(--x-ffffff-a18);
  background: var(--x-030b16-a50);
  color: var(--cream);
  font: 800 13px var(--font-display, sans-serif);
  letter-spacing: .14em;
}
.te-tabs button[data-slot="p1"].is-on { background: var(--zima); border-color: var(--p1); }
.te-tabs button[data-slot="p2"].is-on { background: var(--x-c8473d); border-color: var(--p2); }
.te-row { display: grid; grid-template-columns: 78px 1fr; align-items: center; gap: 8px; font-size: 13px; }
.te-row input[type="range"] { width: 100%; height: 30px; accent-color: var(--gold-400); touch-action: pan-x; }
.te-actions { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.te-actions .btn { min-height: 38px; padding: 0 6px; }

/* ==========================================================================
   Roster grids (Casual character select + Tournament "Who's Playing").
   Scrolling layouts use EXPLICIT column counts - never measured, never
   auto-fit - so the same viewport always gives the same grid:
     phone portrait (< 600px wide)        3 columns, rows as needed
     tablet portrait (>= 600px wide)      4 columns
     phone landscape (<= 560px tall)      6 columns
     tablet landscape (> 560px tall)      Casual 3 (between the P1/P2
                                          panels), Who's Playing 6
   Desktop windows keep the measured fit-to-screen grid, except short
   windows (<= 560px tall), which scroll and so use the 6-column rule too.
   Every cell is the same size; a short last row keeps full-size cards.
   ========================================================================== */
@media (max-height: 560px) {
  .cs-roster, .ps-roster { --roster-cols: 6; }
}
body.is-touch .cs-roster, body.is-touch .ps-roster { --roster-cols: 6; }
@media (orientation: landscape) and (min-height: 561px) {
  body.is-touch .cs-roster { --roster-cols: 3; }
}
@media (orientation: portrait) {
  body.is-touch .cs-roster, body.is-touch .ps-roster { --roster-cols: 4; }
}
@media (orientation: portrait) and (max-width: 599px) {
  body.is-touch .cs-roster, body.is-touch .ps-roster { --roster-cols: 3; }
}

.cs-roster.is-fixed-grid, .ps-roster.is-fixed-grid {
  --roster-gap: 12px;
  --tile-max: 170px;
  width: min(100%, calc(var(--roster-cols) * var(--tile-max) + (var(--roster-cols) - 1) * var(--roster-gap)));
  grid-template-columns: repeat(var(--roster-cols), minmax(0, 1fr));
  grid-auto-rows: auto;
  gap: 14px var(--roster-gap);
  justify-content: stretch;
  justify-items: stretch;
  align-content: start;
}
.is-fixed-grid .cs-tile, .is-fixed-grid .ps-tile { min-width: 0; width: 100%; }
.is-fixed-grid .cs-tile-img, .is-fixed-grid .ps-tile-img { width: 100%; height: auto; aspect-ratio: 1 / 1; }
.is-fixed-grid .cs-tile-name, .is-fixed-grid .ps-tile-name {
  display: block;
  width: 100%;
  font-size: 12px;
  line-height: 16px;
  height: 16px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
@media (orientation: portrait) and (max-width: 599px) {
  body.is-touch .is-fixed-grid { --roster-gap: 10px; }
  body.is-touch .is-fixed-grid .cs-tile-name, body.is-touch .is-fixed-grid .ps-tile-name { letter-spacing: .1em; }
}
/* Keyboard focus ring means nothing on touch - selection shows via the check. */
body.is-touch .ps-tile.is-focus .ps-tile-img { outline: none; }
/* Fixed grids span the full width, so corner badges sit INSIDE the card
   (still overlays - they never add to the card's size or get clipped). */
.is-fixed-grid .ps-check { top: 5px; right: 5px; width: 26px; height: 26px; }
.is-fixed-grid .ps-check::after { width: 8px; height: 13px; border-width: 0 3px 3px 0; }
.is-fixed-grid .cs-cursor { top: 4px; z-index: 2; }
.is-fixed-grid .cs-cursor.p1 { left: 4px; }
.is-fixed-grid .cs-cursor.p2 { right: 4px; }
.is-fixed-grid.cs-roster { padding-top: 0; }
/* Champion actions wrap on narrow phones instead of running off-screen. */
body.is-touch .ch-actions { flex-wrap: wrap; justify-content: center; max-width: calc(100vw - 32px); }
body.is-touch .ch-actions .btn { flex: 1 1 auto; }
