@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@400;600;700;800&display=swap');

/* ─────────────────────────────────────────────────────────────────
   Times Tables Trainer — style.css
   Tablet-first, touch-optimised, fluid typography
   ───────────────────────────────────────────────────────────────── */

/* ── Reset & base ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --c-bg:       #fff4e6;
  --c-surface:  #ffffff;
  --c-primary:  #ff8a00;
  --c-primary-dark: #e87400;
  --c-primary-light: #ffecd1;
  --c-success:  #22c55e;
  --c-danger:   #ef4444;
  --c-warning:  #f59e0b;
  --c-warning-bg: #fef3c7;
  --c-text:     #1f2937;
  --c-muted:    #6b7280;
  --c-border:   #f1d7bf;

  --radius-sm:  10px;
  --radius:     16px;
  --radius-lg:  26px;

  --shadow:     0 4px 14px rgba(255,138,0,.12);
  --shadow-lg:  0 12px 36px rgba(255,138,0,.2);

  --tap-min:    54px;   /* minimum tap target */
}

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

body {
  font-family: "Fredoka", "Trebuchet MS", "Comic Sans MS", system-ui, sans-serif;
  background: radial-gradient(circle at 10% 10%, #ffe7cc 0, #fff4e6 45%, #ffeef5 100%);
  color: var(--c-text);
  min-height: 100dvh;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

button,
.btn,
.icon-btn,
.numpad-btn,
.pin-btn,
.player-card,
.avatar-option {
  touch-action: manipulation;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(140px 140px at 10% 20%, rgba(255,138,0,.15), transparent 60%),
    radial-gradient(180px 180px at 85% 15%, rgba(79,110,247,.18), transparent 60%),
    radial-gradient(220px 220px at 80% 80%, rgba(34,197,94,.12), transparent 60%);
  pointer-events: none;
  z-index: -1;
}

/* ── Typography ────────────────────────────────────────────────── */
h1 { font-size: clamp(1.6rem, 4vw, 2.4rem); font-weight: 800; }
h2 { font-size: clamp(1.2rem, 3vw, 1.8rem); font-weight: 700; }
h3 { font-size: clamp(1rem, 2.5vw, 1.4rem); font-weight: 600; }

/* ── Views ─────────────────────────────────────────────────────── */
.view { display: none; min-height: 100dvh; padding: 16px; }
.view.active { display: flex; flex-direction: column; }

/* ── Top bar ───────────────────────────────────────────────────── */
.top-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 0 12px;
}
.top-bar .back-btn {
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  min-width: var(--tap-min);
  min-height: var(--tap-min);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--c-primary);
}
.top-bar .back-btn:hover { background: var(--c-border); }
.top-bar h2 {
  flex: 1;
  text-align: left;
}
.top-bar .icon-btn {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  min-width: var(--tap-min);
  min-height: var(--tap-min);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
}
.top-bar .icon-btn:hover { background: var(--c-border); }

/* ── Buttons ───────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 24px;
  height: var(--tap-min);
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform .12s, box-shadow .12s, filter .12s;
  text-decoration: none;
  white-space: nowrap;
  font-family: inherit;
}
.btn:active { transform: scale(.96); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary  { background: var(--c-primary); color: #fff; box-shadow: var(--shadow); }
.btn-primary:hover:not(:disabled) { background: var(--c-primary-dark); filter: saturate(1.1); }

.btn-success  { background: var(--c-success); color: #fff; box-shadow: var(--shadow); }
.btn-danger   { background: var(--c-danger);  color: #fff; box-shadow: var(--shadow); }
.btn-ghost    { background: #fff8ef; color: #c84f00; border: 2px dashed #ffb36b; }
.btn-ghost:hover:not(:disabled) { background: #ffe5c7; color: #7a2e00; }

.btn-large { height: 64px; font-size: 1.2rem; padding: 0 32px; border-radius: var(--radius-lg); }
.btn-full  { width: 100%; }

/* ── Cards ─────────────────────────────────────────────────────── */
.card {
  background: var(--c-surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border: 2px solid rgba(255,179,107,.35);
}

/* ── Player select screen ──────────────────────────────────────── */
#playerSelectView {
  align-items: center;
  gap: 24px;
  position: relative;
}
.help-btn-top {
  position: absolute;
  top: 16px;
  right: 16px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-size: .9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 10;
}
.help-btn-top:hover {
  background: var(--c-border);
}
#playerSelectView .app-title {
  text-align: center;
  padding-top: 24px;
}
#playerSelectView .app-title h1 { font-size: clamp(2rem, 6vw, 3rem); }
#playerSelectView .subtitle { color: var(--c-muted); font-size: 1rem; }

.player-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 16px;
  width: 100%;
  max-width: 640px;
}
.player-card {
  background: var(--c-surface);
  border-radius: var(--radius-lg);
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: var(--shadow);
  border: 2px solid #ffe1c7;
  position: relative;
  transition: transform .12s, border-color .15s, box-shadow .15s;
  min-height: 140px;
  user-select: none;
}
.player-card:hover, .player-card:focus {
  border-color: #ffb36b;
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px) rotate(-0.6deg);
  outline: none;
}
.player-card .avatar { font-size: 2.6rem; line-height: 1; }
.player-card .player-name { font-weight: 700; font-size: 1rem; }
.player-card .player-level { font-size: .85rem; color: var(--c-muted); }
.player-card .h2h-badge {
  position: absolute;
  top: 8px; right: 8px;
  background: var(--c-danger);
  color: #fff;
  border-radius: 99px;
  font-size: .75rem;
  font-weight: 700;
  padding: 2px 7px;
  min-width: 24px;
  text-align: center;
}

.home-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  justify-items: stretch;
  align-items: stretch;
  max-width: 680px;
  width: 100%;
}
.home-actions .btn { width: 100%; }

.global-stats-card {
  width: 100%;
  max-width: 680px;
}

.global-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.global-stat {
  background: #fff8ef;
  border: 1px solid var(--c-border);
  border-radius: 12px;
  padding: 10px;
  text-align: center;
}

.global-stat .v {
  font-size: 1.2rem;
  font-weight: 800;
  color: #c84f00;
}

.global-stat .k {
  font-size: .75rem;
  color: var(--c-muted);
}

.hard-list {
  margin-top: 12px;
  display: grid;
  gap: 6px;
}

.hard-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 10px;
  background: #fff;
  border: 1px solid #f3dfca;
  font-size: .9rem;
}

.hard-row .rate {
  font-weight: 700;
  color: #b42318;
}

.global-split-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
}

.global-split-card {
  padding: 14px;
}

.global-heatmaps-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 12px;
}

.global-heatmap-card {
  padding: 14px;
}

.help-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
  justify-items: stretch;
  align-items: stretch;
  max-width: 680px;
  width: 100%;
}

.help-strip .btn { width: 100%; }

.home-actions .btn,
.help-strip .btn {
  white-space: normal;
  text-align: left;
  justify-content: flex-start;
  gap: 10px;
  padding: 12px 16px;
  line-height: 1.2;
}



/* ── Quiz view ─────────────────────────────────────────────────── */
#quizView { gap: 12px; max-width: 600px; margin: 0 auto; width: 100%; }

.quiz-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.quiz-meta { display: flex; align-items: center; gap: 12px; font-size: .9rem; color: var(--c-muted); }
.level-badge {
  background: var(--c-primary);
  color: #fff;
  border-radius: 99px;
  padding: 4px 12px;
  font-size: .85rem;
  font-weight: 700;
}
.streak-counter { font-size: 1rem; font-weight: 700; color: var(--c-warning); }

.timer-bar-wrap {
  height: 8px;
  background: var(--c-border);
  border-radius: 4px;
  overflow: hidden;
}
.timer-bar {
  height: 100%;
  background: var(--c-primary);
  border-radius: 4px;
  transition: width .1s linear, background .3s;
}
.timer-bar.urgent { background: var(--c-danger); }

.question-card {
  background: var(--c-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 32px 20px;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.question-text {
  font-size: clamp(2rem, 8vw, 3.5rem);
  font-weight: 800;
  letter-spacing: .02em;
}
.question-feedback {
  margin-top: 12px;
  font-size: 2rem;
  font-weight: 700;
  min-height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s;
}
.question-feedback.show { opacity: 1; }
.question-feedback.correct { color: #16a34a; background: rgba(34,197,94,.15); }
.question-feedback.wrong   { color: #dc2626; background: rgba(239,68,68,.15); }

/* number input */
.answer-section { display: flex; flex-direction: column; gap: 12px; }
.answer-display {
  background: var(--c-surface);
  border: 2px solid var(--c-border);
  border-radius: var(--radius);
  padding: 12px 20px;
  font-size: 2rem;
  font-weight: 700;
  text-align: center;
  min-height: 64px;
  letter-spacing: .05em;
  color: var(--c-text);
}
.answer-display.has-value { border-color: var(--c-primary); }

.numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.numpad-btn {
  background: var(--c-surface);
  border: 2px solid var(--c-border);
  border-radius: var(--radius);
  font-size: 1.4rem;
  font-weight: 700;
  height: 64px;
  cursor: pointer;
  transition: background .1s, transform .08s;
  box-shadow: var(--shadow);
}
.numpad-btn:active { transform: scale(.94); background: var(--c-primary); color: #fff; border-color: var(--c-primary); }
.numpad-btn.del   { color: var(--c-danger); }
.numpad-btn.submit { background: var(--c-primary); color: #fff; border-color: var(--c-primary); font-size: 1.1rem; }
.numpad-btn.submit:active { background: var(--c-primary-dark); }

/* ── Dashboard ──────────────────────────────────────────────────── */
#dashboardView { gap: 16px; max-width: 720px; margin: 0 auto; width: 100%; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 12px;
}
.stat-card {
  background: var(--c-surface);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat-card .stat-value { font-size: 1.8rem; font-weight: 800; color: var(--c-primary); }
.stat-card .stat-label { font-size: .8rem; color: var(--c-muted); margin-top: 4px; }

.chart-wrap { position: relative; height: 180px; }

/* Heatmap */
.heatmap-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.heatmap {
  display: grid;
  grid-template-columns: 28px repeat(10, 1fr);
  gap: 3px;
  min-width: 320px;
}
.heatmap-cell {
  aspect-ratio: 1;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .65rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform .1s;
}
.heatmap-cell:hover { transform: scale(1.15); z-index: 1; }
.heatmap-header { background: transparent; font-size: .7rem; color: var(--c-muted); font-weight: 700; }
.heatmap-label  { background: transparent; font-size: .7rem; color: var(--c-muted); font-weight: 700; display: flex; align-items: center; justify-content: flex-end; padding-right: 4px; }
.heatmap-cell[data-disabled="1"] { background: #e2e8f0 !important; color: var(--c-muted); }
.heatmap-cell[data-nodata="1"] { color: transparent; border: 1px dashed #dbe3ee; }

.session-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.session-table th, .session-table td { padding: 10px 8px; text-align: left; border-bottom: 1px solid var(--c-border); }
.session-table th { font-weight: 700; color: var(--c-muted); font-size: .8rem; }

.achievement-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.achievement-badge {
  background: var(--c-surface);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.achievement-badge .badge-label { font-weight: 700; font-size: .9rem; }
.achievement-badge .badge-date  { font-size: .75rem; color: var(--c-muted); }
.achievement-badge.locked       { opacity: .45; filter: grayscale(1); }
.achievement-badge .badge-desc  { font-size: .75rem; color: var(--c-muted); }

/* ── Leaderboard ────────────────────────────────────────────────── */
#leaderboardView { gap: 16px; max-width: 640px; margin: 0 auto; width: 100%; }

/* ── Global stats view ───────────────────────────────────────────── */
#globalStatsView { gap: 16px; max-width: 720px; margin: 0 auto; width: 100%; }
.global-stats-card { margin: 0 auto; }

.tab-bar {
  display: flex;
  gap: 8px;
  background: var(--c-surface);
  border-radius: var(--radius);
  padding: 4px;
  box-shadow: var(--shadow);
}
.tab-btn {
  flex: 1;
  height: 40px;
  border: none;
  border-radius: 10px;
  background: transparent;
  font-weight: 600;
  font-size: .9rem;
  cursor: pointer;
  transition: background .15s, color .15s;
  color: var(--c-muted);
}
.tab-btn.active { background: var(--c-primary); color: #fff; }

.leaderboard-list { display: flex; flex-direction: column; gap: 10px; }
.leaderboard-row {
  background: var(--c-surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: box-shadow .15s;
}
.leaderboard-row:hover { box-shadow: var(--shadow-lg); }
.leaderboard-row .rank {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--c-muted);
  min-width: 28px;
  text-align: center;
}
.leaderboard-row.rank-1 .rank { color: #f59e0b; }
.leaderboard-row.rank-2 .rank { color: #94a3b8; }
.leaderboard-row.rank-3 .rank { color: #b45309; }
.leaderboard-row .avatar-name { flex: 1; }
.leaderboard-row .player-avatar { font-size: 1.5rem; }
.leaderboard-row .player-name-lb { font-weight: 700; }
.leaderboard-row .score-pts { font-size: 1.1rem; font-weight: 800; color: var(--c-primary); }
.countdown-label { text-align: center; color: var(--c-muted); font-size: .85rem; padding: 8px 0; }

/* ── Daily challenge ─────────────────────────────────────────────── */
#dailyChallengeView { gap: 16px; max-width: 600px; margin: 0 auto; width: 100%; }

.daily-result-banner {
  background: var(--c-success);
  color: #fff;
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  font-weight: 700;
  font-size: 1.1rem;
}

/* ── Head-to-head ────────────────────────────────────────────────── */
#h2hView { gap: 16px; max-width: 640px; margin: 0 auto; width: 100%; }

.h2h-result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.h2h-player-col {
  background: var(--c-surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  text-align: center;
}
.h2h-player-col.winner { border: 3px solid var(--c-success); }
.h2h-answers-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.h2h-answers-table th, .h2h-answers-table td { padding: 8px 6px; border-bottom: 1px solid var(--c-border); }

/* ── PIN entry views ─────────────────────────────────────────────── */
#childPinView,
#parentPinView {
  align-items: center;
  justify-content: center;
  gap: 20px;
}
.pin-display {
  display: flex;
  gap: 12px;
  justify-content: center;
}
.pin-dot {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--c-border);
  transition: background .15s;
}
.pin-dot.filled { background: var(--c-primary); }

.pin-numpad {
  display: grid;
  grid-template-columns: repeat(3, 80px);
  gap: 12px;
  justify-content: center;
  margin: 24px auto 0;
}
.pin-key {
  width: 80px; height: 80px;
  border: 2px solid var(--c-border);
  border-radius: var(--radius);
  background: var(--c-surface);
  font-size: 1.6rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: background .1s, transform .08s;
}
.pin-key:active { transform: scale(.93); background: var(--c-primary); color: #fff; border-color: var(--c-primary); }
.pin-key.del { font-size: 1.2rem; color: var(--c-danger); }
.pin-error { color: var(--c-danger); font-weight: 600; text-align: center; font-size: .9rem; }

#parentPanelView { gap: 16px; max-width: 720px; margin: 0 auto; width: 100%; }

.parent-player-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--c-surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.parent-player-row .avatar-col { font-size: 1.8rem; }
.parent-player-row .info-col { flex: 1; }
.parent-player-row .info-col .name { font-weight: 700; }
.parent-player-row .info-col .meta { font-size: .85rem; color: var(--c-muted); }

.factor-toggle-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
  gap: 10px;
}

.factor-toggle-block {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.factor-toggle-title {
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--c-muted);
}

.factor-toggle-btn {
  display: grid;
  gap: 4px;
  align-items: center;
  justify-items: center;
  padding: 10px 6px;
  border-radius: var(--radius);
  border: 2px solid var(--c-border);
  background: var(--c-surface);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform .08s, border-color .12s, background .12s;
}

.factor-toggle-btn:active { transform: scale(.96); }

.factor-toggle-btn.is-on {
  border-color: rgba(34,197,94,.6);
  background: rgba(34,197,94,.12);
}

.factor-toggle-btn.is-off {
  border-color: rgba(148,163,184,.8);
  background: rgba(148,163,184,.12);
}

.factor-label {
  font-size: 1.2rem;
  font-weight: 800;
}

.factor-state {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--c-muted);
}

.table-grid-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-grid {
  display: grid;
  grid-template-columns: 28px repeat(10, 1fr);
  gap: 3px;
  min-width: 320px;
}
.tg-cell {
  aspect-ratio: 1;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .7rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .1s, transform .08s;
  border: 1px solid var(--c-border);
  background: var(--c-success);
  color: #fff;
  user-select: none;
}
.tg-cell:hover { transform: scale(1.15); z-index: 1; }
.tg-cell:active { transform: scale(.9); }
.tg-cell.disabled { background: #e2e8f0; color: var(--c-muted); }
.tg-cell.header { background: transparent; color: var(--c-muted); cursor: default; font-weight: 700; border: none; }
.tg-cell.header:hover { transform: none; }
.tg-cell.row-hdr { background: var(--c-primary); color: #fff; border-radius: 6px; }

.avatar-picker { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.avatar-option {
  font-size: 2rem;
  width: 52px; height: 52px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  border: 2px solid var(--c-border);
  transition: border-color .1s, transform .08s;
}
.avatar-option:active { transform: scale(.95); }
.avatar-option.selected { border-color: var(--c-primary); background: rgba(79,110,247,.1); }

.level-control {
  display: flex;
  align-items: center;
  gap: 16px;
}
.level-control .level-val { font-size: 1.4rem; font-weight: 800; min-width: 32px; text-align: center; }

/* ── Achievement unlock overlay ──────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
}
.overlay.show { opacity: 1; pointer-events: all; }
.overlay-card {
  background: var(--c-surface);
  border-radius: var(--radius-lg);
  padding: 40px 32px;
  text-align: center;
  max-width: 340px;
  width: 92%;
  box-shadow: var(--shadow-lg);
  transform: scale(.85);
  transition: transform .25s;
}
.overlay.show .overlay-card { transform: scale(1); }
.overlay-icon { font-size: 4rem; margin-bottom: 12px; }
.overlay-title { font-size: 1.4rem; font-weight: 800; margin-bottom: 6px; }
.overlay-subtitle { color: var(--c-muted); font-size: .95rem; margin-bottom: 24px; }

/* ── Player action menu overlay ──────────────────────────────────── */
#playerMenuOverlay .overlay-card {
  text-align: left;
  padding: 24px;
  max-width: 420px;
}
.count-btn-row { display: flex; gap: 8px; }
.count-btn {
  flex: 1;
  padding: 12px 0;
  border: 2px solid var(--c-border);
  border-radius: var(--radius-sm);
  background: var(--c-bg);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all .15s;
}
.count-btn.active {
  background: var(--c-primary);
  border-color: var(--c-primary);
  color: #fff;
}

/* ── Level up/down overlay ───────────────────────────────────────── */
.level-overlay-icon { font-size: 5rem; margin-bottom: 16px; }
.level-overlay-title { font-size: 1.8rem; font-weight: 800; }
.level-overlay-sub   { color: var(--c-muted); margin-top: 8px; }

/* ── Point breakdown modal ───────────────────────────────────────── */
.point-breakdown-modal {
  background: var(--c-surface);
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 640px;
  width: 92%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  position: relative;
}

.modal-close-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 36px;
  height: 36px;
  border: none;
  background: var(--c-bg);
  border-radius: 50%;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
  color: var(--c-text);
  z-index: 10;
}

.modal-close-btn:hover {
  background: var(--c-border);
  transform: scale(1.1);
}

.modal-close-btn:active {
  transform: scale(0.95);
}

.points-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 16px 0;
}

.points-summary-item {
  background: var(--c-bg);
  border-radius: var(--radius-sm);
  padding: 16px 12px;
  text-align: center;
}

.points-summary-label {
  font-size: .8rem;
  color: var(--c-muted);
  margin-bottom: 8px;
}

.points-summary-value {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--c-primary);
  margin-bottom: 4px;
}

.points-summary-count {
  font-size: .75rem;
  color: var(--c-muted);
}

.points-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
}

.points-table thead th {
  background: var(--c-bg);
  padding: 10px 12px;
  text-align: left;
  font-size: .85rem;
  font-weight: 700;
  border-bottom: 2px solid var(--c-border);
}

.points-table tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--c-border);
  font-size: .9rem;
}

.points-table tbody tr:last-child td {
  border-bottom: none;
}

@media (max-width: 520px) {
  .points-summary {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  
  .points-summary-item {
    padding: 12px;
  }
}

/* ── Misc utilities ──────────────────────────────────────────────── */
.text-center { text-align: center; }
.text-muted  { color: var(--c-muted); }
.mt-8  { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.gap-8  { gap: 8px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.section-title { font-weight: 700; font-size: 1rem; color: var(--c-muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 8px; }
.empty-state { text-align: center; color: var(--c-muted); padding: 32px; }

/* ── On-site documentation ─────────────────────────────────────── */
.help-card {
  max-width: 600px;
  margin: 0 auto;
  line-height: 1.4;
  padding: 22px;
  text-align: left;
}

.help-card p,
.help-card li,
.help-card h3 {
  text-align: left;
}

.help-lead {
  font-weight: 700;
  font-size: 1.05rem;
  margin-bottom: 12px;
}

.help-section {
  margin-top: 16px;
}

.help-section h3 {
  font-size: 1rem;
  color: var(--c-muted);
  text-transform: none;
  letter-spacing: 0;
  margin-bottom: 8px;
}

.help-steps {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px;
}

.help-step {
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-weight: 600;
}

.help-list {
  margin: 6px 0 0 18px;
  display: grid;
  gap: 4px;
}

/* ── Responsive tweaks ───────────────────────────────────────────── */
@media (max-width: 480px) {
  html { font-size: 16px; }
  .view { padding: 12px; }
  .player-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  .pin-numpad { grid-template-columns: repeat(3, 72px); }
  .pin-key { width: 72px; height: 72px; }
}

@media (min-width: 768px) {
  .player-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}

/* ── Animations ──────────────────────────────────────────────────── */
@keyframes pop {
  0%   { transform: scale(.8); opacity: 0; }
  70%  { transform: scale(1.08); }
  100% { transform: scale(1); opacity: 1; }
}
.pop { animation: pop .3s ease both; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60%  { transform: translateX(-6px); }
  40%, 80%  { transform: translateX(6px); }
}
.shake { animation: shake .35s ease; }

@keyframes flash-green {
  0%   { background: rgba(34,197,94,.3); }
  100% { background: transparent; }
}
.flash-correct { animation: flash-green .4s ease; }

@keyframes flash-red {
  0%   { background: rgba(239,68,68,.25); }
  100% { background: transparent; }
}
.flash-wrong { animation: flash-red .4s ease; }



/* ── Loading spinner ─────────────────────────────────────────────── */
.spinner {
  border: 3px solid var(--c-border);
  border-top-color: var(--c-primary);
  border-radius: 50%;
  width: 32px; height: 32px;
  animation: spin .7s linear infinite;
  margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
