/* ─── CSS Custom Properties ─────────────────────────────────────────────── */

:root {
  --bg:          #ffffff;
  --surface:     #ffffff;
  --text:        #3c3c43;
  --text-muted:  #6a6a71;
  --accent:      #3451b2;
  --accent-dim:  #3a5ccc;
  --accent-soft: rgba(52, 81, 178, .1);
  --border:      #e2e2e3;
  --code-bg:     #f6f6f7;
  --mark-bg:     #fef08a;
  --shadow:      0 1px 2px rgba(0,0,0,.04), 0 1px 2px rgba(0,0,0,.06);
  --nav-w:       268px;
  --toc-w:       220px;
  --radius:      8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:          #1b1b1f;
    --surface:     #1b1b1f;
    --text:        #dfdfd6;
    --text-muted:  #98989f;
    --accent:      #a8b1ff;
    --accent-dim:  #8591f0;
    --accent-soft: rgba(168, 177, 255, .16);
    --border:      #2e2e32;
    --code-bg:     #161618;
    --mark-bg:     #78350f;
    --shadow:      0 1px 2px rgba(0,0,0,.24), 0 2px 8px rgba(0,0,0,.24);
  }
}

html.theme-light {
  --bg:          #ffffff;
  --surface:     #ffffff;
  --text:        #3c3c43;
  --text-muted:  #6a6a71;
  --accent:      #3451b2;
  --accent-dim:  #3a5ccc;
  --accent-soft: rgba(52, 81, 178, .1);
  --border:      #e2e2e3;
  --code-bg:     #f6f6f7;
  --mark-bg:     #fef08a;
  --shadow:      0 1px 2px rgba(0,0,0,.04), 0 1px 2px rgba(0,0,0,.06);
}

html.theme-dark {
  --bg:          #1b1b1f;
  --surface:     #1b1b1f;
  --text:        #dfdfd6;
  --text-muted:  #98989f;
  --accent:      #a8b1ff;
  --accent-dim:  #8591f0;
  --accent-soft: rgba(168, 177, 255, .16);
  --border:      #2e2e32;
  --code-bg:     #161618;
  --mark-bg:     #78350f;
  --shadow:      0 1px 2px rgba(0,0,0,.24), 0 2px 8px rgba(0,0,0,.24);
}

/* ─── Reset ──────────────────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  min-height: 100vh;
}

/* ─── Layout ─────────────────────────────────────────────────────────────── */

#layout {
  display: flex;
  min-height: 100vh;
}

/* ─── Left Navigation ────────────────────────────────────────────────────── */

#nav {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--nav-w);
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 100;
  box-shadow: var(--shadow);
}

#nav-header {
  padding: 16px 14px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#nav-logo {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
  display: block;
  margin-bottom: 10px;
  letter-spacing: -.3px;
}

#search-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

#search-input-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
}

#search-input {
  width: 100%;
  padding: 7px 28px 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: .85rem;
  outline: none;
  transition: border-color .15s;
}

#search-input:focus { border-color: var(--accent); }
#search-input::-webkit-search-cancel-button { display: none; }

#search-clear {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  display: none;
  padding: 2px;
}

#search-clear.visible { display: block; }

#search-count {
  font-size: .75rem;
  color: var(--text-muted);
  white-space: nowrap;
  min-width: 28px;
  text-align: right;
}

#theme-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, border-color .15s;
}

#theme-btn:hover { background: var(--code-bg); border-color: var(--text-muted); }

#nav-links {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0 24px;
}

#nav-links ul {
  list-style: none;
}

/* ─── Grouped nav sections ───────────────────────────────────────────────── */

.nav-group + .nav-group {
  margin-top: 18px;
}

.nav-group-title {
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-muted);
  opacity: .75;
  padding: 0 18px 6px;
}

#nav-links li a {
  display: block;
  padding: 7px 18px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: .875rem;
  border-left: 3px solid transparent;
  transition: color .12s, background .12s, border-color .12s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#nav-links li a:hover {
  color: var(--text);
  background: var(--code-bg);
}

#nav-links li a.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}

#nav-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  font-size: .75rem;
  color: var(--text-muted);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

#nav-footer a { color: var(--accent); text-decoration: none; }
#nav-footer a:hover { text-decoration: underline; }

/* ─── Collapsible nav groups ─────────────────────────────────────────────── */

.nav-row {
  display: flex;
  align-items: center;
}

.nav-row > a {
  flex: 1;
  min-width: 0; /* allow text-overflow to work */
}

#nav-links.no-transition .nav-sub,
#nav-links.no-transition .nav-toggle { transition: none !important; }

.nav-toggle {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--border);
  cursor: pointer;
  font-size: .55rem;
  padding: 6px 12px 6px 4px;
  line-height: 1;
  transition: transform .2s ease, color .12s;
}

.nav-toggle:hover { color: var(--text-muted); }

#nav-links > ul > li.open .nav-toggle {
  transform: rotate(90deg);
  color: var(--text-muted);
}

/* ─── Nested sub-section links ───────────────────────────────────────────── */

.nav-sub {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 0;
  overflow: hidden;
  transition: max-height .22s ease;
}

#nav-links > ul > li.open .nav-sub {
  max-height: 800px; /* large enough for any group */
}

#nav-links .nav-sub li a {
  display: block;
  padding: 2px 18px 2px 38px;
  color: color-mix(in srgb, var(--text-muted) 80%, transparent);
  text-decoration: none;
  font-size: .72rem;
  border-left: 3px solid transparent;
  transition: color .12s, background .12s, border-color .12s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.55;
  letter-spacing: .01em;
}

#nav-links .nav-sub li a:hover {
  color: var(--text-muted);
  background: var(--code-bg);
}

#nav-links .nav-sub li a.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--accent-soft);
  font-weight: 500;
}

/* ─── Hamburger (mobile) ─────────────────────────────────────────────────── */

#hamburger {
  display: none;
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 200;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 11px;
  cursor: pointer;
  font-size: 1.15rem;
  box-shadow: var(--shadow);
  color: var(--text);
}

#nav-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 99;
}

/* ─── Main Content ───────────────────────────────────────────────────────── */

#content-area {
  margin-left: var(--nav-w);
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: flex-start;
}

#content {
  flex: 1;
  min-width: 0;
}

section {
  display: none;
  max-width: 760px;
  margin: 0 auto;
  padding: 40px 48px 80px;
}

section.active { display: block; }

/* ─── Breadcrumb ──────────────────────────────────────────────────────────── */

#breadcrumb {
  max-width: 760px;
  margin: 0 auto;
  padding: 24px 48px 0;
  font-size: .82rem;
  color: var(--text-muted);
}

#breadcrumb a { color: var(--text-muted); text-decoration: none; }
#breadcrumb a:hover { color: var(--accent); }
#breadcrumb .crumb-group { color: var(--text-muted); }
#breadcrumb .crumb-current { color: var(--text); font-weight: 500; }

/* ─── "On this page" TOC (right rail) ────────────────────────────────────── */

#toc {
  width: var(--toc-w);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  max-height: 100vh;
  overflow-y: auto;
  padding: 40px 24px 40px 0;
}

#toc.empty { display: none; }

.toc-label {
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-muted);
  opacity: .75;
  margin-bottom: 10px;
}

#toc-inner ul {
  list-style: none;
  margin: 0;
  border-left: 1px solid var(--border);
}

#toc-inner li { margin-bottom: 0; }

#toc-inner a {
  display: block;
  padding: 5px 0 5px 14px;
  margin-left: -1px;
  border-left: 2px solid transparent;
  color: var(--text-muted);
  text-decoration: none;
  font-size: .8rem;
  line-height: 1.4;
  transition: color .12s, border-color .12s;
}

#toc-inner li.toc-sub a { padding-left: 26px; font-size: .77rem; }

#toc-inner a:hover { color: var(--text); }

#toc-inner a.active {
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 600;
}

@media (max-width: 1180px) {
  #toc { display: none; }
}

/* ─── "Pick a path" homepage cards ───────────────────────────────────────── */

.path-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  margin: 0 0 32px;
}

.path-card {
  display: block;
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  text-decoration: none;
  color: inherit;
  transition: border-color .15s, transform .15s, box-shadow .15s;
}

.path-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

.path-step {
  display: inline-block;
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--accent);
  margin-bottom: 6px;
}

.path-card h3 {
  margin: 0 0 6px;
  font-size: 1rem;
}

.path-card p {
  margin: 0;
  font-size: .85rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ─── Prev / Next pager ───────────────────────────────────────────────────── */

.pager-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.pager-link {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: inherit;
  transition: border-color .15s, background .15s;
  min-width: 0;
}

.pager-link:hover { border-color: var(--accent); background: var(--accent-soft); }

.pager-next { text-align: right; align-items: flex-end; }

.pager-dir {
  font-size: .72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.pager-title {
  font-size: .92rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ─── Search: show sections with matches ─────────────────────────────────── */

body.searching section { display: none; }
body.searching section.has-match { display: block; }

/* ─── Typography ─────────────────────────────────────────────────────────── */

h1 {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text);
  letter-spacing: -.5px;
}

.section-subtitle {
  color: var(--text-muted);
  font-size: 1.05rem;
  margin-bottom: 32px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 20px;
}

h2 {
  font-size: 1.35rem;
  font-weight: 600;
  margin: 36px 0 12px;
  color: var(--text);
  letter-spacing: -.2px;
}

section h2 {
  border-top: 1px solid var(--border);
  margin-top: 44px;
  padding-top: 28px;
}

/* First h2 after the subtitle needs no separator — it would double-up */
section .section-subtitle + h2,
section .path-grid + h2 {
  border-top: none;
  margin-top: 32px;
  padding-top: 0;
}

h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 24px 0 8px;
  color: var(--text);
}

h4 {
  font-size: .95rem;
  font-weight: 600;
  margin: 16px 0 6px;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: .5px;
}

p { margin-bottom: 12px; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

ul, ol {
  margin: 8px 0 12px 22px;
}

li { margin-bottom: 5px; }

li > ul, li > ol { margin-top: 4px; margin-bottom: 4px; }

strong { font-weight: 600; }

/* ─── Code ───────────────────────────────────────────────────────────────── */

code {
  font-family: ui-monospace, Menlo, 'SF Mono', 'Cascadia Code', Consolas, monospace;
  font-size: .865em;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--text);
}

.code-block {
  position: relative;
  margin: 16px 0;
}

pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 44px 16px 18px;
  overflow-x: auto;
  font-family: ui-monospace, Menlo, 'SF Mono', 'Cascadia Code', Consolas, monospace;
  font-size: .85rem;
  line-height: 1.6;
  color: var(--text);
}

pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
}

/* ── Terminal-style copyable code blocks ── */

.code-block pre {
  background: #1a1a1a;
  color: #e2e2e2;
  border-color: #333;
}

.code-block pre code { color: inherit; }

.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: #2a2a2a;
  border: 1px solid #444;
  border-radius: 5px;
  padding: 4px 9px;
  font-size: .75rem;
  cursor: pointer;
  color: #888;
  transition: color .15s, background .15s;
}

.copy-btn:hover  { background: #353535; color: #bbb; }
.copy-btn.copied { color: #4ade80; }

/* Dark theme — flip code blocks to light so they contrast against the dark page */
@media (prefers-color-scheme: dark) {
  .code-block pre  { background: #f0f0f0; color: #1a1a1a; border-color: #ccc; }
  .copy-btn        { background: #e0e0e0; border-color: #bbb; color: #666; }
  .copy-btn:hover  { background: #d0d0d0; color: #333; }
}

html.theme-light .code-block pre { background: #1a1a1a; color: #e2e2e2; border-color: #333; }
html.theme-light .copy-btn       { background: #2a2a2a; border-color: #444; color: #888; }
html.theme-light .copy-btn:hover { background: #353535; color: #bbb; }

html.theme-dark .code-block pre  { background: #f0f0f0; color: #1a1a1a; border-color: #ccc; }
html.theme-dark .copy-btn        { background: #e0e0e0; border-color: #bbb; color: #666; }
html.theme-dark .copy-btn:hover  { background: #d0d0d0; color: #333; }

/* ─── Tables ─────────────────────────────────────────────────────────────── */

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}

th {
  text-align: left;
  padding: 9px 14px;
  background: var(--code-bg);
  border-bottom: 2px solid var(--border);
  font-weight: 600;
  color: var(--text);
}

td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

tr:last-child td { border-bottom: none; }
tr:nth-child(even) td { background: var(--code-bg); }

/* ─── Figures / Screenshots ──────────────────────────────────────────────── */

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

figure img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: block;
  margin: 0 auto;
}

figcaption {
  margin-top: 8px;
  font-size: .82rem;
  color: var(--text-muted);
  font-style: italic;
}

.screenshots-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
  margin: 20px 0;
}

.screenshots-grid figure { margin: 0; }
.screenshots-grid figcaption { font-size: .78rem; }

/* ─── Callout / Info box ─────────────────────────────────────────────────── */

.callout {
  border-left: 4px solid var(--accent);
  background: var(--accent-soft);
  padding: 12px 16px;
  border-radius: var(--radius);
  margin: 16px 0;
  font-size: .9rem;
}

.callout.warning {
  border-left-color: #f59e0b;
  background: color-mix(in srgb, #f59e0b 8%, var(--surface));
}

/* Only the label strong (always the first child, e.g. "Prerequisite") is a heading line —
   :first-child, not a blanket `strong` selector, so a further <strong> used for inline emphasis
   in the callout's body text (e.g. "v2.1.0 or higher") stays inline instead of also being
   forced onto its own line and breaking the surrounding sentence apart. */
.callout strong:first-child { display: block; margin-bottom: 4px; }

/* ─── Feature List ───────────────────────────────────────────────────────── */

.feature-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 16px 0;
}

.feature-card {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

.feature-card h3 {
  margin-top: 0;
  font-size: .95rem;
  margin-bottom: 8px;
}

.feature-card ul {
  margin: 0;
  padding-left: 18px;
  font-size: .87rem;
  color: var(--text-muted);
}

.feature-card li { margin-bottom: 3px; }

/* ─── Kbd ────────────────────────────────────────────────────────────────── */

kbd {
  display: inline-block;
  padding: 2px 7px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: .78rem;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  color: var(--text);
  white-space: nowrap;
}

/* ─── Lightbox ───────────────────────────────────────────────────────────── */

#lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .88);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
  cursor: zoom-out;
}

#lightbox.open {
  opacity: 1;
  pointer-events: auto;
}

#lightbox img {
  max-width: 90vw;
  max-height: 88vh;
  object-fit: contain;
  border-radius: var(--radius);
  box-shadow: 0 12px 60px rgba(0, 0, 0, .7);
  transform: scale(.95);
  transition: transform .2s ease;
  cursor: zoom-out;
}

#lightbox.open img {
  transform: scale(1);
}

#content figure img {
  cursor: zoom-in;
}

/* ─── Search highlight ───────────────────────────────────────────────────── */

mark {
  background: var(--mark-bg);
  color: var(--text);
  border-radius: 2px;
  padding: 0 2px;
}

mark.current-match {
  outline: 2px solid var(--accent);
}

/* ─── Back to top ────────────────────────────────────────────────────────── */

.back-top {
  display: inline-block;
  margin-top: 40px;
  padding: 7px 16px;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .83rem;
  color: var(--text-muted);
  cursor: pointer;
  text-decoration: none;
}

.back-top:hover { color: var(--text); background: var(--border); }

/* ─── Folder tree ────────────────────────────────────────────────────────── */

.folder-tree {
  font-family: ui-monospace, Menlo, 'SF Mono', Consolas, monospace;
  font-size: .875rem;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  line-height: 1.8;
  margin: 14px 0;
}

/* ─── Step list ──────────────────────────────────────────────────────────── */

.steps {
  list-style: none;
  margin: 12px 0;
  padding: 0;
  counter-reset: step;
}

/* Not display:flex on the <li> itself — its content is plain inline text mixed with <strong>/
   <code>/<a>, and flexbox turns every one of those (including each anonymous text run between
   them) into its own separate flex item, splitting a single sentence into a jumble of
   individually-wrapped boxes instead of one flowing paragraph. The number bubble is positioned
   via ::before + padding-left instead, leaving the <li>'s actual content in normal flow. */
.steps li {
  position: relative;
  padding-left: 38px;
  margin-bottom: 12px;
  counter-increment: step;
  min-height: 26px;
}

.steps li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 1px;
  width: 26px;
  height: 26px;
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  font-size: .8rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ─── Responsive ─────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  #hamburger { display: flex; align-items: center; }

  #nav {
    left: calc(-1 * var(--nav-w));
    transition: left .25s ease;
    z-index: 200;
  }

  #nav.open {
    left: 0;
  }

  #nav-overlay.open {
    display: block;
  }

  #content-area {
    margin-left: 0;
  }

  section {
    padding: 56px 20px 60px;
  }

  #breadcrumb {
    padding: 56px 20px 0;
  }

  h1 { font-size: 1.6rem; }

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

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

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

  .pager-nav {
    grid-template-columns: 1fr;
  }

  .pager-next { text-align: left; align-items: flex-start; }
}

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