:root {
  color-scheme: dark;
  --bg: #08080c;
  --surface: rgba(22, 22, 30, .72);
  --surface-2: rgba(255, 255, 255, .045);
  --surface-3: rgba(255, 255, 255, .08);
  --border: rgba(255, 255, 255, .08);
  --border-strong: rgba(255, 255, 255, .16);
  --text: #f1f1f4;
  --muted: #8d8d9c;
  --faint: #5d5d6b;
  --accent: #e5484d;
  --accent-soft: rgba(229, 72, 77, .14);
  --good: #3dd68c;
  --good-soft: rgba(61, 214, 140, .13);
  --warn: #f5b546;
  --warn-soft: rgba(245, 181, 70, .14);
  --me: #8b7cff;
  --radius: 18px;
  --radius-sm: 11px;
  --shadow: 0 1px 0 rgba(255, 255, 255, .05) inset, 0 24px 60px -24px rgba(0, 0, 0, .7);
  --font: 'Geist', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --serif: 'Instrument Serif', ui-serif, Georgia, serif;
  --mono: 'Geist Mono', ui-monospace, Menlo, monospace;
  /* phase mood, swapped via body[data-phase] */
  --glow-a: #e5484d;
  --glow-b: #5b4bff;
  --felt-a: #1b1b26;
  --felt-b: #101017;
  --rim: rgba(255, 255, 255, .07);
}
body[data-phase="night"] { --glow-a: #3b4cff; --glow-b: #7a3cff; --felt-a: #121633; --felt-b: #0a0b1a; --rim: rgba(130, 140, 255, .18); }
body[data-phase="speech"] { --glow-a: #f5b546; --glow-b: #e5484d; --felt-a: #2a1f14; --felt-b: #140f0b; --rim: rgba(245, 181, 70, .2); }
body[data-phase="vote"] { --glow-a: #e5484d; --glow-b: #f5b546; --felt-a: #2a1418; --felt-b: #140a0c; --rim: rgba(229, 72, 77, .24); }
body[data-phase="ended"] { --glow-a: #3dd68c; --glow-b: #8b7cff; --felt-a: #12241c; --felt-b: #0a120e; --rim: rgba(61, 214, 140, .2); }
body[data-phase="ended"][data-winner="mafia"] { --glow-a: #e5484d; --glow-b: #7a1f2b; --felt-a: #2a1014; --felt-b: #12080a; --rim: rgba(229, 72, 77, .3); }
body[data-winner="mafia"] .phase-icon { color: #ff8a8e !important; }

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 var(--font); letter-spacing: -.005em;
  -webkit-font-smoothing: antialiased;
  display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh;
}
main { flex: 1; width: 100%; max-width: 1480px; margin: 0 auto; padding: 24px 28px 28px; position: relative; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.02em; }
h2 { font-size: 1.05rem; }
h3 { font-size: .78rem; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); font-weight: 600; margin-bottom: 10px; }
p { margin: 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small-text { font-size: .84rem; font-weight: 400; }
.error { color: #ff8a8e; min-height: 1.2em; margin: 6px 0; font-size: .88rem; }
.error:empty { display: none; }
.spacer { flex: 1; }
::selection { background: rgba(229, 72, 77, .35); }

/* ambient background */
.backdrop { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.orb { position: absolute; width: 60vmax; height: 60vmax; border-radius: 50%; filter: blur(90px); opacity: .22; transition: background 1.2s ease; }
.orb-a { background: var(--glow-a); top: -30vmax; left: -18vmax; }
.orb-b { background: var(--glow-b); bottom: -34vmax; right: -20vmax; opacity: .16; }
.grain { position: absolute; inset: 0; opacity: .05; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"); }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 14px; padding: 12px 28px;
  background: rgba(8, 8, 12, .6); backdrop-filter: blur(18px) saturate(1.4); -webkit-backdrop-filter: blur(18px) saturate(1.4);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 9px; font-family: var(--serif); font-size: 1.45rem; letter-spacing: 0; line-height: 1; }
.brand-mark { width: 26px; height: 26px; }
.brand-mark rect:first-child { fill: var(--accent); }
.brand-mark path, .brand-mark rect + rect, .brand-mark path + rect { fill: #fff; }
.room-pill {
  display: inline-flex; align-items: center; gap: 8px; padding: 5px 6px 5px 12px; border-radius: 99px;
  font-size: .8rem; color: var(--muted); background: var(--surface-2);
}
.room-pill .code { background: var(--warn-soft); color: var(--warn); padding: 2px 9px; border-radius: 99px; }
.code { font-family: var(--mono); font-weight: 600; letter-spacing: .14em; }
.phase-chip:empty { display: none; }
.phase-chip { font-weight: 600; font-size: .9rem; padding: 5px 12px 5px 10px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); display: inline-flex; align-items: center; gap: 8px; }
.phase-chip::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--glow-a); box-shadow: 0 0 10px var(--glow-a); }
.top-me { font-size: .86rem; }

/* controls */
label.field { display: flex; flex-direction: column; gap: 7px; color: var(--muted); font-size: .8rem; font-weight: 500; }
input {
  font: inherit; background: rgba(0, 0, 0, .28); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 11px 13px; font-size: .95rem; width: 100%;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
input::placeholder { color: var(--faint); }
input:hover { border-color: var(--border-strong); }
input:focus { outline: none; border-color: rgba(139, 124, 255, .7); box-shadow: 0 0 0 4px rgba(139, 124, 255, .16); background: rgba(0, 0, 0, .4); }
input[type=number] { font-variant-numeric: tabular-nums; }
button {
  font: inherit; font-weight: 550; font-size: .92rem; color: var(--text); cursor: pointer;
  background: var(--surface-3); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 16px;
  transition: background .15s, border-color .15s, transform .1s, box-shadow .15s, opacity .15s;
}
button:hover:not(:disabled) { background: rgba(255, 255, 255, .12); border-color: var(--border-strong); }
button:active:not(:disabled) { transform: scale(.97); }
button:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(139, 124, 255, .45); }
button:disabled { opacity: .4; cursor: not-allowed; }
button.primary {
  background: linear-gradient(180deg, #f05a5f, #d63c42); border-color: rgba(255, 255, 255, .14); color: #fff;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .25) inset, 0 10px 28px -10px rgba(229, 72, 77, .8);
}
button.primary:hover:not(:disabled) { background: linear-gradient(180deg, #f4686c, #dc444a); }
button.ghost { background: transparent; }
button.ghost:hover:not(:disabled) { background: var(--surface-2); }
button.small { padding: 6px 11px; font-size: .8rem; border-radius: 9px; }
button.danger { border-color: rgba(229, 72, 77, .35); color: #ffb1b3; background: var(--accent-soft); }
button.danger:hover:not(:disabled) { background: rgba(229, 72, 77, .22); border-color: rgba(229, 72, 77, .6); }
.big-btn { padding: 13px 18px; font-size: 1rem; width: 100%; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row input { flex: 1; min-width: 0; }
.bar { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 4px; }
.bar h3 { margin: 0; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 16px; }
.count-pill { font-size: .78rem; color: var(--muted); background: var(--surface-2); border: 1px solid var(--border); padding: 3px 10px; border-radius: 99px; font-variant-numeric: tabular-nums; }

/* switch */
label.check { display: flex; align-items: center; gap: 12px; font-size: .9rem; cursor: pointer; color: var(--text); }
input.switch {
  appearance: none; -webkit-appearance: none; flex: none; width: 38px; height: 22px; padding: 0; border-radius: 99px; cursor: pointer;
  background: rgba(255, 255, 255, .12); border: 1px solid var(--border); position: relative; transition: background .2s;
}
input.switch::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .4); transition: transform .2s cubic-bezier(.3, 1.4, .6, 1);
}
input.switch:checked { background: var(--good); border-color: transparent; }
input.switch:checked::after { transform: translateX(16px); }
input.switch:focus { box-shadow: 0 0 0 4px rgba(61, 214, 140, .2); }

/* screens enter */
.screen { animation: rise .45s cubic-bezier(.2, .8, .2, 1); }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

/* home */
#home { display: flex; flex-direction: column; align-items: center; padding-top: 7vh; }
.hero { text-align: center; margin-bottom: 30px; }
.eyebrow { font-size: .76rem; text-transform: uppercase; letter-spacing: .2em; color: var(--muted); margin-bottom: 14px; }
.hero h1 { font-family: var(--serif); font-weight: 400; font-size: clamp(3.2rem, 8vw, 5.6rem); line-height: .95; letter-spacing: -.03em; }
.hero h1 em { font-style: italic; background: linear-gradient(100deg, #ff7a7e, var(--accent) 60%, #b5303a); -webkit-background-clip: text; background-clip: text; color: transparent; padding-right: .06em; }
.hero-sub { margin-top: 14px; font-size: 1rem; }
.home-card { width: min(420px, 100%); display: flex; flex-direction: column; gap: 16px; padding: 26px; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--faint); font-size: .78rem; }
.divider::before, .divider::after { content: ''; flex: 1; border-top: 1px solid var(--border); }
.join-row { flex-wrap: nowrap; }
.code-input { font-family: var(--mono); font-weight: 600; letter-spacing: .3em; text-transform: uppercase; text-align: center; }
.code-input::placeholder { font-family: var(--font); letter-spacing: 0; font-weight: 400; text-transform: none; }
.join-row button { padding-inline: 22px; }

/* avatars */
.avatar {
  --h: 0; flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  font-size: .78rem; font-weight: 650; letter-spacing: 0; color: hsl(var(--h) 90% 88%);
  background: linear-gradient(140deg, hsl(var(--h) 55% 42%), hsl(calc(var(--h) + 40) 60% 26%));
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .12) inset;
}

/* lobby */
.lobby-grid { display: grid; grid-template-columns: minmax(320px, 1fr) minmax(400px, 1.15fr); gap: 20px; align-items: start; }
.list { list-style: none; padding: 0; margin: 0 0 16px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.list li {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; padding: 8px 8px 8px 10px;
  display: flex; align-items: center; gap: 10px; min-height: 52px;
}
.list li.offline { opacity: .55; }
.list .pname { flex: 1; min-width: 0; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; font-weight: 550; }
.list .pname > b { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.list li button { opacity: 0; }
.list li:hover button, .list li button:focus-visible { opacity: 1; }
@media (hover: none) { .list li button { opacity: 1; } }
.list li.empty { border-style: dashed; background: transparent; color: var(--faint); font-size: .85rem; justify-content: center; }
.share { font-size: .88rem; }
.share .code { color: var(--warn); background: var(--warn-soft); padding: 2px 8px; border-radius: 7px; cursor: pointer; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 10px; }
.role-field input { text-align: center; font-size: 1.15rem; font-weight: 600; padding: 9px; }
.role-field[data-team="mafia"] span { color: #ff8a8e; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.settings-rest { margin: 18px 0 4px; padding-top: 18px; border-top: 1px solid var(--border); }
.checks { display: flex; flex-direction: column; gap: 12px; justify-content: center; }
.summary { list-style: none; padding: 14px 16px; margin: 18px 0 14px; display: grid; gap: 6px; font-size: .88rem; color: var(--muted); background: rgba(0, 0, 0, .22); border-radius: 14px; border: 1px solid var(--border); }
.summary li { display: flex; gap: 10px; }
.summary li::before { content: ''; flex: none; width: 5px; height: 5px; border-radius: 50%; background: var(--faint); margin-top: .6em; }
.wait { display: flex; align-items: center; gap: 10px; justify-content: center; padding: 10px; }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: .2s; }
.dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; transform: scale(.85); } 40% { opacity: 1; transform: scale(1); } }

/* tags */
.tag {
  display: inline-flex; align-items: center; font-size: .66rem; font-weight: 600; letter-spacing: .03em; text-transform: uppercase;
  padding: 2px 7px; border-radius: 99px; background: var(--surface-3); color: var(--muted); margin-left: 4px; vertical-align: middle; text-decoration: none;
}
.tag.mafia { background: var(--accent-soft); color: #ff9a9d; box-shadow: 0 0 0 1px rgba(229, 72, 77, .25) inset; }
.tag.town { background: var(--good-soft); color: #8ef0bd; box-shadow: 0 0 0 1px rgba(61, 214, 140, .22) inset; }
.tag.host { background: var(--warn-soft); color: var(--warn); }
.tag.you { background: rgba(139, 124, 255, .16); color: #b9afff; }

/* game */
.game-grid { display: grid; grid-template-columns: 1fr 360px; gap: 22px; height: calc(100dvh - 110px); min-height: 640px; }
.table-wrap { position: relative; min-height: 0; }
.table { position: absolute; inset: 0; container-type: size; }
.felt {
  position: absolute; left: 13%; right: 13%; top: 15%; bottom: 15%; border-radius: 50%;
  background: radial-gradient(ellipse at 50% 35%, var(--felt-a), var(--felt-b) 75%);
  box-shadow: 0 0 0 1px var(--rim), 0 0 0 14px rgba(255, 255, 255, .02), 0 0 0 15px var(--border), 0 40px 120px -20px rgba(0, 0, 0, .9), 0 0 120px -30px var(--glow-a);
  transition: background 1s ease, box-shadow 1s ease;
}
.felt-inner { position: absolute; inset: 9%; border-radius: 50%; border: 1px dashed rgba(255, 255, 255, .06); }
.center-panel {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(42%, 420px);
  text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; z-index: 1;
}
.phase-icon { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; background: rgba(255, 255, 255, .06); border: 1px solid var(--rim); margin-bottom: 2px; }
.phase-icon svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
body[data-phase="night"] .phase-icon { color: #aab3ff; }
body[data-phase="speech"] .phase-icon { color: var(--warn); }
body[data-phase="vote"] .phase-icon { color: #ff8a8e; }
body[data-phase="ended"] .phase-icon { color: var(--good); }
.big { font-family: var(--serif); font-size: 2.1rem; line-height: 1.05; font-weight: 400; letter-spacing: -.01em; }
.prompt { color: rgba(255, 255, 255, .78); max-width: 360px; }
.choice { padding: 8px 14px; border-radius: 12px; background: rgba(0, 0, 0, .3); border: 1px solid var(--border); font-size: .9rem; }
.progress { font-size: .82rem; color: var(--muted); }
.bar-track { width: 140px; height: 4px; border-radius: 99px; background: rgba(255, 255, 255, .1); overflow: hidden; margin-top: 2px; }
.bar-fill { height: 100%; background: var(--glow-a); border-radius: 99px; transition: width .4s ease; }

.timer-ring {
  --p: 1; width: 132px; height: 132px; border-radius: 50%; display: grid; place-items: center; margin: 4px 0;
  background: conic-gradient(var(--ring, var(--warn)) calc(var(--p) * 360deg), rgba(255, 255, 255, .08) 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 6px), #000 calc(100% - 5px));
          mask: radial-gradient(farthest-side, transparent calc(100% - 6px), #000 calc(100% - 5px));
  position: absolute;
}
.timer-wrap { position: relative; width: 132px; height: 132px; display: grid; place-items: center; }
.timer { font-family: var(--mono); font-size: 2.1rem; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1; }
.timer.low { color: var(--accent); animation: pulse 1s infinite; }
.timer-wrap.low { --ring: var(--accent); }
@keyframes pulse { 50% { opacity: .55; } }
.order { display: flex; flex-wrap: wrap; justify-content: center; gap: 5px; font-size: .76rem; margin-top: 4px; }
.order span { padding: 3px 9px; border-radius: 99px; background: rgba(0, 0, 0, .35); color: var(--muted); border: 1px solid transparent; }
.order span.done { opacity: .35; text-decoration: line-through; }
.order span.now { background: var(--warn); color: #1a1206; font-weight: 600; }
.winner { font-family: var(--serif); font-size: 3rem; line-height: 1; }

/* seats */
.seat {
  position: absolute; transform: translate(-50%, -50%); width: clamp(118px, 13cqw, 150px);
  display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; padding: 12px 10px 10px;
  background: rgba(16, 16, 22, .82); border: 1px solid var(--border); border-radius: 18px;
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 14px 34px -14px rgba(0, 0, 0, .8);
  transition: border-color .2s, box-shadow .2s, opacity .3s, filter .3s, transform .2s;
}
.seat .avatar { width: 46px; height: 46px; font-size: .95rem; transition: box-shadow .2s; }
.seat .name { font-weight: 600; font-size: .9rem; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seat .num { position: absolute; top: 8px; left: 10px; font-family: var(--mono); font-size: .68rem; color: var(--faint); }
.seat .meta { font-size: .7rem; color: var(--muted); display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; align-items: center; }
.seat .meta .tag { margin: 0; }
.seat .votes { font-size: .72rem; color: var(--warn); background: var(--warn-soft); padding: 2px 8px; border-radius: 8px; max-width: 100%; }
.seat button { width: 100%; padding: 6px 8px; font-size: .78rem; border-radius: 10px; }
.seat.me { border-color: rgba(139, 124, 255, .45); }
.seat.me .avatar { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--me); }
.seat.dead { opacity: .42; filter: grayscale(1); }
.seat.dead .name { text-decoration: line-through; }
.seat.speaking { border-color: rgba(245, 181, 70, .6); box-shadow: 0 0 0 4px rgba(245, 181, 70, .14), 0 0 40px -6px rgba(245, 181, 70, .55); }
.seat.speaking .avatar { animation: speak 1.6s ease-in-out infinite; }
@keyframes speak { 0%, 100% { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--warn); } 50% { box-shadow: 0 0 0 2px var(--bg), 0 0 0 9px rgba(245, 181, 70, .25); } }
.seat.selected { border-color: rgba(229, 72, 77, .7); box-shadow: 0 0 0 4px rgba(229, 72, 77, .16), 0 0 40px -8px rgba(229, 72, 77, .6); }
.seat.selected button { background: var(--accent); border-color: transparent; color: #fff; }

/* sidebar */
.sidebar { display: flex; flex-direction: column; gap: 14px; min-height: 0; }
.sidebar .card { padding: 18px; }
.sidebar .grow { flex: 1; min-height: 140px; display: flex; flex-direction: column; }
.sidebar .grow .log { flex: 1; max-height: none; }
.role-box { position: relative; overflow: hidden; }
.role-box.revealed::before { content: ''; position: absolute; inset: 0; background: radial-gradient(120% 80% at 100% 0, var(--role-glow, transparent), transparent 60%); opacity: .35; pointer-events: none; }
.role-box.revealed.mafia { --role-glow: var(--accent); border-color: rgba(229, 72, 77, .3); }
.role-box.revealed.town { --role-glow: var(--good); border-color: rgba(61, 214, 140, .25); }
.role-name { font-family: var(--serif); font-size: 2.1rem; line-height: 1.1; margin: 4px 0 6px; }
#roleCard p { color: rgba(255, 255, 255, .72); font-size: .9rem; margin-top: 6px; position: relative; }
.role-hidden { display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: 14px; border: 1px dashed var(--border-strong); color: var(--muted); font-size: .85rem; }
.role-hidden svg { flex: none; width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.host-panel { border-color: rgba(229, 72, 77, .22); background: linear-gradient(180deg, rgba(229, 72, 77, .07), rgba(22, 22, 30, .72)); }
.host-panel h3 { color: #ff9a9d; }
.host-panel p { margin-bottom: 12px; }
.log { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; max-height: 220px; overflow: auto; font-size: .86rem; scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, .15) transparent; }
.log li { color: var(--muted); padding: 7px 0 7px 18px; position: relative; border-left: 1px solid var(--border); margin-left: 4px; }
.log li::before { content: ''; position: absolute; left: -4px; top: 13px; width: 7px; height: 7px; border-radius: 50%; background: var(--faint); box-shadow: 0 0 0 3px var(--bg); }
.log li:first-child { color: var(--text); }
.log li:first-child::before { background: var(--glow-a); box-shadow: 0 0 0 3px var(--bg), 0 0 10px var(--glow-a); }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(4, 4, 8, .6); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); display: flex; align-items: center; justify-content: center; z-index: 10; animation: fade .2s ease; padding: 16px; }
.modal-box { background: rgba(24, 24, 32, .96); border: 1px solid rgba(229, 72, 77, .28); border-radius: 22px; padding: 26px; width: min(480px, 100%); box-shadow: 0 40px 100px -20px rgba(0, 0, 0, .9); animation: pop .25s cubic-bezier(.2, 1.2, .4, 1); }
.modal-box h2 { font-size: 1.25rem; margin-bottom: 8px; }
.modal-box p { color: var(--muted); }
.modal-actions { justify-content: flex-end; margin-top: 22px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(.94) translateY(8px); } }
.hold { position: relative; overflow: hidden; user-select: none; -webkit-user-select: none; min-width: 230px; touch-action: none; }
.hold-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: linear-gradient(90deg, rgba(229, 72, 77, .5), var(--accent)); }
.hold-label { position: relative; }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 20; max-width: calc(100vw - 32px);
  background: rgba(30, 30, 40, .92); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(229, 72, 77, .4); color: #fff; padding: 11px 18px; border-radius: 14px; font-size: .9rem;
  box-shadow: 0 20px 50px -12px rgba(0, 0, 0, .8); animation: toast .3s cubic-bezier(.2, 1.2, .4, 1);
}
.toast.info { border-color: rgba(61, 214, 140, .4); }
@keyframes toast { from { opacity: 0; transform: translate(-50%, 12px); } }

.lang-select {
  font: inherit; font-size: .8rem; color: var(--text); cursor: pointer; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 9px; padding: 6px 10px;
}
.lang-select:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(139, 124, 255, .45); }

/* ---------- quality-of-life additions ---------- */
.icon-btn { width: 34px; height: 34px; padding: 0; display: grid; place-items: center; border-radius: 10px; background: var(--surface-2); color: var(--muted); }
.icon-btn svg { width: 17px; height: 17px; stroke: currentColor; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn[aria-pressed="true"] { color: var(--text); }
.row.center { justify-content: center; }

/* reconnecting banner */
.offline-banner {
  position: fixed; top: 64px; left: 50%; transform: translateX(-50%); z-index: 30;
  display: flex; align-items: center; gap: 10px; padding: 9px 16px; border-radius: 99px; font-size: .88rem; font-weight: 550;
  background: rgba(60, 40, 10, .92); color: #ffd58a; border: 1px solid rgba(245, 181, 70, .45);
  box-shadow: 0 16px 40px -12px rgba(0, 0, 0, .8); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  animation: toast .3s ease;
}
.spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid rgba(255, 213, 138, .3); border-top-color: #ffd58a; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* invite */
.invite { display: flex; gap: 16px; align-items: center; padding: 14px; border-radius: 14px; background: rgba(0, 0, 0, .22); border: 1px solid var(--border); }
.qr { flex: none; width: 104px; height: 104px; border-radius: 10px; background: #fff; padding: 4px; }
.invite-body { display: flex; flex-direction: column; gap: 8px; min-width: 0; }

/* hold-to-peek role card */
.role-card { cursor: pointer; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: none; border-radius: 14px; outline: none; }
.role-card:focus-visible { box-shadow: 0 0 0 3px rgba(139, 124, 255, .45); }
.role-card:active .role-hidden { border-color: var(--border-strong); background: var(--surface-2); }
.role-hidden { transition: background .15s, border-color .15s; }
.allies { color: #ff9a9d !important; }

/* tabs */
.tabs-card { padding-top: 12px !important; }
.tabs { display: flex; gap: 4px; padding: 4px; margin-bottom: 14px; border-radius: 12px; background: rgba(0, 0, 0, .28); border: 1px solid var(--border); }
.tabs button { flex: 1; padding: 6px 8px; font-size: .8rem; border: 0; background: transparent; color: var(--muted); border-radius: 9px; }
.tabs button:hover:not(:disabled) { background: var(--surface-2); border: 0; }
.tabs button.active { background: var(--surface-3); color: var(--text); box-shadow: 0 1px 0 rgba(255, 255, 255, .06) inset; }
.tab-panel { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: auto; scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, .15) transparent; }
.tab-panel .log { max-height: none; overflow: visible; }
.note-pad { flex: 1; min-height: 140px; resize: none; font: inherit; font-size: .9rem; line-height: 1.5; color: var(--text); background: rgba(0, 0, 0, .28); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 11px 13px; }
.note-pad:focus { outline: none; border-color: rgba(139, 124, 255, .7); box-shadow: 0 0 0 4px rgba(139, 124, 255, .16); }
.notes-hint { margin-top: 10px; }

/* votes history */
.votes-panel { display: flex; flex-direction: column; gap: 14px; }
.vote-day-head { font-size: .78rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 6px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.vote-day-head .muted { text-transform: none; letter-spacing: 0; font-weight: 500; }
.vote-row { display: grid; grid-template-columns: minmax(90px, auto) 1fr; gap: 10px; align-items: baseline; padding: 6px 10px; border-radius: 10px; font-size: .84rem; }
.vote-row:nth-child(odd) { background: var(--surface-2); }
.vote-row.out { background: var(--accent-soft); box-shadow: 0 0 0 1px rgba(229, 72, 77, .25) inset; }
.vote-target { font-weight: 600; display: flex; gap: 6px; align-items: baseline; }
.vote-target b { font-family: var(--mono); font-size: .75rem; color: var(--warn); }
.vote-voters { color: var(--muted); }
.waiting-for { font-size: .8rem; color: var(--warn); max-width: 340px; }

/* seat extras: marks, notes, voted check */
.avatar-wrap { position: relative; display: inline-flex; }
.voted { position: absolute; right: -4px; bottom: -4px; width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; background: var(--good); color: #062014; box-shadow: 0 0 0 2px #101016; }
.voted svg { width: 12px; height: 12px; stroke: currentColor; fill: none; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.mark-btn {
  position: absolute; top: 7px; right: 7px; width: 18px !important; height: 18px; padding: 0; border-radius: 50%;
  background: transparent; border: 1.5px dashed rgba(255, 255, 255, .22);
}
.mark-btn:hover:not(:disabled) { border-color: rgba(255, 255, 255, .5); background: var(--surface-2); }
/* a bigger invisible hit area for fingers */
.mark-btn::after { content: ''; position: absolute; inset: -8px; }
.mark-btn.black { background: #050507; border: 1.5px solid #6b6b78; color: #e8e8ee; }
.mark-btn.red { background: #c2262c; border: 1.5px solid #ff6b70; color: #fff; }
.mark-btn.unsure { background: var(--warn-soft); border: 1.5px solid var(--warn); color: var(--warn); }
.mark-tag.black { background: #050507; color: #e8e8ee; box-shadow: 0 0 0 1px #6b6b78 inset; }
.mark-tag.red { background: #c2262c; color: #fff; }
.mark-tag.unsure { background: var(--warn-soft); color: var(--warn); }
.seat.marked-black { border-color: rgba(160, 160, 175, .4); background: linear-gradient(180deg, rgba(0, 0, 0, .55), rgba(16, 16, 22, .85)); }
.seat.marked-red { border-color: rgba(229, 72, 77, .45); }
.seat.marked-unsure { border-color: rgba(245, 181, 70, .35); }
.seat-note { font-size: .7rem; font-style: italic; color: #cfcfe0; background: rgba(255, 255, 255, .06); padding: 2px 8px; border-radius: 8px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.mark-menu {
  position: absolute; z-index: 15; width: 250px; padding: 12px; border-radius: 16px; display: flex; flex-direction: column; gap: 8px;
  background: rgba(24, 24, 32, .97); border: 1px solid var(--border-strong); box-shadow: 0 24px 60px -16px rgba(0, 0, 0, .9);
  animation: pop .18s ease;
}
.mark-title { font-weight: 600; font-size: .88rem; padding: 0 4px 2px; }
.mark-options { display: grid; gap: 4px; }
.mk { display: flex; align-items: center; gap: 10px; text-align: left; padding: 8px 10px; font-size: .84rem; background: transparent; border-color: transparent; }
.mk i { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.mk.black i { background: #050507; box-shadow: 0 0 0 1.5px #6b6b78; }
.mk.red i { background: #c2262c; box-shadow: 0 0 0 1.5px #ff6b70; }
.mk.unsure i { background: var(--warn-soft); box-shadow: 0 0 0 1.5px var(--warn); }
.mk.clear i { box-shadow: 0 0 0 1.5px dashed rgba(255, 255, 255, .3); border: 1.5px dashed rgba(255, 255, 255, .3); }
.mk.active { background: var(--surface-3); border-color: var(--border); }
.mark-menu input { padding: 9px 11px; font-size: .85rem; }

/* overlays: role reveal and recap */
.overlay { position: fixed; inset: 0; z-index: 12; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(4, 4, 8, .72); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); animation: fade .25s ease; }
.reveal-stage { display: flex; flex-direction: column; align-items: center; gap: 22px; width: min(340px, 100%); perspective: 1200px; }
.flip-card { position: relative; width: 100%; aspect-ratio: 5 / 7; padding: 0; border: 0; background: none; transform-style: preserve-3d; transition: transform .8s cubic-bezier(.3, 1.3, .5, 1); cursor: pointer; }
.flip-card:hover:not(:disabled) { background: none; border: 0; }
.flip-card.flipped { transform: rotateY(180deg); cursor: default; }
.flip-face {
  position: absolute; inset: 0; border-radius: 24px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 28px;
  backface-visibility: hidden; -webkit-backface-visibility: hidden; text-align: center; box-shadow: 0 40px 100px -20px rgba(0, 0, 0, .9);
}
.flip-back { background: radial-gradient(120% 80% at 50% 0, #3a1418, #120709 70%); border: 1px solid rgba(229, 72, 77, .35); }
.flip-back::before { content: ''; position: absolute; inset: 12px; border-radius: 16px; border: 1px dashed rgba(229, 72, 77, .3); }
.flip-mark { width: 74px; height: 74px; fill: var(--accent); filter: drop-shadow(0 0 24px rgba(229, 72, 77, .6)); }
.flip-tap { font-family: var(--serif); font-size: 1.7rem; line-height: 1.1; color: var(--text); }
.flip-front { transform: rotateY(180deg); background: radial-gradient(120% 80% at 50% 0, #1c1c28, #0c0c12 70%); border: 1px solid var(--border-strong); }
.flip-front.mafia { background: radial-gradient(120% 80% at 50% 0, #4a1418, #12070a 70%); border-color: rgba(229, 72, 77, .5); }
.flip-front.town { background: radial-gradient(120% 80% at 50% 0, #123a28, #07120d 70%); border-color: rgba(61, 214, 140, .4); }
.flip-front .role-name { font-size: 3rem; }
.flip-front p { color: rgba(255, 255, 255, .78); font-size: .95rem; }
.flip-front .eyebrow { margin: 0; }

.sheet { width: min(760px, 100%); max-height: min(88vh, 900px); display: flex; flex-direction: column; border-radius: 22px; background: rgba(20, 20, 28, .97); border: 1px solid var(--border-strong); box-shadow: 0 40px 100px -20px rgba(0, 0, 0, .9); animation: pop .25s cubic-bezier(.2, 1.2, .4, 1); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.sheet-head h2 { font-size: 1.15rem; }
.sheet-body { padding: 20px 22px 24px; overflow: auto; }
.recap-winner { font-family: var(--serif); font-size: 2.4rem; line-height: 1.1; margin-bottom: 18px; }
.recap-roles { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 24px; }
.recap-player { display: inline-flex; align-items: center; gap: 8px; padding: 5px 10px 5px 5px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); font-size: .85rem; }
.recap-player .avatar { width: 26px; height: 26px; font-size: .66rem; }
.recap-player b { font-weight: 600; }
.recap-player .tag { margin: 0; }
.recap-steps { display: flex; flex-direction: column; gap: 12px; }
.recap-step { padding: 14px 16px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface-2); }
.recap-step.night { background: linear-gradient(180deg, rgba(59, 76, 255, .08), rgba(255, 255, 255, .02)); border-color: rgba(130, 140, 255, .18); }
.recap-step h4 { margin: 0 0 10px; display: flex; align-items: center; gap: 8px; font-size: .92rem; }
.recap-step h4 svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; color: var(--muted); }
.recap-step ul { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 5px; font-size: .86rem; color: rgba(255, 255, 255, .8); }
.recap-step li { padding-left: 16px; position: relative; }
.recap-step li::before { content: ''; position: absolute; left: 2px; top: .55em; width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
.recap-step li.r-mafia::before { background: var(--accent); }
.recap-step li.r-doctor::before { background: var(--good); }
.recap-step li.r-cop::before { background: #6aa8ff; }
.recap-step li.r-hooker::before { background: #d68cff; }
.recap-step .vote-row { margin-bottom: 2px; }
.recap-result { font-size: .86rem; font-weight: 600; margin-top: 8px; }
.recap-result.bad { color: #ff9a9d; }
.recap-result.good { color: #8ef0bd; }

/* ---------- chat ---------- */
.lobby-col { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.lobby-chat .chat-slot { height: 300px; }
.chat-slot { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.tab-panel[data-panel="chat"] { overflow: hidden; }
.chat { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; }
.chat-channels { display: flex; gap: 6px; }
.chat-channels button { flex: 1; padding: 6px 10px; font-size: .8rem; border-radius: 9px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: transparent; color: var(--muted); }
.chat-channels button.active { background: var(--surface-3); color: var(--text); border-color: var(--border-strong); }
.chat-channels button[data-channel="mafia"].active { background: var(--accent-soft); color: #ffb1b3; border-color: rgba(229, 72, 77, .45); }
.badge { min-width: 17px; height: 17px; padding: 0 5px; border-radius: 99px; background: var(--accent); color: #fff; font-size: .66rem; font-weight: 700; line-height: 17px; text-align: center; font-variant-numeric: tabular-nums; }
.tabs button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.chat-list { flex: 1; min-height: 120px; overflow-y: auto; display: flex; flex-direction: column; gap: 3px; padding-right: 4px; scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, .15) transparent; }
.chat.mafia .chat-list { background: linear-gradient(180deg, rgba(229, 72, 77, .06), transparent 40%); border-radius: 12px; }
.chat-empty { margin: auto; text-align: center; color: var(--faint); font-size: .85rem; max-width: 240px; }
.chat-sep { display: flex; align-items: center; gap: 10px; margin: 10px 0 6px; color: var(--faint); font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; }
.chat-sep::before, .chat-sep::after { content: ''; flex: 1; border-top: 1px solid var(--border); }
.msg { display: flex; align-items: flex-end; gap: 8px; max-width: 92%; margin-top: 6px; }
.msg.grouped { margin-top: 0; }
.msg .avatar, .msg-gap { width: 26px; height: 26px; font-size: .64rem; flex: none; }
.msg-body { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.msg-name { font-size: .72rem; color: var(--muted); font-weight: 600; padding-left: 4px; }
.bubble {
  background: var(--surface-3); border: 1px solid var(--border); padding: 6px 10px 6px 11px; border-radius: 14px 14px 14px 5px;
  font-size: .88rem; line-height: 1.4; overflow-wrap: anywhere; white-space: pre-wrap;
}
.bubble time { float: right; margin: 4px 0 0 10px; font-size: .64rem; color: var(--faint); font-variant-numeric: tabular-nums; }
.msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.msg.mine .msg-gap { display: none; }
.msg.mine .bubble { background: linear-gradient(180deg, rgba(139, 124, 255, .3), rgba(139, 124, 255, .2)); border-color: rgba(139, 124, 255, .35); border-radius: 14px 14px 5px 14px; }
.msg.mine .bubble time { color: rgba(255, 255, 255, .5); }
.chat.mafia .msg.mine .bubble { background: linear-gradient(180deg, rgba(229, 72, 77, .32), rgba(229, 72, 77, .2)); border-color: rgba(229, 72, 77, .4); }
.chat-form { display: flex; gap: 6px; }
.chat-form input { padding: 9px 12px; font-size: .9rem; }
.chat-form button { flex: none; width: 40px; padding: 0; display: grid; place-items: center; }
.chat-form button svg { width: 17px; height: 17px; fill: #fff; }
.chat-closed { font-size: .82rem; color: var(--muted); text-align: center; padding: 10px; border-radius: 12px; border: 1px dashed var(--border-strong); }
.timer-wrap.small { width: 84px; height: 84px; }
.timer-wrap.small .timer-ring { width: 84px; height: 84px; }
.timer-wrap.small .timer { font-size: 1.35rem; }

/* narrow screens: stacked */
@media (max-width: 1000px) {
  main { padding: 16px; }
  .topbar { flex-wrap: wrap; gap: 8px 10px; padding: 10px 16px; }
  .top-me { display: none; }
  .lobby-grid, .game-grid { grid-template-columns: 1fr; height: auto; min-height: 0; }
  .grid4 { grid-template-columns: 1fr 1fr; }
  .table-wrap { position: static; }
  .table { position: static; display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; container-type: normal; }
  .felt { display: none; }
  .center-panel {
    position: static; transform: none; width: auto; grid-column: 1 / -1; order: -1; padding: 22px 16px;
    background: radial-gradient(ellipse at 50% 0, var(--felt-a), var(--felt-b)); border: 1px solid var(--rim); border-radius: var(--radius);
  }
  .seat { position: static; transform: none; width: auto; }
  .offline-banner { top: auto; bottom: 84px; }
  .tab-panel[data-panel="chat"] { height: 420px; flex: none; }
}
@media (max-width: 560px) {
  .list, .grid2 { grid-template-columns: 1fr; }
  #home { padding-top: 3vh; }
  .hold { min-width: 0; flex: 1; }
  .invite { flex-direction: column; align-items: flex-start; }
  .table { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
  .seat { padding: 10px 6px 8px; border-radius: 14px; }
  .seat .avatar { width: 38px; height: 38px; font-size: .82rem; }
  .big { font-size: 1.8rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
