:root {
  --bg: #fdf6e8;
  --paper: #ffffff;
  --ink: #2b1d12;
  --muted: #7a6656;
  --accent: #d9481e;
  --accent-ink: #ffffff;
  --teal: #2f8f83;
  --line: #ead9bf;
  --shadow: 0 6px 20px rgba(80, 45, 10, 0.12);
  --radius: 18px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1410;
    --paper: #2a201a;
    --ink: #f6ebdc;
    --muted: #b9a693;
    --line: #3d3027;
    --shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Sans HK", "PingFang HK", "Heiti TC", system-ui, sans-serif;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}
a { color: inherit; }
.wrap { max-width: 640px; margin: 0 auto; padding: 0 16px; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0 6px;
}
.brand { display: inline-flex; align-items: center; gap: 7px; text-decoration: none; }
.brand img { width: 34px; height: 34px; display: block; }
.brand b { font-weight: 900; font-size: 21px; letter-spacing: 0.02em; line-height: 1; }
.brand span { color: var(--accent); font-weight: 900; font-size: 14px; letter-spacing: 0.01em; align-self: flex-end; margin-bottom: 2px; }
.topbar small { color: var(--muted); font-size: 13px; }
h1 { font-size: 26px; line-height: 1.25; margin: 10px 0 4px; font-weight: 900; }
.lead { color: var(--muted); margin: 0 0 14px; font-size: 15px; }
.btn {
  appearance: none; border: 0; border-radius: 999px;
  padding: 12px 18px; font: inherit; font-weight: 700; font-size: 16px;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--paper); color: var(--ink); box-shadow: var(--shadow);
  -webkit-tap-highlight-color: transparent; text-decoration: none;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn[disabled] { opacity: 0.4; pointer-events: none; }
.footer { color: var(--muted); font-size: 13px; padding: 28px 0 40px; text-align: center; }
.prose { font-size: 15px; }
.prose h2 { font-size: 18px; margin: 28px 0 6px; }
.prose p, .prose li { color: var(--muted); }

/* ---- shared result sheet ---- */
.modal {
  position: fixed; inset: 0; background: rgba(20, 12, 6, 0.6);
  display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10;
}
.modal[hidden] { display: none; }
.sheet {
  background: var(--paper); border-radius: 22px; padding: 16px; width: 100%; max-width: 420px;
  max-height: calc(100dvh - 32px); overflow: auto; box-shadow: var(--shadow);
}
.sheet img { width: 100%; border-radius: 14px; display: block; }
.sheet .row { display: flex; gap: 10px; margin-top: 12px; }
.sheet .row .btn { flex: 1; }
.sheet .note { color: var(--muted); font-size: 12px; text-align: center; margin: 8px 0 0; }
.sheet .fallback { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.sheet .fallback[hidden] { display: none; }
.sheet .fallback .btn { flex: 1 1 40%; font-size: 14px; padding: 10px; }
.sheet .next { display: block; text-align: center; margin-top: 12px; color: var(--accent); font-weight: 700; text-decoration: none; }
.stage-wrap { position: relative; margin: 6px auto 14px; max-width: 520px; }
.stage { display: block; width: 100%; border-radius: 22px; box-shadow: var(--shadow); touch-action: none; user-select: none; -webkit-user-select: none; }
.pill {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  background: rgba(43, 29, 18, 0.78); color: #fff; font-size: 14px; font-weight: 700;
  padding: 6px 14px; border-radius: 999px; pointer-events: none; white-space: nowrap; transition: opacity 0.3s;
}
.pill.gone { opacity: 0; }
.controls { display: flex; gap: 10px; justify-content: center; max-width: 520px; margin: 0 auto; }
.controls .btn { flex: 1; }
.controls .btn.primary { flex: 1.4; }
.plays { color: var(--muted); font-size: 12px; }

/* ---- leaderboards ---- */
.sheet .rank { margin-top: 12px; padding: 12px; border-radius: 14px; background: var(--bg); }
.sheet .rank[hidden], .rank-form[hidden] { display: none; }
.rank-form { display: flex; gap: 8px; }
.rank-form input {
  flex: 1; min-width: 0; font: inherit; font-size: 16px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--paper); color: var(--ink);
}
.rank-form .btn { flex: 0 0 auto; padding: 10px 16px; }
.rank-msg { margin: 8px 0 0; font-size: 14px; text-align: center; color: var(--muted); }
.rank-msg:empty { display: none; }
.rank-msg b { color: var(--accent); font-size: 16px; }
.linkish { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); text-decoration: underline; cursor: pointer; }
.board { max-width: 520px; margin: 22px auto 0; background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.board-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.board-head h2 { font-size: 18px; margin: 0; }
.tabs { display: flex; background: var(--bg); border-radius: 999px; padding: 3px; }
.tabs button { font: inherit; font-size: 14px; font-weight: 700; border: 0; background: none; color: var(--muted); padding: 6px 14px; border-radius: 999px; cursor: pointer; }
.tabs button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.board-list { list-style: none; margin: 10px 0 0; padding: 0; }
.board-list li { display: flex; align-items: center; gap: 10px; padding: 8px 4px; border-top: 1px solid var(--line); font-size: 15px; }
.board-list li:first-child { border-top: 0; }
.board-list li.empty { justify-content: center; color: var(--muted); font-size: 14px; padding: 14px 0; }
.board-list li.me { background: color-mix(in srgb, var(--accent) 12%, transparent); border-radius: 10px; }
.board-list .pos { width: 28px; text-align: center; font-weight: 900; color: var(--muted); }
.board-list .who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.board-list .val { font-variant-numeric: tabular-nums; font-weight: 900; color: var(--accent); }
.board-note { color: var(--muted); font-size: 12px; margin: 8px 0 0; text-align: center; }
.wall-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; margin-top: 12px; }
.wall-grid .empty { grid-column: 1 / -1; text-align: center; color: var(--muted); font-size: 14px; margin: 10px 0; }
.wall-sign {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 14px 8px 10px; cursor: pointer;
  background: #14161f; border: 1px solid #2b2f3d; border-radius: 12px; font: inherit;
}
.wall-sign span {
  font-size: 22px; font-weight: 500; color: #fff; letter-spacing: 0.06em; word-break: break-all;
  text-shadow: 0 0 2px #fff, 0 0 6px var(--neon), 0 0 14px var(--neon), 0 0 26px var(--neon);
}
.wall-sign small { color: #8d93a8; font-size: 11px; }
.topbar .sound-toggle {
  margin-left: 10px; width: 36px; height: 36px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--paper); box-shadow: var(--shadow); font-size: 17px; line-height: 1;
}
.topbar small { margin-left: auto; }
