/* =========================================================================
   Agents' Last Exam — Documentation design system
   A single, consistent, high-end aesthetic. Light + dark via CSS variables.
   ========================================================================= */

/* ---- Design tokens ---------------------------------------------------- */
:root {
  /* Neutral ramp — matches the agenthle homepage (warm off-white + slate ink) */
  --bg:        #F7F5F2;
  --surface:   #FFFFFF;
  --surface-2: #F1F5F9;
  --ink:       #0F172A;
  --ink-soft:  #1E293B;
  --muted:     #475569;
  --faint:     #94A3B8;
  --border:    #E4E4E0;
  --border-strong: #CBD5E1;

  /* Warm clay accent — Anthropic-style, same colour temperature as the cream bg.
     Used only on interactive / decorative bits; structure stays near-black. */
  --accent:      #C2613D;
  --accent-ink:  #A34E2E;
  --accent-soft: rgba(194, 97, 61, 0.10);
  --accent-line: rgba(194, 97, 61, 0.32);

  /* Syntax / code surface */
  --code-bg:   #1C1E22;
  --code-ink:  #E6E6E6;
  --code-faint:#8A9099;
  --code-kw:   #E8896A;   /* keyword — warm clay, reads on dark code bg */

  /* Text selection — warm tint, clearly visible */
  --select-bg: rgba(194, 97, 61, 0.18);

  /* Semantic */
  --ok:    #15803D;
  --warn:  #B45309;
  --todo:  #9333EA;

  /* Geometry */
  --radius:    16px;
  --radius-sm: 10px;
  --sidebar-w: 280px;
  --toc-w:     220px;
  --content-max: 820px;

  --shadow-sm: 0 1px 2px rgba(20,20,25,.05), 0 1px 3px rgba(20,20,25,.04);
  --shadow-md: 0 4px 16px rgba(20,20,25,.08), 0 1px 4px rgba(20,20,25,.05);

  --font-sans: "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "Geist Mono", "SF Mono", ui-monospace, "Cascadia Code", Menlo, Consolas, monospace;
}

:root[data-theme="dark"] {
  --bg:        #0E0F12;
  --surface:   #16181C;
  --surface-2: #1C1F24;
  --ink:       #ECEDEF;
  --ink-soft:  #CDD0D4;
  --muted:     #9CA1AB;
  --faint:     #6B707B;
  --border:    #262A30;
  --border-strong: #333841;

  --accent:      #E8896A;
  --accent-ink:  #F0A088;
  --accent-soft: rgba(232, 137, 106, 0.14);
  --accent-line: rgba(232, 137, 106, 0.34);

  --code-bg:   #0A0B0D;
  --code-ink:  #E6E6E6;
  --code-faint:#7C828C;
  --code-kw:   #F0A088;

  --select-bg: rgba(232, 137, 106, 0.26);

  --ok:    #4ADE80;
  --warn:  #FBBF24;
  --todo:  #C084FC;

  --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
  --shadow-md: 0 6px 24px rgba(0,0,0,.4);
}

/* ---- Reset / base ----------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

/* FOUC guard. Each page ships with only a bare <article> in the body; app.js
   rebuilds the body into the sidebar+layout shell on DOMContentLoaded. Without
   this, the browser paints the bare article first and then jumps it into the
   layout — a one-frame reflow on every navigation. Hide until app.js reveals
   (it sets body visibility after assembling the shell). The animation is a
   failsafe: content reveals after 1.2s even if JS never runs. */
body { visibility: hidden; animation: ale-reveal 0s linear 1.2s forwards; }
@keyframes ale-reveal { to { visibility: visible; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15.5px;
  line-height: 1.7;
  letter-spacing: -0.003em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-ink); text-decoration: underline; text-underline-offset: 3px; }
::selection { background: var(--select-bg); color: var(--ink); }
/* Code surfaces are light-on-dark in both themes, so they need their own
   selection: keep the light text, use a stronger clay highlight. */
.article pre ::selection {
  background: rgba(232, 137, 106, 0.42);
  color: var(--code-ink);
}

/* Prose links stay discoverable in a monochrome palette via a subtle underline */
.article p a, .article li a, .article .lede a, .note a, .article td a {
  text-decoration: underline;
  text-decoration-color: var(--accent-line);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  font-weight: 540;
}
.article p a:hover, .article li a:hover, .article .lede a:hover, .note a:hover, .article td a:hover {
  text-decoration-color: var(--accent);
}

/* ---- Layout ----------------------------------------------------------- */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}

/* ---- Sidebar ---------------------------------------------------------- */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 22px 18px 40px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 6px 8px 18px;
  margin-bottom: 6px;
}
.brand .title { font-weight: 650; font-size: 15px; color: var(--ink); line-height: 1.2; }
.brand .subtitle { font-size: 11.5px; color: var(--faint); letter-spacing: .02em; }

.nav-group { margin-top: 16px; }
.nav-group > .label {
  font-size: 11px;
  font-weight: 650;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--faint);
  padding: 6px 10px;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6.5px 10px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 14px;
  font-weight: 480;
  line-height: 1.35;
  transition: background .12s ease, color .12s ease;
}
.nav-link:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.nav-link.active {
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-weight: 580;
}
.nav-link .dot {
  width: 5px; height: 5px; border-radius: 50%;
  background: currentColor; opacity: .4; flex-shrink: 0;
}
.nav-link.child {
  margin-left: 18px;
  padding-left: 12px;
  border-left: 1px solid var(--border);
  font-size: 13.5px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.nav-link.child .dot { display: none; }
.nav-link.child.active { border-left-color: var(--accent); }
.nav-link.active .dot { opacity: 1; }
.nav-link .badge {
  margin-left: auto;
  font-size: 9.5px;
  font-weight: 650;
  letter-spacing: .04em;
  text-transform: uppercase;
  padding: 1px 6px;
  border-radius: 100px;
  background: var(--surface-2);
  color: var(--faint);
  border: 1px solid var(--border);
}
.nav-link .badge.draft { color: var(--todo); border-color: var(--accent-line); }

/* ---- Main / content --------------------------------------------------- */
.main { min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  height: 56px;
  display: flex; align-items: center; gap: 14px;
  padding: 0 28px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar .crumbs { font-size: 13px; color: var(--faint); }
.topbar .crumbs b { color: var(--ink-soft); font-weight: 560; }
.topbar .spacer { flex: 1; }
.icon-btn {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: all .12s ease;
}
.icon-btn:hover { color: var(--ink); border-color: var(--border-strong); }
.icon-btn svg { display: block; }
#theme-icon { display: grid; place-items: center; }
.menu-btn { display: none; }

.content-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--toc-w);
  gap: 48px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 44px 28px 120px;
}
.article { max-width: var(--content-max); min-width: 0; }

/* ---- Typography in article ------------------------------------------- */
.article h1 {
  font-size: 33px; font-weight: 700; letter-spacing: -0.02em;
  line-height: 1.15; margin: 0 0 10px;
}
.article .lede { font-size: 17.5px; color: var(--muted); margin: 0 0 30px; line-height: 1.6; }
.article h2 {
  font-size: 22px; font-weight: 650; letter-spacing: -0.015em;
  margin: 44px 0 14px; padding-top: 8px; scroll-margin-top: 80px;
}
.article h3 {
  font-size: 17px; font-weight: 620; letter-spacing: -0.01em;
  margin: 30px 0 10px; scroll-margin-top: 80px; color: var(--ink-soft);
}
.article p { margin: 0 0 16px; }
.article ul, .article ol { margin: 0 0 16px; padding-left: 22px; }
.article li { margin: 5px 0; }
.article li::marker { color: var(--faint); }
.article strong { font-weight: 620; color: var(--ink); }
.article hr { border: 0; border-top: 1px solid var(--border); margin: 40px 0; }

/* inline code */
.article :not(pre) > code {
  font-family: var(--font-mono);
  font-size: .86em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 1.5px 6px;
  border-radius: 6px;
  color: var(--ink-soft);
  white-space: nowrap;
}

/* code blocks */
.article pre {
  background: var(--code-bg);
  color: var(--code-ink);
  border-radius: var(--radius);
  padding: 18px 20px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  margin: 0 0 20px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.article pre code { font-family: inherit; color: inherit; white-space: pre; }
.article pre .c { color: var(--code-faint); }       /* comment */
.article pre .k { color: var(--code-kw); }            /* keyword/accent */
.article pre .s { color: #E5C07B; }                   /* string */

/* code block + copy button */
.code-wrap { position: relative; margin: 0 0 20px; }
.code-wrap > pre { margin: 0; }
.copy-btn {
  position: absolute; top: 10px; right: 10px;
  display: inline-flex; align-items: center; gap: 5px;
  height: 28px; padding: 0 10px;
  font-family: var(--font-sans);
  font-size: 12px; font-weight: 560; line-height: 1;
  color: var(--code-faint);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 7px;
  cursor: pointer;
  opacity: .55;
  transition: opacity .14s ease, color .14s ease, background .14s ease, border-color .14s ease;
}
.code-wrap:hover .copy-btn, .copy-btn:focus-visible { opacity: 1; }
.copy-btn:hover { color: var(--code-ink); background: rgba(255, 255, 255, 0.12); border-color: rgba(255, 255, 255, 0.24); }
.copy-btn.copied { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, transparent); opacity: 1; }
.copy-btn svg { width: 13px; height: 13px; }

/* ---- Components ------------------------------------------------------- */

/* callout / note boxes */
.note {
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  margin: 0 0 20px;
  font-size: 14.5px;
}
.note .note-title {
  font-weight: 620; font-size: 12.5px; letter-spacing: .03em;
  text-transform: uppercase; color: var(--accent-ink); margin-bottom: 4px;
}
.note.warn { border-left-color: var(--warn); }
.note.warn .note-title { color: var(--warn); }
.note.todo { border-left-color: var(--todo); }
.note.todo .note-title { color: var(--todo); }

/* tables */
.article table {
  width: 100%; border-collapse: collapse; margin: 0 0 22px;
  font-size: 14px; border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden;
}
.article th {
  text-align: left; font-weight: 600; font-size: 12.5px;
  letter-spacing: .02em; color: var(--muted);
  background: var(--surface-2); padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.article td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.article tr:last-child td { border-bottom: 0; }
.article tbody tr:hover { background: var(--surface-2); }
.article td .sub { font-family: var(--font-mono); font-size: 11.5px; color: var(--faint); margin-top: 3px; }

/* card grid (for hub pages) */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px; margin: 0 0 28px;
}
.card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  transition: border-color .14s ease, transform .14s ease, box-shadow .14s ease;
}
.card:hover {
  text-decoration: none; border-color: var(--accent-line);
  transform: translateY(-2px); box-shadow: var(--shadow-md);
}
.card .k {
  font-size: 11px; font-weight: 650; letter-spacing: .08em;
  text-transform: uppercase; color: var(--accent); margin-bottom: 7px;
}
.card .t { font-size: 16px; font-weight: 620; color: var(--ink); margin-bottom: 5px; }
.card .d { font-size: 13.5px; color: var(--muted); line-height: 1.5; }

/* pillar / stat strip */
.pillars { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin: 0 0 30px; }
.pillar {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 16px;
}
.pillar .t { font-weight: 620; font-size: 14px; margin-bottom: 3px; }
.pillar .d { font-size: 12.5px; color: var(--muted); line-height: 1.45; }

/* ascii / diagram block */
.diagram {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 22px 24px; margin: 0 0 22px;
  overflow-x: auto;
  font-family: var(--font-mono); font-size: 12.5px; line-height: 1.5;
  color: var(--ink-soft); white-space: pre;
}

/* horizontal phase flow (a prettier alternative to ASCII diagrams) */
.flow { display: flex; align-items: stretch; margin: 0 0 22px; overflow-x: auto; }
.flow .phase {
  flex: 1 1 0; min-width: 132px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 13px 15px;
}
.flow .phase .pk {
  font-size: 11.5px; font-weight: 640; letter-spacing: .01em;
  color: var(--accent); margin-bottom: 5px;
}
.flow .phase .pd { font-size: 12.5px; color: var(--muted); line-height: 1.45; }
.flow .arrow {
  flex: 0 0 auto; align-self: center; padding: 0 9px;
  color: var(--accent-line); font-size: 17px;
}
@media (max-width: 640px) {
  .flow { flex-direction: column; }
  .flow .arrow { transform: rotate(90deg); padding: 5px 0; }
}

/* three swappable slots (overview) */
.slots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 6px 0 20px; }
.slots .slot {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 14px 16px;
}
.slots .slot .sk {
  font-size: 11px; font-weight: 650; letter-spacing: .06em; text-transform: uppercase;
  color: var(--accent); margin-bottom: 6px;
}
.slots .slot .st { font-weight: 600; font-size: 14.5px; color: var(--ink); margin-bottom: 3px; }
.slots .slot .sd { font-size: 13px; color: var(--muted); line-height: 1.45; }
@media (max-width: 640px) { .slots { grid-template-columns: 1fr; } }

/* run lifecycle timeline (overview): a vertical map of a run + the pages it leads to */
.lifecycle { list-style: none; margin: 14px 0 24px; padding: 0; position: relative; }
.lifecycle::before {
  content: ""; position: absolute; left: 6px; top: 8px; bottom: 14px;
  width: 2px; background: var(--border);
}
.lifecycle > li { position: relative; padding: 0 0 22px 30px; }
.lifecycle > li::before {
  content: ""; position: absolute; left: 0; top: 5px;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 0 3px var(--bg);
}
.lifecycle > li:last-child { padding-bottom: 0; }
.lifecycle .lt { font-weight: 600; font-size: 15px; color: var(--ink); }
.lifecycle .ld { font-size: 13.5px; color: var(--muted); line-height: 1.55; margin-top: 3px; }
.lifecycle .lp { font-size: 12.5px; margin-top: 5px; }

/* hero (home) */
.hero { padding: 8px 0 8px; margin-bottom: 8px; }
.hero .eyebrow {
  font-size: 12px; font-weight: 650; letter-spacing: .18em; text-transform: uppercase;
  color: var(--accent); margin-bottom: 14px;
}
.hero h1 { font-size: 42px; line-height: 1.08; letter-spacing: -0.03em; margin: 0 0 16px; }
.hero .lede { font-size: 18px; max-width: 660px; }
.btn-row { display: flex; gap: 12px; flex-wrap: wrap; margin: 26px 0 8px; }
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 20px; border-radius: 100px; font-weight: 600; font-size: 14.5px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--ink);
  transition: all .14s ease;
}
.btn:hover { text-decoration: none; border-color: var(--border-strong); background: var(--surface-2); transform: translateY(-1px); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.btn.primary:hover { background: var(--ink-soft); border-color: var(--ink-soft); }

/* status pill inline */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 600; padding: 2px 9px; border-radius: 100px;
  border: 1px solid var(--border);
}
.pill.ok   { color: var(--ok);   border-color: color-mix(in srgb, var(--ok) 40%, var(--border)); }
.pill.todo { color: var(--todo); border-color: var(--accent-line); }

/* ---- Right TOC -------------------------------------------------------- */
.toc { position: sticky; top: 84px; align-self: start; font-size: 13px; }
.toc .label {
  font-size: 11px; font-weight: 650; letter-spacing: .08em; text-transform: uppercase;
  color: var(--faint); margin-bottom: 10px;
}
.toc a {
  display: block; color: var(--muted); padding: 3.5px 0 3.5px 12px;
  border-left: 2px solid var(--border); line-height: 1.4;
}
.toc a:hover { color: var(--ink); text-decoration: none; }
.toc a.active { color: var(--accent-ink); border-left-color: var(--accent); font-weight: 540; }
.toc a.lvl3 { padding-left: 24px; font-size: 12.5px; }

/* ---- Prev / next footer ---------------------------------------------- */
.pagenav { display: flex; gap: 14px; margin-top: 56px; padding-top: 28px; border-top: 1px solid var(--border); }
.pagenav a {
  flex: 1; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 18px; color: var(--ink); transition: border-color .14s ease;
}
.pagenav a:hover { text-decoration: none; border-color: var(--accent-line); }
.pagenav .dir { font-size: 11.5px; color: var(--faint); margin-bottom: 3px; }
.pagenav .ttl { font-weight: 580; font-size: 14.5px; color: var(--accent-ink); }
.pagenav a.next { text-align: right; }

/* ---- Responsive ------------------------------------------------------- */
@media (max-width: 1100px) {
  .content-wrap { grid-template-columns: minmax(0,1fr); }
  .toc { display: none; }
  .pillars { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 60; width: 86%; max-width: 320px;
    transform: translateX(-100%); transition: transform .22s ease;
    box-shadow: var(--shadow-md);
  }
  .sidebar.open { transform: translateX(0); }
  .menu-btn { display: grid; }
  .scrim {
    position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 50;
    opacity: 0; pointer-events: none; transition: opacity .22s ease;
  }
  .scrim.show { opacity: 1; pointer-events: auto; }
  .pillars { grid-template-columns: 1fr; }
  .hero h1 { font-size: 32px; }
}
