:root {
  color-scheme: light;
  --ink: #171713;
  --muted: #6f7068;
  --paper: #f0eee6;
  --paper-2: #e7e4da;
  --card: rgba(250, 249, 244, 0.86);
  --line: rgba(23, 23, 19, 0.16);
  --accent: #ff5a1f;
  --accent-soft: #ffd7c7;
  --acid: #d8ff3e;
  --success: #2d7f58;
  --shadow: 0 20px 60px rgba(42, 40, 30, 0.1);
  --sidebar: 268px;
  --mono: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
  --serif: "Noto Serif SC", "Songti SC", serif;
}

[data-theme="dark"] {
  color-scheme: dark;
  --ink: #f0eee5;
  --muted: #aaa99f;
  --paper: #181814;
  --paper-2: #22221d;
  --card: rgba(35, 35, 29, 0.88);
  --line: rgba(240, 238, 229, 0.14);
  --accent-soft: #5a2d20;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--serif);
  transition: color .25s ease, background .25s ease;
}
button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, [tabindex]:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.noise {
  position: fixed; inset: 0; z-index: 20; pointer-events: none; opacity: .5;
  background-image: url("./noise.png");
  background-size: 64px 64px;
  background-repeat: repeat;
}
.app-shell { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar) 1fr; transition: grid-template-columns .24s ease; }
.app-shell.sidebar-collapsed { --sidebar: 82px; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar); z-index: 10;
  display: flex; flex-direction: column; padding: 28px 20px 20px;
  border-right: 1px solid var(--line); background: color-mix(in srgb, var(--paper) 94%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); transition: width .24s ease, padding .24s ease;
}
.sidebar-collapse { position: absolute; top: 50%; right: -14px; z-index: 2; width: 29px; height: 38px; display: grid; place-items: center; padding: 0; transform: translateY(-50%); border: 1px solid var(--line); border-left: 0; border-radius: 0 18px 18px 0; background: var(--paper); box-shadow: 4px 5px 14px rgba(0,0,0,.08); cursor: pointer; font: 600 21px/1 var(--mono); transition: color .18s ease, background .18s ease; }
.sidebar-collapse:hover { background: var(--acid); color: #171713; }
.brand { display: flex; align-items: flex-start; gap: 13px; padding: 0 8px 34px; }
.brand-mark {
  width: 45px; height: 45px; display: grid; place-items: center; flex: 0 0 auto;
  border: 2px solid var(--ink); background: var(--acid); color: #15150f;
  font: 600 15px/1 var(--mono); transform: rotate(-4deg); box-shadow: 4px 4px 0 var(--ink);
}
.eyebrow { margin: 1px 0 5px; color: var(--accent); font: 600 9px/1.2 var(--mono); letter-spacing: .14em; }
.brand h1 { margin: 0; font-size: 22px; line-height: 1.18; letter-spacing: -.04em; }
.author-credit { display: grid; gap: 3px; margin: 11px 0 0; }
.author-credit span { color: var(--accent); font: 600 8px/1.2 var(--mono); letter-spacing: .12em; }
.author-credit strong { color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: .05em; white-space: nowrap; }
.nav { display: grid; gap: 6px; min-height: 0; overflow-x: hidden; overflow-y: auto; padding-right: 4px; scrollbar-width: thin; }
.nav-item {
  position: relative; display: flex; align-items: center; gap: 13px; width: 100%; padding: 12px 13px;
  border: 0; border-radius: 4px; background: transparent; cursor: pointer; text-align: left; font-weight: 700;
  transition: background .18s ease, transform .18s ease;
}
.nav-item::after { content: ""; position: absolute; right: 13px; width: 6px; height: 6px; border-radius: 50%; background: transparent; }
.nav-item span { color: var(--muted); font: 500 10px/1 var(--mono); }
.nav-item:hover { background: var(--paper-2); transform: translateX(2px); }
.nav-item.active { background: var(--ink); color: var(--paper); }
.nav-item.active span { color: var(--acid); }
.nav-item.active::after { background: var(--accent); }
[data-theme="dark"] .nav-item.active {
  background: linear-gradient(100deg, var(--acid), #eeff9a);
  color: #171713;
  box-shadow: 4px 4px 0 var(--accent), inset 0 0 0 1px rgba(255, 255, 255, .38);
  transform: translateX(2px);
}
[data-theme="dark"] .nav-item.active span { color: #4a4c2e; }
[data-theme="dark"] .nav-item.active::after {
  width: 8px;
  height: 8px;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(23, 23, 19, .16);
}
[data-theme="dark"] .nav-item.active:hover { background: linear-gradient(100deg, #e3ff70, var(--acid)); }
.sidebar-footer { margin-top: auto; }
.sidebar-footer > p { margin: 13px 6px 0; color: var(--muted); font: 10px/1.5 var(--mono); }
.streak-card { display: flex; align-items: center; gap: 11px; padding: 13px; border: 1px solid var(--line); background: var(--card); }
.streak-card strong { display: block; font: 600 20px/1 var(--mono); }
.streak-card small { display: block; margin-top: 5px; color: var(--muted); font: 10px/1 var(--mono); }
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 5px var(--accent-soft); }
.sidebar-collapsed .sidebar { padding-inline: 12px; }
.sidebar-collapsed .brand { justify-content: center; padding-inline: 0; }
.sidebar-collapsed .brand > div:last-child { display: none; }
.sidebar-collapsed .brand-mark { width: 42px; height: 42px; }
.sidebar-collapsed .nav-item { justify-content: center; gap: 0; padding-inline: 0; overflow: hidden; font-size: 0; }
.sidebar-collapsed .nav-item span { font-size: 10px; }
.sidebar-collapsed .nav-item::after { right: 7px; width: 5px; height: 5px; }
.sidebar-collapsed .sidebar-footer > p, .sidebar-collapsed .streak-card div { display: none; }
.sidebar-collapsed .streak-card { justify-content: center; padding-inline: 0; }
.main { grid-column: 2; min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 8; min-height: 72px; display: flex; align-items: center; gap: 16px;
  padding: 14px clamp(20px, 4vw, 58px); border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 86%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.search-wrap { max-width: 660px; flex: 1; display: flex; align-items: center; gap: 10px; padding: 0 14px; border: 1px solid var(--line); background: var(--card); }
.search-wrap > span { font: 24px/1 var(--serif); transform: rotate(-15deg); }
.search-wrap input { width: 100%; height: 42px; border: 0; outline: 0; background: transparent; color: var(--ink); font: 13px/1 var(--mono); }
kbd { padding: 3px 6px; border: 1px solid var(--line); border-bottom-width: 2px; color: var(--muted); background: var(--paper-2); font: 10px/1 var(--mono); }
.top-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.text-button, .icon-button { border: 1px solid var(--line); background: var(--card); cursor: pointer; }
.text-button { height: 44px; padding: 0 16px; font: 600 11px/1 var(--mono); letter-spacing: .03em; }
.text-button:hover { border-color: var(--ink); background: var(--acid); color: #171713; }
.icon-button { width: 44px; height: 44px; display: grid; place-items: center; font: 18px/1 var(--mono); }
.icon-button:hover { border-color: var(--accent); color: var(--accent); }
.mobile-menu { display: none; }
.view { display: none; padding: clamp(28px, 5vw, 70px) clamp(20px, 5vw, 72px) 80px; animation: enter .45s ease both; }
#libraryView { padding-left: clamp(12px, 2vw, 24px); }
.view.active { display: block; }
@keyframes enter { from { opacity: 0; transform: translateY(10px); } }
.hero { position: relative; padding: 10px 0 44px; border-bottom: 1px solid var(--line); }
.hero::after { content: "REVIEW / BUILD / REPEAT"; position: absolute; right: 0; bottom: 14px; color: var(--muted); font: 9px/1 var(--mono); letter-spacing: .18em; }
.hero-kicker { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; color: var(--accent); font: 600 11px/1 var(--mono); letter-spacing: .1em; }
.hero-kicker::before { content: ""; width: 34px; height: 2px; background: var(--accent); }
.hero h2 { max-width: 890px; margin: 0; font-size: clamp(38px, 6vw, 78px); line-height: 1.03; letter-spacing: -.07em; }
.hero h2 em { color: var(--accent); font-style: normal; }
.hero p { max-width: 680px; margin: 22px 0 0; color: var(--muted); font-size: 15px; line-height: 1.9; }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); margin-top: 30px; border: 1px solid var(--line); }
.stat-card { min-height: 150px; padding: 23px; border-right: 1px solid var(--line); background: var(--card); }
.stat-card:last-child { border-right: 0; }
.stat-card small { color: var(--muted); font: 10px/1 var(--mono); letter-spacing: .08em; }
.stat-card strong { display: block; margin-top: 20px; font: 600 clamp(34px, 4vw, 50px)/1 var(--mono); letter-spacing: -.06em; }
.stat-card span { color: var(--accent); font-size: 13px; }
.section-head { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin: 50px 0 18px; }
.section-head h3 { margin: 0; font-size: 25px; letter-spacing: -.04em; }
.section-head p { margin: 0; color: var(--muted); font: 10px/1 var(--mono); }
.collection-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.collection-card { position: relative; isolation: isolate; width: 100%; min-height: 238px; padding: 25px 25px 78px; overflow: hidden; border: 1px solid var(--line); background: var(--card); color: var(--ink); cursor: pointer; text-align: left; font-family: var(--serif); transition: transform .2s ease, box-shadow .2s ease; }
.collection-card:hover { transform: translateY(-4px); box-shadow: var(--shadow); }
.collection-card::after { content: attr(data-index); position: absolute; right: -7px; bottom: -25px; z-index: 0; color: color-mix(in srgb, var(--ink) 7%, transparent); font: 900 110px/1 var(--mono); pointer-events: none; }
.collection-card .tag { display: inline-flex; padding: 5px 8px; background: var(--ink); color: var(--paper); font: 9px/1 var(--mono); }
.collection-card:nth-child(2) .tag { background: var(--accent); }
.collection-card:nth-child(3) .tag { background: #256ad6; }
.collection-card:nth-child(4) .tag { background: #7c48bc; }
.collection-card:nth-child(5) .tag { background: #087f8c; }
.collection-card .card-title { position: relative; z-index: 1; display: block; margin: 28px 0 10px; font-size: 28px; font-weight: 700; letter-spacing: -.05em; }
.collection-card .card-description { position: relative; z-index: 1; display: block; max-width: 76%; margin: 0; color: var(--muted); line-height: 1.7; font-size: 13px; }
.collection-card .card-footer { position: absolute; z-index: 2; right: 25px; bottom: 22px; left: 25px; display: block; font: 10px/1 var(--mono); }
.progress-rail { position: relative; z-index: 2; width: 100%; height: 5px; margin-top: 8px; overflow: hidden; background: var(--paper-2); }
.progress-rail i { display: block; height: 100%; background: var(--accent); }
.recent-list { border-top: 1px solid var(--line); }
.recent-item { width: 100%; display: grid; grid-template-columns: 56px 1fr auto; gap: 14px; align-items: center; padding: 16px 4px; border: 0; border-bottom: 1px solid var(--line); background: transparent; color: var(--ink); cursor: pointer; text-align: left; }
.recent-item:hover .recent-title { color: var(--accent); }
.recent-index { color: var(--muted); font: 10px/1 var(--mono); }
.recent-title { font-weight: 700; }
.recent-meta { color: var(--muted); font: 10px/1 var(--mono); }
.library-header { display: flex; align-items: end; justify-content: space-between; gap: 20px; padding-bottom: 26px; border-bottom: 1px solid var(--line); }
.library-header h2 { margin: 7px 0 5px; font-size: clamp(36px, 5vw, 64px); line-height: 1; letter-spacing: -.06em; }
.library-header p { margin: 0; color: var(--muted); }
.library-count { text-align: right; }
.library-count strong { display: block; font: 600 34px/1 var(--mono); }
.library-count span { color: var(--muted); font: 10px/1 var(--mono); }
.library-layout { display: grid; grid-template-columns: minmax(240px, 320px) minmax(0, 1fr); gap: 24px; margin-top: 26px; }
.question-panel { position: sticky; top: 97px; align-self: start; max-height: calc(100vh - 120px); overflow: auto; padding-right: 8px; }
.module-filter { margin-bottom: 14px; padding: 13px; border: 1px solid var(--line); background: var(--card); }
.module-filter > span { display: block; margin-bottom: 10px; color: var(--muted); font: 600 9px/1 var(--mono); letter-spacing: .1em; }
.module-row { display: flex; flex-wrap: wrap; gap: 6px; }
.module-chip { padding: 7px 9px; border: 1px solid var(--line); background: var(--paper); color: var(--muted); cursor: pointer; font: 9px/1 var(--mono); transition: border-color .18s ease, background .18s ease, color .18s ease; }
.module-chip:hover { border-color: var(--ink); color: var(--ink); }
.module-chip.active { border-color: var(--ink); background: var(--acid); color: #171713; font-weight: 600; }
.filter-row { display: flex; gap: 6px; margin-bottom: 12px; }
.filter-chip { padding: 7px 10px; border: 1px solid var(--line); background: transparent; cursor: pointer; color: var(--muted); font: 9px/1 var(--mono); }
.filter-chip.active { background: var(--ink); color: var(--paper); }
.question-list { display: grid; gap: 6px; }
.question-button { width: 100%; padding: 13px 4px; border: 1px solid transparent; background: transparent; cursor: pointer; text-align: left; }
.question-button:hover { border-color: var(--line); background: var(--card); }
.question-button.active { border-color: var(--ink); background: var(--ink); color: var(--paper); }
.question-button strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.question-button span { display: flex; justify-content: space-between; margin-top: 7px; color: var(--muted); font: 9px/1 var(--mono); }
.question-button.active span { color: color-mix(in srgb, var(--paper) 68%, transparent); }
.reader { min-width: 0; border: 1px solid var(--line); background: var(--card); box-shadow: var(--shadow); }
.reader-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px 15px; border-bottom: 1px solid var(--line); }
.reader-toolbar .spacer { flex: 1; }
.reader-toolbar button { padding: 8px 10px; border: 1px solid var(--line); background: transparent; cursor: pointer; font: 10px/1 var(--mono); }
.reader-toolbar button:hover, .reader-toolbar button.active { background: var(--acid); color: #171713; border-color: #171713; }
.reader-content { padding: clamp(24px, 4vw, 54px); }
.mastery-panel { display: grid; grid-template-columns: minmax(0, .72fr) minmax(0, 1.8fr); gap: 22px; align-items: center; width: 100%; min-width: 0; margin: 0 0 38px; padding: 18px; overflow: hidden; border: 1px solid var(--line); border-left: 5px solid #c74646; background: var(--paper); }
.mastery-panel.level-1 { border-left-color: #d98713; }
.mastery-panel.level-2 { border-left-color: var(--success); }
.mastery-copy { min-width: 0; }
.mastery-copy > span { display: block; margin-bottom: 8px; color: var(--muted); font: 600 9px/1 var(--mono); letter-spacing: .12em; }
.mastery-copy > strong { display: block; font-size: 21px; line-height: 1.2; }
.mastery-copy > small { display: block; margin-top: 7px; color: var(--muted); font-size: 11px; line-height: 1.55; }
.mastery-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; min-width: 0; }
.mastery-option { min-width: 0; width: 100%; display: flex; align-items: center; gap: 9px; padding: 12px; overflow: hidden; border: 1px solid var(--line); background: var(--card); text-align: left; cursor: pointer; transition: transform .18s ease, border-color .18s ease, background .18s ease; }
.mastery-option:hover { transform: translateY(-2px); border-color: var(--ink); }
.mastery-option > b { display: grid; place-items: center; width: 28px; height: 28px; flex: 0 0 auto; border-radius: 50%; background: var(--paper-2); font: 600 15px/1 var(--mono); }
.mastery-option span { min-width: 0; }
.mastery-option strong { display: block; overflow: hidden; font-size: 12px; line-height: 1.2; white-space: nowrap; text-overflow: ellipsis; }
.mastery-option small { display: block; margin-top: 5px; overflow: hidden; color: var(--muted); font-size: 9px; line-height: 1.3; white-space: nowrap; text-overflow: ellipsis; }
.mastery-option.mastery-0.active { border-color: #c74646; background: color-mix(in srgb, #c74646 12%, var(--card)); box-shadow: inset 0 0 0 1px #c74646; }
.mastery-option.mastery-1.active { border-color: #d98713; background: color-mix(in srgb, #d98713 13%, var(--card)); box-shadow: inset 0 0 0 1px #d98713; }
.mastery-option.mastery-2.active { border-color: var(--success); background: color-mix(in srgb, var(--success) 13%, var(--card)); box-shadow: inset 0 0 0 1px var(--success); }
.mastery-option.active > b { background: var(--ink); color: var(--paper); }
.reader-content > .question-no { color: var(--accent); font: 600 11px/1 var(--mono); letter-spacing: .08em; }
.reader-content > h1 { margin: 12px 0 30px; font-size: clamp(30px, 4vw, 50px); line-height: 1.18; letter-spacing: -.05em; }
.answer { font-size: 15px; line-height: 1.9; }
.answer.blurred { max-height: 280px; overflow: hidden; mask-image: linear-gradient(#000 30%, transparent); filter: blur(5px); user-select: none; }
.answer h2, .answer h3, .answer h4 { margin: 34px 0 13px; line-height: 1.35; letter-spacing: -.03em; }
.answer p { margin: 12px 0; }
.answer ul, .answer ol { padding-left: 23px; }
.answer li { margin: 7px 0; }
.answer blockquote { margin: 20px 0; padding: 14px 18px; border-left: 4px solid var(--accent); background: var(--accent-soft); }
.answer table { display: block; width: 100%; overflow-x: auto; border-collapse: collapse; margin: 20px 0; font-size: 13px; }
.answer th, .answer td { padding: 10px 12px; border: 1px solid var(--line); text-align: left; }
.answer code { padding: 2px 5px; background: var(--paper-2); font: 12px/1.5 var(--mono); }
.answer pre { position: relative; overflow: auto; margin: 20px 0; padding: 40px 22px 22px; background: #161713; color: #e9eadf; border-left: 4px solid var(--acid); }
.answer pre::before { content: attr(data-language); position: absolute; left: 12px; top: 12px; color: #77796f; font: 9px/1 var(--mono); }
.code-copy { position: absolute; top: 7px; right: 9px; padding: 5px 8px; border: 1px solid rgba(233, 234, 223, .2); border-radius: 3px; background: transparent; color: #b9bcb0; cursor: pointer; font: 10px/1 var(--mono); transition: color .18s ease, border-color .18s ease, background .18s ease; }
.code-copy:hover, .code-copy:focus-visible { border-color: var(--acid); background: rgba(216, 255, 62, .12); color: var(--acid); }
.code-copy.active { border-color: var(--acid); color: var(--acid); }
.answer pre code { padding: 0; background: transparent; color: inherit; font-size: 12px; line-height: 1.75; }
.code-token-comment { color: #858b7e; }
.code-token-string { color: #d7f58b; }
.code-token-number { color: #8bd8ff; }
.code-token-literal { color: #f6cf72; }
.code-token-keyword { color: #ff9b78; }
.code-token-function { color: #ffd166; }
.code-token-property { color: #b9e87d; }
.empty-state { padding: 80px 30px; text-align: center; border: 1px dashed var(--line); }
.empty-state strong { display: block; margin-bottom: 10px; font-size: 25px; }
.empty-state p { color: var(--muted); }
.command-hint { position: fixed; left: 50%; bottom: 24px; z-index: 30; padding: 11px 15px; transform: translate(-50%, 20px); opacity: 0; background: var(--ink); color: var(--paper); font: 11px/1 var(--mono); transition: .2s ease; pointer-events: none; }
.command-hint.show { opacity: 1; transform: translate(-50%, 0); }
@media (max-width: 1050px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-card:nth-child(2) { border-right: 0; }
  .stat-card:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
}
@media (max-width: 1180px) {
  .library-layout { grid-template-columns: 1fr; }
  .question-panel { position: static; max-height: 360px; }
  .mastery-panel { grid-template-columns: 1fr; }
}
@media (max-width: 800px) {
  .app-shell, .app-shell.sidebar-collapsed { --sidebar: 268px; display: block; }
  .sidebar, .sidebar-collapsed .sidebar { width: min(86vw, 268px); padding: 28px 20px 20px; transform: translateX(-105%); transition: transform .25s ease; box-shadow: 20px 0 50px rgba(0,0,0,.2); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-collapse { display: none; }
  .sidebar-collapsed .brand { justify-content: flex-start; padding: 0 8px 34px; }
  .sidebar-collapsed .brand > div:last-child { display: block; }
  .sidebar-collapsed .nav-item { justify-content: flex-start; gap: 13px; padding: 12px 13px; font-size: inherit; }
  .sidebar-collapsed .nav-item::after { right: 13px; width: 6px; height: 6px; }
  .sidebar-collapsed .sidebar-footer > p { display: block; }
  .sidebar-collapsed .streak-card { justify-content: flex-start; padding: 13px; }
  .sidebar-collapsed .streak-card div { display: block; }
  .main { width: 100%; }
  .mobile-menu { display: grid; flex: 0 0 auto; }
  .text-button { display: none; }
  .view { padding-inline: 18px; }
  .collection-grid { grid-template-columns: 1fr; }
  .library-layout { grid-template-columns: 1fr; }
  .question-panel { max-height: 330px; }
  .mastery-options { grid-template-columns: 1fr; }
  .mastery-option small { white-space: normal; }
}
@media (max-width: 520px) {
  .topbar { padding-inline: 12px; gap: 8px; }
  .search-wrap { padding-inline: 10px; }
  .search-wrap kbd { display: none; }
  .stat-grid { grid-template-columns: 1fr; }
  .stat-card { border-right: 0; border-bottom: 1px solid var(--line); }
  .hero::after { display: none; }
  .library-header { align-items: flex-start; }
  .library-count { display: none; }
  .reader-toolbar .spacer { display: none; }
  .reader-toolbar button { flex: 1 1 auto; }
  .reader-content { padding: 24px 18px; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
