/* ============================================================================
   Portable Agent Workspace — explainer site
   Quiet documentation / operating-tool aesthetic.
   Palette: near-white, graphite, green, blue, one warm accent. No gradients,
   glass, glow, or bokeh. Radius <= 8px. System fonts only.
   ========================================================================== */

/* ---- Design tokens ------------------------------------------------------ */
:root {
  /* Neutrals */
  --bg:          #fbfbfa;
  --bg-band:     #f5f6f5;
  --surface:     #ffffff;
  --surface-2:   #f2f3f2;
  --ink:         #1b1f23;
  --ink-2:       #464d54;
  --ink-3:       #6d747b;
  --line:        #e3e5e3;
  --line-2:      #d0d3d0;

  /* Accents (balanced, never one-hue) */
  --green:       #1c7a53;
  --green-strong:#15603f;
  --green-soft:  #e7f2ec;
  --blue:        #2660a4;
  --blue-strong: #1d4c85;
  --blue-soft:   #e8f0f8;
  --warm:        #bd6425;
  --warm-strong: #9a4f1b;
  --warm-soft:   #f8ece2;

  /* Status / semantic */
  --danger:      #b03a2e;
  --danger-soft: #f7e8e6;

  /* Typography */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --fs-hero: clamp(2rem, 1.35rem + 2.7vw, 3.05rem);
  --fs-h2:   clamp(1.5rem, 1.2rem + 1.2vw, 2rem);
  --fs-h3:   clamp(1.2rem, 1.08rem + 0.5vw, 1.4rem);
  --fs-h4:   1.05rem;
  --fs-body: 1.0625rem;
  --fs-sm:   0.9375rem;
  --fs-xs:   0.8125rem;

  --lh-body: 1.62;
  --lh-tight: 1.32;

  --measure: 68ch;
  --measure-wide: 1120px;

  --radius: 8px;
  --radius-sm: 6px;
  --radius-xs: 4px;

  --sidebar-w: 264px;
  --topbar-h: 56px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;

  --shadow-1: 0 1px 2px rgba(20,25,30,.06);
  --shadow-2: 0 4px 16px rgba(20,25,30,.10);

  --focus: 0 0 0 3px rgba(38,96,164,.40);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:          #14171a;
    --bg-band:     #191d21;
    --surface:     #1c2024;
    --surface-2:   #23282d;
    --ink:         #eceeef;
    --ink-2:       #b6bcc2;
    --ink-3:       #878e95;
    --line:        #2c3237;
    --line-2:      #3a4147;

    --green:       #4bbd8a;
    --green-strong:#6fd0a4;
    --green-soft:  #16332a;
    --blue:        #6aa6e0;
    --blue-strong: #8cbcec;
    --blue-soft:   #142838;
    --warm:        #dc9057;
    --warm-strong: #e7a878;
    --warm-soft:   #33241a;

    --danger:      #e07a6e;
    --danger-soft: #37211f;

    --shadow-1: 0 1px 2px rgba(0,0,0,.30);
    --shadow-2: 0 6px 22px rgba(0,0,0,.42);
    --focus: 0 0 0 3px rgba(106,166,224,.45);
  }
}
/* Explicit theme override (toggle wins in both directions) */
:root[data-theme="light"] {
  --bg:#fbfbfa; --bg-band:#f5f6f5; --surface:#fff; --surface-2:#f2f3f2;
  --ink:#1b1f23; --ink-2:#464d54; --ink-3:#6d747b; --line:#e3e5e3; --line-2:#d0d3d0;
  --green:#1c7a53; --green-strong:#15603f; --green-soft:#e7f2ec;
  --blue:#2660a4; --blue-strong:#1d4c85; --blue-soft:#e8f0f8;
  --warm:#bd6425; --warm-strong:#9a4f1b; --warm-soft:#f8ece2;
  --danger:#b03a2e; --danger-soft:#f7e8e6;
  --shadow-1:0 1px 2px rgba(20,25,30,.06); --shadow-2:0 4px 16px rgba(20,25,30,.10);
  --focus:0 0 0 3px rgba(38,96,164,.40);
}
:root[data-theme="dark"] {
  --bg:#14171a; --bg-band:#191d21; --surface:#1c2024; --surface-2:#23282d;
  --ink:#eceeef; --ink-2:#b6bcc2; --ink-3:#878e95; --line:#2c3237; --line-2:#3a4147;
  --green:#4bbd8a; --green-strong:#6fd0a4; --green-soft:#16332a;
  --blue:#6aa6e0; --blue-strong:#8cbcec; --blue-soft:#142838;
  --warm:#dc9057; --warm-strong:#e7a878; --warm-soft:#33241a;
  --danger:#e07a6e; --danger-soft:#37211f;
  --shadow-1:0 1px 2px rgba(0,0,0,.30); --shadow-2:0 6px 22px rgba(0,0,0,.42);
  --focus:0 0 0 3px rgba(106,166,224,.45);
}

/* ---- Base --------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  color: var(--ink);
  background: var(--bg);
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1,h2,h3,h4 { line-height: var(--lh-tight); font-weight: 650; color: var(--ink); letter-spacing: 0; }
h2 { font-size: var(--fs-h2); margin: 0 0 var(--space-3); }
h3 { font-size: var(--fs-h3); margin: var(--space-6) 0 var(--space-2); }
h4 { font-size: var(--fs-h4); margin: var(--space-5) 0 var(--space-2); font-weight: 650; }
p { margin: 0 0 var(--space-4); max-width: var(--measure); }
a { color: var(--blue-strong); text-decoration: underline; text-underline-offset: 2px; text-decoration-thickness: 1px; }
a:hover { color: var(--blue); }
strong { font-weight: 650; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--radius-xs); }
img { max-width: 100%; height: auto; }
hr { border: 0; border-top: 1px solid var(--line); margin: var(--space-6) 0; }
ul, ol { max-width: var(--measure); padding-left: 1.3em; margin: 0 0 var(--space-4); }
li { margin: 0 0 var(--space-2); }
li > ul, li > ol { margin-top: var(--space-2); }

.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 100;
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 0 0 var(--radius) 0;
}
.skip-link:focus { left: 0; }

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

/* Sidebar (desktop) */
.sidebar {
  grid-column: 1;
  border-right: 1px solid var(--line);
  background: var(--surface);
  position: sticky; top: 0; align-self: start;
  height: 100vh; overflow-y: auto;
  padding: var(--space-5) 0 var(--space-6);
  display: flex; flex-direction: column;
}
.brand { padding: 0 var(--space-5) var(--space-4); }
.brand-mark {
  display: inline-flex; align-items: baseline; gap: 8px;
  font-weight: 700; font-size: 1.02rem; color: var(--ink); text-decoration: none; letter-spacing: 0;
}
.brand-mark .paw-glyph {
  font-family: var(--mono); font-weight: 700; color: #fff; background: var(--green);
  padding: 2px 7px; border-radius: var(--radius-sm); font-size: .82rem; letter-spacing: .5px;
}
.brand-sub { display:block; font-size: var(--fs-xs); color: var(--ink-3); margin-top: 6px; line-height:1.4; }

.side-nav { padding: var(--space-2) var(--space-3); overflow-y: auto; }
.side-nav ol { list-style: none; margin: 0; padding: 0; max-width: none; counter-reset: nav; }
.side-nav li { margin: 0; }
.side-nav a {
  display: flex; gap: 10px; align-items: baseline;
  padding: 7px 12px; border-radius: var(--radius-sm);
  color: var(--ink-2); text-decoration: none; font-size: var(--fs-sm); line-height: 1.3;
}
.side-nav a .num { font-family: var(--mono); font-size: .72rem; color: var(--ink-3); min-width: 1.6em; }
.side-nav a:hover { background: var(--surface-2); color: var(--ink); }
.side-nav a[aria-current="true"] { background: var(--green-soft); color: var(--green-strong); font-weight: 600; }
.side-nav a[aria-current="true"] .num { color: var(--green-strong); }
.side-foot { margin-top: auto; padding: var(--space-4) var(--space-5) 0; border-top: 1px solid var(--line); }
.side-foot .status-pill { margin-bottom: var(--space-3); }

/* Topbar (mobile) */
.topbar { display: none; }

/* Main */
.main { grid-column: 2; min-width: 0; }
.section {
  padding: var(--space-8) var(--space-7);
  border-bottom: 1px solid var(--line);
  scroll-margin-top: var(--space-4);
}
.section:nth-of-type(even) { background: var(--bg-band); }
.section > .wrap { max-width: var(--measure-wide); margin: 0 inherit; }
.wrap-text { max-width: 760px; }
.section-kicker {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--mono); font-size: var(--fs-xs); color: var(--ink-3);
  text-transform: uppercase; letter-spacing: .06em; margin-bottom: var(--space-3);
}
.section-kicker .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--green); }
.lede { font-size: 1.14rem; color: var(--ink-2); max-width: 720px; margin-bottom: var(--space-5); }

/* ---- Hero --------------------------------------------------------------- */
.hero { padding-top: var(--space-7); }
.hero h1 { font-size: var(--fs-hero); font-weight: 700; margin: 0 0 var(--space-3); max-width: 16ch; }
.hero .define {
  font-size: 1.24rem; color: var(--ink); max-width: 40ch; margin: 0 0 var(--space-4);
  border-left: 3px solid var(--green); padding-left: var(--space-4); line-height: 1.5;
}
.hero-meta { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; margin-bottom: var(--space-5); }
.hero-actions { display: flex; flex-wrap: wrap; gap: var(--space-3); margin: var(--space-5) 0 var(--space-6); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  font: inherit; font-size: var(--fs-sm); font-weight: 550;
  padding: 10px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink);
  text-decoration: none; cursor: pointer; transition: background .12s ease, border-color .12s ease;
}
.btn:hover { background: var(--surface-2); border-color: var(--ink-3); }
.btn-primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn-primary:hover { background: var(--green-strong); border-color: var(--green-strong); color: #fff; }
.btn svg { width: 16px; height: 16px; }

/* ---- Status pills / badges --------------------------------------------- */
.status-pill {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: var(--fs-xs); font-weight: 600; padding: 4px 10px;
  border-radius: 999px; border: 1px solid var(--line-2); background: var(--surface); color: var(--ink-2);
}
.status-pill .led { width: 7px; height: 7px; border-radius: 50%; background: var(--warm); box-shadow: 0 0 0 3px var(--warm-soft); }

/* Semantic tags: requirement / recommendation / option / example / candidate / local lesson / hypothesis */
.tag {
  display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
  font-size: var(--fs-xs); font-weight: 650; line-height: 1;
  padding: 4px 8px; border-radius: var(--radius-xs); border: 1px solid transparent;
  font-family: var(--mono); letter-spacing: .01em;
}
.tag-req  { background: var(--green); color: #fff; border-color: var(--green); }
.tag-rec  { background: var(--blue-soft); color: var(--blue-strong); border-color: color-mix(in srgb, var(--blue) 40%, transparent); }
.tag-opt  { background: var(--surface); color: var(--ink-2); border-color: var(--line-2); }
.tag-ex   { background: transparent; color: var(--ink-3); border: 1px dashed var(--line-2); }
.tag-cand { background: var(--warm-soft); color: var(--warm-strong); border-color: color-mix(in srgb, var(--warm) 40%, transparent); }
.tag-local{ background: transparent; color: var(--warm-strong); border: 1px dashed color-mix(in srgb, var(--warm) 55%, transparent); }
.tag-hyp  { background: transparent; color: var(--ink-3); border: 1px dashed var(--ink-3); font-style: italic; }
.tag-normative { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.tag-legend { display: flex; flex-wrap: wrap; gap: 10px 14px; margin: var(--space-4) 0; padding: 0; list-style: none; max-width: none; }
.tag-legend li { display: flex; align-items: center; gap: 8px; margin: 0; font-size: var(--fs-sm); color: var(--ink-2); }
.tag-legend .desc { color: var(--ink-3); font-size: var(--fs-xs); }

/* ---- Callouts ----------------------------------------------------------- */
.callout {
  border: 1px solid var(--line); border-left: 3px solid var(--ink-3);
  background: var(--surface); border-radius: var(--radius-sm);
  padding: var(--space-4) var(--space-5); margin: var(--space-4) 0; max-width: var(--measure);
}
.callout p:last-child { margin-bottom: 0; }
.callout-title { font-weight: 650; margin-bottom: var(--space-2); display: flex; align-items: center; gap: 8px; }
.callout.note   { border-left-color: var(--blue); }
.callout.warn   { border-left-color: var(--warm); background: var(--warm-soft); }
.callout.key    { border-left-color: var(--green); background: var(--green-soft); }
.callout.not    { border-left-color: var(--danger); background: var(--danger-soft); }

/* "Not this" list */
.not-list { list-style: none; padding: 0; max-width: var(--measure); }
.not-list li { position: relative; padding-left: 26px; }
.not-list li::before { content: "✕"; position: absolute; left: 4px; color: var(--danger); font-weight: 700; }

/* ---- Code / file trees -------------------------------------------------- */
code { font-family: var(--mono); font-size: .9em; background: var(--surface-2); padding: 2px 5px; border-radius: var(--radius-xs); color: var(--ink); }
pre {
  font-family: var(--mono); font-size: var(--fs-sm); line-height: 1.55;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: var(--space-4); overflow-x: auto; margin: var(--space-4) 0; max-width: 100%;
  color: var(--ink);
}
pre code { background: none; padding: 0; font-size: 1em; }
.filetree { position: relative; }
.filetree .cm { color: var(--ink-3); }
.code-caption { font-size: var(--fs-xs); color: var(--ink-3); margin: -8px 0 var(--space-4); font-family: var(--mono); }
.copy-btn {
  position: absolute; top: 8px; right: 8px; font-size: var(--fs-xs); padding: 4px 8px;
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink-2);
  border-radius: var(--radius-xs); cursor: pointer;
}
.copy-btn:hover { background: var(--surface-2); }
.pre-wrap { position: relative; }

/* ---- Tables ------------------------------------------------------------- */
.table-scroll { overflow-x: auto; margin: var(--space-4) 0; border: 1px solid var(--line); border-radius: var(--radius-sm); }
table { border-collapse: collapse; width: 100%; font-size: var(--fs-sm); background: var(--surface); }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
thead th { background: var(--surface-2); font-weight: 650; color: var(--ink); white-space: nowrap; position: sticky; top: 0; }
tbody tr:last-child td { border-bottom: 0; }
td code { white-space: nowrap; }
.table-scroll table { border: 0; }

/* ---- Cards / grids ------------------------------------------------------ */
.grid { display: grid; gap: var(--space-4); margin: var(--space-4) 0; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: var(--space-4) var(--space-5); box-shadow: var(--shadow-1);
}
.card h4 { margin-top: 0; }
.card p:last-child, .card ul:last-child { margin-bottom: 0; }
.card .card-eyebrow { font-family: var(--mono); font-size: var(--fs-xs); color: var(--ink-3); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 6px; }

/* Definition rows */
.deflist { display: grid; grid-template-columns: minmax(140px, 220px) 1fr; gap: 0; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; margin: var(--space-4) 0; background: var(--surface); }
.deflist dt { padding: 10px 14px; font-weight: 650; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.deflist dd { padding: 10px 14px; margin: 0; border-bottom: 1px solid var(--line); color: var(--ink-2); }
.deflist dt:last-of-type, .deflist dd:last-of-type { border-bottom: 0; }

/* ---- Diagrams (accessible HTML/CSS) ------------------------------------- */
.diagram {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
  padding: var(--space-5); margin: var(--space-5) 0;
}
.diagram-title { font-size: var(--fs-xs); font-family: var(--mono); text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); margin-bottom: var(--space-4); }

/* Flow of boxes with arrows */
.flow { display: flex; flex-wrap: wrap; align-items: stretch; gap: 0; }
.flow-node {
  flex: 1 1 150px; min-width: 130px;
  border: 1px solid var(--line-2); border-radius: var(--radius-sm); background: var(--surface-2);
  padding: var(--space-3) var(--space-4); position: relative;
}
.flow-node .fn-label { font-weight: 650; font-size: var(--fs-sm); display: block; }
.flow-node .fn-sub { font-size: var(--fs-xs); color: var(--ink-3); display: block; margin-top: 4px; }
.flow-arrow { display: flex; align-items: center; justify-content: center; color: var(--ink-3); padding: 0 6px; flex: 0 0 auto; font-size: 1.2rem; }
.flow-arrow::before { content: "→"; }
.flow.vertical { flex-direction: column; }
.flow.vertical .flow-arrow { transform: rotate(90deg); padding: 4px 0; }
.flow-node.accent-green { border-left: 3px solid var(--green); }
.flow-node.accent-blue  { border-left: 3px solid var(--blue); }
.flow-node.accent-warm  { border-left: 3px solid var(--warm); }

/* Operating map */
.opmap { display: grid; gap: var(--space-3); }
.opmap-row { display: grid; grid-template-columns: 120px 1fr; gap: var(--space-3); align-items: center; }
.opmap-row .lane { font-family: var(--mono); font-size: var(--fs-xs); color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; }
.opmap-row .lane-body { display: flex; flex-wrap: wrap; gap: 8px; }
.opnode {
  border: 1px solid var(--line-2); background: var(--surface-2); border-radius: var(--radius-sm);
  padding: 6px 12px; font-size: var(--fs-sm); font-weight: 550; color: var(--ink);
}
.opnode.entry { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.opnode.canon { border-left: 3px solid var(--green); }
.opnode.ext   { border-left: 3px solid var(--blue); }
.opnode.gate  { border-left: 3px solid var(--warm); }

/* Nested boundary diagram */
.nest-outer { border: 2px solid var(--green); border-radius: var(--radius); padding: var(--space-5); background: var(--green-soft); }
.nest-outer > .nest-label { font-weight: 650; color: var(--green-strong); margin-bottom: var(--space-3); display: block; }
.nest-inner { border: 2px dashed var(--blue); border-radius: var(--radius-sm); padding: var(--space-4); background: var(--surface); margin-top: var(--space-3); }
.nest-inner > .nest-label { font-weight: 650; color: var(--blue-strong); margin-bottom: var(--space-2); display: block; }
.nest-file { font-family: var(--mono); font-size: var(--fs-sm); color: var(--ink-2); }

/* Matrix (authority) */
.matrix { display: grid; gap: var(--space-3); grid-template-columns: repeat(3, 1fr); margin: var(--space-4) 0; }
.matrix .cell { border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); padding: var(--space-4); }
.matrix .cell .k { font-weight: 650; display: block; margin-bottom: 4px; }
.matrix .cell .v { font-size: var(--fs-sm); color: var(--ink-2); }
.matrix .cell.is-authority { border-left: 3px solid var(--green); }
.matrix .cell.not-authority { border-left: 3px solid var(--ink-3); }

/* Timeline */
.timeline { display: flex; flex-wrap: wrap; gap: 0; align-items: stretch; }
.tl-step { flex: 1 1 130px; min-width: 120px; padding: var(--space-3) var(--space-4); border-top: 3px solid var(--line-2); position: relative; }
.tl-step .tl-k { font-weight: 650; font-size: var(--fs-sm); display: block; }
.tl-step .tl-v { font-size: var(--fs-xs); color: var(--ink-3); display: block; margin-top: 4px; }
.tl-step.done { border-top-color: var(--green); }
.tl-step.active { border-top-color: var(--warm); }
.tl-step.future { border-top-color: var(--line-2); }

/* ---- Segmented control (audience lens) ---------------------------------- */
.lens-bar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: none;
  border-bottom: 1px solid var(--line);
  padding: var(--space-3) var(--space-7);
  display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center;
}
.lens-label { font-size: var(--fs-xs); color: var(--ink-3); font-family: var(--mono); text-transform: uppercase; letter-spacing: .05em; }
.segmented { display: inline-flex; border: 1px solid var(--line-2); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface); flex-wrap: wrap; }
.segmented button {
  font: inherit; font-size: var(--fs-sm); padding: 7px 13px; border: 0; background: transparent;
  color: var(--ink-2); cursor: pointer; border-right: 1px solid var(--line);
}
.segmented button:last-child { border-right: 0; }
.segmented button[aria-pressed="true"] { background: var(--green); color: #fff; font-weight: 600; }
.segmented button:hover:not([aria-pressed="true"]) { background: var(--surface-2); }

/* Lens-conditional content.
   Default (no JS): every lens note is visible so nothing is hidden behind script.
   With JS (html.js): hide all, reveal only the active lens. */
.lens-note {
  display: block;
  border-left: 3px solid var(--blue); background: var(--blue-soft);
  border-radius: var(--radius-sm); padding: var(--space-3) var(--space-4); margin: var(--space-4) 0; max-width: var(--measure);
  font-size: var(--fs-sm);
}
.lens-note .lens-tag { font-family: var(--mono); font-size: var(--fs-xs); color: var(--blue-strong); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; display: block; margin-bottom: 4px; }
html.js .lens-note { display: none; }
/* Safety net: if app.js never sets a lens, still show the default one. */
html.js body:not([data-lens]) .lens-note.first-timer { display: block; }
html.js body[data-lens="first-timer"] .lens-note.first-timer,
html.js body[data-lens="ai-builder"] .lens-note.ai-builder,
html.js body[data-lens="engineer"] .lens-note.engineer,
html.js body[data-lens="lead"] .lens-note.lead { display: block; }

/* ---- Interactive panels (task explorer, setup preview, filters) --------- */
.panel {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
  padding: var(--space-5); margin: var(--space-5) 0;
}
.panel h4 { margin-top: 0; }
.control-row { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-bottom: var(--space-4); }
.chip {
  font: inherit; font-size: var(--fs-sm); padding: 7px 13px; border-radius: 999px;
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink-2); cursor: pointer;
}
.chip[aria-pressed="true"], .chip.is-active { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip:hover:not([aria-pressed="true"]):not(.is-active) { background: var(--surface-2); }

.explorer-out, .setup-out {
  border: 1px solid var(--line); border-left: 3px solid var(--green);
  border-radius: var(--radius-sm); background: var(--surface-2); padding: var(--space-4);
  margin-top: var(--space-3);
}
.explorer-out .route-name { font-weight: 650; }

fieldset { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: var(--space-4); margin: 0 0 var(--space-4); }
legend { font-weight: 650; font-size: var(--fs-sm); padding: 0 6px; }
.field { margin-bottom: var(--space-3); }
.field > label.q { display: block; font-weight: 600; font-size: var(--fs-sm); margin-bottom: 6px; }
.radioset { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.radioset label {
  display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-sm);
  padding: 6px 12px; border: 1px solid var(--line-2); border-radius: var(--radius-sm); cursor: pointer; background: var(--surface);
}
.radioset input { accent-color: var(--green); }
.radioset label:has(input:checked) { border-color: var(--green); background: var(--green-soft); color: var(--green-strong); }
select, input[type="text"] {
  font: inherit; font-size: var(--fs-sm); padding: 8px 10px; border: 1px solid var(--line-2);
  border-radius: var(--radius-sm); background: var(--surface); color: var(--ink);
}

/* ---- Source register ---------------------------------------------------- */
.filters { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: flex-end; margin-bottom: var(--space-4); }
.filters .fgroup { display: flex; flex-direction: column; gap: 4px; }
.filters label { font-size: var(--fs-xs); color: var(--ink-3); font-family: var(--mono); text-transform: uppercase; letter-spacing: .04em; }
.reg-count { font-size: var(--fs-sm); color: var(--ink-3); margin-bottom: var(--space-3); }
tr.hidden-row { display: none; }
.evc { font-family: var(--mono); font-size: var(--fs-xs); font-weight: 650; padding: 2px 7px; border-radius: var(--radius-xs); white-space: nowrap; }
.evc-standard   { background: var(--green-soft); color: var(--green-strong); }
.evc-official   { background: var(--blue-soft); color: var(--blue-strong); }
.evc-practice   { background: var(--surface-2); color: var(--ink-2); }
.evc-signal     { background: var(--warm-soft); color: var(--warm-strong); }
.evc-local      { background: var(--danger-soft); color: var(--danger); }
.evc-hypothesis { background: transparent; color: var(--ink-3); border: 1px dashed var(--ink-3); }
.conf { font-size: var(--fs-xs); font-weight: 600; }

/* ---- Repository map ----------------------------------------------------- */
.repo-map { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: var(--space-3); margin: var(--space-4) 0; }
.repo-node {
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface);
  padding: var(--space-3) var(--space-4); cursor: pointer; text-align: left; font: inherit;
}
.repo-node:hover { border-color: var(--ink-3); background: var(--surface-2); }
.repo-node .rn-path { font-family: var(--mono); font-size: var(--fs-sm); font-weight: 650; display: block; }
.repo-node .rn-role { font-size: var(--fs-xs); color: var(--ink-3); display: block; margin-top: 4px; }
.repo-node.canonical { border-left: 3px solid var(--green); }
.repo-node.derived   { border-left: 3px solid var(--ink-3); }
.repo-node.upstream  { border-left: 3px solid var(--blue); }
.repo-node.is-selected { box-shadow: var(--focus); }
.repo-detail { border: 1px solid var(--line); border-left: 3px solid var(--green); border-radius: var(--radius-sm); background: var(--surface-2); padding: var(--space-4); margin-top: var(--space-3); }
.legend-inline { display: flex; flex-wrap: wrap; gap: 14px; margin: var(--space-3) 0; font-size: var(--fs-sm); }
.legend-inline span { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); }
.legend-inline i { width: 12px; height: 12px; border-radius: 2px; display: inline-block; }
.legend-inline .l-canon { background: var(--green); }
.legend-inline .l-deriv { background: var(--ink-3); }
.legend-inline .l-up { background: var(--blue); }

/* ---- Why this choice? (details/summary) --------------------------------- */
details.why {
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface);
  margin: var(--space-3) 0; max-width: var(--measure); overflow: hidden;
}
details.why > summary {
  cursor: pointer; padding: 10px 14px; font-weight: 600; font-size: var(--fs-sm); color: var(--ink-2);
  list-style: none; display: flex; align-items: center; gap: 8px;
}
details.why > summary::-webkit-details-marker { display: none; }
details.why > summary::before { content: "＋"; font-family: var(--mono); color: var(--ink-3); }
details.why[open] > summary::before { content: "－"; }
details.why > summary:hover { background: var(--surface-2); }
details.why .why-body { padding: 0 14px var(--space-3); font-size: var(--fs-sm); color: var(--ink-2); }
details.why .why-body p { max-width: none; }

/* ---- Canonical sources disclosure --------------------------------------- */
.sources {
  margin-top: var(--space-6); border-top: 1px solid var(--line); padding-top: var(--space-4);
}
.sources > .sources-title {
  font-family: var(--mono); font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .06em;
  color: var(--ink-3); margin-bottom: var(--space-3); display: flex; align-items: center; gap: 8px;
}
.sources > .sources-title::before { content: ""; width: 14px; height: 14px; border: 1px solid var(--green); border-radius: 3px; background: var(--green-soft); display: inline-block; }
.source-links { display: flex; flex-wrap: wrap; gap: 8px; list-style: none; padding: 0; margin: 0; max-width: none; }
.source-links li { margin: 0; }
.source-links a, .source-links .src-path {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--mono); font-size: var(--fs-xs); color: var(--ink-2);
  padding: 4px 9px; border: 1px solid var(--line-2); border-radius: var(--radius-xs);
  background: var(--surface); text-decoration: none;
}
.source-links a:hover { border-color: var(--green); color: var(--green-strong); background: var(--green-soft); }
.source-links .authority-badge { color: var(--ink-3); font-size: .7rem; }

/* ---- Misc utilities ----------------------------------------------------- */
.muted { color: var(--ink-3); }
.small { font-size: var(--fs-sm); }
.xs { font-size: var(--fs-xs); }
.mono { font-family: var(--mono); }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-5); align-items: start; }
.stack-sm > * + * { margin-top: var(--space-3); }
.divider-label { display:flex; align-items:center; gap: var(--space-3); color: var(--ink-3); font-size: var(--fs-xs); font-family: var(--mono); text-transform: uppercase; letter-spacing: .05em; margin: var(--space-5) 0 var(--space-3); }
.divider-label::after { content:""; flex:1; height:1px; background: var(--line); }

.notice-bar {
  border: 1px solid var(--line-2); border-left: 3px solid var(--warm); background: var(--warm-soft);
  border-radius: var(--radius-sm); padding: var(--space-3) var(--space-4); font-size: var(--fs-sm);
  color: var(--ink-2); margin: var(--space-4) 0; max-width: var(--measure);
}
.asof { font-family: var(--mono); font-size: var(--fs-xs); color: var(--ink-3); }

/* Footer */
.site-foot { padding: var(--space-7); color: var(--ink-3); font-size: var(--fs-sm); background: var(--surface); border-top: 1px solid var(--line); }
.site-foot .wrap { max-width: var(--measure-wide); }
.site-foot a { color: var(--ink-2); }
.foot-grid { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: var(--space-6); margin-bottom: var(--space-5); }
.foot-grid h5 { margin: 0 0 var(--space-3); font-size: var(--fs-sm); color: var(--ink); }
.foot-grid ul { list-style: none; padding: 0; margin: 0; }
.foot-grid li { margin-bottom: 8px; font-size: var(--fs-sm); }

/* Theme toggle */
.theme-toggle {
  display: inline-flex; align-items: center; gap: 6px; font: inherit; font-size: var(--fs-xs);
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink-2);
  padding: 6px 10px; border-radius: var(--radius-sm); cursor: pointer;
}
.theme-toggle:hover { background: var(--surface-2); }

/* ---- Responsive --------------------------------------------------------- */
@media (max-width: 940px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: min(84vw, 320px);
    transform: translateX(-100%); transition: transform .2s ease; z-index: 60;
    box-shadow: var(--shadow-2);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  .nav-scrim { display: none; position: fixed; inset: 0; background: rgba(15,18,20,.42); z-index: 55; border: 0; }
  body.nav-open .nav-scrim { display: block; }
  .topbar {
    display: flex; align-items: center; gap: var(--space-3); position: sticky; top: 0; z-index: 40;
    height: var(--topbar-h); padding: 0 var(--space-4);
    background: var(--surface); border-bottom: 1px solid var(--line);
  }
  .topbar .menu-btn { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border: 1px solid var(--line-2); background: var(--surface); border-radius: var(--radius-sm); cursor: pointer; color: var(--ink); }
  .topbar .tb-brand { font-weight: 700; font-size: .98rem; display: flex; align-items: baseline; gap: 6px; }
  .topbar .paw-glyph { font-family: var(--mono); font-weight: 700; color: #fff; background: var(--green); padding: 2px 6px; border-radius: var(--radius-sm); font-size: .74rem; }
  .topbar .tb-spacer { flex: 1; }
  .main { grid-column: 1; }
  .section { padding: var(--space-6) var(--space-4); }
  .lens-bar { padding: var(--space-3) var(--space-4); top: var(--topbar-h); position: sticky; }
  .matrix { grid-template-columns: 1fr; }
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
  .two-col { grid-template-columns: 1fr; }
  .foot-grid { grid-template-columns: 1fr; gap: var(--space-5); }
  .deflist { grid-template-columns: 1fr; }
  .deflist dt { border-bottom: 0; }
  .opmap-row { grid-template-columns: 1fr; gap: 6px; }
  .hero .define { font-size: 1.12rem; }
}
@media (min-width: 941px) {
  .topbar { display: none; }
  .nav-scrim { display: none; }
}
@media (max-width: 560px) {
  .flow { flex-direction: column; }
  .flow-arrow { transform: rotate(90deg); padding: 4px 0; }
  .timeline { flex-direction: column; }
  .tl-step { border-top: 0; border-left: 3px solid var(--line-2); }
  .tl-step.done { border-left-color: var(--green); border-top: 0; }
  .tl-step.active { border-left-color: var(--warm); border-top: 0; }
  .hero-actions { flex-direction: column; align-items: stretch; }
  .hero-actions .btn { justify-content: center; }
}

/* ---- Overflow guards ----------------------------------------------------
   Grid/flex children default to min-width:auto, which lets a wide <pre> or
   <code> stretch the whole layout instead of scrolling inside its own box.
   Force min-width:0 on every content container so inner overflow-x works,
   and never let the page itself scroll sideways. */
html, body { max-width: 100%; }
.main { min-width: 0; max-width: 100%; overflow-x: clip; }
.section, .section > .wrap { min-width: 0; max-width: 100%; }
.grid > *, .two-col > *, .card, .matrix > .cell, .flow > *, .opmap-row,
.opmap-row .lane-body, .repo-map > *, .deflist, .timeline > *, .panel,
.diagram, .nest-inner, .nest-outer, figure.diagram { min-width: 0; }
pre, .pre-wrap, .table-scroll { max-width: 100%; min-width: 0; }
.card pre { max-width: 100%; }
code { overflow-wrap: anywhere; }
pre code { overflow-wrap: normal; }   /* keep code blocks scrolling, not wrapping */

/* ---- Print -------------------------------------------------------------- */
@media print {
  .sidebar, .topbar, .lens-bar, .nav-scrim, .copy-btn, .theme-toggle, .btn { display: none !important; }
  .app { display: block; }
  .main { grid-column: 1; }
  .section { padding: 18pt 0; border-bottom: 1px solid #ccc; background: #fff !important; break-inside: avoid; }
  .lens-note { display: block !important; }
  details.why { border: 1px solid #ccc; }
  details.why:not([open]) > .why-body { display: block; } /* expand rationale for print */
  .sources { break-inside: avoid; }
  a { color: #000; text-decoration: underline; }
  body { color: #000; background: #fff; font-size: 11pt; }
  pre, .card, .diagram, .panel, table { break-inside: avoid; }
}
