/* Spyfall Web — style.css
   Dark "secret dossier" look. Single committed dark theme. Mobile-first, 375px baseline. */

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-2: #242838;
  --border: #343a4f;
  --text: #f4f5f9;
  --muted: #9aa0b5;
  --accent: #ffb703;
  --accent-2: #8ecae6;
  --danger: #ff4d6d;
  --success: #3ddc97;
  --warn: #fb8500;
  --radius: 14px;
  --tap: 44px;
  --font-display: 'Bebas Neue', Impact, 'Arial Narrow', sans-serif;
  --font-body: Inter, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { overflow-x: hidden; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh; /* iOS Safari: exclude the collapsible toolbar */
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.45;
  padding-top: env(safe-area-inset-top, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { margin: 0; }

.brand, .section h2, .screen-title, .countdown, .card-location, .banner-text,
.modal-title, .theme-name, .card-spy-title, .option-value, .hold-pad, .hidden-flash-text {
  font-family: var(--font-display);
  letter-spacing: 0.04em;
  font-weight: 400;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

button { font: inherit; color: inherit; }

/* ---------- Header ---------- */
.app-header {
  max-width: 640px;
  margin: 0 auto;
  padding: 14px 16px 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand {
  font-size: 34px;
  line-height: 1;
  color: var(--accent);
  letter-spacing: 0.12em;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 4px 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  max-width: 60%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chip[hidden] { display: none; }

/* ---------- Layout ---------- */
#app {
  max-width: 640px;
  margin: 0 auto;
  padding: 8px 16px 24px;
  width: 100%;
}
.section { margin: 22px 0; }
.section h2 {
  font-size: 24px;
  color: var(--text);
  margin-bottom: 10px;
}
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.section-head h2 { margin-bottom: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.stack { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.center { text-align: center; }
.screen-title { font-size: 34px; line-height: 1.05; margin-bottom: 6px; }
.subtitle { color: var(--muted); margin: 0 0 16px; }
.instruction { font-size: 17px; margin: 6px 0 16px; }
.instruction strong { color: var(--accent); }
.empty {
  padding: 18px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}
p { margin: 0 0 10px; overflow-wrap: anywhere; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 10px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
  font-size: 16px;
  line-height: 1.2;
  cursor: pointer;
  text-align: center;
  overflow-wrap: anywhere;
  width: 100%;
  transition: transform 80ms ease, filter 120ms ease;
  -webkit-user-select: none;
  user-select: none;
}
.btn:active:not(:disabled) { transform: scale(0.98); filter: brightness(1.08); }
.btn:disabled, .btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #0f1117; border-color: var(--accent); }
.btn-secondary { background: var(--accent-2); color: #0f1117; border-color: var(--accent-2); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-danger { background: var(--danger); color: #0f1117; border-color: var(--danger); }
.btn-lg { min-height: 56px; font-size: 18px; }
.btn-auto { width: auto; }
.link {
  background: none;
  border: 0;
  padding: 8px 4px;
  min-height: var(--tap);
  color: var(--accent-2);
  text-decoration: underline;
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
}
.link:disabled { opacity: 0.5; cursor: not-allowed; }
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--tap);
  min-height: var(--tap);
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--danger);
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  flex: 0 0 auto;
}
.icon-btn:hover { background: var(--surface-2); }

/* ---------- Theme picker ---------- */
.theme-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
}
@media (min-width: 600px) {
  .theme-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.theme-card {
  position: relative;
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  column-gap: 12px;
  row-gap: 4px;
  align-items: start;
  padding: 14px 14px 12px;
  min-height: 96px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
  -webkit-user-select: none;
  user-select: none;
}
.theme-card:hover { background: var(--surface-2); }
.theme-card.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.theme-emoji {
  grid-row: 1 / span 3;
  font-size: 40px;
  line-height: 1;
  width: 56px;
  text-align: center;
  padding-top: 2px;
}
.theme-name { font-size: 26px; line-height: 1; padding-right: 30px; overflow-wrap: anywhere; }
.theme-tagline { color: var(--muted); font-size: 14px; line-height: 1.35; overflow-wrap: anywhere; }
.theme-meta {
  grid-column: 2;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 10px;
  margin-top: 6px;
  font-size: 13px;
  color: var(--muted);
}
.theme-check {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent);
  color: #0f1117;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
}
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  color: #0f1117;
  letter-spacing: 0.02em;
}
.badge-family { background: var(--success); }
.badge-pg13 { background: var(--warn); }
.badge-adult { background: var(--danger); }
.theme-card .link { min-height: var(--tap); padding: 4px 6px; margin-left: auto; font-size: 14px; }

/* ---------- Players ---------- */
.player-list {
  list-style: none;
  margin: 0 0 10px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.player-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 4px 4px 4px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.player-row .player-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 600;
}
.player-row .player-num { color: var(--muted); font-size: 13px; width: 20px; flex: 0 0 auto; }
.add-row {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}
.add-row input {
  flex: 1 1 auto;
  min-width: 0;
  min-height: var(--tap);
  padding: 8px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 16px;
}
.add-row input::placeholder { color: var(--muted); }
.add-row .btn { width: auto; flex: 0 0 auto; padding-inline: 20px; }
.add-row input.shake { animation: shake 320ms ease; border-color: var(--danger); }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}
.error { color: var(--danger); font-size: 14px; margin: 8px 0 0; }
.error[hidden] { display: none; }
.count { margin-top: 8px; font-size: 14px; }

/* ---------- Options ---------- */
.option-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 56px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 8px;
}
.option-row.option-col { flex-direction: column; align-items: stretch; gap: 8px; }
.option-label { font-weight: 600; }
.option-label .small { display: block; font-weight: 400; color: var(--muted); }
.option-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.option-value { font-size: 24px; color: var(--accent); }

.segmented {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface-2);
  flex: 0 0 auto;
}
.segmented button {
  min-width: 56px;
  min-height: var(--tap);
  border: 0;
  background: transparent;
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
  padding: 0 14px;
}
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button.active { background: var(--accent); color: #0f1117; }
.segmented button:disabled { opacity: 0.5; cursor: not-allowed; }

input[type="range"] {
  width: 100%;
  min-height: var(--tap);
  accent-color: var(--accent);
  margin: 0;
  cursor: pointer;
}
.range-ticks { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }

.toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  min-height: var(--tap);
  cursor: pointer;
}
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle .track {
  width: 56px;
  height: 32px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  position: relative;
  transition: background 150ms ease;
}
.toggle .track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 150ms ease, background 150ms ease;
}
.toggle input:checked + .track { background: var(--accent); border-color: var(--accent); }
.toggle input:checked + .track::after { transform: translateX(24px); background: #0f1117; }
.toggle input:focus-visible + .track { outline: 3px solid var(--accent); outline-offset: 2px; }

.start-block { margin-top: 26px; }
.hint { color: var(--muted); font-size: 14px; text-align: center; margin: 10px 0 0; }

/* ---------- Name grid (pass / accuse / spy pick) ---------- */
.name-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
@media (min-width: 600px) {
  .name-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
.name-btn {
  min-height: 64px;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  font-size: 17px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  overflow-wrap: anywhere;
  text-align: center;
  min-width: 0;
}
.name-btn:hover { background: var(--surface-2); }
.name-btn.viewed { opacity: 0.6; border-color: var(--success); }
.name-btn .check { color: var(--success); font-size: 14px; font-weight: 700; }
.name-btn .name-text { min-width: 0; max-width: 100%; }

/* ---------- Round ---------- */
.timer-block {
  text-align: center;
  padding: 18px 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.countdown {
  font-size: 64px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
@media (min-width: 600px) { .countdown { font-size: 88px; } }
.countdown.warn { color: var(--danger); animation: pulse 1s ease-in-out infinite; }
.countdown.paused { color: var(--muted); }
.countdown.timeup { color: var(--danger); animation: none; } /* 00:00 sits still while people argue */
@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.06); opacity: 0.75; }
}
.interrogation { text-align: center; }
.interrogation .instruction { margin-bottom: 6px; }
.interrogation .link { min-height: var(--tap); margin-top: 4px; }
.prompt { font-size: 20px; margin: 10px 0 4px; overflow-wrap: anywhere; }
.timer-state { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 6px; }
.timer-block .btn { width: auto; margin-top: 12px; padding-inline: 28px; }
.timeup-banner {
  background: var(--danger);
  color: #0f1117;
  font-weight: 700;
  padding: 12px 14px;
  border-radius: 12px;
  margin-bottom: 12px;
  text-align: center;
}

.checklist {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 6px;
}
@media (min-width: 600px) { .checklist { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: var(--tap);
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  overflow-wrap: anywhere;
  font-size: 15px;
  min-width: 0;
}
.check-row .box {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  border-radius: 6px;
  border: 2px solid var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
}
.check-row .label { min-width: 0; }
.check-row.eliminated { opacity: 0.45; }
.check-row.eliminated .label { text-decoration: line-through; }
.check-row.eliminated .box { background: var(--muted); color: #0f1117; border-color: var(--muted); }

/* ---------- Reveal ---------- */
.banner {
  padding: 22px 16px;
  border-radius: var(--radius);
  text-align: center;
  color: #0f1117;
  margin-bottom: 14px;
}
.banner-spies { background: var(--danger); }
.banner-nonspies { background: var(--success); }
.banner-none { background: var(--muted); }
.banner-text { font-size: 48px; line-height: 1; }
.reason { text-align: center; font-size: 17px; margin-bottom: 18px; }
.location-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  background: var(--surface);
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  margin-bottom: 18px;
  min-width: 0;
}
.location-card .emoji { font-size: 40px; line-height: 1; flex: 0 0 auto; }
.location-card .label { color: var(--muted); font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase; }
.location-card .card-location { font-size: 34px; line-height: 1; overflow-wrap: anywhere; min-width: 0; }
.location-card .text { min-width: 0; }
.reveal-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.reveal-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  min-height: var(--tap);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.reveal-row.spy { border-color: var(--danger); background: rgba(255, 77, 109, 0.08); }
.reveal-row .who { font-weight: 700; min-width: 0; overflow-wrap: anywhere; flex: 0 1 40%; }
.reveal-row .what { color: var(--muted); min-width: 0; overflow-wrap: anywhere; flex: 1 1 auto; font-size: 14px; }
.reveal-row.spy .what { color: var(--danger); font-weight: 700; }

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(5, 6, 10, 0.72); }
.modal-box {
  position: relative;
  width: 100%;
  max-width: 440px;
  max-height: calc(100vh - 32px);
  max-height: calc(100svh - 32px); /* iOS Safari: keep Close above the toolbar */
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 18px 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.modal-title { font-size: 30px; line-height: 1.05; margin-bottom: 8px; overflow-wrap: anywhere; }
.modal-body { color: var(--text); overflow-y: auto; min-height: 0; margin-bottom: 14px; overflow-wrap: anywhere; }
.modal-body p { margin: 0 0 8px; }
.modal-body .muted { font-size: 14px; }
.modal-buttons { display: flex; flex-direction: column; gap: 8px; }
.peek-list {
  list-style: none;
  margin: 0;
  padding: 0;
  columns: 2;
  column-gap: 14px;
  font-size: 14px;
}
.peek-list li { padding: 5px 0; border-bottom: 1px solid var(--border); break-inside: avoid; overflow-wrap: anywhere; }

/* ---------- Card overlay ---------- */
.card-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 16px calc(env(safe-area-inset-bottom, 0px) + 14px);
  max-width: 100%;
  overflow: hidden;
}
.card-overlay[hidden] { display: none; }
.card-owner { text-align: center; font-size: 30px; margin-bottom: 8px; overflow-wrap: anywhere; font-family: var(--font-display); letter-spacing: 0.04em; font-weight: 400; }
.card-stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  position: relative;
}
.card-stage.revealed { border-style: solid; border-color: var(--accent); }
.card-placeholder {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--muted);
  text-align: center;
  padding: 20px;
}
.card-placeholder .lock { font-size: 40px; }
.card-placeholder[hidden] { display: none; }
.card-content {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 16px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.card-content:empty { display: none; }
.card-emoji { font-size: 56px; line-height: 1; margin-bottom: 8px; }
.card-label {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin-top: 14px;
}
.card-location { font-size: 44px; line-height: 1.02; color: var(--accent); overflow-wrap: anywhere; max-width: 100%; }
.card-role { font-size: 20px; font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; max-width: 100%; }
.card-spy-title { font-size: 52px; line-height: 1; color: var(--danger); }
.card-spy-sub { color: var(--muted); margin: 6px 0 10px; }
.spy-list {
  list-style: none;
  margin: 0;
  padding: 0;
  width: 100%;
  text-align: left;
  columns: 2;
  column-gap: 12px;
  font-size: 13px;
}
.spy-list li { padding: 4px 0; border-bottom: 1px solid var(--border); break-inside: avoid; overflow-wrap: anywhere; }
.card-controls { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.hold-pad {
  min-height: 84px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  border: 2px solid var(--accent);
  background: rgba(255, 183, 3, 0.12);
  color: var(--accent);
  font-size: 26px;
  letter-spacing: 0.08em;
  cursor: pointer;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  text-align: center;
  padding: 8px 12px;
}
.hold-pad.active { background: var(--accent); color: #0f1117; }
.tap-bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.tap-bar[hidden] { display: none; }
.tap-bar-fill { height: 100%; width: 100%; background: var(--accent-2); }

/* ---------- Hidden curtain ---------- */
.hidden-flash {
  position: fixed;
  inset: 0;
  z-index: 110;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
  padding: 24px;
  cursor: pointer;
}
.hidden-flash[hidden] { display: none; }
.hidden-flash-text { font-size: 36px; letter-spacing: 0.06em; }
.hidden-flash-sub { font-size: 14px; color: var(--muted); }

/* ---------- Time-up flash ---------- */
.flash {
  position: fixed;
  inset: 0;
  z-index: 40;
  pointer-events: none;
  background: var(--danger);
  opacity: 0;
}
.flash.flashing { animation: flash3 1.5s linear; }
@keyframes flash3 {
  0%, 33.3%, 66.6%, 100% { opacity: 0; }
  16.6%, 50%, 83.3% { opacity: 0.85; }
}

.noscript { padding: 24px; text-align: center; color: var(--danger); }

/* ---------- Motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .countdown.warn { animation: none; }
  .flash.flashing { animation: none; }
  .add-row input.shake { animation: none; }
  .btn { transition: none; }
}
