:root {
  --bg: #140e1c;
  --ink: #fff7ee;
  --muted: #e4d4ef;
  --left: #ff5d3a;
  --left-deep: #9d2418;
  --right: #2ee6c7;
  --right-deep: #0c6e68;
  --gold: #ffc857;
  --gold-deep: #a87420;
  --card: #2a1b38;
  --groove: 22px;
  --remote-w: 48px;
  --remote-h: 86px;
  color-scheme: dark;
  --font: "PingFang HK", "PingFang TC", "Noto Sans HK", "Noto Sans TC", "Microsoft JhengHei", "Heiti TC", "WenQuanYi Micro Hei", "Droid Sans Fallback", sans-serif;
}

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

[hidden] { display: none !important; }

html {
  height: 100%;
  touch-action: manipulation;
  overscroll-behavior: none;
}

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(900px 420px at 50% -8%, rgba(255, 93, 58, 0.22), transparent 60%),
    radial-gradient(800px 480px at 50% 110%, rgba(46, 230, 199, 0.14), transparent 55%),
    radial-gradient(ellipse at 50% 36%, #3a2158 0%, var(--bg) 62%);
  -webkit-tap-highlight-color: transparent;
}

body.play-shell {
  height: 100vh;
  height: 100svh;
  overflow: hidden;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

button,
input { font-family: inherit; }

button {
  -webkit-appearance: none;
  appearance: none;
}

::selection { background: var(--left); color: white; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 1400px;
  margin: 0 auto;
}

.topbar {
  position: relative;
  z-index: 30;
  background: linear-gradient(180deg, rgba(20, 14, 28, 0.94), rgba(20, 14, 28, 0.78) 72%, transparent);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding:
    calc(10px + env(safe-area-inset-top))
    calc(14px + env(safe-area-inset-right))
    0
    calc(14px + env(safe-area-inset-left));
}

.brand { min-width: 0; flex: 1; }

.eyebrow {
  margin: 0 0 2px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
}

.brand h1 {
  margin: 0;
  font-size: clamp(20px, 5vw, 32px);
  line-height: 1.12;
  font-weight: 900;
}

.dot { color: var(--muted); font-weight: 700; }

body:not([data-phase="setup"]) .eyebrow,
body:not([data-phase="setup"]) .full-only { display: none; }

body:not([data-phase="setup"]) .brand h1 { font-size: clamp(16px, 4vw, 22px); }

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.icon-btn,
.lang button {
  min-width: 44px;
  min-height: 44px;
  border-radius: 14px;
  border: 1px solid rgba(255, 247, 238, 0.16);
  background: rgba(255, 247, 238, 0.06);
  color: var(--ink);
  cursor: pointer;
}

.icon-btn {
  display: grid;
  place-items: center;
  padding: 0 10px;
}

.icon-btn[aria-pressed="false"] .icon-on,
.icon-btn[aria-pressed="true"] .icon-off { display: none; }

.lang {
  display: flex;
  padding: 3px;
  gap: 2px;
  border-radius: 16px;
  background: rgba(255, 247, 238, 0.06);
  border: 1px solid rgba(255, 247, 238, 0.12);
}

.lang button {
  border: 0;
  background: transparent;
  min-width: 44px;
  border-radius: 12px;
  font-weight: 800;
  font-size: 14px;
}

.lang button[aria-pressed="true"] {
  background: var(--ink);
  color: #24141c;
}

.icon-btn:focus-visible,
.lang button:focus-visible,
.go:focus-visible,
.ghost:focus-visible,
.tap-zone:focus-visible,
input:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

.scoreboard {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 8px 14px 0;
}

.side-score {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-weight: 800;
}

.side-b { justify-content: flex-end; }

.side-a { color: #ffb09e; }
.side-b { color: #9af6ea; }

.nm {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 8em;
  font-size: 14px;
}

.pips { display: flex; gap: 5px; flex-shrink: 0; }

.pips i {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid currentColor;
  display: block;
  opacity: 0.4;
}

.pips i.on { opacity: 1; background: currentColor; }

.round {
  font-size: clamp(11px, 3.1vw, 13px);
  font-weight: 800;
  color: var(--gold);
  white-space: nowrap;
  text-align: center;
}

#stage {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.setup {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: safe center;
  padding: 12px 16px calc(18px + env(safe-area-inset-bottom));
  -webkit-overflow-scrolling: touch;
}

.setup-card {
  width: min(480px, 100%);
  background: var(--card);
  border: 1px solid rgba(255, 247, 238, 0.1);
  border-radius: 28px;
  padding: 22px 18px 14px;
  box-shadow: 0 24px 50px rgba(0, 0, 0, 0.35);
}

.preview {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-bottom: 8px;
}

.preview-side {
  width: 56px;
  height: 10px;
  border-radius: 999px;
}

.preview-side.a { background: linear-gradient(90deg, transparent, var(--left)); }
.preview-side.b { background: linear-gradient(90deg, var(--right), transparent); }

.tagline {
  margin: 0 0 14px;
  text-align: center;
  font-size: 16px;
  line-height: 1.5;
  font-weight: 700;
}

.names {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.name-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 800;
}

.name-a { color: #ffb09e; }
.name-b { color: #9af6ea; }

.name-field input {
  width: 100%;
  min-height: 52px;
  border-radius: 14px;
  border: 2px solid rgba(255, 247, 238, 0.16);
  background: #140e1c;
  color: var(--ink);
  font-size: 16px;
  font-weight: 700;
  padding: 10px 12px;
}

.name-a input { border-color: rgba(255, 93, 58, 0.7); }
.name-b input { border-color: rgba(46, 230, 199, 0.7); }

input:-webkit-autofill {
  -webkit-text-fill-color: var(--ink);
  caret-color: var(--ink);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 14px 0 8px;
  padding: 0;
  list-style: none;
}

.chips li {
  border-radius: 999px;
  padding: 5px 10px;
  background: rgba(255, 200, 87, 0.12);
  color: var(--gold);
  font-size: 12px;
  font-weight: 800;
}

.rules,
.keys,
.last,
.legal {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.rules { margin: 0 0 14px; }

.keys,
.last { margin: 10px 0 0; text-align: center; font-size: 13px; }

.last { color: var(--gold); font-weight: 800; }

.go,
.ghost {
  width: 100%;
  border: 0;
  cursor: pointer;
  font-weight: 900;
}

.go {
  min-height: 64px;
  border-radius: 18px;
  background: var(--gold);
  color: #2a1608;
  font-size: 22px;
  box-shadow: 0 6px 0 var(--gold-deep);
}

.go:active { transform: translateY(3px); box-shadow: 0 3px 0 var(--gold-deep); }

.ghost {
  min-height: 48px;
  margin-top: 8px;
  border-radius: 14px;
  background: transparent;
  color: var(--ink);
  border: 1px solid rgba(255, 247, 238, 0.28);
  font-size: 16px;
}

.legal { text-align: center; margin: 14px 0 0; }
.legal a { color: var(--ink); font-weight: 800; }

.board {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  touch-action: none;
}

.arena {
  flex-shrink: 0;
  /* Room for the remote, which is taller than the groove and hangs out of it. */
  padding: calc((var(--remote-h) - var(--groove)) / 2 + 14px) 18px 0;
}

.track-wrap {
  position: relative;
  max-width: 920px;
  margin: 0 auto;
}

.groove {
  position: relative;
  height: var(--groove);
  border-radius: 999px;
  overflow: hidden;
  background: linear-gradient(#120c12, #3a2a32);
  box-shadow: inset 0 3px 6px rgba(0, 0, 0, 0.55), 0 1px 0 rgba(255, 255, 255, 0.08);
}

.advantage {
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 50%;
  width: 0;
  border-radius: 999px;
  transition: left 80ms linear, width 80ms linear;
}

.center-tick {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 2px;
  margin-left: -1px;
  background: rgba(255, 247, 238, 0.55);
  z-index: 1;
}

.endcap {
  position: absolute;
  top: calc(var(--groove) / 2);
  width: 16px;
  height: 16px;
  border-radius: 50%;
  transform: translateY(-50%);
  z-index: 2;
}

.endcap-a { left: -2px; background: var(--left); }
.endcap-b { right: -2px; background: var(--right); }

.endcap.hot {
  box-shadow: 0 0 0 6px rgba(255, 247, 238, 0.18), 0 0 18px currentColor;
}

.remote {
  position: absolute;
  top: calc(var(--groove) / 2);
  left: 50%;
  z-index: 3;
  transform: translate(-50%, -50%);
  transition: left 80ms linear;
  pointer-events: none;
  filter: drop-shadow(0 8px 8px rgba(0, 0, 0, 0.35));
}

.remote-body {
  width: var(--remote-w);
  height: var(--remote-h);
  border-radius: 12px;
  background: linear-gradient(180deg, #fffaf3, #e4d8c6);
  box-shadow: inset 0 1px 0 #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 7px 6px 8px;
}

.remote-body.mini {
  width: 42px;
  height: 72px;
  margin: 0 auto 8px;
}

.led {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #9a9086;
}

.remote[data-lead="a"] .led { background: var(--left); box-shadow: 0 0 8px var(--left); }
.remote[data-lead="b"] .led { background: #0f9e90; box-shadow: 0 0 8px var(--right); }

.btn {
  width: 14px;
  height: 6px;
  border-radius: 2px;
  background: #2a241f;
  display: block;
}

.btn.power {
  width: 16px;
  height: 7px;
  background: var(--left);
  border-radius: 3px;
}

.cluster {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
}

.pad {
  width: 22px;
  height: 14px;
  border-radius: 4px;
  background: #2a241f;
  margin-top: auto;
}

body[data-phase="play"] .remote[data-lead="even"] .remote-body {
  animation: bob 1.4s ease-in-out infinite;
}

.remote.bump .remote-body { animation: bump 110ms ease; }

.remote.win .remote-body { animation: remote-win 560ms cubic-bezier(0.2, 1.4, 0.4, 1); }

@keyframes bob {
  50% { transform: translateY(-3px); }
}

@keyframes bump {
  50% { transform: scale(1.08, 0.92); }
}

@keyframes remote-win {
  0% { transform: scale(1) rotate(0); }
  40% { transform: scale(1.28) rotate(-12deg) translateY(-8px); }
  100% { transform: scale(1.06) rotate(0); }
}

.tug-label {
  min-height: 1.4em;
  margin: calc((var(--remote-h) - var(--groove)) / 2 + 8px) 0 0;
  text-align: center;
  font-size: 15px;
  font-weight: 800;
}

.tug-label[data-lead="a"] { color: #ffb09e; }
.tug-label[data-lead="b"] { color: #9af6ea; }
.tug-label[data-lead="even"] { color: var(--gold); }

.tug-label[data-hot="1"] { animation: pulse-label 0.45s ease-in-out infinite; }

@keyframes pulse-label {
  50% { transform: scale(1.06); }
}

.zones {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
}

.tap-zone {
  position: relative;
  overflow: hidden;
  border: 0;
  border-radius: 28px;
  color: white;
  min-height: 140px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  padding: 12px;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.2);
}

.zone-a {
  background:
    radial-gradient(80% 50% at 50% 18%, rgba(255, 255, 255, 0.18), transparent 58%),
    repeating-linear-gradient(-18deg, rgba(255, 255, 255, 0.05) 0 2px, transparent 2px 8px),
    linear-gradient(180deg, #ff5d3a, #c42712 48%, #86180f);
  box-shadow: inset 0 -10px 0 rgba(0, 0, 0, 0.18), 0 8px 0 #6e1812;
}

.zone-b {
  background:
    radial-gradient(80% 50% at 50% 18%, rgba(255, 255, 255, 0.16), transparent 58%),
    repeating-linear-gradient(18deg, rgba(255, 255, 255, 0.05) 0 2px, transparent 2px 8px),
    linear-gradient(180deg, #14b3a4, #0c6b63 48%, #064640);
  box-shadow: inset 0 -10px 0 rgba(0, 0, 0, 0.18), 0 8px 0 #084e4a;
}

.tap-zone:active {
  transform: translateY(5px);
}

.zone-a:active { box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.18), 0 3px 0 #6e1812; }
.zone-b:active { box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.18), 0 3px 0 #084e4a; }

body[data-phase="countdown"] .tap-zone { filter: brightness(0.72); }

.zone-kicker {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  opacity: 0.9;
}

.zone-name {
  max-width: 100%;
  padding: 0 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: clamp(16px, 4vw, 24px);
  font-weight: 800;
}

.zone-verb {
  font-size: clamp(56px, 14vw, 112px);
  font-weight: 900;
  line-height: 0.9;
  letter-spacing: 0.04em;
}

.key-hint { display: none; }

@media (hover: hover) and (pointer: fine) {
  .key-hint {
    display: grid;
    place-items: center;
    position: absolute;
    top: 12px;
    min-width: 28px;
    height: 28px;
    padding: 0 8px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.25);
    font-family: inherit;
    font-size: 14px;
    font-weight: 800;
  }
  .zone-a .key-hint { left: 12px; }
  .zone-b .key-hint { right: 12px; }
}

.tap-zone.hot::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.6);
  pointer-events: none;
  animation: pulse-label 0.5s ease-in-out infinite;
}

.tap-zone.winner { animation: glow 0.55s ease-in-out 3; }

@keyframes glow {
  50% { filter: brightness(1.28); }
}

.spark {
  position: absolute;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
  pointer-events: none;
  animation: spark 380ms ease-out forwards;
}

@keyframes spark {
  to { transform: scale(6); opacity: 0; }
}

#countdown {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 15;
  pointer-events: none;
  font-size: clamp(88px, 22vh, 200px);
  font-weight: 900;
  text-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

#countdown.tick { animation: count-pop 280ms ease-out; }

@keyframes count-pop {
  from { transform: scale(0.55); opacity: 0.15; }
  to { transform: scale(1); opacity: 1; }
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(8, 4, 14, 0.78);
}

#confetti {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.result-card {
  position: relative;
  z-index: 1;
  width: min(420px, 100%);
  max-height: min(90dvh, 640px);
  overflow: auto;
  background: #2c1c3c;
  border-radius: 28px;
  padding: 22px 18px 18px;
  text-align: center;
  border: 1px solid rgba(255, 247, 238, 0.12);
  animation: popin 220ms ease-out;
}

.result-card.win-a { box-shadow: inset 0 7px 0 var(--left), 0 24px 50px rgba(0, 0, 0, 0.45); }
.result-card.win-b { box-shadow: inset 0 7px 0 var(--right), 0 24px 50px rgba(0, 0, 0, 0.45); }

@keyframes popin {
  from { transform: translateY(16px) scale(0.96); }
  to { transform: none; }
}

.kicker {
  margin: 0;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
}

#resultTitle {
  margin: 6px 0 8px;
  font-size: clamp(28px, 7vw, 42px);
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.detail {
  margin: 0 0 16px;
  color: var(--muted);
  font-weight: 700;
}

.result-actions { display: flex; flex-direction: column; }

.noscript {
  position: fixed;
  inset: auto 16px 16px 16px;
  background: var(--card);
  color: var(--ink);
  padding: 14px 16px;
  border-radius: 14px;
  z-index: 30;
}

body.doc {
  min-height: 100dvh;
  overflow: auto;
  padding: 28px 16px 48px;
}

.doc-card {
  width: min(40rem, 100%);
  margin: 0 auto;
  background: var(--card);
  border-radius: 28px;
  padding: 26px 22px 18px;
  border: 1px solid rgba(255, 247, 238, 0.1);
}

.doc-card h1 {
  margin: 8px 0 10px;
  font-size: 32px;
  line-height: 1.2;
}

.doc-card h2 {
  margin: 22px 0 8px;
  font-size: 18px;
}

.doc-card p,
.doc-card li { line-height: 1.6; }

.doc-card ul { padding-left: 1.2em; }

@media (max-height: 520px) {
  :root {
    --groove: 16px;
    --remote-w: 38px;
    --remote-h: 64px;
  }

  .arena { padding-left: 12px; padding-right: 12px; }
  .tug-label { font-size: 13px; }
  .zone-verb { font-size: clamp(40px, 10vh, 72px); }
  .tap-zone { min-height: 0; border-radius: 20px; }
  .zones { gap: 8px; padding-top: 8px; }
  .scoreboard { padding-top: 4px; }
}

@media (max-width: 380px) {
  .names { grid-template-columns: 1fr; }
  .round { font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
