:root {
  color-scheme: light;
  --bg: #f7fbf8;
  --paper: #ffffff;
  --paper-soft: #fff8e9;
  --ink: #24313a;
  --muted: #657580;
  --line: #dce9e4;
  --primary: #277d74;
  --primary-strong: #17665e;
  --mint: #dff8ef;
  --blue: #e3f0ff;
  --lavender: #eee8ff;
  --cream: #fff3cf;
  --danger: #b75252;
  --ok: #217b4c;
  --shadow: 0 14px 34px rgba(39, 125, 116, 0.13);
  --radius: 14px;
  --font-size: 16px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
  font-size: var(--font-size);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.75;
  letter-spacing: 0;
  background:
    radial-gradient(circle at 15% 0%, rgba(223, 248, 239, 0.9), transparent 34rem),
    linear-gradient(180deg, #f7fbf8 0%, #f4f7ff 100%);
}

body.large-text {
  --font-size: 18px;
}

button, input, textarea, select {
  font: inherit;
}

button {
  min-height: 48px;
  border: 0;
  border-radius: 12px;
  padding: 0.78rem 1rem;
  color: #ffffff;
  background: var(--primary);
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

button:hover {
  background: var(--primary-strong);
}

button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 3px solid #f7cf67;
  outline-offset: 3px;
}

button.secondary {
  color: var(--primary-strong);
  background: var(--mint);
}

button.soft {
  color: var(--ink);
  background: #eef5f4;
}

button.warn {
  color: #7c3d00;
  background: #ffe4b8;
}

button.ghost {
  color: var(--primary-strong);
  background: transparent;
  border: 1px solid var(--line);
}

button:disabled {
  opacity: 0.72;
  cursor: not-allowed;
}

a {
  color: var(--primary-strong);
  font-weight: 700;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: #fff;
  padding: 0.5rem 1rem;
  z-index: 20;
}

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

.app-shell {
  width: 100%;
  max-width: 680px;
  min-height: 100vh;
  margin: 0 auto;
  background: rgba(255,255,255,0.58);
  border-left: 1px solid rgba(255,255,255,0.8);
  border-right: 1px solid rgba(255,255,255,0.8);
  box-shadow: 0 0 40px rgba(36,49,58,0.05);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  gap: 0.65rem;
  align-items: center;
  padding: 0.7rem 0.9rem;
  background: rgba(247, 251, 248, 0.94);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.icon-button {
  min-width: 48px;
  padding: 0;
  color: var(--primary-strong);
  background: #ffffff;
  border: 1px solid var(--line);
}

.brand-kicker, .brand-name {
  margin: 0;
  line-height: 1.2;
}

.brand-kicker {
  color: var(--muted);
  font-size: 0.78rem;
}

.brand-name {
  font-weight: 800;
}

.app {
  padding: 1rem 0.95rem 6.3rem;
}

.footer {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 6;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.35rem;
  width: min(680px, 100%);
  padding: 0.5rem 0.55rem calc(0.5rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: rgba(255,255,255,0.95);
  border-top: 1px solid var(--line);
}

.footer button {
  min-height: 48px;
  padding: 0.48rem 0.35rem;
  color: var(--primary-strong);
  background: #f1f8f6;
  border-radius: 10px;
  font-size: 0.88rem;
}

.hero {
  padding: 1.25rem;
  border-radius: 18px;
  background:
    linear-gradient(135deg, rgba(223,248,239,0.95), rgba(238,232,255,0.94)),
    var(--paper);
  border: 1px solid rgba(39,125,116,0.12);
  box-shadow: var(--shadow);
}

.hero h1 {
  margin: 0.2rem 0 0.4rem;
  font-size: clamp(1.7rem, 8vw, 2.45rem);
  line-height: 1.18;
}

.subtitle {
  margin: 0 0 0.8rem;
  color: var(--primary-strong);
  font-weight: 800;
}

.lead {
  margin: 0.7rem 0 0;
  color: #34444d;
}

.hero-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 58px;
  height: 58px;
  margin-bottom: 0.45rem;
  border-radius: 18px;
  background: #fff;
  box-shadow: inset 0 -8px 0 rgba(39,125,116,0.08);
  font-size: 2rem;
}

.grid, .button-grid, .card-grid {
  display: grid;
  gap: 0.75rem;
}

.button-grid {
  margin-top: 1rem;
  grid-template-columns: 1fr;
}

.card-grid {
  margin-top: 0.9rem;
}

.card, .panel, .stat-card, .result-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: 0 8px 22px rgba(36,49,58,0.06);
}

.card, .panel, .result-card {
  padding: 1rem;
}

.panel + .panel, .ad-slot + .panel, .card + .card {
  margin-top: 0.85rem;
}

.card h2, .panel h2, .card h3, .panel h3 {
  margin: 0 0 0.55rem;
  line-height: 1.35;
}

.eyebrow {
  margin: 0 0 0.35rem;
  color: var(--primary-strong);
  font-size: 0.86rem;
  font-weight: 800;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.9rem;
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
  margin: 1rem 0;
}

.stat-card {
  padding: 0.8rem;
  min-height: 86px;
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.stat-card strong {
  display: block;
  margin-top: 0.2rem;
  color: var(--primary-strong);
  font-size: 1.55rem;
  line-height: 1.1;
}

.ad-slot {
  display: grid;
  place-items: center;
  min-height: 84px;
  margin: 1rem 0;
  border: 1px dashed #98b8ae;
  border-radius: 12px;
  color: #668077;
  background: repeating-linear-gradient(135deg, #f7fbf8, #f7fbf8 10px, #edf7f4 10px, #edf7f4 20px);
}

.ad-slot span {
  padding: 0.2rem 0.7rem;
  border-radius: 999px;
  background: rgba(255,255,255,0.85);
  font-size: 0.85rem;
}

.search-row {
  display: grid;
  gap: 0.55rem;
  margin: 0.85rem 0;
}

.input, .select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.85rem;
  color: var(--ink);
  background: #fff;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-top: 0.75rem;
}

.toolbar button {
  flex: 1 1 auto;
}

.progress-track {
  width: 100%;
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8efed;
}

.progress-bar {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #4eb9a7, #8acb6f);
  transition: width 220ms ease;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  color: var(--primary-strong);
  background: var(--mint);
  font-size: 0.87rem;
  font-weight: 700;
}

.chapter-body {
  font-size: 1rem;
  line-height: 1.9;
  white-space: pre-line;
}

.key-list {
  padding-left: 1.25rem;
}

.term-card {
  padding: 0.8rem;
  border-radius: 12px;
  background: #f4f8ff;
  border: 1px solid #dce6fb;
}

.choice {
  display: block;
  width: 100%;
  min-height: 52px;
  margin-top: 0.55rem;
  text-align: left;
  color: var(--ink);
  background: #f7fbfb;
  border: 1px solid var(--line);
}

.choice.selected {
  border-color: var(--primary);
  background: var(--mint);
}

.choice.correct {
  color: #114a31;
  border-color: #84c69d;
  background: #e4f7ea;
}

.choice.wrong {
  color: #743131;
  border-color: #e5aaa5;
  background: #fff0ef;
}

.feedback {
  margin-top: 0.8rem;
  padding: 0.85rem;
  border-radius: 12px;
  background: #fff8e9;
  border: 1px solid #f1dba7;
}

.terminal {
  min-height: 96px;
  margin-top: 0.75rem;
  padding: 0.9rem;
  border-radius: 12px;
  color: #e7fff5;
  background: #17252f;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  white-space: pre-wrap;
}

.code-input {
  min-height: 180px;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  line-height: 1.55;
  resize: vertical;
}

.sparkle {
  position: fixed;
  inset: 0;
  z-index: 15;
  pointer-events: none;
  background:
    radial-gradient(circle at 20% 35%, rgba(255, 229, 119, 0.85) 0 5px, transparent 7px),
    radial-gradient(circle at 70% 30%, rgba(134, 214, 192, 0.9) 0 6px, transparent 8px),
    radial-gradient(circle at 52% 62%, rgba(190, 176, 255, 0.8) 0 5px, transparent 7px);
  animation: sparkle 850ms ease forwards;
}

details {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.8rem;
  background: #fff;
}

summary {
  cursor: pointer;
  font-weight: 800;
}

.modal-root:not(:empty) {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(24, 38, 47, 0.45);
}

.modal {
  width: min(560px, 100%);
  max-height: min(78vh, 720px);
  overflow: auto;
  padding: 1rem;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 22px 80px rgba(0,0,0,0.22);
}

.hidden {
  display: none !important;
}

.legal-page {
  max-width: 760px;
  margin: 0 auto;
  padding: 1rem;
}

.legal-page h1 {
  line-height: 1.28;
}

@keyframes sparkle {
  from { opacity: 0; transform: scale(0.92); }
  40% { opacity: 1; }
  to { opacity: 0; transform: scale(1.04); }
}

@media (min-width: 560px) {
  .button-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .card-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .search-row {
    grid-template-columns: 1fr auto;
    align-items: center;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

body.reduce-motion *, body.reduce-motion *::before, body.reduce-motion *::after {
  scroll-behavior: auto !important;
  animation-duration: 0.01ms !important;
  transition-duration: 0.01ms !important;
}
