:root {
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 28px;
  --space-8: 32px;
  --page-gutter: clamp(16px, 2vw, 32px);
  --section-gap: 24px;
}

/* Shell controls and search dialog share the compact Fieldnotes spacing scale. */
.top-actions { display:flex; align-items:center; gap:var(--space-2); }
.panel-toggle, .search-trigger { min-height:44px; display:inline-flex; align-items:center; justify-content:center; gap:var(--space-2); padding:var(--space-2); }
.panel-toggle[hidden] { display:none; }
.panel-toggle { min-width:44px; border-color:var(--border); background:transparent; color:var(--accent); }
.theme-label select { min-width:120px; }
.search-trigger { color:var(--muted); }
.search-trigger kbd { border:1px solid var(--border); border-radius:3px; padding:0 var(--space-1); font-size:10px; }
.shell.sidebar-hidden { grid-template-columns:minmax(0,1fr); }
.shell.sidebar-hidden aside { display:none; }
#search-dialog { width:min(680px,calc(100vw - 2 * var(--space-4))); max-height:calc(100dvh - 2 * var(--space-4)); padding:var(--space-5); border:1px solid var(--border); border-radius:8px; background:var(--surface); color:var(--ink); }
#search-dialog::backdrop { background:rgb(0 0 0 / 70%); }
.dialog-heading { display:flex; align-items:center; justify-content:space-between; gap:var(--space-3); }
#search-dialog input { width:100%; margin-block:var(--space-3); }
#global-results { max-height:50dvh; overflow:auto; display:grid; gap:var(--space-1); }
#global-results a { min-height:44px; display:grid; padding:var(--space-2); border-radius:5px; color:var(--ink); text-decoration:none; }
#global-results a:hover, #global-results a:focus-visible { background:var(--tint); }
#global-results small { color:var(--muted); }
@media(max-width:1100px) { .panel-toggle { display:none; } }
@media(max-width:850px) { .search-trigger span, .search-trigger kbd { display:none; } }

/* Chapter reader and contents rail, aligned to the shared spacing contract. */
.reader:has(.reader-layout) { max-width:none; }
.reader-layout { display:grid; grid-template-columns:minmax(0,1fr); gap:var(--space-4); align-items:start; }
.reader-layout .article { min-width:0; font-size:16px; line-height:1.75; }
.reader-layout .article h2 { font-size:clamp(23px, 2.2vw, 29px); line-height:1.4; border-top:1px solid var(--border); margin-top:var(--space-3); padding-top:var(--space-5); }
.reader-layout .article h3 { font-size:21px; line-height:1.5; }
.reader-contents { position:static; border-block:1px solid var(--border); padding-block:var(--space-2); }
.reader-contents summary { min-height:44px; display:list-item; align-content:center; cursor:pointer; }
.reader-layout .article { max-width:86ch; }
.reader-layout .article .actions { margin-block:var(--space-4); }
.reader-contents summary { color:var(--muted); font-size:12px; font-weight:600; }
.reader-contents details > div { display:grid; gap:var(--space-1); }
.reader-contents button { display:block; width:100%; text-align:left; background:transparent; border:0; min-height:44px; color:var(--muted); padding:var(--space-2); font-size:12px; }
.reader-contents button:hover { background:var(--tint); color:var(--ink); }
.reader-layout h2 { scroll-margin-top:calc(76px + var(--space-4)); }
@media(max-width:1100px) { .reader-contents details:not([open]) > div { display:none; } }
@media(min-width:1101px) {
  .reader-layout { grid-template-columns:minmax(0,1fr) clamp(190px,16vw,240px); gap:var(--space-6); }
  .reader-layout .article { max-width:none; }
  .reader-layout.contents-hidden { grid-template-columns:minmax(0,1fr); }
  .reader-layout.contents-hidden .reader-contents { display:none; }
  .reader-contents { position:sticky; top:calc(76px + var(--space-4)); max-height:calc(100dvh - 76px - 2 * var(--space-4)); overflow:auto; border-block:0; border-left:1px solid var(--border); padding:0 0 0 var(--space-4); }
  .reader-contents summary { display:none; }
  .reader-contents details::before { content:"ON THIS PAGE"; display:block; color:var(--muted); font:11px ui-monospace,monospace; letter-spacing:.1em; padding:var(--space-2); }
}

@media(max-width:850px) { .reader-layout h2 { scroll-margin-top:180px; } }

.knowledge-check { max-width:86ch; border:1px solid var(--border); border-radius:8px; background:var(--surface); padding:var(--space-5); display:grid; gap:var(--space-3); }
.knowledge-check form, .knowledge-check fieldset { display:grid; gap:var(--space-3); }
.knowledge-check fieldset { border:0; margin:0; padding:0; min-width:0; }
.knowledge-check legend { font-weight:600; padding:0; }
.knowledge-check label { display:flex; gap:var(--space-2); align-items:center; min-height:44px; cursor:pointer; }
.knowledge-check input { flex:none; min-height:0; width:18px; height:18px; accent-color:var(--accent); }
.knowledge-check button { justify-self:start; }
.knowledge-check .check-feedback:empty { display:none; }

/* The Fieldnotes shell keeps its primary routes with the chapter navigation. */
.topbar .top-actions { margin-left:auto; }
.primary-nav { display:grid; gap:var(--space-1); margin-bottom:var(--space-5); }
.primary-nav a { display:flex; align-items:center; gap:var(--space-2); min-height:44px; padding:var(--space-2); border-radius:5px; color:var(--muted); font-size:13px; text-decoration:none; }
.primary-nav a svg { flex:none; width:20px; height:20px; padding:3px; border:1px solid color-mix(in srgb,var(--accent) 45%,var(--border)); border-radius:5px; color:var(--accent); fill:none; stroke:currentColor; stroke-width:1.5; stroke-linecap:round; stroke-linejoin:round; }
.primary-nav a:hover, .primary-nav a[aria-current="page"] { color:var(--ink); background:var(--tint); }
.primary-nav a[aria-current="page"] { box-shadow:inset 3px 0 var(--accent); }
.sidebar-intro { margin-bottom:var(--space-2); }
#subjects a .subject-icon { display:grid; place-items:center; flex:none; width:20px; height:20px; border:1px solid color-mix(in srgb,var(--accent) 45%,var(--border)); border-radius:5px; background:var(--tint); color:var(--accent); font-size:9px; }
#subjects a .subject-icon svg { width:13px; height:13px; }
#subjects a .count { display:grid; place-items:center; min-width:24px; min-height:20px; padding-inline:var(--space-1); border-radius:4px; background:var(--tint); color:var(--muted); }
#subjects a[aria-current="location"], #subjects a[aria-current="page"] { background:var(--tint); color:var(--ink); box-shadow:inset 3px 0 var(--accent); }
@media(max-width:1100px) { .shell.sidebar-hidden aside { display:block; } .primary-nav { display:flex; gap:var(--space-2); flex-wrap:wrap; margin-bottom:0; } .primary-nav a { flex:1 1 auto; justify-content:center; padding-inline:var(--space-2); } }

/* Home uses the same compact cards and theme surfaces as Fieldnotes. */
.hero .decision-map { background:var(--surface); border-radius:8px; padding:var(--space-4) var(--space-5); }
.hero .button.primary { background:var(--surface); border-color:var(--border); color:var(--ink); }
.hero .button.primary:hover { background:var(--hover); }
.hero-copy h1 { font-size:clamp(36px,3.7vw,56px); line-height:1.1; letter-spacing:-2.3px; }
.hero-copy h1 em { font-family:Georgia, "Times New Roman", serif; font-style:italic; font-weight:400; }
/* Keep the curriculum controls beside its heading on wide screens, as in Fieldnotes. */
@media(min-width:1101px) {
  .hero { padding-bottom:0; border-bottom:0; }
  .stack:has(> #module-grid) { grid-template-columns:minmax(220px,1fr) minmax(400px,1fr); align-items:end; }
  .stack:has(> #module-grid) > .filters { justify-content:flex-end; }
  .stack:has(> #module-grid) > #module-grid { grid-column:1 / -1; }
  .stack:has(> #module-grid) > #search-status { position:absolute; width:1px; height:1px; padding:0; overflow:hidden; clip-path:inset(50%); white-space:nowrap; }
}
#module-grid { grid-template-columns:repeat(3,minmax(0,1fr)); }
#module-grid .card { padding:var(--space-4); border-radius:8px; }
#module-grid .card h3 { font-size:20px; font-weight:500; letter-spacing:-0.5px; }
#module-grid .card p { font-size:12px; line-height:1.75; }
.subject-art { position:relative; height:104px; overflow:hidden; border:1px solid var(--border); border-radius:6px; background:linear-gradient(135deg,var(--surface),var(--tint)); }
.subject-art svg { width:100%; height:100%; display:block; fill:none; stroke:var(--accent); stroke-width:1; opacity:.38; }
.subject-art circle { fill:var(--accent); }
.subject-art-label { position:absolute; z-index:1; top:var(--space-2); left:var(--space-2); padding:2px 7px; border:1px solid var(--border); border-radius:4px; background:var(--surface); color:var(--accent); font:600 9px ui-monospace,monospace; text-transform:uppercase; }
.subject-preview { display:grid; gap:var(--space-1); margin-top:auto; }
.subject-preview a { display:flex; justify-content:space-between; align-items:center; gap:var(--space-2); min-height:44px; padding:var(--space-2); border:1px solid var(--border); border-radius:5px; color:var(--ink); text-decoration:none; font-size:12px; }
.subject-preview a:hover { background:var(--tint); border-color:var(--accent); }
.subject-preview a span:last-child { color:var(--accent); }
/* Subject overviews use the same hero, metrics and chapter-card hierarchy. */
.subject-hero { display:grid; grid-template-columns:minmax(0,2fr) minmax(180px,1fr); align-items:center; gap:var(--space-6); }
.subject-hero .button { justify-self:start; }
.subject-hero-art svg { width:100%; max-height:160px; fill:none; stroke:var(--accent); stroke-width:1; opacity:.55; }
.subject-metrics { display:flex; gap:var(--space-8); flex-wrap:wrap; padding-block:var(--space-4); border-block:1px solid var(--border); }
.subject-metrics span { display:grid; color:var(--muted); font-size:12px; }
.subject-metrics strong { color:var(--ink); font-size:20px; }
.subject-overview .chapter-list { grid-template-columns:repeat(4,minmax(0,1fr)); gap:var(--space-4); }
.subject-overview .chapter-link { display:flex; flex-direction:column; align-items:stretch; gap:var(--space-3); min-width:0; padding:var(--space-4); border-radius:8px; }
.subject-overview .chapter-link:hover { border-color:var(--accent); background:var(--hover); }
.chapter-art { height:104px; border:1px solid var(--border); border-radius:5px; background:var(--tint); overflow:hidden; }
.chapter-art svg { width:100%; height:100%; fill:none; stroke:var(--accent); opacity:.45; }
.chapter-link strong { font-size:18px; line-height:1.35; }
.chapter-card-footer { display:flex; justify-content:space-between; align-items:center; gap:var(--space-2); margin-top:auto; padding-top:var(--space-3); border-top:1px solid var(--border); }
@media(max-width:1100px) { .subject-overview .chapter-list { grid-template-columns:repeat(2,minmax(0,1fr)); } }
@media(max-width:700px) { .subject-hero { grid-template-columns:minmax(0,1fr); } .subject-hero-art { display:none; } .subject-overview .chapter-list { grid-template-columns:minmax(0,1fr); } }
@media(max-width:1050px) { #module-grid { grid-template-columns:repeat(2,minmax(0,1fr)); } }
@media(max-width:700px) { #module-grid { grid-template-columns:minmax(0,1fr); } #module-grid .card h3 { font-size:18px; } }

/* Mobile subject drawer follows the Fieldnotes chapter navigation pattern. */
.chapters-trigger { display:none; }
#chapters-dialog { width:min(440px,calc(100vw - 2 * var(--space-4))); max-height:calc(100dvh - 2 * var(--space-4)); padding:var(--space-5); border:1px solid var(--border); border-radius:8px; background:var(--surface); color:var(--ink); }
#chapters-dialog::backdrop { background:rgb(0 0 0 / 70%); }
#chapters-dialog input { width:100%; margin-block:var(--space-3); }
#mobile-subjects { display:grid; gap:var(--space-1); max-height:55dvh; overflow:auto; overscroll-behavior:contain; }
#mobile-subjects a { min-height:44px; display:flex; align-items:center; justify-content:space-between; gap:var(--space-2); padding:var(--space-2); color:var(--ink); text-decoration:none; border-radius:5px; }
#mobile-subjects a:hover, #mobile-subjects a:focus-visible { background:var(--tint); }
#mobile-subjects a span:last-child { color:var(--muted); font-size:11px; white-space:nowrap; }
@media(max-width:1100px) { #subject-menu { display:none; } .chapters-trigger { min-width:44px; min-height:44px; display:inline-flex; align-items:center; justify-content:center; gap:var(--space-1); padding:var(--space-2); } .chapters-trigger span { display:none; } }

/* On narrow screens, the drawer owns navigation as in the Fieldnotes shell. */
@media(max-width:1100px) {
  .shell, .shell.sidebar-hidden { grid-template-columns:minmax(0,1fr); }
  .shell aside, .shell.sidebar-hidden aside { display:none; }
  #mobile-primary-nav { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); margin:var(--space-3) 0; }
  #mobile-primary-nav a { justify-content:flex-start; }
  #mobile-subjects { max-height:min(42dvh, 360px); }
}

/* Chapter sidebar resizing uses a single shared width and a keyboard-operable handle. */
@media(min-width:1101px) {
  .shell { grid-template-columns:var(--sidebar-width, 244px) minmax(0,1fr); }
  .shell > aside { grid-column:1; grid-row:1; }
  .shell > main { grid-column:2; grid-row:1; }
  .shell > aside :is(#subjects, .primary-nav) { padding-right:var(--space-4); }
  #sidebar-resizer { grid-column:1; grid-row:1; justify-self:end; align-self:start; position:sticky; top:76px; height:calc(100dvh - 76px); width:44px; margin-right:calc(-1 * var(--space-4)); z-index:5; cursor:ew-resize; touch-action:none; }
  #sidebar-resizer::after { content:""; position:absolute; top:0; bottom:0; left:calc(50% + 5px); width:2px; background:var(--border); }
  #sidebar-resizer:hover::after, #sidebar-resizer:focus-visible::after { background:var(--accent); }
  #sidebar-resizer:focus-visible { outline:2px solid var(--accent); outline-offset:-4px; }
  .shell.sidebar-hidden > main { grid-column:1; }
  .shell.sidebar-hidden #sidebar-resizer { display:none; }
}
@media(max-width:1100px) { #sidebar-resizer { display:none; } }
