:root {
  --bg: #f6f4ef;
  --panel: #ffffff;
  --panel-2: #fbfaf6;
  --ink: #1f2528;
  --muted: #6b7378;
  --line: #e3ded4;
  --accent: #b4552d;
  --accent-2: #2f6f6a;
  --accent-soft: #f2e2d8;
  --ok: #2f7d4f;
  --warn: #a66a12;
  --bad: #a13b3b;
  --shadow: 0 10px 30px rgba(31, 37, 40, .08);
  --radius: 14px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

[data-theme="dark"] {
  --bg: #171a1c;
  --panel: #202528;
  --panel-2: #1b2023;
  --ink: #eceae4;
  --muted: #9aa3a7;
  --line: #333b3f;
  --accent: #e08a5f;
  --accent-2: #73b9ae;
  --accent-soft: #3a2a22;
  --ok: #7bc49a;
  --warn: #e0b15f;
  --bad: #e08a8a;
  --shadow: 0 10px 30px rgba(0, 0, 0, .25);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent-2); }
code, pre, .mono { font-family: var(--mono); font-size: .92em; }
h1, h2, h3, h4 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: clamp(1.7rem, 1.2rem + 1.6vw, 2.6rem); letter-spacing: -.02em; }
h2 { font-size: 1.35rem; margin-top: 1.6em; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .9em; }
ul, ol { margin: 0 0 1em; padding-left: 1.35em; }
img { max-width: 100%; height: auto; }

.skip-link {
  position: absolute; left: -999px; top: 8px; z-index: 1000;
  background: var(--panel); padding: 8px 12px; border-radius: 8px;
}
.skip-link:focus { left: 8px; }

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  height: 62px; padding: 0 18px;
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px;
  display: grid; place-items: center;
  background: var(--accent); color: #fff; font-weight: 800; font-size: .8rem;
  letter-spacing: .02em;
}
.brand-title { font-weight: 700; letter-spacing: -.01em; }
.brand-sub { color: var(--muted); font-size: .78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  width: 36px; height: 36px; border-radius: 10px; cursor: pointer;
  display: grid; place-items: center; font-size: 1.1rem;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.icon-btn.small { width: 28px; height: 28px; font-size: .85rem; }
.progress-chip { display: flex; align-items: center; gap: 8px; font-size: .78rem; color: var(--muted); }
.progress-track { width: 90px; height: 7px; background: var(--line); border-radius: 999px; overflow: hidden; }
#progressBar { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .25s ease; }

.tabs {
  position: sticky; top: 62px; z-index: 30;
  display: flex; gap: 4px; padding: 0 14px;
  background: var(--bg); border-bottom: 1px solid var(--line);
  overflow-x: auto; scrollbar-width: thin;
}
.tabs::-webkit-scrollbar { height: 5px; }
.tabs::-webkit-scrollbar-thumb { background: var(--line); border-radius: 999px; }
.tab {
  appearance: none; border: 0; background: transparent; color: var(--muted);
  padding: 13px 12px 11px; cursor: pointer; white-space: nowrap;
  border-bottom: 2px solid transparent; font: inherit; font-size: .88rem;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--ink); border-bottom-color: var(--accent); font-weight: 650; }
.tab .badge { font-size: .68rem; margin-left: 5px; color: var(--muted); }
.tab.draft { opacity: .55; }

.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 286px;
  gap: 28px; max-width: 1240px; margin: 0 auto; padding: 24px 22px 80px;
  align-items: start;
}
.content { min-width: 0; max-width: 980px; padding: 26px 34px 90px; }

.app-shell {
  display: grid; grid-template-columns: 276px minmax(0, 1fr);
  max-width: 1440px; margin: 0 auto; align-items: start;
}
.leftnav {
  position: sticky; top: 62px; height: calc(100vh - 62px); overflow: auto;
  padding: 16px 12px 24px; border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 72%, var(--bg));
}
.leftnav-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 4px 10px; margin-bottom: 8px; border-bottom: 1px solid var(--line);
  color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .09em;
}
#leftnavClose { display: none; }
.leftnav-body { display: grid; gap: 4px; }
.leftnav-foot { color: var(--muted); font-size: .7rem; padding: 16px 6px 0; border-top: 1px solid var(--line); margin-top: 14px; }
.menu-btn { display: none; border: 0; background: transparent; color: var(--ink); font-size: 1.25rem; cursor: pointer; padding: 4px 6px; border-radius: 8px; }
.menu-btn:hover { background: var(--panel-2); }
.nav-group { border-radius: 10px; }
.nav-group + .nav-group { border-top: 1px solid var(--line); padding-top: 4px; }
.nav-head {
  width: 100%; border: 0; background: transparent; color: var(--ink);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 9px 8px; border-radius: 9px; cursor: pointer; font: inherit;
  font-size: .84rem; font-weight: 650; text-align: left;
}
.nav-head:hover { background: var(--panel-2); }
.nav-head .nav-badge { font-size: .64rem; font-weight: 500; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 1px 6px; }
.nav-head .arrow { color: var(--muted); font-size: .7rem; transition: transform .16s ease; }
.nav-group.open .nav-head .arrow { transform: rotate(180deg); }
.nav-body { display: grid; gap: 1px; padding: 0 0 6px 10px; margin-left: 8px; border-left: 1px solid var(--line); }
.nav-link {
  display: block; color: var(--ink); text-decoration: none; padding: 6px 8px;
  border-radius: 7px; font-size: .8rem;
}
.nav-link:hover { background: var(--panel-2); color: var(--accent); }
.nav-link.active { background: var(--accent-soft); color: var(--accent); font-weight: 650; }
.nav-sub { display: grid; gap: 1px; margin-left: 10px; padding-left: 8px; border-left: 1px dashed var(--line); }
.nav-sub .nav-link { font-size: .75rem; color: var(--muted); }
.nav-sub .nav-link:hover, .nav-sub .nav-link.active { color: var(--accent); }
.sidebar {
  position: sticky; top: 112px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px; max-height: calc(100vh - 132px); overflow: auto;
}
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: .74rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); padding: 2px 4px 10px; border-bottom: 1px solid var(--line);
}
#sidebarClose { display: none; }
.sidebar-nav { display: grid; gap: 2px; padding-top: 8px; }
.side-link {
  display: block; width: 100%; text-align: left; border: 0; background: transparent;
  color: var(--ink); padding: 7px 8px; border-radius: 8px; cursor: pointer;
  font: inherit; font-size: .84rem;
}
.side-link:hover { background: var(--panel-2); }
.side-link.active { background: var(--accent-soft); color: var(--accent); font-weight: 650; }
.sidebar-foot { border-top: 1px solid var(--line); margin-top: 10px; padding: 10px 4px 2px; font-size: .76rem; color: var(--muted); }
.sidebar-toggle { display: none; }
.layout.no-sidebar { grid-template-columns: minmax(0, 1fr); max-width: 1040px; }
.layout.no-sidebar .sidebar { display: none; }
.acc-item { border-radius: 9px; }
.acc-head {
  width: 100%; border: 0; background: transparent; color: var(--ink);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 9px 8px; cursor: pointer; font: inherit; font-size: .84rem; font-weight: 650;
  border-radius: 9px;
}
.acc-head:hover { background: var(--panel-2); }
.acc-arrow { color: var(--muted); transition: transform .16s ease; font-size: .75rem; }
.acc-item.open .acc-arrow { transform: rotate(180deg); }
.acc-body { display: grid; gap: 1px; padding: 0 0 4px 8px; border-left: 1px solid var(--line); margin-left: 12px; }
.check.inline-check { display: inline-flex; align-items: center; gap: 7px; background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 7px 11px; }
.check.inline-check input { margin: 0; }
.check.inline-check .check-id { display: none; }

.page-head { margin-bottom: 22px; }
.eyebrow { color: var(--accent); font-size: .74rem; text-transform: uppercase; letter-spacing: .09em; font-weight: 700; margin-bottom: 6px; }
.lead { font-size: 1.08rem; color: var(--muted); max-width: 70ch; }
.meta-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.meta-pill { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 4px 10px; font-size: .76rem; color: var(--muted); }
.meta-pill b { color: var(--ink); font-weight: 650; }

.section { scroll-margin-top: 126px; margin: 0 0 30px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.section-head h2 { margin: 0; }
.section-kicker { font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 15px; box-shadow: 0 1px 0 rgba(0,0,0,.02);
}
.card h3 { margin-bottom: 4px; font-size: .98rem; }
.card p { color: var(--muted); margin: 0; font-size: .9rem; }
.card .card-link { display: inline-block; margin-top: 9px; font-size: .82rem; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { text-align: left; padding: 9px 11px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--panel-2); font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
tr:last-child td { border-bottom: 0; }

.steps { display: grid; gap: 10px; counter-reset: step; }
.step { display: grid; grid-template-columns: 32px 1fr; gap: 12px; align-items: start; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 13px 15px; }
.step::before { counter-increment: step; content: counter(step); width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: .78rem; }
.step h3 { margin: 2px 0 3px; font-size: .95rem; }
.step p { margin: 0; color: var(--muted); font-size: .88rem; }

.checklist { display: grid; gap: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
.check {
  display: grid; grid-template-columns: 20px 1fr auto; gap: 10px; align-items: start;
  padding: 8px 9px; border-radius: 9px; cursor: pointer;
}
.check:hover { background: var(--panel-2); }
.check input { margin: 3px 0 0; accent-color: var(--accent); }
.check span { font-size: .9rem; }
.check.done span { color: var(--muted); text-decoration: line-through; text-decoration-thickness: 1px; }
.check .check-id { font-size: .7rem; color: var(--muted); font-family: var(--mono); }

.assignment { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: var(--radius); padding: 16px; }
.assignment h3 { margin-bottom: 6px; }
.assignment p { color: var(--muted); }
.link-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--ink); padding: 7px 11px; border-radius: 9px;
  text-decoration: none; font: inherit; font-size: .84rem; cursor: pointer;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.btn.danger { color: var(--bad); }

.artifacts { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 8px; }
.artifact { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 11px; text-decoration: none; color: var(--ink); font-size: .86rem; }
.artifact:hover { border-color: var(--accent); color: var(--accent); }
.artifact .type { font-size: .65rem; color: var(--muted); font-family: var(--mono); }

.prompt-list { display: grid; gap: 10px; }
.prompt-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.prompt-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.prompt-head h3 { margin: 0; font-size: .95rem; }
.prompt-tag { display: inline-block; margin-top: 3px; font-size: .68rem; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 1px 7px; }
.prompt-card pre { margin: 0; padding: 11px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px; white-space: pre-wrap; word-break: break-word; font-size: .8rem; line-height: 1.5; }
.visual-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.visual-card { margin: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; }
.visual-card a { display: block; }
.visual-card img { display: block; width: 100%; max-height: 320px; object-fit: contain; border-radius: 8px; background: var(--panel-2); }
.visual-card figcaption { font-size: .78rem; color: var(--muted); padding: 7px 3px 2px; }
.visual-card figcaption small { display: block; margin-top: 2px; }
.tool-embed { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.tool-embed-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.tool-embed-head b { display: block; font-size: .95rem; }
.tool-embed-head span { display: block; color: var(--muted); font-size: .8rem; margin-top: 2px; }
.tool-embed-badge { border: 1px solid var(--line); border-radius: 999px; padding: 2px 8px; color: var(--muted); font-size: .68rem; font-family: var(--mono); }
.tool-embed iframe { display: block; width: 100%; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.tool-embed .link-row { margin-top: 10px; }
.formula { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 15px; font-size: .92rem; }
.formula b { color: var(--accent); }
.muted { color: var(--muted); font-size: .86rem; }

.calculator { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.calc-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; }
.field { display: grid; gap: 4px; }
.field label { font-size: .76rem; color: var(--muted); }
.field input { width: 100%; border: 1px solid var(--line); background: var(--panel-2); color: var(--ink); border-radius: 9px; padding: 8px 10px; font: inherit; }
.field input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.calc-out { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-top: 14px; }
.calc-result { border: 1px solid var(--line); border-radius: 10px; padding: 10px 11px; background: var(--panel-2); }
.calc-result .label { font-size: .72rem; color: var(--muted); }
.calc-result .value { font-size: 1.15rem; font-weight: 700; margin-top: 2px; }
.calc-result.ok .value { color: var(--ok); }
.calc-result.warn .value { color: var(--warn); }
.calc-result.bad .value { color: var(--bad); }
.calc-note { margin-top: 10px; font-size: .78rem; color: var(--muted); }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin: 14px 0 20px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 13px; }
.stat .n { font-size: 1.45rem; font-weight: 750; letter-spacing: -.02em; }
.stat .l { font-size: .74rem; color: var(--muted); }

.lesson-card { display: flex; flex-direction: column; gap: 6px; }
.lesson-card .status { font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.lesson-card.locked { opacity: .6; }

.settings { display: grid; gap: 14px; max-width: 720px; }
.settings .card { display: grid; gap: 10px; }
.settings label { font-size: .84rem; }
.settings input[type="file"] { font-size: .8rem; }

.search-modal { position: fixed; inset: 0; z-index: 100; background: rgba(20,23,25,.55); display: grid; place-items: start center; padding: 12vh 16px 16px; }
.search-modal[hidden] { display: none; }
.search-box { width: min(680px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 12px; }
.search-box input { width: 100%; border: 1px solid var(--line); background: var(--panel-2); color: var(--ink); border-radius: 10px; padding: 11px 12px; font: inherit; }
.search-results { display: grid; gap: 4px; margin-top: 8px; max-height: 50vh; overflow: auto; }
.search-item { display: block; width: 100%; text-align: left; border: 0; background: transparent; color: var(--ink); padding: 9px 10px; border-radius: 9px; cursor: pointer; font: inherit; }
.search-item:hover, .search-item.active { background: var(--accent-soft); }
.search-item small { display: block; color: var(--muted); }
.search-hint { font-size: .72rem; color: var(--muted); padding: 8px 4px 0; }

.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none; background: var(--ink); color: var(--bg); padding: 9px 14px; border-radius: 999px; font-size: .82rem; transition: .2s ease; z-index: 120; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 1080px) {
  .app-shell { display: block; }
  .leftnav {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 90;
    width: min(340px, 88vw); height: 100vh; border-right: 1px solid var(--line);
    transform: translateX(-105%); transition: transform .22s ease;
    box-shadow: var(--shadow);
  }
  .leftnav.open { transform: translateX(0); }
  #leftnavClose { display: grid; }
  .menu-btn { display: inline-grid; place-items: center; }
  .content { max-width: none; padding: 20px 16px 90px; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; top: 0; right: 0; bottom: 0; z-index: 80;
    width: min(340px, 88vw); max-height: none; border-radius: 16px 0 0 16px;
    transform: translateX(105%); transition: transform .22s ease;
  }
  .sidebar.open { transform: translateX(0); }
  #sidebarClose { display: grid; }
  .sidebar-toggle {
    display: inline-flex; position: fixed; right: 16px; bottom: 18px; z-index: 70;
    border: 1px solid var(--line); background: var(--panel); color: var(--ink);
    padding: 9px 13px; border-radius: 999px; box-shadow: var(--shadow); cursor: pointer; font: inherit; font-size: .82rem;
  }
}

@media (max-width: 640px) {
  .topbar { height: 56px; padding: 0 12px; }
  .brand-sub { display: none; }
  .tabs { top: 56px; padding: 0 8px; }
  .layout { padding: 18px 12px 80px; }
  .progress-chip .progress-track { width: 56px; }
  .meta-row { gap: 6px; }
  .section-head { flex-direction: column; align-items: flex-start; gap: 2px; }
}

@media print {
  .topbar, .tabs, .sidebar, .sidebar-toggle, .search-modal, .toast, .link-row, .btn { display: none !important; }
  .layout { display: block; padding: 0; max-width: none; }
  .content { max-width: none; }
  body { background: #fff; color: #000; }
  .card, .table-wrap, .assignment, .checklist, .calculator { box-shadow: none; break-inside: avoid; }
}
