/* ============================================================
   7 Wonders Scorer — Design System
   Style: Classical board-game table (felt green + gold on dark)
   Fonts: Fredoka (display) / Nunito (body)
   ============================================================ */

:root {
  /* Core palette */
  --bg: #0b1220;
  --bg-2: #0f172a;
  --surface: rgba(255, 255, 255, 0.045);
  --surface-2: rgba(255, 255, 255, 0.07);
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.18);

  --felt: #15803d;
  --felt-deep: #14532d;
  --gold: #d97706;
  --gold-bright: #f5b942;
  --gold-soft: #fcd9a0;

  --fg: #f8fafc;
  --muted: #94a3b8;
  --muted-2: #cbd5e1;

  --danger: #ef4444;
  --ring: rgba(245, 185, 66, 0.55);

  /* Category colors (match the real card colors) */
  --c-military: #ef4444;
  --c-treasury: #f5b942;
  --c-wonders: #c2884e;
  --c-civilian: #3b82f6;
  --c-commercial: #eab308;
  --c-science: #22c55e;
  --c-guild: #a855f7;

  /* Spacing scale (4/8) */
  --r-sm: 10px;
  --r-md: 16px;
  --r-lg: 22px;
  --r-xl: 30px;

  --shadow-soft: 0 10px 30px -12px rgba(0, 0, 0, 0.6);
  --shadow-card: 0 18px 48px -20px rgba(0, 0, 0, 0.75);
  --gold-glow: 0 0 0 1px rgba(245, 185, 66, 0.35), 0 8px 40px -8px rgba(245, 185, 66, 0.4);

  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--fg);
  font-family: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: clip;
  overscroll-behavior: none;
  padding-top: env(safe-area-inset-top);
  -webkit-tap-highlight-color: transparent;
}

/* ---- Touch ergonomics (mobile / tablet) ---- */
button, .tab, .count-pill, a, input, label, select { touch-action: manipulation; }
button, .tab, .count-pill, .cat-title, .cat-hint, .section-label, .eyebrow,
.tab-name, .brand, .site-footer, .bd-legend, .results-head, .winner-card,
.medal, .rank-name { -webkit-user-select: none; user-select: none; }

/* ---- Decorative background (felt table) ---- */
.bg-decor {
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(1100px 620px at 50% -8%, rgba(21, 128, 61, 0.34), transparent 60%),
    radial-gradient(900px 600px at 88% 12%, rgba(245, 185, 66, 0.10), transparent 55%),
    radial-gradient(800px 700px at 6% 92%, rgba(21, 128, 61, 0.16), transparent 55%),
    linear-gradient(180deg, #0b1220 0%, #0a1018 100%);
}
.bg-decor::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1.4px);
  background-size: 22px 22px;
  mask-image: radial-gradient(120% 90% at 50% 30%, #000 35%, transparent 78%);
  opacity: 0.6;
}

#confetti {
  position: fixed;
  inset: 0;
  z-index: 60;
  pointer-events: none;
}

/* ---- Layout shell ---- */
#app {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: clamp(20px, 4vw, 44px) clamp(16px, 4vw, 32px) 40px;
  padding-left: max(clamp(16px, 4vw, 32px), env(safe-area-inset-left));
  padding-right: max(clamp(16px, 4vw, 32px), env(safe-area-inset-right));
}

.view { animation: viewIn 0.5s var(--ease-out) both; }

.site-footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
  padding: 8px 16px max(28px, calc(env(safe-area-inset-bottom) + 14px));
}
.site-footer strong { color: var(--gold-soft); font-weight: 700; }

/* ============================================================
   Typography helpers
   ============================================================ */
.display {
  font-family: "Fredoka", sans-serif;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.05;
}
.eyebrow {
  font-family: "Fredoka", sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.28em;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--gold-bright);
}

/* ============================================================
   Brand header
   ============================================================ */
.brand {
  text-align: center;
  margin-bottom: clamp(22px, 4vw, 38px);
}
.brand .num {
  display: inline-grid;
  place-items: center;
  width: 74px;
  height: 74px;
  margin-bottom: 14px;
  border-radius: 20px;
  font-family: "Fredoka", sans-serif;
  font-weight: 700;
  font-size: 2.6rem;
  color: #1b1206;
  background: linear-gradient(145deg, var(--gold-bright), var(--gold));
  box-shadow: var(--gold-glow), inset 0 2px 0 rgba(255, 255, 255, 0.4);
  animation: floaty 6s ease-in-out infinite;
}
.brand h1 {
  font-family: "Fredoka", sans-serif;
  font-weight: 700;
  font-size: clamp(2.1rem, 7vw, 3.4rem);
  margin: 0;
  background: linear-gradient(180deg, #fff 10%, var(--gold-soft) 130%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 38px rgba(245, 185, 66, 0.18);
}
.brand p {
  margin: 6px 0 0;
  color: var(--muted-2);
  font-weight: 600;
}
.brand .badge {
  display: inline-block;
  margin-top: 12px;
  padding: 4px 14px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--gold-soft);
  background: rgba(245, 185, 66, 0.10);
  border: 1px solid rgba(245, 185, 66, 0.3);
}

/* ============================================================
   Card / panel base
   ============================================================ */
.card {
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(6px);
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  appearance: none;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--fg);
  font-family: "Fredoka", sans-serif;
  font-weight: 600;
  font-size: 1.02rem;
  padding: 14px 24px;
  min-height: 52px;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: transform 0.18s var(--ease-spring), background 0.2s, box-shadow 0.2s, border-color 0.2s;
}
.btn:hover { background: rgba(255, 255, 255, 0.12); transform: translateY(-2px); }
.btn:active { transform: translateY(0) scale(0.97); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--ring); }

.btn-primary {
  border: none;
  color: #1b1206;
  background: linear-gradient(145deg, var(--gold-bright), var(--gold));
  box-shadow: var(--gold-glow);
}
.btn-primary:hover { box-shadow: 0 0 0 1px rgba(245, 185, 66, 0.5), 0 14px 48px -8px rgba(245, 185, 66, 0.6); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; filter: grayscale(0.4); transform: none; box-shadow: none; }

.btn-ghost { background: transparent; }
.btn-lg { font-size: 1.15rem; padding: 16px 34px; min-height: 60px; }
.btn-block { width: 100%; }
.btn svg { width: 20px; height: 20px; }

/* ============================================================
   SETUP view
   ============================================================ */
.setup-card {
  padding: clamp(22px, 4vw, 38px);
  max-width: 640px;
  margin: 0 auto;
}
.section-label {
  display: block;
  font-family: "Fredoka", sans-serif;
  font-weight: 600;
  font-size: 1.12rem;
  margin-bottom: 14px;
}
.section-label .hint { display: block; font-family: "Nunito"; font-weight: 600; font-size: 0.85rem; color: var(--muted); margin-top: 2px; }

.count-pills {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
  margin-bottom: 30px;
}
.count-pill {
  appearance: none;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted-2);
  font-family: "Fredoka", sans-serif;
  font-weight: 600;
  font-size: 1.4rem;
  height: 64px;
  border-radius: var(--r-md);
  transition: transform 0.18s var(--ease-spring), background 0.2s, color 0.2s, box-shadow 0.2s, border-color 0.2s;
}
.count-pill:hover { transform: translateY(-2px); border-color: var(--border-strong); }
.count-pill:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--ring); }
.count-pill.active {
  color: #1b1206;
  background: linear-gradient(145deg, var(--gold-bright), var(--gold));
  border-color: transparent;
  box-shadow: var(--gold-glow);
  transform: translateY(-2px);
}

.name-list { display: grid; gap: 12px; margin-bottom: 28px; }
.name-field {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 6px 10px 6px 6px;
  transition: border-color 0.2s, box-shadow 0.2s;
  animation: popIn 0.45s var(--ease-spring) both;
}
.name-field:focus-within { border-color: rgba(245, 185, 66, 0.5); box-shadow: 0 0 0 3px rgba(245, 185, 66, 0.16); }
.name-field .seat {
  flex: none;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  font-family: "Fredoka", sans-serif;
  font-weight: 700;
  color: #0b1220;
}
.name-field input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  color: var(--fg);
  font-family: "Nunito", sans-serif;
  font-weight: 700;
  font-size: 1.06rem;
  padding: 10px 6px;
}
.name-field input::placeholder { color: var(--muted); font-weight: 600; }
.name-field input:focus { outline: none; }

/* ============================================================
   SCORING view
   ============================================================ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.topbar h2 { font-family: "Fredoka"; font-weight: 600; font-size: 1.5rem; margin: 0; }
.topbar .sub { color: var(--muted); font-size: 0.85rem; font-weight: 600; }

/* Player tabs */
.tabs {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 10px 2px 12px;
  margin-bottom: 8px;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
  /* Stay visible while scrolling the score cards on mobile/tablet */
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 30;
  margin-inline: calc(-1 * max(clamp(16px, 4vw, 32px), env(safe-area-inset-left)));
  padding-inline: max(clamp(16px, 4vw, 32px), env(safe-area-inset-left));
  background: rgba(11, 18, 32, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.tab {
  flex: 0 0 auto;
  cursor: pointer;
  color: var(--fg);
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--r-md);
  padding: 10px 16px;
  min-width: 124px;
  text-align: left;
  transition: transform 0.18s var(--ease-spring), border-color 0.2s, background 0.2s, box-shadow 0.2s;
}
.tab:hover { transform: translateY(-2px); border-color: var(--border-strong); }
.tab:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--ring); }
.tab.active { border-color: rgba(245, 185, 66, 0.6); background: rgba(245, 185, 66, 0.10); box-shadow: var(--shadow-soft); }
.tab .tab-name {
  display: flex; align-items: center; gap: 6px;
  font-family: "Fredoka"; font-weight: 600; font-size: 0.98rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px;
}
.tab .tab-total { font-size: 1.7rem; font-family: "Fredoka"; font-weight: 700; color: var(--gold-bright); font-variant-numeric: tabular-nums; }
.tab .crown { color: var(--gold-bright); flex: none; display: none; }
.tab.leader .crown { display: inline-flex; }

/* Category grid */
.panel { animation: panelIn 0.4s var(--ease-out) both; }
.cat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
.cat-card {
  --c: var(--gold);
  position: relative;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border);
  border-left: 4px solid var(--c);
  border-radius: var(--r-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.cat-card:focus-within { box-shadow: 0 0 0 2px color-mix(in srgb, var(--c) 45%, transparent); }
.cat-head { display: flex; align-items: center; gap: 12px; }
.cat-icon {
  flex: none;
  width: 42px; height: 42px;
  display: grid; place-items: center;
  border-radius: 12px;
  color: var(--c);
  background: color-mix(in srgb, var(--c) 18%, transparent);
  border: 1px solid color-mix(in srgb, var(--c) 35%, transparent);
}
.cat-icon svg { width: 22px; height: 22px; }
.cat-title { flex: 1; min-width: 0; font-family: "Fredoka"; font-weight: 600; font-size: 1.05rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-info {
  flex: none;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border: none; background: transparent;
  color: var(--muted);
  cursor: pointer; border-radius: 50%;
  transition: color 0.18s, background 0.18s, transform 0.12s var(--ease-spring);
}
.cat-info svg { width: 19px; height: 19px; }
.cat-info:hover { color: var(--c); background: rgba(255, 255, 255, 0.08); }
.cat-info:active { transform: scale(0.88); }
.cat-info:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }
.cat-hint { color: var(--muted); font-size: 0.78rem; font-weight: 600; line-height: 1.3; }
.cat-points {
  margin-left: auto;
  flex: none;
  font-family: "Fredoka"; font-weight: 700;
  font-size: 1.35rem;
  color: var(--c);
  font-variant-numeric: tabular-nums;
  min-width: 44px; text-align: right;
}
.cat-points .unit { font-size: 0.7rem; color: var(--muted); margin-left: 2px; }
.pulse { animation: pulse 0.4s var(--ease-spring); }

/* Stepper */
.stepper {
  display: flex;
  align-items: stretch;
  gap: 8px;
}
.stepper button {
  appearance: none;
  cursor: pointer;
  width: 48px; height: 48px;
  flex: none;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--fg);
  font-size: 1.5rem;
  line-height: 1;
  display: grid; place-items: center;
  transition: transform 0.12s var(--ease-spring), background 0.18s, border-color 0.18s;
}
.stepper button:hover { background: rgba(255, 255, 255, 0.14); border-color: var(--border-strong); }
.stepper button:active { transform: scale(0.88); }
.stepper button:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--ring); }
.stepper input {
  flex: 1;
  min-width: 0;
  text-align: center;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.22);
  color: var(--fg);
  font-family: "Fredoka", sans-serif;
  font-weight: 600;
  font-size: 1.3rem;
  border-radius: 12px;
  height: 48px;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}
.stepper input::-webkit-outer-spin-button,
.stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.stepper input:focus { outline: none; border-color: rgba(245, 185, 66, 0.5); box-shadow: 0 0 0 3px rgba(245, 185, 66, 0.16); }

/* Science triple */
.sci-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.sci-sym { text-align: center; }
.sci-sym .sci-label { display: flex; align-items: center; justify-content: center; gap: 5px; color: var(--c-science); font-size: 0.72rem; font-weight: 700; margin-bottom: 6px; }
.sci-sym .sci-label svg { width: 15px; height: 15px; }
.sci-mini { display: flex; flex-direction: column; gap: 6px; align-items: center; }
.sci-mini input {
  width: 100%;
  text-align: center;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.22);
  color: var(--fg);
  font-family: "Fredoka"; font-weight: 600; font-size: 1.15rem;
  border-radius: 10px; height: 44px;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}
.sci-mini input::-webkit-outer-spin-button,
.sci-mini input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.sci-mini input:focus { outline: none; border-color: rgba(34, 197, 94, 0.55); box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.18); }
.sci-btns { display: flex; gap: 6px; width: 100%; }
.sci-btns button {
  flex: 1; height: 44px; cursor: pointer;
  border-radius: 9px; border: 1px solid var(--border-strong);
  background: var(--surface-2); color: var(--fg); font-size: 1.1rem; line-height: 1;
  transition: transform 0.12s var(--ease-spring), background 0.18s;
}
.sci-btns button:active { transform: scale(0.85); }
.sci-btns button:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }
.sci-formula {
  text-align: center; color: var(--muted-2);
  font-size: 0.8rem; font-weight: 700;
  background: rgba(34, 197, 94, 0.08);
  border: 1px solid rgba(34, 197, 94, 0.22);
  border-radius: 10px; padding: 7px 10px;
  font-variant-numeric: tabular-nums;
}
.sci-formula b { color: var(--c-science); }

/* Coins helper */
.coin-help { text-align: center; color: var(--muted); font-size: 0.78rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.coin-help b { color: var(--c-treasury); }

.scoring-actions { margin-top: 22px; display: flex; gap: 12px; flex-wrap: wrap; }
.scoring-actions .btn { flex: 1; min-width: 160px; }

/* ============================================================
   RESULTS view
   ============================================================ */
.results-head { text-align: center; margin-bottom: 26px; }
.results-head .eyebrow { animation: fadeInUp 0.5s var(--ease-out) both; }
.results-head h2 {
  font-family: "Fredoka"; font-weight: 700;
  font-size: clamp(2rem, 7vw, 3rem);
  margin: 6px 0 0;
  background: linear-gradient(180deg, #fff, var(--gold-soft));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

.winner-card {
  position: relative;
  text-align: center;
  padding: 32px 24px 28px;
  border-radius: var(--r-xl);
  background:
    radial-gradient(120% 130% at 50% -10%, rgba(245, 185, 66, 0.22), transparent 60%),
    linear-gradient(180deg, rgba(245, 185, 66, 0.10), rgba(255, 255, 255, 0.03));
  border: 1px solid rgba(245, 185, 66, 0.45);
  box-shadow: var(--gold-glow), var(--shadow-card);
  overflow: hidden;
  animation: winnerPop 0.7s var(--ease-spring) both;
}
.winner-card::before {
  content: "";
  position: absolute; inset: -40%;
  background: conic-gradient(from 0deg, transparent 0 78%, rgba(245, 185, 66, 0.28) 86%, transparent 92%);
  animation: spin 9s linear infinite;
  z-index: 0;
}
.winner-card > * { position: relative; z-index: 1; }
.winner-crown {
  width: 64px; height: 64px;
  margin: 0 auto 8px;
  color: var(--gold-bright);
  filter: drop-shadow(0 6px 18px rgba(245, 185, 66, 0.5));
  animation: floaty 4s ease-in-out infinite;
}
.winner-card .label { font-family: "Fredoka"; font-weight: 600; letter-spacing: 0.2em; text-transform: uppercase; color: var(--gold-soft); font-size: 0.82rem; }
.winner-card .wname { font-family: "Fredoka"; font-weight: 700; font-size: clamp(1.8rem, 6vw, 2.6rem); margin: 4px 0; }
.winner-card .wscore { font-family: "Fredoka"; font-weight: 700; font-size: clamp(3rem, 13vw, 5rem); line-height: 1; color: var(--gold-bright); font-variant-numeric: tabular-nums; text-shadow: 0 0 30px rgba(245, 185, 66, 0.4); }
.winner-card .wscore .pts { font-size: 1.1rem; color: var(--muted-2); margin-left: 6px; }
.winner-card .tiebreak { margin-top: 8px; font-size: 0.82rem; color: var(--gold-soft); font-weight: 700; }

.rank-list { display: grid; gap: 12px; margin-top: 18px; }
.rank-row {
  display: grid;
  grid-template-columns: 46px 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border-radius: var(--r-md);
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border);
  animation: fadeInUp 0.5s var(--ease-out) both;
}
.rank-row .medal {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 50%;
  font-family: "Fredoka"; font-weight: 700; font-size: 1.1rem;
  background: var(--surface-2); color: var(--muted-2);
  border: 1px solid var(--border-strong);
}
.rank-row.gold .medal { background: linear-gradient(145deg, #fde68a, #d97706); color: #1b1206; border: none; }
.rank-row.silver .medal { background: linear-gradient(145deg, #f1f5f9, #94a3b8); color: #0b1220; border: none; }
.rank-row.bronze .medal { background: linear-gradient(145deg, #f0b27a, #a85b2e); color: #1b1206; border: none; }
.rank-main { min-width: 0; }
.rank-name { font-family: "Fredoka"; font-weight: 600; font-size: 1.15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-score { font-family: "Fredoka"; font-weight: 700; font-size: 1.7rem; color: var(--gold-bright); font-variant-numeric: tabular-nums; }
.rank-score .pts { font-size: 0.7rem; color: var(--muted); margin-left: 3px; }

/* breakdown bar */
.breakdown {
  display: flex;
  height: 9px;
  width: 100%;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 8px;
  background: rgba(0, 0, 0, 0.3);
}
.breakdown span {
  height: 100%;
  width: 0;
  transition: width 0.9s var(--ease-out);
  transition-delay: 0.25s;
}
.bd-legend { display: flex; flex-wrap: wrap; gap: 10px 14px; justify-content: center; margin: 22px 0 6px; }
.bd-legend .item { display: inline-flex; align-items: center; gap: 6px; font-size: 0.76rem; font-weight: 700; color: var(--muted-2); }
.bd-legend .dot { width: 11px; height: 11px; border-radius: 3px; }

.results-actions { margin-top: 28px; display: flex; gap: 12px; flex-wrap: wrap; }
.results-actions .btn { flex: 1; min-width: 180px; }

/* ============================================================
   Info modal
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  background: rgba(4, 8, 15, 0.72);
  backdrop-filter: blur(7px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.25s, visibility 0.25s;
}
.modal-overlay.open { opacity: 1; visibility: visible; pointer-events: auto; }

.modal {
  --c: var(--gold-bright);
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(560px, 100%);
  max-height: min(85dvh, 760px);
  overflow: hidden;
  background: linear-gradient(180deg, #15233c, #0d1726);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-card);
  padding: 22px clamp(18px, 4vw, 26px) 20px;
  transform: scale(0.93) translateY(10px);
  opacity: 0;
  transition: transform 0.32s var(--ease-spring), opacity 0.22s;
}
.modal-overlay.open .modal { transform: none; opacity: 1; }

.modal-close {
  position: absolute;
  top: 10px; right: 10px;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border: none; background: transparent;
  color: var(--muted-2);
  border-radius: 50%; cursor: pointer;
  transition: background 0.18s, color 0.18s, transform 0.12s var(--ease-spring);
}
.modal-close:hover { background: rgba(255, 255, 255, 0.1); color: var(--fg); }
.modal-close:active { transform: scale(0.9); }
.modal-close:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }
.modal-close svg { width: 22px; height: 22px; }

.modal-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 13px;
  padding-right: 40px;
  margin-bottom: 8px;
}
.modal-icon {
  flex: none;
  width: 46px; height: 46px;
  display: grid; place-items: center;
  border-radius: 13px;
  color: var(--c);
  background: color-mix(in srgb, var(--c) 18%, transparent);
  border: 1px solid color-mix(in srgb, var(--c) 35%, transparent);
}
.modal-icon svg { width: 25px; height: 25px; }
.modal-head h3 { font-family: "Fredoka"; font-weight: 700; font-size: 1.45rem; margin: 0; }

.modal-body {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  margin: 2px -6px 0;
  padding: 0 6px;
}
.modal-body h4 {
  font-family: "Fredoka"; font-weight: 600;
  font-size: 0.96rem; color: var(--fg);
  margin: 16px 0 7px;
}
.modal-body p { margin: 0 0 10px; color: var(--muted-2); font-size: 0.92rem; line-height: 1.55; }
.modal-body strong { color: var(--fg); font-weight: 700; }
.m-lead { color: var(--fg); font-weight: 600; font-size: 0.98rem; }
.m-note { font-size: 0.84rem; color: var(--muted); font-style: italic; }
.m-list { margin: 0 0 10px; padding: 0; list-style: none; display: grid; gap: 8px; }
.m-list li {
  position: relative; padding-left: 20px;
  color: var(--muted-2); font-size: 0.9rem; line-height: 1.5;
}
.m-list li::before {
  content: ""; position: absolute; left: 3px; top: 8px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--c);
}
.m-list li strong { color: var(--fg); }
.m-eg {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-left: 3px solid var(--c);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.88rem; color: var(--muted-2);
  margin: 6px 0 10px; line-height: 1.5;
}
.m-eg b { color: var(--fg); font-weight: 700; }
.m-formula {
  text-align: center;
  background: color-mix(in srgb, var(--c) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--c) 30%, transparent);
  border-radius: 12px;
  padding: 14px 12px;
  margin: 10px 0;
  font-family: "Fredoka"; font-weight: 600;
  color: var(--muted-2);
  font-variant-numeric: tabular-nums; line-height: 1.7;
}
.m-formula b { color: var(--c); font-size: 1.15rem; }

.modal-foot {
  flex: none;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 0.76rem; color: var(--muted);
  text-align: center; font-weight: 600;
}

/* ============================================================
   Keyframes
   ============================================================ */
@keyframes viewIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes panelIn { from { opacity: 0; transform: translateY(8px) scale(0.99); } to { opacity: 1; transform: none; } }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
@keyframes popIn { from { opacity: 0; transform: scale(0.92); } to { opacity: 1; transform: none; } }
@keyframes pulse { 0% { transform: scale(1); } 40% { transform: scale(1.22); } 100% { transform: scale(1); } }
@keyframes floaty { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-7px); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes winnerPop { 0% { opacity: 0; transform: scale(0.85) translateY(20px); } 100% { opacity: 1; transform: none; } }

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 560px) {
  .cat-grid { grid-template-columns: 1fr; }
  .count-pills { grid-template-columns: repeat(3, 1fr); }
  .rank-row { grid-template-columns: 40px 1fr auto; gap: 10px; padding: 12px; }
}

@media (min-width: 880px) {
  .cat-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ============================================================
   Reduced motion
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .breakdown span { transition: none; }
}
