:root {
  color-scheme: dark;
  --bg: #0d1117;
  --bg-elevated: #111821;
  --surface: #151e29;
  --surface-2: #1a2532;
  --surface-3: #202d3b;
  --text: #edf3f7;
  --muted: #9eabb8;
  --faint: #6e7b88;
  --line: rgba(255, 255, 255, 0.09);
  --accent: #77dcc4;
  --accent-strong: #a7f2dd;
  --accent-soft: rgba(119, 220, 196, 0.12);
  --gold: #e1c17a;
  --gold-soft: rgba(225, 193, 122, 0.12);
  --danger: #ff8f8f;
  --danger-soft: rgba(255, 143, 143, 0.12);
  --warning: #f4c66c;
  --warning-soft: rgba(244, 198, 108, 0.12);
  --good: #79d59b;
  --good-soft: rgba(121, 213, 155, 0.12);
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.32);
  --radius-xl: 26px;
  --radius-lg: 18px;
  --radius-md: 13px;
  --sidebar-width: 282px;
  --font: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP", sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f1f3f4;
  --bg-elevated: #fafbfb;
  --surface: #ffffff;
  --surface-2: #f5f7f7;
  --surface-3: #eaf0ef;
  --text: #172026;
  --muted: #5d6b73;
  --faint: #89949a;
  --line: rgba(20, 40, 45, 0.11);
  --accent: #167c68;
  --accent-strong: #0b5e4e;
  --accent-soft: rgba(22, 124, 104, 0.09);
  --gold: #9a7019;
  --gold-soft: rgba(154, 112, 25, 0.09);
  --danger: #b63f4b;
  --danger-soft: rgba(182, 63, 75, 0.09);
  --warning: #9d6500;
  --warning-soft: rgba(157, 101, 0, 0.09);
  --good: #19713c;
  --good-soft: rgba(25, 113, 60, 0.09);
  --shadow: 0 18px 45px rgba(31, 48, 50, 0.12);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 70% -10%, rgba(119, 220, 196, 0.09), transparent 34rem),
    radial-gradient(circle at 10% 90%, rgba(225, 193, 122, 0.06), transparent 30rem),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.65;
}
button, input, textarea, select { font: inherit; }
button { color: inherit; }
a { color: var(--accent-strong); }
img { max-width: 100%; }
.nowrap { white-space: nowrap; }
::selection { background: var(--accent); color: #07110f; }

.skip-link {
  position: fixed;
  left: 16px;
  top: -100px;
  z-index: 1000;
  padding: 10px 16px;
  border-radius: 9px;
  background: var(--accent);
  color: #07110f;
  font-weight: 800;
}
.skip-link:focus { top: 16px; }

.app-shell { min-height: 100vh; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  display: flex;
  width: var(--sidebar-width);
  flex-direction: column;
  padding: 24px 18px 18px;
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg-elevated) 92%, transparent);
  backdrop-filter: blur(20px);
}
.brand { display: flex; gap: 13px; align-items: flex-start; padding: 6px 8px 26px; }
.brand-mark {
  display: grid;
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
  border-radius: 15px;
  background: linear-gradient(145deg, var(--accent-soft), var(--gold-soft));
  color: var(--accent-strong);
  font-weight: 900;
  font-size: 21px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.03);
}
.brand h1 { margin: 1px 0 0; font-size: 17px; line-height: 1.35; letter-spacing: .02em; }
.eyebrow { margin: 0 0 4px; color: var(--accent); font-size: 10px; font-weight: 850; letter-spacing: .18em; text-transform: uppercase; }
.nav-list { display: grid; gap: 7px; }
.nav-item {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 13px;
  padding: 12px 14px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  text-align: left;
  transition: .18s ease;
}
.nav-item span:first-child { width: 22px; text-align: center; font-weight: 900; }
.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.active { border-color: color-mix(in srgb, var(--accent) 28%, transparent); background: var(--accent-soft); color: var(--accent-strong); }
.privacy-card {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-top: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}
.privacy-card strong { font-size: 12px; }
.privacy-card p { margin: 2px 0 0; color: var(--muted); font-size: 11px; }
.status-dot { width: 8px; height: 8px; flex: 0 0 8px; margin-top: 7px; border-radius: 999px; background: var(--good); box-shadow: 0 0 14px var(--good); }
.sidebar-footer { display: flex; justify-content: space-between; align-items: center; padding: 14px 4px 0; color: var(--faint); font-size: 11px; }

.main-column { min-height: 100vh; margin-left: var(--sidebar-width); }
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  height: 76px;
  align-items: center;
  gap: 14px;
  padding: 14px clamp(20px, 4vw, 54px);
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(20px);
}
.search-wrap {
  position: relative;
  display: flex;
  max-width: 760px;
  flex: 1;
  align-items: center;
}
.search-wrap > span { position: absolute; left: 14px; color: var(--faint); }
.search-wrap input {
  width: 100%;
  padding: 11px 55px 11px 40px;
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  background: var(--surface);
  color: var(--text);
}
.search-wrap input:focus { border-color: color-mix(in srgb, var(--accent) 55%, transparent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-wrap kbd { position: absolute; right: 11px; padding: 2px 7px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-2); color: var(--faint); font-size: 10px; }
.menu-button { display: none; border: 0; background: transparent; cursor: pointer; font-size: 22px; }

main { width: min(1320px, 100%); margin: 0 auto; padding: 38px clamp(20px, 4vw, 54px) 80px; }
.view { display: none; animation: fade-in .2s ease; }
.view.active { display: block; }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.hero-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 40px;
  min-height: 360px;
  align-items: center;
  padding: clamp(28px, 5vw, 62px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background:
    linear-gradient(135deg, var(--surface), color-mix(in srgb, var(--surface-2) 90%, var(--accent) 10%));
  box-shadow: var(--shadow);
}
.hero-copy h2 { max-width: 780px; margin: 8px 0 16px; font-size: clamp(31px, 4.8vw, 64px); line-height: 1.12; letter-spacing: -.035em; }
.hero-lead { max-width: 720px; margin: 0; color: var(--muted); font-size: clamp(15px, 1.6vw, 19px); }
.hero-actions { display: flex; flex-wrap: wrap; gap: 11px; margin-top: 27px; }
.hero-progress { display: grid; place-items: center; align-self: center; padding: 22px; text-align: center; }
.hero-progress p { margin: 15px 0 2px; color: var(--muted); }
.hero-progress small { color: var(--faint); }
.progress-ring {
  --progress: 0deg;
  display: grid;
  width: 164px;
  height: 164px;
  place-items: center;
  border-radius: 50%;
  background: conic-gradient(var(--accent) var(--progress), var(--surface-3) 0);
  box-shadow: 0 0 55px rgba(119, 220, 196, .1);
}
.progress-ring::before { content: ""; grid-area: 1/1; width: 132px; height: 132px; border-radius: 50%; background: var(--surface); }
.progress-ring span { z-index: 1; grid-area: 1/1; font-size: 30px; font-weight: 900; }

.primary-button, .secondary-button, .ghost-button, .danger-button, .copy-button, .text-button, .icon-button, .filter-chip, .reference-tab, .tool-tab {
  border-radius: 10px;
  cursor: pointer;
  transition: .16s ease;
}
.primary-button { padding: 11px 17px; border: 1px solid var(--accent); background: var(--accent); color: #07120f; font-weight: 850; }
.primary-button:hover { transform: translateY(-1px); filter: brightness(1.05); }
.secondary-button { padding: 10px 15px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font-weight: 700; }
.secondary-button:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); background: var(--surface-2); }
.ghost-button { padding: 8px 10px; border: 1px solid var(--line); background: transparent; color: var(--muted); }
.ghost-button.compact { padding: 5px 8px; font-size: 10px; }
.danger-button { padding: 10px 15px; border: 1px solid var(--danger); background: var(--danger-soft); color: var(--danger); font-weight: 750; }
.text-button { padding: 4px 0; border: 0; background: transparent; color: var(--accent); font-weight: 750; }
.text-button:hover { color: var(--accent-strong); }
.copy-button { padding: 7px 10px; border: 1px solid var(--line); background: var(--surface-2); color: var(--muted); font-size: 12px; }
.icon-button { width: 38px; height: 38px; border: 1px solid var(--line); background: var(--surface); font-size: 20px; }

.section-heading { margin: 46px 0 17px; }
.section-heading h3, .page-heading h2 { margin: 4px 0 0; font-size: clamp(24px, 3vw, 36px); line-height: 1.2; letter-spacing: -.025em; }
.inline-heading { display: flex; justify-content: space-between; align-items: end; }
.today-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.today-card, .role-card, .risk-strip article, .project-snapshot, .module-card, .glossary-card, .command-card, .trouble-card, .rule-card, .source-card, .output-card, .checklist-card, .note-card {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius-lg);
}
.today-card { position: relative; min-height: 180px; padding: 20px; overflow: hidden; }
.today-card::after { content: attr(data-step); position: absolute; right: 13px; bottom: -16px; color: var(--surface-3); font-size: 88px; font-weight: 950; line-height: 1; }
.today-card strong { display: block; margin-bottom: 7px; font-size: 15px; }
.today-card p { position: relative; z-index: 1; margin: 0; color: var(--muted); }
.today-card small { display: inline-block; margin-top: 16px; color: var(--accent); font-weight: 800; }
.role-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.role-card { padding: 22px; }
.role-card h4 { margin: 10px 0 8px; font-size: 18px; }
.role-card ul { margin: 0; padding-left: 19px; color: var(--muted); }
.role-card li + li { margin-top: 5px; }
.role-icon { display: grid; width: 42px; height: 42px; place-items: center; border-radius: 12px; background: var(--surface-3); font-size: 13px; font-weight: 900; }
.owner-card .role-icon { color: var(--gold); background: var(--gold-soft); }
.shared-card .role-icon { color: var(--accent); background: var(--accent-soft); }
.ai-card .role-icon { color: var(--good); background: var(--good-soft); }
.risk-strip { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.risk-strip article { padding: 20px; }
.risk-strip h4 { margin: 9px 0 5px; }
.risk-strip p { margin: 0; color: var(--muted); }
.risk-label { display: inline-flex; min-width: 35px; justify-content: center; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 900; }
.risk-label.low { background: var(--good-soft); color: var(--good); }
.risk-label.medium { background: var(--warning-soft); color: var(--warning); }
.risk-label.high { background: var(--danger-soft); color: var(--danger); }
.project-snapshot { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 1fr); gap: 25px; align-items: center; margin-top: 42px; padding: 28px; }
.project-snapshot h3 { margin: 3px 0 8px; }
.project-snapshot p:last-child { margin: 0; color: var(--muted); }
.stack-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.stack-chip { padding: 7px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface-2); color: var(--muted); font-family: var(--mono); font-size: 11px; }

.page-heading { display: flex; justify-content: space-between; gap: 20px; align-items: flex-end; margin-bottom: 26px; }
.page-heading p:last-child { margin: 9px 0 0; color: var(--muted); }
.filter-row { display: flex; max-width: 540px; flex-wrap: wrap; justify-content: flex-end; gap: 7px; }
.filter-chip { padding: 6px 10px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); font-size: 12px; }
.filter-chip.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-strong); }
.curriculum-list { display: grid; gap: 16px; }
.module-card { overflow: hidden; }
.module-header { display: grid; grid-template-columns: 58px minmax(0, 1fr) auto; gap: 16px; align-items: center; padding: 22px; cursor: pointer; }
.module-number { display: grid; width: 48px; height: 48px; place-items: center; border-radius: 14px; background: var(--accent-soft); color: var(--accent); font-family: var(--mono); font-size: 12px; font-weight: 900; }
.module-header h3 { margin: 0; font-size: 20px; }
.module-header p { margin: 3px 0 0; color: var(--muted); }
.module-progress { min-width: 108px; text-align: right; }
.module-progress strong { display: block; }
.mini-progress { width: 108px; height: 5px; margin-top: 7px; overflow: hidden; border-radius: 999px; background: var(--surface-3); }
.mini-progress span { display: block; height: 100%; border-radius: inherit; background: var(--accent); }
.lesson-list { display: none; border-top: 1px solid var(--line); }
.module-card.open .lesson-list { display: block; }
.lesson-row { display: grid; grid-template-columns: 31px minmax(0, 1fr) auto; gap: 13px; align-items: center; padding: 16px 22px; border-bottom: 1px solid var(--line); }
.lesson-row:last-child { border-bottom: 0; }
.lesson-check {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  cursor: pointer;
}
.lesson-check.completed { border-color: var(--accent); background: var(--accent); color: #07120f; }
.lesson-row h4 { margin: 0; font-size: 15px; }
.lesson-row p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.lesson-meta { display: flex; gap: 7px; align-items: center; }
.lesson-tag { padding: 3px 8px; border: 1px solid var(--line); border-radius: 999px; color: var(--faint); font-size: 10px; }
.open-lesson { padding: 7px 9px; border: 0; background: transparent; color: var(--accent); cursor: pointer; font-weight: 800; }

.reference-tabs, .tool-tabs { display: flex; gap: 7px; margin-bottom: 20px; overflow-x: auto; padding-bottom: 3px; }
.reference-tab, .tool-tab { white-space: nowrap; padding: 9px 13px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); }
.reference-tab.active, .tool-tab.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-strong); }
.reference-panel, .tool-panel { display: none; }
.reference-panel.active, .tool-panel.active { display: block; }
.reference-toolbar { display: flex; gap: 10px; margin-bottom: 17px; }
.reference-toolbar input, .reference-toolbar select { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--text); }
.reference-toolbar input { flex: 1; }
.glossary-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 13px; }
.glossary-card { padding: 19px; }
.glossary-card h3 { margin: 5px 0 5px; font-size: 17px; }
.glossary-card p { margin: 0; color: var(--muted); font-size: 13px; }
.term-category { color: var(--accent); font-size: 10px; font-weight: 850; letter-spacing: .08em; }
.term-alias { margin-top: 9px !important; color: var(--faint) !important; font-family: var(--mono); font-size: 11px !important; }
.command-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.command-card { padding: 20px; }
.command-card h3 { margin: 0 0 3px; font-size: 16px; }
.command-card > p { margin: 0 0 13px; color: var(--muted); font-size: 13px; }
.code-row { display: flex; gap: 8px; align-items: center; padding: 10px 12px; border-radius: 10px; background: #090d12; color: #dce8e4; }
:root[data-theme="light"] .code-row { background: #172026; }
.code-row code { flex: 1; overflow-x: auto; font-family: var(--mono); font-size: 12px; }
.trouble-list { display: grid; gap: 12px; }
.trouble-card { padding: 20px; }
.trouble-card summary { cursor: pointer; font-weight: 850; }
.trouble-body { padding-top: 12px; color: var(--muted); }
.trouble-body ol { margin: 8px 0 0; padding-left: 22px; }
.trouble-body li + li { margin-top: 6px; }
.rule-callout { margin-bottom: 17px; padding: 15px 17px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface-2); color: var(--muted); }
.rule-callout strong { color: var(--text); }
.warning-callout { border-color: color-mix(in srgb, var(--warning) 40%, var(--line)); background: var(--warning-soft); }
.warning-callout strong { color: var(--warning); }
.rule-grid, .source-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; }
.rule-card, .source-card { padding: 19px; }
.rule-card h3, .source-card h3 { margin: 0 0 6px; font-size: 16px; }
.rule-card p, .source-card p { margin: 0; color: var(--muted); font-size: 13px; }
.rule-card.high-risk { border-color: color-mix(in srgb, var(--danger) 34%, var(--line)); }
.rule-card.high-risk h3 { color: var(--danger); }
.source-intro { color: var(--muted); }
.source-card { display: flex; flex-direction: column; gap: 8px; }
.source-card a { margin-top: auto; font-weight: 800; text-decoration: none; }
.source-badge { align-self: flex-start; padding: 2px 7px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 10px; font-weight: 800; }

.form-output-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, .85fr); gap: 17px; align-items: start; }
.builder-form { display: grid; gap: 13px; }
.builder-form label, .standalone-label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 750; }
.builder-form input, .builder-form textarea, .builder-form select, .standalone-label input, .standalone-label textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  resize: vertical;
  background: var(--surface);
  color: var(--text);
  font-weight: 450;
}
.builder-form input:focus, .builder-form textarea:focus, .builder-form select:focus, .standalone-label input:focus, .standalone-label textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.two-column-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.output-card { position: sticky; top: 96px; min-height: 410px; padding: 18px; }
.output-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 13px; }
.output-heading h3 { margin: 0; font-size: 17px; }
.output-card pre { min-height: 320px; margin: 0; padding: 15px; overflow: auto; border-radius: 11px; background: #090d12; color: #dce8e4; font-family: var(--mono); font-size: 12px; white-space: pre-wrap; word-break: break-word; }
:root[data-theme="light"] .output-card pre { background: #172026; }
.review-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, .85fr); gap: 17px; align-items: start; }
.checklist-card { padding: 18px; }
.checklist-heading { display: flex; justify-content: space-between; align-items: center; }
.checklist-heading h3 { margin: 0; }
.review-item { display: grid; grid-template-columns: 24px minmax(0, 1fr); gap: 11px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.review-item:last-child { border-bottom: 0; }
.review-item input { width: 18px; height: 18px; accent-color: var(--accent); }
.review-item strong { display: block; font-size: 13px; }
.review-item span { display: block; color: var(--muted); font-size: 12px; }
.review-output-card { display: grid; gap: 13px; }
.review-output-card pre { min-height: 220px; }
.file-button { display: inline-flex; align-items: center; cursor: pointer; }
.file-button input { display: none; }

.notes-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.note-card { display: grid; min-height: 270px; padding: 17px; }
.note-card input { width: 100%; padding: 3px 0 9px; border: 0; border-bottom: 1px solid var(--line); outline: none; background: transparent; color: var(--text); font-weight: 850; }
.note-card textarea { width: 100%; min-height: 160px; padding: 11px 0; border: 0; outline: none; resize: vertical; background: transparent; color: var(--muted); }
.note-footer { display: flex; justify-content: space-between; align-items: center; color: var(--faint); font-size: 10px; }
.note-delete { border: 0; background: transparent; color: var(--danger); cursor: pointer; }

.search-results {
  position: fixed;
  z-index: 100;
  top: 68px;
  left: calc(var(--sidebar-width) + clamp(20px, 4vw, 54px));
  width: min(760px, calc(100vw - var(--sidebar-width) - 110px));
  max-height: min(560px, calc(100vh - 90px));
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.search-result { display: block; width: 100%; padding: 13px 16px; border: 0; border-bottom: 1px solid var(--line); background: transparent; color: var(--text); cursor: pointer; text-align: left; }
.search-result:last-child { border-bottom: 0; }
.search-result:hover, .search-result:focus { background: var(--surface-2); }
.search-result strong { display: block; }
.search-result span { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; }
.search-empty { padding: 20px; color: var(--muted); text-align: center; }

.dialog-card, .lesson-dialog {
  width: min(680px, calc(100vw - 30px));
  max-height: calc(100vh - 40px);
  overflow: auto;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
.dialog-card::backdrop, .lesson-dialog::backdrop { background: rgba(0,0,0,.65); backdrop-filter: blur(5px); }
.dialog-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 14px; }
.dialog-header h2 { margin: 0; }
.dialog-card > p { color: var(--muted); }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 9px; margin: 20px 0; }
.lesson-dialog { width: min(900px, calc(100vw - 30px)); }
.lesson-dialog-header { position: sticky; top: -22px; z-index: 2; margin: -22px -22px 0; padding: 20px 22px 15px; border-bottom: 1px solid var(--line); background: var(--surface); }
#lessonDialogContent { padding: 22px 2px 12px; }
.lesson-section { margin-bottom: 24px; }
.lesson-section h3 { margin: 0 0 8px; font-size: 17px; }
.lesson-section p, .lesson-section li { color: var(--muted); }
.lesson-section ul, .lesson-section ol { padding-left: 22px; }
.lesson-section li + li { margin-top: 6px; }
.lesson-example { padding: 14px; border-left: 3px solid var(--accent); border-radius: 0 10px 10px 0; background: var(--accent-soft); color: var(--muted); }
.lesson-source-links { display: flex; flex-wrap: wrap; gap: 8px; }
.lesson-source-links a { padding: 7px 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-2); text-decoration: none; font-size: 12px; font-weight: 800; }
.lesson-dialog-footer { position: sticky; bottom: -22px; display: flex; justify-content: center; gap: 9px; margin: 12px -22px -22px; padding: 14px 22px 20px; border-top: 1px solid var(--line); background: var(--surface); }

.toast { position: fixed; right: 22px; bottom: 22px; z-index: 200; max-width: min(390px, calc(100vw - 30px)); padding: 11px 15px; border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line)); border-radius: 11px; background: var(--surface); box-shadow: var(--shadow); color: var(--text); font-size: 13px; }

@media (max-width: 1120px) {
  .glossary-grid, .notes-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hero-card { grid-template-columns: minmax(0, 1fr) 210px; }
  .role-grid, .today-grid, .risk-strip { grid-template-columns: 1fr; }
  .today-card { min-height: 130px; }
}

@media (max-width: 880px) {
  :root { --sidebar-width: 276px; }
  .sidebar { transform: translateX(-105%); transition: transform .2s ease; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .main-column { margin-left: 0; }
  .menu-button { display: block; }
  .topbar { padding-inline: 16px; }
  .topbar > .secondary-button { display: none; }
  main { padding: 26px 16px 65px; }
  .search-results { left: 16px; width: calc(100vw - 32px); }
  .mobile-overlay { position: fixed; inset: 0; z-index: 35; background: rgba(0,0,0,.58); }
  .hero-card { grid-template-columns: 1fr; gap: 24px; }
  .hero-progress { grid-template-columns: auto 1fr; gap: 16px; justify-content: start; text-align: left; }
  .hero-progress p, .hero-progress small { grid-column: 2; margin: 0; }
  .progress-ring { grid-row: 1 / span 2; width: 118px; height: 118px; }
  .progress-ring::before { width: 94px; height: 94px; }
  .progress-ring span { font-size: 23px; }
  .project-snapshot, .form-output-layout, .review-layout { grid-template-columns: 1fr; }
  .output-card { position: static; }
  .page-heading { align-items: flex-start; flex-direction: column; }
  .filter-row { justify-content: flex-start; }
}

@media (max-width: 620px) {
  .hero-card { min-height: auto; padding: 26px 20px; border-radius: 20px; }
  .hero-copy h2 { font-size: 33px; }
  .search-wrap kbd { display: none; }
  .hero-actions > * { width: 100%; }
  .hero-progress { display: flex; flex-direction: column; text-align: center; }
  .glossary-grid, .command-grid, .rule-grid, .source-grid, .notes-grid { grid-template-columns: 1fr; }
  .two-column-fields { grid-template-columns: 1fr; }
  .module-header { grid-template-columns: 45px minmax(0, 1fr); }
  .module-number { width: 40px; height: 40px; }
  .module-progress { grid-column: 2; width: 100%; text-align: left; }
  .mini-progress { width: 100%; }
  .lesson-row { grid-template-columns: 28px minmax(0, 1fr); }
  .lesson-meta { grid-column: 2; justify-content: space-between; }
  .reference-toolbar { flex-direction: column; }
  .dialog-actions > * { width: 100%; justify-content: center; }
  .lesson-dialog-footer { display: grid; grid-template-columns: 1fr 1fr; }
  #lessonComplete { grid-column: 1 / -1; grid-row: 1; }
}

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


/* v2: beginner textbook */
.foundation-banner {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 240px;
  gap: 24px;
  align-items: center;
  margin-top: 18px;
  padding: 22px 24px;
  border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--line));
  border-radius: var(--radius-lg);
  background: linear-gradient(120deg, var(--accent-soft), var(--surface) 58%);
}
.foundation-banner h3 { margin: 3px 0 7px; font-size: 22px; }
.foundation-banner p:not(.eyebrow) { margin: 0; color: var(--muted); }
.foundation-progress { display: grid; gap: 8px; }
.foundation-progress strong { font-size: 17px; }
.mini-progress, .book-progress-track { height: 8px; overflow: hidden; border-radius: 999px; background: var(--surface-3); }
.mini-progress span, .book-progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--accent), var(--gold)); transition: width .25s ease; }

.textbook-heading { align-items: center; }
.book-progress-card { width: min(280px, 100%); padding: 15px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); }
.book-progress-card > span { display: block; margin-bottom: 8px; font-weight: 850; }
.book-progress-card small { display: block; margin-top: 7px; color: var(--faint); }
.book-toolbar { display: flex; gap: 14px; align-items: center; margin: 20px 0; }
.book-search-wrap { position: relative; flex: 1; }
.book-search-wrap span { position: absolute; left: 14px; top: 10px; color: var(--faint); }
.book-search-wrap input { width: 100%; padding: 11px 14px 11px 40px; border: 1px solid var(--line); border-radius: 12px; outline: 0; background: var(--surface); color: var(--text); }
.book-search-wrap input:focus { border-color: color-mix(in srgb, var(--accent) 55%, transparent); box-shadow: 0 0 0 3px var(--accent-soft); }
.book-filters { display: flex; flex-wrap: wrap; gap: 7px; justify-content: flex-end; }
.textbook-layout { display: grid; grid-template-columns: 330px minmax(0, 1fr); gap: 18px; align-items: start; }
.book-toc-card { position: sticky; top: 96px; max-height: calc(100vh - 116px); overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); }
.book-toc-heading { display: flex; justify-content: space-between; align-items: end; padding: 18px; border-bottom: 1px solid var(--line); }
.book-toc-heading h3 { margin: 2px 0 0; }
.book-toc-heading > span { color: var(--faint); font-size: 12px; }
.book-toc { max-height: calc(100vh - 205px); overflow: auto; padding: 8px; }
.book-toc-item { display: grid; grid-template-columns: 38px minmax(0, 1fr) 24px; gap: 10px; width: 100%; align-items: start; padding: 12px 10px; border: 1px solid transparent; border-radius: 11px; background: transparent; color: var(--muted); cursor: pointer; text-align: left; }
.book-toc-item:hover { background: var(--surface-2); color: var(--text); }
.book-toc-item.active { border-color: color-mix(in srgb, var(--accent) 35%, transparent); background: var(--accent-soft); color: var(--text); }
.book-toc-item.completed .book-number { color: var(--good); }
.book-number { color: var(--accent); font-family: var(--mono); font-size: 12px; font-weight: 900; }
.book-toc-item strong { display: block; font-size: 13px; line-height: 1.4; }
.book-toc-item small { display: block; margin-top: 4px; color: var(--faint); font-size: 10px; }
.book-check { display: grid; width: 20px; height: 20px; place-items: center; border: 1px solid var(--line); border-radius: 50%; color: var(--good); font-size: 11px; }
.book-toc-item.completed .book-check { border-color: var(--good); background: var(--good-soft); }
.book-reader { min-width: 0; border: 1px solid var(--line); border-radius: var(--radius-xl); background: var(--surface); box-shadow: var(--shadow); }
.book-chapter-header { display: flex; justify-content: space-between; gap: 22px; align-items: flex-start; padding: clamp(24px, 5vw, 48px); border-bottom: 1px solid var(--line); background: linear-gradient(140deg, var(--surface), color-mix(in srgb, var(--surface-2) 92%, var(--accent) 8%)); border-radius: var(--radius-xl) var(--radius-xl) 0 0; }
.book-chapter-header h2 { max-width: 760px; margin: 6px 0 9px; font-size: clamp(29px, 4vw, 48px); line-height: 1.15; letter-spacing: -.035em; }
.book-subtitle { max-width: 760px; margin: 0; color: var(--muted); font-size: 16px; }
.book-intro, .book-outcome { margin: 28px clamp(22px, 5vw, 54px) 0; padding: 20px; border-radius: 14px; }
.book-intro { border: 1px solid var(--line); background: var(--surface-2); }
.book-outcome { border-left: 4px solid var(--accent); background: var(--accent-soft); }
.book-intro strong, .book-outcome span { color: var(--accent-strong); font-size: 12px; font-weight: 900; letter-spacing: .08em; }
.book-intro p, .book-outcome p { margin: 7px 0 0; }
.book-section { position: relative; margin: 44px clamp(22px, 5vw, 54px) 0; padding-top: 17px; border-top: 1px solid var(--line); }
.book-section-number { position: absolute; right: 0; top: 10px; color: var(--surface-3); font-size: 44px; font-weight: 950; line-height: 1; }
.book-section h3 { position: relative; max-width: 78%; margin: 0 0 18px; font-size: clamp(22px, 3vw, 31px); letter-spacing: -.025em; }
.formal-explanation, .plain-book-box, .project-example-box { margin-top: 13px; padding: 18px 20px; border-radius: 14px; }
.formal-explanation { border: 1px solid var(--line); background: var(--bg-elevated); }
.plain-book-box { border: 1px solid color-mix(in srgb, var(--accent) 38%, var(--line)); background: var(--accent-soft); }
.project-example-box { border: 1px solid color-mix(in srgb, var(--gold) 35%, var(--line)); background: var(--gold-soft); }
.explanation-label, .plain-label { display: inline-block; margin-bottom: 7px; color: var(--accent-strong); font-size: 11px; font-weight: 900; letter-spacing: .09em; }
.project-example-box .explanation-label { color: var(--gold); }
.formal-explanation p, .plain-book-box p, .project-example-box p { margin: 0; }
.concept-flow { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 16px; padding: 15px; border: 1px dashed var(--line); border-radius: 13px; background: var(--surface-2); }
.flow-node { flex: 1 1 105px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); text-align: center; font-size: 12px; font-weight: 750; }
.flow-arrow { color: var(--accent); font-weight: 900; }
.book-points { margin: 14px 0 0; padding: 15px 18px 15px 38px; border-radius: 12px; background: var(--surface-2); }
.book-warning-section, .book-check-section, .book-quiz-section, .book-note-section, .book-related-section { margin: 44px clamp(22px, 5vw, 54px) 0; padding: 22px; border-radius: 16px; }
.book-warning-section { border: 1px solid color-mix(in srgb, var(--warning) 40%, var(--line)); background: var(--warning-soft); }
.book-check-section { border: 1px solid color-mix(in srgb, var(--good) 35%, var(--line)); background: var(--good-soft); }
.book-warning-section h3, .book-check-section h3, .book-quiz-section h3, .book-note-section h3, .book-related-section h3 { margin: 3px 0 8px; font-size: 21px; }
.book-warning-section ul, .book-check-section ul { margin: 10px 0 0; padding-left: 22px; }
.book-section-title { display: flex; justify-content: space-between; align-items: end; gap: 16px; }
.book-section-title > span { color: var(--faint); font-size: 11px; }
.book-quiz-section { border: 1px solid var(--line); background: var(--surface-2); }
.quiz-card { margin-top: 13px; padding: 17px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); }
.quiz-card > strong { display: block; margin-bottom: 11px; }
.quiz-options { display: grid; gap: 7px; }
.quiz-option { padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-2); color: var(--text); cursor: pointer; text-align: left; }
.quiz-option:hover { border-color: var(--accent); }
.quiz-option.selected { border-color: var(--gold); }
.quiz-option.correct { border-color: var(--good); background: var(--good-soft); }
.quiz-option.wrong { border-color: var(--danger); background: var(--danger-soft); }
.quiz-feedback { margin-top: 10px; padding: 11px 13px; border-radius: 10px; }
.quiz-feedback.correct { background: var(--good-soft); color: var(--good); }
.quiz-feedback.wrong { background: var(--danger-soft); color: var(--danger); }
.quiz-feedback p { margin: 3px 0 0; color: var(--text); }
.book-note-section { display: grid; grid-template-columns: .75fr 1.25fr; gap: 20px; border: 1px solid var(--line); background: linear-gradient(125deg, var(--surface-2), var(--surface)); }
.book-note-section p { margin: 0; color: var(--muted); }
.book-note-section textarea { min-height: 130px; resize: vertical; padding: 13px; border: 1px solid var(--line); border-radius: 11px; outline: 0; background: var(--bg); color: var(--text); }
.book-note-section textarea:focus { border-color: var(--accent); }
.book-related-section { border-top: 1px solid var(--line); border-radius: 0; padding-left: 0; padding-right: 0; }
.book-term-list, .book-related-lessons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.book-term-list button, .book-related-lessons button { padding: 7px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface-2); color: var(--muted); cursor: pointer; }
.book-term-list button:hover, .book-related-lessons button:hover { border-color: var(--accent); color: var(--text); }
.book-related-lessons button { border-radius: 9px; color: var(--accent-strong); }
.book-reader-footer { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: center; margin-top: 46px; padding: 22px clamp(22px, 5vw, 54px); border-top: 1px solid var(--line); }
.book-reader-footer > :last-child { justify-self: end; }
.book-reader-footer button:disabled { opacity: .35; cursor: not-allowed; }

.plain-explanation, .analogy-explanation, .misconception-explanation { border-radius: 13px; }
.plain-explanation { border: 1px solid color-mix(in srgb, var(--accent) 38%, var(--line)); background: var(--accent-soft); }
.analogy-explanation { border: 1px solid color-mix(in srgb, var(--gold) 36%, var(--line)); background: var(--gold-soft); }
.misconception-explanation { border: 1px solid color-mix(in srgb, var(--warning) 38%, var(--line)); background: var(--warning-soft); }
.analogy-explanation .plain-label { color: var(--gold); }
.misconception-explanation .plain-label { color: var(--warning); }
.glossary-plain { display: grid; grid-template-columns: auto 1fr; gap: 8px; margin-top: 12px; padding: 10px; border-radius: 10px; background: var(--accent-soft); font-size: 12px; }
.glossary-plain strong { color: var(--accent-strong); }

@media (max-width: 1080px) {
  .textbook-layout { grid-template-columns: 280px minmax(0, 1fr); }
  .book-toolbar { align-items: flex-start; flex-direction: column; }
  .book-filters { justify-content: flex-start; }
}
@media (max-width: 860px) {
  .foundation-banner { grid-template-columns: 1fr; }
  .textbook-layout { grid-template-columns: 1fr; }
  .book-toc-card { position: static; max-height: none; }
  .book-toc { max-height: 390px; }
  .book-chapter-header { flex-direction: column; }
  .book-note-section { grid-template-columns: 1fr; }
  .textbook-heading { align-items: flex-start; }
  .book-progress-card { width: 100%; }
}
@media (max-width: 620px) {
  .foundation-banner { padding: 18px; }
  .book-toolbar { margin-top: 14px; }
  .book-filters { flex-wrap: nowrap; width: 100%; overflow-x: auto; padding-bottom: 4px; }
  .book-filters .filter-chip { flex: 0 0 auto; }
  .book-chapter-header { padding: 23px 19px; }
  .book-intro, .book-outcome, .book-section, .book-warning-section, .book-check-section, .book-quiz-section, .book-note-section, .book-related-section { margin-left: 17px; margin-right: 17px; }
  .book-section h3 { max-width: 84%; }
  .concept-flow { align-items: stretch; flex-direction: column; }
  .flow-arrow { transform: rotate(90deg); text-align: center; }
  .flow-node { flex-basis: auto; }
  .book-reader-footer { grid-template-columns: 1fr 1fr; padding: 18px 17px; }
  .book-reader-footer #bookCompleteBottom { grid-column: 1 / -1; grid-row: 1; }
  .book-reader-footer #bookNext { justify-self: stretch; }
  .book-reader-footer button { width: 100%; }
  .glossary-plain { grid-template-columns: 1fr; }
}
