/* =====================================================================
   Mafia — neobrutalist UI over the 3D scene.
   Tokens live on :root; each theme's /js/themes/<id>/theme.css re-tints them
   (accent, card tints, washes) and keeps the scene palette the recap card uses.
   ===================================================================== */

/* ============ Tokens ============ */
:root {
  /* Ink, surfaces and the pastel palette */
  --nb-ink: #1b1b1e;
  --nb-ink-2: #46464f;
  --nb-muted: #55545e; /* 7:1 on white */
  --nb-surface: #fbf8fc;
  --nb-white: #ffffff;
  --nb-butter: #fef9e7;
  --nb-primary: #fef08a;
  --nb-mint: #d1fae5;
  --nb-lavender: #ede9fe;
  --nb-blush: #ffe4e6;
  --nb-sky: #e0f2fe;
  --nb-grey: #e7e5ea;
  --nb-error: #ba1a1a;
  --nb-secondary: #1b6b4f;
  --nb-tertiary: #5f5a7c;

  /* Faction colour coding: Town = mint/green, Mafia = blush/red, Neutral = lavender/purple */
  --town-bg: var(--nb-mint);
  --town-fg: #14583f;
  --town-solid: #34d399;
  --mafia-bg: var(--nb-blush);
  --mafia-fg: #9b1414;
  --mafia-solid: #fb7185;
  --neutral-bg: var(--nb-lavender);
  --neutral-fg: #4c3d99;
  --neutral-solid: #a78bfa;

  /* Re-tinted per theme */
  --accent: var(--nb-primary);
  --card-identity: var(--nb-lavender);
  --card-roles: var(--nb-mint);
  --card-mech: var(--nb-butter);
  --card-lobby: var(--nb-blush);
  --hero-tint: var(--nb-white);
  --night-pill: var(--nb-lavender);
  --day-pill: var(--nb-primary);
  --trial-pill: var(--nb-blush);
  --scrim: rgba(10, 10, 14, 0.38);
  --accent-ink: var(--nb-ink);

  /* Scene and transitions (re-tinted per theme) */
  --scene-bg: #07070a;
  --scene-glow: #1a1626;
  --spot-cone: rgba(255, 226, 168, 0.4);
  --wash-sunset: #c0563a;
  --wash-sunrise: #e2a265;
  /* Patterned pastel backdrop when there is no 3D scene (reduced motion, no WebGL) */
  --backdrop-day: #fdf6d3;
  --backdrop-night: #e6e1fa;
  --backdrop-trial: #fde3e6;
  --backdrop-dot: rgba(27, 27, 30, 0.16);

  /* Shape */
  --bw: 2px;
  --nb-line: var(--bw) solid var(--nb-ink);
  --sh-2: 2px 2px 0 0 var(--nb-ink);
  --sh-3: 3px 3px 0 0 var(--nb-ink);
  --sh-4: 4px 4px 0 0 var(--nb-ink);
  --sh-6: 6px 6px 0 0 var(--nb-ink);
  --r-12: 12px;
  --r-16: 16px;
  --r-24: 24px;
  --gutter: 16px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --sub-h: 0px;
  --appbar-h: 64px;
  --drawer-w: 380px;

  /* Type */
  --font-head: 'Space Grotesk', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  --font-body: 'Plus Jakarta Sans', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  color-scheme: light;
}
@media (min-width: 720px) { :root { --gutter: 24px; } }

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: radial-gradient(120% 80% at 50% 0%, var(--scene-glow) 0%, var(--scene-bg) 60%) fixed, var(--scene-bg);
  color: var(--nb-ink);
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { font-family: var(--font-head); font-weight: 700; margin: 0; line-height: 1.05; letter-spacing: -0.01em; }
p { margin: 0; }
:focus-visible { outline: 3px solid var(--nb-ink); outline-offset: 3px; box-shadow: 0 0 0 6px var(--accent); }
/* Keyboard focus and scripted scrolling never park a control under the sticky HUD or the caption bar */
.screen :is(button, input, summary, [tabindex]) { scroll-margin: 96px 0 calc(var(--sub-h) + 24px); }
.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; }
.ico { flex: none; display: block; }

/* ============ Atmosphere layers (scene behind the UI) ============ */
#scene { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; display: block; }
.atmos {
  position: fixed; inset: 0; z-index: 1; pointer-events: none;
  background: linear-gradient(180deg, rgba(7, 7, 10, 0.1) 0%, var(--scrim) 60%, rgba(7, 7, 10, 0.6) 100%);
  transition: background 1.2s var(--ease);
}
body[data-mood='day'] .atmos { background: linear-gradient(180deg, rgba(7, 7, 10, 0.02) 0%, rgba(7, 7, 10, 0.2) 60%, rgba(7, 7, 10, 0.5) 100%); }
body[data-mood='trial'] .atmos { background: radial-gradient(50% 40% at 50% 20%, rgba(254, 240, 138, 0.1), transparent 70%), linear-gradient(180deg, rgba(7, 7, 10, 0.3), rgba(7, 7, 10, 0.7)); }
/* Sunset / sunrise colour wash (30 % at its peak) */
.wash { position: fixed; inset: 0; z-index: 2; pointer-events: none; opacity: 0; background: var(--wash-sunset); }
.wash[data-kind='sunrise'] { background: var(--wash-sunrise); }
.wash.play { animation: wash 3s ease-in-out; }
@keyframes wash { 0% { opacity: 0; } 45% { opacity: 0.3; } 100% { opacity: 0; } }
.grain {
  position: fixed; inset: -50%; z-index: 2; pointer-events: none; opacity: 0.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='.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: grain 0.9s steps(4) infinite;
}
/* No 3D scene (reduced motion, no WebGL, or three.js failed to load): a flat pastel backdrop
   with an ink dot grid, tinted by the theme and the time of day. */
.no-scene #scene, .no-scene .atmos, .no-scene .grain { display: none; }
.no-scene body {
  --backdrop: var(--backdrop-day);
  background-color: var(--backdrop);
  background-image:
    radial-gradient(circle at 1.5px 1.5px, var(--backdrop-dot) 1.5px, transparent 2px),
    radial-gradient(60% 55% at 0% 0%, color-mix(in srgb, var(--card-roles) 80%, transparent), transparent 70%),
    radial-gradient(55% 50% at 100% 100%, color-mix(in srgb, var(--card-identity) 85%, transparent), transparent 70%);
  background-size: 22px 22px, 100% 100%, 100% 100%;
  background-attachment: fixed;
  transition: background-color 1.2s var(--ease);
}
.no-scene body[data-mood='night'], .no-scene body[data-mood='mafia'] { --backdrop: var(--backdrop-night); }
.no-scene body[data-mood='trial'] { --backdrop: var(--backdrop-trial); }
.no-scene .wash.play { animation-name: wash-flat; }
@keyframes wash-flat { 0% { opacity: 0; } 45% { opacity: 0.45; } 100% { opacity: 0; } }
@keyframes grain {
  0% { transform: translate(0, 0); } 25% { transform: translate(-3%, 2%); }
  50% { transform: translate(2%, -3%); } 75% { transform: translate(-2%, -1%); } 100% { transform: translate(0, 0); }
}

/* ============ Layout ============ */
.screen {
  position: relative; z-index: 3;
  padding: max(env(safe-area-inset-top), 16px) var(--gutter) calc(var(--sub-h) + 32px);
  min-height: 100dvh;
}
.wrap { max-width: 1240px; margin: 0 auto; }

/* ============ Type helpers ============ */
.label-sm, .label, .kicker {
  font-family: var(--font-head); font-weight: 700; font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--nb-ink-2);
}
.label { display: block; margin: 0 0 8px; }
.label--icon { display: flex; align-items: center; gap: 6px; }
.seg--status span .ico, .pill .ico { flex: none; }
.muted { color: var(--nb-muted); }
.mono { font-family: var(--font-head); font-weight: 700; font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ============ Cards ============ */
.card {
  position: relative;
  background: var(--nb-white); color: var(--nb-ink);
  border: var(--nb-line); border-radius: var(--r-24); box-shadow: var(--sh-6);
  padding: 20px;
}
@media (min-width: 720px) { .card { padding: 24px; } }
.card--lavender { background: var(--card-identity); }
.card--mint { background: var(--card-roles); }
.card--butter { background: var(--card-mech); }
.card--blush { background: var(--card-lobby); }
.card--sm { border-radius: var(--r-16); box-shadow: var(--sh-4); padding: 14px 16px; }
.card__head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.card__head h2 { font-size: 22px; text-transform: uppercase; letter-spacing: 0.01em; }
.card__head .spacer { flex: 1; }
.card__num {
  flex: none; width: 36px; height: 36px; display: grid; place-items: center; border: var(--nb-line); border-radius: 10px;
  background: var(--nb-white); font-family: var(--font-head); font-weight: 700; font-size: 14px; box-shadow: var(--sh-2);
}
.sub { margin-top: 18px; }
.sub > .label { margin-bottom: 10px; }

/* ============ Buttons ============ */
.btn {
  --btn-bg: var(--nb-white);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px; border-radius: var(--r-12);
  border: var(--nb-line); background: var(--btn-bg); color: var(--nb-ink); box-shadow: var(--sh-3);
  font-family: var(--font-head); font-weight: 700; font-size: 15px; letter-spacing: 0.02em; text-transform: uppercase;
  transition: transform 120ms var(--ease), box-shadow 120ms var(--ease), background 150ms;
  user-select: none; text-decoration: none;
}
.btn:hover { transform: translate(-2px, -2px); box-shadow: var(--sh-6); }
.btn:active { transform: translate(2px, 2px); box-shadow: none; }
.btn[disabled], .btn[aria-disabled='true'] { opacity: 0.55; cursor: not-allowed; transform: none; box-shadow: var(--sh-2); background: var(--nb-grey); }
.btn--primary { --btn-bg: var(--accent); color: var(--accent-ink); }
.btn--ink { --btn-bg: var(--nb-ink); color: var(--nb-white); box-shadow: var(--sh-3); }
.btn--ink:hover { box-shadow: 6px 6px 0 0 var(--accent); }
.btn--mint { --btn-bg: var(--town-bg); }
.btn--blush { --btn-bg: var(--mafia-bg); }
.btn--ghost { --btn-bg: transparent; box-shadow: none; }
.btn--ghost:hover { --btn-bg: var(--nb-white); box-shadow: var(--sh-3); }
.btn--sm { min-height: 40px; padding: 0 14px; font-size: 13px; border-radius: 10px; box-shadow: var(--sh-2); }
.btn--sm:hover { box-shadow: var(--sh-4); }
.btn--xl { min-height: 64px; font-size: 19px; border-radius: var(--r-16); box-shadow: var(--sh-4); }
.btn--block { width: 100%; }
.btn--danger-armed { --btn-bg: var(--nb-error) !important; color: #fff !important; }
.btn.chosen { --btn-bg: var(--nb-ink); color: #fff; }
.icon-btn {
  display: inline-grid; place-items: center; flex: none; width: 44px; height: 44px; padding: 0;
  border: var(--nb-line); border-radius: var(--r-12); background: var(--nb-white); box-shadow: var(--sh-2);
  transition: transform 120ms var(--ease), box-shadow 120ms var(--ease);
}
.icon-btn:hover { transform: translate(-2px, -2px); box-shadow: var(--sh-4); }
.icon-btn:active { transform: translate(2px, 2px); box-shadow: none; }
.icon-btn[aria-pressed='true'] { background: var(--nb-ink); color: #fff; }
.icon-btn--sm { width: 36px; height: 36px; border-radius: 10px; }

/* ============ Pills, chips, badges ============ */
.pill {
  display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 12px; border-radius: 999px;
  border: var(--nb-line); background: var(--nb-white); box-shadow: var(--sh-2);
  font-family: var(--font-head); font-weight: 700; font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; white-space: nowrap;
}
.pill--ink { background: var(--nb-ink); color: #fff; }
.pill--accent { background: var(--accent); color: var(--accent-ink); }
.pill--mint { background: var(--town-bg); }
.pill--lavender { background: var(--neutral-bg); }
.pill--sky { background: var(--nb-sky); }
.pills { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px;
  border: var(--nb-line); background: var(--nb-white); color: var(--nb-ink);
  font-family: var(--font-head); font-weight: 700; font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; white-space: nowrap;
}
.chip .ico { width: 13px; height: 13px; }
.chip--town { background: var(--town-bg); color: var(--town-fg); border-color: var(--nb-ink); }
.chip--mafia { background: var(--mafia-bg); color: var(--mafia-fg); border-color: var(--nb-ink); }
.chip--neutral { background: var(--neutral-bg); color: var(--neutral-fg); border-color: var(--nb-ink); }
.chip--plain { background: var(--nb-grey); }
.badge-innocent { background: var(--town-bg); color: var(--town-fg); }
.badge-mafia { background: var(--mafia-bg); color: var(--mafia-fg); }
.tag {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 7px; border-radius: 6px; border: var(--nb-line);
  font-family: var(--font-head); font-weight: 700; font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase;
  background: var(--accent); color: var(--accent-ink);
}
.tag--ink { background: var(--nb-ink); color: #fff; }

/* Initials avatar: tint derived from the player id */
.avatar {
  --tint: var(--nb-primary);
  flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  background: var(--tint); border: var(--nb-line); color: var(--nb-ink);
  font-family: var(--font-head); font-weight: 700; font-size: 15px; letter-spacing: 0.02em; line-height: 1;
}
.avatar--lg { width: 72px; height: 72px; font-size: 26px; box-shadow: var(--sh-3); }
.avatar--sm { width: 30px; height: 30px; font-size: 11px; }

/* ============ Inputs ============ */
.input {
  width: 100%; min-height: 52px; padding: 0 16px; border-radius: var(--r-12);
  background: var(--nb-white); border: var(--nb-line); box-shadow: var(--sh-2); color: var(--nb-ink);
  font-size: 17px; font-weight: 600;
}
.input:focus { outline: none; box-shadow: var(--sh-4); background: var(--nb-butter); }
.input:focus-visible { outline: 3px solid var(--nb-ink); outline-offset: 2px; }
.input--code { font-family: var(--font-head); text-transform: uppercase; letter-spacing: 0.4em; text-align: center; font-size: 20px; font-weight: 700; }
.input::placeholder { color: #8b8a93; }
.input-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; }
.input-row .icon-btn { width: 52px; height: 52px; }

/* Segmented pill switcher */
.seg {
  display: grid; grid-template-columns: repeat(var(--n, 3), 1fr); gap: 4px; padding: 4px;
  border: var(--nb-line); border-radius: 999px; background: var(--nb-white); box-shadow: var(--sh-2);
}
.seg button {
  min-height: 40px; padding: 0 12px; border: var(--bw) solid transparent; border-radius: 999px; background: transparent;
  font-family: var(--font-head); font-weight: 700; font-size: 13px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--nb-ink-2);
  transition: background 150ms, color 150ms;
}
.seg button:hover:not([disabled]) { background: var(--nb-butter); color: var(--nb-ink); }
.seg button[aria-pressed='true'], .seg button[aria-selected='true'] { background: var(--accent); color: var(--accent-ink); border-color: var(--nb-ink); }
.seg button[disabled] { cursor: not-allowed; }
.seg[aria-disabled='true'] button:not([aria-pressed='true']) { opacity: 0.6; }

/* Status display (not a control): same look as the switcher */
.seg--status span { display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 0 12px; border: var(--bw) solid transparent; border-radius: 999px;
  font-family: var(--font-head); font-weight: 700; font-size: 13px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--nb-ink-2); }
.seg--status span.is-on { background: var(--nb-ink); color: #fff; border-color: var(--nb-ink); }

/* Chip selectors (timers, themes, presets) */
.choices { display: flex; flex-wrap: wrap; gap: 8px; }
.choice {
  min-height: 44px; padding: 0 16px; border: var(--nb-line); border-radius: 999px; background: var(--nb-white); box-shadow: var(--sh-2);
  font-family: var(--font-head); font-weight: 700; font-size: 13px; letter-spacing: 0.06em; text-transform: uppercase;
  transition: transform 120ms var(--ease), box-shadow 120ms var(--ease), background 150ms;
}
.choice:hover:not([disabled]) { transform: translate(-2px, -2px); box-shadow: var(--sh-4); }
.choice:active:not([disabled]) { transform: translate(2px, 2px); box-shadow: none; }
.choice[aria-pressed='true'] { background: var(--nb-ink); color: #fff; }
.choice[disabled] { opacity: 0.6; cursor: not-allowed; }
.choice small { display: block; font-size: 10px; letter-spacing: 0.04em; font-weight: 500; text-transform: none; opacity: 0.8; }
.choice--tall { flex: 1 1 150px; max-width: 240px; min-height: 56px; border-radius: var(--r-12); text-align: left; padding: 8px 14px; }

/* Checkbox tiles (house rules, AI narrator) */
.check-tiles { display: grid; gap: 10px; grid-template-columns: 1fr; }
@media (min-width: 560px) { .check-tiles { grid-template-columns: 1fr 1fr; } }
.check-tile {
  position: relative; display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: start;
  padding: 12px 14px; min-height: 60px; border: var(--nb-line); border-radius: var(--r-12); background: var(--nb-white); box-shadow: var(--sh-2);
  cursor: pointer; transition: transform 120ms var(--ease), box-shadow 120ms var(--ease), background 150ms;
}
.check-tile:hover { transform: translate(-2px, -2px); box-shadow: var(--sh-4); }
.check-tile input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.check-tile__box {
  width: 26px; height: 26px; border: var(--nb-line); border-radius: 7px; background: var(--nb-white); display: grid; place-items: center; margin-top: 1px;
}
.check-tile__box .ico { opacity: 0; width: 18px; height: 18px; }
.check-tile input:checked + .check-tile__box { background: var(--nb-ink); color: var(--accent); }
.check-tile input:checked + .check-tile__box .ico { opacity: 1; }
.check-tile:has(input:checked) { background: var(--accent); }
.check-tile:has(input:focus-visible) { outline: 3px solid var(--nb-ink); outline-offset: 3px; }
.check-tile b { display: block; font-family: var(--font-head); font-size: 15px; line-height: 1.2; }
.check-tile small { display: block; font-size: 13px; color: var(--nb-ink-2); margin-top: 2px; }
.check-tile.is-readonly { cursor: default; }
.check-tile.is-readonly:hover { transform: none; box-shadow: var(--sh-2); }
.check-tile.is-disabled { opacity: 0.65; cursor: not-allowed; }

/* Neobrutalist alert */
.alert {
  display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start; margin-top: 14px;
  padding: 12px 14px; border: var(--nb-line); border-radius: var(--r-12); background: var(--mafia-bg); box-shadow: var(--sh-3);
  color: var(--mafia-fg); font-weight: 700; font-size: 14px;
}
.alert ul { margin: 0; padding: 0 0 0 16px; display: grid; gap: 2px; }
.alert__icon { width: 26px; height: 26px; border-radius: 50%; background: var(--nb-error); color: #fff; display: grid; place-items: center; font-family: var(--font-head); font-weight: 700; border: var(--nb-line); }

/* 44px touch targets on phones */
@media (max-width: 719px) {
  .btn--sm, .seg button { min-height: 44px; }
  .icon-btn--sm, .stepper .icon-btn, .code-chip .icon-btn { width: 44px; height: 44px; }
  .vol { min-height: 44px; }
}

/* ============ Top app bar (lobby, end) ============ */
.appbar {
  position: fixed; z-index: 15; top: 0; left: 0; right: 0;
  background: var(--nb-white); border-bottom: var(--nb-line); box-shadow: 0 4px 0 0 var(--nb-ink);
  padding: max(env(safe-area-inset-top), 8px) var(--gutter) 8px;
}
.appbar__inner { max-width: 1240px; margin: 0 auto; display: flex; align-items: center; gap: 10px; min-height: 48px; }
.logo {
  font-family: var(--font-head); font-weight: 700; font-size: 22px; letter-spacing: 0.08em; line-height: 1;
  padding: 7px 10px; border: var(--nb-line); border-radius: 10px; background: var(--nb-ink); color: var(--accent);
}
.appbar__chips { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; overflow: hidden; }
.appbar__right { display: flex; align-items: center; gap: 8px; }
.code-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 2px 2px 12px; border: var(--nb-line); border-radius: 999px;
  background: var(--accent); color: var(--accent-ink); box-shadow: var(--sh-2);
  font-family: var(--font-head); font-weight: 700; font-size: 15px; letter-spacing: 0.18em;
}
.code-chip .icon-btn { width: 34px; height: 34px; border-radius: 999px; box-shadow: none; }
.me { display: inline-flex; align-items: center; gap: 8px; font-family: var(--font-head); font-weight: 700; font-size: 14px; }
.me__name { max-width: 14ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.appbar + .wrap, .has-appbar { padding-top: calc(var(--appbar-h) + 24px); }
@media (max-width: 719px) {
  .hide-sm { display: none !important; }
  .logo { font-size: 18px; padding: 6px 8px; }
  .appbar__right .btn--sm { padding: 0 10px; min-width: 44px; }
  .code-chip .icon-btn { width: 44px; height: 44px; }
}
@media (max-width: 380px) { .hide-xs { display: none !important; } }

/* ============ Home ============ */
.home { display: grid; gap: 20px; align-content: center; min-height: calc(100dvh - 60px); max-width: 520px; margin: 0 auto; }
.home__brand { background: var(--accent); text-align: center; padding: 28px 20px; }
.home__brand .kicker { color: var(--nb-ink); }
.home__title { font-size: clamp(64px, 20vw, 120px); letter-spacing: 0.04em; line-height: 0.9; margin: 10px 0 8px; text-shadow: 4px 4px 0 var(--nb-white); }
.home__tag { font-size: 17px; max-width: 30ch; margin: 0 auto; font-weight: 600; }
.home__form { display: grid; gap: 14px; }
.divider { display: flex; align-items: center; gap: 12px; }
.divider::before, .divider::after { content: ''; flex: 1; height: 2px; background: var(--nb-ink); }
.join-row { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; }
.join-row .btn { padding: 0 14px; }
.join-row [hidden] { display: none; }
/* How it works: three stickers under the form */
.home__how { list-style: none; margin: 0; display: grid; gap: 10px; }
.home__how li { display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: center; }
.home__how b { display: block; font-family: var(--font-head); font-size: 15px; line-height: 1.2; }
.home__how small { display: block; font-size: 13px; color: var(--nb-ink-2); font-weight: 600; }
.how__icon { width: 40px; height: 40px; display: grid; place-items: center; border: var(--nb-line); border-radius: var(--r-12); box-shadow: var(--sh-2); }
.home__how li:nth-child(1) .how__icon { background: var(--town-bg); }
.home__how li:nth-child(2) .how__icon { background: var(--accent); }
.home__how li:nth-child(3) .how__icon { background: var(--neutral-bg); }
@media (min-width: 720px) {
  .home { max-width: 560px; }
}
.hint { margin-top: 8px; font-size: 13px; font-weight: 600; color: var(--nb-ink-2); }
/* Why you're back home (room closed, removed by the host) */
.notice { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; background: var(--mafia-bg); }
.notice__icon { width: 44px; height: 44px; display: grid; place-items: center; border: var(--nb-line); border-radius: var(--r-12); background: var(--nb-white); box-shadow: var(--sh-2); }
.notice__body { display: grid; gap: 2px; min-width: 0; font-weight: 600; font-size: 14px; }
.notice__body b { font-family: var(--font-head); font-size: 17px; text-transform: uppercase; letter-spacing: 0.02em; }
/* Loading */
.home--loading { align-content: center; }
.loading-card { width: min(100%, 420px); justify-self: center; display: grid; justify-items: center; gap: 12px; text-align: center; padding: 28px 20px; background: var(--hero-tint); }
.loading-card b { font-family: var(--font-head); font-size: 22px; text-transform: uppercase; }
.code-chip--plain { padding: 2px 10px; box-shadow: none; font-size: 13px; }
.spinner { display: inline-flex; gap: 6px; }
.spinner span { width: 14px; height: 14px; border: var(--nb-line); border-radius: 4px; background: var(--accent); animation: hop 900ms var(--ease) infinite; }
.spinner span:nth-child(2) { animation-delay: 150ms; background: var(--town-bg); }
.spinner span:nth-child(3) { animation-delay: 300ms; background: var(--mafia-bg); }
.spinner--sm span { width: 10px; height: 10px; border-radius: 3px; }
@keyframes hop { 0%, 60%, 100% { transform: none; } 30% { transform: translateY(-6px); } }

/* Reconnecting bar */
.netbar {
  position: fixed; z-index: 45; left: 50%; top: max(env(safe-area-inset-top), 10px); transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px; max-width: calc(100vw - 2 * var(--gutter)); padding: 8px 14px 8px 8px;
  border: var(--nb-line); border-radius: 999px; background: var(--accent); color: var(--accent-ink); box-shadow: var(--sh-4);
  font-weight: 600; font-size: 14px; animation: drop 300ms var(--spring);
}
.netbar[hidden] { display: none; }
.netbar b { font-family: var(--font-head); text-transform: uppercase; letter-spacing: 0.04em; white-space: nowrap; }
.netbar__icon { width: 32px; height: 32px; flex: none; display: grid; place-items: center; border: var(--nb-line); border-radius: 50%; background: var(--nb-white); }
.netbar__text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 420px) { .netbar__text { display: none; } }

/* ============ Lobby ============ */
.lobby { display: grid; gap: 22px; }
.hero { display: grid; gap: 18px; background: var(--hero-tint); }
@media (min-width: 900px) { .hero { grid-template-columns: 1fr auto; align-items: center; } }
.hero__title { font-size: clamp(32px, 6vw, 52px); text-transform: uppercase; margin: 12px 0 10px; }
.hero__sub { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-weight: 600; color: var(--nb-ink-2); }
.hero__switch { display: grid; gap: 8px; min-width: min(100%, 300px); }
.hero__switch .seg { --n: 2; }
.lobby-grid { display: grid; gap: 22px; grid-template-columns: minmax(0, 1fr); }
/* Phones: one column ordered identity, start, roles, mechanics. Desktop: two real columns. */
.lobby-col { display: contents; }
.area-identity { order: 1; }
.area-start { order: 2; }
.area-roles { order: 3; }
.area-mech { order: 4; }
@media (min-width: 980px) {
  .lobby-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
  .lobby-col { display: grid; gap: 22px; align-content: start; }
}
.identity { display: grid; grid-template-columns: auto 1fr; gap: 16px; align-items: center; }
.field-ro { display: grid; gap: 4px; padding: 10px 14px; border: var(--nb-line); border-radius: var(--r-12); background: var(--nb-white); box-shadow: var(--sh-2); min-width: 0; }
.field-ro b { font-family: var(--font-head); font-size: 20px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 16px; }
.status-row .seg { --n: 2; flex: 1; min-width: 0; }
.status-row .seg span { white-space: nowrap; padding: 0 8px; }
.hp-card {
  display: flex; gap: 12px; align-items: center; width: 100%; text-align: left; min-height: 60px;
  padding: 12px 14px; border: var(--nb-line); border-radius: var(--r-12); background: var(--nb-white); box-shadow: var(--sh-2);
  transition: transform 120ms var(--ease), box-shadow 120ms var(--ease), background 150ms;
}
.hp-card:hover { transform: translate(-2px, -2px); box-shadow: var(--sh-4); }
.hp-card[aria-pressed='true'] { background: var(--town-bg); }
.hp-card small { display: block; color: var(--nb-ink-2); font-size: 13px; }
.hp-card b { font-family: var(--font-head); }

/* Faction balance bar */
.fbar { display: flex; height: 40px; border: var(--nb-line); border-radius: var(--r-12); overflow: hidden; background: var(--nb-white); box-shadow: var(--sh-3); }
.fbar__seg {
  display: grid; place-items: center; min-width: 0; border-right: var(--nb-line); overflow: hidden;
  font-family: var(--font-head); font-weight: 700; font-size: 13px; white-space: nowrap; transition: flex-grow 300ms var(--ease);
}
.fbar__seg:last-child { border-right: 0; }
.fbar__seg--town { background: var(--town-solid); }
.fbar__seg--mafia { background: var(--mafia-solid); }
.fbar__seg--neutral { background: var(--neutral-solid); }
.fbar-legend { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; font-weight: 700; font-size: 14px; }
.balance { margin-top: 12px; }
.balance__track { position: relative; height: 12px; border: var(--nb-line); border-radius: 99px; background: linear-gradient(90deg, var(--town-solid), var(--nb-primary) 50%, var(--mafia-solid)); }
.balance__mark { position: absolute; top: 50%; width: 20px; height: 20px; border-radius: 50%; background: var(--nb-white); border: var(--nb-line); transform: translate(-50%, -50%); transition: left 300ms; box-shadow: var(--sh-2); }
.balance__labels { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; font-size: 12px; font-weight: 700; color: var(--nb-ink-2); }
.balance__labels b { font-family: var(--font-head); color: var(--nb-ink); padding: 2px 10px; border: var(--nb-line); border-radius: 999px; background: var(--nb-white); }
.balance[data-tone='0'] .balance__labels b { background: var(--town-bg); }
.balance[data-tone='2'] .balance__labels b, .balance[data-tone='3'] .balance__labels b { background: var(--mafia-bg); }

/* Faction blocks with role tiles */
.fblocks { display: grid; gap: 14px; margin-top: 18px; }
.fblock { border: var(--nb-line); border-radius: var(--r-16); padding: 12px; box-shadow: var(--sh-3); }
.fblock--mafia { background: var(--mafia-bg); }
.fblock--town { background: var(--town-bg); }
.fblock--neutral { background: var(--neutral-bg); }
.fblock__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.fblock__head h3 { font-size: 15px; text-transform: uppercase; letter-spacing: 0.06em; }
.fblock__total { min-width: 32px; height: 32px; padding: 0 8px; display: grid; place-items: center; border: var(--nb-line); border-radius: 999px; background: var(--nb-white); font-family: var(--font-head); font-weight: 700; }
.tiles { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; grid-template-columns: 1fr; }
.fblocks { container-type: inline-size; }
@container (min-width: 600px) { .tiles { grid-template-columns: 1fr 1fr; } }
.tile {
  display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center;
  padding: 10px; border: var(--nb-line); border-radius: var(--r-12); background: var(--nb-white);
}
.tile.is-zero { background: rgba(255, 255, 255, 0.55); border-style: dashed; }
.tile__icon { width: 36px; height: 36px; border: var(--nb-line); border-radius: 10px; display: grid; place-items: center; }
.tile--mafia .tile__icon { background: var(--mafia-bg); color: var(--mafia-fg); }
.tile--town .tile__icon { background: var(--town-bg); color: var(--town-fg); }
.tile--neutral .tile__icon { background: var(--neutral-bg); color: var(--neutral-fg); }
.tile__body { min-width: 0; }
.tile__name { display: block; font-family: var(--font-head); font-weight: 700; font-size: 15px; line-height: 1.15; }
.tile__name small { font-family: var(--font-body); font-weight: 600; font-size: 11px; color: var(--nb-muted); margin-left: 4px; }
.tile__blurb { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: 12px; line-height: 1.3; color: var(--nb-ink-2); margin-top: 2px; }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper b { min-width: 2ch; text-align: center; font-family: var(--font-head); font-size: 17px; }
.stepper .icon-btn { width: 36px; height: 36px; border-radius: 10px; }
.stepper .icon-btn[disabled] { opacity: 0.35; cursor: not-allowed; transform: none; box-shadow: none; }
.count-badge { min-width: 34px; height: 34px; padding: 0 8px; display: grid; place-items: center; border: var(--nb-line); border-radius: 10px; background: var(--nb-ink); color: #fff; font-family: var(--font-head); font-weight: 700; }

/* Roster of player pods */
.roster { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px 10px; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.rpod {
  position: relative; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; align-items: center;
  padding: 10px; min-height: 60px; border: var(--nb-line); border-radius: var(--r-12); background: var(--nb-white); box-shadow: var(--sh-2);
}
.rpod.is-you { background: var(--accent); }
.rpod__name { font-family: var(--font-head); font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.rpod__tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 2px; }
.rpod__crown { position: absolute; top: -12px; left: 8px; width: 26px; height: 22px; display: grid; place-items: center; border: var(--nb-line); border-radius: 6px; background: var(--accent); }
.rpod__crown .ico { width: 15px; height: 15px; }
.rpod--spectator { background: var(--nb-sky); }
.rpod--empty { border-style: dashed; background: transparent; box-shadow: none; color: var(--nb-ink-2); font-weight: 700; justify-items: center; grid-template-columns: 1fr; text-align: center; font-size: 13px; }
.code-block { display: grid; gap: 12px; margin-top: 18px; padding: 16px; border: var(--nb-line); border-radius: var(--r-16); background: var(--nb-white); box-shadow: var(--sh-3); text-align: center; }
.code-big { font-family: var(--font-head); font-weight: 700; font-size: clamp(48px, 14vw, 76px); letter-spacing: 0.22em; padding-left: 0.22em; line-height: 1; }
.cta { display: grid; gap: 12px; margin-top: 18px; }
.cta__why { font-weight: 700; font-size: 14px; text-align: center; }
.waiting { padding: 16px; border: var(--nb-line); border-radius: var(--r-16); background: var(--nb-white); text-align: center; font-family: var(--font-head); font-weight: 700; font-size: 18px; box-shadow: var(--sh-3); }
.waiting .dots::after { content: '…'; }

/* Footer legend */
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; }
.legend__item { display: inline-flex; align-items: center; gap: 8px; font-family: var(--font-head); font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; }
.swatch { width: 18px; height: 18px; border: var(--nb-line); border-radius: 5px; }
.swatch--town { background: var(--town-solid); }
.swatch--mafia { background: var(--mafia-solid); }
.swatch--neutral { background: var(--neutral-solid); }
.swatch--alive { background: var(--nb-white); }
.swatch--accused { background: var(--mafia-bg); }
.swatch--dead { background: var(--nb-grey); }
.foot { margin-top: 24px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }

/* Sound sliders */
.sound-settings { display: grid; gap: 10px; margin-top: 14px; }
.vol { display: grid; grid-template-columns: 80px 1fr; align-items: center; gap: 12px; font-family: var(--font-head); font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; min-height: 32px; }
.vol input { width: 100%; accent-color: var(--nb-ink); height: 44px; margin: 0; }
.vol input:disabled { opacity: 0.4; }

/* ============ In-game HUD ============ */
.game-screen { padding-top: 0; }
.hud {
  position: sticky; top: max(env(safe-area-inset-top), 10px); z-index: 15; margin: 0 auto 12px;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 10px;
  background: rgba(255, 255, 255, 0.95); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border: var(--nb-line); border-radius: var(--r-24); box-shadow: var(--sh-4);
}
.hud__spacer { flex: 1; }
.hud .pill { box-shadow: none; }
.pill--phase { background: var(--day-pill); }
.pill--phase.is-night { background: var(--night-pill); }
body[data-mood='trial'] .pill--phase { background: var(--trial-pill); }
.timer {
  display: inline-flex; align-items: center; gap: 8px; min-height: 32px; padding: 0 10px; border: var(--nb-line); border-radius: 999px; background: var(--nb-white);
  font-family: var(--font-head); font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums;
}
.timer__t { min-width: 5ch; text-align: center; }
.gauge { width: 54px; height: 10px; border: var(--nb-line); border-radius: 99px; overflow: hidden; background: var(--nb-grey); }
.gauge__fill { display: block; height: 100%; width: 100%; background: var(--town-solid); border-right: var(--nb-line); transform-origin: left; transition: width 300ms linear, background 300ms; }
.timer.urgent { background: var(--mafia-bg); }
.timer.urgent .gauge__fill { background: var(--nb-error); }
.timer.urgent .timer__t { animation: pulse 1s infinite; }
.timer.paused .gauge__fill { background: var(--nb-tertiary); }
@keyframes pulse { 50% { opacity: 0.45; } }
@media (max-width: 560px) {
  .hud { gap: 6px; padding: 6px 8px; border-radius: var(--r-16); }
  .hud .pill { min-height: 30px; padding: 0 9px; font-size: 11px; }
  .gauge { width: 36px; }
}

.hostbar {
  display: flex; align-items: center; gap: 8px; margin: 0 0 12px; padding: 6px; width: fit-content; max-width: 100%;
  overflow-x: auto; scrollbar-width: none;
  background: var(--nb-white); border: var(--nb-line); border-radius: var(--r-16); box-shadow: var(--sh-3);
}
.hostbar::-webkit-scrollbar { display: none; }
.hostbar .btn { flex: none; box-shadow: none; }
.hostbar .btn:hover { box-shadow: var(--sh-2); }
.hostbar__label {
  flex: none; display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 12px; border-radius: 10px;
  background: var(--nb-ink); color: var(--accent); font-family: var(--font-head); font-weight: 700; font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase;
}

.banner {
  display: flex; gap: 12px; align-items: center; padding: 12px 14px; margin: 0 0 12px;
  border: var(--nb-line); border-radius: var(--r-16); box-shadow: var(--sh-4); background: var(--nb-white); font-weight: 600;
}
.banner b { font-family: var(--font-head); font-size: 17px; }
.banner--silenced { position: sticky; top: 76px; z-index: 14; background: var(--neutral-bg); }
.banner--dead { background: var(--nb-grey); }
.banner--spectator { background: var(--nb-sky); }
.banner__icon { width: 44px; height: 44px; flex: none; display: grid; place-items: center; border: var(--nb-line); border-radius: var(--r-12); background: var(--nb-white); box-shadow: var(--sh-2); }
.banner .muted { font-size: 14px; }

/* Layout: tray + drawer */
.game-layout { position: relative; display: flex; flex-direction: column; }
@media (min-width: 1024px) { .game-layout { min-height: calc(100dvh - var(--sub-h) - 150px); } }
@media (min-width: 1024px) {
  .game-screen.drawer-open .game-layout, .game-screen.drawer-open > .hud, .game-screen.drawer-open > .hostbar, .game-screen.drawer-open > .banner { margin-right: calc(var(--drawer-w) + 20px); }
  .tray { margin-top: auto; }
}

/* Seat tray */
.tray { padding: 14px; border-radius: var(--r-24); background: rgba(255, 255, 255, 0.95); }
.tray__head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 14px; margin-bottom: 12px; }
.tray__head h2 { font-size: 15px; text-transform: uppercase; letter-spacing: 0.08em; }
.tray__hint { font-weight: 700; font-size: 13px; color: var(--nb-ink-2); }
.seats { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
/* Phones: one horizontally scrolling row of full-size pods (names stay readable), with a
   fade on the right edge hinting that it scrolls. */
@media (max-width: 719px) {
  .seats {
    display: flex; gap: 10px; overflow-x: auto; overscroll-behavior-x: contain; scroll-snap-type: x proximity;
    margin: -10px -14px 0; padding: 14px 32px 12px 14px; scroll-padding: 0 14px; scrollbar-width: none;
    -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent);
    mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent);
  }
  .seats::-webkit-scrollbar { display: none; }
  .seats .pod { flex: 0 0 108px; scroll-snap-align: start; }
}
.pod {
  position: relative; display: grid; justify-items: center; align-content: start; gap: 5px; min-width: 0; min-height: 118px;
  padding: 18px 6px 10px; border: var(--nb-line); border-radius: var(--r-12); background: var(--nb-white); color: var(--nb-ink);
  text-align: center; box-shadow: var(--sh-2); font: inherit;
  transition: transform 120ms var(--ease), box-shadow 120ms var(--ease), opacity 300ms, filter 300ms, background 150ms;
}
@media (min-width: 720px) { .pod { padding: 18px 8px 10px; gap: 6px; } }
button.pod:hover { transform: translate(-2px, -2px); box-shadow: var(--sh-4); }
button.pod:active { transform: translate(2px, 2px); box-shadow: none; }
.pod.is-target { background: var(--nb-white); outline: 2px dashed var(--nb-ink); outline-offset: 2px; }
.pod.is-selected { background: var(--accent); box-shadow: var(--sh-4); outline: 3px solid var(--nb-ink); outline-offset: 2px; }
.pod.is-you { background: var(--accent); box-shadow: 0 0 0 3px var(--nb-white), 0 0 0 5px var(--nb-ink); }
.pod.is-off { opacity: 0.55; }
.pod__seat {
  position: absolute; top: -2px; left: -2px; min-width: 22px; height: 20px; padding: 0 5px; display: grid; place-items: center;
  border: var(--nb-line); border-radius: var(--r-12) 0 8px 0; background: var(--nb-ink); color: #fff;
  font-family: var(--font-head); font-weight: 700; font-size: 11px;
}
.pod .avatar { width: 44px; height: 44px; font-size: 15px; }
.pod__name { max-width: 100%; font-family: var(--font-head); font-weight: 700; font-size: 14px; line-height: 1.15; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pod__status { max-width: 100%; font-family: var(--font-head); font-weight: 700; font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--nb-ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pod__rolewrap { display: block; max-width: 100%; min-width: 0; }
.pod__role { font-size: 10px; padding: 1px 6px; max-width: 100%; overflow: hidden; }
.pod__role .rn { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.pod__badges { position: absolute; top: 2px; right: 2px; display: flex; gap: 2px; }
.pod__badge { width: 20px; height: 20px; display: grid; place-items: center; font-size: 11px; line-height: 1; border: var(--nb-line); border-radius: 6px; background: var(--nb-white); }
.pod__badge--lover { background: var(--mafia-bg); color: #be123c; }
.pod__badge--silenced { background: var(--neutral-bg); }
.pod__votes {
  position: absolute; top: -10px; right: -8px; min-width: 26px; height: 26px; padding: 0 6px; display: grid; place-items: center; z-index: 1;
  border: var(--nb-line); border-radius: 999px; background: var(--nb-ink); color: #fff; font-family: var(--font-head); font-weight: 700; font-size: 13px;
  animation: pop 300ms var(--spring);
}
.pod__voters { font-size: 10px; line-height: 1.2; color: var(--nb-ink-2); max-width: 100%; overflow-wrap: anywhere; }
.pod__epitaph { font-size: 11px; font-style: italic; line-height: 1.25; color: var(--nb-ink-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
@media (max-width: 719px) { .pod__epitaph, .pod__voters { display: none; } }
.pod--accused { background: var(--mafia-bg); box-shadow: var(--sh-4); }
.pod--accused .pod__status { color: var(--mafia-fg); }
.pod--dead { background: var(--nb-grey); box-shadow: none; }
.pod--dead .avatar { background: #cfcdd4; }
.pod--dead .pod__name { text-decoration: line-through; text-decoration-thickness: 2px; }
.pod.grave { filter: grayscale(1); }
.pod.grave .pod__role { filter: none; }
@keyframes pop { from { transform: scale(0.4); } to { transform: scale(1); } }
/* Spotlight on the accused: everyone else dims; the accused gets a light cone and a slow pulse */
body[data-spotlight] .seats .pod:not(.pod--accused) { opacity: 0.4; filter: saturate(0.3); }
.pod--accused::before {
  content: ''; position: absolute; inset: 0; pointer-events: none; border-radius: inherit;
  background: linear-gradient(180deg, var(--spot-cone, rgba(255, 226, 168, 0.5)), transparent 80%);
  clip-path: polygon(30% 0, 70% 0, 100% 100%, 0 100%);
  animation: spot-pulse 2.8s ease-in-out infinite;
}
@keyframes spot-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }
.tray .legend { gap: 6px 12px; }
.tray .legend__item { font-size: 11px; }
.tray .swatch { width: 14px; height: 14px; }

/* ============ Action drawer ============ */
.drawer {
  position: fixed; z-index: 16; right: 16px; top: 16px; bottom: calc(var(--sub-h) + 16px); width: var(--drawer-w);
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--nb-surface); border: var(--nb-line); border-radius: var(--r-24); box-shadow: var(--sh-6);
  transition: transform 260ms var(--ease), opacity 200ms;
}
.drawer[hidden] { display: none; }
.drawer__head { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: var(--nb-line); background: var(--accent); }
.drawer__head h2 { font-size: 19px; line-height: 1.1; }
.drawer__head .kicker { color: var(--nb-ink); }
.drawer__head .grow { flex: 1; min-width: 0; }
.drawer__icon { width: 44px; height: 44px; flex: none; display: grid; place-items: center; border: var(--nb-line); border-radius: var(--r-12); background: var(--nb-white); }
.drawer__body { flex: 1; overflow-y: auto; padding: 16px; display: grid; gap: 16px; align-content: start; overscroll-behavior: contain; }
.drawer-pill {
  position: fixed; z-index: 16; right: 16px; bottom: calc(var(--sub-h) + 16px);
  display: inline-flex; align-items: center; gap: 8px; min-height: 48px; padding: 0 18px;
  border: var(--nb-line); border-radius: 999px; background: var(--nb-white); box-shadow: var(--sh-4);
  font-family: var(--font-head); font-weight: 700; font-size: 14px; letter-spacing: 0.06em; text-transform: uppercase;
}
.drawer-pill:hover { transform: translate(-2px, -2px); box-shadow: var(--sh-6); }
.drawer-pill.is-pending { background: var(--accent); animation: nudge 1.6s ease-in-out infinite; }
.drawer-pill[hidden] { display: none; }
@keyframes nudge { 0%, 100% { box-shadow: var(--sh-4); } 50% { box-shadow: 0 0 0 6px rgba(254, 240, 138, 0.6), var(--sh-4); } }
/* Phones and tablets: the action sheet docks under the seat tray (in the page flow) instead
   of floating over it, so the table stays visible while you pick. Collapsing it leaves the
   floating Actions pill. */
@media (max-width: 1023px) {
  .drawer { position: relative; inset: auto; width: auto; margin-top: 16px; overflow: visible; box-shadow: var(--sh-6); }
  .drawer__body { overflow: visible; }
  .drawer__head { border-radius: calc(var(--r-24) - 2px) calc(var(--r-24) - 2px) 0 0; }
  .game-screen { padding-bottom: calc(var(--sub-h) + 96px); }
}

.section { display: grid; gap: 10px; }
.section__title { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.section__title h3 { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.1em; }
.drawer .banner { margin: 0; box-shadow: var(--sh-3); }
.brief { padding: 14px; border: var(--nb-line); border-radius: var(--r-16); background: var(--nb-white); box-shadow: var(--sh-3); display: grid; gap: 10px; }
.brief h3 { font-size: 20px; }
.brief p { color: var(--nb-ink-2); font-weight: 600; font-size: 14px; }
.targets { display: flex; flex-wrap: wrap; gap: 8px; }
.target {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 4px 12px 4px 4px; max-width: 100%;
  border: var(--nb-line); border-radius: 999px; background: var(--nb-white); box-shadow: var(--sh-2);
  font-family: var(--font-head); font-weight: 700; font-size: 14px;
  transition: transform 120ms var(--ease), box-shadow 120ms var(--ease), background 150ms;
}
.target span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.target:hover { transform: translate(-2px, -2px); box-shadow: var(--sh-4); }
.target:active { transform: translate(2px, 2px); box-shadow: none; }
.target[aria-pressed='true'] { background: var(--accent); box-shadow: var(--sh-3); }
.target[aria-pressed='true'] .avatar { box-shadow: 0 0 0 2px var(--nb-ink); }
.target .avatar { width: 32px; height: 32px; font-size: 11px; }
.target__count { margin-left: 2px; padding: 0 6px; border-radius: 999px; background: var(--nb-ink); color: #fff; font-size: 11px; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.actions > :only-child { grid-column: 1 / -1; }
.verdict { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.verdict .btn { min-height: 64px; font-size: 19px; }
.tally { display: flex; flex-wrap: wrap; gap: 8px; }
.tally span { padding: 4px 10px; border: var(--nb-line); border-radius: 999px; background: var(--nb-white); font-family: var(--font-head); font-weight: 700; font-size: 13px; }
.tally .g { background: var(--mafia-bg); }
.tally .i { background: var(--town-bg); }

/* Role card: hold to reveal */
.rolecard {
  position: relative; min-height: 168px; overflow: hidden; border: var(--nb-line); border-radius: var(--r-16); box-shadow: var(--sh-3);
  user-select: none; -webkit-user-select: none; touch-action: none; cursor: pointer;
  background: repeating-linear-gradient(45deg, var(--nb-ink) 0 10px, #2a2a30 10px 20px);
}
.rolecard__cover, .rolecard__face { position: absolute; inset: 0; padding: 16px; display: grid; transition: opacity 220ms var(--ease), transform 300ms var(--ease); }
.rolecard__cover { place-items: center; align-content: center; text-align: center; gap: 6px; color: #fff; }
.rolecard__cover b { font-family: var(--font-head); font-size: 17px; text-transform: uppercase; letter-spacing: 0.04em; }
.rolecard__cover .seal {
  width: 52px; height: 52px; display: grid; place-items: center; margin: 0 auto 4px; border: var(--nb-line); border-color: #fff; border-radius: 14px;
  background: var(--accent); color: var(--nb-ink); font-family: var(--font-head); font-weight: 700; font-size: 24px; box-shadow: 3px 3px 0 0 #fff;
}
.rolecard__cover .kicker { color: #d8d7de; }
.rolecard__face { opacity: 0; transform: translateY(10px); align-content: start; gap: 8px; background: var(--nb-white); }
.rolecard.open .rolecard__face { opacity: 1; transform: none; }
.rolecard.open .rolecard__cover { opacity: 0; }
.rolecard__face h3 { font-size: 30px; text-transform: uppercase; }
.rolecard__face p { font-size: 14px; color: var(--nb-ink-2); font-weight: 600; }
.rolecard__face .emblem { position: absolute; right: -8px; bottom: -12px; opacity: 0.14; }
.rolecard[data-team='town'] .rolecard__face { background: var(--town-bg); }
.rolecard[data-team='mafia'] .rolecard__face { background: var(--mafia-bg); }
.rolecard[data-team='neutral'] .rolecard__face { background: var(--neutral-bg); }
.abilities { display: flex; flex-wrap: wrap; gap: 6px; }

/* Notes / results */
.notes { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.notes li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border: var(--nb-line); border-radius: var(--r-12); background: var(--nb-white); font-weight: 600; font-size: 14px; }
.notes li.note-text { display: block; }
.notes .who { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }

/* Collapsible sections */
.fold { border: var(--nb-line); border-radius: var(--r-16); background: var(--nb-white); box-shadow: var(--sh-2); }
.fold > summary { cursor: pointer; list-style: none; display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 48px; padding: 0 14px; font-family: var(--font-head); font-weight: 700; font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; }
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary::after { content: '+'; font-size: 20px; line-height: 1; }
.fold[open] > summary::after { content: '–'; }
.fold__body { padding: 0 14px 14px; }
.casefile ol { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; font-size: 14px; }
.casefile li { padding: 6px 0 6px 12px; border-left: 3px solid var(--nb-ink); }
.house-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 14px; }
.house-list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 10px; border: var(--nb-line); border-radius: 10px; background: var(--nb-white); font-weight: 600; }
.house-list .on { background: var(--town-bg); }

/* Ghost chat (inside the drawer) */
.ghost { border: var(--nb-line); border-radius: var(--r-16); background: var(--neutral-bg); box-shadow: var(--sh-3); padding: 12px; display: grid; gap: 10px; }
.ghost--candle { background: var(--nb-butter); }
.chat-log { list-style: none; margin: 0; padding: 0; max-height: 260px; overflow-y: auto; display: grid; gap: 6px; align-content: start; font-size: 14px; overflow-wrap: anywhere; }
.chat-log li { padding: 8px 10px; border: var(--nb-line); border-radius: 12px 12px 12px 4px; background: var(--nb-white); }
.chat-log li.mine { background: var(--accent); border-radius: 12px 12px 4px 12px; margin-left: 24px; }
.chat-log li.muted { border-style: dashed; background: transparent; }
.chat-log b { font-family: var(--font-head); margin-right: 4px; }
.chat-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.chat-form .input { min-height: 44px; font-size: 15px; }

/* ============ Rules sheet (modal) ============ */
.modal-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(10, 10, 14, 0.55); }
.modal {
  position: fixed; z-index: 41; left: 50%; top: max(env(safe-area-inset-top), 20px); transform: translateX(-50%);
  width: min(720px, calc(100vw - 24px)); max-height: calc(100dvh - var(--sub-h) - 40px); overflow-y: auto; overscroll-behavior: contain;
  background: var(--nb-surface); border: var(--nb-line); border-radius: var(--r-24); box-shadow: var(--sh-6);
}
.modal__head { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; background: var(--accent); border-bottom: var(--nb-line); }
.modal__head h2 { font-size: 20px; text-transform: uppercase; }
.modal__body { padding: 16px; display: grid; gap: 16px; }
.rule-roles { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.rule-roles li { display: grid; grid-template-columns: auto 1fr; gap: 10px; padding: 10px; border: var(--nb-line); border-radius: var(--r-12); background: var(--nb-white); }
.rule-roles li p { font-size: 14px; color: var(--nb-ink-2); margin-top: 4px; }

/* ============ End screen ============ */
.end { max-width: 980px; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; }
.end-hero { text-align: center; display: grid; gap: 12px; justify-items: center; }
.end-hero__title { max-width: 100%; overflow-wrap: anywhere; font-size: clamp(34px, 10vw, 84px); text-transform: uppercase; padding: 6px 18px; border: var(--nb-line); border-radius: var(--r-16); box-shadow: var(--sh-6); background: var(--accent); }
.end[data-winner='town'] .end-hero__title { background: var(--town-solid); }
.end[data-winner='mafia'] .end-hero__title { background: var(--mafia-solid); }
.end[data-winner='serialKiller'] .end-hero__title { background: var(--neutral-solid); }
.end[data-winner='lovers'] .end-hero__title { background: #fda4af; }
.end-hero__tag { font-size: 18px; font-weight: 600; max-width: 46ch; }
.winners { display: grid; gap: 12px; }
.winners__block { display: grid; gap: 8px; }
.winners__row { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.winner { display: inline-flex; align-items: center; gap: 8px; padding: 4px 10px 4px 4px; border: var(--nb-line); border-radius: 999px; background: var(--nb-white); box-shadow: var(--sh-2); font-family: var(--font-head); font-weight: 700; }
.winner.is-dead { opacity: 0.6; }
.end .seg { --n: 3; }
.end-tab { min-height: 80px; margin-top: 14px; }
.empty { display: flex; align-items: center; gap: 12px; padding: 14px; border: var(--bw) dashed var(--nb-ink); border-radius: var(--r-16); background: rgba(255, 255, 255, 0.6); font-weight: 600; color: var(--nb-ink-2); }
.empty b { font-family: var(--font-head); color: var(--nb-ink); }
.empty__icon { width: 44px; height: 44px; flex: none; display: grid; place-items: center; border: var(--nb-line); border-radius: var(--r-12); background: var(--nb-grey); color: var(--nb-ink); }
.who { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.who .pname { font-family: var(--font-head); font-weight: 700; overflow-wrap: anywhere; }
.who .avatar { width: 30px; height: 30px; font-size: 11px; }
.awards { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.award { display: flex; gap: 12px; align-items: flex-start; padding: 14px; border: var(--nb-line); border-radius: var(--r-16); background: var(--nb-white); box-shadow: var(--sh-3); }
.award:nth-child(4n + 1) { background: var(--nb-butter); }
.award:nth-child(4n + 2) { background: var(--nb-mint); }
.award:nth-child(4n + 3) { background: var(--nb-lavender); }
.award:nth-child(4n + 4) { background: var(--nb-sky); }
.award-emoji { font-size: 30px; line-height: 1; flex: none; width: 48px; height: 48px; display: grid; place-items: center; border: var(--nb-line); border-radius: 12px; background: var(--nb-white); }
.award-body { display: grid; gap: 6px; min-width: 0; }
.award-line { font-size: 14px; color: var(--nb-ink-2); font-weight: 600; }
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.tl-round ul { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; }
.tl-death { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; padding: 10px 12px; border: var(--nb-line); border-radius: var(--r-12); background: var(--nb-white); }
.tl-cause { margin-left: auto; font-size: 13px; font-weight: 700; padding: 2px 8px; border: var(--nb-line); border-radius: 999px; }
.tl-cause.is-exec { background: var(--nb-primary); }
.tl-cause.is-night { background: var(--mafia-bg); }
.vote-table { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.vt-trial { padding: 12px 14px; border: var(--nb-line); border-radius: var(--r-16); background: var(--nb-white); display: grid; gap: 10px; }
.vt-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.vt-head .chip { margin-left: auto; }
.vt-votes { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0; font-size: 14px; }
.vt-votes dd { margin: 0; font-weight: 600; }
.recap-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 16px; }
.end-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }

/* ============ Player look picker (Spec 6) ============ */
.look { display: grid; gap: 8px; margin-top: 14px; }
.swatch-row { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 8px; }
.swatch-btn {
  aspect-ratio: 1; min-width: 0; min-height: 36px; display: grid; place-items: center; padding: 0;
  border: var(--nb-line); border-radius: 50%; background: var(--c); color: var(--nb-ink); box-shadow: var(--sh-2); cursor: pointer;
  transition: transform 120ms var(--ease), box-shadow 120ms var(--ease);
}
.swatch-btn:hover:not(:disabled) { transform: translate(-1px, -1px); box-shadow: var(--sh-3); }
.swatch-btn[aria-pressed='true'] { outline: 3px solid var(--nb-ink); outline-offset: 2px; }
.swatch-btn[aria-pressed='true'] .ico { color: #fff; filter: drop-shadow(0 0 1.5px #000); }
.swatch-btn:disabled { opacity: 0.25; cursor: not-allowed; box-shadow: none; background-image: linear-gradient(135deg, transparent 45%, var(--nb-ink) 45% 55%, transparent 55%); }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-btn {
  min-height: 34px; padding: 0 12px; border: var(--nb-line); border-radius: 999px; background: var(--nb-white); color: var(--nb-ink);
  font: inherit; font-size: 13px; font-weight: 700; cursor: pointer; box-shadow: var(--sh-2);
}
.chip-btn[aria-pressed='true'] { background: var(--nb-ink); color: var(--accent); }

/* ============ 3D table mode (Spec 6): panels over a full-screen scene ============ */
/* The screen's empty space is click-through so taps reach the figures on the canvas. */
.table-3d .screen { pointer-events: none; }
.table-3d .screen :is(.card, .hud, .hostbar, .banner, .drawer, .drawer-pill, .tray, .appbar, .modal, .modal-backdrop, .notice, .home, .end, form, button, a, input, select, textarea, label, summary, details) { pointer-events: auto; }
.table-3d .home-screen, .table-3d .loading-screen { pointer-events: auto; }
/* Lobby: the cards sit in a column beside the table (desktop) or under it (phones). */
@media (min-width: 1024px) {
  .table-3d .lobby-screen .wrap { max-width: 560px; margin-right: 0; }
  .table-3d .lobby-screen .lobby-grid { grid-template-columns: minmax(0, 1fr); }
  .table-3d .lobby-screen .lobby-col { display: grid; gap: 22px; }
}
@media (max-width: 1023px) {
  .table-3d .lobby-screen .wrap.has-appbar { padding-top: 50dvh; }
}
/* Game: the 3D table replaces the seat tray visually; the tray stays in the DOM for screen
   readers and slides up when a seat button gets keyboard focus. */
.table-3d .game-screen .tray:not(:focus-within) {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.table-3d .game-screen .tray:focus-within { position: fixed; left: var(--gutter); right: var(--gutter); bottom: calc(var(--sub-h) + 16px); z-index: 17; max-height: 45dvh; overflow: auto; }
.table-3d .game-screen .game-layout { min-height: 0; }
/* Phones and tablets: the action sheet floats at the bottom, over the scene. */
@media (max-width: 1023px) {
  .table-3d .drawer {
    position: fixed; left: 8px; right: 8px; top: auto; bottom: calc(var(--sub-h) + 8px); width: auto; margin: 0;
    max-height: min(46dvh, 520px); overflow: hidden; display: flex; flex-direction: column;
    background: color-mix(in srgb, var(--nb-surface) 92%, transparent); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
    animation: sheet-up 280ms var(--ease);
  }
  .table-3d .drawer__body { overflow-y: auto; }
  .table-3d .drawer__head { padding: 10px 14px; }
  .table-3d .drawer__head h2 { font-size: 17px; }
  .table-3d .game-screen { padding-bottom: 0; }
}
@keyframes sheet-up { from { transform: translateY(24px); opacity: 0; } }
/* Desktop drawer: translucent so the scene shows through the edges. */
@media (min-width: 1024px) {
  .table-3d .drawer { background: color-mix(in srgb, var(--nb-surface) 94%, transparent); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); }
}

/* ============ Subtitle (narrator captions) ============ */
.subtitle[hidden] { display: none; }
.subtitle {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: auto auto minmax(0, 1fr); gap: 8px 12px; align-items: center;
  padding: 12px var(--gutter) max(12px, env(safe-area-inset-bottom));
  background: var(--nb-white); border-top: var(--nb-line); box-shadow: 0 -4px 0 0 var(--nb-ink);
}
.subtitle__tag {
  display: inline-flex; align-items: center; gap: 8px; min-height: 32px; padding: 0 12px; border: var(--nb-line); border-radius: 999px;
  background: var(--nb-ink); color: var(--accent); font-family: var(--font-head); font-weight: 700; font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase;
}
.subtitle__live { width: 9px; height: 9px; border-radius: 50%; background: var(--nb-grey); }
.subtitle.is-live .subtitle__live { background: var(--accent); animation: pulse 1.2s infinite; }
.subtitle__text {
  max-width: 900px;
  font-family: var(--font-head); font-weight: 700; font-size: clamp(17px, 4.2vw, 22px); line-height: 1.3; color: var(--nb-ink);
}
@media (max-width: 719px) {
  .subtitle { grid-template-columns: auto minmax(0, 1fr); gap: 4px 12px; align-items: start; padding-top: 10px; }
  .subtitle__replay { grid-column: 1; grid-row: 1 / 3; }
  .subtitle__tag { grid-column: 2; grid-row: 1; justify-self: start; min-height: 22px; padding: 0 8px; gap: 6px; font-size: 10px; border-width: 0; }
  .subtitle__text { grid-column: 2; grid-row: 2; font-size: 17px; }
}
.subtitle__text .w { opacity: 0; display: inline-block; animation: word 420ms var(--ease) forwards; }
@keyframes word { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.subtitle__replay {
  flex: none; width: 44px; height: 44px; display: grid; place-items: center;
  border: var(--nb-line); border-radius: var(--r-12); background: var(--accent); color: var(--nb-ink); box-shadow: var(--sh-2);
}

/* ============ Toast ============ */
.toast {
  position: fixed; z-index: 50; left: 50%; top: max(env(safe-area-inset-top), 16px); transform: translateX(-50%);
  max-width: min(92vw, 460px); padding: 12px 18px; border: var(--nb-line); border-radius: var(--r-12); box-shadow: var(--sh-4);
  background: var(--mafia-bg); color: var(--nb-ink); font-weight: 700; animation: drop 300ms var(--spring);
}
.toast.ok { background: var(--town-bg); }
.toast[hidden] { display: none; }
@keyframes drop { from { transform: translate(-50%, -20px); opacity: 0; } }

/* ============ Entrance choreography (only on phase change) ============ */
body[data-enter] .enter { opacity: 0; animation: rise 520ms var(--ease) forwards; animation-delay: calc(var(--i, 0) * 50ms); }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
  .btn:hover, .icon-btn:hover, .choice:hover, .check-tile:hover, button.pod:hover, .target:hover, .hp-card:hover, .drawer-pill:hover { transform: none; }
  .grain { display: none; }
  /* Fades still play under reduced motion (no movement involved) */
  .wash.play { animation-duration: 3s !important; }
}
