/* Two-Faced — phone-first styles. No external fonts or libraries. */
:root {
  --bg: #14111a;
  --bg-2: #1d1925;
  --panel: #221d2c;
  --line: #3a3347;
  --text: #f4efe6;
  --muted: #a99fb8;
  --accent: #f2c14e;      /* warm gold: the "light" face */
  --accent-ink: #1a1408;
  --danger: #ff6b6b;
  --done: #5b5566;        /* grey used for cards that are finished */
  --radius: 18px;
  --tap: 56px;
  --font: "Avenir Next", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background:
    radial-gradient(120% 60% at 50% -10%, #2b2238 0%, transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

#app {
  max-width: 520px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  min-height: 100%;
}
.screen { display: flex; flex-direction: column; gap: 16px; min-height: calc(100vh - 40px); min-height: calc(100dvh - 40px); }

h1 { font-size: 32px; line-height: 1.1; margin: 0; font-weight: 800; letter-spacing: -0.02em; }
h2 { font-size: 15px; margin: 0; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); font-weight: 700; }

/* Brand */
.brand { text-align: center; padding: 12px 0 4px; }
.brand h1 { font-size: 44px; }
.tagline { color: var(--muted); margin: 6px 0 0; }
.mark {
  width: 64px; height: 64px; margin: 0 auto 10px; border-radius: 50%;
  background: linear-gradient(90deg, var(--accent) 50%, #2a2333 50%);
  border: 3px solid var(--accent);
  position: relative;
}
.mark span::before, .mark span::after {
  content: ""; position: absolute; top: 24px; width: 9px; height: 9px; border-radius: 50%;
}
.mark span::before { left: 14px; background: #2a2333; } /* same tone as the dark half, matching the app icon */
.mark span::after { right: 14px; background: var(--accent); }

/* Panels */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; }
.count { font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 700; }

/* Buttons */
.btn {
  min-height: var(--tap); padding: 0 20px; border-radius: 14px; border: 2px solid transparent;
  font-weight: 700; font-size: 17px; display: inline-flex; align-items: center; justify-content: center;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:disabled { background: #3a3347; color: #7d748c; cursor: not-allowed; }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn-big { min-height: 64px; font-size: 20px; width: 100%; }
.btn:focus-visible, .toggle:focus-visible, .segmented button:focus-visible, .name-card:focus-visible, .hold-btn:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 2px;
}

/* Add player */
.add-row { display: flex; gap: 8px; }
.add-row input {
  flex: 1; min-width: 0; min-height: var(--tap); padding: 0 16px; border-radius: 14px;
  border: 2px solid var(--line); background: var(--bg-2); font-size: 18px;
}
.add-row input::placeholder { color: #7d748c; }
.field-error { color: var(--danger); margin: -4px 0 0; min-height: 0; font-size: 15px; }
.field-error:empty { display: none; }

.player-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.player-list li {
  display: flex; align-items: center; gap: 12px; min-height: var(--tap);
  padding: 4px 4px 4px 14px; border-radius: 14px; background: var(--bg-2);
  border: 3px solid var(--c);
}
.dot { width: 14px; height: 14px; border-radius: 50%; background: var(--c); flex: none; }
.player-list .pname { flex: 1; font-weight: 700; font-size: 18px; overflow-wrap: anywhere; }
.remove-btn {
  width: 48px; height: 48px; border-radius: 12px; border: 0; background: transparent;
  color: var(--muted); font-size: 26px; line-height: 1;
}
.remove-btn:active { background: #2e2839; }

/* Settings */
.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: var(--tap); }
.setting-stack { flex-direction: column; align-items: stretch; }
.setting-label { font-weight: 700; display: block; }
.setting-help { color: var(--muted); font-size: 14px; display: block; }
.hint { margin: -6px 0 0; color: var(--muted); font-size: 14px; }
.hint:empty { display: none; }
.hint::before { content: "🔒 "; }

.segmented { display: inline-flex; background: var(--bg-2); border: 2px solid var(--line); border-radius: 14px; padding: 3px; gap: 3px; }
.segmented button {
  min-width: 56px; min-height: 48px; border: 0; border-radius: 10px; background: transparent; font-weight: 800; font-size: 18px;
}
.segmented button[aria-checked="true"] { background: var(--accent); color: var(--accent-ink); }
.segmented button:disabled { color: #5f586c; cursor: not-allowed; text-decoration: line-through; }
.segmented-wide { display: grid; grid-template-columns: repeat(3, 1fr); }
.segmented-wide button { min-width: 0; font-size: 16px; }

.toggle {
  width: 64px; height: 40px; flex: none; border-radius: 999px; border: 2px solid var(--line); background: var(--bg-2);
  position: relative; padding: 0;
}
.toggle span { position: absolute; top: 4px; left: 4px; width: 28px; height: 28px; border-radius: 50%; background: var(--muted); transition: transform .15s; }
.toggle[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); }
.toggle[aria-pressed="true"] span { transform: translateX(24px); background: var(--accent-ink); }
.toggle:disabled { opacity: .4; cursor: not-allowed; }

select { min-height: 48px; border-radius: 12px; background: var(--bg-2); border: 2px solid var(--line); padding: 0 12px; }

/* Rules */
.rules ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.rules li { display: flex; gap: 10px; align-items: flex-start; font-size: 15px; }
.rules .status {
  flex: none; font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em;
  padding: 3px 8px; border-radius: 999px; margin-top: 1px; min-width: 84px; text-align: center;
}
.rules .is-on .status { background: #2f4a2b; color: #bff0b0; }
.rules .is-off .status { background: #3a3347; color: #a99fb8; }
.rules .is-off .rule-text { color: var(--muted); }

/* Start bar */
.start-bar { position: sticky; bottom: 0; margin-top: auto; padding: 12px 0 4px; background: linear-gradient(transparent, var(--bg) 30%); display: flex; flex-direction: column; gap: 8px; }
.start-note { margin: 0; text-align: center; color: var(--muted); font-size: 15px; }

/* Reveal list */
.screen-head { text-align: center; padding-top: 8px; }
.screen-head p { color: var(--muted); margin: 6px 0 0; }
.progress { font-weight: 700; color: var(--text) !important; font-variant-numeric: tabular-nums; }
.card-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.name-card {
  width: 100%; min-height: 88px; border-radius: var(--radius); background: var(--panel);
  border: 4px solid var(--c); font-weight: 800; font-size: 20px; padding: 10px; overflow-wrap: anywhere;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
}
.name-card:active { transform: scale(.98); }
.name-card.is-done { border-color: var(--done); background: #1b1820; color: #77707f; cursor: not-allowed; }
.name-card .tag { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .1em; }
#quit-btn { margin-top: auto; }

/* Reveal one player */
.screen-reveal { text-align: center; }
.reveal-top { padding-top: 8px; }
.pass-label { margin: 0; color: var(--muted); text-transform: uppercase; letter-spacing: .14em; font-size: 13px; font-weight: 700; }
.reveal-name { margin: 4px 0; font-size: 38px; font-weight: 900; letter-spacing: -0.02em; overflow-wrap: anywhere; color: var(--c); }
.reveal-only { margin: 0; color: var(--muted); }

/* Same size and colour for every role, so nothing leaks from across the room. */
.role-box {
  min-height: 230px; border-radius: var(--radius); border: 2px dashed var(--line);
  display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 18px; gap: 6px;
}
.role-box.is-open { border-style: solid; border-color: var(--text); background: #0d0b11; }
.role-you { margin: 0; color: var(--muted); font-size: 15px; text-transform: uppercase; letter-spacing: .14em; }
.role-name { margin: 0; font-size: 34px; font-weight: 900; line-height: 1.05; }
.role-word-label { margin: 10px 0 0; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .14em; }
.role-word { margin: 0; font-size: 36px; font-weight: 900; color: var(--accent); overflow-wrap: anywhere; }
.role-note { margin: 4px 0 0; font-size: 15px; }
.role-note + .role-note { color: var(--muted); }

.hold-btn {
  align-self: center; width: 180px; height: 180px; border-radius: 50%;
  border: 4px solid var(--accent); background: radial-gradient(circle at 50% 40%, #3a2f47, #1d1925);
  font-weight: 800; font-size: 20px; color: var(--text);
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: none;
}
.hold-btn.is-holding { background: var(--accent); color: var(--accent-ink); transform: scale(.97); }
.hold-help { margin: -4px 0 0; color: var(--muted); font-size: 14px; }
.reveal-actions { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }

/* Everyone has seen */
.first-wrap { text-align: center; margin: auto 0; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.first-label { margin: 0; color: var(--muted); text-transform: uppercase; letter-spacing: .14em; font-size: 13px; font-weight: 700; }
.first-card {
  min-width: 70%; padding: 24px 20px; border-radius: var(--radius); border: 5px solid var(--c);
  background: var(--panel); font-size: 34px; font-weight: 900; overflow-wrap: anywhere;
}
.first-help { margin: 0; color: var(--muted); max-width: 32ch; }

/* Language toggle (flags + code, never colour alone) */
.lang-toggle { display: inline-flex; gap: 4px; background: var(--bg-2); border: 2px solid var(--line); border-radius: 14px; padding: 3px; }
.lang-btn {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px; min-width: 64px; padding: 0 10px;
  border: 0; border-radius: 10px; background: transparent; font-weight: 800; font-size: 15px; color: var(--muted);
}
.lang-btn .flag { display: inline-flex; width: 30px; height: 20px; align-items: center; justify-content: center; border-radius: 3px; overflow: hidden; box-shadow: 0 0 0 1px rgba(255,255,255,.25); }
.lang-btn .flag svg { width: 30px; height: 20px; display: block; }
.lang-btn[aria-checked="true"] { background: var(--accent); color: var(--accent-ink); }
.lang-btn[aria-checked="false"] .flag { opacity: .7; }
.lang-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Shared bottom buttons */
.bottom-actions { margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding-top: 8px; }
.sticky-actions { position: sticky; bottom: 0; padding: 12px 0 4px; background: linear-gradient(transparent, var(--bg) 30%); }
.btn-danger { background: var(--danger); color: #250707; }
.btn-danger:disabled { background: #3a3347; color: #7d748c; cursor: not-allowed; }

/* Round */
.timer {
  text-align: center; font-size: 72px; font-weight: 900; line-height: 1; letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums; padding: 8px 0;
}
.timer.is-low { color: var(--danger); }
.card-grid-small .name-card { min-height: 64px; font-size: 17px; border-width: 3px; }
.name-card-static { cursor: default; }
.name-card-static:active { transform: none; }
.name-card.is-dead { border-color: var(--done); background: #1b1820; color: #77707f; }
.name-card.is-dead > span:first-child { text-decoration: line-through; }

/* Voting */
.time-up { margin: 0 0 6px !important; color: var(--danger) !important; font-weight: 800; text-transform: uppercase; letter-spacing: .12em; }
.vote-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.vote-option {
  width: 100%; min-height: 64px; display: flex; align-items: center; gap: 14px; padding: 0 16px;
  border-radius: 16px; background: var(--panel); border: 3px solid var(--c, var(--line)); text-align: left;
  font-size: 20px; font-weight: 800;
}
.vote-mark { width: 26px; height: 26px; flex: none; border-radius: 50%; border: 3px solid var(--c, var(--muted)); }
.vote-option[aria-checked="true"] { background: #3a2f47; box-shadow: 0 0 0 3px var(--text) inset; }
.vote-option[aria-checked="true"] .vote-mark { background: var(--c, var(--text)); box-shadow: 0 0 0 4px var(--panel) inset; }
.vote-name { overflow-wrap: anywhere; }
.vote-none { --c: var(--muted); border-style: dashed; color: var(--muted); }
.vote-none[aria-checked="true"] { color: var(--text); }

/* Vote result */
.result-wrap { margin: auto 0; display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center; }
.result-card {
  width: 100%; padding: 32px 20px; border-radius: var(--radius); border: 5px solid var(--c, var(--line));
  background: var(--panel);
}
.result-card.is-none { border-style: dashed; }
.result-line { margin: 0; font-size: 30px; font-weight: 900; line-height: 1.15; overflow-wrap: anywhere; }

/* Game over */
.over-head { text-align: center; padding: 16px 0 4px; }
.over-title { font-size: 36px; line-height: 1.1; color: var(--accent); }
.over-word { text-align: center; gap: 4px; }
.over-word-main { margin: 0; font-size: 36px; font-weight: 900; overflow-wrap: anywhere; }
.over-hint { margin: 0; color: var(--muted); }
.over-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.over-row {
  display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 6px 12px;
  border-radius: 14px; background: var(--bg-2); border: 3px solid var(--c);
}
.over-name { flex: 1; font-weight: 800; font-size: 18px; overflow-wrap: anywhere; }
.over-row.is-out .over-name { text-decoration: line-through; color: var(--muted); }
.out-tag { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.role-chip { font-size: 13px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; padding: 4px 10px; border-radius: 999px; background: #3a3347; }
.role-imposter .role-chip { background: var(--danger); color: #250707; }
.role-jester .role-chip { background: var(--accent); color: var(--accent-ink); }

/* Opening intro (GAME.md, Design). Pure CSS: it hides itself at the end even if the script fails. */
.intro {
  position: fixed; inset: 0; z-index: 50; background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  animation: intro-out .3s ease-in .85s forwards;
}
.intro-face { width: 180px; height: 180px; overflow: visible; animation: intro-thud .2s ease-out .5s forwards; }
.intro-half, .intro-pulse { transform-box: view-box; transform-origin: 256px 256px; }
.intro-half-l { animation: intro-pull-l .45s cubic-bezier(.6,0,.9,.4) .05s both, intro-snap-l .2s ease-out .5s forwards; }
.intro-half-r { animation: intro-pull-r .45s cubic-bezier(.6,0,.9,.4) .05s both, intro-snap-r .2s ease-out .5s forwards; }
.intro-pulse { animation: intro-pulse .4s ease-out .5s forwards; }
/* The halves start apart, upright, and accelerate towards each other like magnets */
@keyframes intro-pull-l { 0% { opacity: 0; transform: translateX(-110px); } 20% { opacity: 1; } 100% { opacity: 1; transform: translateX(0); } }
@keyframes intro-pull-r { 0% { opacity: 0; transform: translateX(110px); } 20% { opacity: 1; } 100% { opacity: 1; transform: translateX(0); } }
/* A small bounce when they click together */
@keyframes intro-snap-l { 0% { transform: translateX(0); } 40% { transform: translateX(-5px); } 100% { transform: translateX(0); opacity: 1; } }
@keyframes intro-snap-r { 0% { transform: translateX(0); } 40% { transform: translateX(5px); } 100% { transform: translateX(0); opacity: 1; } }
@keyframes intro-thud { 0% { transform: scale(1); } 35% { transform: scale(1.06); } 100% { transform: scale(1); } }
@keyframes intro-pulse { 0% { opacity: .9; transform: scale(1); } 100% { opacity: 0; transform: scale(1.35); } }
@keyframes intro-out { to { opacity: 0; visibility: hidden; } }
@media (prefers-reduced-motion: reduce) { .intro { display: none; } }

/* Toasts */
.toasts { position: fixed; left: 0; right: 0; top: max(12px, env(safe-area-inset-top)); display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; z-index: 20; padding: 0 16px; }
.toast {
  max-width: 488px; width: 100%; background: #f4efe6; color: #1a1408; border-radius: 14px; padding: 14px 16px;
  font-weight: 700; box-shadow: 0 8px 30px rgba(0,0,0,.4); animation: toast-in .2s ease-out;
}
.toast.is-lock { background: #ffd6d6; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

/* Dialog */
.dialog { position: fixed; inset: 0; background: rgba(8,6,12,.75); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 30; }
.dialog-box { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; width: 100%; max-width: 420px; }
.dialog-box p { margin: 0 0 16px; font-size: 18px; font-weight: 700; }
.dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
