* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --accent: #e94560;
  --accent-glow: rgba(233,69,96,0.2);
  --bg: #1a1a2e;
  --bg-card: #16213e;
  --bg-pattern: none;
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  background: var(--bg-pattern), var(--bg);
  color: #eee;
  padding: 1rem 0;
}

.container {
  text-align: center;
  max-width: 520px;
  width: 100%;
  padding: 1.5rem;
  margin: auto 0;
}

h1 {
  font-size: 2.4rem;
  margin-bottom: 0.3rem;
  background: linear-gradient(135deg, var(--accent), #0f3460);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle {
  color: #888;
  font-size: 0.95rem;
  margin-bottom: 2rem;
}

/* ---- HOME SCREEN ---- */
.home { display: block; }
.home.hidden { display: none; }

.subject-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 1rem;
}

.subject-grid .subject-card:last-child:nth-child(odd) {
  grid-column: 1 / -1;
}

.subject-card {
  background: var(--bg-card);
  border: 2px solid transparent;
  border-radius: 16px;
  padding: 2rem 1rem;
  cursor: pointer;
  transition: transform 0.2s, border-color 0.3s, box-shadow 0.3s;
}

.subject-card:hover {
  transform: translateY(-4px);
  border-color: var(--accent);
  box-shadow: 0 8px 25px var(--accent-glow);
}

.subject-icon {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}

.subject-name {
  font-size: 1.15rem;
  font-weight: 700;
}

.subject-desc {
  font-size: 0.75rem;
  color: #888;
  margin-top: 0.3rem;
}

/* ---- GAME SCREEN ---- */
.game { display: none; }
.game.active { display: block; }

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.back-btn {
  background: none;
  border: 1px solid #444;
  color: #aaa;
  padding: 0.4rem 1rem;
  font-size: 0.85rem;
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.3s, color 0.3s;
}

.back-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: none;
}

.mode-label {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
}

.stats {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin: 0.5rem 0;
}

.stat {
  background: var(--bg-card);
  padding: 0.5rem 0.7rem;
  border-radius: 12px;
  min-width: 0;
  flex: 1;
}

.stat-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  color: #888;
  letter-spacing: 1px;
}

.stat-value {
  font-size: 1.4rem;
  font-weight: bold;
  color: var(--accent);
}

.level-bar {
  width: 100%;
  height: 8px;
  background: var(--bg-card);
  border-radius: 4px;
  margin: 0.4rem 0 0.9rem;
  overflow: hidden;
}

.level-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #0f3460);
  border-radius: 4px;
  transition: width 0.5s ease;
}

.level-name {
  font-size: 0.85rem;
  color: #aaa;
}

.question-area {
  background: var(--bg-card);
  border-radius: 20px;
  padding: 1.8rem 1.5rem;
  margin-bottom: 0.8rem;
}

.question {
  font-size: 2.5rem;
  font-weight: bold;
  letter-spacing: 2px;
}

.input-row {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

.number-input {
  flex: 1;
  display: flex;
  min-width: 0;
}

#answer {
  flex: 1;
  padding: 0.9rem 0.5rem;
  font-size: 1.3rem;
  border: 2px solid #0f3460;
  border-radius: 0;
  background: var(--bg);
  color: #eee;
  outline: none;
  text-align: center;
  transition: border-color 0.3s;
  min-width: 0;
}

#answer:focus { border-color: var(--accent); }

/* Hide native spinner */
#answer::-webkit-inner-spin-button,
#answer::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
#answer[type=number] { -moz-appearance: textfield; }

.step-btn {
  width: 44px;
  font-size: 1.4rem;
  font-weight: bold;
  border: 2px solid #0f3460;
  background: var(--bg-card);
  color: var(--accent);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.step-btn:hover {
  background: #1a2a4e;
  border-color: var(--accent);
}

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

#decBtn {
  border-radius: 12px 0 0 12px;
  border-right: none;
}

#incBtn {
  border-radius: 0 12px 12px 0;
  border-left: none;
}

#slashBtn {
  display: none;
  border-radius: 0;
  border-left: none;
}

.show-slash #slashBtn { display: block; }

.go-btn {
  padding: 0.9rem 1.8rem;
  font-size: 1.1rem;
  font-weight: bold;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  transition: transform 0.1s, background 0.3s;
}

.go-btn:hover { filter: brightness(0.82); }
.go-btn:active { transform: scale(0.96); }

.feedback {
  height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 600;
}

.feedback.correct { color: #4ecca3; }
.feedback.wrong { color: var(--accent); }

.stat.best-stat {
  border: 1px solid #ffd700;
}

.stat-value.gold {
  color: #ffd700;
}

.streak-info {
  font-size: 0.85rem;
  color: #888;
  margin-top: 0.5rem;
}

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

@keyframes pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

.shake { animation: shake 0.4s ease; }
.pop { animation: pop 0.3s ease; }

.question sup {
  font-size: 0.6em;
}

/* ---- HOME HEADER ---- */
.home-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.2rem 1.2rem 0.4rem;
  margin-bottom: 0;
}

.home-header h1 { margin-bottom: 0; flex: 1; text-align: center; }

/* ---- NAV TOGGLE BUTTON ---- */
.nav-toggle-btn {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  color: #ccc;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 1.3rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s, color 0.2s, transform 0.25s;
}
.nav-toggle-btn:hover { background: rgba(255,255,255,0.15); color: white; }
.nav-toggle-btn.open { transform: rotate(90deg); color: var(--accent); }

/* ---- NAV BAR ---- */
.nav-bar {
  display: flex;
  gap: 0.5rem;
  padding: 0 1rem;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.3s ease, opacity 0.25s ease, padding 0.3s ease;
}
.nav-bar.open {
  max-height: 90px;
  opacity: 1;
  padding: 0 1rem 0.75rem;
}

.nav-bar-item {
  flex: 1;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.12);
  color: #ccc;
  border-radius: 14px;
  padding: 0.55rem 0.3rem 0.5rem;
  font-size: 0.7rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  position: relative;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}
.nav-bar-item:hover { background: rgba(255,255,255,0.13); border-color: var(--accent); color: white; }

.nav-bar-icon { font-size: 1.15rem; line-height: 1; }

.award-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  font-size: 0.6rem;
  font-weight: bold;
  display: none;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

/* ---- AWARDS GRID ---- */
.awards-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  margin-top: 0.5rem;
  max-height: 55vh;
  overflow-y: auto;
}

.award-card {
  background: var(--bg);
  border-radius: 12px;
  padding: 0.7rem 0.5rem;
  text-align: center;
  border: 2px solid transparent;
  transition: opacity 0.3s, border-color 0.3s;
}
.award-card.earned { border-color: var(--accent); }
.award-card.locked { opacity: 0.35; filter: grayscale(1); }
/* Lesson achievement cards get a teal glow */
.award-card.award-cat-lesson.earned {
  border-color: #4ecca3;
  background: rgba(78, 204, 163, 0.1);
}
.award-card.award-cat-lesson .award-name { color: #4ecca3; }
.award-icon { font-size: 1.8rem; }
.award-name { font-size: 0.78rem; font-weight: bold; margin: 0.25rem 0 0.1rem; color: #eee; }
.award-desc { font-size: 0.65rem; color: #888; }

.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.settings-overlay.hidden { display: none; }

.settings-panel {
  background: var(--bg-card);
  border: 2px solid var(--accent);
  border-radius: 20px;
  padding: 2rem 2.5rem;
  text-align: center;
  min-width: 300px;
}

.settings-panel h2 {
  font-size: 1.6rem;
  margin-bottom: 0.3rem;
  color: var(--accent);
}

.settings-section {
  margin: 1.5rem 0;
}

.settings-section p {
  font-size: 0.85rem;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 0.9rem;
}

.color-swatches {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
}

.swatch {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: transform 0.2s, border-color 0.2s, opacity 0.2s;
  outline: none;
  position: relative;
  overflow: hidden;
}

.swatch:hover { transform: scale(1.15); }

.swatch.locked-swatch { cursor: not-allowed; opacity: 0.5; }
.swatch.locked-swatch:hover { transform: none; }
.swatch-lock {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  background: rgba(0,0,0,0.45);
  border-radius: 50%;
  pointer-events: none;
}

.swatch.active {
  border-color: #fff;
  transform: scale(1.15);
}

/* ---- SWATCH TOOLTIP ---- */
.swatch-wrap {
  position: relative;
  display: inline-flex;
}

.swatch-tooltip {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: #0d0d1a;
  border: 1px solid #444;
  color: #eee;
  font-size: 0.68rem;
  font-weight: bold;
  white-space: nowrap;
  padding: 0.3rem 0.65rem;
  border-radius: 8px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s, transform 0.15s;
  transform: translateX(-50%) translateY(4px);
  z-index: 200;
}

.swatch-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: #444;
}

.swatch-wrap:hover .swatch-tooltip {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.theme-swatch { border-color: #555; }
.theme-swatch.active { border-color: #fff; }

.close-settings-btn {
  margin-top: 1.5rem;
  padding: 0.65rem 2rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  transition: filter 0.2s;
}

.close-settings-btn:hover { filter: brightness(0.85); }

/* ---- ALGEBRA ---- */
.algebra-x {
  color: var(--accent);
  font-style: italic;
}

/* ---- PATTERNS ---- */
.pattern-seq {
  font-size: 1.55rem;
  font-weight: bold;
  line-height: 2;
  word-spacing: 0.1rem;
}
.pattern-arrow { color: #555; margin: 0 0.1rem; }
.pattern-q { color: var(--accent); font-size: 2rem; }

/* ---- HINT ---- */
.hint-btn {
  background: none;
  border: none;
  color: #555;
  font-size: 0.8rem;
  cursor: pointer;
  margin-top: 0.6rem;
  padding: 0;
  text-decoration: underline;
  transition: color 0.2s;
}
.hint-btn:hover { color: var(--accent); }
.hint-text {
  margin-top: 0.45rem;
  background: rgba(255,255,255,0.05);
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  padding: 0.45rem 0.75rem;
  font-size: 0.82rem;
  color: #bbb;
  text-align: left;
}
.hint-text.hidden { display: none; }

/* ---- SIMULTANEOUS EQUATIONS ---- */
.simul-eq {
  font-size: 1.85rem;
  line-height: 1.8;
}

.number-input.hidden-input { display: none; }

.dual-input {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.dual-input.hidden { display: none; }

.input-row.dual-mode {
  flex-direction: column;
}

.input-row.dual-mode .go-btn {
  width: 100%;
}

.game.simul-active .stats       { margin: 0.4rem 0; }
.game.simul-active .level-bar   { margin: 0.4rem 0 0.8rem; }
.game.simul-active .streak-info { margin-top: 0.2rem; }

.question-area.simul-active {
  padding: 1rem 1.5rem;
  margin-bottom: 0.8rem;
}

.question-area.simul-active .simul-eq {
  font-size: 1.55rem;
  line-height: 1.6;
}

.question-area.simul-active .dual-field input {
  padding-top: 0.55rem;
  padding-bottom: 0.55rem;
}

.dual-field {
  flex: 1;
  display: flex;
  align-items: center;
  border: 2px solid #0f3460;
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg-card);
  transition: border-color 0.3s;
}

.dual-field:focus-within { border-color: var(--accent); }

.dual-label {
  padding: 0 0.4rem 0 0.75rem;
  font-size: 1.1rem;
  font-style: italic;
  color: var(--accent);
  white-space: nowrap;
}

.dual-field input {
  flex: 1;
  padding: 0.9rem 0.5rem 0.9rem 0;
  font-size: 1.3rem;
  border: none;
  background: transparent;
  color: #eee;
  outline: none;
  text-align: center;
  min-width: 0;
  -moz-appearance: textfield;
}

.dual-field input::-webkit-inner-spin-button,
.dual-field input::-webkit-outer-spin-button { -webkit-appearance: none; }

.dual-step-btn {
  background: none;
  border: none;
  border-left: 2px solid #0f3460;   /* separator on left (for + button) */
  color: #c0cce0;
  font-size: 1.45rem;
  font-weight: bold;
  padding: 0 0.65rem;
  cursor: pointer;
  line-height: 1;
  transition: color 0.15s, background 0.15s, transform 0.1s;
  flex-shrink: 0;
  user-select: none;
  align-self: stretch;              /* stretch to full field height */
  display: flex;
  align-items: center;
}

/* The − button sits right after the label → separator goes on its right instead */
.dual-label + .dual-step-btn {
  border-left: none;
  border-right: 2px solid #0f3460;
}

.dual-step-btn:hover  { color: var(--accent); background: rgba(255,255,255,0.06); }
.dual-step-btn:active { transform: scale(0.88); }

/* ---- PLAYER CHIP ---- */
.player-chip-row {
  margin: 0.3rem 0 0;
}
.player-chip {
  background: none;
  border: 1px solid #444;
  color: #aaa;
  padding: 0.25rem 0.85rem;
  font-size: 0.8rem;
  border-radius: 20px;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}
.player-chip:hover { border-color: var(--accent); color: var(--accent); }

/* ---- PLAYER MODAL ---- */
.player-panel { min-width: 290px; }
.player-panel h2 { color: var(--accent); }

.player-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 0.75rem 0 0.5rem;
  max-height: 38vh;
  overflow-y: auto;
}
.player-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  background: var(--bg);
  border: 2px solid transparent;
  border-radius: 12px;
  padding: 0.55rem 0.85rem;
  transition: border-color 0.2s;
}
.player-item.active { border-color: var(--accent); }

/* Left side: name + stats stacked */
.player-item-info  { display: flex; flex-direction: column; gap: 0.12rem; flex: 1; min-width: 0; }
.player-item-name  { font-size: 0.9rem; font-weight: bold; color: #eee; }
.player-item-stats { font-size: 0.66rem; color: #666; }

/* Right side: badge/switch + delete */
.player-item-actions { display: flex; align-items: center; gap: 0.4rem; flex-shrink: 0; }
.player-item-badge   { font-size: 0.72rem; color: var(--accent); font-weight: bold; }
.player-select-btn   {
  background: none; border: 1px solid #555; color: #aaa;
  padding: 0.22rem 0.65rem; border-radius: 8px; font-size: 0.76rem;
  cursor: pointer; transition: border-color 0.2s, color 0.2s;
}
.player-select-btn:hover { border-color: var(--accent); color: var(--accent); }
.player-delete-btn {
  background: none; border: none; cursor: pointer;
  font-size: 0.88rem; padding: 0.15rem 0.25rem; border-radius: 6px;
  opacity: 0.4; transition: opacity 0.2s;
  line-height: 1;
}
.player-delete-btn:hover { opacity: 1; }
.no-players { color: #555; font-size: 0.82rem; font-style: italic; padding: 0.4rem 0; text-align: center; }

.new-player-section {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.4rem;
}
.new-player-input {
  flex: 1;
  background: var(--bg);
  border: 2px solid #444;
  border-radius: 10px;
  color: #eee;
  padding: 0.48rem 0.75rem;
  font-size: 0.88rem;
  outline: none;
  transition: border-color 0.2s;
}
.new-player-input:focus { border-color: var(--accent); }
.new-player-add-btn {
  padding: 0.48rem 0.9rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: bold;
  cursor: pointer;
  white-space: nowrap;
  transition: filter 0.2s;
}
.new-player-add-btn:hover { filter: brightness(0.85); }

/* ---- TOP SCORES BUTTON ---- */
.top-scores-link {
  background: none;
  border: 1px solid #444;
  color: #888;
  padding: 0.28rem 0.9rem;
  font-size: 0.8rem;
  border-radius: 20px;
  cursor: pointer;
  margin-bottom: 1.2rem;
  transition: border-color 0.2s, color 0.2s;
}
.top-scores-link:hover { border-color: var(--accent); color: var(--accent); }

.top-scores-icon-btn {
  background: none;
  border: 1px solid #444;
  color: #aaa;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 0.6rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color 0.3s, color 0.3s;
}
.top-scores-icon-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ---- TOP SCORES MODAL ---- */
.top-scores-panel { min-width: 300px; max-width: 380px; }
.top-scores-panel h2 { color: var(--accent); }

.top-scores-tabs {
  display: flex;
  gap: 0.5rem;
  margin: 0.75rem 0 0.6rem;
}
.ts-tab {
  flex: 1;
  padding: 0.45rem 0;
  background: var(--bg);
  border: 2px solid #444;
  border-radius: 10px;
  color: #888;
  font-size: 0.82rem;
  font-weight: bold;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}
.ts-tab.active { border-color: var(--accent); color: var(--accent); }

.ts-content { margin: 0.1rem 0; max-height: 52vh; overflow-y: auto; }
.ts-content.hidden { display: none; }

/* Regular tab — one row per subject */
.ts-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.42rem 0.4rem;
  border-radius: 8px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.ts-row:last-child { border-bottom: none; }
.ts-row.ts-unplayed { opacity: 0.35; }
.ts-icon { font-size: 1rem; width: 26px; text-align: center; flex-shrink: 0; font-style: normal; }
.ts-name { flex: 1; text-align: left; font-size: 0.83rem; color: #ccc; }
.ts-stat { text-align: center; min-width: 46px; line-height: 1.1; }
.ts-val  { font-size: 1rem; font-weight: bold; color: var(--accent); display: block; }
.ts-lbl  { font-size: 0.55rem; text-transform: uppercase; color: #666; letter-spacing: 0.5px; display: block; }
.ts-date { font-size: 0.5rem; color: #555; display: block; margin-top: 1px; }

/* Timed tab — one row per time limit */
.ts-timed-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.5rem;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.ts-timed-row:last-child { border-bottom: none; }
.ts-timed-label { font-size: 0.9rem; color: #ccc; }
.ts-timed-right { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 0.05rem; }
.ts-timed-best  { font-size: 1.5rem; font-weight: bold; color: var(--accent); line-height: 1; }
.ts-timed-best.empty { font-size: 1.1rem; color: #555; }
.ts-timed-date  { font-size: 0.6rem; color: #555; }

/* Timed setup back bar — flex so Back + 📊 sit side by side */
.timed-setup-back {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

/* ---- TIMED SETUP ---- */
.timed-setup { display: none; }
.timed-setup.active { display: block; }
.timed-setup-back { text-align: left; margin-bottom: 1rem; }
.timed-setup h2 {
  font-size: 2rem; font-weight: bold; margin: 0.2rem 0 0.2rem;
  background: linear-gradient(135deg, var(--accent), #0f3460);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.timed-section-label {
  font-size: 0.72rem; text-transform: uppercase; color: #888;
  letter-spacing: 1px; margin: 1rem 0 0.5rem;
}
.time-picker { display: flex; gap: 0.5rem; }
.time-btn {
  flex: 1; padding: 0.65rem 0; font-size: 0.95rem; font-weight: bold;
  background: var(--bg-card); border: 2px solid #444; border-radius: 12px;
  color: #aaa; cursor: pointer; transition: border-color 0.2s, color 0.2s;
}
.time-btn:hover { border-color: var(--accent); color: var(--accent); }
.time-btn.selected { background: var(--accent); border-color: var(--accent); color: #fff; }
.timed-sub-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 0.6rem; max-height: 38vh; overflow-y: auto; margin-top: 0;
}
.timed-sub-card {
  background: var(--bg-card); border: 2px solid transparent; border-radius: 12px;
  padding: 0.85rem 0.5rem; cursor: pointer; text-align: center;
  transition: transform 0.15s, border-color 0.2s;
}
.timed-sub-card:hover { transform: translateY(-3px); border-color: var(--accent); }
.timed-sub-card.selected { border-color: var(--accent); background: var(--accent-glow); }
.timed-sub-card .t-icon { font-size: 1.5rem; margin-bottom: 0.2rem; }
.timed-sub-card .t-name { font-size: 0.82rem; font-weight: bold; }
.start-timed-btn {
  margin-top: 1rem; width: 100%; padding: 0.95rem;
  font-size: 1.15rem; font-weight: bold; background: var(--accent);
  color: #fff; border: none; border-radius: 14px;
  cursor: pointer; transition: filter 0.2s, opacity 0.2s;
}
.start-timed-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.start-timed-btn:not(:disabled):hover { filter: brightness(0.85); }

/* ---- TIMED HUD ---- */
.timed-hud { display: none; margin-bottom: 0.6rem; }
.game.timed-active .timed-hud { display: block; }
.game.timed-active .stats,
.game.timed-active .level-name,
.game.timed-active .level-bar,
.game.timed-active .streak-info { display: none; }
.timer-track {
  width: 100%; height: 10px; background: var(--bg-card);
  border-radius: 5px; overflow: hidden; margin-bottom: 0.5rem;
}
.timer-fill {
  height: 100%; background: linear-gradient(90deg, #4ecca3, var(--accent));
  border-radius: 5px; transition: width 0.85s linear;
}
.timer-fill.danger { background: linear-gradient(90deg, #f97316, #e94560); }
.timed-row { display: flex; gap: 0.5rem; }
.timed-box {
  background: var(--bg-card); border-radius: 12px;
  padding: 0.35rem 0; flex: 1; text-align: center;
}
.timed-box-lbl { font-size: 0.62rem; text-transform: uppercase; color: #888; letter-spacing: 1px; }
.timed-box-val { font-size: 1.45rem; font-weight: bold; color: var(--accent); line-height: 1.15; }
.timed-box-val.time-val { color: #4ecca3; }
.timed-box-val.danger { color: var(--accent); animation: blink 0.5s infinite; }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0.35} }

/* ---- WORD PROBLEMS ---- */
.word-problem {
  font-size: 1rem;
  font-weight: normal;
  letter-spacing: 0;
  text-align: left;
  background: rgba(255,255,255,0.04);
  border-left: 3px solid var(--accent);
  border-radius: 0 10px 10px 0;
  padding: 0.75rem 1.1rem 0.9rem;
  color: #dce6f5;
  margin: 0 auto 0.2rem;
}
.word-scene {
  font-size: 1.7rem;
  letter-spacing: 4px;
  text-align: center;
  margin-bottom: 0.55rem;
  line-height: 1;
}
.word-text {
  line-height: 1.65;
}

/* ---- FORMS PROBLEM ---- */
.forms-problem {
  text-align: center;
  background: rgba(255,255,255,0.04);
  border-left: 3px solid var(--accent);
  border-radius: 0 10px 10px 0;
  padding: 0.9rem 1.2rem 1rem;
  color: #dce6f5;
  margin: 0 auto 0.2rem;
}
.forms-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--accent);
  margin-bottom: 0.6rem;
  opacity: 0.85;
}
.forms-eq {
  font-size: 1.6rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  line-height: 1.4;
}

/* ---- SCORE POPUP ---- */
.question-area { position: relative; }
.score-popup {
  position: absolute; top: 0.6rem; right: 0.9rem;
  font-size: 1rem; font-weight: bold; color: #4ecca3;
  pointer-events: none; opacity: 0;
}
.score-popup.bonus { color: #f97316; }
@keyframes floatUp {
  0%   { opacity: 1; transform: translateY(0); }
  80%  { opacity: 1; transform: translateY(-22px); }
  100% { opacity: 0; transform: translateY(-32px); }
}
.score-popup.show { animation: floatUp 0.85s forwards; }

/* ---- AWARD TOAST ---- */
.award-toast {
  position: fixed;
  top: 1rem;
  left: 1rem;
  background: linear-gradient(135deg, #1a1a3e 0%, #2a1040 100%);
  border: 2px solid var(--accent);
  border-radius: 14px;
  padding: 0.7rem 1rem 0.7rem 0.85rem;
  color: #eee;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  z-index: 2000;
  max-width: 240px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.5), 0 0 0 1px rgba(255,255,255,0.06);
  transform: translateX(calc(-100% - 1.5rem));
  transition: transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
}
.award-toast.show {
  transform: translateX(0);
}
.award-toast-icon {
  font-size: 1.6rem;
  line-height: 1;
  flex-shrink: 0;
}
.award-toast-body {
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
  min-width: 0;
}
.award-toast-label {
  font-size: 0.6rem;
  font-weight: bold;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--accent);
}
.award-toast-name {
  font-size: 0.92rem;
  font-weight: bold;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.award-toast-desc {
  font-size: 0.72rem;
  color: #aaa;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- TIMED RESULTS ---- */
.timed-results { display: none; text-align: center; padding: 0.5rem 0; }
.timed-results.active { display: block; }
.timed-results-icon { font-size: 2.8rem; margin-bottom: 0.3rem; }
.timed-results h2 {
  font-size: 2rem; font-weight: bold; margin-bottom: 0.7rem;
  background: linear-gradient(135deg, var(--accent), #0f3460);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.new-best-badge {
  display: inline-block; background: linear-gradient(135deg,#ffd700,#f59e0b);
  color: #111; font-size: 0.78rem; font-weight: bold;
  padding: 0.3rem 0.9rem; border-radius: 20px; margin-bottom: 0.9rem;
}
.new-best-badge.hidden { display: none; }
.result-cards { display: flex; gap: 0.6rem; margin-bottom: 1.2rem; }
.result-card {
  background: var(--bg-card); border-radius: 14px;
  padding: 0.75rem 0.5rem; flex: 1;
}
.result-card-val { font-size: 2rem; font-weight: bold; color: var(--accent); }
.result-card-val.gold { color: #ffd700; }
.result-card-lbl { font-size: 0.62rem; text-transform: uppercase; color: #888; letter-spacing: 1px; margin-top: 0.15rem; }
.result-btns { display: flex; gap: 0.75rem; }
.result-btn {
  flex: 1; padding: 0.85rem; font-size: 1rem; font-weight: bold;
  border-radius: 12px; cursor: pointer; border: none; transition: filter 0.2s;
}
.result-btn.primary { background: var(--accent); color: #fff; }
.result-btn.secondary { background: var(--bg-card); color: #aaa; border: 1px solid #444; }
.result-btn:hover { filter: brightness(0.88); }

/* ============================================================
   LESSONS SCREEN
   ============================================================ */
.lessons-screen.hidden { display: none; }
.lessons-screen {
  padding-bottom: 2rem;
}

.lessons-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 1.2rem 1rem 0.85rem;
  background: rgba(0,0,0,0.15);
  margin-bottom: 0.6rem;
}

.lessons-title {
  flex: 1;
  text-align: center;
  font-size: 1.2rem;
  font-weight: 700;
  color: white;
  margin: 0;
}

.lessons-back-btn {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  color: #aaa;
  padding: 0.45rem 1rem;
  border-radius: 20px;
  font-size: 0.82rem;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: border-color 0.2s, color 0.2s;
}
.lessons-back-btn:hover { border-color: var(--accent); color: var(--accent); }

.chapter-list {
  padding: 0 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.chapter-card {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 16px;
  padding: 0.85rem 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.chapter-num {
  font-size: 0.62rem;
  color: #555;
  font-weight: 700;
  min-width: 16px;
  text-align: right;
  flex-shrink: 0;
}

.chapter-circle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
  letter-spacing: -1px;
}

.chapter-info { flex: 1; min-width: 0; }
.chapter-name { font-size: 0.95rem; font-weight: 700; color: white; line-height: 1.2; }
.chapter-tagline { font-size: 0.7rem; color: #777; margin-top: 0.12rem; }

.chapter-actions { display: flex; gap: 0.4rem; flex-shrink: 0; }

.chapter-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  color: #ccc;
  padding: 0.45rem 0.65rem;
  font-size: 1rem;
  cursor: pointer;
  min-width: 50px;
  transition: background 0.2s, border-color 0.2s;
}
.chapter-btn span { font-size: 0.58rem; color: #888; }
.chapter-btn:hover { background: rgba(255,255,255,0.13); border-color: var(--accent); }
.chapter-zone-btn:hover { background: rgba(233,69,96,0.15); border-color: var(--accent); }

/* ---- MILESTONE CARD ---- */
.chapter-card.chapter-milestone {
  background: rgba(255, 200, 50, 0.06);
  border-color: rgba(255, 200, 50, 0.3);
  margin: 0.2rem 0;   /* slightly more breathing room around checkpoints */
}
.chapter-card.chapter-milestone .chapter-circle {
  background: #7a5a10;
}
.chapter-card.chapter-milestone.chapter-complete {
  border-color: #4ecca3;
  background: rgba(78, 204, 163, 0.07);
}
.chapter-card.chapter-milestone.chapter-complete .chapter-circle {
  background: #1b6b52;
}
.chapter-milestone-marker {
  font-size: 0.85rem;
  color: #ffd700;
  min-width: 16px;
  text-align: right;
  flex-shrink: 0;
  font-weight: 700;
}
.chapter-milestone-btn {
  border-color: rgba(255, 200, 50, 0.4);
  color: #ffd700;
}
.chapter-milestone-btn span { color: #ffd700; }
.chapter-milestone-btn:hover {
  background: rgba(255, 200, 50, 0.15);
  border-color: #ffd700;
}

/* ---- LOCKED LESSON ---- */
.chapter-card.chapter-locked {
  opacity: 0.38;
  border-color: rgba(255,255,255,0.05);
  pointer-events: none;
}
.chapter-card.chapter-locked .chapter-circle {
  background: #333;
}
.chapter-locked-msg {
  font-size: 1.3rem;
  padding: 0.4rem 0.6rem;
  opacity: 0.6;
}

/* ---- COMPLETE LESSON ---- */
.chapter-card.chapter-complete {
  border-color: #4ecca3;
  background: rgba(78, 204, 163, 0.07);
}
.chapter-card.chapter-complete .chapter-circle {
  background: #1b6b52;
}
.chapter-zone-btn.chapter-zone-done {
  border-color: #4ecca3;
  color: #4ecca3;
}
.chapter-zone-btn.chapter-zone-done span { color: #4ecca3; }
.chapter-zone-btn.chapter-zone-done:hover {
  background: rgba(78, 204, 163, 0.15);
  border-color: #4ecca3;
}

/* ============================================================
   BOOK OVERLAY
   ============================================================ */
.book-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
}
.book-overlay.hidden { display: none; }

.book-modal {
  background: var(--card);
  border-radius: 24px 24px 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.book-top {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1rem 0.8rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}

.book-icon-circle {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
  letter-spacing: -1px;
}

.book-title {
  flex: 1;
  font-size: 1.15rem;
  font-weight: 700;
  color: white;
  margin: 0;
}

.book-close-btn {
  background: rgba(255,255,255,0.1);
  border: none;
  color: #aaa;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.82rem;
  flex-shrink: 0;
  transition: background 0.2s;
}
.book-close-btn:hover { background: rgba(255,255,255,0.2); color: white; }

.book-body {
  flex: 1;
  overflow-y: auto;
  padding: 0.9rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.book-section {
  background: rgba(255,255,255,0.04);
  border-radius: 12px;
  padding: 0.85rem 1rem;
}

.book-heading {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent);
  margin: 0 0 0.45rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.book-text {
  font-size: 0.87rem;
  color: #ccc;
  line-height: 1.65;
  margin: 0;
}

.book-example {
  background: rgba(0,0,0,0.3);
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  padding: 0.6rem 0.9rem;
  font-family: 'Courier New', monospace;
  font-size: 0.83rem;
  color: #dce8ff;
  white-space: pre;
  margin: 0.65rem 0 0;
  overflow-x: auto;
}

.book-note {
  font-size: 0.75rem;
  color: #666;
  font-style: italic;
  margin: 0.35rem 0 0;
}

.book-practice-btn {
  padding: 1rem;
  background: var(--accent);
  border: none;
  color: white;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  letter-spacing: 0.3px;
  transition: filter 0.2s;
}
.book-practice-btn:hover { filter: brightness(1.1); }
