/* Block Brawl Chess: toy-box arcade UI.
   Chunky outlined panels, press-down buttons, rounded display type, team colours from the theme. */

:root {
  --ink: #1e2240;
  --ink-soft: #4b5179;
  --ink-faint: rgba(30, 34, 64, 0.12);
  --paper: #fffaf0;
  --paper-2: #f6eedb;
  --paper-3: #e9dcbf;
  --sun: #ffc83d;
  --go: #1fae64;
  --sky: #2f7fe8;
  --grape: #7656ee;
  --cherry: #e4474f;
  --team-w: #3b8cff;
  --team-b: #ff4b4b;
  --team-w-text: #ffffff;
  --team-b-text: #ffffff;
  --team-w-edge: #24579e;
  --team-b-edge: #9e2e2e;

  --bw: 3px;
  --drop: 5px;
  --r-xl: 26px;
  --r-lg: 20px;
  --r-md: 15px;
  --r-sm: 11px;
  --gap: 16px;
  --font: "Fredoka", "Baloo 2", "Nunito", "Varela Round", "Arial Rounded MT Bold", ui-rounded, "Segoe UI", system-ui, -apple-system, sans-serif;
  --shadow: 0 var(--drop) 0 var(--ink), 0 14px 28px rgba(16, 20, 48, 0.22);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #9fd4ff;
  font-family: var(--font);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

body { position: fixed; inset: 0; }

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  outline: none;
}

#ui {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  font-size: 16px;
}
#ui button, #ui input, #ui [role="dialog"], #ui .panel, #ui .menu-card, #ui .cinema-tap { pointer-events: auto; }

button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
kbd {
  font: 600 0.78em/1 var(--font);
  padding: 3px 6px;
  border: 2px solid currentColor;
  border-radius: 6px;
  opacity: 0.75;
}
svg { flex: none; display: block; }

:focus { outline: none; }
:focus-visible { outline: 3px solid #fff; outline-offset: 3px; box-shadow: 0 0 0 6px var(--ink) !important; }

/* ---- panels and buttons ------------------------------------------------------------- */
.panel {
  background: var(--paper);
  border: var(--bw) solid var(--ink);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
}

.btn {
  --bg: var(--paper);
  --fg: var(--ink);
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 48px;
  padding: 10px 20px;
  border: var(--bw) solid var(--ink);
  border-radius: var(--r-md);
  background: var(--bg);
  color: var(--fg);
  font-weight: 600;
  font-size: 17px;
  line-height: 1.1;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.16), inset 0 2px 0 rgba(255, 255, 255, 0.35), 0 var(--drop) 0 var(--ink);
  transform: translateY(0);
  transition: transform 90ms ease, box-shadow 90ms ease, filter 120ms ease;
  touch-action: manipulation;
}
.btn:hover { filter: brightness(1.06) saturate(1.04); }
.btn:active, .btn.pressed {
  transform: translateY(calc(var(--drop) - 1px));
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.16), inset 0 2px 0 rgba(255, 255, 255, 0.3), 0 1px 0 var(--ink);
}
.btn:disabled { cursor: default; filter: grayscale(0.85) opacity(0.5); transform: none; box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.1), 0 var(--drop) 0 rgba(30, 34, 64, 0.5); }
.btn-go { --bg: var(--go); --fg: #fff; text-shadow: 0 2px 0 rgba(20, 24, 50, 0.35); }
.btn-sky { --bg: var(--sky); --fg: #fff; text-shadow: 0 2px 0 rgba(20, 24, 50, 0.35); }
.btn-grape { --bg: var(--grape); --fg: #fff; text-shadow: 0 2px 0 rgba(20, 24, 50, 0.35); }
.btn-cherry { --bg: var(--cherry); --fg: #fff; text-shadow: 0 2px 0 rgba(20, 24, 50, 0.35); }
.btn-sun { --bg: var(--sun); --fg: var(--ink); }
.btn-paper { --bg: var(--paper); --fg: var(--ink); }
.btn-sm { min-height: 44px; padding: 8px 14px; font-size: 15px; border-radius: var(--r-sm); gap: 6px; }
.btn-wide { width: 100%; justify-content: flex-start; }
.btn-icon { width: 48px; height: 48px; padding: 0; }

.btn-big {
  width: 100%;
  justify-content: flex-start;
  gap: 14px;
  min-height: 64px;
  padding: 10px 18px 10px 12px;
  border-radius: var(--r-lg);
  text-align: left;
}
.btn-big .btn-ico {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.22);
  border: 2.5px solid rgba(30, 34, 64, 0.55);
}
.btn-sun.btn-big .btn-ico, .btn-paper.btn-big .btn-ico { background: rgba(255, 255, 255, 0.55); }
.btn-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.btn-title { font-size: 21px; font-weight: 700; letter-spacing: 0.01em; }
.btn-sub { font-size: 14px; font-weight: 500; opacity: 0.92; text-shadow: none; }

.btn-x {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
}
.btn-x:hover { background: var(--ink-faint); color: var(--ink); }

/* ---- loading screen ----------------------------------------------------------------- */
#loading {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 26px;
  background: radial-gradient(120% 90% at 50% 110%, #e9f7ff 0%, #a9dbff 45%, #4b9cf0 100%);
  transition: opacity 0.5s ease, visibility 0.5s;
}
#loading.done { opacity: 0; visibility: hidden; transition: opacity 0.35s ease 0.05s, visibility 0.4s; }
#loading.done > * { opacity: 0; transition: opacity 0.12s ease; }   /* no ghost logo over the menu */
.load-blocks { display: flex; gap: 10px; height: 64px; align-items: flex-end; }
.load-blocks i {
  width: 30px; height: 30px;
  border: var(--bw) solid var(--ink);
  border-radius: 8px;
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.18), 0 4px 0 var(--ink);
  animation: hop 1.1s cubic-bezier(.3, .7, .4, 1) infinite;
}
.load-blocks i:nth-child(1) { background: #3b8cff; }
.load-blocks i:nth-child(2) { background: #ffc83d; animation-delay: 0.12s; }
.load-blocks i:nth-child(3) { background: #ff4b4b; animation-delay: 0.24s; }
.load-blocks i:nth-child(4) { background: #1fae64; animation-delay: 0.36s; }
@keyframes hop {
  0%, 60%, 100% { transform: translateY(0) rotate(0); }
  25% { transform: translateY(-26px) rotate(-8deg); }
  40% { transform: translateY(0) scale(1.12, 0.86); }
}
.load-text { font-weight: 600; font-size: 18px; color: var(--ink); letter-spacing: 0.02em; }
#loading .logo { font-size: 15px; }

/* ---- logo --------------------------------------------------------------------------- */
.logo {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  font-size: 17px;               /* everything below scales from this */
  line-height: 1;
  font-weight: 700;
  pointer-events: none;
}
.logo-block { display: flex; gap: 0.32em; margin-left: 0.25em; }
.brick {
  position: relative;
  display: grid;
  place-items: center;
  width: 1.5em;
  height: 1.5em;
  font-size: 1.45em;
  font-style: normal;
  font-weight: 700;
  color: #fff;
  border: var(--bw) solid var(--ink);
  border-radius: 0.3em;
  box-shadow: inset 0 -0.16em 0 rgba(0, 0, 0, 0.2), inset 0 0.08em 0 rgba(255, 255, 255, 0.4), 0 0.14em 0 var(--ink);
  -webkit-text-stroke: 0.1em var(--ink);
  paint-order: stroke fill;
}
/* one stud on top of each brick: it is a toy brick, after all */
.brick::before {
  content: "";
  position: absolute;
  top: -0.3em;
  left: 50%;
  width: 0.62em;
  height: 0.3em;
  transform: translateX(-50%);
  background: inherit;
  border: var(--bw) solid var(--ink);
  border-bottom: none;
  border-radius: 0.14em 0.14em 0 0;
  box-shadow: inset 0 0.06em 0 rgba(255, 255, 255, 0.4);
}
.brick-0 { background: var(--team-w); transform: rotate(-5deg) translateY(2px); }
.brick-1 { background: var(--sun); transform: rotate(3deg) translateY(-1px); }
.brick-2 { background: var(--team-b); transform: rotate(-2deg) translateY(1px); }
.brick-3 { background: var(--go); transform: rotate(4deg); }
.brick-4 { background: var(--team-w); transform: rotate(-3deg) translateY(-2px); }
.logo-brawl {
  position: relative;
  margin-top: 0.12em;
  font-size: 5.1em;
  letter-spacing: 0.015em;
  color: var(--sun);
  -webkit-text-stroke: 0.075em var(--ink);
  paint-order: stroke fill;
  text-shadow:
    0 0.035em 0 var(--ink), 0 0.07em 0 var(--ink), 0 0.1em 0 var(--ink),
    0 0.16em 0.12em rgba(16, 20, 48, 0.3);
  transform: rotate(-3deg) skewX(-4deg);
  transform-origin: left center;
}
.logo-chess {
  display: inline-flex;
  align-items: center;
  gap: 0.55em;
  margin-top: 0.5em;
  margin-left: 0.4em;
  padding: 0.38em 0.9em 0.38em 0.7em;
  font-size: 1.25em;
  letter-spacing: 0.42em;
  color: var(--paper);
  background: var(--ink);
  border-radius: 999px;
  box-shadow: 0 0 0 0.14em var(--paper), 0 0.3em 0 rgba(16, 20, 48, 0.35);
  transform: rotate(-3deg);
}
.logo-chess span { margin-right: -0.42em; }
.logo-chess .pico { width: 1.3em; height: 1.3em; stroke: var(--paper); }

/* ---- main menu ---------------------------------------------------------------------- */
.menu {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  padding: max(24px, 4vh) max(24px, 5vw);
  background: linear-gradient(90deg, rgba(14, 22, 52, 0.38) 0%, rgba(14, 22, 52, 0.12) 38%, rgba(14, 22, 52, 0) 60%);
  animation: fade-in 0.4s ease backwards;
}
.menu-col { display: flex; flex-direction: column; gap: 22px; width: min(430px, 44vw); min-width: 340px; }
.menu-logo { padding-left: 6px; }
.menu-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  animation: pop-in 0.35s cubic-bezier(.2, 1.4, .4, 1) both;
}
.menu-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 2px; }
.menu-row .btn { padding: 10px 12px; }
.menu-foot {
  position: absolute;
  right: max(24px, 3vw);
  bottom: max(18px, 3vh);
  margin: 0;
  max-width: none;
  white-space: nowrap;
  padding: 10px 14px;
  font-size: 15px;
  font-weight: 500;
  color: #fff;
  background: rgba(16, 20, 48, 0.55);
  border-radius: 14px;
  text-align: right;
}
.menu-head { display: flex; align-items: center; gap: 12px; }
.menu-head h2 { margin: 0; font-size: 24px; font-weight: 700; }
.menu-head .btn-icon { width: 44px; height: 44px; min-height: 44px; border-radius: 13px; }
.menu-label { margin: 6px 2px -2px; font-size: 14px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-soft); }
.menu-note { margin: 0 2px; font-size: 16px; color: var(--ink-soft); line-height: 1.35; }
.btn-start { justify-content: center; margin-top: 6px; }
.btn-start .btn-title { font-size: 23px; }

.level-wrap { display: flex; flex-direction: column; gap: 8px; }
.level-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.level, .side {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 62px;
  padding: 8px 4px;
  background: var(--paper-2);
  border: var(--bw) solid var(--ink);
  border-radius: var(--r-md);
  box-shadow: 0 3px 0 var(--ink);
  cursor: pointer;
  transition: transform 90ms ease, background 120ms ease, box-shadow 90ms ease;
  touch-action: manipulation;
}
.level:hover, .side:hover { background: #fff; }
.level:active, .side:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.level[aria-checked="true"], .side[aria-checked="true"] {
  background: var(--sun);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.14), 0 3px 0 var(--ink);
}
.level-pips { display: flex; gap: 3px; }
.level-pips i { width: 7px; height: 7px; border-radius: 2px; background: rgba(30, 34, 64, 0.16); }
.level-pips i.on { background: var(--ink); }
.level-name { font-weight: 600; font-size: 15px; }
.level-blurb { margin: 0 2px; min-height: 1.3em; font-size: 15px; color: var(--ink-soft); }
.level-blurb b { color: var(--ink); font-weight: 600; }
.side-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.side { min-height: 88px; gap: 3px; }
.side-ico { display: grid; place-items: center; height: 34px; }
.side-title { font-weight: 700; font-size: 17px; }
.side-sub { font-size: 13px; color: var(--ink-soft); }

/* ---- HUD ---------------------------------------------------------------------------- */
/* Two layouts. WIDE (default, landscape with room beside the board): player cards, piece card
   and coach live in columns left and right of the board, banner and tools along the top edge.
   COMPACT (narrow or squarish windows, phones): a slim top bar, a tool dock at the bottom and a
   tips strip just above the dock. In both, ui.js reports the space the HUD takes as camera
   insets so the board is framed in what is left and is never covered. */
.hud {
  --col: clamp(212px, calc((100vw - 88vh) / 2 - 28px), 320px);
  --tips-h: 0px;
  position: absolute;
  inset: 0;
  z-index: 1;               /* own stacking context: HUD layers never rise above dialogs */
  animation: fade-in 0.35s ease backwards;
  transition: opacity 0.25s ease;
}
.is-cinematic .hud { opacity: 0; }
.is-cinematic .hud * { pointer-events: none !important; }

.hud-players {
  position: absolute;
  top: var(--gap);
  left: var(--gap);
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: var(--col);
}
.plate {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 7px 12px 7px 7px;
  border-radius: var(--r-md);
  box-shadow: 0 4px 0 var(--ink), 0 10px 20px rgba(16, 20, 48, 0.16);
  transition: transform 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
  pointer-events: auto;
}
.plate-ico {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  border: var(--bw) solid var(--ink);
  border-radius: 12px;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.18);
}
.plate-w .plate-ico { background: var(--team-w); color: var(--team-w-text); }
.plate-b .plate-ico { background: var(--team-b); color: var(--team-b-text); }
.plate-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; flex: 1; }
.plate-top { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.plate-name { font-weight: 700; font-size: 17px; white-space: nowrap; }
.plate-who { font-size: 13.5px; font-weight: 500; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.plate-bottom { display: flex; align-items: center; gap: 6px; min-height: 20px; }
.plate-caps { display: flex; flex-wrap: wrap; align-items: center; min-width: 0; }
.plate-caps .pico { width: 20px; height: 20px; margin-right: -4px; }
.caps-none { font-size: 13px; color: rgba(30, 34, 64, 0.45); white-space: nowrap; }
.plate-adv {
  font-size: 13px;
  font-weight: 700;
  padding: 1px 7px;
  margin-left: 4px;
  background: var(--ink);
  color: var(--paper);
  border-radius: 999px;
}
.plate:not(.active) { background: var(--paper-2); }
.plate:not(.active) .plate-ico { filter: saturate(0.75); }
.plate.active { background: #fff; transform: translateX(6px); }
.plate-w.active { box-shadow: inset 7px 0 0 var(--team-w), 0 4px 0 var(--ink), 0 0 0 4px var(--team-w), 0 10px 20px rgba(16, 20, 48, 0.16); }
.plate-b.active { box-shadow: inset 7px 0 0 var(--team-b), 0 4px 0 var(--ink), 0 0 0 4px var(--team-b), 0 10px 20px rgba(16, 20, 48, 0.16); }
.plate.active .plate-ico { margin-left: 4px; }

.turn-banner {
  position: absolute;
  top: var(--gap);
  left: 0;
  right: 0;
  width: max-content;
  max-width: calc(100% - 2 * var(--gap));
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 54px;
  padding: 6px 22px 6px 8px;
  border: var(--bw) solid var(--ink);
  border-radius: 999px;
  background: var(--team-w);
  color: var(--team-w-text);
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.16), 0 var(--drop) 0 var(--ink), 0 12px 24px rgba(16, 20, 48, 0.2);
  white-space: nowrap;
}
.turn-banner.flip { animation: banner-in 0.45s cubic-bezier(.2, 1.4, .4, 1) both; }
.turn-banner[data-team="b"] { background: var(--team-b); color: var(--team-b-text); }
.turn-banner.over { background: var(--paper); color: var(--ink); }
.turn-ico {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  border: 2.5px solid var(--ink);
}
.turn-body { display: flex; flex-direction: column; line-height: 1.05; }
.turn-text { font-size: 21px; font-weight: 700; }
.turn-sub { font-size: 13.5px; font-weight: 500; opacity: 0.92; }
.think-dots { display: none; gap: 4px; margin-left: 2px; }
.turn-banner.thinking .think-dots { display: inline-flex; }
.think-dots i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: dot 1s ease-in-out infinite; }
.think-dots i:nth-child(2) { animation-delay: 0.15s; }
.think-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes dot { 0%, 80%, 100% { transform: translateY(0); opacity: 0.45; } 40% { transform: translateY(-5px); opacity: 1; } }

.hud-tools {
  position: absolute;
  top: var(--gap);
  right: var(--gap);
  display: flex;
  gap: 8px;
  padding: 7px;
  border-radius: var(--r-lg);
}
.btn-tool {
  width: 50px;
  height: 50px;
  min-height: 0;
  padding: 0;
  border-radius: 14px;
  --drop: 4px;
}
.btn-tool .tool-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.btn-tool[data-tool="hint"] { --bg: var(--sun); }
.btn-tool.is-off { --bg: var(--paper-3); }
.btn-tool.busy .tool-ico { animation: spin-wobble 0.7s ease-in-out infinite; }
@keyframes spin-wobble { 0%, 100% { transform: rotate(-12deg) scale(1); } 50% { transform: rotate(12deg) scale(1.12); } }
@media (hover: hover) and (pointer: fine) {
  [data-tip]::after {
    content: attr(data-tip);
    position: absolute;
    top: calc(100% + 12px);
    left: 50%;
    transform: translate(-50%, -4px);
    padding: 6px 10px;
    font-size: 13.5px;
    font-weight: 600;
    white-space: nowrap;
    color: var(--paper);
    background: var(--ink);
    border-radius: 9px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.12s ease, transform 0.12s ease;
    text-shadow: none;
    z-index: 5;
  }
  [data-tip]:hover::after, [data-tip]:focus-visible::after { opacity: 1; transform: translate(-50%, 0); transition-delay: 0.25s; }
  .hud-tools [data-tool="pause"]::after { left: auto; right: -4px; transform: translate(0, -4px); }
  .hud-tools [data-tool="pause"]:hover::after { transform: translate(0, 0); }
}

.hud-moves {
  position: absolute;
  top: calc(var(--gap) + 82px);
  right: var(--gap);
  width: var(--col);
  border-radius: var(--r-md);
  overflow: hidden;
  box-shadow: 0 4px 0 var(--ink), 0 10px 20px rgba(16, 20, 48, 0.16);
  z-index: 2;
}
.moves-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 46px;
  padding: 6px 12px;
  border: none;
  background: transparent;
  font-weight: 600;
  font-size: 16px;
  cursor: pointer;
  text-align: left;
}
.moves-toggle:hover { background: var(--paper-2); }
.mt-title { flex: none; }
.mt-count { font-size: 13px; padding: 1px 8px; border-radius: 999px; background: var(--ink-faint); }
.mt-last { margin-left: auto; white-space: nowrap; font-size: 15px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.moves-toggle .ico-chevronUp, .moves-toggle .ico-chevronDown { margin-left: auto; }
.mt-last + .ico { margin-left: 4px; }
.moves-scroll { display: none; max-height: min(42vh, 300px); overflow-y: auto; border-top: 2px solid var(--ink-faint); scrollbar-width: thin; }
.hud-moves.open .moves-scroll { display: block; }
.moves-list { margin: 0; padding: 6px 8px 8px; list-style: none; font-variant-numeric: tabular-nums; }
.moves-list li { display: grid; grid-template-columns: 34px 1fr 1fr; gap: 4px; padding: 4px 6px; border-radius: 8px; font-size: 15px; }
.moves-list li:nth-child(even) { background: var(--paper-2); }
.moves-list li.latest { background: #fff3c9; }
.mv-n { color: var(--ink-soft); font-weight: 500; }
.mv { font-weight: 600; }
.mv-empty { display: block !important; color: var(--ink-soft); }

/* Tips (piece card + coach). Wide: each sits in a side column under the top-row panels. */
.hud-tips { display: contents; }
.piece-card {
  position: absolute;
  top: calc(var(--gap) + 146px);
  left: var(--gap);
  display: flex;
  gap: 10px;
  width: var(--col);
  padding: 10px 12px 12px 10px;
  border-radius: var(--r-lg);
}
.piece-card.pop, .coach.pop { animation: pop-in 0.3s cubic-bezier(.2, 1.4, .4, 1) both; }
.pc-ico {
  display: grid;
  place-items: center;
  flex: none;
  width: 50px;
  height: 50px;
  background: var(--paper-2);
  border: var(--bw) solid var(--ink);
  border-radius: 14px;
}
.pc-ico .pico { width: 40px; height: 40px; }
.pc-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.pc-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 8px; }
.pc-name { font-size: 19px; font-weight: 700; }
.pc-team { font-size: 12.5px; font-weight: 600; padding: 0 8px; border-radius: 999px; border: 2px solid var(--ink); }
.piece-card[data-team="w"] .pc-team { background: var(--team-w); color: var(--team-w-text); }
.piece-card[data-team="b"] .pc-team { background: var(--team-b); color: var(--team-b-text); }
.pc-how { margin: 0; font-size: 15px; line-height: 1.32; }
.pc-tip { margin: 0; display: flex; gap: 6px; font-size: 13.5px; line-height: 1.3; color: var(--ink-soft); }
.pc-tip .ico { margin-top: 1px; color: #d89a00; }

.coach {
  position: absolute;
  top: calc(var(--gap) + 82px);      /* over the move-list toggle while it is up */
  right: var(--gap);
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 10px;
  width: var(--col);
  padding: 10px 12px 12px 10px;
  border-radius: var(--r-xl);
  z-index: 3;
}
.coach[data-tone="warn"] { background: #fff1ee; }
.coach[data-tone="hint"] { background: #fffbe8; }
.coach-avatar { grid-row: 1; align-self: start; }
.coach-avatar svg { width: 42px; height: 42px; }
.coach-body { display: contents; }
.coach-title { grid-column: 2; align-self: center; padding-right: 26px; font-size: 18px; font-weight: 700; line-height: 1.15; }
.coach[data-tone="warn"] .coach-title { color: #b8262f; }
.coach-text { grid-column: 1 / -1; margin: 2px 0 0; font-size: 15px; line-height: 1.35; }
.coach-actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.coach-actions .btn { flex: 1 1 auto; min-height: 40px; padding: 6px 10px; font-size: 14.5px; gap: 4px; }
.coach .btn-x { position: absolute; top: 4px; right: 4px; }

/* ---- overlay layer: call-out, toasts, cinematic ------------------------------------- */
.overlay-layer { position: absolute; inset: 0; pointer-events: none; z-index: 5; }
.callout {
  position: absolute;
  top: 36%;
  left: 50%;
  font-size: clamp(52px, 9vw, 120px);
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--sun);
  -webkit-text-stroke: 0.08em var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 0.05em 0 var(--ink), 0 0.1em 0 var(--ink), 0 0.2em 0.2em rgba(16, 20, 48, 0.35);
  transform: translate(-50%, -50%) scale(0.3) rotate(-8deg);
  opacity: 0;
  white-space: nowrap;
}
.callout[data-team="w"] { color: var(--team-w); }
.callout[data-team="b"] { color: var(--team-b); }
.callout.show { animation: stamp 1.5s cubic-bezier(.2, 1.3, .4, 1) both; }
@keyframes stamp {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(2.2) rotate(-12deg); }
  14% { opacity: 1; transform: translate(-50%, -50%) scale(0.92) rotate(-5deg); }
  24% { transform: translate(-50%, -50%) scale(1.06) rotate(-6deg); }
  34%, 78% { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(-6deg); }
  100% { opacity: 0; transform: translate(-50%, -62%) scale(0.95) rotate(-6deg); }
}

.toasts {
  position: absolute;
  top: 88px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: max-content;
  max-width: calc(100vw - 32px);
}
.toast {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px 9px 12px;
  font-size: 15.5px;
  font-weight: 600;
  color: var(--paper);
  background: var(--ink);
  border-radius: 14px;
  box-shadow: 0 8px 18px rgba(16, 20, 48, 0.3);
  animation: toast-in 0.25s cubic-bezier(.2, 1.3, .4, 1) both;
}
.toast[data-tone="warn"] .ico { color: #ff9a8a; }
.toast[data-tone="good"] .ico { color: #6ee7a8; }
.toast .ico { color: var(--sun); }
.toast.leaving { animation: toast-out 0.22s ease both; }

.cinema { position: absolute; inset: 0; }
.cinema-tap { position: absolute; inset: 0; cursor: pointer; }
.bar {
  position: absolute;
  left: 0;
  right: 0;
  height: 11vh;
  min-height: 54px;
  background: #0b0d1c;
  transition: transform 0.32s cubic-bezier(.3, .8, .3, 1);
  pointer-events: none;
}
.bar-top { top: 0; transform: translateY(-100%); }
.bar-bottom { bottom: 0; transform: translateY(100%); display: flex; align-items: center; justify-content: flex-end; padding: 0 max(18px, 3vw) var(--safe-b); }
.cinema.in .bar { transform: translateY(0); }
.btn-skip {
  pointer-events: auto;
  min-height: 46px;
  padding: 8px 14px 8px 18px;
  --bg: rgba(255, 255, 255, 0.1);
  --fg: #fff;
  border-color: rgba(255, 255, 255, 0.75);
  box-shadow: none;
  font-size: 17px;
  opacity: 0;
  transition: opacity 0.3s ease 0.25s, background 0.15s ease;
}
.btn-skip:hover { --bg: rgba(255, 255, 255, 0.2); }
.btn-skip:active { transform: translateY(1px); box-shadow: none; }
.btn-skip kbd { margin-left: 2px; font-size: 12px; }
.cinema.in .btn-skip { opacity: 1; }

.over-bar {
  position: absolute;
  left: 0;
  right: 0;
  width: max-content;
  max-width: calc(100% - 2 * var(--gap));
  margin: 0 auto;
  bottom: calc(var(--gap) + var(--safe-b));
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 8px 8px 18px;
  font-size: 18px;
  pointer-events: auto;
  animation: pop-in 0.3s cubic-bezier(.2, 1.4, .4, 1) both;
  white-space: nowrap;
}
.over-bar strong { margin-right: 6px; }

/* ---- modals ------------------------------------------------------------------------- */
.modal-layer { position: absolute; inset: 0; pointer-events: none; z-index: 10; }
.modal {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(14, 18, 42, 0.5);
  pointer-events: auto;
  animation: fade-in 0.2s ease both;
}
.modal.no-backdrop { background: transparent; pointer-events: none; }
.modal.leaving { animation: fade-out 0.16s ease both; }
.modal-card {
  position: relative;
  width: min(440px, 100%);
  max-height: calc(100% - 8px);
  overflow-y: auto;
  padding: 24px 24px 22px;
  background: var(--paper);
  border: var(--bw) solid var(--ink);
  border-radius: var(--r-xl);
  box-shadow: 0 7px 0 var(--ink), 0 24px 50px rgba(10, 14, 40, 0.4);
  animation: pop-in 0.32s cubic-bezier(.2, 1.35, .4, 1) both;
  scrollbar-width: thin;
  -webkit-user-select: text;
  user-select: text;
  overscroll-behavior: contain;
}
.modal-tall { width: min(860px, 100%); padding: 26px 28px 24px; }
.modal-x { position: absolute; top: 12px; right: 12px; }
.modal-title { margin: 0 0 6px; font-size: 30px; font-weight: 700; text-align: center; line-height: 1.1; }
.modal-text { margin: 0 auto 16px; max-width: 34em; font-size: 16.5px; line-height: 1.4; text-align: center; color: var(--ink-soft); }
.modal-foot { margin: 14px 0 0; font-size: 14px; text-align: center; color: var(--ink-soft); }
.modal-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin-top: 20px; }
.modal-badge {
  display: grid;
  place-items: center;
  width: 60px;
  height: 60px;
  margin: -6px auto 12px;
  border: var(--bw) solid var(--ink);
  border-radius: 18px;
  background: var(--sun);
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.14), 0 4px 0 var(--ink);
  transform: rotate(-6deg);
}
.modal-badge[data-tone="warn"] { background: #ff8a7a; }

.promo-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.modal-promo { width: min(520px, 100%); }
.promo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 4px 10px;
  background: var(--paper-2);
  border: var(--bw) solid var(--ink);
  border-radius: var(--r-lg);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.08), 0 4px 0 var(--ink);
  cursor: pointer;
  transition: transform 90ms ease, background 120ms ease, box-shadow 90ms ease;
}
.promo:hover { background: #fff; transform: translateY(-2px); box-shadow: 0 6px 0 var(--ink); }
.promo:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.promo[data-piece="q"] { background: #fff3c9; }
.promo-ico { display: grid; place-items: center; height: 60px; }
.promo-name { font-weight: 700; font-size: 18px; }
.promo-sub { font-size: 12.5px; color: var(--ink-soft); text-align: center; line-height: 1.2; }

.modal-confirm .modal-actions .btn, .over .modal-actions .btn { min-width: 120px; }
.pause-list { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; }
.modal-pause { width: min(380px, 100%); }

.modal-over { width: min(480px, 100%); text-align: center; overflow: visible; }
.over-badge {
  display: grid;
  place-items: center;
  width: 84px;
  height: 84px;
  margin: -66px auto 10px;
  border: var(--bw) solid var(--ink);
  border-radius: 26px;
  background: var(--sun);
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, 0.14), 0 5px 0 var(--ink);
  transform: rotate(-6deg);
  animation: wiggle 2.4s ease-in-out 0.4s infinite;
}
.over[data-team="w"] .over-badge { background: var(--team-w); color: var(--team-w-text); }
.over[data-team="b"] .over-badge { background: var(--team-b); color: var(--team-b-text); }
.over-kicker { margin: 0; font-size: 15px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.14em; color: var(--ink-soft); }
.over-title { margin: 4px 0 8px; font-size: 40px; font-weight: 700; line-height: 1.05; }
.over[data-team="w"] .over-title { color: var(--team-w-edge); }
.over[data-team="b"] .over-title { color: var(--team-b-edge); }
.over-text { margin: 0 auto; max-width: 28em; font-size: 17px; line-height: 1.4; color: var(--ink-soft); }
.over-stats { display: flex; justify-content: center; gap: 10px; margin: 16px 0 0; }
.over-stats div { min-width: 92px; padding: 8px 10px; background: var(--paper-2); border: 2px solid var(--ink-faint); border-radius: 14px; }
.over-stats dt { font-size: 12.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-soft); }
.over-stats dd { margin: 2px 0 0; font-size: 22px; font-weight: 700; }

.section-title { margin: 22px 2px 10px; font-size: 15px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-soft); }
.howto-legend { display: flex; flex-wrap: wrap; gap: 16px; margin: -2px 2px 12px; font-size: 14px; color: var(--ink-soft); }
.howto-legend span { display: inline-flex; align-items: center; gap: 6px; }
.howto-legend i { position: relative; width: 18px; height: 18px; border-radius: 5px; background: #e9dcbf; }
.howto-pieces { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.howto-card, .rule-card {
  padding: 14px;
  background: #fff;
  border: var(--bw) solid var(--ink);
  border-radius: var(--r-lg);
  box-shadow: 0 4px 0 var(--ink);
}
.howto-card p, .rule-card p { margin: 10px 0 0; font-size: 15px; line-height: 1.38; }
.howto-card .howto-special { color: var(--ink-soft); font-size: 14px; }
.howto-card-head, .rule-head { display: flex; align-items: center; gap: 10px; }
.howto-card h3, .rule-card h3 { margin: 0; font-size: 20px; font-weight: 700; }
.diagram {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  width: 100%;
  max-width: 196px;
  aspect-ratio: 1;
  margin: 12px auto 0;
  border: var(--bw) solid var(--ink);
  border-radius: 10px;
  overflow: hidden;
}
.diagram i { position: relative; display: grid; place-items: center; }
.diagram i.l, .howto-legend i { background: #f3e6c4; }
.diagram i.d { background: #c9d9a8; }
.diagram i.me { background: var(--sun); }
.diagram i.me .pico { width: 82%; height: 82%; }
.mk-m::after, .mk-f::after, .mk-x::after { content: ""; position: absolute; inset: 0; margin: auto; border-radius: 50%; }
.mk-m::after { width: 42%; height: 42%; background: var(--go); border: 2px solid var(--ink); }
.mk-f::after { width: 42%; height: 42%; background: transparent; border: 2.5px dashed var(--go); }
.mk-x::after { width: 64%; height: 64%; background: transparent; border: 3px solid var(--cherry); }
.howto-rules { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.rule-ico {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: var(--bw) solid var(--ink);
  border-radius: 12px;
  background: var(--sun);
}
.hc-ico { display: grid; place-items: center; width: 42px; height: 42px; background: var(--paper-2); border: var(--bw) solid var(--ink); border-radius: 12px; }
.howto-keys { margin-top: 18px; padding: 14px 18px; background: var(--paper-2); border-radius: var(--r-lg); }
.howto-keys h3 { margin: 0 0 8px; font-size: 18px; }
.howto-keys ul { margin: 0; padding-left: 18px; font-size: 15px; line-height: 1.7; }
.howto-keys kbd { margin-left: 2px; }

.modal-settings { width: min(620px, 100%); }
.set-group { margin-top: 6px; }
.set-group .section-title { margin-top: 16px; }
.set-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 56px;
  padding: 8px 0;
  border-bottom: 2px solid var(--ink-faint);
}
.set-group .set-row:last-child { border-bottom: none; }
.set-label { display: flex; flex-direction: column; gap: 2px; flex: 1 1 180px; min-width: 0; }
.set-label span { font-size: 17px; font-weight: 600; }
.set-label small { font-size: 13.5px; color: var(--ink-soft); }
.seg { display: inline-flex; flex: none; padding: 3px; gap: 3px; background: var(--paper-3); border: var(--bw) solid var(--ink); border-radius: 14px; }
.seg-btn {
  min-width: 66px;
  min-height: 40px;
  padding: 6px 12px;
  border: none;
  border-radius: 10px;
  background: transparent;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
}
.seg-btn:hover { background: rgba(255, 255, 255, 0.5); }
.seg-btn[aria-checked="true"] { background: var(--paper); box-shadow: 0 0 0 2.5px var(--ink), 0 3px 0 2.5px var(--ink); }
.switch {
  position: relative;
  flex: none;
  width: 66px;
  height: 40px;
  padding: 0;
  border: var(--bw) solid var(--ink);
  border-radius: 999px;
  background: var(--paper-3);
  cursor: pointer;
  transition: background 0.15s ease;
}
.switch i {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 28px;
  height: 28px;
  border: var(--bw) solid var(--ink);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 0 var(--ink);
  transition: transform 0.18s cubic-bezier(.3, 1.4, .5, 1);
}
.switch[aria-checked="true"] { background: var(--go); }
.switch[aria-checked="true"] i { transform: translateX(26px); }
.slider-wrap { display: flex; align-items: center; gap: 10px; flex: none; }
.slider-val { width: 44px; font-size: 15px; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.slider {
  --fill: 50%;
  width: 190px;
  height: 44px;
  margin: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}
.slider::-webkit-slider-runnable-track {
  height: 14px;
  border: var(--bw) solid var(--ink);
  border-radius: 999px;
  background: linear-gradient(90deg, var(--go) var(--fill), var(--paper-3) var(--fill));
}
.slider::-moz-range-track { height: 8px; border: var(--bw) solid var(--ink); border-radius: 999px; background: var(--paper-3); }
.slider::-moz-range-progress { height: 8px; border-radius: 999px; background: var(--go); }
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 28px;
  height: 28px;
  margin-top: -10px;
  border: var(--bw) solid var(--ink);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 0 var(--ink);
}
.slider::-moz-range-thumb { width: 22px; height: 22px; border: var(--bw) solid var(--ink); border-radius: 50%; background: #fff; }
.theme-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.theme-swatch {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  background: var(--paper-2);
  border: var(--bw) solid var(--ink);
  border-radius: var(--r-md);
  box-shadow: 0 3px 0 var(--ink);
  cursor: pointer;
}
.theme-swatch[aria-checked="true"] { background: var(--sun); }
.sw-art {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 10px;
  height: 58px;
  padding-bottom: 8px;
  border: 2.5px solid var(--ink);
  border-radius: 10px;
  background: linear-gradient(var(--sky), var(--hor));
}
.sw-art i { width: 20px; height: 28px; border: 2.5px solid var(--ink); border-radius: 6px 6px 3px 3px; box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.2); }
.sw-art .sw-w { background: var(--tw); }
.sw-art .sw-b { background: var(--tb); }
.sw-name { font-weight: 600; font-size: 15px; }

/* ---- boot error --------------------------------------------------------------------- */
.boot-error {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 20px;
  background: radial-gradient(120% 90% at 50% 110%, #e9f7ff 0%, #a9dbff 45%, #4b9cf0 100%);
  -webkit-user-select: text;
  user-select: text;
}
.boot-card { width: min(520px, 100%); padding: 26px 28px 24px; text-align: center; }
.boot-card h1 { margin: 6px 0 10px; font-size: 28px; line-height: 1.15; }
.boot-text { margin: 0 0 16px; font-size: 16.5px; line-height: 1.45; color: var(--ink-soft); }
.boot-card details { margin: 0 0 18px; text-align: left; font-size: 14px; color: var(--ink-soft); }
.boot-card code { display: block; margin-top: 6px; padding: 10px; background: var(--paper-2); border-radius: 10px; font-size: 13px; word-break: break-word; }
.boot-art { display: flex; justify-content: center; align-items: flex-end; gap: 6px; height: 56px; }
.boot-art i { width: 24px; height: 24px; border: var(--bw) solid var(--ink); border-radius: 6px; box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.18); }
.boot-art i:nth-child(1) { background: #3b8cff; transform: rotate(-18deg) translateY(2px); }
.boot-art i:nth-child(2) { background: #ffc83d; transform: rotate(10deg) translateY(-10px); }
.boot-art i:nth-child(3) { background: #ff4b4b; transform: rotate(-6deg); }
.boot-art i:nth-child(4) { background: #1fae64; transform: rotate(24deg) translateY(4px); }
.boot-art i:nth-child(5) { background: #7656ee; transform: rotate(-30deg) translateY(-4px); }

/* ---- motion ------------------------------------------------------------------------- */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-out { from { opacity: 1; } to { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(10px) scale(0.94); } to { opacity: 1; transform: none; } }
@keyframes banner-in { 0% { transform: scale(0.82) rotate(-3deg); } 55% { transform: scale(1.1) rotate(1.5deg); } 100% { transform: none; } }
@keyframes toast-in { from { opacity: 0; transform: translateY(-10px) scale(0.9); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-8px); } }
@keyframes wiggle { 0%, 100% { transform: rotate(-6deg); } 50% { transform: rotate(4deg) scale(1.04); } }

/* ---- big screens -------------------------------------------------------------------- */
@media (min-width: 1500px) and (min-height: 820px) {
  #ui { font-size: 18px; }
  .logo { font-size: 21px; }
  .menu-col { width: 470px; }
  .btn-tool { width: 56px; height: 56px; }
}

/* ---- short desktop windows ---------------------------------------------------------- */
@media (max-height: 620px) and (min-width: 701px) {
  .menu { padding-top: 18px; padding-bottom: 18px; }
  .logo { font-size: 11.5px; }
  .menu-col { gap: 12px; }
  .menu.sub .menu-logo { display: none; }
  .btn-big { min-height: 52px; padding-top: 6px; padding-bottom: 6px; }
  .btn-big .btn-ico { width: 38px; height: 38px; }
  .btn-title { font-size: 19px; }
  .btn-sub { font-size: 13px; }
  .menu-card { gap: 9px; padding: 12px; }
  .menu-row .btn { min-height: 46px; }
  .piece-card .pc-tip { display: none; }
}

/* ---- phones and narrow windows ------------------------------------------------------ */
@media (max-width: 700px) {
  :root { --gap: 10px; --drop: 4px; }
  .menu {
    flex-direction: column;
    align-items: stretch;
    justify-content: space-between;
    padding: calc(14px + var(--safe-t)) 12px calc(12px + var(--safe-b));
    background: linear-gradient(180deg, rgba(14, 22, 52, 0.25) 0%, rgba(14, 22, 52, 0) 30%, rgba(14, 22, 52, 0) 50%, rgba(14, 22, 52, 0.4) 100%);
  }
  .menu-col { display: contents; }
  .menu-logo { align-self: center; padding: 0; }
  .logo { font-size: 12.5px; align-items: center; }
  .logo-block { margin-left: 0; }
  .logo-brawl { transform-origin: center; }
  .logo-chess { margin-left: 0; }
  .menu-card { margin-top: auto; padding: 12px; gap: 10px; }
  .menu.sub .menu-logo { display: none; }
  .menu-foot { display: none; }
  .btn-big { min-height: 58px; }
  .btn-title { font-size: 19px; }
  .btn-sub { font-size: 13px; }
  .level-name { font-size: 13px; }
  .side { min-height: 80px; }
  .side-title { font-size: 15px; }

  .over .modal-actions .btn { min-width: 0; flex: 1 1 0; }
  .over .modal-actions [data-primary] { order: -1; flex-basis: 100%; }

  .modal { padding: 10px; align-items: end; }
  .modal-card { padding: 20px 16px 18px; border-radius: 24px; max-height: calc(100% - 20px); }
  .modal-tall { padding: 20px 14px 18px; }
  .modal-over { align-self: center; }
  .modal-title { font-size: 26px; }
  .promo-grid { grid-template-columns: repeat(2, 1fr); }
  .howto-pieces { grid-template-columns: 1fr 1fr; gap: 10px; }
  .howto-card { padding: 10px; }
  .howto-card h3 { font-size: 17px; }
  .howto-card p { font-size: 14px; }
  .howto-rules { grid-template-columns: 1fr; gap: 10px; }
  .set-row { flex-wrap: wrap; gap: 8px; }
  .set-row .slider-wrap { width: 100%; }
  .slider { flex: 1; width: auto; }
  .theme-grid { gap: 8px; }
  .sw-name { font-size: 13px; }
  .over-title { font-size: 34px; }
  .over-stats div { min-width: 80px; }
}

@media (max-width: 380px) {
  .howto-pieces { grid-template-columns: 1fr; }
}

/* ---- compact HUD: phones, tablets and squarish windows ------------------------------ */
/* Chosen by space, not device: when the strips beside the board are narrower than a card
   (width - 0.88 * height < ~420 px, roughly aspect < 1.4) or the window is under 760 px wide.
   Must match COMPACT_QUERY in src/ui/ui.js. */
@media (max-width: 759px), (max-aspect-ratio: 7/5) {
  .hud {
    --tips-h: 102px;
    --dock-w: min(100%, 470px);
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    grid-template-rows: auto auto 1fr auto auto;
    grid-template-areas: "pw banner pb" ". . ." ". . ." "tips tips tips" "tools tools tools";
    column-gap: 8px;
    padding-top: calc(var(--gap) + var(--safe-t));
  }
  .hud-players { display: contents; }
  .plate { padding: 4px 10px 4px 4px; gap: 8px; align-self: center; min-height: 48px; }
  .plate-w { grid-area: pw; margin-left: var(--gap); }
  .plate-b { grid-area: pb; margin-right: var(--gap); flex-direction: row-reverse; padding: 4px 4px 4px 10px; text-align: right; }
  .plate-b .plate-body { align-items: flex-end; }
  .plate-b .plate-top { flex-direction: row-reverse; }
  .plate-b .plate-bottom { flex-direction: row-reverse; }
  .plate-ico { width: 34px; height: 34px; border-radius: 10px; }
  .plate-name { font-size: 15px; }
  .plate-who { font-size: 12.5px; }
  .plate-body { gap: 1px; }
  .plate-bottom { min-height: 16px; }
  .plate-caps .pico { width: 16px; height: 16px; margin-right: -3px; }
  .caps-none { font-size: 12px; }
  .plate.active { transform: none; }
  .plate.active .plate-ico { margin-left: 3px; }
  .plate-b.active .plate-ico { margin-left: 0; margin-right: 3px; }
  .plate-b.active { box-shadow: inset -7px 0 0 var(--team-b), 0 4px 0 var(--ink), 0 0 0 4px var(--team-b), 0 10px 20px rgba(16, 20, 48, 0.16); }

  .turn-banner { position: relative; top: auto; grid-area: banner; align-self: center; max-width: none; margin: 0; min-height: 48px; padding: 4px 18px 4px 6px; }
  .turn-ico { width: 32px; height: 32px; }
  .turn-text { font-size: 18px; }
  .turn-sub { font-size: 12px; }

  .hud-moves {
    top: calc(var(--gap) + var(--safe-t) + 60px);
    width: auto;
    max-width: calc(100% - 2 * var(--gap));
  }
  .hud-moves.open { width: min(320px, calc(100% - 2 * var(--gap))); }
  .moves-toggle { min-height: 44px; padding: 4px 10px; font-size: 14px; }
  .moves-toggle .mt-title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .hud-moves.open .mt-title { position: static; width: auto; height: auto; clip: auto; }
  .moves-scroll { max-height: 40vh; }

  /* Tips strip: a reserved band just above the dock (the camera keeps the board out of it). */
  .hud-tips {
    grid-area: tips;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    width: var(--dock-w);
    height: var(--tips-h);
    margin: 0 auto 6px;
    pointer-events: none;
  }
  .hud-tips:has(.coach:not([hidden])) .piece-card { display: none; }
  .piece-card, .coach { position: relative; top: auto; left: auto; right: auto; width: 100%; }
  .piece-card { align-items: center; padding: 6px 12px 6px 6px; border-radius: var(--r-md); }
  .pc-ico { width: 42px; height: 42px; border-radius: 11px; }
  .pc-ico .pico { width: 34px; height: 34px; }
  .pc-head { flex-wrap: nowrap; }
  .pc-name { font-size: 16px; }
  .pc-team { display: none; }
  .pc-how { font-size: 14px; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .pc-tip { display: none; }
  .coach {
    grid-template-columns: auto 1fr auto;
    grid-template-rows: auto 1fr;
    align-items: center;
    gap: 2px 10px;
    max-height: var(--tips-h);
    padding: 6px 10px 6px 6px;
    border-radius: var(--r-md);
  }
  .coach-avatar { grid-row: 1 / 3; align-self: center; }
  .coach-avatar svg { width: 38px; height: 38px; }
  .coach-title { grid-column: 2; grid-row: 1; font-size: 15.5px; padding-right: 0; }
  .coach-text { grid-column: 2; grid-row: 2; margin: 0; font-size: 13.5px; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; align-self: start; }
  .coach-actions { grid-column: 3; grid-row: 1 / 3; flex-direction: column; flex-wrap: nowrap; margin: 0; gap: 6px; }
  .coach-actions .btn { min-height: 44px; padding: 4px 12px; font-size: 14px; }
  .coach .btn-x { position: static; grid-column: 3; grid-row: 1 / 3; width: 40px; height: 40px; }
  .coach:has(.coach-actions:not([hidden])) .btn-x { display: none; }

  .hud-tools {
    position: relative;
    top: auto;
    right: auto;
    grid-area: tools;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
    width: var(--dock-w);
    margin: 0 auto;
    padding: 8px 8px calc(8px + var(--safe-b));
    border-radius: 22px 22px 0 0;
    border-bottom: none;
    box-shadow: 0 -8px 24px rgba(16, 20, 48, 0.18);
  }
  .btn-tool { width: auto; height: 56px; flex-direction: column; gap: 2px; border-radius: 14px; }
  .btn-tool .tool-label { position: static; width: auto; height: auto; clip: auto; font-size: 12.5px; font-weight: 600; }
  .btn-tool .ico { width: 24px; height: 24px; }
  [data-tip]::after { display: none; }

  .toasts { top: calc(118px + var(--safe-t)); }
  .callout { top: 42%; }
  .bar { height: 12vh; min-height: 60px; }
  .over-bar { bottom: calc(12px + var(--safe-b)); }
}

/* phones: two rows on top (plates, then banner + moves), a taller tips strip */
@media (max-width: 559px) {
  .hud {
    --tips-h: 126px;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: auto auto 1fr auto auto;
    grid-template-areas: "pw pb" "banner banner" ". ." "tips tips" "tools tools";
    row-gap: 8px;
  }
  .plate-w { margin-left: var(--gap); }
  .plate-b { margin-right: var(--gap); }
  .turn-banner { justify-self: center; }
  .hud-moves { top: calc(var(--gap) + var(--safe-t) + 60px); }
  .hud-moves:not(.open) { width: auto; }
  .hud-moves:not(.open) .mt-last { display: none; }
  .hud-tips { width: calc(100% - 2 * var(--gap)); }
  .hud-tools { width: 100%; border-left: none; border-right: none; border-radius: 22px 22px 0 0; }
  .coach { grid-template-columns: auto 1fr; grid-template-rows: auto auto auto; }
  .coach-avatar { grid-row: 1 / 3; }
  .coach { max-height: none; }
  .coach-text { -webkit-line-clamp: 2; }
  .plate-who { display: none; }      /* the banner says You / Computer for whoever is to move */
  .coach-actions { grid-column: 1 / -1; grid-row: 3; flex-direction: row; }
  .coach-actions .btn { min-height: 44px; flex: 1; }
  .toasts { top: calc(128px + var(--safe-t)); }
}

/* ---- online play ------------------------------------------------------------------------ */
.btn-teal { --bg: #0f9d9a; --fg: #fff; text-shadow: 0 2px 0 rgba(20, 24, 50, 0.35); }
.menu-row-3 { grid-template-columns: repeat(3, 1fr); gap: 10px; }
.btn-stack { flex-direction: column; gap: 3px; min-height: 58px; padding: 6px 6px; font-size: 14.5px; line-height: 1.1; }
.btn.is-busy { cursor: progress; }
input, textarea { -webkit-user-select: text; user-select: text; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field-label { font-size: 14px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-soft); }
.field-help { font-size: 13px; color: var(--ink-soft); }
.text-input {
  width: 100%;
  min-height: 48px;
  padding: 8px 14px;
  font: 600 18px/1.2 var(--font);
  color: var(--ink);
  background: #fff;
  border: var(--bw) solid var(--ink);
  border-radius: var(--r-md);
  box-shadow: inset 0 3px 0 rgba(30, 34, 64, 0.08);
}
.text-input::placeholder { color: rgba(30, 34, 64, 0.35); }
.text-input:focus-visible { outline: 3px solid var(--sun); outline-offset: 2px; box-shadow: none !important; }
.code-input { font-size: 30px; letter-spacing: 0.32em; text-align: center; text-transform: uppercase; padding-left: 0.32em; }
.menu-error {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.3;
  color: #8f1d25;
  background: #ffe9e6;
  border: 2.5px solid #e4474f;
  border-radius: var(--r-md);
}
.menu-error .ico { flex: none; color: #e4474f; }
.menu-error .btn { margin-left: auto; flex: none; }
.code-bricks { display: flex; justify-content: center; gap: 12px; padding: 10px 0 4px; font-size: 22px; }
.code-bricks .brick { width: 1.7em; height: 1.7em; font-size: 1.6em; }
.code-bricks .brick:nth-child(odd) { transform: rotate(-4deg); }
.code-bricks .brick:nth-child(even) { transform: rotate(3deg) translateY(-2px); }
.lobby-link { margin: 0; text-align: center; font-size: 17px; font-weight: 600; color: var(--ink-soft); word-break: break-all; -webkit-user-select: text; user-select: text; }
.lobby-meta { margin: 0; text-align: center; font-size: 14px; color: var(--ink-soft); }
.waiting { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 8px; font-size: 17px; font-weight: 600; }
.wait-blocks { display: inline-flex; gap: 5px; align-items: flex-end; height: 26px; }
.wait-blocks i { width: 14px; height: 14px; border: 2.5px solid var(--ink); border-radius: 4px; background: var(--team-w); animation: hop 1.1s cubic-bezier(.3, .7, .4, 1) infinite; }
.wait-blocks i:nth-child(2) { background: var(--sun); animation-delay: 0.15s; }
.wait-blocks i:nth-child(3) { background: var(--team-b); animation-delay: 0.3s; }
.menu-switch { border-bottom: none; padding: 2px 2px; min-height: 0; }
.net-dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: #9aa0b8; border: 2px solid var(--ink); align-self: center; }
.net-dot.on { background: #2fd27a; box-shadow: 0 0 0 3px rgba(47, 210, 122, 0.25); }
.net-banners { position: absolute; left: 0; right: 0; top: calc(var(--gap) + 76px); display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; z-index: 3; }
.net-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: min(520px, calc(100% - 24px));
  padding: 8px 16px 8px 12px;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  background: #fff4cc;
  border: var(--bw) solid var(--ink);
  border-radius: 14px;
  box-shadow: 0 4px 0 var(--ink);
  animation: toast-in 0.25s cubic-bezier(.2, 1.3, .4, 1) both;
}
.net-banner.net-self { background: #ffe1dc; }
.net-spin { flex: none; width: 16px; height: 16px; border: 3px solid rgba(30, 34, 64, 0.25); border-top-color: var(--ink); border-radius: 50%; animation: spin 0.9s linear infinite; }
.net-opponent .net-spin { animation: none; border-color: #e4474f; background: #ffb3ab; }
@keyframes spin { to { transform: rotate(360deg); } }
.emote-layer { position: absolute; inset: 0; pointer-events: none; z-index: 4; }
.emote-bubble {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 230px;
  padding: 8px 14px 8px 10px;
  font-size: 17px;
  font-weight: 700;
  background: #fff;
  border: var(--bw) solid var(--ink);
  border-radius: 18px;
  box-shadow: 0 4px 0 var(--ink), 0 10px 20px rgba(16, 20, 48, 0.2);
  animation: pop-in 0.3s cubic-bezier(.2, 1.4, .4, 1) both;
}
.emote-bubble::before { content: ""; position: absolute; left: 20px; top: -11px; width: 16px; height: 16px; background: #fff; border-left: var(--bw) solid var(--ink); border-top: var(--bw) solid var(--ink); transform: rotate(45deg); }
.emote-bubble[data-team="w"] { border-color: var(--team-w-edge); }
.emote-bubble[data-team="b"] { border-color: var(--team-b-edge); }
.emote-bubble.leaving { animation: toast-out 0.25s ease both; }
.emote-icon { font-size: 24px; line-height: 1; }
.emote-pop { position: absolute; z-index: 6; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; width: 290px; padding: 8px; pointer-events: auto; animation: pop-in 0.2s ease both; }
.emote-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 6px 10px;
  font: 600 15px/1.1 var(--font);
  color: var(--ink);
  background: var(--paper-2);
  border: 2.5px solid var(--ink);
  border-radius: 12px;
  cursor: pointer;
  text-align: left;
}
.emote-btn:hover, .emote-btn:focus-visible { background: var(--sun); }
.over-rematch { margin: 14px 0 0; font-size: 17px; font-weight: 700; color: var(--grape); }
.btn.pulse { animation: ring 1.3s ease-in-out infinite; }   /* no transform: a moving button is hard to tap */
@keyframes ring { 0%, 100% { outline: 0 solid transparent; } 50% { outline: 5px solid var(--sun); outline-offset: 3px; } }
@media (max-width: 759px), (max-aspect-ratio: 7/5) {
  .net-banners { top: calc(var(--gap) + var(--safe-t) + 112px); }
}
@media (max-width: 559px) {
  .code-bricks { font-size: 18px; }
  .menu-row-3 .btn-stack span { font-size: 13px; }
}

/* wide layout: connection banners sit between the side columns, never over the player cards */
@media not ((max-width: 759px) or (max-aspect-ratio: 7/5)) {
  .net-banners { --side: clamp(212px, calc((100vw - 88vh) / 2 - 28px), 320px); left: calc(var(--side) + 2 * var(--gap)); right: calc(var(--side) + 2 * var(--gap)); }
}
/* short windows: the main menu has five rows now; drop the button subtitles so it fits */
@media (max-height: 620px) and (min-width: 701px) {
  .menu-card[data-view="main"] .btn-big .btn-sub { display: none; }
  .menu-card[data-view="main"] .btn-big { min-height: 50px; }
}
/* ---- reduced motion ----------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .callout.show { animation: none; opacity: 1; transform: translate(-50%, -50%) rotate(-6deg); }
  .load-blocks i { animation: none; }
}
