:root {
  color-scheme: dark;
  --table: #221939; --table-2: #35274e; --glow: #492f61; --ink: #160e23;
  --cream: #fff1dd; --muted: #dccbe2; --pop: #ffda75; --paper: #f6e6c9;
  --focus: #ffda75; --safe: #bcdec0; --danger: #a52d46; --danger-light: #ffd1d9;
  --shadow: 0 4px 0 var(--ink);
  --display: Chonburi, Kanit, sans-serif;
}
:root[data-phase=day], :root[data-phase=vote] {
  color-scheme: light;
  --table: #ffd5b4; --table-2: #ffe4cc; --glow: #f3ad91;
  --cream: #2d1831; --muted: #5c3a53; --pop: #ffd461; --focus: #6f3975;
  --danger: #96263d; --danger-light: #78182f;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; color: var(--cream); font: 400 16px/1.5 Kanit, sans-serif;
  background: radial-gradient(ellipse at 50% 0%, var(--glow), transparent 70%), radial-gradient(circle, #aa7b9d45 1px, transparent 1px), var(--table);
  background-size: 100% 100%, 22px 22px, auto; background-attachment: fixed;
}
main { min-height: 100dvh; }
h1, h2, h3, p, ul { margin: 0; overflow-wrap: anywhere; }
h1, h2, .stamp, .eyebrow, .seal, .ticket strong, .room-pill { font-family: var(--display); }
h1 { font-weight: 400; line-height: 1.2; }
h2 { font-size: 22px; font-weight: 400; }
h3 { font-size: 18px; font-weight: 600; }
button, input { font: inherit; }
button, input, .ticket, .panel, .peek, .hero { border: 3px solid var(--ink); box-shadow: var(--shadow); }
button {
  min-width: 44px; min-height: 48px; border-radius: 999px; padding: 8px 15px;
  background: var(--paper); color: var(--ink); font-weight: 600; cursor: pointer;
  transition: transform 150ms, box-shadow 150ms; overflow-wrap: anywhere;
}
button:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
button:disabled { opacity: .63; cursor: default; box-shadow: none; }
button.primary, button[aria-pressed=true] { background: var(--pop); }
button[aria-pressed=true]::before { content: '✓ '; }
button.large { width: 100%; min-height: 58px; font-size: 21px; }
button.quiet { color: var(--cream); background: var(--table-2); }
button.danger { background: var(--danger); color: #fff2e9; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
input { width: 100%; min-height: 50px; min-width: 0; border-radius: 14px; background: var(--paper); color: var(--ink); padding: 8px 12px; font-size: 18px; }
input::placeholder { color: #65516c; }
input[type=checkbox], input[type=radio] { width: 20px; height: 20px; min-height: 20px; box-shadow: none; vertical-align: middle; accent-color: #755093; }
.setup { width: 100%; max-width: 568px; margin: auto; display: grid; gap: 18px; padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 28px max(14px, env(safe-area-inset-left)); }
.home-controls { display: flex; justify-content: flex-end; }
.hero {
  height: clamp(170px, 45vw, 255px); display: grid; place-items: center; overflow: hidden;
  border-radius: 24px; background: radial-gradient(circle at 50% 45%, #ffe39c 0 25%, #37274e 25.3%, #241933 65%);
  transform: rotate(-1.5deg); position: relative;
}
.hero::before, .hero::after {
  content: '✦'; position: absolute; inset: 18% auto auto 15%; color: #ffdf8c; font-size: 28px;
}
.hero::after { inset: 30% 17% auto auto; font-size: 19px; }
.hero span { font-size: clamp(79px, 20vw, 122px); filter: drop-shadow(0 7px 0 #160e2390); transform: translateY(-8%); }
.title { display: grid; justify-items: center; text-align: center; gap: 8px; margin-top: -50px; z-index: 1; }
.title h1 { font-size: clamp(35px, 11vw, 65px); color: var(--ink); padding: 8px 12px; background: var(--pop); border: 3px solid var(--ink); border-radius: 10px; box-shadow: var(--shadow); transform: rotate(-2deg); }
.title p { font-size: 22px; font-weight: 600; }
.eyebrow { color: var(--muted); border: 2px solid currentColor; border-radius: 999px; padding: 2px 12px; }
.home-form { display: grid; gap: 10px; }
.home-form label { color: var(--muted); }
.home-form button.large { margin: 3px 0 8px; }
.join { display: flex; gap: 8px; }
.join button { flex-shrink: 0; }
.panel { min-width: 0; padding: 14px; border-radius: 16px; background: var(--table-2); }
.panel summary { cursor: pointer; min-height: 44px; align-content: center; font-size: 20px; }
.guide > :not(summary) { margin-top: 10px; }
.guide-role { padding: 8px 0; border-top: 1px solid color-mix(in srgb, var(--muted) 40%, transparent); }
.guide-role p { color: var(--muted); }
.room { padding-bottom: calc(92px + env(safe-area-inset-bottom)); }
.room-controls { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.room-pill { letter-spacing: .08em; }
.phase-title { text-align: center; font-size: clamp(24px, 7vw, 33px); }
.ticket { display: grid; justify-items: center; gap: 6px; padding: 16px; border-radius: 18px; background: var(--pop); color: var(--ink); transform: rotate(-1deg); }
.ticket strong { font-size: clamp(28px, 9vw, 55px); letter-spacing: .07em; line-height: 1.2; }
.players { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.room:not([data-phase=lobby]) .players { order: 6; }
.room:not([data-phase=lobby]) .log { order: 7; }
.round-controls { order: 8; }
.player-chip { display: grid; grid-template-columns: 31px minmax(0, 1fr); align-items: center; gap: 0 7px; min-height: 46px; padding: 4px 7px; background: var(--table-2); border: 2px solid var(--ink); border-radius: 13px; overflow-wrap: anywhere; }
.player-chip .initial { grid-row: span 2; width: 30px; height: 30px; display: grid; place-items: center; border-radius: 50%; background: var(--paper); color: var(--ink); }
.player-chip small { grid-column: 2; line-height: 1.2; color: var(--muted); }
.player-chip.offline { border-style: dashed; }
.player-chip.dead { border-color: var(--danger); }
.player-chip.dead .initial { background: #ffcdd3; }
.clock { color: var(--pop); text-align: center; font: 600 clamp(46px, 14vw, 77px)/1 Kanit, sans-serif; font-variant-numeric: tabular-nums; }
[data-phase=day] .clock, [data-phase=vote] .clock { color: #692c56; }
.clock::before { content: ''; display: block; height: 9px; margin: 0 auto 8px; border: 2px solid var(--ink); border-radius: 999px; background: linear-gradient(to right, currentColor calc(var(--left, 1) * 100%), var(--table-2) 0); }
.clock.urgent { color: var(--danger-light); }
.peek { position: relative; width: 100%; border-radius: 12px 17px 17px 17px; background: var(--paper); color: var(--ink); overflow: hidden; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: none; }
.peek:active:not(:disabled) { transform: none; box-shadow: var(--shadow); }
.peek::before { content: ''; position: absolute; inset: 0 0 auto; height: 8px; background: repeating-linear-gradient(-45deg, var(--ink) 0 10px, var(--pop) 10px 20px); border-bottom: 2px solid var(--ink); }
.cover { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 0 8px; padding-top: 7px; }
.cover strong { font-size: 19px; }
.cover small { color: #61476d; width: 100%; }
.card-back { font-size: 24px; }
.seal { color: #971e3a; border: 2px solid currentColor; border-radius: 5px; padding: 0 5px; transform: rotate(10deg); font-size: 13px; }
.secret { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 20px; background: #160e23ed; pointer-events: none; }
.role-card { width: min(100%, 420px); max-height: 82dvh; overflow: auto; pointer-events: auto; display: grid; gap: 10px; padding: 16px; border: 4px solid var(--ink); border-radius: 22px; background: var(--paper); color: var(--ink); box-shadow: 0 8px 0 #0009; animation: reveal-in 180ms both; }
.role-card header { display: grid; justify-items: center; padding: 8px; border: 3px solid var(--ink); border-radius: 12px; background: var(--safe); }
.role-card[data-team=wolf] header { color: #fff2e9; background: var(--danger); }
.role-card[data-team=solo] header { background: var(--pop); }
.role-emoji { font-size: clamp(36px, 13vw, 70px); line-height: 1.1; }
.role-card strong { font: 400 23px/1.5 var(--display); text-align: center; }
.team { font-size: 15px; }
.notes { padding: 0 0 0 20px; }
.phase, .deck, .log-items, .report, .night-body { display: grid; gap: 10px; }
.phase > .prompt, .phase > .muted, .phase > .waiting, .phase > p { text-align: center; }
.prompt { font-size: 20px; font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 3px 9px; border: 2px solid var(--ink); border-radius: 999px; background: var(--paper); color: var(--ink); font-size: 14px; }
.toggle { display: flex; align-items: center; width: fit-content; min-height: 44px; gap: 6px; cursor: pointer; }
.steppers { display: grid; gap: 5px; }
.step { display: grid; grid-template-columns: minmax(0, 1fr) 44px 23px 44px; gap: 4px; align-items: center; }
.step button { min-height: 44px; padding: 2px; font-size: 20px; }
.step strong { text-align: center; }
.times { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; padding: 0; border: 0; margin: 0; }
.times legend { margin-bottom: 6px; }
.times label { display: flex; align-items: center; justify-content: center; min-height: 48px; gap: 3px; background: var(--table-2); border: 2px solid var(--ink); border-radius: 12px; cursor: pointer; }
.muted { color: var(--muted); }
.waiting { padding: 14px 12px; border: 2px dashed var(--muted); border-radius: 14px; }
.targets { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.targets button { min-width: 0; padding-inline: 8px; border-radius: 15px; }
.event { padding: 8px 10px; border-inline-start: 3px solid currentColor; background: var(--table); border-radius: 6px; }
.event.death { color: var(--danger-light); border-color: var(--danger); }
.voters { padding-inline-start: 19px; }
.results { list-style: none; display: grid; gap: 8px; padding: 0; }
.results li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 8px; }
.results li span { grid-column: 1; }
.results li small { grid-column: 2; grid-row: 1; }
.results .winner { background: var(--pop); color: var(--ink); }
.stamp { justify-self: center; text-align: center; margin: 4px 0; padding: 8px 14px; border: 4px solid currentColor; border-radius: 12px; background: #231832; color: #ffda75; font-size: clamp(23px, 7vw, 38px); transform: rotate(-3deg); }
.bar { position: fixed; z-index: 10; inset: auto 0 0; display: flex; align-items: center; justify-content: center; gap: 4px; padding: 8px max(4px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(4px, env(safe-area-inset-left)); border-top: 3px solid var(--ink); background: var(--table); }
.reactions { display: flex; gap: 2px; justify-content: center; }
.reactions button { min-width: 44px; min-height: 44px; padding: 3px; font-size: 19px; }
.host-menu summary { list-style: none; width: 44px; min-height: 44px; display: grid; place-items: center; border: 2px solid var(--muted); border-radius: 999px; cursor: pointer; }
.host-menu summary::-webkit-details-marker { display: none; }
.host-menu[open] > button { position: absolute; right: 10px; bottom: calc(100% + 8px); }
.host-menu[open] > button + button { bottom: calc(100% + 64px); }
.settings-wrap { position: relative; flex: 0 0 48px; }
.sound { width: 48px; padding: 5px; }
.settings { position: absolute; z-index: 20; top: calc(100% + 8px); right: 0; width: min(290px, calc(100vw - 28px)); padding: 12px; display: grid; gap: 10px; background: var(--paper); color: var(--ink); border: 3px solid var(--ink); border-radius: 16px; box-shadow: var(--shadow); }
.settings-row { display: flex; gap: 8px; align-items: center; }
.settings-row input[type=range] { padding: 0; border: 0; box-shadow: none; accent-color: #755093; }
.settings-row button, .settings-row span { flex-shrink: 0; }
.settings-row button { padding: 7px; }
.connection:not(:empty) { position: sticky; top: 0; z-index: 30; padding: 8px; color: var(--ink); background: var(--pop); text-align: center; }
.toast:empty { display: none; }
.toast { position: fixed; z-index: 70; bottom: calc(80px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); width: max-content; max-width: calc(100vw - 28px); border: 3px solid var(--ink); background: var(--paper); color: var(--ink); padding: 8px 14px; border-radius: 14px; pointer-events: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.sheet { width: min(480px, calc(100vw - 22px)); max-height: 85dvh; overflow: auto; margin: auto; padding: 14px; border: 3px solid var(--ink); border-radius: 20px; color: var(--cream); background: var(--table); }
.sheet[open] { display: grid; gap: 12px; }
.sheet::backdrop { background: #160e23ed; }
.night-sheet > header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.reveal { background: var(--table-2); }
.reveal-stack { display: grid; gap: 8px; }
.reveal-stack:empty { display: none; }
.reveal-stack .event { animation: reveal-in 280ms both; animation-delay: calc(min(var(--stagger), 7) * 155ms); }
.floating-emoji { position: fixed; bottom: 90px; z-index: 75; pointer-events: none; font-size: 44px; }
@keyframes reveal-in { from { opacity: 0; transform: translateY(10px) scale(.97); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }
@media (max-width: 350px) {
  .bar, .reactions { gap: 0; }
  .bar { padding-inline: max(3px, env(safe-area-inset-left)) max(3px, env(safe-area-inset-right)); }
}
