:root {
  --bg: #17120f;
  --bg2: #211915;
  --panel: #2a201b;
  --line: #43342b;
  --ink: #f6ecdc;
  --muted: #b9a894;
  --cream: #f3e6cc;
  --tick: #4a3a30;
  --amber: #ffb547;
  --team0: #43c6b0;
  --team1: #f2728f;
  --active: var(--team0);
  --other: var(--team1);
  --z2: #f6d27b;
  --z3: #f39a4a;
  --z4: #e04a3a;
  --specL: #7fb3e3;
  --specR: #f3925f;
  color-scheme: dark;
  font-family: "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--ink);
  background:
    radial-gradient(1100px 560px at 50% -12%, #3b2a20 0%, transparent 62%),
    var(--bg);
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
button { font: inherit; cursor: pointer; }
code { background: var(--bg); padding: 1px 6px; border-radius: 6px; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 10px 14px;
  max-width: 960px; margin: 0 auto; padding: 12px 16px;
}
.brand { font-family: Fraunces, Georgia, serif; font-weight: 800; font-size: 1.45rem; letter-spacing: -.01em; }
.brand span { color: var(--amber); }
.scores { display: flex; gap: 8px; align-items: center; margin-left: auto; flex-wrap: wrap; justify-content: flex-end; }
.score {
  --c: var(--team0);
  display: flex; align-items: center; gap: 8px;
  padding: 5px 5px 5px 12px; border-radius: 999px;
  border: 2px solid var(--line); background: var(--bg2); color: var(--ink);
}
.score.t1 { --c: var(--team1); }
.score .nm { max-width: 9em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.score b { min-width: 2.1em; padding: 2px 8px; border-radius: 999px; background: var(--c); color: #1a1310; text-align: center; }
.score.on { border-color: var(--c); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 28%, transparent); }
.goal { color: var(--muted); font-size: .85rem; }

/* ---------- Buttons & inputs ---------- */
.primary {
  background: var(--amber); color: #1f150e; border: 0;
  padding: 12px 20px; border-radius: 12px; font-weight: 700;
  box-shadow: 0 6px 18px rgba(255, 181, 71, .18);
}
.primary:hover { filter: brightness(1.07); }
.primary:active { transform: translateY(1px); }
.ghost {
  background: transparent; color: var(--ink);
  border: 1.5px solid var(--line); padding: 11px 16px; border-radius: 12px; font-weight: 600;
}
.ghost:hover { border-color: var(--muted); }
.link { background: none; border: 0; color: var(--muted); text-decoration: underline; padding: 8px; margin-top: 18px; }
.big { padding: 15px 26px; font-size: 1.1rem; }
.small { padding: 6px 12px; font-size: .85rem; }
.wide { width: 100%; }
:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; }

input[type=text], input:not([type]), textarea, select {
  background: var(--bg); color: var(--ink);
  border: 1.5px solid var(--line); border-radius: 10px;
  padding: 10px 12px; font: inherit;
}
input:focus, textarea:focus, select:focus { border-color: var(--amber); outline: none; }
textarea { resize: vertical; }

/* ---------- Screen visibility ---------- */
#setup, #table, .overlay, .step, #phonePill { display: none; }
[hidden] { display: none !important; }
body[data-view=setup] #setup { display: block; }
body:not([data-view=setup]) #table { display: flex; }
body[data-view=setup] .scores,
body[data-view=setup] #menuBtn { display: none; }
body.remote:not([data-view=setup]) #phonePill { display: inline-flex; }
body[data-view=handoff] #handoff,
body[data-view=gameover] #gameover { display: grid; }
body[data-view=psychic] .step[data-step=psychic],
body[data-view=r-handoff] .step[data-step=r-handoff],
body[data-view=r-psychic] .step[data-step=r-psychic],
body[data-view=guess] .step[data-step=guess],
body[data-view=counter] .step[data-step=counter],
body[data-view=reveal] .step[data-step=reveal] { display: block; }

/* ---------- Phone mode bits ---------- */
.pill {
  align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px;
  border: 1.5px solid var(--line); background: var(--bg2); color: var(--ink); font-weight: 600; font-size: .85rem;
}
.pill.ok { border-color: color-mix(in srgb, #7bd88f 55%, var(--line)); color: #a8ecb5; }
.pill.warn { border-color: var(--amber); color: var(--amber); }

.phone-setup {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  background: var(--panel); border: 1.5px dashed var(--line); border-radius: 16px;
  padding: 14px 16px; margin: 0 0 16px;
}
.phone-setup.ok { border-style: solid; border-color: color-mix(in srgb, #7bd88f 50%, var(--line)); }
.ps-icon { font-size: 1.8rem; }
.ps-text { flex: 1 1 220px; }
.ps-text p { margin: 3px 0 0; }
.ps-btns { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.ps-btns .link { margin: 0; }

.pass { font-family: Fraunces, Georgia, serif; font-size: clamp(1.8rem, 6vw, 2.6rem); margin: .1em 0; line-height: 1.05; }
.step[data-step^=r-] .psy { font-size: 1.2rem; }
.step[data-step=r-psychic] .psy b { color: var(--active); }

.modal {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px;
  background: rgba(10, 7, 6, .72); backdrop-filter: blur(4px);
}
.modal-card {
  position: relative; width: min(440px, 100%); max-height: calc(100dvh - 32px); overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 22px 20px; text-align: center;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .5);
}
.modal-card h2 { font-family: Fraunces, Georgia, serif; margin: 0 0 6px; }
.x { position: absolute; top: 8px; right: 10px; background: none; border: 0; color: var(--muted); font-size: 1.8rem; line-height: 1; padding: 6px 10px; }
.qr { width: min(240px, 70vw); margin: 10px auto; background: #fff; border-radius: 12px; padding: 6px; }
.qr svg { display: block; width: 100%; height: auto; }
.code { font-family: Fraunces, Georgia, serif; font-size: 2.6rem; font-weight: 800; letter-spacing: .18em; color: var(--amber); }
.pair-done .big-check {
  width: 72px; height: 72px; margin: 14px auto 6px; border-radius: 50%; display: grid; place-items: center;
  background: color-mix(in srgb, #7bd88f 22%, transparent); color: #a8ecb5; font-size: 2.4rem; font-weight: 800;
}
.pair-status { color: var(--amber); min-height: 1.2em; margin: 10px 0 0; }
.pair-status:empty { display: none; }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 30;
  max-width: min(520px, calc(100vw - 32px)); padding: 12px 16px; border-radius: 12px;
  background: #3a2b22; border: 1px solid var(--amber); color: var(--ink); box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
}

/* ---------- Setup ---------- */
#setup { max-width: 760px; margin: 0 auto; padding: 4px 16px 48px; }
.hero { text-align: center; padding: 10px 0 18px; }
.hero h1 { font-family: Fraunces, Georgia, serif; font-size: clamp(2.6rem, 10vw, 4.4rem); margin: .1em 0 0; letter-spacing: -.02em; line-height: 1; }
.tag { color: var(--muted); font-size: 1.1rem; margin: .6em 0 0; }
.mini {
  position: relative; width: 200px; height: 100px; margin: 0 auto;
  border-radius: 100px 100px 0 0; border: 8px solid #120d0b; border-bottom: 0;
  background: conic-gradient(from -90deg at 50% 100%,
    var(--cream) 0 104deg, var(--z2) 0 111deg, var(--z3) 0 118deg, var(--z4) 0 125deg,
    var(--z3) 0 132deg, var(--z2) 0 139deg, var(--cream) 0 180deg, transparent 0);
}
.mini i {
  position: absolute; left: 50%; bottom: 0; width: 4px; height: 82px; margin-left: -2px;
  background: #1d1512; border-radius: 4px; transform-origin: 50% 100%;
  animation: sway 4s ease-in-out infinite;
}
@keyframes sway { 0%, 100% { transform: rotate(-40deg); } 50% { transform: rotate(38deg); } }

.teams { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
fieldset {
  margin: 0; padding: 10px 14px 14px; border-radius: 16px;
  border: 1.5px solid var(--line); background: var(--panel); min-width: 0;
}
fieldset.t0 { border-top: 5px solid var(--team0); }
fieldset.t1 { border-top: 5px solid var(--team1); }
legend { font-weight: 700; padding: 0 6px; }
fieldset label { display: block; font-weight: 600; font-size: .9rem; margin-top: 8px; }
fieldset input, fieldset textarea { display: block; width: 100%; margin-top: 5px; }
.opt { color: var(--muted); font-weight: 400; font-size: .85rem; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 22px; margin: 16px 0; }
.row label { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 600; flex-wrap: wrap; }
.check input { width: 18px; height: 18px; accent-color: var(--amber); margin: 0; }
details {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px 14px; margin: 14px 0;
}
details textarea { width: 100%; margin: 6px 0 10px; }
summary { cursor: pointer; font-weight: 700; }
.rules ol { padding-left: 1.3em; margin: 10px 0 2px; }
.rules li { margin: 8px 0; color: #e9dcc8; line-height: 1.45; }

/* ---------- Table ---------- */
#table { flex-direction: column; gap: 14px; max-width: 760px; margin: 0 auto; padding: 0 16px 40px; }
.status { text-align: center; font-weight: 600; color: var(--muted); min-height: 1.4em; font-size: 1.05rem; }
.status b { color: var(--active); }
.status .o { color: var(--other); }

.dial-wrap {
  padding: 16px 16px 8px; border-radius: 30px 30px 18px 18px;
  background: linear-gradient(#30251f, #221a16);
  border: 1px solid var(--line);
  box-shadow: 0 22px 50px rgba(0, 0, 0, .45), inset 0 1px 0 rgba(255, 255, 255, .06);
}
#dial { display: block; width: 100%; height: auto; max-height: 50vh; user-select: none; -webkit-user-select: none; }
#dial.grab { touch-action: none; cursor: grab; }
#dial.grab:active { cursor: grabbing; }

.bezel, .base, .hub-back { fill: #120d0b; }
.face { fill: var(--cream); }
.ticks line { stroke: var(--tick); stroke-width: 1.2; stroke-linecap: round; }
.ticks line.major { stroke-width: 2.4; }
.z2 { fill: var(--z2); } .z3 { fill: var(--z3); } .z4 { fill: var(--z4); }
.target path { stroke: rgba(0, 0, 0, .18); stroke-width: .6; }
.zl { font: 700 15px "DM Sans", sans-serif; fill: #2a1a12; text-anchor: middle; dominant-baseline: central; }
.lid { transition: transform 1.1s cubic-bezier(.65, 0, .35, 1); }
.lid.open { transform: rotate(180deg); }
.lid-edge { fill: none; stroke: #5a463b; stroke-width: 2; }
.lid-label { font: 800 20px Fraunces, Georgia, serif; fill: #7a6152; text-anchor: middle; letter-spacing: .28em; }
.needle { transition: transform .08s linear, opacity .35s; }
.needle .shaft-back { stroke: #1d1512; stroke-width: 8; stroke-linecap: round; }
.needle .shaft { stroke: var(--active); stroke-width: 4; stroke-linecap: round; }
.needle .tip { fill: var(--active); stroke: #1d1512; stroke-width: 2.5; }
.needle.hidden { opacity: 0; }
.hub { fill: #2b211c; stroke: var(--active); stroke-width: 3; }

.spectrum { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.end {
  padding: 12px 14px; font-weight: 700; line-height: 1.15; color: #15100d;
  font-size: clamp(1rem, 3.4vw, 1.35rem); min-height: 3.2em; display: flex; align-items: center;
}
.end.left { background: var(--specL); border-radius: 16px 6px 6px 16px; }
.end.right { background: var(--specR); border-radius: 6px 16px 16px 6px; justify-content: flex-end; text-align: right; }
.end.left::before { content: "◀"; font-size: .7em; margin-right: 8px; opacity: .55; }
.end.right::after { content: "▶"; font-size: .7em; margin-left: 8px; opacity: .55; }

.clue { text-align: center; font-family: Fraunces, Georgia, serif; font-weight: 600; font-size: clamp(1.5rem, 5.5vw, 2.3rem); line-height: 1.15; }
.clue:empty { display: none; }
.clue .muted { font-family: "DM Sans", sans-serif; font-size: 1rem; color: var(--muted); font-weight: 500; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 18px 16px; }
.step { text-align: center; }
.hint { color: var(--muted); margin: 0 0 12px; line-height: 1.45; }
.hint b { color: var(--ink); }
.small-hint { font-size: .9rem; margin: 8px 0 0; }
.btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }
#clueInput { width: 100%; font-size: 1.25rem; padding: 14px; text-align: center; }
#needleRange { width: 100%; accent-color: var(--active); height: 32px; }

.lr .choice {
  flex: 1 1 140px; display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 16px; border-radius: 14px; border: 2px solid var(--line);
  background: var(--bg2); color: var(--ink); font-weight: 700; font-size: 1.2rem;
}
.lr .choice:hover { border-color: var(--other); }
.choice small { font-weight: 500; color: var(--muted); font-size: .85rem; }
.other-name { color: var(--other) !important; }

.result { animation: pop .45s 1s both; margin-bottom: 6px; }
.result .pts { font-family: Fraunces, Georgia, serif; font-size: clamp(2.6rem, 10vw, 3.6rem); font-weight: 800; color: var(--active); line-height: 1; }
.result .pts.zero { color: var(--muted); }
.result p { margin: 8px 0; }
.result .bonus { color: var(--amber); font-weight: 700; }
#btnNext { animation: pop .4s 1.35s both; }
@keyframes pop { from { opacity: 0; transform: scale(.92); } to { opacity: 1; transform: none; } }

/* ---------- Overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 10; place-items: center; padding: 24px 16px; text-align: center; overflow-y: auto;
  background: radial-gradient(800px 520px at 50% 28%, color-mix(in srgb, var(--active) 24%, var(--bg)), var(--bg));
}
.ov-card { max-width: 560px; }
.ov-card h2 { font-family: Fraunces, Georgia, serif; font-size: clamp(2rem, 8vw, 3.4rem); margin: .15em 0; line-height: 1.05; }
.team-name { color: var(--active); }
.eyebrow { text-transform: uppercase; letter-spacing: .2em; font-size: .8rem; color: var(--muted); margin: 0; }
.psy { font-size: 1.25rem; margin: .4em 0; }
.psy b { color: var(--active); }
.lookaway { font-size: 1.05rem; color: var(--muted); margin: 0 0 26px; }
.lookaway b { color: var(--ink); }
.ov-scores { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; margin-top: 26px; }
.ov-scores .score { cursor: default; }

/* ---------- Responsive ---------- */
@media (max-width: 600px) {
  .teams { grid-template-columns: 1fr; }
  .dial-wrap { padding: 10px 8px 6px; border-radius: 22px 22px 14px 14px; }
  .brand { font-size: 1.25rem; }
  .topbar { padding: 10px 16px; gap: 8px; }
  #menuBtn { margin-left: auto; }
  .scores { order: 3; width: 100%; justify-content: center; margin: 0; flex-wrap: nowrap; }
  .score { padding: 3px 3px 3px 10px; font-size: .9rem; min-width: 0; }
  .score .nm { max-width: 7.5em; }
  .goal { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .lid { transition-duration: .25s; }
  .mini i { animation: none; transform: rotate(20deg); }
  .result, #btnNext { animation-delay: .25s; }
}

/* ---------- Psychic phone page ---------- */
.phone-page .role-tag { font-family: "DM Sans", sans-serif; font-weight: 500; font-size: .75rem; color: var(--muted); letter-spacing: .02em; margin-left: 4px; }
.phone-page .score { cursor: default; }
.pmain { max-width: 520px; margin: 0 auto; padding: 8px 16px 40px; }
.pv { display: none; text-align: center; }
body[data-pv=join] .pv[data-pv=join],
body[data-pv=msg] .pv[data-pv=msg],
body[data-pv=handoff] .pv[data-pv=handoff],
body[data-pv=psychic] .pv[data-pv=psychic],
body[data-pv=guess] .pv[data-pv=guess],
body[data-pv=reveal] .pv[data-pv=reveal] { display: block; }
.pv h1 { font-family: Fraunces, Georgia, serif; font-size: 2.6rem; margin: .3em 0 0; line-height: 1; }
.pv h2 { font-family: Fraunces, Georgia, serif; font-size: 2rem; margin: .2em 0; line-height: 1.1; }
.pv .mini { margin-top: 24px; }
.pv .tag { margin: .5em 0 1em; }
.pv .btns { margin: 14px 0 6px; }
.pv .opt { display: block; margin-top: 12px; }
.code-input {
  display: block; width: 100%; margin: 8px 0 14px; padding: 14px; text-align: center;
  font: 800 2.4rem Fraunces, Georgia, serif; letter-spacing: .3em; text-transform: uppercase;
}
.msg-icon { font-size: 3.4rem; margin-top: 30px; }
.pv[data-pv=handoff] { padding-top: 30px; }
.who { font-size: clamp(2.6rem, 13vw, 3.6rem) !important; color: var(--active); }
.pv[data-pv=psychic] .dial-wrap { margin: 8px 0 10px; padding: 10px 8px 6px; border-radius: 22px 22px 14px 14px; }
.pv[data-pv=psychic] .end { font-size: 1rem; min-height: 2.8em; }
.pv[data-pv=psychic] #clueInput { margin-top: 12px; }
.peek { margin-top: 18px; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: none; }
.peek:active { border-color: var(--active); }
.peek-view { visibility: hidden; margin-top: 14px; }
.peek-view.on { visibility: visible; }
.peek-view .dial-wrap { padding: 10px 8px 6px; }
.pv .pts { font-family: Fraunces, Georgia, serif; font-size: 4rem; font-weight: 800; color: var(--active); margin-top: 30px; }
.pv .pts.zero { color: var(--muted); }
.next-box { margin-top: 26px; padding: 18px; border-radius: 18px; background: var(--panel); border: 1px solid var(--line); font-size: 1.1rem; }
.next-box:empty { display: none; }
.who-next { font-family: Fraunces, Georgia, serif; font-size: 2.2rem; color: var(--amber); }
.net-banner {
  position: fixed; left: 0; right: 0; bottom: 0; padding: 10px 16px; text-align: center; font-weight: 600;
  background: var(--amber); color: #1f150e; z-index: 30;
}
@media (max-width: 600px) {
  .phone-page .scores { order: 0; width: auto; margin-left: auto; }
}
