/* BALL BATTLE — dark arcade shell around the four boards. */

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #0d0f16;
  --panel: rgba(18, 21, 32, 0.82);
  --line: rgba(255, 255, 255, 0.08);
  --text: #e8ecf8;
  --muted: #8b93ab;
}

html, body { height: 100%; }

body {
  background: var(--bg) url('assets/bg.webp') center / cover no-repeat fixed;
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  display: flex;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

#stage {
  width: 100%;
  max-width: 860px;
  padding: 16px 12px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

/* header ------------------------------------------------------------- */

#top {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

img#logo { height: 64px; width: auto; }
h1#logo { font-size: 28px; letter-spacing: 3px; }

#pool-panel {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
}

.pool-label {
  font-size: 11px;
  letter-spacing: 2px;
  color: var(--muted);
}

#pool-chips { display: flex; gap: 10px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
}

.chip b { display: inline-block; min-width: 2ch; }

.chip b.bump { animation: chip-bump 0.3s ease; }

@keyframes chip-bump {
  40% { transform: scale(1.4); }
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
  box-shadow: inset -2px -2px 3px rgba(0, 0, 0, 0.35),
              inset 2px 2px 3px rgba(255, 255, 255, 0.35);
}

/* boards ------------------------------------------------------------- */

#boards {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  justify-content: center;
  flex-wrap: wrap;
}

#ai-boards { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

.board {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.board.human { border-color: rgba(255, 95, 95, 0.35); }

.board.blast {
  box-shadow: 0 0 26px rgba(255, 255, 255, 0.22);
  transition: box-shadow 60ms ease-out;
}
.board.winner { border-color: rgba(255, 214, 90, 0.75); box-shadow: 0 0 24px rgba(255, 214, 90, 0.25); }
.board.out { opacity: 0.75; }

.board-head {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  letter-spacing: 1.5px;
}

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  display: inline-block;
}

.next { margin-left: auto; display: inline-flex; gap: 4px; }

.incoming {
  margin-left: 8px;
  color: #ff5f5f;
  font-weight: 700;
  animation: incoming-pulse 0.9s ease-in-out infinite;
}

.incoming.hidden { display: none; }

@keyframes incoming-pulse {
  50% { opacity: 0.45; }
}

.board-body { position: relative; line-height: 0; }

.board-body canvas { border-radius: 6px; }

.board-status {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 3px;
  background: rgba(8, 9, 14, 0.55);
  border-radius: 6px;
}

.board-foot {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.board-foot .score { color: var(--text); font-weight: 600; }

/* touch bar ---------------------------------------------------------- */

#touchbar { display: none; gap: 10px; }

@media (pointer: coarse) {
  #touchbar { display: flex; }
  #help { display: none; }
}

body.touch #touchbar {
  display: flex;
  position: fixed;
  bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
}
body.touch #help { display: none; }
body.touch #stage { padding-bottom: calc(92px + env(safe-area-inset-bottom, 0px)); }

#touchbar button {
  background: rgba(18, 21, 32, 0.94);
  backdrop-filter: blur(4px);
}

body.touch #touchbar button { width: 62px; height: 54px; }

#touchbar button {
  width: 56px;
  height: 48px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}

#touchbar button:active { background: rgba(255, 255, 255, 0.12); }

/* footer ------------------------------------------------------------- */

#help {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
  font-size: 12px;
  color: var(--muted);
}

#rules {
  max-width: 620px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--muted);
  text-align: center;
}

#build {
  margin-top: 10px;
  font-size: 11px;
  letter-spacing: 1px;
  opacity: 0.55;
}

#build-stamp {
  position: fixed;
  right: 8px;
  bottom: 6px;
  font-size: 11px;
  letter-spacing: 1px;
  color: #8b93ab;
  opacity: 0.8;
  z-index: 4;
  pointer-events: none;
}

/* utility ------------------------------------------------------------ */

.hidden { display: none !important; }

/* menu & lobby -------------------------------------------------------- */

#menu {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 10, 0.78);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 20;
  padding: 20px;
}
/* 內容比螢幕高時(手機橫向 390px 實測)置中會把標題推到頂端之外、捲不回來。safe center: 放得下才置中,
   放不下就從頂端排、可捲。不支援 safe 的瀏覽器會丟掉這一行, 退回上一行的 center。 */
#menu { justify-content: safe center; overflow-y: auto; }

.menu-card {
  background: #141827;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 26px 30px;
  width: min(360px, 92vw);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.menu-title {
  text-align: center;
  letter-spacing: 3px;
  font-size: 14px;
  color: var(--muted);
}

.menu-title b { color: var(--text); font-size: 18px; letter-spacing: 5px; }

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 11px;
  letter-spacing: 2px;
  color: var(--muted);
}

.field input, #join-code {
  background: #0d1019;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 12px 14px;
  font-size: 16px;
  letter-spacing: 1px;
  width: 100%;
}

#join-code { text-transform: uppercase; letter-spacing: 6px; text-align: center; }

.menu-card button, #overlay-buttons button {
  padding: 13px 18px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: #232a42;
  color: var(--text);
  font-size: 14px;
  letter-spacing: 1.5px;
  cursor: pointer;
}

.menu-card button.big { font-weight: 700; }
.menu-card button.alt { background: #1b2233; }
.menu-card button:hover, #overlay-buttons button:hover { background: #2d3554; }

.menu-row { display: flex; gap: 10px; }
.menu-row input { flex: 1; }

#menu-flash {
  color: #ff8080;
  font-size: 13px;
  text-align: center;
  max-width: 340px;
}

.seat-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 4px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

.seat-row:last-child { border-bottom: none; }
.seat-row .seat-open { color: var(--muted); font-size: 12px; }
.seat-row b { margin-left: auto; color: #ffd65a; font-size: 11px; letter-spacing: 2px; }

#lobby-wait { text-align: center; color: var(--muted); font-size: 13px; }

/* overlay ------------------------------------------------------------ */

#overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 10, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

#overlay.hidden { display: none; }

#overlay-card {
  background: #141827;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 32px 44px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#overlay-title { font-size: 34px; font-weight: 800; letter-spacing: 4px; }
#overlay-sub { color: var(--muted); font-size: 14px; }

#overlay-buttons {
  margin-top: 8px;
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* small screens ------------------------------------------------------ */

@media (max-width: 700px) {
  #stage { padding: 10px 8px 32px; gap: 10px; }
  img#logo { height: 40px; }
  #top { justify-content: center; }
  #pool-panel { padding: 6px 10px; }
  #boards { flex-direction: column; align-items: center; gap: 10px; }
  #ai-boards { flex-wrap: nowrap; gap: 6px; }
  .board { padding: 6px; }
  .board-head { font-size: 10px; }
  .board-foot { font-size: 10px; }
  #rules { font-size: 12px; padding: 0 8px; }
  .board-status { font-size: 12px; letter-spacing: 2px; }
}

/* results, invite, focus (2026-10-01) -------------------------------------- */

/* Per-board score and blocks under the result title. */
#overlay-stats {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: min(260px, 70vw);
  margin-top: 2px;
}
.stat-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  background: rgba(255, 255, 255, 0.05);
}
.stat-row.win { background: rgba(255, 214, 90, 0.16); }
.stat-name { flex: 1; text-align: left; letter-spacing: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat-row b { min-width: 5ch; text-align: right; }
.stat-kills { min-width: 7ch; text-align: right; font-size: 12px; color: var(--muted); }

.menu-card button:disabled { opacity: 0.55; cursor: progress; }

#lobby-share { width: 100%; }
#overlay-card:focus { outline: none; }

/* Keyboard focus that can be seen (UI-DESIGN-STANDARD 5.7). Mouse and touch
   presses do not trigger :focus-visible, so nothing changes for them. */
button:focus-visible,
input:focus-visible,
.pshare button:focus-visible {
  outline: 3px solid rgba(46, 143, 214, 0.78);
  outline-offset: 2px;
}

/* park palette for the menu, lobby and overlay ------------------------------
   UI-DESIGN-STANDARD §2: cream cards, honey primary, warm brown ink. Colours
   only, in one block at the end - the boards, the HUD and the arena behind
   them keep their own arcade look (the standard's carve-out for in-match HUD). */

:root {
  --ui-cream-0: #fffdf7; --ui-cream-1: #fff8e8; --ui-cream-2: #f6e8c8;
  --ui-ink: #3a2c12; --ui-text: #6b5327; --ui-muted: #806d4d;
  --ui-gold: #f5a91b; --ui-gold-dark: #9d6508; --ui-danger: #d94b52;
  --ui-shadow-card: 0 14px 38px rgba(63, 42, 19, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.75);
}

#menu { background: rgba(28, 18, 8, 0.6); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
/* No blur here: the result and pause cards sit over the boards, which stay readable. */
#overlay { background: rgba(28, 18, 8, 0.55); }

.menu-card,
#overlay-card {
  background: linear-gradient(rgba(255, 253, 247, 0.97), rgba(255, 248, 232, 0.95));
  border: 3px solid #fff;
  border-radius: 18px;
  box-shadow: var(--ui-shadow-card);
  color: var(--ui-text);
}

.menu-title { color: var(--ui-muted); }
.menu-card .park-badge { --park-badge-accent: var(--ui-gold-dark); }
.menu-title b { color: var(--ui-ink); }
.field { color: var(--ui-muted); }

.field input, #join-code {
  background: #fff;
  border: 2px solid rgba(150, 115, 55, 0.22);
  border-radius: 11px;
  color: var(--ui-ink);
}
.field input::placeholder, #join-code::placeholder { color: #b9a682; }
.field input[readonly] { background: var(--ui-cream-1); color: var(--ui-muted); }

/* Secondary: cream. */
.menu-card button, #overlay-buttons button {
  min-height: 44px;
  border-radius: 11px;
  border: 2px solid rgba(150, 115, 55, 0.22);
  background: rgba(255, 252, 244, 0.95);
  color: var(--ui-text);
  box-shadow: 0 3px 0 rgba(150, 110, 40, 0.14);
  transition: transform 160ms ease, filter 160ms ease;
}
.menu-card button:hover, #overlay-buttons button:hover { background: var(--ui-cream-1); }
.menu-card button:active, #overlay-buttons button:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(150, 110, 40, 0.14); }
.menu-card button.alt { background: rgba(255, 252, 244, 0.95); font-weight: 700; }

/* The one primary action per card: honey. */
#btn-solo, #lobby-start, #overlay-buttons button:first-child {
  background: linear-gradient(#ffe08a, #f5a91b);
  border-color: #ffedb0;
  color: #5a3800;
  font-weight: 800;
  box-shadow: 0 6px 0 #c9871a;
}
#btn-solo:hover, #lobby-start:hover, #overlay-buttons button:first-child:hover {
  background: linear-gradient(#ffe08a, #f5a91b);
  filter: brightness(1.04);
}
#btn-solo:active, #lobby-start:active, #overlay-buttons button:first-child:active { box-shadow: 0 2px 0 #c9871a; }

#menu-flash {
  color: #fff;
  background: rgba(217, 75, 82, 0.92);
  border-radius: 999px;
  padding: 6px 14px;
}

.seat-row { border-bottom-color: rgba(150, 115, 55, 0.18); color: var(--ui-ink); }
.seat-row .seat-open { color: var(--ui-muted); }
.seat-row b { color: var(--ui-gold-dark); }
#lobby-wait { color: var(--ui-muted); }

#overlay-sub { color: var(--ui-muted); }
/* The title keeps the seat colour it is given; a dark edge keeps the light
   ones (amber, teal) readable on cream. */
#overlay-title { text-shadow: 0 1px 0 rgba(58, 44, 18, 0.55), 0 0 1px rgba(58, 44, 18, 0.6); }
.stat-row { background: rgba(246, 232, 200, 0.55); color: var(--ui-ink); }
.stat-row.win { background: linear-gradient(rgba(255, 224, 138, 0.7), rgba(245, 169, 27, 0.35)); }
.stat-kills { color: var(--ui-muted); }

#lobby-share {
  --pshare-bg: rgba(246, 232, 200, 0.6);
  --pshare-fg: #6b5327;
  --pshare-accent: #9d6508;
  --pshare-btn: rgba(255, 252, 244, 0.95);
}
#lobby-share .pshare-row button { border: 2px solid rgba(150, 115, 55, 0.22); min-height: 40px; }
