:root {
  --bg: #14112b;
  --bg2: #221c48;
  --panel: rgba(255, 255, 255, 0.07);
  --panel-2: rgba(255, 255, 255, 0.12);
  --line: rgba(255, 255, 255, 0.16);
  --text: #f6f3ff;
  --muted: #b5addb;
  --accent: #ffb703;
  --coral: #ff7b6b;
  --teal: #2ec4b6;
  --empty: #cbc3a3;
  --alarm: #1b1b1f;
  --radius: 16px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: radial-gradient(1200px 700px at 15% -10%, color-mix(in srgb, var(--accent) 28%, transparent), transparent 60%),
              radial-gradient(900px 600px at 110% 110%, #3a2a8a, transparent 60%), var(--bg);
  background-attachment: fixed;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
h1, h2, h3 { line-height: 1.1; margin: 0 0 .4em; letter-spacing: -0.01em; }
p { margin: 0 0 .6em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.warn, .error { color: #ffd166; font-weight: 700; }
.error { background: rgba(255, 92, 92, .15); border: 1px solid rgba(255, 92, 92, .5); padding: .6em .8em; border-radius: 12px; color: #ffb3b3; }
[hidden] { display: none !important; }

/* ---------- buttons & forms ---------- */
.btn {
  appearance: none; border: 2px solid var(--line); background: var(--panel-2); color: var(--text);
  font: inherit; font-weight: 800; padding: .7em 1.2em; border-radius: 999px; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: .4em;
  transition: transform .08s ease, background .15s ease, opacity .15s;
  touch-action: manipulation;
}
.btn:hover { background: rgba(255, 255, 255, .18); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--accent); border-color: transparent; color: #17122e; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.big { font-size: 1.2rem; padding: .8em 1.6em; }
.btn.small { font-size: .85rem; padding: .45em .9em; }
.btn.ghost { background: transparent; }
input, textarea, select {
  font: inherit; font-size: 1.15rem; color: var(--text); background: rgba(0, 0, 0, .25);
  border: 2px solid var(--line); border-radius: 12px; padding: .65em .8em; width: 100%;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
textarea { resize: none; }
label { display: grid; gap: .3em; font-weight: 700; color: var(--muted); font-size: .9rem; }
.row { display: flex; gap: .8em; flex-wrap: wrap; justify-content: center; margin-top: 1em; }
.stack { display: grid; gap: .6em; margin: 1em 0; }

/* ---------- home ---------- */
.home { max-width: 1100px; margin: 0 auto; padding: 2rem 1.2rem 3rem; }
.hero { text-align: center; padding: 1.5rem 0 1rem; }
.hero h1 { font-size: clamp(2.4rem, 6vw, 4rem); font-weight: 900; }
.hero p { color: var(--muted); font-size: 1.15rem; max-width: 40ch; margin: 0 auto; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem 1.4rem; }
.join-card { max-width: 640px; margin: 1.2rem auto 2.4rem; }
.join-form { display: grid; grid-template-columns: 1fr auto; gap: .8rem; align-items: end; }
.join-form input[name=code] { text-transform: uppercase; letter-spacing: .25em; font-weight: 900; }
.join-form.stacked { grid-template-columns: 1fr; }
@media (max-width: 560px) { .join-form { grid-template-columns: 1fr; } }
.section-title { font-size: 1.3rem; margin: 1.5rem 0 .8rem; color: var(--muted); }
.game-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem; }
.game-card {
  display: flex; flex-direction: column; gap: .3rem; text-decoration: none; padding: 1.3rem;
  border-radius: var(--radius); background: linear-gradient(160deg, color-mix(in srgb, var(--accent) 30%, transparent), var(--panel) 55%);
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line)); transition: transform .15s ease, box-shadow .15s;
}
.game-card:hover { transform: translateY(-4px); box-shadow: 0 14px 40px rgba(0, 0, 0, .35); }
.game-card .btn { margin-top: auto; align-self: flex-start; }
.game-card .btn.primary { background: var(--accent); }
.game-emoji { font-size: 2.6rem; }
.game-card h3 { font-size: 1.5rem; margin: .1em 0; }
.game-card p { color: var(--muted); }
.game-meta { font-size: .85rem; font-weight: 700; color: color-mix(in srgb, var(--accent) 70%, white); margin-bottom: .8rem; }
.home-foot { margin-top: 3rem; text-align: center; color: var(--muted); }

/* ---------- shared bits ---------- */
.center-msg { min-height: 100vh; display: grid; place-content: center; text-align: center; gap: 1rem; padding: 2rem; font-size: 1.3rem; }
.offline { position: fixed; top: 0; left: 50%; transform: translateX(-50%); background: #ffd166; color: #222; font-weight: 800; padding: .4em 1em; border-radius: 0 0 12px 12px; z-index: 20; }
.toast {
  position: fixed; bottom: calc(1.2rem + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  background: #fff; color: #1b1535; font-weight: 800; padding: .8em 1.2em; border-radius: 14px; z-index: 30;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .4); max-width: 90vw; text-align: center; animation: pop .2s ease;
}
.toast.out { opacity: 0; transition: opacity .4s; }
@keyframes pop { from { transform: translate(-50%, 10px); opacity: 0; } }
.timer {
  --pct: 100%; width: 3.2em; height: 3.2em; border-radius: 50%; display: grid; place-content: center;
  font-weight: 900; background: conic-gradient(var(--accent) var(--pct), rgba(255, 255, 255, .12) 0);
  position: relative; flex: none;
}
.timer::before { content: ""; position: absolute; inset: .3em; border-radius: 50%; background: var(--bg2); z-index: -1; }
.timer { isolation: isolate; }
.timer.urgent { animation: pulse 1s infinite; --accent: #ff5d5d; }
@keyframes pulse { 50% { transform: scale(1.08); } }
.chips { display: flex; flex-wrap: wrap; gap: .5em; justify-content: center; margin: 1em 0; }
.chip {
  --c: var(--accent); border: 2px solid var(--c); color: var(--text); background: transparent; border-radius: 999px;
  padding: .35em .9em; font: inherit; font-weight: 800;
}
button.chip { cursor: pointer; }
.chip.done { background: var(--c); color: #17122e; }
.chip.away { opacity: .4; border-style: dashed; }
.chips.big .chip { font-size: 1.3rem; }
.kicker { text-transform: uppercase; letter-spacing: .12em; font-weight: 900; color: var(--accent); font-size: .9rem; }
.hint { color: var(--muted); font-size: 1.3rem; }
blockquote { margin: 1em 0; padding: .8em 1em; border-left: 4px solid var(--accent); background: var(--panel); border-radius: 0 12px 12px 0; font-size: 1.15rem; font-weight: 700; }

/* ---------- game screen (any device) ---------- */
body.play { min-height: 100dvh; }
.screen {
  width: 100%; max-width: 860px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) max(1rem, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(1rem, env(safe-area-inset-left));
  font-size: clamp(1rem, .9rem + .4vw, 1.25rem);
}
.screen.v-board, .screen.v-final { max-width: 1400px; }
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: .8rem; padding: .6rem 0;
  background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.topbar .brand { font-weight: 900; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .room { font-weight: 900; letter-spacing: .15em; color: var(--muted); font-size: .85em; }
.topbar .timer { margin-left: auto; font-size: .85em; width: 2.7em; height: 2.7em; }
.topbar .me { margin-left: auto; font-weight: 900; border-bottom: 3px solid var(--c); white-space: nowrap; }
.topbar .timer:not([hidden]) + .me { margin-left: 0; }
.topbar .me b { color: var(--accent); }
.content { flex: 1; display: flex; flex-direction: column; gap: .5rem; padding: 1rem 0 1.5rem; }
.content > * { margin-top: 0; margin-bottom: 0; }
.content > .btn { align-self: center; }
.game-title { font-size: clamp(1.8rem, 1.2rem + 2.5vw, 3rem); text-align: center; }
.prompt { font-size: clamp(1.5rem, 1rem + 2.5vw, 3rem); font-weight: 900; }
.waiting { text-align: center; color: var(--muted); font-weight: 700; margin: 1rem 0; }
.wait-card { text-align: center; padding: .5rem 0 1rem; border-bottom: 1px dashed var(--line); margin-bottom: .5rem; }
.wait-title { font-size: clamp(2rem, 1.4rem + 3vw, 3.4rem); color: var(--accent); }
.chips.left { justify-content: flex-start; }
.chip-x { background: none; border: 0; color: inherit; font: inherit; font-weight: 900; cursor: pointer; padding: 0 0 0 .4em; opacity: .7; }
.invite-box { text-align: center; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
.invite-box .row { margin: .4rem 0; }
.invite-url { font-size: clamp(1.2rem, 1rem + 1.5vw, 1.8rem); font-weight: 900; color: var(--accent); word-break: break-all; margin: .2rem 0; }
.code { letter-spacing: .15em; }
.qr { width: min(240px, 70%); background: #fff; border-radius: 14px; padding: 8px; display: block; margin: .6rem auto; }
.inline { display: flex; flex-direction: row; align-items: center; justify-content: center; gap: .6em; }
.inline select { width: auto; font-size: 1rem; padding: .4em .6em; }
details > summary { cursor: pointer; font-weight: 800; color: var(--muted); padding: .3rem 0; }
.howto ol { color: var(--muted); padding-left: 1.3em; margin: .3rem 0; }
.option-list { list-style: upper-alpha; display: grid; gap: .5rem; font-weight: 700; padding-left: 2em; margin: .5rem 0; }
.option-list li { background: var(--panel); border-radius: 12px; padding: .5em .8em; }
.option-list li::marker { color: var(--accent); font-weight: 900; }
.reveal-list { display: grid; gap: .6rem; margin: .5rem 0; }
.reveal-item {
  display: flex; gap: 1rem; align-items: center; justify-content: space-between; background: var(--panel);
  border: 2px solid var(--line); border-radius: 14px; padding: .8rem 1rem; animation: slideIn .45s both;
}
.reveal-item.highlight { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 18%, transparent); }
.reveal-label { font-size: 1.15em; font-weight: 800; margin: 0; }
.reveal-by { color: var(--muted); margin: .15em 0 0; font-weight: 700; font-size: .9em; }
.voters { color: var(--muted); margin: .15em 0 0; font-size: .85em; }
.reveal-side { text-align: right; flex: none; }
.points { font-size: 1.5em; font-weight: 900; color: var(--accent); margin: 0; }
.note { font-weight: 800; color: #ffd166; margin: 0; font-size: .85em; }
@keyframes slideIn { from { opacity: 0; transform: translateY(12px); } }
.scoreboard { list-style: none; padding: 0; margin: .5rem auto; display: grid; gap: .4rem; width: 100%; max-width: 640px; }
.scoreboard li { display: flex; align-items: center; gap: .8rem; background: var(--panel); border-left: 6px solid var(--c); border-radius: 10px; padding: .5em 1em; font-weight: 800; }
.scoreboard li:first-child { font-size: 1.25em; background: color-mix(in srgb, var(--accent) 22%, transparent); }
.scoreboard .who { flex: 1; }
.scores { border-top: 1px solid var(--line); padding: .4rem 0; }
.admin-bar {
  position: sticky; bottom: 0; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; justify-content: flex-end;
  padding: .6rem 0 calc(.6rem + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(8px); border-top: 1px solid var(--line);
}
.admin-bar .muted { margin-right: auto; }
.meter { height: 14px; background: var(--panel-2); border-radius: 999px; overflow: hidden; }
.meter-fill { height: 100%; background: var(--accent); transition: width .4s ease; }
.text-form { display: grid; gap: .5rem; margin-top: .5rem; }
.counter { justify-self: end; color: var(--muted); font-size: .8rem; }
.choices { display: grid; gap: .6rem; margin-top: .6rem; }
@media (min-width: 700px) { .choices { grid-template-columns: 1fr 1fr; } }
.btn.choice { border-radius: 14px; justify-content: flex-start; text-align: left; font-size: 1.05em; padding: .9em 1em; font-weight: 700; }
.btn.choice .note { color: var(--muted); font-weight: 600; }
.word-form, .clue-form { display: grid; grid-template-columns: 1fr auto; gap: .5rem; }
.clue-form { grid-template-columns: 5em 1fr; }
.clue-form input { grid-column: 1 / -1; }
.word-form input, .clue-form input { text-transform: uppercase; }
.my-words { list-style: none; padding: 0; margin: .3rem 0; display: flex; flex-wrap: wrap; gap: .4rem; }
.my-words li { background: #f4ecd8; color: #2a2238; font-weight: 900; border-radius: 8px; padding: .3em .2em .3em .7em; display: flex; align-items: center; gap: .2em; }
.my-words .x { background: none; border: 0; color: #2a2238; font-size: 1.3rem; cursor: pointer; padding: 0 .4em; line-height: 1; }

/* before joining */
.entry { justify-content: center; gap: 1rem; max-width: 520px; padding-top: 2rem; padding-bottom: 2rem; }
.entry-brand { font-weight: 900; text-decoration: none; color: var(--muted); text-align: center; }
.entry h1 { text-align: center; }
.invite-card { text-align: center; background: linear-gradient(160deg, color-mix(in srgb, var(--accent) 30%, transparent), var(--panel) 60%); border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line)); border-radius: 20px; padding: 1.4rem; }
.invite-card h1 { font-size: clamp(2rem, 1.5rem + 3vw, 3rem); margin: .1em 0 .2em; }
.entry-form { display: grid; gap: .8rem; }
.account { display: flex; justify-content: flex-end; color: var(--muted); font-size: .9rem; }

/* ---------- crews & board (Word Heist) ---------- */
.t-coral { --team: var(--coral); }
.t-teal { --team: var(--teal); }
.t-coral-text { color: var(--coral); }
.t-teal-text { color: var(--teal); }
.t-coral-btn { border-color: var(--coral); }
.t-teal-btn { border-color: var(--teal); }
.team-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin: 1rem auto; max-width: 900px; text-align: left; }
.team-col { border: 2px solid var(--team); border-radius: 16px; padding: .8rem 1rem; background: color-mix(in srgb, var(--team) 12%, transparent); }
.team-col.mine { box-shadow: 0 0 0 3px color-mix(in srgb, var(--team) 50%, transparent); }
.team-col h3 { color: var(--team); }
.team-col ul { list-style: none; margin: 0; padding: 0; display: grid; gap: .3rem; }
.team-col li { display: flex; align-items: center; gap: .5em; font-weight: 700; }
.team-col li.away { opacity: .45; }
.dot { width: .7em; height: .7em; border-radius: 50%; flex: none; }
.badge { font-size: .7em; text-transform: uppercase; letter-spacing: .06em; background: var(--team); color: #17122e; padding: .15em .5em; border-radius: 6px; margin-left: auto; }
.team-pills { display: flex; gap: .6rem; flex-wrap: wrap; justify-content: center; }
.team-pill { border: 2px solid var(--team); border-radius: 999px; padding: .3em .9em; font-weight: 700; opacity: .7; }
.team-pill b { color: var(--team); font-size: 1.3em; }
.team-pill.active { opacity: 1; background: color-mix(in srgb, var(--team) 20%, transparent); }
.turn-status { font-size: 1.4rem; font-weight: 800; text-align: center; margin: .6rem 0; }
.clue { display: inline-block; margin-left: .6em; background: #fff; color: #17122e; padding: .1em .6em; border-radius: 8px; letter-spacing: .04em; }

.board { display: grid; grid-template-columns: repeat(5, 1fr); gap: clamp(4px, 1vw, 12px); width: 100%; margin: .8rem auto; }
.tile {
  position: relative; aspect-ratio: 3 / 2; border-radius: clamp(6px, 1vw, 12px); border: 2px solid transparent;
  background: #f4ecd8; color: #2a2238; font: inherit; font-weight: 900; display: grid; place-items: center;
  padding: .2em; text-align: center; overflow: hidden; box-shadow: 0 3px 0 rgba(0, 0, 0, .35);
  font-size: clamp(.55rem, 1.5vw, 1.5rem); text-transform: uppercase; overflow-wrap: anywhere; line-height: 1.05;
}
button.tile { cursor: pointer; }
button.tile:active { transform: translateY(2px); box-shadow: none; }
.tile.selected { outline: 4px solid var(--accent); outline-offset: 2px; transform: scale(1.04); z-index: 1; }
.tile-icon { position: absolute; top: .1em; right: .25em; font-size: .9em; }
/* clue-giver key: tint unrevealed tiles */
.tile.keyed.k-coral { background: color-mix(in srgb, var(--coral) 45%, #f4ecd8); }
.tile.keyed.k-teal { background: color-mix(in srgb, var(--teal) 45%, #f4ecd8); }
.tile.keyed.k-empty { background: #e6dfca; color: #6f6852; }
.tile.keyed.k-alarm { background: #3b3b45; color: #fff; border-color: #ff5d5d; }
/* revealed tiles */
.tile.revealed { animation: flip .45s ease both; }
.tile.revealed.k-coral { background: var(--coral); color: #2a0f0b; }
.tile.revealed.k-teal { background: var(--teal); color: #062522; }
.tile.revealed.k-empty { background: var(--empty); color: #5a5340; opacity: .75; }
.tile.revealed.k-alarm { background: var(--alarm); color: #ff6b6b; border-color: #ff5d5d; }
.tile.revealed .tile-word { text-decoration: line-through; text-decoration-thickness: 2px; opacity: .8; }
@keyframes flip { from { transform: rotateX(90deg); } }


/* Word Heist layout: board + side panel; side-by-side when there is room */
.heist { display: grid; gap: 1rem; }
.heist-side { display: flex; flex-direction: column; gap: .5rem; }
.heist-side .btn { align-self: center; }
.v-board .turn-status { font-size: 1.1em; margin: .2rem 0; }
.v-board .turn-status.mine { color: var(--accent); }
.board .tile { aspect-ratio: auto; min-height: 3.1em; font-size: clamp(.55rem, 2.6vw, 1.5rem); }
@media (min-width: 900px) and (min-aspect-ratio: 1/1) {
  .heist { grid-template-columns: minmax(0, 1fr) 320px; align-items: start; }
  /* fit the whole board on screen height */
  .heist-board { max-width: calc((100dvh - 9rem) * 1.6); }
  .board .tile { aspect-ratio: 8 / 5; font-size: clamp(.7rem, 1.25vw, 1.6rem); }
}
.confirm-bar {
  position: sticky; bottom: calc(.6rem + env(safe-area-inset-bottom)); display: flex; align-items: center; gap: .5rem;
  flex-wrap: wrap; justify-content: center; background: var(--bg2); border: 2px solid var(--accent); border-radius: 16px;
  padding: .6rem; box-shadow: 0 10px 30px rgba(0, 0, 0, .5); z-index: 4;
}
.confirm-bar span { width: 100%; text-align: center; font-size: 1.1em; }
.clue-log ul { list-style: none; padding: 0; margin: .3rem 0 .8rem; display: grid; gap: .4rem; }
.clue-log li { border-left: 5px solid var(--team); padding: .3em .6em; background: var(--panel); border-radius: 0 8px 8px 0; display: grid; }
.clue-log li span { color: var(--muted); font-size: .9em; }
.clue-log .team-cols { grid-template-columns: 1fr 1fr; font-size: .9em; }
.my-role { text-align: center; font-weight: 900; color: var(--team); text-transform: uppercase; letter-spacing: .08em; font-size: .9em; }
