:root {
  --bg: #0f1419;
  --bg-elev: #1a222d;
  --bg-card: #222c3a;
  --bg-hover: #2a3648;
  --line: #334155;
  --text: #e8eef6;
  --muted: #94a3b8;
  --accent: #f59e0b;
  --accent-2: #38bdf8;
  --good: #34d399;
  --bad: #f87171;
  --purple: #a78bfa;
  --pink: #f472b6;
  --radius: 14px;
  --shadow: 0 8px 32px rgba(0,0,0,.35);
  --font: "DM Sans", system-ui, sans-serif;
  --display: "Fraunces", Georgia, serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(245,158,11,.12), transparent 50%),
    radial-gradient(900px 500px at 100% 0%, rgba(56,189,248,.10), transparent 45%),
    var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

#app { max-width: 920px; margin: 0 auto; padding: 0 16px 48px; min-height: 100dvh; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 0 12px; position: sticky; top: 0; z-index: 20;
  background: linear-gradient(to bottom, var(--bg) 70%, transparent);
  backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 10px; cursor: pointer; border: 0; background: none; color: inherit; text-align: left; padding: 0; }
.brand-mark { font-size: 1.6rem; filter: drop-shadow(0 0 8px rgba(245,158,11,.4)); }
.brand-title { font-family: var(--display); font-weight: 700; font-size: 1.15rem; letter-spacing: -.02em; }
.brand-sub { font-size: .72rem; color: var(--muted); }

.stats { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.stat {
  display: flex; flex-direction: column; align-items: center;
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: 10px; padding: 4px 12px; min-width: 52px;
}
.stat-label { font-size: .65rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.stat-value { font-weight: 700; font-size: 1rem; color: var(--accent); }
.stat.streak .stat-value { color: var(--accent-2); }

.btn-ghost, .btn-primary, .btn-secondary, .btn-choice, .chip {
  font-family: inherit; cursor: pointer; border-radius: 10px; border: 1px solid transparent;
  transition: transform .12s ease, background .15s, border-color .15s, box-shadow .15s;
}
.btn-ghost {
  background: transparent; border-color: var(--line); color: var(--muted);
  padding: 6px 10px; font-size: .8rem;
}
.btn-ghost:hover { color: var(--text); border-color: var(--muted); }
.btn-primary {
  background: linear-gradient(135deg, #f59e0b, #f97316);
  color: #111; font-weight: 700; padding: 12px 20px; font-size: .95rem;
  box-shadow: 0 4px 16px rgba(245,158,11,.3);
}
.btn-primary:hover { transform: translateY(-1px); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-secondary {
  background: var(--bg-card); border-color: var(--line); color: var(--text);
  padding: 10px 16px; font-weight: 600;
}
.btn-secondary:hover { background: var(--bg-hover); border-color: var(--accent-2); }

main { flex: 1; padding-bottom: var(--safe-bottom); }

.hero {
  text-align: center; padding: 28px 8px 20px;
}
.hero h1 {
  font-family: var(--display); font-size: clamp(1.8rem, 5vw, 2.5rem);
  margin: 0 0 8px; letter-spacing: -.03em; line-height: 1.15;
}
.hero .lede { color: var(--muted); max-width: 34em; margin: 0 auto 20px; font-size: 1.02rem; }
.hero .badge-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 8px; }
.badge {
  font-size: .75rem; padding: 4px 10px; border-radius: 999px;
  background: var(--bg-elev); border: 1px solid var(--line); color: var(--muted);
}
.badge.hot { border-color: rgba(245,158,11,.5); color: var(--accent); background: rgba(245,158,11,.1); }

.progress-ring-wrap {
  display: flex; justify-content: center; gap: 24px; margin: 16px 0 28px; flex-wrap: wrap;
}
.progress-card {
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 18px; min-width: 140px; text-align: center;
}
.progress-card .big { font-family: var(--display); font-size: 1.8rem; color: var(--accent); }
.progress-card .lbl { font-size: .8rem; color: var(--muted); }

.section-label {
  font-size: .75rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); margin: 8px 0 12px; font-weight: 600;
}

.unit-grid { display: grid; gap: 12px; margin-bottom: 28px; }
@media (min-width: 640px) { .unit-grid { grid-template-columns: 1fr 1fr; } }

.unit-card {
  background: var(--bg-card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; text-align: left; color: inherit; cursor: pointer;
  box-shadow: var(--shadow); position: relative; overflow: hidden;
  display: flex; flex-direction: column; gap: 8px; width: 100%;
  font-family: inherit;
}
.unit-card::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  opacity: 0; transition: opacity .2s;
}
.unit-card:hover::before, .unit-card.open::before { opacity: 1; }
.unit-card:hover { border-color: #475569; transform: translateY(-2px); }
.unit-card.locked { opacity: .72; cursor: default; }
.unit-card.locked:hover { transform: none; }
.unit-card .uc-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.unit-card h2 { margin: 0; font-family: var(--display); font-size: 1.2rem; }
.unit-card p { margin: 0; color: var(--muted); font-size: .9rem; flex: 1; }
.unit-card .uc-meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 4px; }
.pill {
  font-size: .7rem; font-weight: 600; padding: 3px 8px; border-radius: 999px;
  background: rgba(56,189,248,.12); color: var(--accent-2); border: 1px solid rgba(56,189,248,.25);
}
.pill.done { background: rgba(52,211,153,.12); color: var(--good); border-color: rgba(52,211,153,.3); }
.pill.soon { background: rgba(167,139,250,.12); color: var(--purple); border-color: rgba(167,139,250,.3); }
.bar { height: 6px; background: var(--bg); border-radius: 99px; overflow: hidden; width: 100%; margin-top: 4px; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--good)); border-radius: 99px; transition: width .4s ease; }

/* Unit hub */
.back-row { margin: 8px 0 16px; }
.unit-hero { margin-bottom: 20px; }
.unit-hero h1 { font-family: var(--display); font-size: clamp(1.5rem, 4vw, 2rem); margin: 0 0 6px; }
.unit-hero p { color: var(--muted); margin: 0; }

.module-list { display: flex; flex-direction: column; gap: 10px; }
.module-item {
  display: flex; align-items: center; gap: 14px;
  background: var(--bg-card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; cursor: pointer; color: inherit; text-align: left;
  font-family: inherit; width: 100%;
}
.module-item:hover { border-color: var(--accent-2); background: var(--bg-hover); }
.module-item.complete { border-color: rgba(52,211,153,.35); }
.mod-icon {
  width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center;
  font-size: 1.3rem; background: var(--bg-elev); flex-shrink: 0;
}
.mod-body { flex: 1; min-width: 0; }
.mod-body h3 { margin: 0 0 2px; font-size: 1rem; }
.mod-body p { margin: 0; font-size: .82rem; color: var(--muted); }
.mod-xp { font-size: .75rem; font-weight: 700; color: var(--accent); white-space: nowrap; }
.check { color: var(--good); font-size: 1.2rem; }

/* Activity views */
.activity-wrap { max-width: 720px; margin: 0 auto; }
.activity-head { margin-bottom: 20px; }
.activity-head .type-tag {
  display: inline-block; font-size: .7rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--accent); font-weight: 700; margin-bottom: 6px;
}
.activity-head h1 { font-family: var(--display); font-size: 1.55rem; margin: 0 0 8px; }
.activity-head p { color: var(--muted); margin: 0; }

.card {
  background: var(--bg-card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.card h2, .card h3 { font-family: var(--display); margin: 0 0 10px; }
.card p { margin: 0 0 10px; }
.card p:last-child { margin-bottom: 0; }
.card ul, .card ol { margin: 0 0 10px; padding-left: 1.2em; color: var(--text); }
.card li { margin-bottom: 6px; }
.callout {
  border-left: 3px solid var(--accent-2); padding: 10px 14px;
  background: rgba(56,189,248,.08); border-radius: 0 10px 10px 0; margin: 12px 0;
  font-size: .95rem;
}
.callout.amber { border-color: var(--accent); background: rgba(245,158,11,.08); }
.callout.green { border-color: var(--good); background: rgba(52,211,153,.08); }

/* Reading */
.reading-nav { display: flex; gap: 10px; justify-content: space-between; margin-top: 16px; flex-wrap: wrap; }
.step-dots { display: flex; gap: 6px; justify-content: center; margin: 12px 0; }
.step-dots span {
  width: 8px; height: 8px; border-radius: 50%; background: var(--line);
}
.step-dots span.on { background: var(--accent); box-shadow: 0 0 8px rgba(245,158,11,.5); }

/* Worked example */
.cee-grid { display: grid; gap: 12px; }
@media (min-width: 600px) { .cee-grid { grid-template-columns: 1fr; } }
.cee-block {
  border-radius: 12px; padding: 14px 16px; border: 1px solid var(--line);
}
.cee-block.claim { background: rgba(245,158,11,.08); border-color: rgba(245,158,11,.3); }
.cee-block.evidence { background: rgba(56,189,248,.08); border-color: rgba(56,189,248,.3); }
.cee-block.explain { background: rgba(167,139,250,.08); border-color: rgba(167,139,250,.3); }
.cee-label { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 6px; opacity: .85; }
.cee-block.claim .cee-label { color: var(--accent); }
.cee-block.evidence .cee-label { color: var(--accent-2); }
.cee-block.explain .cee-label { color: var(--purple); }

/* Fill blanks */
.blank-passage { font-size: 1.05rem; line-height: 1.85; }
.blank-input {
  display: inline-block; min-width: 110px; max-width: 180px;
  margin: 0 4px; padding: 4px 10px;
  background: var(--bg); border: 2px dashed var(--line); border-radius: 8px;
  color: var(--text); font-family: inherit; font-size: .95rem; text-align: center;
}
.blank-input:focus { outline: none; border-color: var(--accent-2); border-style: solid; }
.blank-input.correct { border-color: var(--good); border-style: solid; background: rgba(52,211,153,.1); }
.blank-input.wrong { border-color: var(--bad); border-style: solid; background: rgba(248,113,113,.1); }
.feedback { margin-top: 12px; padding: 12px; border-radius: 10px; font-size: .92rem; }
.feedback.ok { background: rgba(52,211,153,.12); color: var(--good); border: 1px solid rgba(52,211,153,.3); }
.feedback.no { background: rgba(248,113,113,.12); color: #fecaca; border: 1px solid rgba(248,113,113,.3); }
.feedback.partial { background: rgba(245,158,11,.12); color: #fcd34d; border: 1px solid rgba(245,158,11,.3); }

/* MCQ */
.choices { display: flex; flex-direction: column; gap: 8px; margin: 14px 0; }
.btn-choice {
  text-align: left; padding: 12px 14px; background: var(--bg-elev);
  border: 1px solid var(--line); color: var(--text); font-size: .95rem;
  display: flex; gap: 10px; align-items: flex-start;
}
.btn-choice:hover:not(:disabled) { border-color: var(--accent-2); background: var(--bg-hover); }
.btn-choice .letter {
  width: 26px; height: 26px; border-radius: 8px; background: var(--bg);
  display: grid; place-items: center; font-weight: 700; font-size: .8rem; flex-shrink: 0;
  color: var(--muted);
}
.btn-choice.correct { border-color: var(--good); background: rgba(52,211,153,.12); }
.btn-choice.correct .letter { background: var(--good); color: #111; }
.btn-choice.incorrect { border-color: var(--bad); background: rgba(248,113,113,.1); opacity: .85; }
.btn-choice:disabled { cursor: default; }
.explain-box {
  margin-top: 10px; padding: 12px 14px; border-radius: 10px;
  background: rgba(56,189,248,.1); border: 1px solid rgba(56,189,248,.25);
  font-size: .92rem;
}
.q-progress { font-size: .8rem; color: var(--muted); margin-bottom: 8px; }

/* Vocab */
.vocab-mode-tabs { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.chip {
  padding: 8px 14px; background: var(--bg-elev); border-color: var(--line); color: var(--muted); font-size: .85rem;
}
.chip.active { background: rgba(245,158,11,.15); border-color: var(--accent); color: var(--accent); font-weight: 600; }

.flip-card {
  perspective: 1000px; height: 220px; margin-bottom: 14px; cursor: pointer;
}
.flip-inner {
  position: relative; width: 100%; height: 100%;
  transition: transform .45s; transform-style: preserve-3d;
}
.flip-card.flipped .flip-inner { transform: rotateY(180deg); }
.flip-face {
  position: absolute; inset: 0; backface-visibility: hidden;
  border-radius: var(--radius); border: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 20px; text-align: center; background: var(--bg-card);
}
.flip-face.back { transform: rotateY(180deg); background: linear-gradient(160deg, #1e293b, #0f172a); border-color: var(--accent-2); }
.flip-face .term { font-family: var(--display); font-size: 1.5rem; margin-bottom: 8px; }
.flip-face .hint { font-size: .8rem; color: var(--muted); }
.flip-face .def { font-size: 1.05rem; line-height: 1.5; }
.flip-nav { display: flex; justify-content: space-between; gap: 10px; align-items: center; }

.match-board { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 520px) { .match-board { grid-template-columns: 1fr; } }
.match-col { display: flex; flex-direction: column; gap: 8px; }
.match-btn {
  padding: 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg-elev); color: var(--text); font-family: inherit;
  cursor: pointer; text-align: left; font-size: .9rem;
}
.match-btn.selected { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(245,158,11,.25); }
.match-btn.matched { opacity: .45; border-color: var(--good); pointer-events: none; }
.match-btn.shake { animation: shake .35s; border-color: var(--bad); }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

/* Timeline */
.timeline-list { list-style: none; padding: 0; margin: 0 0 14px; display: flex; flex-direction: column; gap: 8px; }
.timeline-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; cursor: grab; user-select: none;
}
.timeline-item:active { cursor: grabbing; }
.timeline-item .grip { color: var(--muted); font-size: 1.1rem; letter-spacing: -2px; }
.timeline-item .t-text { flex: 1; font-size: .95rem; }
.timeline-item .t-move { display: flex; flex-direction: column; gap: 2px; }
.timeline-item .t-move button {
  background: var(--bg); border: 1px solid var(--line); color: var(--muted);
  border-radius: 6px; width: 28px; height: 22px; cursor: pointer; font-size: .7rem; padding: 0;
}
.timeline-item .t-move button:hover { color: var(--text); border-color: var(--accent-2); }
.timeline-item.correct-pos { border-color: var(--good); background: rgba(52,211,153,.08); }

/* Teach-back */
.timer-ring {
  width: 90px; height: 90px; margin: 0 auto 16px;
  border-radius: 50%; border: 4px solid var(--line);
  display: grid; place-items: center; font-family: var(--display); font-size: 1.6rem;
  position: relative;
}
.timer-ring.running { border-color: var(--accent); box-shadow: 0 0 20px rgba(245,158,11,.25); }
.timer-ring.done { border-color: var(--good); }
.teach-prompts { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.teach-prompts .prompt-card {
  padding: 12px 14px; background: var(--bg-elev); border-radius: 10px; border: 1px solid var(--line);
  font-size: .95rem;
}
.notes-area {
  width: 100%; min-height: 100px; padding: 12px; border-radius: 10px;
  background: var(--bg); border: 1px solid var(--line); color: var(--text);
  font-family: inherit; font-size: .95rem; resize: vertical;
}
.notes-area:focus { outline: none; border-color: var(--accent-2); }

.actions-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.complete-banner {
  text-align: center; padding: 24px; border-radius: var(--radius);
  background: linear-gradient(160deg, rgba(52,211,153,.15), rgba(56,189,248,.1));
  border: 1px solid rgba(52,211,153,.35); margin: 16px 0;
}
.complete-banner h2 { font-family: var(--display); margin: 0 0 8px; color: var(--good); }
.xp-pop { animation: pop .5s ease; }
@keyframes pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

.site-foot {
  text-align: center; padding: 24px 8px 8px; font-size: .72rem; color: var(--muted);
  border-top: 1px solid var(--line); margin-top: 32px;
}

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--bg-elev); border: 1px solid var(--accent);
  color: var(--text); padding: 12px 20px; border-radius: 999px;
  box-shadow: var(--shadow); z-index: 100; font-weight: 600; font-size: .9rem;
  animation: slideUp .3s ease;
}
@keyframes slideUp {
  from { opacity: 0; transform: translateX(-50%) translateY(12px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 90;
  display: grid; place-items: center; padding: 20px;
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--bg-card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 24px; max-width: 420px; width: 100%; box-shadow: var(--shadow);
}
.modal-card h2 { font-family: var(--display); margin: 0 0 10px; }
.modal-card #modal-body { color: var(--muted); margin-bottom: 16px; font-size: .95rem; }

.hidden { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
