:root {
  --bg: #16142e;
  --bg-2: #1d1a3d;
  --panel: #241f4a;
  --panel-2: #2f2960;
  --line: #3f3878;
  --text: #f7f3ea;
  --muted: #c3bedf;
  --gold: #ffb238;
  --gold-ink: #241a05;
  --coral: #ff6b5b;
  --teal: #3cc6b4;
  --face: #f6efdf;
  --band-4: #c81e3a;
  --band-3: #f26a3d;
  --band-2: #f7c548;
  --left: #8fd6f0;
  --right: #ffb59e;
  --ink: #1b1733;
  --danger: #ff8a7d;
  --radius: 18px;
  --font-display: 'Fredoka', ui-rounded, 'Segoe UI', system-ui, sans-serif;
  --font-body: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: dark;
}

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

html, body { margin: 0; }
body {
  min-height: 100vh;
  background:
    radial-gradient(1000px 500px at 50% -10%, #2c2468 0%, transparent 70%),
    var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font-body);
  -webkit-tap-highlight-color: transparent;
}

h1, h2, .brand, .big-code, .final-score, .reveal-points, .stat-value, .scale-label, .clue-text {
  font-family: var(--font-display);
}
h1 { font-size: clamp(2rem, 6vw, 3.2rem); line-height: 1.1; margin: 0 0 .5rem; }
h2 { font-size: 1.25rem; margin: 0 0 .75rem; }
a { color: var(--gold); }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; max-width: 980px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; font-size: 1.35rem; font-weight: 700; }
.brand svg { width: 40px; height: 24px; }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.room-badge {
  font-family: var(--font-display); letter-spacing: .08em; background: var(--panel-2);
  padding: 4px 10px; border-radius: 999px; font-size: .9rem;
}

main { max-width: 980px; margin: 0 auto; padding: 8px 16px 48px; }

/* ---------- buttons & inputs ---------- */
.btn {
  font: 600 1rem/1.2 var(--font-display); letter-spacing: .01em;
  border: 2px solid transparent; border-radius: 999px; padding: 12px 22px;
  cursor: pointer; transition: transform .08s ease, background .15s ease, opacity .15s;
  min-height: 46px; touch-action: manipulation;
}
.btn:active { transform: translateY(1px) scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--gold); color: var(--gold-ink); }
.btn-primary:hover:not(:disabled) { background: #ffc35f; }
.btn-secondary { background: var(--panel-2); color: var(--text); border-color: var(--line); }
.btn-secondary:hover:not(:disabled) { background: #3a3375; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn-ghost:hover:not(:disabled) { background: var(--panel); }
.btn-small { padding: 6px 14px; min-height: 36px; font-size: .9rem; }
.btn-tiny { padding: 2px 10px; min-height: 28px; font-size: .8rem; margin-left: auto; }
.btn-big { padding: 14px 34px; font-size: 1.15rem; min-height: 54px; }

label { display: block; font-weight: 600; margin: .6rem 0 .3rem; }
input:not([type=checkbox]) {
  width: 100%; font: inherit; color: var(--text); background: var(--bg-2);
  border: 2px solid var(--line); border-radius: 12px; padding: 10px 12px; min-height: 46px;
}
input:not([type=checkbox]):focus { border-color: var(--gold); outline: none; }
input::placeholder { color: #8f89b8; }
input:disabled { opacity: .6; }
.code-input { text-transform: uppercase; letter-spacing: .3em; font-family: var(--font-display); font-size: 1.3rem; }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.center { justify-content: center; }
.row > input { flex: 1 1 180px; width: auto; }

.hint { color: var(--muted); font-size: .92rem; margin: .4rem 0; }
.hint.sub { margin: -.1rem 0 .5rem 2.3rem; font-size: .85rem; }
.form-error { color: var(--danger); min-height: 1.2em; margin: .4rem 0; font-weight: 600; }
.status-line { text-align: center; color: var(--muted); }
.eyebrow { text-transform: uppercase; letter-spacing: .15em; font-size: .75rem; color: var(--muted); margin: 0; }
.pill { font-size: .8rem; background: var(--panel-2); padding: 2px 10px; border-radius: 999px; vertical-align: middle; font-family: var(--font-body); }

/* switches */
.switch { display: flex; align-items: center; gap: 12px; cursor: pointer; margin: .8rem 0 .2rem; font-weight: 600; }
.switch input {
  appearance: none; -webkit-appearance: none; flex: none;
  width: 48px; height: 28px; border-radius: 999px; background: #4a4480; position: relative; cursor: pointer; margin: 0;
  transition: background .15s;
}
.switch input::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: var(--text); transition: transform .15s;
}
.switch input:checked { background: var(--teal); }
.switch input:checked::after { transform: translateX(20px); }
.switch input:disabled { opacity: .5; cursor: not-allowed; }
.switch input:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* ---------- cards ---------- */
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; box-shadow: 0 10px 30px rgba(0,0,0,.25);
}
.card .btn { margin-top: 14px; }
.card.wide { margin: 0 auto 16px; max-width: 720px; }
.card-alt { background: linear-gradient(160deg, #2a2457, #1f3a52); }
.cards { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-weight: 700; font-family: var(--font-display); font-size: 1.1rem; padding: 0; }

.hero { text-align: center; padding: 20px 0 26px; }
.hl { color: var(--gold); }
.lede { color: var(--muted); max-width: 560px; margin: 0 auto; font-size: 1.05rem; }
.screen-title { text-align: center; font-size: 2rem; }

/* ---------- lobby ---------- */
.lobby-head { display: flex; flex-wrap: wrap; gap: 20px; align-items: center; justify-content: space-between; }
.big-code { font-size: clamp(2.4rem, 9vw, 3.4rem); letter-spacing: .18em; margin: 0; color: var(--gold); font-weight: 700; }
.share { flex: 1 1 300px; }
.share label { margin-top: 0; }
.share .btn { margin-top: 0; }
.lobby-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); max-width: 720px; margin: 0 auto 20px; }
.player-list, .name-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.player-list li {
  display: flex; align-items: center; gap: 8px; background: var(--bg-2); border-radius: 12px; padding: 8px 12px;
}
.player-list li.offline .pname { opacity: .55; }
.pname { font-weight: 600; overflow-wrap: anywhere; }
.tag { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; padding: 1px 8px; border-radius: 999px; background: var(--panel-2); color: var(--muted); }
.tag-host { background: var(--gold); color: var(--gold-ink); }
.tag-you { background: var(--teal); color: #062420; }
.tag-disconnected { background: #5a2b3a; color: #ffd2cb; }
.name-list li { display: flex; gap: 8px; align-items: center; }
.name-list input { flex: 1; }
.name-list .btn-tiny { margin-left: 0; }
.settings-grid { display: block; }
.settings-grid input[type=number] { max-width: 120px; }

/* ---------- game ---------- */
.status-bar {
  display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center;
  max-width: 720px; margin: 0 auto 12px;
}
.stat { display: flex; flex-direction: column; align-items: center; background: var(--panel); border-radius: 14px; padding: 6px 14px; min-width: 76px; }
.stat-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); }
.stat-value { font-size: 1.4rem; font-weight: 700; line-height: 1.1; }
.role-pill {
  justify-self: center; text-align: center; font-weight: 700; font-family: var(--font-display);
  background: var(--panel-2); border-radius: 999px; padding: 8px 16px; font-size: .98rem;
}
.role-pill.giver { background: var(--coral); color: #2a0b06; }
.role-pill.guesser { background: var(--teal); color: #062420; }

.board { max-width: 720px; margin: 0 auto; }
.scale-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 8px; }
.scale-label {
  border-radius: 14px; padding: 10px 14px; font-weight: 600; font-size: clamp(1rem, 3.6vw, 1.3rem);
  color: var(--ink); overflow-wrap: anywhere; display: flex; align-items: center; min-height: 52px;
}
.scale-label.left { background: var(--left); }
.scale-label.left::before { content: '◀'; margin-right: 8px; font-size: .8em; }
.scale-label.right { background: var(--right); justify-content: flex-end; text-align: right; }
.scale-label.right::after { content: '▶'; margin-left: 8px; font-size: .8em; }
.scale-row.pending .scale-label { opacity: .7; }
.scale-note { text-align: center; color: var(--muted); background: var(--panel); border-radius: 14px; padding: 10px; margin: 0 0 8px; }

.dial-wrap { position: relative; }
.dial { display: block; width: 100%; height: auto; touch-action: none; user-select: none; -webkit-user-select: none; border-radius: 12px; }
.dial.can-drag { cursor: grab; }
.dial.can-drag:active { cursor: grabbing; }
.dial-rim { fill: #0d0b20; }
.dial-face { fill: var(--face); }
.band-4 { fill: var(--band-4); }
.band-3 { fill: var(--band-3); }
.band-2 { fill: var(--band-2); }
.band-label { font: 700 20px var(--font-display); text-anchor: middle; dominant-baseline: middle; }
.band-4-label { fill: #fff; }
.band-3-label, .band-2-label { fill: #2a1206; }
.tick { stroke: #8a8070; stroke-width: 2; }
.tick.major { stroke: #4d4538; stroke-width: 3; }
.cover-base { fill: #2f2960; }
.cover-stripe { fill: #3b3478; }
.cover-hub { fill: #16142e; }
.cover-text { font: 700 44px var(--font-display); fill: var(--gold); text-anchor: middle; dominant-baseline: middle; }
.needle-hit { stroke: transparent; stroke-width: 40; stroke-linecap: round; }
.needle-line { stroke: var(--coral); stroke-width: 7; stroke-linecap: round; filter: drop-shadow(0 0 2px #0008); }
.needle-knob { fill: var(--coral); stroke: #fff; stroke-width: 3; }
.needle-pivot { fill: #0d0b20; stroke: var(--coral); stroke-width: 4; }
.dial:focus-visible { outline: 3px solid var(--gold); outline-offset: 4px; }

.curtain {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; background: rgba(22,20,46,.96); border-radius: 12px; padding: 16px;
}
.curtain-title { font-family: var(--font-display); font-size: 1.4rem; margin: 0; }
.curtain-title strong { color: var(--gold); }

.clue-box {
  margin-top: 10px; background: var(--face); color: var(--ink); border-radius: 14px; padding: 10px 16px;
  display: flex; gap: 12px; align-items: baseline;
}
.clue-label { text-transform: uppercase; font-size: .75rem; letter-spacing: .15em; font-weight: 700; color: #6b5f4a; }
.clue-text { margin: 0; font-size: clamp(1.2rem, 4.5vw, 1.6rem); font-weight: 600; overflow-wrap: anywhere; }

.panel { max-width: 720px; margin: 14px auto 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; text-align: center; }
.panel .row { justify-content: center; }
.panel form .row { flex-wrap: nowrap; }
.waiting { color: var(--muted); font-size: 1.05rem; margin: .4rem 0; }
.spin-msg { animation: pulse 1s ease-in-out infinite alternate; }
@keyframes pulse { from { opacity: .55; } to { opacity: 1; } }
.or { color: var(--muted); margin: 18px 0 4px; font-size: .9rem; }
.custom-inputs { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; text-align: left; }
.draft { margin-bottom: 4px; }
.needle-readout { font-size: 1.1rem; margin: .3rem 0 .8rem; }
.reveal-points { font-size: clamp(2rem, 8vw, 3rem); font-weight: 700; margin: 0; animation: pop .5s cubic-bezier(.2,1.6,.4,1) both; animation-delay: 1s; }
.reveal-points[data-points="4"] { color: var(--gold); }
.reveal-points[data-points="0"] { color: var(--muted); }
@keyframes pop { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.host-tools { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line); color: var(--muted); }
.host-tools p { margin: 0 0 8px; }

.player-strip { list-style: none; padding: 0; margin: 16px auto 0; max-width: 720px; display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.player-strip li { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; font-size: .9rem; overflow-wrap: anywhere; }
.player-strip li.is-giver { background: var(--coral); color: #2a0b06; border-color: var(--coral); font-weight: 700; }
.player-strip li.is-giver::before { content: '✎ '; }
.player-strip li.is-you { outline: 2px solid var(--teal); }
.player-strip li.offline { opacity: .5; text-decoration: line-through; }

/* ---------- results ---------- */
.results { text-align: center; }
.final-score { font-size: clamp(3.4rem, 14vw, 5rem); font-weight: 700; margin: 0; color: var(--gold); line-height: 1.1; }
.out-of { font-size: .4em; color: var(--muted); }
.final-rating { font-size: 1.2rem; margin: .3rem 0 .8rem; }
.table-wrap { overflow-x: auto; }
.history { width: 100%; border-collapse: collapse; font-size: .95rem; }
.history th, .history td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.history th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; }
.history td:last-child, .history th:last-child { text-align: right; font-weight: 700; }

/* ---------- dialogs / overlay / toast ---------- */
.modal {
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius);
  max-width: min(560px, calc(100vw - 32px)); padding: 22px;
}
.modal::backdrop { background: rgba(8,6,20,.7); }
.how { padding-left: 1.2rem; }
.how li { margin-bottom: .55rem; }
.overlay { position: fixed; inset: 0; background: rgba(8,6,20,.85); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 20; }
.overlay-box { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 26px; max-width: 420px; text-align: center; }
.overlay-box p { color: var(--muted); }
.spinner { width: 42px; height: 42px; margin: 0 auto 12px; border-radius: 50%; border: 5px solid var(--panel-2); border-top-color: var(--gold); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 30px); opacity: 0; pointer-events: none;
  background: var(--face); color: var(--ink); padding: 10px 18px; border-radius: 999px; font-weight: 600;
  transition: all .2s ease; max-width: calc(100vw - 32px); text-align: center; z-index: 30;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.noscript { text-align: center; padding: 40px; }

@media (max-width: 560px) {
  .status-bar { grid-template-columns: auto auto; }
  .role-pill { grid-column: 1 / -1; grid-row: 2; }
  .stat:last-child { justify-self: end; }
  .custom-inputs { grid-template-columns: 1fr; }
  .panel form .row { flex-wrap: wrap; }
  .panel form .row .btn { width: 100%; }
  .topbar .brand span { font-size: 1.15rem; }
  .hint.sub { margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

.history td:first-child, .history th:first-child, .history td:last-child, .history th:last-child { white-space: nowrap; overflow-wrap: normal; width: 1%; }

@media (max-width: 560px) {
  .topbar { padding: 10px 12px; }
  .topbar-right { flex-wrap: nowrap; gap: 6px; }
  .room-badge { display: none; }
  .brand svg { width: 32px; height: 20px; }
}
@media (max-width: 380px) {
  .brand span { display: none; }
}
.host-tools p:empty { display: none; }
