:root {
  --bg: #f4f2ec;
  --surface: #ffffff;
  --surface-2: #efece5;
  --surface-3: #e6e2d9;
  --text: #1c1b19;
  --muted: #6a675f;
  --line: #dedad0;
  --accent: #5b4bdb;
  --accent-ink: #ffffff;
  --accent-soft: #e8e5fb;
  --honest: #1f8a5b;
  --honest-soft: #dff3e9;
  --imp: #d0433a;
  --imp-soft: #fbe4e2;
  --warn: #b7791f;
  --warn-soft: #fbf0db;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 10px 30px rgba(20,16,40,.07);
  --radius: 18px;
  --p1: #e07a3f;
  --p2: #3f8ce0;
  --p3: #a44fd0;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121117;
    --surface: #1b1a21;
    --surface-2: #24222b;
    --surface-3: #2e2b36;
    --text: #ecebf1;
    --muted: #a19eac;
    --line: #34313d;
    --accent: #9b8fff;
    --accent-ink: #15122b;
    --accent-soft: #2c2750;
    --honest: #4fcf94;
    --honest-soft: #173b2b;
    --imp: #ff7a70;
    --imp-soft: #45201e;
    --warn: #e8b35a;
    --warn-soft: #3f311a;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121117;
  --surface: #1b1a21;
  --surface-2: #24222b;
  --surface-3: #2e2b36;
  --text: #ecebf1;
  --muted: #a19eac;
  --line: #34313d;
  --accent: #9b8fff;
  --accent-ink: #15122b;
  --accent-soft: #2c2750;
  --honest: #4fcf94;
  --honest-soft: #173b2b;
  --imp: #ff7a70;
  --imp-soft: #45201e;
  --warn: #e8b35a;
  --warn-soft: #3f311a;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, .display { font-family: "Space Grotesk", Inter, system-ui, sans-serif; line-height: 1.2; letter-spacing: -.01em; }
h1 { font-size: clamp(1.9rem, 5vw, 2.8rem); margin: 0 0 .4rem; }
h2 { font-size: 1.45rem; margin: 0 0 .4rem; }
h3 { font-size: 1.05rem; margin: 0 0 .5rem; }
p { margin: 0 0 .8rem; }
button, input { font: inherit; color: inherit; }
mark { background: var(--accent-soft); color: var(--accent); border-radius: 4px; padding: 0 .25em; font-weight: 600; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-weight: 800; font-size: .8rem; letter-spacing: -.05em;
}
.brand-name { font-family: "Space Grotesk", sans-serif; font-weight: 700; font-size: 1.1rem; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface);
  cursor: pointer; font-weight: 700; display: grid; place-items: center;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.judge-pill {
  font-size: .78rem; font-weight: 600; padding: 5px 10px; border-radius: 99px;
  background: var(--surface); border: 1px solid var(--line); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.judge-pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.judge-pill.online::before { background: var(--honest); }
.judge-pill.error::before, .judge-pill.offline::before { background: var(--warn); }
@media (max-width: 560px) { .judge-pill .long { display: none; } .brand-name { font-size: 1rem; } }

.banner { background: var(--warn-soft); color: var(--warn); text-align: center; font-weight: 600; padding: 8px 16px; font-size: .9rem; }

/* layout */
.layout {
  max-width: 1160px; margin: 0 auto;
  padding: 24px 16px 64px;
  display: grid; gap: 20px;
  grid-template-columns: minmax(0, 1fr);
}
@media (min-width: 960px) {
  .layout.with-aside { grid-template-columns: minmax(0, 1fr) 320px; align-items: start; }
  .aside { position: sticky; top: 84px; }
}
.stack { display: grid; gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); }
.card.tight { padding: 16px; }
@media (max-width: 560px) { .card { padding: 18px 16px; } }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.label { font-size: .74rem; text-transform: uppercase; letter-spacing: .07em; font-weight: 700; color: var(--muted); }

/* buttons & inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 20px; border-radius: 12px; border: 1.5px solid transparent;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; cursor: pointer;
  transition: transform .06s ease, filter .15s ease;
  text-decoration: none;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; filter: none; transform: none; }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; color: var(--accent); border-color: var(--accent); }
.btn.quiet { background: var(--surface-2); color: var(--text); }
.btn.red { background: var(--imp); color: #fff; }
.btn.green { background: var(--honest); color: #fff; }
.input {
  width: 100%; min-height: 48px; padding: 10px 14px; border-radius: 12px;
  border: 1.5px solid var(--line); background: var(--surface); outline: none;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.code { text-transform: uppercase; letter-spacing: .25em; font-weight: 700; font-family: "Space Grotesk", sans-serif; }
.field { display: grid; gap: 6px; }
.form-row { display: flex; gap: 10px; }
.form-row .input { flex: 1; min-width: 0; }
@media (max-width: 480px) { .form-row.stack-sm { flex-direction: column; } }
.error { color: var(--imp); font-weight: 600; font-size: .9rem; }
.counter { font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }

.seg { display: inline-grid; grid-auto-flow: column; background: var(--surface-2); padding: 4px; border-radius: 12px; gap: 4px; }
.seg button { border: 0; background: transparent; padding: 8px 18px; border-radius: 9px; cursor: pointer; font-weight: 700; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.seg button:disabled { cursor: default; }

/* home */
.hero { display: grid; gap: 20px; }
@media (min-width: 900px) { .hero { grid-template-columns: 1.1fr .9fr; align-items: stretch; } }
.hero-title .blank-demo { display: inline-block; min-width: 2.6em; border-bottom: 4px solid var(--imp); }
.steps { display: grid; gap: 12px; margin: 0; padding: 0; list-style: none; counter-reset: s; }
.steps li { counter-increment: s; display: grid; grid-template-columns: 32px 1fr; gap: 12px; align-items: start; }
.steps li::before {
  content: counter(s); width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; font-family: "Space Grotesk", sans-serif;
}
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: .85rem; margin: 6px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* phase header */
.phase-head { display: grid; gap: 10px; margin-bottom: 18px; }
.phase-meta { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.phase-title { font-family: "Space Grotesk", sans-serif; font-weight: 700; font-size: 1.05rem; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; font-family: "Space Grotesk", sans-serif; color: var(--muted); }
.timer.low { color: var(--imp); }
.bar { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .25s linear; }
.turn-dots { display: flex; gap: 6px; }
.turn-dots i { width: 22px; height: 6px; border-radius: 99px; background: var(--surface-3); }
.turn-dots i.done { background: var(--accent); }
.turn-dots i.now { background: var(--accent); opacity: .5; }

/* role & prompt */
.role {
  display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: .86rem;
  padding: 6px 12px; border-radius: 99px;
}
.role.honest { background: var(--honest-soft); color: var(--honest); }
.role.impostor { background: var(--imp-soft); color: var(--imp); }
.prompt-card { border-radius: 16px; padding: 20px; border: 1.5px solid var(--line); background: var(--surface-2); }
.prompt-card.honest { border-color: var(--honest); background: var(--honest-soft); }
.prompt-card.impostor { border-color: var(--imp); background: var(--imp-soft); }
.prompt-card.compact { padding: 12px 16px; }
.prompt-text { font-family: "Space Grotesk", sans-serif; font-weight: 600; font-size: clamp(1.3rem, 3.4vw, 1.9rem); line-height: 1.25; }
.compact .prompt-text { font-size: 1.1rem; }
.prompt-text .key { background: var(--accent); color: var(--accent-ink); border-radius: 8px; padding: 0 .25em; }
.prompt-text .blank { display: inline-block; min-width: 3em; border-bottom: 3px solid var(--imp); transform: translateY(-.1em); }

/* avatars & players */
.avatar {
  width: 32px; height: 32px; border-radius: 50%; flex: none; display: grid; place-items: center;
  font-weight: 700; font-size: .85rem; color: #fff; background: var(--p1);
}
.avatar.c1 { background: var(--p2); }
.avatar.c2 { background: var(--p3); }
.avatar.sm { width: 26px; height: 26px; font-size: .74rem; }
.players { display: grid; gap: 8px; }
.player {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 14px;
  background: var(--surface-2); border: 1px solid transparent;
}
.player.me { border-color: var(--accent); }
.player.offline { opacity: .5; }
.player .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player .score { margin-left: auto; font-family: "Space Grotesk", sans-serif; font-weight: 700; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.player .tag { font-size: .72rem; font-weight: 700; color: var(--muted); }
.status-dot { width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; font-size: .7rem; flex: none; }
.status-dot.done { background: var(--honest); color: #fff; }
.status-dot.waiting { border: 2px dashed var(--line); }
.seat-empty { padding: 12px; border-radius: 14px; border: 1.5px dashed var(--line); color: var(--muted); text-align: center; font-size: .9rem; }

/* answers */
.turns { display: grid; gap: 14px; }
.turn-block { display: grid; gap: 8px; }
.answers { display: grid; gap: 8px; }
@media (min-width: 700px) { .answers.cols-2 { grid-template-columns: 1fr 1fr; } .answers.cols-3 { grid-template-columns: 1fr 1fr 1fr; } }
.answer { display: flex; gap: 10px; align-items: flex-start; }
.bubble {
  background: var(--surface); border: 1px solid var(--line); padding: 8px 12px; border-radius: 4px 14px 14px 14px;
  font-weight: 500; overflow-wrap: anywhere;
}
.bubble.missed { color: var(--muted); font-style: italic; }
.bubble.mine { border-color: var(--accent); }

/* vote */
.vote-card { border: 1.5px solid var(--line); border-radius: 16px; padding: 16px; display: grid; gap: 12px; background: var(--surface); }
.vote-card.marked-honest { border-color: var(--honest); }
.vote-card.marked-impostor { border-color: var(--imp); }
.vote-answers { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--surface-2); padding: 4px 10px; border-radius: 99px; font-size: .88rem; }
.choice { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.choice button {
  min-height: 44px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--surface-2); cursor: pointer; font-weight: 700;
}
.choice button.honest[aria-pressed="true"] { background: var(--honest); border-color: var(--honest); color: #fff; }
.choice button.impostor[aria-pressed="true"] { background: var(--imp); border-color: var(--imp); color: #fff; }

/* judging overlay */
.judging { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-radius: 14px; background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid currentColor; border-right-color: transparent; animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* results */
.result-grid { display: grid; gap: 14px; }
@media (min-width: 760px) { .result-grid.cols-2 { grid-template-columns: 1fr 1fr; } .result-grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; } }
.result-card { border: 1.5px solid var(--line); border-radius: 16px; padding: 16px; display: grid; gap: 12px; background: var(--surface); align-content: start; }
.result-card.impostor { border-color: var(--imp); }
.result-card.honest { border-color: var(--honest); }
.points { font-family: "Space Grotesk", sans-serif; font-size: 1.8rem; font-weight: 700; line-height: 1; }
.points.neg { color: var(--imp); }
.jev-bars { display: grid; gap: 8px; }
.jev-row { display: grid; gap: 4px; }
.jev-row .top { display: flex; justify-content: space-between; gap: 8px; font-size: .9rem; }
.jev-row .top span:first-child { overflow-wrap: anywhere; }
.jev-row .val { font-variant-numeric: tabular-nums; font-weight: 700; }
.jev-row .read { font-size: .76rem; color: var(--muted); }
.track { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.track > i { display: block; height: 100%; border-radius: 99px; background: var(--accent); }
.lines { display: grid; gap: 4px; font-size: .9rem; margin: 0; padding: 0; list-style: none; }
.lines li { display: flex; justify-content: space-between; gap: 8px; }
.lines .plus { color: var(--honest); font-weight: 700; }
.lines .minus { color: var(--imp); font-weight: 700; }
.badge { font-size: .74rem; font-weight: 700; padding: 3px 9px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.badge.good { background: var(--honest-soft); color: var(--honest); }
.badge.bad { background: var(--imp-soft); color: var(--imp); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }

/* game over */
.podium { display: grid; gap: 10px; }
.podium .player { padding: 14px 16px; }
.podium .rank { font-family: "Space Grotesk", sans-serif; font-weight: 700; font-size: 1.4rem; width: 28px; }
.podium .first { background: var(--accent-soft); border-color: var(--accent); }
.highlights { display: grid; gap: 10px; }
@media (min-width: 700px) { .highlights { grid-template-columns: repeat(3, 1fr); } }
.highlight { padding: 14px; border-radius: 14px; background: var(--surface-2); display: grid; gap: 4px; }

/* aside */
.aside .card + .card { margin-top: 16px; }
.share { display: flex; gap: 8px; align-items: center; background: var(--surface-2); border-radius: 12px; padding: 6px 6px 6px 14px; }
.share code { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .9rem; }
.room-code { font-family: "Space Grotesk", sans-serif; font-weight: 700; font-size: 2.6rem; letter-spacing: .15em; line-height: 1; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 20;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; box-shadow: var(--shadow);
}

/* rules dialog */
.rules { border: 0; padding: 0; border-radius: 20px; max-width: 620px; width: calc(100% - 32px); background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.rules::backdrop { background: rgba(10, 8, 20, .55); }
.rules-inner { padding: 22px; max-height: 85vh; overflow: auto; }
.rules-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.rules-list { padding-left: 20px; display: grid; gap: 10px; margin: 0 0 18px; }
.rules-table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.rules-table td { padding: 8px 0; border-bottom: 1px solid var(--line); }
.rules-table td:last-child { text-align: right; font-weight: 700; white-space: nowrap; padding-left: 12px; }

.fade-in { animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
