:root {
  --bg: #14110f;
  --bg-2: #1e1916;
  --card: #241e1a;
  --line: #3a302a;
  --text: #f3ece4;
  --muted: #a99b8e;
  --accent: #d6453d;
  --accent-2: #f0b35a;
  --good: #5fb87a;
  --night-bg: #070b16;
  --night-card: #10172a;
  --night-line: #1f2a46;
  --radius: 16px;
  --display: 'Playfair Display', Georgia, 'Times New Roman', serif;
  --body: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--body);
  font-size: 17px;
  line-height: 1.45;
  transition: background 0.8s ease;
  -webkit-tap-highlight-color: transparent;
}

body.night { background: var(--night-bg); }
body.night .card { background: var(--night-card); border-color: var(--night-line); }

h1, h2, h3, .display { font-family: var(--display); font-weight: 700; margin: 0; letter-spacing: 0.01em; }

.muted { color: var(--muted); }
.small { font-size: 14px; }
.center { text-align: center; }
.stack > * + * { margin-top: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.hidden { display: none !important; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  transition: background 0.8s ease, border-color 0.8s ease;
}

button, .btn {
  font: inherit;
  font-weight: 600;
  border: 0;
  border-radius: 12px;
  padding: 14px 18px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  width: 100%;
  touch-action: manipulation;
}
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.secondary { background: transparent; border: 1px solid var(--line); color: var(--text); }
body.night button.secondary { border-color: var(--night-line); }
button.ghost { background: transparent; color: var(--muted); width: auto; padding: 8px 10px; }
button.inline { width: auto; }

input[type='text'] {
  font: inherit;
  width: 100%;
  padding: 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--text);
}
input[type='text']:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.error { color: #ff8a80; font-size: 15px; }

/* ---------- player (phone) ---------- */

.phone {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px 16px 40px;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0 14px;
}
.topbar .who { font-weight: 700; }
.pill {
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
}
.pill.dead { color: #ff8a80; border-color: #6b2a26; }

.brand {
  text-align: center;
  padding: 36px 0 22px;
}
.brand .logo { font-size: 54px; }
.brand h1 { font-size: 40px; margin-top: 4px; }

.role-card {
  text-align: center;
  padding: 26px 18px;
  user-select: none;
}
.role-card .emoji { font-size: 58px; line-height: 1; }
.role-card h2 { font-size: 34px; margin: 10px 0 6px; }
.role-card.mafia h2 { color: var(--accent); }
.role-card.town h2 { color: var(--accent-2); }
.role-card .cover {
  padding: 34px 0;
  color: var(--muted);
}
.role-card .cover .emoji { opacity: 0.7; }

.teammates, .intel {
  margin-top: 14px;
  padding: 12px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.25);
  text-align: left;
  font-size: 15px;
}
.intel .mafia-hit { color: #ff8a80; font-weight: 700; }

.announce h2 { font-size: 24px; }
.announce p { margin: 6px 0 0; }

.targets { display: grid; gap: 10px; }
.target {
  text-align: left;
  background: var(--bg-2);
  border: 2px solid transparent;
  color: var(--text);
  font-weight: 600;
}
body.night .target { background: #0b1222; }
.target.selected { border-color: var(--accent); background: rgba(214, 69, 61, 0.18); }
.target.skip { color: var(--muted); }

.locked {
  text-align: center;
  padding: 26px 16px;
}
.locked .big { font-size: 26px; font-family: var(--display); margin: 6px 0; }

.team-picks { font-size: 15px; }
.team-picks .agree { color: var(--good); }
.team-picks .disagree { color: var(--accent-2); }

.player-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.player-list li { display: flex; justify-content: space-between; gap: 8px; }
.player-list li.dead .n { text-decoration: line-through; color: var(--muted); }
.offline { color: var(--muted); font-size: 13px; }

.timer {
  font-family: var(--display);
  font-variant-numeric: tabular-nums;
}

.result-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.result-table td { padding: 6px 0; border-bottom: 1px solid var(--line); }
.result-table td:last-child { text-align: right; color: var(--muted); }

.banner {
  text-align: center;
  padding: 28px 16px;
}
.banner .emoji { font-size: 56px; }
.banner h1 { font-size: 34px; margin-top: 8px; }
.banner.win h1 { color: var(--good); }
.banner.lose h1 { color: var(--accent); }

/* ---------- host (laptop / TV) ---------- */

.host {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 28px 48px;
}
.host header { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
.host header h1 { font-size: 30px; }

.host-grid { display: grid; grid-template-columns: 1.6fr 1fr; gap: 20px; }
@media (max-width: 860px) { .host-grid { grid-template-columns: 1fr; } }

.stage { min-height: 360px; display: flex; flex-direction: column; justify-content: center; text-align: center; padding: 40px 32px; }
.stage .phase-emoji { font-size: 72px; line-height: 1; }
.stage h2 { font-size: 52px; margin: 14px 0 10px; }
.stage p.lead { font-size: 24px; max-width: 760px; margin: 0 auto; }
.stage .timer { font-size: 84px; margin-top: 18px; }
.stage .progress { margin-top: 18px; font-size: 20px; color: var(--muted); }
.host-actions { margin-top: 26px; display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.host-actions button { width: auto; min-width: 220px; font-size: 18px; }

.join-box { display: flex; gap: 22px; align-items: center; flex-wrap: wrap; }
.join-box img { width: 220px; height: 220px; border-radius: 12px; background: #fff; padding: 8px; }
.join-url { font-size: 26px; font-weight: 700; word-break: break-all; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  font-weight: 600;
}
body.night .chip { background: #0b1222; border-color: var(--night-line); }
.chip.dead { opacity: 0.5; text-decoration: line-through; }
.chip.off { border-style: dashed; color: var(--muted); }
.chip .role { font-weight: 400; color: var(--muted); font-size: 14px; }
.chip button.x { width: auto; padding: 0 2px; background: none; color: var(--muted); font-size: 18px; line-height: 1; }

.settings { display: grid; gap: 12px; }
.settings label { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.settings select {
  font: inherit;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--line);
}
.settings input[type='checkbox'] { width: 22px; height: 22px; accent-color: var(--accent); }

.side .card + .card { margin-top: 16px; }
.side h3 { font-size: 20px; margin-bottom: 12px; }

/* ---------- online rooms ---------- */

a { color: var(--accent-2); }
a.btn { display: block; text-align: center; text-decoration: none; }
.home-link { text-decoration: none; color: inherit; }
.row.nowrap { flex-wrap: nowrap; }
.warn { color: var(--accent-2); }
.danger { color: #ff8a80 !important; }

button.google { background: #fff; color: #1f1f1f; display: flex; align-items: center; justify-content: center; gap: 10px; }
button.google .g { font-weight: 700; color: #4285f4; font-size: 20px; }
button.small-btn, .small-btn { font-size: 14px; padding: 8px 12px; }
button.ghost.small-btn { padding: 6px 8px; }

.avatar {
  width: 36px; height: 36px; border-radius: 50%; object-fit: cover;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--bg-2); border: 1px solid var(--line); font-weight: 700;
}

.code-input {
  text-transform: uppercase; letter-spacing: 0.3em; font-weight: 700; text-align: center;
  font-size: 22px !important;
}

.code-box { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.code-box .qr { width: 160px; height: 160px; border-radius: 12px; background: #fff; padding: 6px; }
.code-box.big .qr { width: 220px; height: 220px; }
.room-code { font-family: var(--display); font-size: 40px; letter-spacing: 0.12em; line-height: 1.1; }
.code-box.big .room-code { font-size: 64px; }
.inline-code { font-size: inherit; letter-spacing: 0.08em; }
.code-url { word-break: break-all; }

.narrator { border-color: #5a4a2a; }
.narrator-line { text-align: center; }
.narrator-unlock {
  background: var(--accent-2); color: #1b130c;
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse { 50% { transform: scale(1.02); box-shadow: 0 0 0 6px rgba(240, 179, 90, 0.25); } }
@media (prefers-reduced-motion: reduce) { .narrator-unlock { animation: none; } }
.voice-settings { display: grid; gap: 10px; margin-top: 12px; }
.voice-settings label { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.voice-settings select, .settings select { max-width: 60%; }
.voice-settings select {
  font: inherit; font-size: 14px; padding: 8px; border-radius: 10px;
  background: var(--bg-2); color: var(--text); border: 1px solid var(--line);
}

.admin-panel { border-color: #5a3a2a; }
.admin-panel h3 { font-size: 20px; }
.admin-panel .host-actions { margin-top: 0; }
.admin-panel .host-actions button { min-width: 0; width: 100%; }
.admin-panel .progress { color: var(--muted); text-align: center; }
details summary { cursor: pointer; font-weight: 600; padding: 6px 0; color: var(--muted); }
details[open] summary { margin-bottom: 10px; }
.side h3 + p { margin-top: 0; }

.device-list { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 8px; }
.device-list li {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 12px; background: var(--bg-2);
}
body.night .device-list li { background: #0b1222; }
.device-list li.off { opacity: 0.55; }
.pill.on { color: var(--accent-2); border-color: #5a4a2a; white-space: nowrap; }

.big-timer { font-size: 44px; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  max-width: calc(100% - 32px); padding: 12px 16px; border-radius: 12px;
  background: #3a2320; color: #fff; border: 1px solid #6b2a26;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 10;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 520px) {
  .host { padding: 16px 16px 40px; }
  .stage { padding: 28px 16px; min-height: 0; }
  .stage h2 { font-size: 34px; }
  .stage p.lead { font-size: 19px; }
  .stage .timer { font-size: 60px; }
  .host-actions button { min-width: 0; width: 100%; }
  .code-box.big .room-code { font-size: 48px; }
}
.host > .stack:not(:empty) { margin-bottom: 18px; }
