:root {
  --bg: #fbfbfa;
  --surface: #ffffff;
  --sidebar: #f3f3f1;
  --text: #1d1f22;
  --muted: #5b6068;
  --border: #dcdcd8;
  --accent: #b4441c;
  --accent-soft: #fbeee8;
  --code-bg: #f0f0ed;
  --note: #e8f1fb;
  --note-border: #3d78b8;
  --warn: #fdf4e3;
  --warn-border: #c58a1a;
  --sidebar-width: 17rem;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a;
    --surface: #1c1f23;
    --sidebar: #1a1c20;
    --text: #e6e6e3;
    --muted: #a3a8b0;
    --border: #33373d;
    --accent: #f08a5d;
    --accent-soft: #3a261d;
    --code-bg: #24282d;
    --note: #1b2836;
    --note-border: #5d97d3;
    --warn: #31281a;
    --warn-border: #d6a245;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { scroll-padding-top: 4.5rem; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

a { color: var(--accent); }
a:hover { text-decoration-thickness: 2px; }

.skip { position: absolute; left: -999px; }
.skip:focus { left: 1rem; top: 1rem; z-index: 10; background: var(--surface); padding: .5rem; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 1rem;
  height: 3.5rem; padding: 0 1rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; color: var(--text); text-decoration: none; }
.brand span { font-weight: 400; color: var(--muted); }
.repo { margin-left: auto; font-size: .9rem; }
.menu {
  display: none; font: inherit; font-size: .9rem;
  background: none; color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; padding: .25rem .6rem;
}

.layout { display: flex; }

.sidebar {
  position: sticky; top: 3.5rem; flex: 0 0 var(--sidebar-width);
  height: calc(100vh - 3.5rem); overflow-y: auto;
  padding: 1rem 1rem 2rem; background: var(--sidebar); border-right: 1px solid var(--border);
}
.sidebar .nav-group {
  margin: 1.2rem 0 .3rem; font-size: .75rem; font-weight: 700;
  letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
}
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar a {
  display: block; padding: .3rem .6rem; border-radius: 6px;
  color: var(--text); text-decoration: none; font-size: .95rem;
}
.sidebar a:hover { background: var(--accent-soft); }
.sidebar a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

main { flex: 1; min-width: 0; padding: 2rem 2.5rem 3rem; max-width: 56rem; }

article h1 { font-size: 2rem; line-height: 1.25; margin: 0 0 1rem; }
article h2 { font-size: 1.45rem; margin: 2.4rem 0 .8rem; padding-top: .6rem; border-top: 1px solid var(--border); }
article h3 { font-size: 1.12rem; margin: 1.8rem 0 .5rem; }
article .lead { font-size: 1.12rem; color: var(--muted); }

code, kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .88em; background: var(--code-bg); border-radius: 4px; padding: .1em .35em;
}
kbd { border: 1px solid var(--border); border-bottom-width: 2px; }
pre { background: var(--code-bg); border-radius: 8px; padding: 1rem; overflow-x: auto; }
pre code { background: none; padding: 0; }

table { width: 100%; border-collapse: collapse; margin: 1rem 0; font-size: .94rem; display: block; overflow-x: auto; }
th, td { text-align: left; vertical-align: top; padding: .5rem .7rem; border-bottom: 1px solid var(--border); }
th { background: var(--sidebar); font-weight: 600; }

.note, .warning {
  margin: 1.2rem 0; padding: .8rem 1rem; border-left: 4px solid; border-radius: 0 8px 8px 0;
}
.note { background: var(--note); border-color: var(--note-border); }
.warning { background: var(--warn); border-color: var(--warn-border); }
.note > :first-child, .warning > :first-child { margin-top: 0; }
.note > :last-child, .warning > :last-child { margin-bottom: 0; }

ol.steps > li { margin-bottom: .5rem; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: 1rem; margin: 1.5rem 0; }
.cards a {
  display: block; padding: 1rem; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); text-decoration: none;
}
.cards a:hover { border-color: var(--accent); }
.cards strong { display: block; color: var(--accent); margin-bottom: .25rem; }

figure { margin: 1.5rem 0; }
figure img { max-width: 100%; height: auto; border: 1px solid var(--border); border-radius: 8px; }
figcaption { font-size: .88rem; color: var(--muted); }

.toc {
  margin: 1.5rem 0; padding: .8rem 1rem; border: 1px solid var(--border);
  border-radius: 10px; background: var(--surface); font-size: .92rem;
}
.toc p { margin: 0 0 .3rem; font-weight: 600; }
.toc ul { margin: 0; padding-left: 1.2rem; columns: 2; }

.pager { display: flex; gap: 1rem; margin-top: 3rem; }
.pager a {
  flex: 1; padding: .8rem 1rem; border: 1px solid var(--border); border-radius: 10px;
  text-decoration: none; background: var(--surface);
}
.pager a span { display: block; font-size: .8rem; color: var(--muted); }
.pager .next { text-align: right; }

footer { margin-top: 2.5rem; font-size: .85rem; color: var(--muted); }

@media (max-width: 860px) {
  .menu { display: inline-block; }
  .repo { display: none; }
  .sidebar {
    display: none; position: fixed; top: 3.5rem; left: 0; right: 0; z-index: 4;
    width: auto; height: calc(100vh - 3.5rem);
  }
  .sidebar.open { display: block; }
  main { padding: 1.25rem 1rem 2.5rem; }
  .toc ul { columns: 1; }
  .pager { flex-direction: column; }
}

figure.narrow { max-width: 22rem; }
figure.inline-widget { max-width: 30rem; margin: .8rem 0 1rem; }
.gallery {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
  gap: 1rem; margin: 1.2rem 0;
}
.gallery figure { margin: 0; }
.gallery figcaption { margin-top: .3rem; }
.pair { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); gap: 1rem; align-items: start; }
.pair figure { margin: 0; }
.data-note { font-size: .88rem; color: var(--muted); border-left: 3px solid var(--border); padding-left: .8rem; }
