:root {
  --bg: #f5f5f5;
  --panel: #ffffff;
  --ink: #171717;
  --muted: #5c5c5c;
  --accent: #1a1a1a;
  --accent-soft: #ebebeb;
  --border: #dedede;
  --shadow: 0 12px 50px rgba(0, 0, 0, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", sans-serif;
  line-height: 1.7;
}

code {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", sans-serif;
}

h1, h2, h3 {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", sans-serif;
  margin: 0 0 12px;
  letter-spacing: 0.02em;
}

p {
  margin: 0 0 14px;
  color: var(--muted);
}

.note-block > p {
  text-align: justify;
  text-justify: inter-word;
  hyphens: auto;
}

.hero p {
  text-align: justify;
  text-justify: inter-word;
  hyphens: auto;
}

.about-author {
  max-width: 900px;
}

.memory-photos {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin: 20px 0;
}

.memory-photos figure {
  margin: 0;
}

.memory-photos img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  padding: 12px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 12px;
}

.memory-photos figcaption {
  margin-top: 8px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.45;
}

a,
a:visited {
  color: #171717;
  font-weight: 600;
}

.page {
  display: grid;
  grid-template-columns: minmax(260px, 350px) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 32px 24px;
  background: #111111;
  color: #f5f5f5;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

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

.eyebrow {
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #6b6b6b;
  margin-bottom: 8px;
}

.brand .title {
  font-size: 20px;
  margin: 0;
  color: #f0f0f0;
}

.brand .eyebrow {
  color: #a3a3a3;
  margin: 0 0 4px;
}

.toc {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
}

.sidebar-footer {
  margin: auto 0 0;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
  color: #a3a3a3;
  font-size: 11px;
  line-height: 1.5;
}

.toc-nested {
  display: flex;
  flex-direction: column;
  margin-left: 10px;
  gap: 6px;
}

.toc-level-3 {
  margin-left: 14px;
  padding-left: 8px;
  border-left: 1px solid rgba(255, 255, 255, 0.18);
}

.toc-number {
  color: #a3a3a3;
  font-size: 0.85em;
  font-variant-numeric: tabular-nums;
  flex: 0 0 auto;
}

.toc-title {
  min-width: 0;
}

.toc .section-label {
  margin: 0 0 6px;
  color: #cbcbcb;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.toc a {
  color: #ededed;
  text-decoration: none;
  font-weight: 600;
  padding: 8px 10px;
  border-radius: 10px;
  transition: background 0.2s, color 0.2s;
  display: flex;
  align-items: baseline;
  gap: 0.4em;
}

.toc a.active {
  background: rgba(255, 255, 255, 0.16);
  color: #ffffff;
}

.toc a:hover {
  background: rgba(255, 255, 255, 0.10);
  color: #ffffff;
}

.toc-unavailable {
  color: #8a8a8a;
  padding: 8px 10px;
  display: flex;
  align-items: baseline;
  gap: 0.4em;
  cursor: not-allowed;
}

.hint {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 14px 16px;
}

.hint-title {
  margin: 0 0 8px;
  font-weight: 600;
  color: #e2e2e2;
}

.hint ul {
  margin: 0;
  padding-left: 18px;
  color: #cbcbcb;
  line-height: 1.6;
}

.content {
  min-width: 0;
  padding: 48px min(8vw, 120px);
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.hero {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 18px;
  align-items: start;
}

.sidebar[data-current="index"] ~ .content .hero {
  max-width: 900px;
  grid-template-columns: 1fr;
}

.label {
  display: inline-block;
  padding: 8px 12px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 12px;
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 12px;
}

.lede {
  font-size: 18px;
  color: var(--ink);
}

.card {
  background: var(--panel);
  border-radius: 18px;
  padding: 18px 20px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.sidebar[data-current="ch1"] ~ .content .note-block > .card,
.sidebar[data-current="ch2"] ~ .content .note-block > .card {
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.stats {
  align-self: stretch;
}

.stats .stat-title {
  margin: 0 0 10px;
  font-weight: 700;
  color: var(--ink);
}

.stats ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
}

.note-block {
  background: var(--panel);
  border-radius: 24px;
  padding: 26px 28px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.callout {
  background: var(--accent-soft);
  border-radius: 14px;
  padding: 14px 16px;
  border: 1px solid rgba(0, 0, 0, 0.14);
}

.callout-title {
  margin: 0 0 6px;
  font-weight: 700;
  color: var(--accent);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}

pre {
  background: #171717;
  color: #f5f5f5;
  border-radius: 12px;
  padding: 12px;
  overflow-x: auto;
  margin: 10px 0 0;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

ul, ol {
  color: var(--ink);
}

.math-block {
  background: #f5f5f5;
  border-radius: 14px;
  padding: 14px 16px;
  margin: 12px 0;
  border: 1px solid #dedede;
  overflow-x: auto;
  overflow-y: hidden;
}

.figure {
  margin: 18px 0;
  text-align: center;
}

.figure img {
  max-width: 100%;
  height: auto;
  width: 70%;
  min-width: 240px;
  display: block;
  margin: 0 auto;
  padding: 24px;
  background: #ffffff;
  border-radius: 14px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.figure-compact img {
  width: 35%;
}

.figure-medium img {
  width: 55%;
}

.figure-sixty img {
  width: 60%;
}

.figure-small img {
  width: 30%;
}

.sidebar[data-current="ch3-4-1"] ~ .content .figure img {
  width: 30%;
}

.sidebar[data-current="ch3-4-1"] ~ .content img[src="images/fig3-4-1.svg"],
.sidebar[data-current="ch3-4-1"] ~ .content img[src="images/fig3-4-3.svg"],
.sidebar[data-current="ch3-4-1"] ~ .content img[src="images/fig3-4-5.svg"] {
  width: 75%;
}

img[src="images/fig3-3-2.svg"] {
  width: 30%;
}

img[src="images/fig3-3-4.svg"],
img[src="images/fig3-3-5.svg"] {
  width: 30%;
}

.figure figcaption,
.figure caption {
  display: block;
  margin-top: 10px;
  font-size: 14px;
  color: var(--muted);
}

.table-wrap {
  overflow-x: auto;
  margin: 18px 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--border);
}

table caption {
  caption-side: top;
  text-align: left;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 14px;
}

th,
td {
  padding: 10px 12px;
  border: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

th {
  background: #f0f0f0;
  font-weight: 600;
}

.subnote {
  color: #6b6b6b;
  font-size: 14px;
}

.unavailable-link {
  color: var(--muted);
  cursor: not-allowed;
}

.references-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.references-list li {
  position: relative;
  padding-left: 1.25em;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.references-list li::before {
  content: "•";
  position: absolute;
  left: 0;
  color: var(--ink);
}

.longform {
  margin-top: 12px;
}

.raw-text {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: inherit;
  color: var(--muted);
  line-height: 1.7;
}

.steps {
  margin: 12px 0 0;
  padding-left: 18px;
}

.steps li {
  margin-bottom: 6px;
}

.nav-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.btn {
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--ink);
  text-decoration: none;
  box-shadow: var(--shadow);
  transition: transform 0.1s ease, box-shadow 0.2s ease;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
}

.btn.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

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

  .sidebar {
    position: relative;
    height: auto;
    border-bottom: 1px solid #333333;
  }

  .toc {
    overflow: visible;
  }
}

@media (max-width: 768px) {
  .content {
    padding: 28px 18px;
  }

  .note-block {
    padding: 20px;
    border-radius: 18px;
  }

  .hero {
    grid-template-columns: 1fr;
  }

  .memory-photos {
    grid-template-columns: 1fr;
  }

  .figure img,
  .sidebar[data-current="ch3-4-1"] ~ .content .figure img,
  .sidebar[data-current="ch3-4-1"] ~ .content img[src] {
    width: 100%;
    min-width: 0;
    padding: 12px;
  }

  .nav-buttons .btn {
    flex: 1 1 180px;
    text-align: center;
  }
}
