:root {
  --bg: #0d1220;
  --bg2: #131a2c;
  --card: #171f33;
  --line: #2a3550;
  --text: #e8ecf5;
  --muted: #8b95ad;
  --accent: #ff8a3d;
  --accent-dim: #c96a2c;
  --red: #e5484d;
  --blue: #4c8dff;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  /* Generated night-court art sits under a dark wash so UI text stays readable. */
  background:
    linear-gradient(rgba(13, 18, 32, 0.72), rgba(13, 18, 32, 0.82)),
    url('assets/court-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; }

/* ------------------------------------------------------------- home --- */

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

.logo {
  font-size: 40px;
  letter-spacing: 10px;
  text-align: center;
  background: linear-gradient(180deg, #ffb37a, var(--accent) 60%, #e06a1f);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 12px 40px rgba(255, 138, 61, 0.25);
}

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

.mascot-row { display: flex; justify-content: center; align-items: flex-end; gap: 4px; margin-top: 6px; }
.mascot-row img { height: 58px; width: auto; }
.mascot-row img:nth-child(even) { height: 50px; }

.over-mascot { height: 110px; width: auto; margin-bottom: 6px; }

.field { display: block; margin: 10px 0 4px; }
.field span { display: block; font-size: 11px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }

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

.seg { display: flex; gap: 6px; }
.seg button {
  flex: 1;
  background: #0b101c;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  padding: 9px 0;
  cursor: pointer;
}
.seg button.on { background: rgba(255, 138, 61, 0.14); border-color: var(--accent-dim); color: var(--accent); }

.hint { color: var(--muted); font-size: 12px; margin: 8px 0 2px; text-align: center; }

/* Character picker: portrait buttons + stat bars for the selection. */
.char-seg { display: flex; gap: 6px; }
.char-seg button {
  flex: 1; background: #0b101c; border: 1px solid var(--line); border-radius: 10px;
  padding: 6px 2px 2px; cursor: pointer; display: flex; flex-direction: column;
  align-items: center; gap: 2px; color: var(--muted); font-size: 10px; font-weight: 600;
}
.char-seg button img { height: 42px; width: auto; }
.char-seg button.on { background: rgba(255, 138, 61, 0.14); border-color: var(--accent-dim); color: var(--accent); }
.char-stats {
  display: grid; grid-template-columns: auto 1fr auto 1fr; gap: 4px 8px;
  margin-top: 8px; padding: 8px 10px; background: #0b101c;
  border: 1px solid var(--line); border-radius: 10px;
  font-size: 10px; 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: #232c44;
}
.char-stats .bar i.f { background: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: #202a44;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
  padding: 11px 18px;
  cursor: pointer;
  width: 100%;
  margin-top: 10px;
}
.btn:hover { filter: brightness(1.12); }
.btn.primary { background: linear-gradient(180deg, var(--accent), #e06a1f); border-color: #a3541e; color: #1b0f05; }
.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: 12px; margin: 12px 0 2px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.room-list { list-style: none; margin: 10px 0 0; padding: 0; max-height: 168px; 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: 13px; font-weight: 600; letter-spacing: 0.4px; }
.room-join { width: 84px; 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: 22px; text-align: center; color: var(--muted); font-size: 12px;
  display: flex; flex-wrap: wrap; gap: 6px 10px; justify-content: center; align-items: center;
}
.controls-note.small { margin-top: 0; }
.key {
  display: inline-block; background: #0b101c; border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 6px; padding: 2px 7px; font-size: 11px; font-weight: 700; color: var(--text);
}

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

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

.teams { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.team-name { font-size: 13px; letter-spacing: 3px; margin-bottom: 8px; }
.team-name.red { color: var(--red); }
.team-name.blue { color: var(--blue); }

.seat-list { list-style: none; min-height: 60px; }
.seat-list li {
  background: #0b101c; border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 10px; margin-bottom: 6px; font-size: 14px;
  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: 10px; 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; }

.room-actions { display: flex; gap: 8px; }
.room-actions .btn { margin-top: 14px; }

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

/* The court owns the whole viewport; scoreboard and controls float on top. */
#screen-game { padding: 0; }

.hud {
  position: fixed; top: 8px; left: 50%; transform: translateX(-50%); z-index: 10;
  background: rgba(13, 18, 32, 0.6); backdrop-filter: blur(6px);
  border: 1px solid var(--line); border-radius: 14px; padding: 6px 22px 8px;
}
.hud-score {
  display: flex; align-items: baseline; justify-content: center; gap: 16px;
  font-weight: 800;
}
.hud-team { font-size: 14px; letter-spacing: 2px; }
.hud-team.red { color: var(--red); }
.hud-team.blue { color: var(--blue); }
.hud-pts { font-size: 30px; min-width: 44px; text-align: center; }
.hud-clock { font-size: 20px; color: var(--muted); min-width: 70px; text-align: center; font-variant-numeric: tabular-nums; }
.hud-sub { display: flex; justify-content: center; gap: 14px; align-items: center; min-height: 22px; }
.shotclock { font-size: 14px; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.shotclock.low { color: var(--red); }
.flag {
  font-size: 11px; font-weight: 800; letter-spacing: 2px; color: #1b0f05;
  background: var(--accent); border-radius: 6px; padding: 2px 8px;
}

.court-wrap { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; }
#court { border-radius: 12px; box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5); max-width: 100%; max-height: 100%; }

.hud-bottom {
  position: fixed; bottom: 10px; left: 50%; transform: translateX(-50%); z-index: 10;
  display: flex; align-items: center; gap: 18px; justify-content: center; flex-wrap: wrap;
  background: rgba(13, 18, 32, 0.6); backdrop-filter: blur(6px);
  border: 1px solid var(--line); border-radius: 14px; padding: 8px 16px;
  max-width: calc(100vw - 24px);
}
.stamina { width: 180px; height: 10px; background: #0b101c; 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, #e5484d, #ff8a3d); }

.exit-btn {
  position: fixed; top: 10px; left: 12px; z-index: 15;
  width: auto; margin: 0; padding: 7px 13px; font-size: 13px;
  border-color: var(--line); color: var(--muted);
}
.exit-btn:hover { color: var(--text); }
.fs-btn { left: auto; right: 12px; padding: 7px 9px; }
.mute-btn { left: auto; right: 56px; padding: 7px 9px; }

.over-panel {
  position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: rgba(9, 12, 22, 0.82); backdrop-filter: blur(4px); z-index: 20;
}
.over-panel[hidden] { display: none; } /* display:flex would defeat the hidden attribute */
.over-panel h2 { font-size: 44px; letter-spacing: 6px; }
.over-score { font-size: 24px; color: var(--muted); margin: 10px 0 6px; font-weight: 700; }
.over-panel .room-actions { width: 300px; }

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

#toast {
  position: fixed; left: 50%; bottom: 88px; transform: translateX(-50%);
  background: #1d2740; 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: 34%; transform: translate(-50%, -50%);
  font-size: 46px; font-weight: 900; letter-spacing: 6px; color: var(--accent);
  text-shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
  z-index: 25; pointer-events: none;
}

@media (max-width: 640px) {
  .logo { font-size: 42px; }
  .hud-pts { font-size: 24px; }
  .over-panel h2 { font-size: 30px; }
  /* Clear the Home/mute/fullscreen buttons on narrow screens. */
  .hud { top: 52px; padding: 4px 14px 6px; }
}

.lang-btn {
  position: absolute; top: 12px; right: 12px;
  background: #0b101c; 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; } }

.board-btn { left: auto; right: 100px; padding: 7px 9px; }
.board {
  position: fixed; top: 90px; left: 50%; transform: translateX(-50%); z-index: 12;
  display: flex; gap: 24px; padding: 14px 22px;
  background: rgba(13, 18, 32, 0.88); backdrop-filter: blur(8px);
  border: 1px solid var(--line); border-radius: 14px;
}
.board-team h4 { font-size: 12px; letter-spacing: 2px; margin-bottom: 6px; }
.board-team h4.red { color: var(--red); }
.board-team h4.blue { color: var(--blue); }
.board table { border-collapse: collapse; font-size: 13px; }
.board td, .board th {
  padding: 3px 10px; text-align: right; color: var(--text);
  font-variant-numeric: tabular-nums;
}
.board th { color: var(--muted); font-size: 10px; letter-spacing: 1px; text-transform: uppercase; }
.board td:first-child, .board th:first-child { text-align: left; }
.board img { height: 20px; width: auto; vertical-align: middle; margin-right: 5px; }

.board-embed {
  position: static; transform: none; background: transparent;
  border: none; backdrop-filter: none; padding: 4px 0 0;
  /* The two team sheets side by side are wider than a phone: they scroll
     sideways inside this box, never the page (and never off its left edge,
     which a centred overflow would do). */
  max-width: calc(100vw - 32px); overflow-x: auto; overscroll-behavior-x: contain;
}
/* Full sheets that scroll, not squeezed ones: a name breaking under its face
   doubles every row. */
.board-embed .board-team { flex: none; }
.board-embed td:first-child { white-space: nowrap; }
@media (max-width: 420px) {
  .board-embed { gap: 10px; }
  .board-embed table { font-size: 12px; }
  .board-embed td, .board-embed th { padding: 3px 4px; }
  .board-embed th { letter-spacing: 0; }
  .board-embed img { height: 18px; margin-right: 3px; }
}

/* ------------------------------------------------------ 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; } /* keyboard legend is noise on a phone */

/* Landscape: slim side gutters, just wide enough for a thumb, keep both
   hands off the court. Portrait gets its own layout further down. */
:root { --tgut: min(112px, 13vw); }

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: 70dvh;
  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: 90px;
  transform: translateX(-50%);
  border: 2px solid rgba(232, 236, 245, 0.28); background: rgba(13, 18, 32, 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(232, 236, 245, 0.5); transform: translate(-50%, -50%);
}

.touch-btn {
  position: fixed; z-index: 14; border-radius: 50%;
  border: 2px solid var(--line); background: rgba(13, 18, 32, 0.55);
  color: var(--text); font-weight: 800; font-size: 12px; letter-spacing: 1px;
  touch-action: none; user-select: none; -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.touch-btn:active { filter: brightness(1.3); }
/* Stacked down the middle of the right gutter, biggest nearest the thumb. */
.touch-btn.shoot, #tb-jump, #tb-pass {
  right: calc((var(--tgut) + env(safe-area-inset-right)) / 2);
  transform: translateX(50%);
  aspect-ratio: 1;
}
.touch-btn.shoot {
  width: min(80px, calc(var(--tgut) - 16px));
  bottom: calc(20px + env(safe-area-inset-bottom));
  border-color: var(--accent-dim); color: var(--accent);
}
.touch-btn.shoot.on { background: rgba(255, 138, 61, 0.3); }
#tb-jump {
  width: min(58px, calc(var(--tgut) - 38px));
  bottom: calc(118px + env(safe-area-inset-bottom));
}
#tb-pass {
  width: min(58px, calc(var(--tgut) - 38px));
  bottom: calc(190px + env(safe-area-inset-bottom));
}

/* Portrait: side gutters would squeeze the court to a sliver. The court is
   width-bound there anyway, so give the full width back and park the
   controls in a bottom strip under the action instead. */
@media (orientation: portrait) {
  body.touch .court-wrap { left: 0; right: 0; bottom: 190px; }
  body.touch .hud-bottom { bottom: 196px; }
  #stick-zone { width: 50vw; height: 190px; }
  #stick-base { width: 104px; left: calc(84px + env(safe-area-inset-left)); bottom: 56px; }
  .touch-btn.shoot, #tb-jump, #tb-pass { transform: none; }
  .touch-btn.shoot {
    width: 80px;
    right: calc(16px + env(safe-area-inset-right));
    bottom: calc(22px + env(safe-area-inset-bottom));
  }
  #tb-jump {
    width: 58px;
    right: calc(110px + env(safe-area-inset-right));
    bottom: calc(90px + env(safe-area-inset-bottom));
  }
  #tb-pass {
    width: 58px;
    right: calc(122px + env(safe-area-inset-right));
    bottom: calc(14px + env(safe-area-inset-bottom));
  }
}

/* Keep the stamina pill clear of the thumb clusters on phones. */
body.touch .hud-bottom { padding: 6px 10px; }
@media (max-width: 760px) {
  body.touch .stamina { width: 110px; }
}

/* ------------------------------------- 2026-10 network / a11y pass --- */

/* Keyboard focus is visible on every control (UI std §5.7). */
button:focus-visible, select:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
/* In-game icon buttons: 44px touch targets (UI std §5.6), re-spaced. */
.exit-btn { min-height: 44px; }
.fs-btn, .mute-btn, .board-btn { min-width: 44px; justify-content: center; }
/* ...and kept clear of the park dock in the same corner (its live width). */
.fs-btn { right: calc(18px + var(--park-dock-w, 0px)); }
.mute-btn { right: calc(68px + var(--park-dock-w, 0px)); }
.board-btn { right: calc(118px + var(--park-dock-w, 0px)); }
@media (max-width: 640px) { .hud { top: 60px; } }
/* Language picker is a select now. */
select.lang-btn { font-family: inherit; appearance: auto; }
/* Room invite panel (shared share.js), in this game's dark skin. */
#room-share { margin: -6px 0 14px; --pshare-bg: #0b101c; --pshare-fg: var(--text); --pshare-accent: var(--accent); --pshare-btn: #202a44; }
/* Ping light: bottom-left is the joystick on touch screens, so it moves
   under the Home button there. */
body.touch .pcs-rtt { bottom: auto; top: calc(132px + env(safe-area-inset-top)); left: 12px; }
#room-share .pshare-head { display: none; }   /* the room code is already the card's headline */
