:root {
  color-scheme: dark;
  --bg: #0b0d11;
  --surface: #15181e;
  --surface-2: #1e222b;
  --surface-3: #292e38;
  --line: #343a46;
  --text: #f4f6f8;
  --muted: #a7afbc;
  --accent: #ff5f6d;
  --accent-2: #ffc857;
  --good: #21c7a8;
  --danger: #f14d58;
  --focus: #7ab8ff;
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body { min-height: 100vh; margin: 0; color: var(--text); background: var(--bg); }
button, input, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .48; }
input, select {
  width: 100%; min-height: 44px; padding: 10px 12px; color: var(--text);
  border: 1px solid var(--line); border-radius: 6px; background: #0f1217;
}
input:focus, select:focus, button:focus-visible { outline: 3px solid color-mix(in srgb, var(--focus) 55%, transparent); outline-offset: 2px; }
label { color: #d9dee5; font-size: .9rem; font-weight: 650; }
h1, h2, h3, p { margin-top: 0; }
h1 { max-width: 720px; margin-bottom: 0; font-size: clamp(2.1rem, 6vw, 4.7rem); line-height: .98; }
h2 { font-size: 1rem; }

.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  min-height: 62px; padding: 8px max(18px, env(safe-area-inset-right)) 8px max(18px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line); background: rgba(11,13,17,.94); backdrop-filter: blur(12px);
}
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); font-weight: 850; text-decoration: none; }
.brand-mark {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 7px;
  color: #101216; background: var(--accent); font-family: Georgia, serif; font-size: 1.45rem; font-style: italic;
}
.top-actions, .room-actions { display: flex; align-items: center; gap: 8px; }
.connection { color: var(--muted); font-size: .78rem; }
.connection[data-state="online"]::before { background: var(--good); }
.connection[data-state="offline"]::before { background: var(--danger); }
.connection::before { display: inline-block; width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; background: #697180; content: ""; }
.icon-button { min-width: 38px; min-height: 38px; border: 1px solid var(--line); border-radius: 6px; color: var(--text); background: var(--surface); font-weight: 800; }
.app-shell { width: min(1500px, 100%); margin: 0 auto; padding: 24px; }

.entry-view { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(320px, .75fr); align-items: end; gap: 7vw; min-height: calc(100vh - 112px); padding: 6vh 2vw 10vh; }
.entry-heading { align-self: center; }
.eyebrow { margin-bottom: 8px; color: var(--accent-2); font-size: .76rem; font-weight: 800; text-transform: uppercase; }
.entry-panel { padding: 22px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin-bottom: 22px; padding: 4px; border-radius: 7px; background: #0e1116; }
.segment { min-height: 40px; border: 0; border-radius: 5px; color: var(--muted); background: transparent; font-weight: 750; }
.segment.active { color: var(--text); background: var(--surface-3); }
.entry-form { display: grid; gap: 10px; }
.entry-form label:not(:first-child) { margin-top: 5px; }
.code-input { text-transform: uppercase; font-weight: 850; letter-spacing: .14em; }
.check-row { display: flex; align-items: center; gap: 9px; min-height: 38px; }
.check-row input { width: 18px; min-height: auto; accent-color: var(--accent); }

.primary, .secondary, .danger, .danger-quiet {
  min-height: 42px; padding: 9px 14px; border-radius: 6px; font-weight: 800;
}
.primary { border: 1px solid var(--accent); color: #101216; background: var(--accent); }
.primary:hover { filter: brightness(1.08); }
.secondary { border: 1px solid var(--line); color: var(--text); background: var(--surface-3); }
.danger { border: 1px solid var(--danger); color: white; background: var(--danger); }
.danger-quiet { border: 1px solid #71313a; color: #ffabb2; background: transparent; }
.wide { width: 100%; margin-top: 8px; }

.room-view { min-width: 0; }
.room-bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px; margin-bottom: 14px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.room-code { padding: 0; border: 0; color: var(--text); background: transparent; font-size: 1.32rem; font-weight: 900; letter-spacing: .13em; }
.room-state { text-align: center; }
.room-state span { display: block; color: var(--muted); font-size: .76rem; text-transform: uppercase; }
.timer { display: block; font-variant-numeric: tabular-nums; font-size: 1.35rem; }
.room-actions { justify-content: flex-end; }

.game-layout { display: grid; grid-template-columns: minmax(0, 1fr) 280px; grid-template-areas: "stage people" "chat people"; gap: 14px; }
.stage, .people-panel, .chat-panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.stage { grid-area: stage; min-height: 480px; padding: 20px; overflow: hidden; }
.people-panel { grid-area: people; padding: 15px; }
.chat-panel { grid-area: chat; display: grid; grid-template-rows: auto minmax(130px, 210px) auto; padding: 15px; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.panel-heading h2 { margin: 0; }
.count-badge { display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; color: #101216; background: var(--accent-2); font-size: .72rem; font-weight: 850; }
.players-list { display: grid; gap: 6px; margin-top: 14px; }
.player-row { display: grid; grid-template-columns: 30px minmax(0, 1fr) auto; align-items: center; gap: 9px; min-height: 42px; padding: 5px 6px; border-bottom: 1px solid #292e37; }
.avatar { display: grid; place-items: center; width: 29px; height: 29px; border-radius: 50%; color: #101216; font-size: .72rem; font-weight: 900; }
.player-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .86rem; }
.player-meta { color: var(--muted); font-size: .68rem; }
.player-actions { display: flex; gap: 4px; }
.mini-button { min-height: 29px; padding: 4px 7px; border: 1px solid var(--line); border-radius: 5px; color: var(--muted); background: transparent; font-size: .67rem; }
.messages { overflow-y: auto; padding: 10px 0; scrollbar-color: #4a515f transparent; }
.message { display: grid; grid-template-columns: 8px 1fr; gap: 8px; padding: 5px 2px; color: #dfe3e9; font-size: .82rem; }
.message-dot { width: 7px; height: 7px; margin-top: 6px; border-radius: 50%; background: #5c6471; }
.message.system { color: var(--muted); font-style: italic; }
.message strong { font-weight: 780; }
.message time { margin-left: 5px; color: #697180; font-size: .66rem; }
.chat-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; }

.stage-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.stage-header h2 { margin-bottom: 5px; font-size: clamp(1.35rem, 3vw, 2rem); }
.stage-copy { color: var(--muted); line-height: 1.55; }
.stage-center { display: grid; place-items: center; min-height: 330px; text-align: center; }
.stage-center > div { width: min(680px, 100%); }
.role-card { position: relative; overflow: hidden; min-height: 270px; padding: 34px 24px; border: 1px solid var(--line); border-radius: 8px; background: #0d1015; }
.role-label { color: var(--accent-2); font-size: .8rem; font-weight: 850; text-transform: uppercase; }
.role-word { margin: 20px 0 8px; overflow-wrap: anywhere; font-size: clamp(2.25rem, 9vw, 5.2rem); font-weight: 950; line-height: .92; }
.role-card.impostor { border-color: #8d3540; }
.role-card.impostor .role-label { color: var(--accent); }
.privacy-cover { position: absolute; inset: 0; display: grid; place-items: center; padding: 20px; border: 0; color: white; background: #141820; font-weight: 850; }
.action-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 18px; }
.config-form { display: grid; grid-template-columns: repeat(4, minmax(120px, 1fr)); gap: 12px; }
.config-form .field { display: grid; gap: 6px; }
.config-form .toggle-field { display: flex; align-items: center; gap: 8px; min-height: 44px; padding-top: 20px; }
.toggle-field input { width: 18px; min-height: auto; accent-color: var(--accent); }
.config-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; margin-top: 4px; }
.clue-history { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px; margin-top: 16px; }
.clue { min-height: 68px; padding: 10px; border-left: 3px solid var(--accent-2); background: var(--surface-2); }
.clue small { display: block; color: var(--muted); }
.clue strong { display: block; margin-top: 4px; overflow-wrap: anywhere; }
.turn-box { padding: 20px; border: 1px solid var(--line); border-radius: 7px; background: #101318; text-align: center; }
.turn-box h3 { margin-bottom: 7px; font-size: 1.6rem; }
.inline-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; width: min(560px, 100%); margin: 16px auto 0; }
.candidate-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(145px, 1fr)); gap: 9px; margin-top: 18px; }
.candidate { min-height: 72px; padding: 10px; border: 1px solid var(--line); border-radius: 7px; color: var(--text); background: var(--surface-2); text-align: left; }
.candidate.selected { border-color: var(--accent-2); box-shadow: inset 0 0 0 1px var(--accent-2); }
.candidate:disabled { opacity: .38; }
.result-banner { padding: 22px; border-left: 5px solid var(--accent-2); background: var(--surface-2); }
.result-banner.win { border-color: var(--good); }
.result-banner.loss { border-color: var(--accent); }
.word-list { display: flex; flex-wrap: wrap; gap: 7px; justify-content: center; margin-top: 13px; }
.word-chip { padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px; color: var(--muted); background: #0e1116; }

dialog { width: min(560px, calc(100% - 32px)); padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); color: var(--text); background: var(--surface); }
dialog::backdrop { background: rgba(0,0,0,.72); }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; }
.dialog-heading h2 { margin: 0; font-size: 1.25rem; }
.rules { display: grid; gap: 12px; padding-left: 22px; color: #d8dde4; line-height: 1.45; }
.toast { position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); z-index: 50; max-width: min(440px, calc(100% - 32px)); padding: 11px 16px; border: 1px solid var(--line); border-radius: 7px; background: #222730; opacity: 0; pointer-events: none; transform: translate(-50%, 14px); transition: .18s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: #863842; color: #ffd4d8; }
.mobile-only { display: none; }

@media (max-width: 900px) {
  .app-shell { padding: 14px; }
  .entry-view { grid-template-columns: 1fr; align-items: center; gap: 34px; min-height: auto; padding: 8vh 0; }
  .entry-heading { padding: 0 6px; }
  .game-layout { grid-template-columns: 1fr; grid-template-areas: "stage" "people"; }
  .stage { min-height: 450px; padding: 15px; }
  .people-panel { min-height: 0; }
  .chat-panel { position: fixed; inset: 62px 0 0; z-index: 30; grid-template-rows: auto 1fr auto; border-radius: 0; padding: 16px; transform: translateY(105%); transition: transform .2s ease; }
  .chat-panel.open { transform: translateY(0); }
  .floating-chat { position: fixed; right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); z-index: 25; min-height: 44px; padding: 10px 14px; border: 1px solid var(--accent); border-radius: 6px; color: #111318; background: var(--accent); font-weight: 850; }
  .mobile-only { display: inline-flex; align-items: center; justify-content: center; }
  .config-form { grid-template-columns: repeat(2, minmax(120px, 1fr)); }
}

@media (max-width: 600px) {
  .topbar { min-height: 56px; padding: 7px 12px; }
  .brand { font-size: .93rem; }
  .brand-mark { width: 31px; height: 31px; }
  .connection { display: none; }
  .app-shell { padding: 8px; }
  .entry-view { padding: 5vh 0; }
  h1 { font-size: 2.6rem; }
  .entry-panel { padding: 15px; }
  .room-bar { grid-template-columns: 1fr auto; gap: 8px; padding: 9px 10px; }
  .room-state { text-align: right; }
  .room-actions { grid-column: 1 / -1; }
  .room-actions button { flex: 1; }
  .stage { min-height: 520px; }
  .stage-header { display: block; }
  .config-form { grid-template-columns: 1fr 1fr; gap: 9px; }
  .config-form .toggle-field { padding-top: 4px; }
  .inline-form { grid-template-columns: 1fr; }
  .candidate-grid { grid-template-columns: 1fr 1fr; }
}

.admin-page { min-height: 100vh; background: var(--bg); }
.admin-shell { width: min(1320px, calc(100% - 32px)); margin: 0 auto; padding: 32px 0 56px; }
.admin-heading, .section-toolbar, .topbar-actions, .toolbar-controls, .row-actions, .dialog-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.admin-heading h1 { margin: 0; font-size: clamp(1.75rem, 4vw, 2.7rem); }
.eyebrow { margin: 0 0 4px; color: var(--accent-2); font-size: .75rem; font-weight: 850; text-transform: uppercase; }
.muted { color: var(--muted); }
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 24px 0; }
.stat { padding: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.stat span { display: block; color: var(--muted); font-size: .76rem; text-transform: uppercase; }
.stat strong { display: block; margin-top: 7px; font-size: 1.85rem; }
.admin-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
.admin-tab { min-height: 44px; padding: 8px 18px; border: 0; border-bottom: 3px solid transparent; color: var(--muted); background: transparent; font-weight: 800; }
.admin-tab.active { border-color: var(--accent); color: var(--text); }
.admin-section { display: none; padding-top: 22px; }
.admin-section.active { display: block; }
.section-toolbar { margin-bottom: 14px; }
.section-toolbar h2 { margin: 0 0 3px; }
.section-toolbar p { margin: 0; }
.section-toolbar input { width: min(330px, 100%); }
.table-scroll { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 11px 13px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { position: sticky; top: 0; z-index: 1; color: var(--muted); background: var(--surface-2); font-size: .72rem; text-transform: uppercase; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(255,255,255,.025); }
.room-table-code { letter-spacing: .1em; }
.status-pill { display: inline-block; padding: 4px 7px; border: 1px solid var(--line); border-radius: 5px; color: var(--muted); font-size: .7rem; font-weight: 800; }
.status-pill.enabled { border-color: #285d46; color: #8be0b0; }
.status-pill.disabled { border-color: #69353b; color: #eaa3aa; }
.compact { min-height: 31px; padding: 4px 8px; font-size: .72rem; }
.empty-row { padding: 32px; color: var(--muted); text-align: center; }
details summary { cursor: pointer; color: var(--accent-2); }
details pre { max-width: 420px; overflow: auto; white-space: pre-wrap; color: var(--muted); font-size: .7rem; }
.admin-form { display: grid; gap: 13px; }
.admin-form label { display: grid; gap: 5px; font-weight: 750; }
.related-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.check-label { display: flex !important; align-items: center; grid-template-columns: auto 1fr; }
.check-label input { width: 18px; min-height: 18px; accent-color: var(--accent); }
.dialog-actions { justify-content: flex-end; }
@media (max-width: 760px) {
  .admin-shell { width: min(100% - 16px, 1320px); padding-top: 18px; }
  .admin-heading, .section-toolbar { align-items: stretch; flex-direction: column; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .toolbar-controls { align-items: stretch; flex-direction: column; }
  .section-toolbar input, .toolbar-controls input { width: 100%; }
  .related-grid { grid-template-columns: 1fr; }
}
