:root {
  --bg: #0d1117;
  --bg2: #131a24;
  --panel: #1a2330;
  --panel2: #212c3b;
  --line: #2c3949;
  --txt: #e6edf5;
  --muted: #93a4b8;
  --accent: #4f9cf9;
  --accent2: #7c5cff;
  --ok: #3fb950;
  --warn: #d29922;
  --bad: #f85149;
  --gold: #e3b341;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

html[data-theme="light"] {
  --bg: #eef2f7;
  --bg2: #e4eaf3;
  --panel: #ffffff;
  --panel2: #f3f6fb;
  --line: #d3dce8;
  --txt: #16202e;
  --muted: #5b6b80;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  background: radial-gradient(1200px 600px at 20% -10%, #1d2b45 0%, var(--bg) 60%);
  color: var(--txt);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  overscroll-behavior-y: none;
}
html[data-theme="light"] body { background: var(--bg); }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }

/* ── Buttons ─────────────────────────────────────── */
.btn {
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--txt);
  border-radius: 10px;
  padding: 9px 14px;
  font-weight: 600;
  transition: transform .06s, filter .15s;
}
.btn:active { transform: scale(.97); }
.btn:hover { filter: brightness(1.12); }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); border-color: transparent; color: #fff; }
.btn.ok { background: var(--ok); border-color: transparent; color: #04220b; }
.btn.warn { background: var(--warn); border-color: transparent; color: #2a1d00; }
.btn.bad { background: var(--bad); border-color: transparent; color: #fff; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 9px; font-size: 13px; border-radius: 8px; }
.btn.wide { width: 100%; }
.btn.on { outline: 2px solid var(--accent); }

.field { margin: 12px 0; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.field input, .field select {
  width: 100%; padding: 11px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel2);
}
.field input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > * { flex: 1 1 auto; }
.err { color: var(--bad); font-size: 14px; min-height: 20px; }
.hint { color: var(--muted); font-size: 13px; }

/* ── Auth screen ─────────────────────────────────── */
.auth-wrap {
  min-height: 100dvh; display: grid; place-items: center; padding: 18px;
}
.auth-card {
  width: min(420px, 100%); background: var(--panel);
  border: 1px solid var(--line); border-radius: 20px;
  padding: 26px 22px; box-shadow: 0 22px 60px rgba(0,0,0,.45);
}
.auth-card h1 { margin: 0 0 4px; font-size: 26px; text-align: center; }
.auth-card .sub { text-align: center; color: var(--muted); margin: 0 0 18px; font-size: 14px; }
.tabs { display: flex; background: var(--panel2); border-radius: 10px; padding: 4px; margin-bottom: 8px; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 8px; font-weight: 600; color: var(--muted); }
.tabs button.on { background: var(--accent); color: #fff; }
.theme-btn { position: fixed; top: 12px; right: 12px; z-index: 40; padding: 7px 10px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel); }

/* ── App shell ───────────────────────────────────── */
#app { display: none; flex-direction: column; min-height: 100dvh; }
#app.on { display: flex; }

.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 10px;
  padding: calc(8px + env(safe-area-inset-top, 0px)) 12px 8px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.topbar .code {
  font-family: ui-monospace, monospace; font-weight: 800; letter-spacing: 2px;
  background: var(--panel2); padding: 5px 10px; border-radius: 9px; cursor: pointer;
}
.phase-pill {
  padding: 4px 11px; border-radius: 999px; font-weight: 700; font-size: 13px;
  background: var(--panel2); border: 1px solid var(--line);
}
.phase-pill.night { background: #2a1b4d; border-color: #55399b; color: #d7c6ff; }
.phase-pill.day { background: #23406b; border-color: #3f6fb5; color: #cfe3ff; }
.phase-pill.vote { background: #5a3a12; border-color: #9c6a1e; color: #ffe1ac; }
.phase-pill.lobby { background: var(--panel2); }
.phase-pill.end { background: #4a2030; border-color: #a04160; color: #ffd7e2; }
html[data-theme="light"] .phase-pill.night { background: #e6dcff; color: #3a2470; }
html[data-theme="light"] .phase-pill.day { background: #dbeaff; color: #173a68; }
html[data-theme="light"] .phase-pill.vote { background: #ffeccd; color: #6b4405; }
html[data-theme="light"] .phase-pill.end { background: #ffdde6; color: #7a1c36; }

.mic-btn { position: relative; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel2); }
.mic-btn.live { background: var(--ok); color: #04220b; border-color: transparent; }
.mic-btn.off { background: var(--bad); color: #fff; border-color: transparent; }
.mic-btn .bars { display: inline-flex; align-items: flex-end; gap: 2px; height: 12px; margin-left: 6px; }
.mic-btn .bars i { width: 2px; background: currentColor; height: 4px; border-radius: 1px; }
.mic-btn.live .bars i { animation: eq .9s infinite ease-in-out; }
.mic-btn .bars i:nth-child(2) { animation-delay: .15s; }
.mic-btn .bars i:nth-child(3) { animation-delay: .3s; }
.mic-btn .bars i:nth-child(4) { animation-delay: .45s; }
@keyframes eq { 0%,100% { height: 3px; } 50% { height: 12px; } }

main { flex: 1; display: flex; flex-direction: column; gap: 10px; padding: 10px 12px calc(96px + var(--safe-b)); }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.panel h3 { margin: 0 0 8px; font-size: 14px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 760px) { .grid2 { grid-template-columns: 1fr; } }

/* ── Player cards ────────────────────────────────── */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.pcard {
  position: relative; background: var(--panel2); border: 2px solid var(--line);
  border-radius: 12px; padding: 9px 7px; text-align: center; user-select: none;
}
.pcard .av { font-size: 24px; line-height: 1.1; }
.pcard .nm { font-size: 12.5px; font-weight: 700; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pcard .rl { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pcard .seat { position: absolute; top: 4px; left: 6px; font-size: 10px; color: var(--muted); }
.pcard.dead { opacity: .38; filter: grayscale(1); }
.pcard.sel { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent); }
.pcard.tap { cursor: pointer; }
.pcard.tap:active { transform: scale(.96); }
.pcard .tags { display: flex; gap: 3px; justify-content: center; margin-top: 3px; }
.tag { font-size: 9.5px; padding: 1px 5px; border-radius: 999px; background: var(--line); color: var(--muted); }
.tag.mod { background: var(--gold); color: #2a1d00; }
.tag.wolf { background: var(--bad); color: #fff; }
.tag.you { background: var(--accent); color: #fff; }
.tag.talk { background: var(--ok); color: #04220b; }
.tag.silenced { background: #8b2fb0; color: #fff; }

/* ── Turn panel (player acting) ──────────────────── */
.turn-panel { border-color: var(--accent); box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 40%, transparent); }
.turn-panel .who { font-size: 18px; font-weight: 800; }
.verbs { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.chip { padding: 7px 13px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel2); font-size: 13.5px; font-weight: 600; }
.chip.on { background: var(--accent); color: #fff; border-color: transparent; }
.picked { font-size: 14px; margin: 6px 0; min-height: 22px; }
.picked b { color: var(--accent); }

/* ── Mod panel ───────────────────────────────────── */
.qitem { display: flex; align-items: center; gap: 8px; padding: 7px 9px; border-radius: 9px; background: var(--panel2); margin-bottom: 6px; font-size: 13.5px; }
.qitem.now { border: 1px solid var(--warn); background: color-mix(in srgb, var(--warn) 14%, var(--panel2)); }
.qitem.done { opacity: .45; }
.vote-row { display: flex; justify-content: space-between; padding: 5px 8px; border-radius: 8px; background: var(--panel2); margin-bottom: 4px; font-size: 13.5px; }
.vote-row b { color: var(--gold); }

/* ── Log / chat ──────────────────────────────────── */
.log { max-height: 34vh; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.msg { background: var(--panel2); border-radius: 10px; padding: 7px 10px; font-size: 14px; overflow-wrap: anywhere; }
.msg .who { font-weight: 700; color: var(--accent); }
.msg.sys { color: var(--muted); font-style: italic; }
.msg.phase { background: color-mix(in srgb, var(--accent2) 22%, var(--panel2)); font-weight: 700; }
.msg.death { background: color-mix(in srgb, var(--bad) 22%, var(--panel2)); }
.msg.win { background: color-mix(in srgb, var(--gold) 26%, var(--panel2)); font-weight: 800; }
.msg.night_call { background: color-mix(in srgb, var(--warn) 18%, var(--panel2)); }
.msg .tagline { font-size: 11px; color: var(--muted); }

.chatbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; display: flex; gap: 7px; padding: 8px 12px calc(8px + var(--safe-b));
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(10px); border-top: 1px solid var(--line); }
.chatbar input { flex: 1; padding: 10px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel2); }

/* ── Private info ────────────────────────────────── */
.info-item { background: var(--panel2); border-left: 3px solid var(--accent2); border-radius: 8px; padding: 8px 10px; margin-bottom: 6px; font-size: 13.5px; }
.info-item .t { font-weight: 800; color: var(--accent2); font-size: 12.5px; }
.info-item .n { color: var(--muted); font-size: 11px; }
.info-item.new { animation: pop .5s; }
@keyframes pop { from { transform: translateY(-6px); opacity: 0; } }

/* ── Role picker ─────────────────────────────────── */
.role-tabs { display: flex; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.role-list { max-height: 42vh; overflow-y: auto; display: grid; gap: 6px; }
.role-item { display: flex; gap: 9px; align-items: flex-start; background: var(--panel2); border: 2px solid transparent;
  border-radius: 10px; padding: 8px 10px; cursor: pointer; }
.role-item.on { border-color: var(--ok); }
.role-item .n { font-weight: 700; font-size: 14px; }
.role-item .d { font-size: 12px; color: var(--muted); }
.counter { font-weight: 800; color: var(--gold); }

/* ── Modal / overlay ─────────────────────────────── */
.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 18px;
  background: rgba(4,7,12,.78); backdrop-filter: blur(3px); }
.modal .box { width: min(520px, 100%); max-height: 88dvh; overflow-y: auto; background: var(--panel);
  border: 1px solid var(--line); border-radius: 16px; padding: 20px; }
.winbox { text-align: center; }
.winbox .big { font-size: 40px; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); top: 62px; z-index: 70;
  background: var(--bad); color: #fff; padding: 9px 16px; border-radius: 999px; font-size: 14px; max-width: 92vw; }
.toast.ok { background: var(--ok); color: #04220b; }

.night-veil { position: fixed; inset: 0; pointer-events: none; z-index: 5;
  background: radial-gradient(circle at 50% 40%, transparent 30%, rgba(40,10,80,.28) 100%); }
.day-veil { position: fixed; inset: 0; pointer-events: none; z-index: 5;
  background: radial-gradient(circle at 50% 30%, rgba(255,200,80,.10), transparent 60%); }

.spinner { width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: sp .7s linear infinite; display: inline-block; }
@keyframes sp { to { transform: rotate(360deg); } }

.rolelist-compact { max-height: 46vh; overflow-y: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl td, .tbl th { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.tbl th { color: var(--muted); font-weight: 600; }
