:root {
  color-scheme: light;
  --bg: #eef2f7;
  --panel: #ffffff;
  --panel-soft: #f6f8fb;
  --sidebar: #0d1424;
  --sidebar-soft: #151f34;
  --text: #172033;
  --muted: #667085;
  --border: #dce2ea;
  --accent: #137f75;
  --accent-strong: #09645d;
  --accent-soft: #ddf5f0;
  --sidebar-text: #f5f7fb;
  --sidebar-muted: #9eabc0;
  --warning: #a9660d;
  --shadow: 0 18px 55px rgba(31, 44, 72, 0.09);
  --reader-size: 18px;
  --reader-width: 790px;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #090f1b;
  --panel: #111a2a;
  --panel-soft: #162134;
  --text: #e9eef7;
  --muted: #9ca9bd;
  --border: #27344a;
  --accent: #65d1c2;
  --accent-strong: #83e2d5;
  --accent-soft: #153c3a;
  --shadow: 0 18px 55px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }
button { color: inherit; }

.reading-progress {
  position: fixed;
  inset: 0 0 auto 0;
  height: 3px;
  z-index: 100;
  background: transparent;
}

.reading-progress span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #4fc7b6, #7dd8cb);
  transition: width 100ms linear;
}

.app-shell { min-height: 100vh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 50;
  width: 332px;
  display: flex;
  flex-direction: column;
  padding: 22px 18px 18px;
  overflow: hidden;
  color: var(--sidebar-text);
  background:
    radial-gradient(circle at 12% -10%, rgba(101, 209, 194, 0.18), transparent 31%),
    var(--sidebar);
  border-right: 1px solid rgba(255,255,255,0.06);
}

.brand {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 2px 4px 18px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  color: #071613;
  background: #73d8ca;
  font-family: Georgia, serif;
  font-size: 22px;
  font-weight: 800;
}

.brand strong, .brand span { display: block; }
.brand strong { font-size: 15px; letter-spacing: 0.01em; }
.brand span { margin-top: 3px; color: var(--sidebar-muted); font-size: 13px; }

.icon-btn, .text-btn {
  min-width: 40px;
  height: 40px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--panel);
  cursor: pointer;
}

.icon-btn:hover, .text-btn:hover { border-color: var(--accent); }
.close-sidebar { display: none; }

.sidebar-progress {
  padding: 14px;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  background: rgba(255,255,255,0.045);
}

.progress-copy {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--sidebar-muted);
  font-size: 13px;
}

.progress-copy strong { color: var(--sidebar-text); font-size: 13px; }

.progress-track {
  height: 6px;
  margin-top: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255,255,255,0.09);
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: #6ed5c6;
  transition: width 240ms ease;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 9px;
  height: 43px;
  margin: 16px 0 12px;
  padding: 0 12px;
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 12px;
  color: var(--sidebar-muted);
  background: rgba(255,255,255,0.045);
}

.search-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  color: var(--sidebar-text);
  background: transparent;
  font-size: 14px;
}

.search-box input::placeholder { color: #77859b; }

.lesson-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 2px 2px 14px;
  scrollbar-width: thin;
  scrollbar-color: #35435b transparent;
}

.lesson-item {
  width: 100%;
  display: grid;
  grid-template-columns: 32px 1fr 24px;
  align-items: center;
  gap: 10px;
  padding: 11px 10px;
  border: 1px solid transparent;
  border-radius: 13px;
  color: var(--sidebar-text);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.lesson-item + .lesson-item { margin-top: 4px; }
.lesson-item:hover { background: rgba(255,255,255,0.05); }
.lesson-item.active { border-color: rgba(116,216,202,0.28); background: rgba(101,209,194,0.11); }

.lesson-number {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  color: var(--sidebar-muted);
  background: rgba(255,255,255,0.06);
  font-size: 13px;
  font-weight: 750;
}

.lesson-item.active .lesson-number { color: #071613; background: #73d8ca; }
.lesson-copy { min-width: 0; }
.lesson-copy strong, .lesson-copy span { display: block; }
.lesson-copy strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; line-height: 1.35; }
.lesson-copy span { margin-top: 3px; color: var(--sidebar-muted); font-size: 12px; }
.status-dot { color: #5e6b80; font-size: 17px; text-align: center; }
.status-dot.complete { color: #70dbc9; }

.sidebar-empty { padding: 24px 12px; color: var(--sidebar-muted); font-size: 14px; text-align: center; }

.sidebar-note {
  padding: 13px 14px;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.sidebar-note span, .sidebar-note strong { display: block; }
.sidebar-note span { color: var(--sidebar-muted); font-size: 12px; }
.sidebar-note strong { margin-top: 4px; font-size: 13px; }

.main-panel { min-height: 100vh; margin-left: 332px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: 72px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 28px;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 72%, transparent);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(16px);
}

.menu-btn { display: none; }
.current-label { flex: 1; min-width: 0; }
.current-label span, .current-label strong { display: block; }
.current-label span { color: var(--accent); font-size: 12px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.current-label strong { max-width: 620px; margin-top: 3px; overflow: hidden; color: var(--text); font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.toolbar { display: flex; gap: 8px; }
.toolbar .icon-btn, .toolbar .text-btn { background: var(--panel); }
.text-btn { font-family: Georgia, serif; font-weight: 700; }

.reader-wrap { width: min(100%, calc(var(--reader-width) + 64px)); margin: 0 auto; padding: 36px 32px 52px; }

.reader-card {
  min-height: calc(100vh - 150px);
  padding: clamp(28px, 5vw, 58px);
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--panel);
  box-shadow: var(--shadow);
  outline: none;
}

.lesson-header { margin-bottom: 34px; padding-bottom: 28px; border-bottom: 1px solid var(--border); }
.eyebrow { color: var(--accent); font-size: 13px; font-weight: 850; letter-spacing: .1em; text-transform: uppercase; }
.lesson-header h1 { max-width: 720px; margin: 10px 0 15px; font-family: Georgia, "Times New Roman", serif; font-size: clamp(34px, 5vw, 54px); line-height: 1.08; letter-spacing: -.025em; }
.lesson-meta { display: flex; flex-wrap: wrap; gap: 8px; }
.meta-chip { padding: 6px 10px; border-radius: 999px; color: var(--muted); background: var(--panel-soft); font-size: 13px; }

.reader-body { font-family: Georgia, "Times New Roman", serif; font-size: var(--reader-size); line-height: 1.78; }
.reader-body > *:first-child { margin-top: 0; }
.reader-body h2, .reader-body h3 { color: var(--text); font-family: Inter, ui-sans-serif, system-ui, sans-serif; letter-spacing: -.02em; }
.reader-body h2 { margin: 2.25em 0 .7em; font-size: 1.5em; line-height: 1.25; }
.reader-body h3 { margin: 1.75em 0 .55em; font-size: 1.17em; line-height: 1.35; }
.reader-body p { margin: 0 0 1.15em; }
.reader-body ul, .reader-body ol { margin: .45em 0 1.25em; padding-left: 1.35em; }
.reader-body li { margin: .42em 0; padding-left: .25em; }
.reader-body strong { color: color-mix(in srgb, var(--text) 90%, var(--accent)); }
.reader-body a { color: var(--accent-strong); text-decoration-thickness: 1px; text-underline-offset: 3px; }
.reader-body blockquote { margin: 1.5em 0; padding: 15px 18px; border-left: 4px solid var(--accent); border-radius: 0 12px 12px 0; color: var(--text); background: var(--accent-soft); }
.reader-body blockquote p { margin: 0; }
.reader-body hr { margin: 2.4em 0; border: 0; border-top: 1px solid var(--border); }
.reader-body code { padding: .12em .35em; border-radius: 5px; background: var(--panel-soft); font: .9em ui-monospace, SFMono-Regular, Consolas, monospace; }
.reader-body table { width: 100%; margin: 1.4em 0; border-collapse: collapse; font-family: Inter, ui-sans-serif, system-ui, sans-serif; font-size: .88em; }
.reader-body th, .reader-body td { padding: 11px 12px; border: 1px solid var(--border); text-align: left; vertical-align: top; }
.reader-body th { background: var(--panel-soft); }

.completion-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-top: 38px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: var(--panel-soft);
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
}
.completion-card span, .completion-card strong { display: block; }
.completion-card span { margin-top: 3px; color: var(--muted); font-size: 13px; }
.complete-btn { flex: 0 0 auto; min-height: 42px; padding: 0 16px; border: 0; border-radius: 11px; color: #fff; background: var(--accent-strong); font-weight: 750; cursor: pointer; }
.complete-btn.done { color: var(--accent-strong); background: var(--accent-soft); }

.lesson-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 18px; }
.nav-btn { min-height: 82px; padding: 15px 17px; border: 1px solid var(--border); border-radius: 15px; background: var(--panel); text-align: left; cursor: pointer; }
.nav-btn.next { text-align: right; }
.nav-btn:hover:not(:disabled) { border-color: var(--accent); }
.nav-btn:disabled { opacity: .4; cursor: default; }
.nav-btn span, .nav-btn strong { display: block; }
.nav-btn span { color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.nav-btn strong { margin-top: 5px; overflow: hidden; font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }

.loading-state, .error-state { padding: 60px 20px; color: var(--muted); text-align: center; }
.error-state strong { display: block; margin-bottom: 7px; color: var(--text); }

.scrim { display: none; }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 90; max-width: 310px; padding: 12px 15px; border-radius: 11px; color: #fff; background: #111a2e; box-shadow: 0 12px 36px rgba(0,0,0,.2); font-size: 14px; opacity: 0; pointer-events: none; transform: translateY(10px); transition: .2s ease; }
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 900px) {
  .sidebar { width: min(88vw, 350px); transform: translateX(-102%); transition: transform 220ms ease; }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .close-sidebar { display: inline-grid; place-items: center; border-color: rgba(255,255,255,.12); color: var(--sidebar-text); background: rgba(255,255,255,.05); }
  .scrim { position: fixed; inset: 0; z-index: 40; display: block; border: 0; background: rgba(3,8,17,.55); opacity: 0; pointer-events: none; transition: opacity 220ms ease; }
  body.sidebar-open .scrim { opacity: 1; pointer-events: auto; }
  .main-panel { margin-left: 0; }
  .menu-btn { display: inline-grid; place-items: center; }
  .topbar { height: 66px; padding: 0 14px; }
  .reader-wrap { padding: 18px 14px 36px; }
  .reader-card { min-height: calc(100vh - 112px); padding: 28px 20px 32px; border-radius: 17px; }
  .lesson-header h1 { font-size: clamp(31px, 10vw, 45px); }
}

@media (max-width: 560px) {
  .current-label strong { max-width: 46vw; }
  .reader-body { line-height: 1.72; }
  .lesson-nav { grid-template-columns: 1fr; }
  .nav-btn.next { text-align: left; }
  .completion-card { align-items: stretch; flex-direction: column; }
  .complete-btn { width: 100%; }
}

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