:root {
  --bg: #0e1013;
  --surface: #161a20;
  --surface2: #1d232c;
  --line: #29313d;
  --text: #eef1f5;
  --muted: #8b95a3;
  --accent: #4c8dff;
  --accent-soft: rgba(76, 141, 255, 0.14);
  --amber: #e8a33d;
  --green: #3fb26f;
  --red: #e5484d;
  --sans: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, Inter, sans-serif;
}
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
html { background: var(--bg); overscroll-behavior: none; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--sans);
  color: var(--text);
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
  background:
    radial-gradient(60% 40% at 50% -10%, rgba(76, 141, 255, 0.13), transparent 70%),
    radial-gradient(50% 35% at 90% 110%, rgba(76, 141, 255, 0.06), transparent 70%),
    var(--bg);
  background-attachment: fixed;
}
button, .chip, .tab, .topbar, .tabbar, .field-label, h1, h2 { -webkit-user-select: none; user-select: none; }
.beat-text, .beat-clue, input { -webkit-user-select: text; user-select: text; }

/* ---------- topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px 16px;
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
  background: rgba(14, 16, 19, 0.85); backdrop-filter: blur(14px);
}
.brand { display: flex; align-items: baseline; gap: 7px; }
.pi-glyph { color: var(--accent); font-size: 19px; font-style: italic; font-family: Georgia, serif; }
.brand-pi { font-size: 20px; font-weight: 800; letter-spacing: 0.12em; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.case-tag { font-size: 12px; color: var(--muted); max-width: 52vw; text-align: right; line-height: 1.3; }
.sound-btn { background: none; border: none; font-size: 19px; cursor: pointer; padding: 4px; }

/* ---------- layout ---------- */
.screen { max-width: 640px; margin: 0 auto; padding: 20px 16px 110px 16px; }
.hidden { display: none !important; }
.screen-title { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; margin-bottom: 12px; }
.muted { color: var(--muted); font-size: 14px; line-height: 1.5; }
.small-print { font-size: 12px; margin-top: 8px; }
.error { color: var(--red); font-size: 14px; margin-top: 10px; min-height: 1em; }
.gold { color: var(--accent); }

/* ---------- hero ---------- */
.hero { text-align: center; padding: 34px 0 22px 0; position: relative; }
.hero-pi {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-family: Georgia, serif; font-style: italic; font-size: 170px; color: var(--accent);
  opacity: 0.07; pointer-events: none; line-height: 1;
}
.hero h1 { font-size: 64px; font-weight: 800; letter-spacing: -0.03em; }
.tagline { color: var(--muted); margin-top: 4px; font-size: 15px; }
.hero.small { padding: 16px 0 10px 0; }
.hero.small h1 { font-size: 40px; }
.hero.small .hero-pi { font-size: 100px; }

/* ---------- controls ---------- */
.btn {
  font-family: var(--sans); font-size: 16px; font-weight: 700;
  background: var(--surface2); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 18px; width: 100%; cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.btn:hover { box-shadow: 0 6px 22px rgba(76, 141, 255, 0.22); border-color: var(--accent); }
.btn:active { transform: scale(0.98); }
.btn.gold { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.gold:hover { box-shadow: 0 6px 24px rgba(76, 141, 255, 0.45); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.ember { background: transparent; border-color: var(--red); color: var(--red); }
.btn.ember:hover { box-shadow: 0 6px 20px rgba(229, 72, 77, 0.25); }
.btn.big { margin-top: 24px; padding: 16px; font-size: 17px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.join-row { display: flex; gap: 10px; }
.join-row input { flex: 1; }

input {
  font-family: var(--sans); font-size: 16px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px; padding: 14px; width: 100%;
}
input:focus { outline: 2px solid var(--accent); border-color: var(--accent); }

/* ---------- builder ---------- */
.field-label { font-size: 12px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent); margin: 22px 0 8px 0; }
.field-label.sub { margin-top: 12px; }
.field-label .hint { color: var(--muted); font-weight: 400; text-transform: none; letter-spacing: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font-family: var(--sans); font-size: 14px; font-weight: 600;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: 999px; padding: 10px 14px; cursor: pointer;
  transition: transform 0.1s ease, border-color 0.15s ease;
}
.chips.small .chip { font-size: 13px; padding: 8px 12px; }
.chip.selected { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 700; }
.chip:hover { border-color: var(--accent); }
.chip:active { transform: scale(0.96); }
.chips.swatches .chip { width: 40px; height: 40px; border-radius: 50%; padding: 0; font-size: 0; border-width: 2px; }
.chips.swatches .chip.selected { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- lists ---------- */
.lobby-code { font-size: 18px; margin-bottom: 6px; }
.lobby-code b { color: var(--accent); font-size: 24px; letter-spacing: 0.2em; font-weight: 800; }
.squad-list { list-style: none; margin-top: 16px; display: flex; flex-direction: column; gap: 10px; }
.squad-list li {
  background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: 12px; padding: 12px 14px; font-size: 15px;
}
.squad-list .who { font-weight: 700; }
.squad-list .what { color: var(--muted); font-size: 13px; }
.squad-list.roster li.pickable { cursor: pointer; transition: border-color 0.15s ease, box-shadow 0.15s ease; }
.squad-list.roster li.pickable:hover { border-color: var(--accent); box-shadow: 0 4px 18px rgba(76, 141, 255, 0.18); }
.squad-list.roster li.locked { opacity: 0.55; border-left-color: var(--line); }
.squad-list li.empty { border-left-color: var(--line); color: var(--muted); font-size: 14px; }
.squad-list .row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.mini-btn {
  font-family: var(--sans); font-size: 12px; font-weight: 700;
  background: transparent; color: var(--red); border: 1px solid var(--red);
  border-radius: 8px; padding: 6px 10px; cursor: pointer;
}
.mini-btn:disabled { color: var(--muted); border-color: var(--line); }
.left-player { opacity: 0.5; }

.spinner { text-align: center; margin-top: 30px; color: var(--muted); }
.badge-pi {
  width: 60px; height: 60px; margin: 0 auto 12px auto; border-radius: 50%;
  border: 2px solid var(--accent); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-family: Georgia, serif; font-style: italic; font-size: 30px;
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 0.4; } 50% { opacity: 1; } }

/* ---------- beat pager ---------- */
.beat-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 10px; }
.nav-arrow {
  background: var(--surface); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; font-size: 20px; line-height: 1; padding: 8px 16px; cursor: pointer;
}
.nav-arrow:disabled { opacity: 0.25; }
#beatPos { font-size: 12px; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent); }

.beat { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; margin-bottom: 18px; overflow: hidden; }
.beat img { width: 100%; display: block; aspect-ratio: 1; object-fit: cover; }
.beat-body { padding: 18px 16px; }
.beat-meta { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.loc-chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 700; color: var(--accent);
  background: var(--accent-soft); border-radius: 999px; padding: 6px 12px;
}
.listen-btn {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: var(--sans); font-size: 13px; font-weight: 700;
  background: var(--surface2); color: var(--text);
  border: 1px solid var(--line); border-radius: 999px; padding: 8px 14px; cursor: pointer;
}
.listen-btn.playing { border-color: var(--accent); color: var(--accent); }
.listen-btn:disabled { opacity: 0.4; }
.beat-text { font-size: 16.5px; line-height: 1.7; white-space: pre-wrap; color: #dfe4ea; }
.beat-clue {
  margin-top: 14px; padding: 12px 14px; border-left: 3px solid var(--amber);
  background: rgba(232, 163, 61, 0.09); font-size: 14px; border-radius: 0 10px 10px 0;
}
.beat-clue b { color: var(--amber); letter-spacing: 0.08em; font-size: 11px; }

/* ---------- choices ---------- */
#choiceArea { margin-top: 4px; }
.choice-title { font-size: 18px; font-weight: 800; letter-spacing: -0.01em; margin: 18px 0 10px 0; }
.choice-btn {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; margin-bottom: 10px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px; padding: 14px; font-size: 15px; line-height: 1.4;
  cursor: pointer; font-family: var(--sans);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.choice-btn:hover { border-color: var(--accent); box-shadow: 0 4px 18px rgba(76, 141, 255, 0.16); }
.choice-btn:active { transform: scale(0.99); }
.choice-btn .t { flex: 1; }
.dc-pill {
  flex-shrink: 0; font-size: 11px; font-weight: 800; letter-spacing: 0.04em;
  color: var(--muted); background: var(--surface2); border: 1px solid var(--line);
  border-radius: 999px; padding: 5px 9px; white-space: nowrap;
}
.dc-pill .plus { color: var(--green); }
.freeform { display: flex; gap: 8px; margin-top: 4px; }
.freeform input { flex: 1; }
.freeform button { width: auto; }
.waiting { color: var(--muted); font-size: 14px; margin: 16px 0; line-height: 1.6; }
.roll-recap { font-size: 13px; color: var(--muted); margin-top: 6px; }
.roll-recap b.crit { color: var(--amber); }
.roll-recap b.success { color: var(--green); }
.roll-recap b.fail { color: var(--red); }
.roll-recap b.fumble { color: var(--red); }

/* ---------- dice overlay ---------- */
.dice-overlay {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(10, 12, 15, 0.86); backdrop-filter: blur(6px);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
}
.die {
  width: 128px; height: 128px; border-radius: 26px;
  background: linear-gradient(145deg, var(--surface2), var(--surface));
  border: 2px solid var(--accent);
  box-shadow: 0 0 44px rgba(76, 141, 255, 0.35);
  display: flex; align-items: center; justify-content: center;
  font-size: 56px; font-weight: 800;
}
.die.rolling { animation: shake 0.09s linear infinite; }
@keyframes shake {
  0% { transform: rotate(-5deg) translate(-2px, 1px); }
  50% { transform: rotate(4deg) translate(2px, -1px); }
  100% { transform: rotate(-3deg) translate(-1px, 2px); }
}
.die.crit { border-color: var(--amber); box-shadow: 0 0 54px rgba(232, 163, 61, 0.55); color: var(--amber); }
.die.success { border-color: var(--green); box-shadow: 0 0 44px rgba(63, 178, 111, 0.45); color: var(--green); }
.die.fail, .die.fumble { border-color: var(--red); box-shadow: 0 0 44px rgba(229, 72, 77, 0.4); color: var(--red); }
.dice-dc { font-size: 14px; font-weight: 700; color: var(--muted); letter-spacing: 0.08em; text-transform: uppercase; }
.dice-result { font-size: 22px; font-weight: 800; letter-spacing: -0.01em; min-height: 1.3em; }
.dice-result.crit { color: var(--amber); }
.dice-result.success { color: var(--green); }
.dice-result.fail, .dice-result.fumble { color: var(--red); }

/* ---------- map ---------- */
.map-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 8px; }
.map-svg { width: 100%; aspect-ratio: 4 / 5; display: block; }
.map-legend { display: flex; gap: 16px; margin-top: 10px; font-size: 12px; color: var(--muted); padding: 0 6px 6px 6px; }
.map-legend .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; }

/* ---------- board ---------- */
.clue-list { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.clue-list li {
  background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--amber);
  border-radius: 12px; padding: 12px 14px; font-size: 14px; line-height: 1.5;
}
.clue-list .b { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; display: block; margin-bottom: 4px; }

/* ---------- tabs ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; background: rgba(14, 16, 19, 0.92); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; background: none; border: none; color: var(--muted);
  font-family: var(--sans); font-size: 12.5px; font-weight: 700; letter-spacing: 0.05em;
  padding: 14px 0; cursor: pointer; border-top: 2px solid transparent;
}
.tab.active { color: var(--accent); border-top-color: var(--accent); }

@media (min-width: 768px) {
  .screen { padding-top: 32px; }
  .hero h1 { font-size: 84px; }
}
