:root {
  color-scheme: light dark;
  --canvas: #f7f8f7;
  --surface: #ffffff;
  --ink: #202827;
  --muted: #5a6864;
  --line: #d4ddda;
  --accent: #087c6c;
  --accent-soft: #dcefe9;
  --code-bg: #f0f4f2;
  --focus: #b9472f;
  --shadow: 0 12px 30px rgb(26 43 37 / 8%);
  font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --canvas: #151a19;
    --surface: #1e2523;
    --ink: #eef4f1;
    --muted: #b8c5bf;
    --line: #3c4945;
    --accent: #5ec6b3;
    --accent-soft: #203f39;
    --code-bg: #18211f;
    --focus: #ff937e;
    --shadow: none;
  }
}

:root[data-theme="dark"] {
  --canvas: #151a19;
  --surface: #1e2523;
  --ink: #eef4f1;
  --muted: #b8c5bf;
  --line: #3c4945;
  --accent: #5ec6b3;
  --accent-soft: #203f39;
  --code-bg: #18211f;
  --focus: #ff937e;
  --shadow: none;
}

* { box-sizing: border-box; }
html { background: var(--canvas); color: var(--ink); }
body { margin: 0; min-width: 320px; font-size: 16px; line-height: 1.85; }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
a:hover { text-decoration-thickness: 2px; }
button, input { font: inherit; }
button { color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.skip-link { position: fixed; top: -5rem; left: 1rem; z-index: 10; padding: 0.4rem 0.75rem; background: var(--ink); color: var(--surface); }
.skip-link:focus { top: 1rem; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.site-header { position: sticky; top: 0; z-index: 4; display: flex; align-items: center; justify-content: space-between; min-height: 3.75rem; padding: 0 1rem; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--canvas) 92%, transparent); backdrop-filter: blur(10px); }
.brand { color: var(--ink); font-size: 1.05rem; font-weight: 750; text-decoration: none; }
.header-actions { display: flex; align-items: center; gap: 0.4rem; }
.header-actions button, .header-actions a, .mobile-nav > summary { display: inline-flex; align-items: center; justify-content: center; min-height: 2.5rem; padding: 0.3rem 0.55rem; border: 1px solid var(--line); background: var(--surface); cursor: pointer; }
.header-actions a { color: var(--ink); text-decoration: none; }
.header-icon { width: 1.25rem; height: 1.25rem; display: block; }
.mobile-nav { position: relative; }
.mobile-nav > .chapter-nav { position: absolute; right: 0; width: min(19rem, calc(100vw - 2rem)); max-height: 75vh; overflow: auto; padding: 0.8rem; border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow); }

.site-shell { display: grid; grid-template-columns: minmax(0, 1fr); max-width: 92rem; margin: 0 auto; }
.book-sidebar, .page-outline { display: none; }
.main-content { min-width: 0; padding: 2.25rem 1rem 4rem; }
.prose { max-width: 45rem; margin: 0 auto; }
.chapter-header { margin-bottom: 2.5rem; border-bottom: 1px solid var(--line); }
.chapter-kicker { margin: 0; color: var(--accent); font-size: 0.9rem; font-weight: 700; }
h1, h2, h3 { color: var(--ink); line-height: 1.35; letter-spacing: 0; scroll-margin-top: 5rem; }
h1 { margin: 0.35rem 0 0.8rem; font-size: 2rem; }
h2 { margin-top: 2.75rem; font-size: 1.45rem; }
h3 { margin-top: 2.1rem; font-size: 1.15rem; }
.chapter-summary { margin: 0 0 1.5rem; color: var(--muted); }
.prose p, .prose li { max-width: 45rem; }
.prose img, .prose svg { display: block; max-width: 100%; height: auto; margin: 1.5rem auto; }
.prose img[src="/cppbook.jpg"] { max-width: min(22rem, 82vw); }
.prose img[src^="/media/diagrams/"] { border: 1px solid var(--line); background: #fff; }
.prose table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; }
.prose th, .prose td { padding: 0.55rem 0.7rem; border: 1px solid var(--line); text-align: left; }
.prose blockquote { margin: 1.5rem 0; padding: 0.75rem 1rem; border-left: 4px solid var(--accent); background: var(--accent-soft); }
.prose details { margin: 1.25rem 0; padding: 0.6rem 0.9rem; border: 1px solid var(--line); background: var(--surface); }
.prose summary { cursor: pointer; font-weight: 700; }
pre { overflow-x: auto; margin: 1.4rem 0; padding: 1rem; border: 1px solid var(--line); background: var(--code-bg); font-size: 0.88rem; line-height: 1.65; }
code { font-family: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace; }
:not(pre) > code { padding: 0.08em 0.28em; background: var(--code-bg); }
pre.shiki { background: var(--code-bg) !important; }
pre.shiki span { color: var(--shiki-light) !important; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) pre.shiki span { color: var(--shiki-dark) !important; } }
:root[data-theme="dark"] pre.shiki span { color: var(--shiki-dark) !important; }
.page-outline { position: sticky; top: 5.25rem; align-self: start; max-height: calc(100vh - 6rem); overflow: auto; padding: 1.25rem 1rem; border-left: 1px solid var(--line); color: var(--muted); font-size: 0.88rem; }
.page-outline p { margin-top: 0; font-weight: 700; }
.page-outline ol { margin: 0; padding-left: 1.1rem; }
.page-outline li { margin: 0.4rem 0; }
.page-outline a { color: inherit; }
.search-dialog { width: min(42rem, calc(100vw - 2rem)); max-height: min(42rem, calc(100vh - 2rem)); padding: 0; border: 1px solid var(--line); background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.search-dialog::backdrop { background: rgb(0 0 0 / 40%); }
.search-panel { padding: 1.25rem; }
.search-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.search-heading h2 { margin: 0; font-size: 1.2rem; }
.search-heading button { border: 0; background: none; text-decoration: underline; cursor: pointer; }
#search-input { width: 100%; margin: 1rem 0; padding: 0.65rem 0.75rem; border: 1px solid var(--line); background: var(--canvas); color: var(--ink); }
#search-results ol { padding-left: 1.2rem; }
#search-results p { margin-top: 0.2rem; color: var(--muted); font-size: 0.92rem; }

@media (min-width: 768px) {
  body { font-size: 17px; }
  .site-header { padding: 0 1.5rem; }
  .main-content { padding: 3rem 2rem 5rem; }
  h1 { font-size: 2.3rem; }
}

@media (min-width: 1024px) {
  .mobile-nav { display: none; }
  .site-shell { grid-template-columns: 16rem minmax(0, 1fr); }
  .book-sidebar { display: block; position: sticky; top: 3.75rem; align-self: start; height: calc(100vh - 3.75rem); overflow: auto; padding: 1.5rem 1rem 2rem; border-right: 1px solid var(--line); }
  .chapter-nav details { margin-bottom: 1rem; }
  .chapter-nav summary { cursor: pointer; font-weight: 700; }
  .chapter-nav ol { margin: 0.35rem 0 0; padding-left: 1.15rem; font-size: 0.9rem; }
  .chapter-nav li { margin: 0.4rem 0; }
  .chapter-nav a[aria-current="page"] { color: var(--ink); font-weight: 750; text-decoration-color: var(--focus); }
}

@media (min-width: 1280px) {
  .site-shell { grid-template-columns: 16rem minmax(0, 1fr) 14rem; }
  .page-outline { display: block; }
}

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