:root {
  --bg: #0d0d12;
  --surface: #16161e;
  --surface-2: #1f1f2a;
  --line: #2a2a37;
  --text: #f4f4f7;
  --muted: #9b9bad;
  --accent: #ff5a4e;
  --accent-press: #e9463b;
  --good: #3ddc97;
  --warn: #ffc94d;
  --radius: 16px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  text-size-adjust: 100%;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
h1, h2, h3, p { margin: 0; }

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: calc(env(safe-area-inset-top) + 16px) 20px calc(env(safe-area-inset-bottom) + 20px);
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.muted { color: var(--muted); }
.small { font-size: 14px; }
.center { text-align: center; }
.grow { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; }

.eyebrow {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.title { font-size: 28px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.15; }

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}
.section-head h2 { font-size: 15px; font-weight: 700; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 54px;
  padding: 0 20px;
  border: 0;
  border-radius: 14px;
  font-size: 17px;
  font-weight: 650;
  transition: transform 120ms ease-out, background-color 150ms ease, opacity 150ms ease;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:active { background: var(--accent-press); }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); }
.btn-ghost { background: transparent; color: var(--muted); min-height: 46px; font-size: 15px; font-weight: 600; }
.btn svg { width: 20px; height: 20px; flex: none; }

@media (hover: hover) {
  .btn-primary:hover:not(:disabled) { background: var(--accent-press); }
  .btn-secondary:hover:not(:disabled) { background: #262634; }
  .btn-ghost:hover { color: var(--text); }
}

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

/* ---------- Inputs ---------- */

.field { display: flex; flex-direction: column; gap: 8px; }
.field label { font-size: 14px; font-weight: 600; color: var(--muted); }
.input {
  width: 100%;
  height: 56px;
  padding: 0 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  font-size: 18px;
  outline: none;
  transition: border-color 150ms ease;
}
.input:focus { border-color: var(--accent); }
.input::placeholder { color: #5f5f70; }
.input-code {
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.3em;
  font-size: 22px;
  text-align: center;
  font-weight: 700;
}
.input-code::placeholder { letter-spacing: 0.3em; }

.error {
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(255, 90, 78, 0.12);
  border: 1px solid rgba(255, 90, 78, 0.35);
  color: #ffb3ad;
  font-size: 15px;
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* ---------- Home ---------- */

.home-hero { padding: 6vh 0 2vh; display: flex; flex-direction: column; gap: 14px; }
.logo { width: 64px; height: 64px; border-radius: 16px; }
.brand { font-size: 44px; font-weight: 850; letter-spacing: -0.035em; line-height: 1; }
.tagline { font-size: 18px; color: var(--muted); max-width: 22ch; }

.howto { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.howto summary {
  list-style: none;
  padding: 16px;
  font-weight: 650;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}
.howto summary::-webkit-details-marker { display: none; }
.howto summary::after { content: "+"; font-size: 22px; color: var(--muted); line-height: 1; }
.howto[open] summary::after { content: "–"; }
.howto ol { margin: 0; padding: 0 16px 16px 36px; color: var(--muted); display: flex; flex-direction: column; gap: 8px; }
.howto b { color: var(--text); font-weight: 600; }

/* ---------- Room chrome ---------- */

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 44px; }
.code-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-family: var(--mono);
  font-weight: 700;
  letter-spacing: 0.15em;
}
.code-pill svg { width: 16px; height: 16px; color: var(--muted); }
.round-tag { font-size: 14px; font-weight: 600; color: var(--muted); }
.leave-btn {
  height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  font-weight: 600;
}

.status { display: none; }
.status.show {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(255, 201, 77, 0.12);
  color: var(--warn);
  font-size: 14px;
  font-weight: 600;
}
.status.show::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 1s ease-in-out infinite alternate;
}
@keyframes pulse { from { opacity: 0.3; } to { opacity: 1; } }

.banner {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
}

/* ---------- Lobby ---------- */

.room-hero { text-align: center; display: flex; flex-direction: column; gap: 8px; align-items: center; padding-top: 4px; }
.room-code {
  font-family: var(--mono);
  font-size: 64px;
  font-weight: 800;
  letter-spacing: 0.14em;
  margin-right: -0.14em;
  line-height: 1.05;
}
.room-hero .btn { margin-top: 8px; }

.players { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.player {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 8px 8px 8px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.player.offline { opacity: 0.55; }
.avatar {
  width: 36px;
  height: 36px;
  flex: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 750;
  font-size: 15px;
  color: #0d0d12;
}
.player-name { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag {
  flex: none;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  letter-spacing: 0.02em;
}
.tag-host { background: rgba(255, 201, 77, 0.14); color: var(--warn); }
.tag-you { background: rgba(255, 255, 255, 0.08); color: var(--text); }
.tag-first { background: rgba(255, 90, 78, 0.15); color: #ff8a80; }
.score { flex: none; font-variant-numeric: tabular-nums; font-weight: 700; color: var(--muted); min-width: 28px; text-align: right; padding-right: 4px; }
.kick {
  flex: none;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
}
.kick svg { width: 18px; height: 18px; }
@media (hover: hover) { .kick:hover { background: var(--surface-2); color: var(--text); } }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
  transition: background-color 150ms ease, color 150ms ease;
}
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip:disabled { cursor: default; }

.actions {
  position: sticky;
  bottom: 0;
  margin-top: auto;
  padding-top: 16px;
  padding-bottom: 4px;
  background: linear-gradient(to bottom, transparent, var(--bg) 18px);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.wait {
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-weight: 600;
  text-align: center;
}
.dots::after { content: "…"; }

/* ---------- Secret card ---------- */

.secret {
  position: relative;
  width: 100%;
  min-height: 240px;
  padding: 28px 22px;
  border-radius: 24px;
  border: 1px solid var(--line);
  background:
    radial-gradient(120% 80% at 50% 0%, rgba(255, 255, 255, 0.05), transparent 60%),
    var(--surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 120ms ease-out;
}
.secret:active { transform: scale(0.985); }
.secret.compact { min-height: 120px; padding: 18px; }
.secret .eye { width: 40px; height: 40px; color: var(--muted); }
.secret-cta { font-size: 20px; font-weight: 700; }
.secret-word {
  font-size: clamp(36px, 12vw, 56px);
  font-weight: 850;
  letter-spacing: -0.03em;
  line-height: 1.05;
  overflow-wrap: anywhere;
}
.secret.compact .secret-word { font-size: 32px; }
.secret-hint { color: var(--muted); font-size: 15px; max-width: 28ch; }
.secret-foot { position: absolute; bottom: 12px; left: 0; right: 0; font-size: 12px; color: #5f5f70; font-weight: 600; }

.reveal-in { animation: reveal 220ms cubic-bezier(0.2, 0.8, 0.2, 1); }
@keyframes reveal { from { opacity: 0; transform: translateY(6px) scale(0.98); } to { opacity: 1; transform: none; } }

/* ---------- Order ---------- */

.order { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; counter-reset: order; }
.order li {
  counter-increment: order;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 6px 12px;
  border-radius: 12px;
  background: var(--surface);
  font-weight: 600;
}
.order li::before {
  content: counter(order);
  width: 26px;
  height: 26px;
  flex: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.order li.first::before { background: var(--accent); color: #fff; }
.order .player-name { font-weight: 600; }

/* ---------- Voting ---------- */

.vote-list { display: flex; flex-direction: column; gap: 8px; }
.vote {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 62px;
  padding: 10px 14px;
  border-radius: 14px;
  border: 2px solid var(--line);
  background: var(--surface);
  text-align: left;
  font-size: 18px;
  font-weight: 650;
  transition: border-color 150ms ease, background-color 150ms ease, transform 120ms ease-out;
}
.vote:active { transform: scale(0.99); }
.vote .check {
  margin-left: auto;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--line);
  display: grid;
  place-items: center;
  flex: none;
}
.vote .check svg { width: 16px; height: 16px; opacity: 0; }
.vote[aria-pressed="true"] { border-color: var(--accent); background: rgba(255, 90, 78, 0.08); }
.vote[aria-pressed="true"] .check { background: var(--accent); border-color: var(--accent); }
.vote[aria-pressed="true"] .check svg { opacity: 1; }

.progress { display: flex; flex-direction: column; gap: 10px; }
.progress-bar { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress-bar span { display: block; height: 100%; background: var(--accent); border-radius: inherit; transition: width 300ms ease-out; }
.voters { display: flex; flex-wrap: wrap; gap: 6px; }
.voter { font-size: 13px; font-weight: 600; padding: 4px 10px; border-radius: 999px; background: var(--surface); color: var(--muted); border: 1px solid var(--line); }
.voter.done { color: var(--good); border-color: rgba(61, 220, 151, 0.35); background: rgba(61, 220, 151, 0.08); }

/* ---------- Results ---------- */

.verdict { text-align: center; display: flex; flex-direction: column; gap: 10px; padding: 8px 0 4px; }
.verdict-title { font-size: 34px; font-weight: 850; letter-spacing: -0.03em; line-height: 1.1; }
.verdict.win .verdict-title { color: var(--good); }
.verdict.lose .verdict-title { color: var(--accent); }

.reveal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.reveal-box {
  padding: 16px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.reveal-box strong { font-size: 22px; font-weight: 800; letter-spacing: -0.01em; overflow-wrap: anywhere; line-height: 1.15; }

.tally { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.tally li { display: flex; flex-direction: column; gap: 6px; }
.tally-top { display: flex; align-items: center; gap: 8px; font-weight: 650; }
.tally-top .count { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--muted); }
.tally-bar { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.tally-bar span { display: block; height: 100%; border-radius: inherit; background: #4a4a5e; }
.tally li.is-imposter .tally-bar span { background: var(--accent); }
.tally-voters { font-size: 13px; color: var(--muted); }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 96px);
  transform: translate(-50%, 12px);
  max-width: calc(100% - 40px);
  padding: 12px 16px;
  border-radius: 12px;
  background: #2b2b38;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease-out, transform 180ms ease-out;
  z-index: 10;
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid var(--surface-2);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading { flex: 1; display: grid; place-items: center; }

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