:root {
  --bg: #0a0f1c;
  --bg2: #121a2c;
  --card: #161f34;
  --line: #283350;
  --text: #e9edf6;
  --muted: #8a94ac;
  --accent: #ffe07a;      /* tennis-ball yellow: the game's one bright note */
  --accent-dim: #c9ab45;
  --near: #ffd166;
  --far: #7cc4ff;
  --ok: #46c878;
  --bad: #e5484d;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }

body {
  /* Generated stadium art under a dark wash, so UI text stays readable. */
  background:
    linear-gradient(rgba(10, 15, 28, 0.74), rgba(10, 15, 28, 0.86)),
    url('assets/bg.webp?v=1') center / cover no-repeat fixed,
    var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

.screen { display: none; height: 100dvh; align-items: center; justify-content: center; flex-direction: column; }
.screen.active { display: flex; }

/* ------------------------------------------------------------- cards --- */

.card::-webkit-scrollbar { display: none; }
.card {
  position: relative;
  width: min(452px, calc(100vw - 28px));
  max-height: calc(100dvh - 20px);
  overflow-y: auto;
  scrollbar-width: none;
  background: linear-gradient(180deg, var(--card), var(--bg2));
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px 22px 16px;
}

.logo {
  font-size: 32px;
  font-weight: 900;
  letter-spacing: 4px;
  text-align: center;
  line-height: 0.98;
  background: linear-gradient(180deg, #fff6c8, var(--accent) 55%, #d3a52c);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 12px 40px rgba(255, 224, 122, 0.22);
}
.logo span { display: block; font-size: 20px; letter-spacing: 11px; }

.tagline { text-align: center; color: var(--muted); font-size: 11.5px; margin: 5px 0 6px; }

.field { display: block; margin: 9px 0 4px; }
.field span {
  display: block; font-size: 10.5px; letter-spacing: 1.6px;
  text-transform: uppercase; color: var(--muted); margin-bottom: 5px;
}

input {
  width: 100%;
  background: #0a0f1b;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  font-size: 16px;
  padding: 8px 12px;
  outline: none;
}
input:focus { border-color: var(--accent-dim); }

.seg { display: flex; gap: 6px; }
.seg button {
  flex: 1;
  background: #0a0f1b;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 600;
  padding: 7px 0;
  cursor: pointer;
}
.seg button.on { background: rgba(255, 224, 122, 0.13); border-color: var(--accent-dim); color: var(--accent); }

/* The surface picker carries its own colour, so the choice reads instantly. */
.surf-seg button::before {
  content: ""; display: inline-block; width: 9px; height: 9px;
  border-radius: 3px; margin-right: 7px; vertical-align: -1px;
}
.surf-hard::before { background: #2f6ba8; }
.surf-clay::before { background: #c4694a; }
.surf-grass::before { background: #4c8f4d; }
.surf-seg button.surf-hard.on { background: rgba(47, 107, 168, 0.24); border-color: #3f7fc0; color: #bcd9f7; }
.surf-seg button.surf-clay.on { background: rgba(196, 105, 74, 0.24); border-color: #c4694a; color: #f2c5b0; }
.surf-seg button.surf-grass.on { background: rgba(76, 143, 77, 0.24); border-color: #5aa85b; color: #c2e8c2; }

.hint { color: var(--muted); font-size: 11.5px; margin: 7px 0 2px; text-align: center; }
.two-up { display: grid; grid-template-columns: 3fr 2fr; gap: 10px; }

/* Character picker: portraits plus stat bars for the current pick. */
.char-seg { display: flex; gap: 6px; }
.char-seg button {
  flex: 1; background: #0a0f1b; border: 1px solid var(--line); border-radius: 10px;
  padding: 5px 2px 3px; cursor: pointer; display: flex; flex-direction: column;
  align-items: center; gap: 2px; color: var(--muted); font-size: 9.5px; font-weight: 700;
  overflow: hidden;
}
.char-seg button img { height: 38px; width: auto; }
.char-seg button.on { background: rgba(255, 224, 122, 0.13); border-color: var(--accent-dim); color: var(--accent); }
.char-stats {
  display: grid; grid-template-columns: auto 1fr auto 1fr; gap: 3px 9px;
  margin-top: 6px; padding: 6px 10px; background: #0a0f1b;
  border: 1px solid var(--line); border-radius: 10px;
  font-size: 9.5px; letter-spacing: 1px; color: var(--muted); text-transform: uppercase;
  align-items: center;
}
.char-stats .bar { display: flex; gap: 2px; }
.char-stats .bar i { width: 12px; height: 6px; border-radius: 2px; background: #212b42; }
.char-stats .bar i.f { background: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: #1d2740;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
  padding: 10px 18px;
  cursor: pointer;
  width: 100%;
  margin-top: 9px;
}
.btn:hover { filter: brightness(1.14); }
.btn.primary {
  background: linear-gradient(180deg, var(--accent), #d9ae33);
  border-color: #a8862a; color: #241c02;
}
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.45; cursor: default; filter: none; }

.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 11.5px; margin: 10px 0 2px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.room-list { list-style: none; margin: 7px 0 0; padding: 0; max-height: 132px; overflow-y: auto; }
.room-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 6px;
}
.room-info { font-size: 12.5px; font-weight: 600; letter-spacing: 0.3px; }
.room-join { width: 82px; margin-top: 0; padding: 6px 0; font-size: 13px; }
.room-empty { color: var(--muted); font-size: 12px; text-align: center; padding: 10px 0; }

.controls-note {
  margin-top: 12px; text-align: center; color: var(--muted); font-size: 11.5px;
  display: flex; flex-wrap: wrap; gap: 6px 8px; justify-content: center; align-items: center;
}
.controls-note.small { margin-top: 0; font-size: 10.5px; gap: 4px 6px; }
.controls-note.small .key { padding: 1px 5px; font-size: 10px; }
.note-em { color: var(--accent); font-weight: 700; }
.key {
  display: inline-block; background: #0a0f1b; border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 6px; padding: 2px 7px; font-size: 11px; font-weight: 700; color: var(--text);
}
.key.wide { letter-spacing: 0.5px; }

/* -------------------------------------------------------------- room --- */

.room-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.room-label { font-size: 10px; letter-spacing: 2px; color: var(--muted); }
.room-code { font-size: 33px; font-weight: 800; letter-spacing: 8px; color: var(--accent); }
.room-meta { color: var(--muted); font-size: 12.5px; text-align: right; }

.sides { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.side-name { font-size: 12px; letter-spacing: 3px; margin-bottom: 8px; }
.side-name.near { color: var(--near); }
.side-name.far { color: var(--far); }

.seat-list { list-style: none; min-height: 52px; }
.seat-list li {
  background: #0a0f1b; border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 10px; margin-bottom: 6px; font-size: 13.5px;
  display: flex; align-items: center; gap: 7px;
}
.seat-list li.you { border-color: var(--accent-dim); }
.seat-list li .tag { margin-left: auto; font-size: 9.5px; letter-spacing: 1px; color: var(--muted); }
.seat-list li .seat-char { height: 22px; width: auto; }
.seat-list li.empty { color: var(--muted); border-style: dashed; font-size: 12px; }
.seat-list li.dc { opacity: 0.5; }

.row-actions { display: flex; gap: 8px; align-items: stretch; }
/* nowrap: "Switch end" wrapped to two lines and made its button taller than
   the two beside it. */
.row-actions .btn { margin-top: 12px; white-space: nowrap; padding: 10px 12px; font-size: 14px; }

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

#screen-game { padding: 0; }
.court-wrap { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; }
#court { max-width: 100%; max-height: 100%; }

/* Broadcast scoreboard, parked top-LEFT the way a real one is — and it has to
   be: centred, it sat directly on top of the far player, who now stands near
   the top middle of the frame. */
.board {
  position: fixed; top: 10px; left: 12px; z-index: 12;
  background: rgba(10, 15, 28, 0.72); backdrop-filter: blur(7px);
  border: 1px solid var(--line); border-radius: 12px; padding: 7px 12px 6px;
  min-width: 250px;
}
.board table { border-collapse: collapse; width: 100%; }
.board td { padding: 2px 5px; font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.b-serve { width: 14px; }
.b-serve .dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: transparent;
}
.b-serve .dot.on { background: var(--accent); box-shadow: 0 0 8px rgba(255, 224, 122, 0.8); }
.b-name { text-align: left; letter-spacing: 1px; font-size: 13px; max-width: 116px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#brow-0 .b-name { color: var(--near); }
#brow-1 .b-name { color: var(--far); }
.b-sets { color: var(--muted); font-size: 13px; letter-spacing: 2px; text-align: right; }
.b-games { text-align: center; width: 26px; }
.b-pts { text-align: center; width: 42px; color: var(--accent); }
.board-tag {
  text-align: center; font-size: 10px; letter-spacing: 2px; color: var(--muted);
  text-transform: uppercase; min-height: 13px; margin-top: 2px;
}

/* Parked bottom-LEFT, not bottom-centre: the camera now frames the near
   player at the bottom middle of the screen, and a centred bar sat straight
   on top of them. */
.hud-bottom {
  position: fixed; bottom: 10px; left: 12px; z-index: 10;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: rgba(10, 15, 28, 0.55); backdrop-filter: blur(6px);
  border: 1px solid var(--line); border-radius: 12px; padding: 6px 11px;
  max-width: calc(100vw - 24px);
}
.stamina { width: 132px; height: 9px; background: #0a0f1b; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
#stamina-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #35c26e, #9be15d); transition: width 0.15s linear; }
#stamina-fill.low { background: linear-gradient(90deg, var(--bad), #ff9c3d); }

/* One flex row, so a chip can carry a real word without being hand-placed
   around its neighbours. */
.chip-row {
  position: fixed; top: 10px; right: 12px; z-index: 15;
  display: flex; align-items: center; gap: 6px;
}
.chip-btn {
  position: static;
  width: auto; margin: 0; padding: 7px 12px; font-size: 13px;
  border-color: var(--line); color: var(--muted);
  background: rgba(10, 15, 28, 0.55); backdrop-filter: blur(6px);
  white-space: nowrap;
}
.chip-btn:hover { color: var(--text); }
.fs-btn, .mute-btn { padding: 7px 9px; }
.replay-btn { gap: 5px; font-size: 11px; letter-spacing: 1px; font-weight: 800; }
.replay-btn.on { color: var(--accent); border-color: var(--accent-dim); }
.replay-btn.off { text-decoration: line-through; opacity: 0.75; }

/* The replay badge, styled like a broadcast bug. */
/* Bottom-RIGHT is the only genuinely free corner: top-centre is where the far
   player stands, top-left is the scoreboard, top-right the chips, bottom-left
   the control pill, and bottom-centre the toast — which this badge was sitting
   underneath. It is also where a broadcast puts a replay bug. */
#replay-tag {
  position: fixed; bottom: 14px; right: 14px; z-index: 26;
  display: flex; align-items: center; gap: 7px;
  background: rgba(10, 15, 28, 0.82); backdrop-filter: blur(6px);
  border: 1px solid var(--accent-dim); border-radius: 999px;
  padding: 5px 14px 5px 11px;
  font-size: 12px; font-weight: 800; letter-spacing: 2.5px; color: var(--accent);
  pointer-events: none;
}
#replay-tag .dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--bad);
  animation: rpblink 1s steps(2, start) infinite;
}
@keyframes rpblink { 50% { opacity: 0.25; } }

/* Chevrons that chase left-to-right, so the badge reads as playback rather
   than as a label that happens to be on screen. */
#replay-tag .chevrons { display: inline-flex; align-items: center; margin-left: 1px; }
#replay-tag .chevrons svg { margin-left: -5px; animation: rpchev 1.05s linear infinite; }
#replay-tag .chevrons svg:nth-child(2) { animation-delay: 0.16s; }
#replay-tag .chevrons svg:nth-child(3) { animation-delay: 0.32s; }
@keyframes rpchev {
  0%, 60%, 100% { opacity: 0.22; }
  25% { opacity: 1; }
}

/* A replay must never be mistaken for live play, so the whole frame is
   marked, not just a corner of it. */
#replay-veil {
  position: fixed; inset: 0; z-index: 24; pointer-events: none;
  box-shadow:
    inset 0 0 0 3px rgba(255, 224, 122, 0.45),
    inset 0 0 120px rgba(0, 0, 0, 0.55);
}

.over-panel {
  position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: rgba(7, 10, 20, 0.86); backdrop-filter: blur(5px); z-index: 20;
  padding: 16px; overflow-y: auto;
}
.over-panel[hidden] { display: none; } /* display:flex would defeat the hidden attribute */
.over-panel h2 { font-size: 42px; letter-spacing: 6px; }
.over-mascot { height: 128px; width: auto; margin-bottom: 4px; }
.over-score { font-size: 20px; color: var(--muted); margin: 8px 0 10px; font-weight: 700; letter-spacing: 3px; }
.over-panel .row-actions { width: 320px; max-width: 100%; }

.stats-table { border-collapse: collapse; font-size: 13px; margin-bottom: 6px; }
.stats-table th { color: var(--muted); font-size: 9.5px; letter-spacing: 1.2px; text-transform: uppercase; padding: 3px 9px; }
.stats-table td { padding: 3px 9px; text-align: right; font-variant-numeric: tabular-nums; }
.stats-table td:first-child, .stats-table th:first-child { text-align: left; }
.stats-table img { height: 20px; width: auto; vertical-align: middle; margin-right: 5px; }

/* ---------------------------------------------------------- overlays --- */

#toast {
  position: fixed; left: 50%; bottom: 8px; transform: translateX(-50%);
  background: #1b2540; border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 9px 16px; font-size: 14px; font-weight: 600;
  z-index: 30; pointer-events: none; white-space: nowrap;
}

#banner {
  position: fixed; left: 50%; top: 32%; transform: translate(-50%, -50%);
  font-size: 44px; font-weight: 900; letter-spacing: 5px; color: var(--accent);
  text-shadow: 0 8px 30px rgba(0, 0, 0, 0.7);
  z-index: 25; pointer-events: none; text-align: center; white-space: nowrap;
}

.lang-btn {
  position: absolute; top: 12px; right: 12px;
  background: #0a0f1b; border: 1px solid var(--line); border-radius: 8px;
  color: var(--muted); font-size: 12px; font-weight: 700; padding: 4px 10px; cursor: pointer;
}
.lang-btn:hover { color: var(--accent); border-color: var(--accent-dim); }
/* 手機上卡片貼近頂端, 卡片右上角正好在園區那一排(fixed 右上角)底下。往左讓位在 360px 會壓到置中的標題,
   所以改放卡片左上角(那一角是空的)。 */
@media (max-width: 640px) { .lang-btn { right: auto; left: 12px; } }

@media (max-width: 640px) {
  .logo { font-size: 34px; }
  .over-panel h2 { font-size: 28px; }
  #banner { font-size: 30px; letter-spacing: 3px; }
  .board { min-width: 196px; padding: 5px 9px 4px; }
  .board td { font-size: 14px; }
}

/* ----------------------------------------------------- touch controls --- */

button { touch-action: manipulation; } /* no double-tap zoom on any control */

#touch-ui { display: none; }
body.touch #touch-ui { display: block; }
body.touch .controls-note { display: none; } /* a keyboard legend is noise on a phone */

:root { --tgut: min(116px, 14vw); }

body.touch .court-wrap {
  left: calc(var(--tgut) + env(safe-area-inset-left));
  right: calc(var(--tgut) + env(safe-area-inset-right));
}

#stick-zone {
  position: fixed; left: 0; bottom: 0; z-index: 14;
  width: calc(var(--tgut) + env(safe-area-inset-left)); height: 72dvh;
  touch-action: none;
}
#stick-base {
  position: fixed; border-radius: 50%;
  width: min(104px, calc(var(--tgut) - 8px)); aspect-ratio: 1;
  left: calc((var(--tgut) + env(safe-area-inset-left)) / 2); bottom: 88px;
  transform: translateX(-50%);
  border: 2px solid rgba(233, 237, 246, 0.28); background: rgba(10, 15, 28, 0.35);
  pointer-events: none;
}
#stick-base.sprint { border-color: var(--accent); }
#stick-nub {
  position: absolute; left: 50%; top: 50%; width: 46%; height: 46%; border-radius: 50%;
  background: rgba(233, 237, 246, 0.5); transform: translate(-50%, -50%);
}

.touch-btn {
  position: fixed; z-index: 14; border-radius: 50%;
  border: 2px solid var(--accent-dim); background: rgba(10, 15, 28, 0.55);
  color: var(--accent); font-weight: 800; font-size: 17px;
  touch-action: none; user-select: none; -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  right: calc((var(--tgut) + env(safe-area-inset-right)) / 2);
  transform: translateX(50%);
  aspect-ratio: 1; width: min(66px, calc(var(--tgut) - 26px));
}
.touch-btn.on { background: rgba(255, 224, 122, 0.32); }
#tb-straight { bottom: calc(96px + env(safe-area-inset-bottom)); }
#tb-left  { bottom: calc(24px + env(safe-area-inset-bottom)); right: calc(var(--tgut) + 4px + env(safe-area-inset-right)); transform: none; }
#tb-right { bottom: calc(24px + env(safe-area-inset-bottom)); }

/* Portrait: side gutters would squeeze the court to a sliver, so give the
   width back and put the controls in a strip under the action. */
@media (orientation: portrait) {
  body.touch .court-wrap { left: 0; right: 0; bottom: 176px; }
  body.touch .hud-bottom { bottom: 182px; }
  #stick-zone { width: 50vw; height: 176px; }
  #stick-base { width: 100px; left: calc(80px + env(safe-area-inset-left)); bottom: 52px; }
  .touch-btn { transform: none; width: 62px; }
  #tb-straight { right: calc(84px + env(safe-area-inset-right)); bottom: calc(96px + env(safe-area-inset-bottom)); }
  #tb-left { right: calc(150px + env(safe-area-inset-right)); bottom: calc(22px + env(safe-area-inset-bottom)); }
  #tb-right { right: calc(18px + env(safe-area-inset-right)); bottom: calc(22px + env(safe-area-inset-bottom)); }
}

body.touch .hud-bottom { padding: 6px 10px; }
@media (max-width: 760px) { body.touch .stamina { width: 108px; } }

/* ------------------------------------------- 2026-10-01 network audit --- */

/* Keyboard focus is visible everywhere; pointer focus stays quiet. */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Room screen: Leave sits top-right beside the match details. */
.room-head-right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.leave-top { margin-top: 0; padding: 6px 12px; font-size: 13px; white-space: nowrap; width: auto; }

/* The shared invite panel, in this game's colours. */
#room-share.pshare {
  --pshare-bg: #0a0f1b; --pshare-fg: var(--text); --pshare-accent: var(--accent); --pshare-btn: #1b2540;
  margin: 0 0 12px; border: 1px solid var(--line);
}

/* The latency pill (conn-status.js) defaults to bottom-left, which on a phone
   is under the movement stick. Right edge, under the chip row and the park
   dock, is empty on every viewport. `body` for specificity: conn-status.js
   injects its stylesheet after this one. */
body .pcs-rtt { left: auto; right: max(12px, env(safe-area-inset-right)); bottom: auto; top: calc(max(10px, env(safe-area-inset-top)) + 52px); }

/* Home: Quick play and a typed match code, under Create match. */
#btn-quick { width: 100%; margin-top: 8px; }
.code-join { display: flex; gap: 8px; margin-top: 8px; }
.code-join input { flex: 1; text-transform: uppercase; letter-spacing: 4px; text-align: center; }
.code-join .btn { margin-top: 0; width: auto; padding: 8px 16px; }
