:root {
  --bg: #f7f9fb;
  --panel: #ffffff;
  --panel-strong: #eef6fb;
  --text: #17212b;
  --muted: #5d6b78;
  --line: #d9e2ea;
  --accent: #007d9c;
  --accent-strong: #005f73;
  --topbar: #073642;
  --toc-text: #263542;
  --body-copy: #273746;
  --code-bg: #0f1720;
  --code-text: #dce7f2;
  --shadow: 0 14px 40px rgba(15, 23, 32, 0.12);
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d141b;
    --panel: #121d26;
    --panel-strong: #17313c;
    --text: #e5eef5;
    --muted: #9fb0be;
    --line: #263746;
    --accent: #00a6cc;
    --accent-strong: #66d9ef;
    --topbar: #06131a;
    --toc-text: #c7d4df;
    --body-copy: #d6e1ea;
    --code-bg: #080d12;
    --code-text: #e0edf6;
    --shadow: 0 18px 48px rgba(0, 0, 0, 0.38);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0d141b;
  --panel: #121d26;
  --panel-strong: #17313c;
  --text: #e5eef5;
  --muted: #9fb0be;
  --line: #263746;
  --accent: #00a6cc;
  --accent-strong: #66d9ef;
  --topbar: #06131a;
  --toc-text: #c7d4df;
  --body-copy: #d6e1ea;
  --code-bg: #080d12;
  --code-text: #e0edf6;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.38);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

a {
  color: inherit;
}
.hero[hidden],
.lesson[hidden] {
  display: none;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  padding: 0 22px;
  background: var(--topbar);
  color: white;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 32px;
  border-radius: 6px;
  background: #00add8;
  color: white;
  font-weight: 800;
  letter-spacing: 0;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 16px;
  line-height: 1.2;
}

.brand small {
  margin-top: 2px;
  color: rgba(255, 255, 255, 0.72);
  font-size: 12px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.ghost-link {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 6px;
  background: transparent;
  color: white;
  font-size: 14px;
  text-decoration: none;
}

.theme-toggle {
  font: inherit;
  cursor: pointer;
}

.shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  min-height: calc(100vh - 64px);
}

.sidebar {
  position: sticky;
  top: 64px;
  height: calc(100vh - 64px);
  overflow: auto;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
}

.toc {
  padding: 14px 12px 24px;
}

.toc-group {
  margin-bottom: 14px;
}

.toc-module {
  margin: 0 0 7px;
  padding: 0 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
}

.toc-link {
  display: block;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--toc-text);
  font-size: 14px;
  line-height: 1.35;
  text-decoration: none;
}

.toc-link:hover,
.toc-link.active {
  background: var(--panel-strong);
  color: var(--accent-strong);
}

.content {
  min-width: 0;
  padding: 42px clamp(18px, 5vw, 72px);
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 32px;
  align-items: center;
  max-width: 1080px;
  min-height: 360px;
}

.eyebrow {
  margin: 0 0 14px;
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 800;
}

.hero h1,
.lesson h1 {
  margin: 0;
  letter-spacing: 0;
}

.hero h1 {
  max-width: 720px;
  font-size: clamp(34px, 7vw, 64px);
  line-height: 1.04;
}

.lead {
  max-width: 680px;
  margin: 22px 0 0;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.7;
}

.hero-panel {
  display: grid;
  align-content: center;
  gap: 10px;
  min-height: 180px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.hero-panel span {
  color: var(--muted);
  font-size: 14px;
}

.hero-panel strong {
  color: var(--accent-strong);
  font-size: 28px;
}

.lesson {
  max-width: 940px;
}

.lesson-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.lesson-meta span {
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.lesson h1 {
  font-size: clamp(30px, 5vw, 46px);
  line-height: 1.12;
}

.english-title {
  margin: 10px 0 0;
  color: var(--muted);
}

.lesson-body {
  margin-top: 28px;
}

.inline-assets {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.inline-code {
  border: 1px solid #213141;
  border-radius: 8px;
}

.inline-image {
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.lesson-body p,
.source-card p {
  color: var(--body-copy);
  font-size: 17px;
  line-height: 1.8;
}

.source-card {
  margin-top: 24px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.source-card h2,
.files h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

.source-card a {
  color: var(--accent-strong);
  font-weight: 700;
}

.files {
  margin-top: 24px;
}

.file-card {
  overflow: hidden;
  margin-bottom: 18px;
  border: 1px solid #213141;
  border-radius: 8px;
  background: var(--code-bg);
}

.file-name {
  padding: 10px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  color: #a8dff0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

pre {
  margin: 0;
  overflow: auto;
  padding: 16px;
  background: var(--code-bg);
  color: var(--code-text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 14px;
  line-height: 1.6;
  tab-size: 4;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.lesson-nav {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 34px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

.nav-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  min-width: 112px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
}

.nav-button.primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.nav-button[aria-disabled="true"] {
  pointer-events: none;
  opacity: 0.45;
}

.icon-button {
  display: none;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.menu-button span {
  display: block;
  width: 20px;
  height: 2px;
  margin: 3px 0;
  background: currentColor;
}

.close-button {
  color: var(--text);
  font-size: 26px;
  line-height: 1;
}

.backdrop {
  display: none;
}

@media (max-width: 860px) {
  .topbar {
    padding: 0 12px;
  }

  .icon-button {
    display: grid;
  }

  .shell {
    display: block;
  }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 40;
    width: min(86vw, 340px);
    height: 100vh;
    transform: translateX(-105%);
    transition: transform 160ms ease;
    box-shadow: var(--shadow);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .backdrop.open {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 30;
    background: rgba(7, 20, 30, 0.45);
  }

  .content {
    padding: 28px 16px 42px;
  }

  .hero {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .hero-panel {
    min-height: 120px;
  }

  .brand small,
  .top-actions a {
    display: none;
  }

  .lesson-nav {
    flex-direction: column;
  }

  .nav-button {
    width: 100%;
  }
}
