:root {
  --bg: #ffffff;
  --bg-soft: #f7f8fa;
  --bg-panel: #ffffff;
  --ink: #111111;
  --muted: #6b7280;
  --line: #ececec;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --good: #157a3a;
  --bad: #b42318;
  --warn: #b45309;
  --focus: #2563eb;
  --shadow: none;
  --radius: 8px;
}

[data-theme="dark"] {
  --bg: #ffffff;
  --bg-soft: #f7f8fa;
  --bg-panel: #ffffff;
  --ink: #111111;
  --muted: #6b7280;
  --line: #ececec;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --good: #157a3a;
  --bad: #b42318;
  --warn: #b45309;
  --focus: #2563eb;
}

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

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  line-height: 1.5;
}

body {
  min-height: 100vh;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--accent);
  color: #fff;
  padding: 0.5rem 0.75rem;
}

.skip-link:focus {
  left: 0.5rem;
  top: 0.5rem;
}

.site-header {
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.site-header-inner,
.page-wrap,
.topbar,
main,
footer {
  width: min(960px, calc(100% - 2rem));
  margin-inline: auto;
}

.site-header-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  min-height: 68px;
  flex-wrap: wrap;
}

.wordmark {
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
  font-size: 1.15rem;
}

.wordmark span {
  color: var(--ink);
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem 1.25rem;
}

.site-nav a {
  color: #6b7280;
  text-decoration: none;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  font-size: 0.95rem;
}

.site-nav a[aria-current="page"],
.site-nav a:hover {
  color: #111;
}

.page-wrap {
  padding: 2rem 0 3rem;
}

.page-title {
  text-align: center;
  margin: 0 0 2rem;
  font-size: 1.8rem;
}

.step-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
  margin-bottom: 2.5rem;
}

.step-card {
  text-align: center;
}

.step-card h2 {
  margin: 0.7rem 0 0.25rem;
  font-size: 1rem;
}

.step-card p {
  margin: 0;
  color: var(--muted);
}

.step-num {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  padding: 1.25rem 0 0.75rem;
}

.brand h1 {
  margin: 0;
  font-size: 1.35rem;
}

.tagline,
.daily,
.hint,
.intro,
.lede,
footer p,
.misses,
.timer-meta,
.mode-badge {
  color: var(--muted);
}

.lede {
  margin: 0 0 1rem;
}

.top-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.35rem;
}

.theme-wrap {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  font-size: 0.9rem;
}

.panel {
  background: var(--bg-panel);
  border: 0;
  border-radius: 0;
  box-shadow: none;
  padding: 0 0 1.5rem;
  margin-bottom: 1.25rem;
}

.choice-group {
  border: 0;
  margin: 0 0 1rem;
  padding: 0;
}

.choice-group legend,
label {
  font-weight: 700;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.45rem 0.8rem;
  min-height: 44px;
  background: #fff;
}

.chip:has(input:checked) {
  border-color: var(--accent);
  color: var(--accent);
}

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

.custom-range input,
select,
#answer-input,
#lesson-input,
#challenge-input {
  width: 100%;
  min-height: 44px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 0.45rem 0.7rem;
  font: inherit;
}

.hint {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--bad);
}

.primary-btn,
.ghost-btn {
  min-height: 44px;
  border-radius: 6px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 700;
  padding: 0.65rem 1.1rem;
  cursor: pointer;
}

.primary-btn {
  background: var(--accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.ghost-btn {
  background: #fff;
  color: var(--ink);
  border-color: #d1d5db;
}

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

.status-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem 0.75rem;
  margin-bottom: 0.85rem;
}

.stat,
.mode-badge {
  margin: 0;
}

.streak.is-milestone {
  color: var(--warn);
}

.timer-wrap {
  margin-bottom: 0.85rem;
}

.timer-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
  margin-bottom: 0.3rem;
}

.progress {
  height: 8px;
  background: #e5e7eb;
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 100%;
  background: var(--accent);
  transform-origin: left center;
  transform: scaleX(1);
}

.progress.is-urgent .progress-fill {
  background: var(--bad);
}

.problem {
  margin: 0.4rem 0 0.9rem;
  text-align: center;
  font-size: clamp(2rem, 8vw, 3.4rem);
  font-weight: 800;
}

.answer-form label {
  display: block;
  margin-bottom: 0.35rem;
}

.answer-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
}

.feedback {
  min-height: 2rem;
  margin-top: 0.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font-weight: 700;
}

.feedback[data-state="correct"] { color: var(--good); }
.feedback[data-state="incorrect"] { color: var(--bad); }

.problem.is-shake {
  animation: shake 280ms ease;
}

.stats-list {
  list-style: none;
  padding: 0;
  margin: 0.4rem 0 0;
}

.stats-list li {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding: 0.55rem 0;
}

.content-band {
  background: var(--bg-soft);
  padding: 2rem 0;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem 2rem;
  margin: 1.25rem 0;
}

.stat-card h2 {
  margin: 0;
  font-size: 0.95rem;
  color: var(--muted);
  font-weight: 700;
}

.stat-card p {
  margin: 0.25rem 0 0;
  font-size: 1.5rem;
  font-weight: 800;
}

.lesson-card {
  padding: 1rem 0;
  border-bottom: 1px solid var(--line);
}

.lesson-card h3 {
  margin: 0 0 0.35rem;
}

.continue-card {
  font-weight: 700;
}

footer {
  padding: 1rem 0 2rem;
  font-size: 0.95rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

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

@media (min-width: 768px) {
  .step-row { grid-template-columns: repeat(3, 1fr); }
  .stats-grid { grid-template-columns: repeat(3, 1fr); }
  .status-row {
    grid-template-columns: repeat(4, auto);
    justify-content: space-between;
  }
  .answer-row { grid-template-columns: 1fr 140px; }
}

@media (prefers-reduced-motion: reduce) {
  .progress-fill,
  .problem.is-shake {
    animation: none !important;
    transition: none !important;
  }
}

@keyframes shake {
  20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}
.welcome-screen {
  position: relative;
  min-height: calc(100vh - 68px);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background:
    radial-gradient(circle at 12% 20%, rgba(37, 99, 235, 0.10), transparent 42%),
    radial-gradient(circle at 88% 78%, rgba(37, 99, 235, 0.08), transparent 40%),
    linear-gradient(#ffffff, #f4f7ff);
  background-image:
    radial-gradient(circle at 12% 20%, rgba(37, 99, 235, 0.10), transparent 42%),
    radial-gradient(circle at 88% 78%, rgba(37, 99, 235, 0.08), transparent 40%),
    linear-gradient(#ffffff, #f4f7ff);
}

.welcome-screen::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(37, 99, 235, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(37, 99, 235, 0.06) 1px, transparent 1px);
  background-size: 44px 44px;
  pointer-events: none;
}

.welcome-math {
  position: absolute;
  inset: 0;
  pointer-events: none;
  color: rgba(37, 99, 235, 0.18);
  font-weight: 700;
  font-size: clamp(1.2rem, 4vw, 2rem);
}

.welcome-math span {
  position: absolute;
}

.welcome-math span:nth-child(1) { top: 12%; left: 8%; }
.welcome-math span:nth-child(2) { top: 18%; right: 12%; }
.welcome-math span:nth-child(3) { top: 42%; left: 6%; }
.welcome-math span:nth-child(4) { bottom: 22%; left: 14%; }
.welcome-math span:nth-child(5) { top: 30%; right: 8%; }
.welcome-math span:nth-child(6) { bottom: 16%; right: 16%; }
.welcome-math span:nth-child(7) { top: 62%; left: 22%; }
.welcome-math span:nth-child(8) { top: 10%; left: 46%; }
.welcome-math span:nth-child(9) { bottom: 12%; left: 48%; }
.welcome-math span:nth-child(10) { top: 52%; right: 22%; }

.welcome-inner {
  position: relative;
  z-index: 1;
  width: min(560px, calc(100% - 2rem));
  text-align: center;
  padding: 1.5rem 0 2.5rem;
}

.welcome-brand {
  margin: 0 0 0.75rem;
  color: #2563eb;
  font-weight: 700;
  font-size: 1.05rem;
}

.welcome-brand span {
  color: #111;
}

.welcome-inner h1 {
  margin: 0 0 0.7rem;
  font-size: clamp(1.8rem, 7vw, 3rem);
  line-height: 1.15;
}

.welcome-copy {
  margin: 0 auto 1.4rem;
  color: #6b7280;
  max-width: 28rem;
}

.welcome-btn {
  width: min(100%, 320px);
}

.welcome-kicker {
  margin: 1rem 0 0;
  color: #9ca3af;
  font-size: 0.9rem;
}

.learn-enter {
  animation: learnEnter 280ms ease;
}

@keyframes learnEnter {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .learn-enter {
    animation: none;
  }
}
#learn-app[hidden],
#welcome-screen[hidden] {
  display: none !important;
}