/* ==========================================================================
   Nightfall - mobile-first, theme-aware night atmosphere.
   Palette switches on [data-theme] set on <html>: werewolf (moonlit indigo)
   and mafia (noir amber). Shared tokens live in :root.
   ========================================================================== */

:root {
  --radius: 18px;
  --radius-sm: 12px;
  --tap: 56px;
  --gap: 14px;
  --maxw: 620px;

  --ink: #eef1ff;
  --ink-dim: #aeb6dd;
  --ink-faint: #767ea6;

  /* werewolf defaults so first paint is themed even before JS */
  --bg-0: #080b18;
  --bg-1: #0d1226;
  --card: rgba(30, 37, 66, 0.72);
  --card-solid: #1a2140;
  --line: rgba(126, 142, 200, 0.22);
  --line-strong: rgba(126, 142, 200, 0.4);

  --accent: #8ea0ff;
  --accent-2: #b9a7ff;
  --action: #5b6cff;
  --action-ink: #ffffff;
  --glow: rgba(120, 140, 255, 0.55);

  --killers: #ff5f74;
  --village: #46e0a8;
  --warn: #ffc061;

  --moon-a: #f2f6ff;
  --moon-b: #b7c6ff;
  --moon-glow: rgba(150, 175, 255, 0.5);
  --sky-top: #0a0f24;
  --sky-bot: #05070f;
  --star: rgba(220, 230, 255, 0.9);
  --star-o: 0.55;
}

html[data-theme="mafia"] {
  --bg-0: #0b0a09;
  --bg-1: #16120c;
  --card: rgba(44, 36, 26, 0.72);
  --card-solid: #211a12;
  --line: rgba(214, 170, 110, 0.2);
  --line-strong: rgba(214, 170, 110, 0.42);

  --accent: #ffc061;
  --accent-2: #ffd79a;
  --action: #d8483f;
  --action-ink: #fff6ec;
  --glow: rgba(255, 176, 84, 0.5);

  --killers: #ff5b5b;
  --village: #ffcf6a;
  --warn: #ffc061;

  --moon-a: #ffe9c2;
  --moon-b: #ffb45e;
  --moon-glow: rgba(255, 170, 80, 0.45);
  --sky-top: #171008;
  --sky-bot: #070604;
  --star: rgba(255, 226, 180, 0.85);
  --star-o: 0.28;
}

* { box-sizing: border-box; }

html {
  margin: 0; padding: 0;
  background: var(--bg-0);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}
body { margin: 0; padding: 0; background: transparent; min-height: 100vh; min-height: 100dvh; overflow-x: hidden; }

/* ---------- night sky backdrop ---------- */
.sky {
  position: fixed; inset: 0; z-index: -1; overflow: hidden;
  background:
    radial-gradient(120% 80% at 78% -10%, color-mix(in srgb, var(--moon-glow) 40%, transparent), transparent 60%),
    linear-gradient(180deg, var(--sky-top), var(--sky-bot));
}
.sky .stars {
  position: absolute; inset: -50%;
  background-image:
    radial-gradient(1.4px 1.4px at 20% 30%, var(--star), transparent),
    radial-gradient(1.2px 1.2px at 45% 65%, var(--star), transparent),
    radial-gradient(1.6px 1.6px at 70% 20%, var(--star), transparent),
    radial-gradient(1px 1px at 85% 55%, var(--star), transparent),
    radial-gradient(1.2px 1.2px at 12% 80%, var(--star), transparent),
    radial-gradient(1px 1px at 60% 85%, var(--star), transparent),
    radial-gradient(1.3px 1.3px at 33% 12%, var(--star), transparent);
  background-repeat: repeat;
  background-size: 320px 320px;
  opacity: var(--star-o);
  animation: twinkle 6s ease-in-out infinite alternate;
}
.sky .moon {
  position: absolute; top: 5%; right: 8%;
  width: 96px; height: 96px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, var(--moon-a), var(--moon-b) 70%, color-mix(in srgb, var(--moon-b) 60%, #000) 100%);
  box-shadow: 0 0 60px 18px var(--moon-glow), inset -10px -8px 22px rgba(0, 0, 0, 0.25);
  animation: float 9s ease-in-out infinite alternate;
}
.sky .fog {
  position: absolute; inset: 0;
  background: radial-gradient(80% 50% at 50% 120%, color-mix(in srgb, var(--glow) 30%, transparent), transparent 70%);
}
@keyframes twinkle { from { opacity: calc(var(--star-o) * 0.6); } to { opacity: var(--star-o); } }
@keyframes float { from { transform: translateY(0); } to { transform: translateY(10px); } }

/* ---------- a11y helpers ---------- */
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 10;
  background: var(--action); color: var(--action-ink); padding: 10px 14px; border-radius: 0 0 var(--radius-sm) 0;
}
.skip-link:focus { left: 0; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* ---------- header ---------- */
.app-header {
  display: flex; align-items: center; gap: 10px;
  padding: max(12px, env(safe-area-inset-top)) 16px 10px;
  max-width: var(--maxw); margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 8px; margin: 0 auto; }
.brand-mark { width: 22px; height: 22px; color: var(--moon-a); filter: drop-shadow(0 0 6px var(--moon-glow)); }
.app-title {
  font-size: 20px; letter-spacing: 0.22em; text-transform: uppercase; margin: 0; font-weight: 800;
  background: linear-gradient(100deg, var(--accent-2), var(--accent) 55%, var(--village));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.round-badge {
  font-size: 12px; color: var(--ink-dim); border: 1px solid var(--line);
  border-radius: 999px; padding: 4px 10px; white-space: nowrap; backdrop-filter: blur(6px);
}

/* ---------- layout ---------- */
.app { max-width: var(--maxw); margin: 0 auto; padding: 8px 16px calc(30px + env(safe-area-inset-bottom)); }
.screen { animation: rise 0.34s cubic-bezier(0.2, 0.7, 0.2, 1); }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.lede { color: var(--ink-dim); margin: 0 0 18px; line-height: 1.55; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.14em; color: var(--ink-faint); margin: 22px 0 10px; }
.big-title { font-size: 30px; font-weight: 800; margin: 6px 0 4px; letter-spacing: -0.01em; }
.centered { text-align: center; }

/* ---------- cards ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: var(--gap); backdrop-filter: blur(10px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
}

/* ---------- buttons ---------- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: var(--tap); border: none; border-radius: var(--radius);
  background: linear-gradient(180deg, color-mix(in srgb, var(--action) 88%, #fff 12%), var(--action));
  color: var(--action-ink); font-size: 18px; font-weight: 700; cursor: pointer; padding: 12px 18px;
  box-shadow: 0 8px 22px color-mix(in srgb, var(--action) 45%, transparent), inset 0 1px 0 rgba(255, 255, 255, 0.18);
  transition: transform 0.08s ease, box-shadow 0.15s ease, filter 0.15s ease;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(2px); box-shadow: 0 3px 12px color-mix(in srgb, var(--action) 40%, transparent); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; filter: none; }
.btn.secondary {
  background: var(--card); color: var(--ink); border: 1px solid var(--line-strong); box-shadow: none; backdrop-filter: blur(8px);
}
.btn.danger { background: linear-gradient(180deg, color-mix(in srgb, var(--killers) 85%, #fff 15%), var(--killers)); color: #2a0a0f; box-shadow: 0 8px 22px color-mix(in srgb, var(--killers) 40%, transparent); }
.btn.good { background: linear-gradient(180deg, color-mix(in srgb, var(--village) 85%, #fff 15%), var(--village)); color: #05271c; box-shadow: 0 8px 22px color-mix(in srgb, var(--village) 40%, transparent); }
.ghost-btn { background: transparent; border: 1px solid var(--line); color: var(--ink-dim); border-radius: 999px; padding: 6px 12px; font-size: 13px; cursor: pointer; }
.ghost-btn:hover { color: var(--ink); border-color: var(--line-strong); }

/* ---------- segmented control ---------- */
.segment { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 5px; gap: 5px; backdrop-filter: blur(8px); }
.segment button { flex: 1; min-height: 50px; border: none; border-radius: 13px; background: transparent; color: var(--ink-dim); font-size: 16px; font-weight: 700; cursor: pointer; transition: background 0.15s, color 0.15s; }
.segment button[aria-pressed="true"] { background: linear-gradient(180deg, color-mix(in srgb, var(--action) 90%, #fff 10%), var(--action)); color: var(--action-ink); box-shadow: 0 6px 16px color-mix(in srgb, var(--action) 40%, transparent); }

/* theme lock (subdomain) */
.theme-lock { text-align: center; }
.theme-lock-name { font-size: 26px; font-weight: 800; letter-spacing: 0.02em; }
.cross-link { display: inline-block; margin-top: 12px; color: var(--accent); font-size: 14px; font-weight: 600; text-decoration: none; border-bottom: 1px dashed color-mix(in srgb, var(--accent) 60%, transparent); }

/* ---------- stepper ---------- */
.stepper-row { display: flex; align-items: center; justify-content: space-between; padding: 6px 0; }
.stepper-label { font-size: 16px; }
.stepper-sub { display: block; font-size: 12px; color: var(--ink-faint); margin-top: 2px; }
.stepper { display: flex; align-items: center; gap: 12px; }
.stepper button { width: 46px; height: 46px; border-radius: 13px; border: 1px solid var(--line-strong); background: var(--card-solid); color: var(--ink); font-size: 24px; line-height: 1; cursor: pointer; }
.stepper button:active { transform: translateY(1px); }
.stepper output { min-width: 34px; text-align: center; font-size: 20px; font-weight: 700; }

/* ---------- toggle ---------- */
.toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; gap: 12px; }
.switch { position: relative; width: 54px; height: 32px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch .track { position: absolute; inset: 0; background: var(--card-solid); border: 1px solid var(--line-strong); border-radius: 999px; transition: background 0.15s, border-color 0.15s; }
.switch .thumb { position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 999px; background: var(--ink-faint); transition: transform 0.18s cubic-bezier(0.4,0,0.2,1), background 0.15s; }
.switch input:checked ~ .track { background: color-mix(in srgb, var(--action) 40%, transparent); border-color: var(--action); }
.switch input:checked ~ .thumb { transform: translateX(22px); background: var(--action); }

.validation { color: var(--warn); font-size: 14px; min-height: 20px; margin: 8px 0 0; }

/* ---------- names ---------- */
.names-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.names-grid input { min-height: 46px; background: var(--card-solid); border: 1px solid var(--line); border-radius: var(--radius-sm); color: var(--ink); padding: 0 12px; font-size: 15px; width: 100%; }
.names-grid input:focus { border-color: var(--accent); outline: none; }

/* ---------- seat grid ---------- */
.seat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; margin-top: 8px; }
.seat {
  min-height: 74px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--card);
  color: var(--ink); font-size: 17px; font-weight: 700; cursor: pointer; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 10px; text-align: center; backdrop-filter: blur(6px);
  transition: transform 0.08s, border-color 0.15s, background 0.15s;
}
.seat:active { transform: scale(0.97); }
.seat .seat-sub { display: block; font-size: 12px; font-weight: 500; color: var(--ink-faint); margin-top: 3px; }
.seat.selected { border-color: var(--accent); background: color-mix(in srgb, var(--action) 22%, transparent); box-shadow: 0 0 0 1px var(--accent), 0 8px 20px color-mix(in srgb, var(--action) 30%, transparent); }
.seat.dead { opacity: 0.4; text-decoration: line-through; cursor: default; }
.seat:disabled { cursor: default; }

/* ---------- handover ---------- */
.handover { text-align: center; padding: 24px 8px; }
.handover .pass-to { font-size: 15px; color: var(--ink-dim); letter-spacing: 0.02em; }
.handover .pass-name { font-size: 36px; font-weight: 800; margin: 8px 0 4px; }
.handover .pass-note { color: var(--ink-faint); font-size: 14px; margin-bottom: 22px; }

/* ---------- reveal pad ---------- */
.reveal-pad {
  user-select: none; -webkit-user-select: none; touch-action: none;
  min-height: 260px; border-radius: 24px; border: 1px solid var(--line-strong);
  background: radial-gradient(120% 120% at 50% 30%, color-mix(in srgb, var(--glow) 22%, transparent), var(--card) 70%);
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  padding: 22px; cursor: pointer; position: relative; overflow: hidden; box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.3);
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.1s;
}
.reveal-pad::before {
  content: ""; position: absolute; width: 130px; height: 130px; border-radius: 50%;
  background: radial-gradient(circle, var(--glow), transparent 70%); opacity: 0.5;
  animation: orb 3.2s ease-in-out infinite;
}
.reveal-pad.holding { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 0 50px color-mix(in srgb, var(--glow) 70%, transparent); transform: scale(1.01); }
.reveal-pad.holding::before { opacity: 0; }
.reveal-pad > * { position: relative; z-index: 1; }
@keyframes orb { 0%, 100% { transform: scale(0.85); opacity: 0.35; } 50% { transform: scale(1.1); opacity: 0.6; } }
.reveal-hint { color: var(--ink-dim); font-size: 16px; }
.reveal-icon { width: 62px; height: 62px; margin-bottom: 10px; }
.reveal-icon.killers { color: var(--killers); }
.reveal-icon.village { color: var(--village); }
.reveal-role { font-size: 34px; font-weight: 800; }
.reveal-team { font-size: 13px; letter-spacing: 0.12em; text-transform: uppercase; margin-top: 4px; }
.reveal-team.killers { color: var(--killers); }
.reveal-team.village { color: var(--village); }
.reveal-desc { color: var(--ink-dim); font-size: 15px; margin-top: 12px; line-height: 1.5; max-width: 34ch; }
.reveal-mates { margin-top: 12px; font-size: 15px; color: var(--warn); font-weight: 700; }

/* ---------- announcements ---------- */
.announce { text-align: center; padding: 22px 8px; }
.announce .pass-to { color: var(--ink-dim); font-size: 15px; letter-spacing: 0.04em; }
.announce .headline { font-size: 27px; font-weight: 800; margin: 10px 0; line-height: 1.2; }
.announce .sub { color: var(--ink-dim); font-size: 16px; line-height: 1.5; }
.tag { display: inline-block; font-size: 13px; padding: 5px 12px; border-radius: 999px; border: 1px solid var(--line-strong); color: var(--ink-dim); margin-top: 12px; }
.tag.killers { color: var(--killers); border-color: var(--killers); }
.tag.village { color: var(--village); border-color: var(--village); }

/* ---------- roster / result ---------- */
.roster { list-style: none; padding: 0; margin: 16px 0 0; }
.roster li { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm); margin-bottom: 8px; background: var(--card); backdrop-filter: blur(6px); }
.role-ic { width: 26px; height: 26px; flex: none; }
.role-ic.killers { color: var(--killers); }
.role-ic.village { color: var(--village); }
.roster .r-name { font-weight: 700; flex: 1; }
.roster .r-role { font-size: 14px; font-weight: 600; }
.roster .r-role.killers { color: var(--killers); }
.roster .r-role.village { color: var(--village); }
.roster li.out .r-name { color: var(--ink-faint); text-decoration: line-through; }

/* scoreboard */
.scoreboard li { gap: 12px; }
.scoreboard .r-rank { width: 26px; text-align: center; font-weight: 800; color: var(--accent); flex: none; }
.scoreboard li:nth-child(1) .r-rank { color: #ffd15c; }
.scoreboard .r-name { flex: 1; }
.scoreboard .r-score { font-weight: 800; font-variant-numeric: tabular-nums; }
.scoreboard .r-of { color: var(--ink-faint); font-weight: 500; }
.scoreboard .r-rate { width: 52px; text-align: right; color: var(--ink-dim); font-variant-numeric: tabular-nums; }

/* ---------- win banner ---------- */
.win-banner { text-align: center; padding: 26px 14px; border-radius: 22px; margin-bottom: 10px; position: relative; overflow: hidden; }
.win-banner::after { content: ""; position: absolute; inset: 0; background: radial-gradient(70% 90% at 50% -10%, currentColor, transparent 60%); opacity: 0.16; }
.win-banner.killers { color: var(--killers); background: color-mix(in srgb, var(--killers) 14%, transparent); border: 1px solid var(--killers); }
.win-banner.village { color: var(--village); background: color-mix(in srgb, var(--village) 14%, transparent); border: 1px solid var(--village); }
.win-banner .win-title { font-size: 32px; font-weight: 800; color: var(--ink); }
.win-banner .win-sub { color: var(--ink-dim); margin-top: 6px; }

.footnote { color: var(--ink-faint); font-size: 13px; text-align: center; margin-top: 18px; line-height: 1.5; }
.error-box { border: 1px solid var(--killers); background: color-mix(in srgb, var(--killers) 10%, transparent); border-radius: var(--radius); padding: 16px; }
.error-box code { background: rgba(0, 0, 0, 0.35); padding: 2px 6px; border-radius: 6px; }

@media (prefers-reduced-motion: reduce) {
  .screen, .sky .stars, .sky .moon, .reveal-pad::before { animation: none; }
  .btn, .seat, .switch .thumb { transition: none; }
}
