:root {
  --ink: #111827;
  --ink-2: #1f2937;
  --muted: #64748b;
  --paper: #f7f7fb;
  --panel: #ffffff;
  --line: #dfe4ec;
  --soft: #eef2f8;
  --rose: #e11d48;
  --rose-soft: #fff1f2;
  --teal: #0f766e;
  --teal-soft: #ccfbf1;
  --amber: #b45309;
  --amber-soft: #fef3c7;
  --blue: #1d4ed8;
  --blue-soft: #dbeafe;
  --sidebar: #111827;
  --sidebar-2: #1b2434;
  --shadow: 0 18px 50px rgba(15, 23, 42, .08);
  --radius: 18px;
}

[data-theme="night"] {
  --ink: #f8fafc;
  --ink-2: #e2e8f0;
  --muted: #9aa9bc;
  --paper: #090e18;
  --panel: #111827;
  --line: #263244;
  --soft: #182234;
  --rose: #fb7185;
  --rose-soft: #3a1721;
  --teal: #5eead4;
  --teal-soft: #103a38;
  --amber: #fbbf24;
  --amber-soft: #3c2b10;
  --blue: #93c5fd;
  --blue-soft: #172e52;
  --sidebar: #050914;
  --sidebar-2: #111827;
  --shadow: 0 18px 50px rgba(0, 0, 0, .24);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.65;
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
a { color: var(--blue); }
.skip-link { position: fixed; left: 1rem; top: -5rem; z-index: 100; background: white; color: #111827; padding: .75rem 1rem; border-radius: 10px; }
.skip-link:focus { top: 1rem; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 310px minmax(0, 1fr); }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  color: #dbe4f0;
  background:
    radial-gradient(circle at 18% 12%, rgba(251,113,133,.16), transparent 28%),
    radial-gradient(circle at 82% 84%, rgba(45,212,191,.12), transparent 30%),
    var(--sidebar);
  padding: 1.4rem 1.05rem 1.25rem;
  scrollbar-width: thin;
  scrollbar-color: #38455a transparent;
}
.brand { display: flex; gap: .8rem; align-items: center; padding: .2rem .35rem 1.15rem; }
.brand-mark { width: 44px; height: 44px; border-radius: 13px; display: grid; place-items: center; font-weight: 900; font-size: 1.3rem; background: #fb7185; color: #111827; box-shadow: inset 0 -5px 15px rgba(0,0,0,.12); }
.brand-mark span { color: #0f766e; }
.brand strong { display: block; color: white; letter-spacing: -.01em; }
.brand small { color: #93a4ba; display: block; font-size: .78rem; }

.course-progress { background: rgba(255,255,255,.065); border: 1px solid rgba(255,255,255,.08); padding: .85rem; border-radius: 14px; margin-bottom: 1rem; }
.progress-row { display: flex; justify-content: space-between; font-size: .77rem; color: #aebbd0; }
.progress-row strong { color: white; }
.progress-track { height: 6px; margin-top: .55rem; background: #2b3648; border-radius: 99px; overflow: hidden; }
.progress-track span { display: block; width: 0; height: 100%; background: linear-gradient(90deg, #fb7185, #2dd4bf); transition: width .35s ease; }

.chapter-nav { display: grid; gap: .24rem; }
.nav-group-label { padding: .75rem .7rem .3rem; color: #73829a; font-size: .66rem; font-weight: 800; text-transform: uppercase; letter-spacing: .13em; }
.chapter-link { width: 100%; display: grid; grid-template-columns: 29px 1fr 18px; align-items: center; gap: .55rem; text-align: left; border: 0; border-radius: 11px; padding: .62rem .65rem; color: #b7c2d3; background: transparent; transition: .18s ease; }
.chapter-link:hover { background: rgba(255,255,255,.07); color: white; }
.chapter-link.active { background: rgba(251,113,133,.14); color: white; box-shadow: inset 3px 0 #fb7185; }
.chapter-number { display: grid; place-items: center; width: 27px; height: 27px; border: 1px solid #3a4659; border-radius: 9px; color: #8fa0b7; font-size: .72rem; font-weight: 750; }
.chapter-link.active .chapter-number { background: #fb7185; color: #111827; border-color: #fb7185; }
.chapter-title { line-height: 1.22; font-size: .84rem; font-weight: 620; }
.chapter-check { color: #5eead4; font-weight: 900; }
.sidebar-note { margin: 1rem .2rem 0; border-top: 1px solid rgba(255,255,255,.08); padding: 1rem .5rem 0; }
.sidebar-note .eyebrow { color: #5eead4; }
.sidebar-note p { font-size: .77rem; color: #8fa0b7; line-height: 1.5; margin: .35rem 0 0; }

.main-column { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 10; min-height: 66px; display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .75rem clamp(1rem, 3vw, 2.5rem); border-bottom: 1px solid color-mix(in srgb, var(--line), transparent 10%); background: color-mix(in srgb, var(--paper), transparent 10%); backdrop-filter: blur(14px); }
.breadcrumb { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-weight: 730; letter-spacing: -.015em; }
.top-actions { display: flex; align-items: center; gap: .6rem; }
.mode-switch { display: flex; padding: .25rem; background: var(--soft); border: 1px solid var(--line); border-radius: 12px; }
.mode-switch button { border: 0; background: transparent; color: var(--muted); border-radius: 8px; padding: .38rem .75rem; font-size: .82rem; font-weight: 750; }
.mode-switch button.active { background: var(--panel); color: var(--ink); box-shadow: 0 2px 7px rgba(15,23,42,.1); }
.icon-button { width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); color: var(--ink); background: var(--panel); }
.menu-button { display: none; }

.lesson { width: min(100%, 1040px); margin: 0 auto; padding: clamp(1.6rem, 4vw, 4rem) clamp(1rem, 4vw, 3.2rem) 3rem; }
.lesson-hero { position: relative; overflow: hidden; background: var(--ink); color: var(--paper); border-radius: 26px; padding: clamp(1.5rem, 4vw, 3.3rem); box-shadow: var(--shadow); }
.lesson-hero::after { content: ""; position: absolute; width: 260px; height: 260px; right: -100px; top: -110px; border: 55px solid rgba(45,212,191,.12); border-radius: 50%; }
.lesson-hero::before { content: ""; position: absolute; width: 190px; height: 190px; right: 100px; bottom: -150px; border: 40px solid rgba(251,113,133,.14); border-radius: 50%; }
.lesson-hero > * { position: relative; z-index: 1; }
.eyebrow { font-size: .74rem; line-height: 1.2; font-weight: 850; text-transform: uppercase; letter-spacing: .13em; color: #fb7185; }
.lesson-hero h1 { max-width: 780px; font-size: clamp(2rem, 5vw, 4rem); line-height: 1.04; letter-spacing: -.05em; margin: .75rem 0 1rem; }
.lesson-hero p { max-width: 740px; font-size: clamp(1rem, 1.7vw, 1.18rem); color: color-mix(in srgb, var(--paper), transparent 20%); margin: 0; }
.hero-meta { display: flex; flex-wrap: wrap; gap: .65rem; margin-top: 1.5rem; }
.hero-chip { padding: .42rem .72rem; border: 1px solid rgba(255,255,255,.14); background: rgba(255,255,255,.07); border-radius: 999px; font-size: .76rem; }

.lesson-body { padding-top: 2.3rem; }
.lesson-body h2 { font-size: clamp(1.45rem, 3vw, 2rem); line-height: 1.2; letter-spacing: -.035em; margin: 2.6rem 0 .8rem; }
.lesson-body h3 { font-size: 1.15rem; line-height: 1.3; margin: 1.9rem 0 .5rem; }
.lesson-body p { margin: .65rem 0 1rem; }
.lesson-body ul, .lesson-body ol { padding-left: 1.25rem; }
.lesson-body li { margin: .45rem 0; }
.lead { font-size: 1.12rem; color: var(--ink-2); }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.nowrap { white-space: nowrap; }

.concept-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 1rem; margin: 1.15rem 0; }
.concept-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.15rem; box-shadow: 0 8px 26px rgba(15,23,42,.035); }
.concept-card h3, .concept-card h4 { margin: .1rem 0 .45rem; line-height: 1.25; }
.concept-card p:last-child { margin-bottom: 0; }
.concept-card.accent { border-top: 4px solid var(--rose); }
.concept-icon { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 11px; margin-bottom: .75rem; background: var(--rose-soft); color: var(--rose); font-size: 1.1rem; font-weight: 900; }

.callout { margin: 1.2rem 0; padding: 1rem 1.1rem; border-left: 4px solid var(--teal); background: var(--teal-soft); border-radius: 0 14px 14px 0; color: var(--ink); }
.callout strong { display: block; margin-bottom: .25rem; }
.callout.warning { border-color: var(--amber); background: var(--amber-soft); }
.callout.rose { border-color: var(--rose); background: var(--rose-soft); }

.data-table-wrap { overflow-x: auto; margin: 1rem 0; border: 1px solid var(--line); border-radius: 15px; background: var(--panel); }
table { width: 100%; border-collapse: collapse; min-width: 650px; }
th, td { text-align: left; vertical-align: top; padding: .78rem .85rem; border-bottom: 1px solid var(--line); }
th { background: var(--soft); font-size: .76rem; text-transform: uppercase; letter-spacing: .07em; }
tr:last-child td { border-bottom: 0; }

.learning-tool { margin: 1.6rem 0; border: 1px solid var(--line); background: var(--panel); border-radius: 20px; overflow: hidden; box-shadow: var(--shadow); }
.tool-header { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; padding: 1.05rem 1.2rem; background: var(--ink); color: var(--paper); }
.tool-header h3 { margin: 0; font-size: 1rem; }
.tool-header p { margin: .2rem 0 0; font-size: .8rem; opacity: .72; }
.tool-badge { flex: none; font-size: .68rem; font-weight: 850; text-transform: uppercase; letter-spacing: .1em; padding: .35rem .55rem; color: #111827; background: #5eead4; border-radius: 7px; }
.tool-body { padding: 1.2rem; }
.tool-body label { display: block; font-weight: 700; margin: .75rem 0 .35rem; }
textarea, input[type="text"], select { width: 100%; border: 1px solid var(--line); background: var(--paper); color: var(--ink); padding: .75rem .82rem; border-radius: 11px; }
textarea { min-height: 140px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; line-height: 1.5; }
textarea:focus, input:focus, select:focus, button:focus-visible { outline: 3px solid color-mix(in srgb, var(--blue), transparent 65%); outline-offset: 2px; }
.button-row { display: flex; flex-wrap: wrap; gap: .65rem; margin-top: 1rem; }
.primary-button, .secondary-button, .ghost-button { border-radius: 11px; padding: .68rem 1rem; font-weight: 780; border: 1px solid transparent; }
.primary-button { background: var(--rose); color: white; }
.secondary-button { background: var(--panel); color: var(--ink); border-color: var(--line); }
.ghost-button { background: var(--soft); color: var(--ink); }
.primary-button:disabled, .secondary-button:disabled { opacity: .45; cursor: not-allowed; }
.tool-result { display: none; margin-top: 1rem; padding: .9rem; border-radius: 12px; background: var(--soft); border: 1px solid var(--line); }
.tool-result.show { display: block; }
.answer-good { color: var(--teal); font-weight: 800; }
.answer-bad { color: var(--rose); font-weight: 800; }

.mini-chart { display: grid; gap: .65rem; margin: 1rem 0; }
.bar-row { display: grid; grid-template-columns: minmax(105px, .55fr) 2fr 45px; align-items: center; gap: .7rem; font-size: .86rem; }
.bar-track { height: 12px; background: var(--soft); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; width: var(--value); background: linear-gradient(90deg, var(--rose), #fb923c); border-radius: inherit; transition: width .35s ease; }

.code-block { position: relative; overflow-x: auto; padding: 1rem; background: #0b1220; color: #d8e2f0; border: 1px solid #243047; border-radius: 14px; font: .86rem/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre; }
.code-key { color: #f472b6; }
.code-str { color: #5eead4; }
.code-num { color: #fbbf24; }

.timeline { display: grid; grid-template-columns: 40px 1fr; gap: 0 .8rem; margin: 1rem 0; }
.timeline-marker { display: grid; justify-items: center; }
.timeline-dot { width: 15px; height: 15px; margin-top: .3rem; border: 4px solid var(--rose); background: var(--panel); border-radius: 50%; }
.timeline-line { width: 2px; min-height: 45px; background: var(--line); }
.timeline-content { padding-bottom: 1.25rem; }
.timeline-content h3 { margin: 0 0 .25rem; }

.summary-box { margin-top: 2.3rem; padding: clamp(1.2rem, 3vw, 2rem); background: var(--ink); color: var(--paper); border-radius: 20px; }
.summary-box h2 { margin: 0 0 .8rem; color: #5eead4; }
.summary-box li { margin: .45rem 0; }
.summary-box .memory-line { margin-top: 1.1rem; padding: .8rem 1rem; border: 1px solid rgba(255,255,255,.15); border-radius: 12px; background: rgba(255,255,255,.06); }

.revision-sheet { display: grid; gap: 1rem; }
.revision-card { background: var(--panel); border: 1px solid var(--line); border-left: 5px solid var(--rose); border-radius: 15px; padding: 1rem 1.1rem; }
.revision-card h3 { margin: 0 0 .45rem; }
.revision-card ul { margin: 0; }

.completion-card { display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; justify-content: space-between; margin-top: 1.5rem; padding: 1.1rem; border: 1px dashed var(--teal); border-radius: 16px; background: var(--teal-soft); }
.completion-card strong { display: block; }
.completion-card p { margin: .15rem 0 0; font-size: .86rem; color: var(--muted); }
.complete-button.completed { background: var(--teal); }

.flashcard { min-height: 190px; display: grid; place-items: center; padding: 1.5rem; border: 1px solid var(--line); border-radius: 17px; background: var(--paper); text-align: center; }
.flashcard-question { font-size: 1.3rem; font-weight: 820; line-height: 1.35; }
.flashcard-answer { display: none; color: var(--ink-2); }
.flashcard.revealed .flashcard-question { display: none; }
.flashcard.revealed .flashcard-answer { display: block; }

.check-list { display: grid; gap: .6rem; }
.check-item { display: flex; align-items: flex-start; gap: .65rem; padding: .7rem; border: 1px solid var(--line); background: var(--paper); border-radius: 11px; }
.check-item input { margin-top: .3rem; width: 18px; height: 18px; accent-color: var(--rose); }

.lesson-footer { width: min(100%, 1040px); margin: 0 auto; padding: 1rem clamp(1rem, 4vw, 3.2rem) 3rem; display: grid; grid-template-columns: 1fr auto 1fr; gap: 1rem; align-items: center; }
.lesson-footer .primary-button { justify-self: end; }
.footer-center { color: var(--muted); font-size: .82rem; text-align: center; }
.toast { position: fixed; z-index: 50; right: 1rem; bottom: 1rem; max-width: min(360px, calc(100vw - 2rem)); transform: translateY(30px); opacity: 0; pointer-events: none; padding: .85rem 1rem; background: var(--ink); color: var(--paper); border-radius: 12px; box-shadow: var(--shadow); transition: .22s ease; }
.toast.show { opacity: 1; transform: translateY(0); }
.mobile-scrim { display: none; }
.only-learn { display: block; }
body.revision-mode .only-learn { display: none; }
body.revision-mode .lesson-body { padding-top: 1.5rem; }

@media (max-width: 920px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 30; inset: 0 auto 0 0; width: min(86vw, 320px); transform: translateX(-105%); transition: transform .25s ease; box-shadow: 18px 0 50px rgba(0,0,0,.25); }
  .sidebar.open { transform: translateX(0); }
  .mobile-scrim { position: fixed; z-index: 20; inset: 0; background: rgba(3,7,18,.55); }
  .mobile-scrim.show { display: block; }
  .menu-button { display: inline-grid; place-items: center; }
  .topbar { padding-inline: 1rem; }
  .lesson { padding-top: 1.25rem; }
}

@media (max-width: 640px) {
  .concept-grid { grid-template-columns: 1fr; }
  .lesson-hero { border-radius: 18px; padding: 1.35rem; }
  .lesson-hero h1 { font-size: 2.25rem; }
  .breadcrumb { display: none; }
  .topbar { justify-content: space-between; }
  .mode-switch button { padding-inline: .6rem; }
  .lesson-footer { grid-template-columns: 1fr 1fr; }
  .footer-center { display: none; }
  .bar-row { grid-template-columns: 95px 1fr 38px; font-size: .78rem; }
  .tool-header { display: block; }
  .tool-badge { display: inline-block; margin-top: .65rem; }
}

@media print {
  .sidebar, .topbar, .lesson-footer, .completion-card, .tool-header .tool-badge, .button-row { display: none !important; }
  .app-shell { display: block; }
  .lesson { width: 100%; max-width: none; padding: 0; }
  .only-learn { display: block !important; }
  .lesson-hero, .summary-box { color: black; background: white; border: 2px solid #222; box-shadow: none; }
  .learning-tool, .concept-card { box-shadow: none; break-inside: avoid; }
}

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