:root {
  --bg: #f7f7f6;
  --surface: #ffffff;
  --surface-subtle: #f9fafb;
  --text: #0f172a;
  --muted: #475569;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --accent: #111827;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: Manrope, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.72;
}

a {
  color: #0f172a;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
}

.topbar-inner {
  max-width: 1360px;
  margin: 0 auto;
  padding: 14px clamp(16px, 2vw, 28px);
  display: grid;
  gap: 12px;
}

.brand {
  font-family: 'Cormorant Garamond', ui-serif, Georgia, serif;
  font-size: clamp(1.24rem, 1.8vw, 1.5rem);
  color: var(--accent);
  letter-spacing: 0.01em;
}

.brand a {
  color: inherit;
  text-decoration: none;
}

.macro-nav {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  align-items: stretch;
  gap: 6px;
  width: 100%;
}

.macro-nav-compact {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 10px;
}

.macro-nav-left,
.macro-nav-right {
  display: grid;
  grid-template-columns: repeat(2, minmax(96px, 132px));
  gap: 6px;
}

.macro-nav-right {
  margin-left: auto;
}

.macro-link {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: #334155;
  font-size: clamp(0.56rem, 0.14vw + 0.5rem, 0.68rem);
  font-weight: 700;
  letter-spacing: 0.03em;
  line-height: 1.12;
  text-transform: uppercase;
  text-decoration: none;
  transition: border-color 0.2s ease, background-color 0.2s ease, color 0.2s ease;
}

.macro-link:hover {
  border-color: var(--line-strong);
  background: var(--surface-subtle);
}

.macro-link.active {
  background: #0f172a;
  border-color: #0f172a;
  color: #ffffff;
}

.page-wrap {
  max-width: 1360px;
  margin: 0 auto;
  padding: clamp(16px, 2vw, 30px);
  display: block;
}

.sidebar {
  position: sticky;
  top: 136px;
  align-self: start;
  max-height: calc(100vh - 156px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  padding: 14px;
}

.sidebar h2 {
  margin: 0 0 8px;
  font-family: 'Cormorant Garamond', ui-serif, Georgia, serif;
  font-size: 1.34rem;
  color: var(--accent);
}

.sidebar p {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.84rem;
  letter-spacing: 0.02em;
}

.subtopics {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.subtopics a {
  display: block;
  color: #1f2937;
  text-decoration: none;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 9px;
  font-size: 0.9rem;
  line-height: 1.35;
  transition: border-color 0.2s ease, background-color 0.2s ease;
}

.subtopics a:hover,
.subtopics a.active {
  border-color: var(--line);
  background: var(--surface-subtle);
}

.content {
  display: grid;
  gap: 14px;
}

section {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  padding: clamp(18px, 2vw, 28px);
  box-shadow: none;
}

.macro-hero h1,
h3,
h4 {
  margin-top: 0;
  color: var(--accent);
  letter-spacing: 0.01em;
  font-family: 'Cormorant Garamond', ui-serif, Georgia, serif;
}

.macro-hero h1 {
  margin-bottom: 8px;
  text-transform: none;
  font-size: clamp(1.72rem, 2.4vw, 2.28rem);
}

h3 {
  margin-bottom: 0.9rem;
  font-size: clamp(1.2rem, 1.7vw, 1.56rem);
}

p,
li {
  color: #1f2937;
  font-size: 1rem;
}

.chapter-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.chapter-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #ffffff;
  padding: 12px;
  text-decoration: none;
  display: block;
}

.chapter-card:hover {
  border-color: var(--line-strong);
  background: var(--surface-subtle);
}

.chapter-card small {
  display: block;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  font-weight: 700;
}

.chapter-card strong {
  display: block;
  color: var(--text);
  font-size: 1rem;
  line-height: 1.4;
  margin-top: 6px;
}

.chapter-card span {
  display: block;
  margin-top: 8px;
  font-size: 0.83rem;
  color: var(--muted);
}

.page-frame {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #ffffff;
  padding: 10px;
}

.page-frame img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 8px;
  border: 1px solid #e9edf3;
  background: #ffffff;
}

.meta-line {
  color: var(--muted);
  font-size: 0.9rem;
}

.site-footer {
  margin-top: clamp(32px, 5vw, 72px);
  border-top: 1px solid var(--line);
  background: #ffffff;
}

.site-footer-inner {
  max-width: 1360px;
  margin: 0 auto;
  padding: clamp(20px, 2.2vw, 34px) clamp(16px, 2vw, 28px);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: #64748b;
  font-size: 0.9rem;
}

.site-footer-copy {
  margin: 0;
}

.site-footer-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.site-footer-links a {
  color: #64748b;
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.site-footer-links a:hover {
  color: #0f172a;
  border-bottom-color: #0f172a;
}

.chapter-scroll {
  background: #ffffff;
}

.chapter-scroll .page-wrap {
  padding-top: 12px;
  padding-bottom: 28px;
}

.chapter-scroll .content {
  gap: 0;
}

.chapter-scroll section {
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 0;
}

.chapter-scroll .macro-hero {
  display: none;
}

.chapter-scroll .macro-hero h1 {
  margin-bottom: 4px;
  display: block;
  width: 100%;
  font-size: clamp(1.34rem, 1.9vw, 1.72rem);
  line-height: 1.2;
  white-space: nowrap;
  overflow: visible;
}

.chapter-scroll .macro-hero p {
  display: none;
}

.chapter-scroll h3 {
  display: none;
}

.chapter-scroll .page-frame {
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 0;
}

.chapter-scroll section.page-note {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #ffffff;
  padding: clamp(20px, 2.2vw, 32px);
  margin-bottom: 18px;
}

.note-kicker {
  margin: 0 0 8px;
  color: #64748b;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 700;
}

.page-note h2 {
  margin: 0 0 10px;
  font-family: "Cormorant Garamond", ui-serif, Georgia, serif;
  font-size: clamp(1.4rem, 2vw, 1.8rem);
  color: #111827;
  line-height: 1.15;
}

.page-note h4 {
  margin: 0 0 8px;
  font-family: "Cormorant Garamond", ui-serif, Georgia, serif;
  font-size: 1.15rem;
  color: #111827;
}

.page-note p {
  margin: 0 0 12px;
  color: #1f2937;
  font-size: 0.98rem;
  line-height: 1.65;
}

.page-note ul {
  margin: 0;
  padding-left: 1.1rem;
  display: grid;
  gap: 6px;
}

.page-note li {
  color: #1f2937;
  font-size: 0.95rem;
  line-height: 1.55;
}

.note-grid {
  display: grid;
  gap: 12px;
  margin: 14px 0 16px;
}

.instrument-card {
  border: 1px solid #dce4ee;
  border-radius: 12px;
  background: #fbfcfe;
  padding: 14px;
  margin: 0 0 16px;
}

.instrument-card > h4 {
  margin: 0 0 10px;
  color: #b91c1c;
}

.instrument-card .note-grid {
  margin: 0;
}

.note-grid.two-col {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.note-block {
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  background: #f8fafc;
  padding: 12px 14px;
}

.note-divider {
  height: 1px;
  background: #e2e8f0;
  margin: 14px 0 16px;
}

.chapter-scroll .page-frame img {
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

  .chapter-scroll .page-svg-inline {
    display: block;
    width: 96%;
    height: auto;
    max-width: 96%;
  margin: 0 auto;
}

  .chapter-scroll .page-svg-inline text,
  .chapter-scroll .page-svg-inline tspan {
    -webkit-user-select: text;
    user-select: text;
  }

  .note-grid.two-col {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 768px) {
  .topbar-inner {
    padding: 10px 14px;
    gap: 10px;
  }

  .macro-nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .macro-nav-compact {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
    gap: 8px;
  }

  .macro-nav-left,
  .macro-nav-right {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .macro-link {
    min-height: 32px;
    padding: 6px 7px;
    font-size: 0.6rem;
  }

  section {
    padding: 16px;
    border-radius: 10px;
  }

  h3 {
    line-height: 1.28;
  }

  .site-footer-inner {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
}
