/* ─── Tokens ─────────────────────────────────────────────────────────── */
:root {
  --pl-purple: #37003c;
  --pl-purple-lite: #4d1552;
  --pl-pink: #ff2882;
  --pl-cyan: #04f5ff;
  --pl-green: #00ff85;
  --pl-bg: #f7f4fb;
  --pl-surface: #ffffff;
  --pl-ink: #1a1a1a;
  --pl-muted: #6b6577;
  --pl-line: #e8e3ef;
  --pl-danger: #d72660;
  --r1: #8b95ff;
  --r2: #55c8ff;
  --r3: #00ff85;
  --r4: #ffb400;
  --r5: #ff2882;
  --radius: 12px;
  --radius-lg: 20px;
  --tap: 56px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--pl-bg);
  color: var(--pl-ink);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
body { overscroll-behavior-y: contain; }

#app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

a { color: var(--pl-purple); }
.muted { color: var(--pl-muted); }
.small { font-size: 0.85rem; }
.error { color: var(--pl-danger); padding: 0.5rem 0; }

/* ─── Buttons ───────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.85rem 1.25rem;
  min-height: 48px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font: inherit;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  text-decoration: none;
  background: var(--pl-surface);
  color: var(--pl-ink);
  transition: transform 0.08s, opacity 0.15s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: var(--pl-purple);
  color: white;
  border-color: var(--pl-purple);
}
.btn-ghost {
  background: transparent;
  border-color: var(--pl-line);
}
.btn-sm { padding: 0.5rem 0.9rem; min-height: 36px; font-size: 0.9rem; }
.btn-big { font-size: 1.125rem; padding: 1rem 1.5rem; min-height: 56px; width: 100%; }
.btn-huge { font-size: 1.5rem; padding: 1.25rem 2rem; min-height: 72px; width: 100%; background: var(--pl-pink); color: white; border-color: var(--pl-pink); }

.icon-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid var(--pl-line);
  background: transparent;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--pl-ink);
}
.back-link {
  font-size: 1.5rem;
  text-decoration: none;
  color: var(--pl-ink);
  padding: 0.25rem 0.75rem;
}

/* ─── Layout primitives ─────────────────────────────────────────────── */
.page-head {
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--pl-line);
  background: var(--pl-surface);
}
.page-head h1 { margin: 0; text-align: center; font-size: 1.15rem; font-weight: 600; }

.full-screen { min-height: 100vh; min-height: 100dvh; padding: 2rem; }
.centred { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1rem; text-align: center; }

/* ─── Home ───────────────────────────────────────────────────────────── */
.home {
  padding: 2rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
  max-width: 560px;
  margin: 0 auto;
  width: 100%;
}
.home-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 1rem;
}
.home-head h1 {
  margin: 0;
  font-size: clamp(2rem, 8vw, 3rem);
  color: var(--pl-purple);
  letter-spacing: -0.02em;
}
.home-cta { padding: 1.5rem 0; display: flex; flex-direction: column; gap: 0.75rem; }
.recent h2 { font-size: 1rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--pl-muted); margin: 0 0 0.75rem; }
.recent.empty { text-align: center; padding: 2rem 0; }
.recent-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.recent-item {
  display: block;
  padding: 0.9rem 1rem;
  background: var(--pl-surface);
  border: 1px solid var(--pl-line);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--pl-ink);
}
.recent-name { font-weight: 600; }
.recent-meta { display: flex; justify-content: space-between; font-size: 0.85rem; margin-top: 0.25rem; }

/* ─── Setup ──────────────────────────────────────────────────────────── */
.setup { max-width: 560px; margin: 0 auto; width: 100%; padding-bottom: 2rem; }
.setup-form { padding: 1rem 1.25rem; display: flex; flex-direction: column; gap: 1.5rem; }
.field { border: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.field legend { font-weight: 600; font-size: 0.95rem; padding: 0; }
.players-list { display: flex; flex-direction: column; gap: 0.5rem; }
.player-row { display: flex; gap: 0.5rem; align-items: center; }
.player-name {
  flex: 1;
  padding: 0.85rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--pl-line);
  background: var(--pl-surface);
  font: inherit;
  font-size: 1rem;
}
.btn-remove {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid var(--pl-line);
  background: transparent;
  cursor: pointer;
  font-size: 1.25rem;
  color: var(--pl-muted);
}
.chip-row { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.chip {
  display: inline-flex;
  align-items: center;
  padding: 0.6rem 1rem;
  border-radius: 999px;
  border: 1px solid var(--pl-line);
  background: var(--pl-surface);
  cursor: pointer;
  font-weight: 500;
  user-select: none;
}
.chip.active {
  background: var(--pl-purple);
  color: white;
  border-color: var(--pl-purple);
}
.chip input { display: none; }
.toggle { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; }
.toggle input { width: 20px; height: 20px; }
input[type="text"], input[type="text"]#pub-note {
  padding: 0.85rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--pl-line);
  background: var(--pl-surface);
  font: inherit;
  font-size: 1rem;
  width: 100%;
}
.setup-submit { padding-top: 0.5rem; }

/* ─── Play ───────────────────────────────────────────────────────────── */
.play { max-width: 640px; margin: 0 auto; width: 100%; display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }
.play.loading { align-items: center; justify-content: center; padding: 2rem; gap: 1rem; }
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--pl-line);
  border-top-color: var(--pl-purple);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.play-head {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--pl-purple);
  color: white;
  position: sticky;
  top: 0;
  z-index: 5;
}
.play-title { font-weight: 600; font-size: 0.95rem; }
.play-head .muted { color: rgba(255,255,255,0.7); }
.play-head .btn { color: white; border-color: rgba(255,255,255,0.3); }
.timer {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 1.25rem;
  padding: 0.25rem 0.75rem;
  border-radius: 8px;
  background: rgba(255,255,255,0.12);
}
.timer-idle { opacity: 0.6; }

.kickoff { padding: 3rem 1.25rem; text-align: center; display: flex; flex-direction: column; gap: 1rem; align-items: center; }
.kickoff p { color: var(--pl-muted); margin: 0; }

.stats-row {
  display: flex;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--pl-surface);
  border-bottom: 1px solid var(--pl-line);
  font-size: 0.9rem;
}
.sync-indicator { color: var(--pl-muted); }

.input-bar {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: var(--pl-surface);
  border-bottom: 1px solid var(--pl-line);
  position: sticky;
  top: 60px;
  z-index: 4;
}
#answer-input {
  flex: 1;
  padding: 0.85rem 1rem;
  font-size: 1.125rem;
  border-radius: var(--radius);
  border: 1px solid var(--pl-line);
  background: var(--pl-bg);
}

.dym, .disambig {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  padding: 0.75rem 1rem;
  background: #fff8e1;
  border-bottom: 1px solid var(--pl-line);
  flex-wrap: wrap;
}

.toast {
  position: fixed;
  bottom: 5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--pl-purple);
  color: white;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius);
  font-weight: 500;
  z-index: 100;
  animation: toast-in 0.2s ease-out;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}
.toast.miss { background: var(--pl-danger); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } }

.found-list { flex: 1; overflow-y: auto; padding: 0.5rem 0 6rem; }
.found-items { list-style: none; margin: 0; padding: 0; }
.found-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--pl-line);
  gap: 0.5rem;
}
.found-item.blank { color: var(--pl-muted); font-family: 'SF Mono', Menlo, monospace; }
.found-item.found { background: var(--pl-surface); }
.found-item .f-name { font-weight: 500; }
.found-item .f-stat { font-weight: 400; color: var(--pl-muted); font-size: 0.85rem; margin-left: 0.3rem; }
.found-item .f-meta { font-size: 0.85rem; color: var(--pl-muted); }
.found-item.r1 .f-name::before,
.found-item.r2 .f-name::before,
.found-item.r3 .f-name::before,
.found-item.r4 .f-name::before,
.found-item.r5 .f-name::before {
  content: '';
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  margin-right: 0.5rem;
  vertical-align: middle;
}
.found-item.r1 .f-name::before { background: var(--r1); }
.found-item.r2 .f-name::before { background: var(--r2); }
.found-item.r3 .f-name::before { background: var(--r3); }
.found-item.r4 .f-name::before { background: var(--r4); }
.found-item.r5 .f-name::before { background: var(--r5); }

.play-foot {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: var(--pl-surface);
  border-top: 1px solid var(--pl-line);
  position: sticky;
  bottom: 0;
}
.play-foot .btn { flex: 1; }

/* ─── Player picker overlay ─────────────────────────────────────────── */
.picker {
  position: fixed;
  inset: 0;
  background: rgba(55, 0, 60, 0.85);
  display: flex;
  flex-direction: column;
  padding: 1rem;
  z-index: 50;
  backdrop-filter: blur(4px);
}
.picker-head {
  text-align: center;
  padding: 1rem;
  color: white;
}
.picker-item { font-size: 1.5rem; font-weight: 700; }
.picker-head .muted { color: rgba(255,255,255,0.7); }
.picker-players {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.75rem;
  align-content: center;
  padding: 1rem 0;
}
.picker-btn {
  min-height: 72px;
  padding: 1rem;
  border-radius: var(--radius-lg);
  border: 2px solid white;
  background: white;
  color: var(--pl-ink);
  font-size: 1.125rem;
  font-weight: 600;
  cursor: pointer;
}
.picker-btn:active { transform: scale(0.97); }
.picker-btn.picker-nobody { background: transparent; color: white; }
.picker-foot { padding: 1rem 0 env(safe-area-inset-bottom); display: flex; justify-content: center; }
.picker-foot .btn { min-width: 160px; }

/* ─── Overlays (scores / scoring guide) ─────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.overlay-sheet {
  background: var(--pl-bg);
  border-top-left-radius: var(--radius-lg);
  border-top-right-radius: var(--radius-lg);
  width: 100%;
  max-width: 640px;
  max-height: 92vh;
  overflow-y: auto;
  padding-bottom: env(safe-area-inset-bottom);
}
.sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--pl-line);
  position: sticky;
  top: 0;
  background: var(--pl-bg);
}
.sheet-head h2 { margin: 0; font-size: 1.15rem; }

/* Scores overlay */
.score-list { list-style: none; margin: 0; padding: 0; }
.score-row { display: grid; grid-template-columns: 40px 1fr auto; gap: 0.75rem; padding: 1rem 1.25rem; border-bottom: 1px solid var(--pl-line); align-items: center; }
.rank { font-size: 1.5rem; font-weight: 700; color: var(--pl-muted); text-align: center; }
.score-name { font-weight: 600; }
.score-total { font-weight: 700; font-size: 1.25rem; }
.score-top { display: flex; justify-content: space-between; align-items: baseline; }
.score-sub { font-size: 0.85rem; margin: 0.25rem 0; }
.rarity-bar { display: flex; gap: 0.25rem; margin-top: 0.25rem; }
.rb { font-size: 0.75rem; padding: 0.1rem 0.4rem; border-radius: 4px; background: var(--pl-line); color: var(--pl-muted); min-width: 22px; text-align: center; }
.rb.r1 { background: var(--r1); color: white; }
.rb.r2 { background: var(--r2); color: white; }
.rb.r3 { background: var(--r3); color: #003320; }
.rb.r4 { background: var(--r4); color: #3d2900; }
.rb.r5 { background: var(--r5); color: white; }
.score-adj { display: flex; flex-direction: column; gap: 0.25rem; }
.adj-btn {
  min-width: 44px; min-height: 32px;
  border: 1px solid var(--pl-line);
  background: var(--pl-surface);
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
}
.adj-log { padding: 1rem 1.25rem; border-top: 1px solid var(--pl-line); }
.adj-log h3 { margin: 0 0 0.5rem; font-size: 0.95rem; }
.adj-log ul { list-style: none; margin: 0; padding: 0; font-size: 0.9rem; }
.adj-log li { padding: 0.35rem 0; }

/* ─── Results ─────────────────────────────────────────────────────── */
.results { max-width: 640px; margin: 0 auto; width: 100%; padding-bottom: 4rem; }
.results.loading { padding: 2rem; display: flex; flex-direction: column; align-items: center; gap: 1rem; }
.results-head { padding: 1.25rem 1.25rem 0.5rem; }
.results-title { text-align: center; }
.invincibles-banner {
  background: var(--pl-pink);
  color: white;
  padding: 0.75rem;
  text-align: center;
  font-weight: 700;
  letter-spacing: 0.1em;
  margin: 1rem 1.25rem;
  border-radius: var(--radius);
}
.winner { text-align: center; padding: 1.5rem 1.25rem; }
.crown { font-size: 3rem; }
.winner-name { font-size: 2rem; font-weight: 700; color: var(--pl-purple); }
.winner-score { font-size: 1.25rem; color: var(--pl-muted); margin-top: 0.25rem; }

.results-board { list-style: none; margin: 0; padding: 0 1.25rem; }
.results-row { display: grid; grid-template-columns: 40px 1fr; gap: 0.75rem; padding: 1rem 0; border-bottom: 1px solid var(--pl-line); align-items: center; }
.r-body { display: flex; flex-direction: column; gap: 0.25rem; }
.r-top { display: flex; justify-content: space-between; align-items: baseline; }
.r-name { font-weight: 600; }
.r-total { font-weight: 700; font-size: 1.25rem; }
.r-sub { font-size: 0.85rem; }
.badge-bonus { display: inline-block; background: var(--pl-green); color: #003320; padding: 0.1rem 0.4rem; border-radius: 4px; font-size: 0.75rem; font-weight: 700; margin-left: 0.5rem; vertical-align: middle; }

.missed { padding: 1.5rem 1.25rem; }
.missed h3 { margin: 0 0 0.75rem; font-size: 1rem; }
.missed-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.5rem; }
.missed-list li { padding: 0.35rem 0.75rem; border-radius: 6px; background: var(--pl-line); font-size: 0.9rem; }
.missed-list li.r5 { background: var(--r5); color: white; }
.missed-list li.r4 { background: var(--r4); color: #3d2900; }
.missed-list li.r3 { background: var(--r3); color: #003320; }

.results-foot { display: flex; flex-direction: column; gap: 0.5rem; padding: 1.5rem 1.25rem; }

/* ─── Scoring guide ─────────────────────────────────────────────────── */
.scoring-guide { max-width: 640px; margin: 0 auto; width: 100%; }
.sg-content { padding: 1.25rem; }
.sg-content h1 { margin: 0 0 1rem; }
.sg-content h2 { margin: 0 0 0.5rem; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--pl-muted); font-weight: 600; }
.sg-section { padding: 1rem 0; border-bottom: 1px solid var(--pl-line); }
.sg-section:last-child { border-bottom: none; }
.sg-section p { margin: 0.5rem 0; line-height: 1.5; }
.sg-section ol, .sg-section ul { padding-left: 1.25rem; margin: 0.5rem 0; line-height: 1.6; }
.sg-section ol li, .sg-section ul li { margin: 0.25rem 0; }
.sg-table { width: 100%; border-collapse: collapse; margin: 0.5rem 0; }
.sg-table th, .sg-table td { padding: 0.5rem; border-bottom: 1px solid var(--pl-line); text-align: left; font-size: 0.9rem; }
.sg-table th { font-weight: 600; color: var(--pl-muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; }

.head-link { color: var(--pl-purple); text-decoration: none; font-size: 0.9rem; padding: 0.5rem 0.75rem; font-weight: 500; text-align: right; }
