/* ============================================================
   Imposter — mobile-first party word game
   Self-contained, no external fonts or CDNs (works offline).
   ============================================================ */

:root {
  /* Color tokens */
  --bg: #13111c;
  --bg-grad-1: #1c1830;
  --bg-grad-2: #13111c;
  --surface: #211d33;
  --surface-2: #2a2542;
  --border: #3a3358;
  --text: #f3f1fb;
  --text-dim: #a59fc4;
  --text-faint: #7d77a0;

  --accent: #ff7a59;
  --accent-2: #ff4f8b;
  --accent-grad: linear-gradient(135deg, #ff7a59 0%, #ff4f8b 100%);
  --imposter: #ff5470;
  --crew: #4ad6c0;

  /* Shape & spacing */
  --radius: 18px;
  --radius-lg: 26px;
  --radius-pill: 999px;
  --shadow: 0 18px 40px -12px rgba(0, 0, 0, 0.55);
  --shadow-accent: 0 14px 30px -10px rgba(255, 79, 139, 0.5);
  --space: 16px;
  --tap: 52px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--font);
  color: var(--text);
  background: radial-gradient(circle at 50% -10%, var(--bg-grad-1), var(--bg-grad-2) 70%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100%;
  position: relative;
}

/* ---------- Screen system ---------- */
.screen {
  display: none;
  flex-direction: column;
  min-height: 100dvh;
  padding: calc(env(safe-area-inset-top) + 20px) 20px
           calc(env(safe-area-inset-bottom) + 20px);
}
.screen.active {
  display: flex;
  animation: screen-in 0.32s ease;
}
@keyframes screen-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
.hidden { display: none !important; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.topbar h2 {
  flex: 1;
  text-align: center;
  font-size: 1.15rem;
  margin: 0;
  letter-spacing: 0.3px;
}
.topbar-spacer { width: var(--tap); height: 1px; }
.icon-btn {
  width: var(--tap);
  height: var(--tap);
  border: none;
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.icon-btn:active { transform: scale(0.94); }

/* ---------- Buttons ---------- */
.btn {
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  padding: 0 22px;
  min-height: var(--tap);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.2s ease, background 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.97); }
.btn-lg { min-height: 60px; font-size: 1.15rem; width: 100%; }
.btn-primary {
  background: var(--accent-grad);
  color: #fff;
  box-shadow: var(--shadow-accent);
}
.btn-secondary {
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.btn-ghost {
  background: transparent;
  color: var(--text-dim);
}
.btn-ghost:active { background: var(--surface); }

/* ---------- Screen action footer ---------- */
.screen-actions {
  margin-top: auto;
  padding-top: 18px;
}
.screen-actions.stack { display: grid; gap: 10px; }

/* ============================================================
   HOME
   ============================================================ */
.home-hero {
  margin-top: auto;
  text-align: center;
}
.logo {
  font-size: 4.5rem;
  line-height: 1;
  filter: drop-shadow(0 10px 20px rgba(255, 79, 139, 0.35));
}
.title {
  font-size: 3rem;
  margin: 12px 0 6px;
  letter-spacing: -1px;
  background: var(--accent-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.tagline {
  color: var(--text-dim);
  font-size: 1.1rem;
  margin: 0 auto;
  max-width: 18em;
  line-height: 1.5;
}
.home-actions {
  margin-top: 40px;
  display: grid;
  gap: 12px;
}
.footnote {
  margin: 18px 0 4px;
  text-align: center;
  color: var(--text-faint);
  font-size: 0.85rem;
}

/* ============================================================
   SETUP
   ============================================================ */
.setup-body { display: grid; gap: 18px; margin-top: 6px; }
.field {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.field-label {
  display: block;
  font-weight: 600;
  font-size: 1rem;
}
.field-help {
  display: block;
  color: var(--text-faint);
  font-size: 0.82rem;
  margin-top: 2px;
}

/* Stepper */
.field:has(.stepper) {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.stepper {
  display: flex;
  align-items: center;
  gap: 6px;
}
.stepper-btn {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}
.stepper-btn:active { transform: scale(0.92); }
.stepper-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.stepper-value {
  min-width: 44px;
  text-align: center;
  font-size: 1.4rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* Field header (label + quick actions) */
.field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.field-head-actions { display: flex; gap: 4px; }
.link-btn {
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
  background: transparent;
  border: none;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
}
.link-btn:active { background: var(--surface-2); }
.count-pill {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 2px 9px;
  vertical-align: middle;
  margin-left: 4px;
}
.count-pill.none { color: var(--accent-2); border-color: var(--accent-2); }

/* Player avatars (coloured by --i, 0-5) */
.player-avatar {
  --i: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 1rem;
  color: #fff;
  background: linear-gradient(135deg,
    hsl(calc(var(--i) * 50 + 12) 85% 62%),
    hsl(calc(var(--i) * 50 + 42) 80% 52%));
  box-shadow: 0 4px 10px -4px rgba(0, 0, 0, 0.5);
}

/* Player name list */
.player-list { display: grid; gap: 8px; margin-top: 12px; }
.player-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 6px 8px 6px 6px;
}
.player-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  padding: 10px 4px;
}
.player-input::placeholder { color: var(--text-faint); font-weight: 500; }
.player-input:focus { outline: none; }
.player-row:focus-within { border-color: var(--accent); }
.player-remove {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text-faint);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}
.player-remove:active { background: var(--surface); }
.player-remove:disabled { opacity: 0; pointer-events: none; }

.add-player {
  margin-top: 10px;
  width: 100%;
  min-height: 46px;
  border: 1px dashed var(--border);
  border-radius: 14px;
  background: transparent;
  color: var(--accent);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
}
.add-player:active { background: var(--surface-2); }
.add-player:disabled { opacity: 0.4; cursor: not-allowed; }
.add-player-plus { font-size: 1.15rem; }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chip {
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 9px 14px;
  min-height: 42px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.15s ease;
}
.chip[aria-checked="true"] {
  background: var(--accent-grad);
  color: #fff;
  border-color: transparent;
}
.chip:active { transform: scale(0.95); }

/* Toggle / switch */
.toggle-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.toggle-text { flex: 1; }
.switch {
  width: 58px;
  height: 34px;
  border-radius: var(--radius-pill);
  border: none;
  background: var(--surface-2);
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s ease;
}
.switch[aria-checked="true"] { background: var(--accent); }
.switch-thumb {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s ease;
}
.switch[aria-checked="true"] .switch-thumb { transform: translateX(24px); }

/* ============================================================
   REVEAL
   ============================================================ */
#screen-reveal { justify-content: center; }
.reveal-progress {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-bottom: 24px;
}
.reveal-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--border);
  transition: background 0.2s ease;
}
.reveal-dot.done { background: var(--accent); }
.reveal-dot.current {
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(255, 122, 89, 0.25);
}

.reveal-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 18px;
}
.reveal-pass {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.reveal-avatar {
  width: 72px;
  height: 72px;
  font-size: 1.9rem;
  margin-bottom: 4px;
}
.reveal-pass-hint {
  color: var(--text-dim);
  margin: 0;
  font-size: 1rem;
}
.reveal-player {
  font-size: 1.9rem;
  margin: 0;
}

/* Card */
.card {
  width: 100%;
  max-width: 360px;
  aspect-ratio: 3 / 4;
  max-height: 56dvh;
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
  padding: 24px;
  box-shadow: var(--shadow);
  animation: card-pop 0.3s ease;
}
@keyframes card-pop {
  from { opacity: 0; transform: scale(0.9); }
  to   { opacity: 1; transform: scale(1); }
}
.card-back {
  border: none;
  cursor: pointer;
  color: #fff;
  font-family: inherit;
  background:
    radial-gradient(circle at 30% 20%, rgba(255,255,255,0.12), transparent 60%),
    var(--accent-grad);
}
.card-back-icon { font-size: 3.2rem; }
.card-back-text { font-size: 1.5rem; font-weight: 700; }
.card-back-sub { font-size: 0.9rem; opacity: 0.85; max-width: 16em; }
.card-back:active { transform: scale(0.97); }

.card-front {
  background: var(--surface);
  border: 1px solid var(--border);
}
.card-front.is-imposter {
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 84, 112, 0.28), transparent 65%),
    var(--surface);
  border-color: var(--imposter);
}
.card-role {
  font-size: 1rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-weight: 600;
}
.card-front.is-imposter .card-role { color: var(--imposter); }
.card-word {
  font-size: 2.6rem;
  font-weight: 800;
  line-height: 1.1;
  word-break: break-word;
}
.card-meta { color: var(--text-faint); font-size: 0.95rem; }
#reveal-shown { width: 100%; }
#reveal-shown .btn { max-width: 360px; margin: 0 auto; }

/* ============================================================
   STANDBY + RESULT
   ============================================================ */
#screen-result { text-align: center; }
.result-stage { margin: auto 0; }

/* "First clue goes to" starter card */
.starter-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 122, 89, 0.18), transparent 70%),
    var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px 20px;
  margin-bottom: 22px;
  animation: card-pop 0.35s ease;
}
.starter-avatar {
  width: 72px;
  height: 72px;
  font-size: 1.9rem;
  margin-bottom: 6px;
}
.starter-kicker {
  color: var(--text-dim);
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-weight: 600;
}
.starter-name {
  font-size: 2.4rem;
  font-weight: 800;
  line-height: 1.1;
  word-break: break-word;
  background: var(--accent-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.starter-sub { color: var(--text-faint); font-size: 0.9rem; margin-top: 2px; }

.steps {
  margin: 0 auto;
  max-width: 22em;
  padding-left: 20px;
  display: grid;
  gap: 14px;
  color: var(--text-dim);
  line-height: 1.5;
  text-align: left;
}
.steps strong { color: var(--text); }

.result-label { color: var(--text-dim); font-size: 1.1rem; margin: 0; }
.result-imposters {
  font-size: 2.4rem;
  margin: 8px 0 28px;
  color: var(--imposter);
}
.result-word-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  display: grid;
  gap: 4px;
}
.result-word-label { color: var(--text-faint); font-size: 0.9rem; }
.result-word { font-size: 2rem; font-weight: 800; }
.result-word-meta { color: var(--text-faint); font-size: 0.9rem; }
#screen-result .screen-actions { margin-top: auto; }

/* ============================================================
   RULES
   ============================================================ */
.rules-body {
  overflow-y: auto;
  line-height: 1.55;
}
.rules-body h3 {
  margin: 22px 0 8px;
  font-size: 1.15rem;
  color: var(--accent);
}
.rules-body h3:first-child { margin-top: 6px; }
.rules-body p { margin: 0 0 8px; color: var(--text-dim); }
.rules-body ul {
  margin: 0;
  padding-left: 20px;
  color: var(--text-dim);
  display: grid;
  gap: 8px;
}
.rules-body strong { color: var(--text); }

/* ============================================================
   Accessibility
   ============================================================ */
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

/* Slightly larger type on roomy phones / tablets */
@media (min-height: 760px) {
  .title { font-size: 3.4rem; }
  .card-word { font-size: 2.9rem; }
}
