:root {
  color-scheme: light;
  --bg: #f7f8fa;
  --panel: #ffffff;
  --panel-soft: #f1f4f7;
  --ink: #1e252d;
  --muted: #637083;
  --line: #d9e0e8;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --warn: #9a5b00;
  --code-bg: #17212b;
  --code-ink: #eaf1f8;
  --shadow: 0 14px 35px rgba(31, 42, 55, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 300px;
  overflow: auto;
  border-right: 1px solid var(--line);
  background: #fbfcfd;
  padding: 22px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 24px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--ink);
  color: white;
  font-weight: 750;
}

.brand h1 {
  margin: 0;
  font-size: 19px;
  line-height: 1.1;
}

.brand p,
.eyebrow,
.meta,
.search span,
#resultCount {
  color: var(--muted);
  font-size: 13px;
}

.brand p {
  margin: 4px 0 0;
}

.search {
  display: grid;
  gap: 7px;
  margin-bottom: 20px;
}

.search input,
select {
  width: 100%;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  padding: 0 12px;
  outline: none;
}

.search input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.15);
}

.topic-nav {
  display: grid;
  gap: 4px;
}

.topic-button {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  padding: 10px 11px;
  text-align: left;
}

.topic-button:hover,
.topic-button.active {
  background: #e8f3f1;
  color: var(--accent-strong);
}

.topic-group {
  display: grid;
  gap: 3px;
}

.section-tree {
  display: grid;
  gap: 2px;
  margin: -1px 0 6px 12px;
  padding-left: 11px;
  border-left: 1px solid var(--line);
}

.section-button {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 7px 9px;
  text-align: left;
  font-size: 13px;
}

.section-button:hover,
.section-button.active {
  background: #eef6f4;
  color: var(--accent-strong);
}

.count {
  color: var(--muted);
  font-size: 12px;
}

.workspace {
  margin-left: 300px;
  padding: 28px;
}

.summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 126px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 8px;
  font-weight: 700;
  text-transform: uppercase;
}

.summary h2 {
  margin: 0;
  max-width: 680px;
  font-size: 34px;
  line-height: 1.08;
  letter-spacing: 0;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(92px, 1fr));
  gap: 10px;
}

.stat {
  min-width: 92px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 12px;
}

.stat strong {
  display: block;
  font-size: 24px;
  line-height: 1;
}

.stat span {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin: 0 0 16px;
}

#sectionSelect {
  max-width: 280px;
}

.content-shell {
  display: grid;
  grid-template-columns: minmax(300px, 390px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.note-list,
.reader {
  min-height: 520px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.note-list {
  overflow: hidden;
}

.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.list-header h3 {
  margin: 0;
  font-size: 16px;
}

#noteList {
  max-height: calc(100vh - 260px);
  overflow: auto;
}

.note-item {
  display: block;
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: white;
  color: inherit;
  cursor: pointer;
  padding: 14px 16px;
  text-align: left;
}

.note-item.topic-overview {
  background: #f1f8f7;
}

.note-item:hover,
.note-item.active {
  background: #f1f8f7;
}

.note-item strong {
  display: block;
  margin-bottom: 5px;
  font-size: 14px;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.badge {
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: var(--panel-soft);
  padding: 3px 8px;
  font-size: 12px;
}

.subtopic-grid {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.subtopic-card {
  display: grid;
  gap: 6px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: inherit;
  cursor: pointer;
  padding: 14px;
  text-align: left;
}

.subtopic-card:hover {
  border-color: rgba(15, 118, 110, 0.45);
  background: #f7fbfa;
}

.subtopic-card strong {
  font-size: 15px;
}

.subtopic-card > span:not(.badges) {
  color: var(--muted);
  font-size: 13px;
}

.reader {
  padding: 28px;
  overflow: auto;
}

.reader-header {
  margin-bottom: 22px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.reader h2 {
  margin: 0 0 10px;
  font-size: 28px;
  line-height: 1.18;
}

.reader h1,
.reader h3,
.reader h4 {
  margin: 24px 0 10px;
}

.reader p,
.reader li,
.reader blockquote {
  line-height: 1.65;
}

.reader a {
  color: var(--accent-strong);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  overflow-wrap: anywhere;
}

.reader pre {
  overflow: auto;
  border-radius: 8px;
  background: var(--code-bg);
  color: var(--code-ink);
  padding: 16px;
}

.reader pre code.hljs {
  background: transparent;
  padding: 0;
}

.tok-keyword {
  color: #ff7b72;
}

.tok-string {
  color: #a5d6ff;
}

.tok-number {
  color: #79c0ff;
}

.tok-comment {
  color: #8b949e;
  font-style: italic;
}

.tok-builtin {
  color: #d2a8ff;
}

.reader code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px;
}

.reader :not(pre) > code {
  border-radius: 5px;
  background: #e9eef3;
  color: #27323d;
  padding: 2px 5px;
}

.reader blockquote {
  margin: 16px 0;
  border-left: 4px solid var(--accent);
  background: #eff7f5;
  padding: 10px 14px;
  color: #334048;
}

.empty {
  padding: 24px;
  color: var(--muted);
}

@media (max-width: 980px) {
  .sidebar {
    position: static;
    width: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .workspace {
    margin-left: 0;
    padding: 20px;
  }

  .summary {
    align-items: stretch;
    flex-direction: column;
  }

  .summary h2 {
    font-size: 28px;
  }

  .content-shell {
    grid-template-columns: 1fr;
  }

  #noteList {
    max-height: 360px;
  }

  #sectionSelect {
    max-width: none;
  }
}

@media (max-width: 560px) {
  .stats {
    grid-template-columns: 1fr;
  }

  .reader {
    padding: 18px;
  }
}
