/* Lab readability layer. Loads last.
   Rules:
   - Pixelify Sans is window chrome only (see 00-foundation.css tokens).
   - Paragraph text is 15px or more. Small labels and table cells are 13px or
     more. SVG text is 12px or more.
   - Headlines wrap between words, never inside them.
   - The first screen is one question, one answer and one chart. Everything
     else is folded, and the agent panels (WebMCP queue, receipts) stay
     hidden until asked for. */

/* ------------------------------------------------------------------ */

/* Headlines: break between words only                                  */

/* ------------------------------------------------------------------ */

h1,
h2,
h3,
h4 {
  overflow-wrap: break-word !important;
  word-break: normal !important;
  hyphens: manual;
  text-wrap: balance;
}

/* ------------------------------------------------------------------ */

/* Text floor                                                           */

/* ------------------------------------------------------------------ */

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-size: 15px;
}

/* Prose is 15px. Labels, tags and units stay at 13px, table cells and
   values at 14px. These use !important because 90-observatory sets sizes
   per component behind long selectors. */

main summary,
main li,
main .depth-freshman,
main .depth-researcher,
main .depth-full_trace,
main [class*="plain-body"],
main [class*="plain-detail"],
main [class*="effect-meaning"],
main [class*="gate-label"],
main .comparison-boundary,
main .causal-fallback-button,
main .causal-reading small,
main details > div > p {
  font-size: 15px !important;
  line-height: 1.55;
}

main td,
main th,
main dd,
main pre {
  font-size: 14px !important;
}

.mission-sidecar p,
.mission-sidecar .mission-human-boundary {
  font-size: 14px !important;
}

/* ------------------------------------------------------------------ */

/* Lab shell: one window, one question, folded detail                   */

/* ------------------------------------------------------------------ */

.obs-window-content {
  display: block;
}

.obs-header {
  position: static;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  min-height: 0;
  padding: 6px 12px;
}

.obs-identity {
  flex: 1 1 auto;
  padding: 0;
}

.obs-wordmark {
  font: 700 1.5rem/1 var(--font-display);
}

.obs-nav {
  height: auto;
}

.obs-nav a {
  padding: 12px 14px;
  font: 600 1rem var(--font-display);
}

.obs-nav a.is-current::after {
  right: 10px;
  left: 10px;
}

.share-state[hidden] {
  display: none;
}

.agent-tools-toggle {
  min-height: 32px;
  padding: 4px 10px;
  color: var(--text-dark);
  font: 600 13px var(--font-body);
  cursor: pointer;
}

.agent-tools-toggle[aria-expanded="true"] {
  border-style: inset;
}

/* Agent panels: closed until asked for, then a plain block above the page. */

.agent-tools {
  border-bottom: 2px solid var(--inset-dark);
  background: var(--chrome-well);
}

.agent-tools[hidden] {
  display: none;
}

.agent-tools .mission-control {
  position: static;
  top: auto;
}

.agent-tools .mission-sidecar {
  position: static;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  max-height: none;
  overflow: visible;
}

#mission-toggle {
  display: none;
}

#observatory-main {
  border-right: 0;
}

/* First screen */

.lab-first,
.lab-deeper {
  width: 100%;
  min-width: 0;
  order: 0;
}

.lab-first {
  max-width: 1100px;
  margin: 0 auto;
  padding: clamp(20px, 3vw, 36px) clamp(16px, 3vw, 32px) 8px;
}

.lab-first h1 {
  max-width: 24ch;
  margin: 0 0 14px;
  color: var(--title-bar);
  font-size: clamp(1.75rem, 1.2rem + 2vw, 2.5rem);
  line-height: 1.15;
}

.lab-answer {
  max-width: 65ch;
  margin: 0 0 24px;
  font-size: 18px !important;
  line-height: 1.7 !important;
}

.lab-placeholder {
  color: var(--text-soft);
  background: var(--gold-wash);
  outline: 2px dashed var(--gold-line);
  outline-offset: 2px;
}

.lab-first .recovery-v2-band {
  margin: 0 -4px;
}

/* Folds */

.evidence-grid {
  grid-template-columns: minmax(0, 1fr);
}

.lab-deeper {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px clamp(16px, 3vw, 32px) 56px;
}

.lab-deeper-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
}

.lab-deeper-head h2 {
  margin: 0;
  font-size: 1.5rem;
}

.lab-deeper-lede {
  margin: 6px 0 16px;
  color: var(--text-soft);
}

.detail-toggle {
  min-height: 34px;
  padding: 4px 12px;
  color: var(--text-dark);
  font: 600 14px var(--font-body);
  cursor: pointer;
}

.detail-toggle[aria-pressed="true"] {
  border-style: inset;
  background: var(--title-bar);
  color: var(--text-light);
}

.lab-fold {
  border: 2px solid var(--chrome-border);
  background: var(--pane-bright);
}

.lab-fold + .lab-fold {
  margin-top: 10px;
}

.lab-fold > summary {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 16px;
  padding: 14px 16px;
  cursor: pointer;
  list-style: none;
}

.lab-fold > summary::-webkit-details-marker {
  display: none;
}

.lab-fold > summary::before {
  content: "+";
  flex: 0 0 auto;
  width: 1.2em;
  font: 700 20px var(--font-mono);
}

.lab-fold[open] > summary::before {
  content: "-";
}

.lab-fold-title {
  flex: 1 1 18ch;
  font: 700 19px/1.3 var(--font-body);
}

.lab-fold-hint {
  color: var(--text-soft);
  font: 500 14px var(--font-body);
}

.lab-fold[open] > summary {
  border-bottom: 2px solid var(--chrome-border);
  background: var(--chrome-well);
}

.lab-fold-loading {
  display: none;
  margin: 0;
  padding: 16px;
}

.lab-fold[data-state="loading"] .lab-fold-loading {
  display: block;
}

.lab-more {
  margin: 14px 0 0;
  border: 1px solid var(--chrome-border);
  background: var(--pane-bright);
}

.lab-more > summary {
  padding: 10px 14px;
  font: 600 15px var(--font-body);
  cursor: pointer;
}

@media (max-width: 760px) {
  body {
    padding-bottom: 0;
    background: var(--window-body);
    background-image: none;
  }

  .desktop-logo,
body .taskbar,
.title-bar,
.obs-nav {
    display: none;
  }

  .obs-desktop {
    width: 100%;
    padding-top: 0;
  }

  .obs-app-window,
.obs-window-content {
    margin: 0;
    border: 0;
    box-shadow: none;
    max-width: 100%;
  }

  .agent-tools .mission-sidecar {
    grid-template-columns: minmax(0, 1fr);
  }

  .lab-answer {
    font-size: 17px !important;
  }
}

/* ------------------------------------------------------------------ */

/* Causal diagram: labels at 12px or more, diagram larger              */

/* ------------------------------------------------------------------ */

.causal-svg-wrap {
  min-height: 0;
  overflow-x: auto;
}

.causal-svg {
  display: block;
  width: 100%;
  min-width: 760px;
  height: auto;
  aspect-ratio: 860 / 520;
}

.causal-svg[data-layout="stacked"] {
  min-width: 0;
  aspect-ratio: auto;
}

main .causal-svg .node-title {
  font: 600 16px var(--font-body) !important;
}

main .causal-svg .node-evidence {
  font: 700 14px var(--font-body) !important;
  letter-spacing: 0;
}

main .causal-svg .node-detail,
main .causal-svg .empty-label {
  font: 500 15px var(--font-mono) !important;
}

main .causal-svg .edge-label {
  font: 500 15px var(--font-body) !important;
  paint-order: stroke;
  stroke: var(--obs-paper);
  stroke-width: 4px;
}

@media (max-width: 760px) {
  .causal-svg-wrap {
    min-height: 0;
  }

  .causal-svg {
    height: auto;
  }

  main .causal-svg .node-title {
    font-size: 16px !important;
  }

  main .causal-svg .node-detail {
    font-size: 15px !important;
  }
}

/* Charts: user-unit text is only readable if the chart is not shrunk below
   about 85% of its design width. Wider than the column? It scrolls sideways
   inside its own frame instead of shrinking the labels. */

main svg[viewBox^="0 0 1000"] {
  display: block;
  width: 100%;
  min-width: 880px;
  height: auto;
}

main svg[viewBox="0 0 720 330"] {
  min-width: 620px;
}

main :has(> svg[viewBox^="0 0 1000"]),
main :has(> svg[viewBox="0 0 720 330"]) {
  overflow-x: auto;
}

/* Two charts side by side left each about 60% of design width. One per row. */

main .learning-visual-grid {
  grid-template-columns: minmax(0, 1fr) !important;
}

/* Chart text floor: 14 chart units, about 12 to 14px after scaling (charts never shrink below 88%). */

main svg text {
  font-size: 14px !important;
}

/* Wide screens: the causal field gets the width. The numbered reading
   moves under it as a three-column strip; the inspector stays on the right. */

@media (min-width: 1100px) {
  /* The column is about 1000px wide at most, so the inspector goes under the
     causal field instead of squeezing it. */
  main .research-band {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "core"
      "inspector"
      "reading";
    min-height: 0;
  }

  main .research-band .evidence-inspector {
    border-top: 1px solid var(--obs-rule);
    border-left: 0;
  }

  main .research-band.inspector-hidden {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "core" "reading";
  }

  main .research-band .research-core {
    grid-area: core;
  }

  main .research-band .causal-reading {
    grid-area: reading;
    border-top: 1px solid var(--obs-rule);
    border-right: 0;
    padding: 16px var(--obs-gutter) 18px;
  }

  main .research-band .evidence-inspector {
    grid-area: inspector;
  }

  main .causal-reading > ol {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px 22px;
  }

  main .causal-reading > ol::before {
    display: none;
  }

  main .causal-reading .evidence-key ul {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 22px;
  }
}

/* ------------------------------------------------------------------ */

/* Clock digits are numbers: pixel 3 and 8 look alike, so use the mono face. */

.taskbar-clock {
  font-family: var(--font-mono);
  font-weight: 600;
}

/* ------------------------------------------------------------------ */

/* Raw trace gate                                                       */

/* ------------------------------------------------------------------ */

.raw-load-button {
  margin: 8px 0 0;
  padding: 8px 14px;
  color: var(--text-dark);
  font: 600 15px var(--font-body);
  cursor: pointer;
}

.raw-load-button:hover:not(:disabled) {
  background: var(--button-hover);
}

.raw-load-button:disabled {
  cursor: progress;
  opacity: 0.65;
}

/* ------------------------------------------------------------------ */

/* Gate badges: a text label beside every gate value, never color alone */

/* ------------------------------------------------------------------ */

.gate-badge {
  display: inline-block;
  margin: 2px 0 6px;
  padding: 2px 7px;
  border: 2px solid currentColor;
  font: 700 0.8125rem/1.3 var(--font-value, monospace);
  letter-spacing: 0.04em;
}

.gate-badge[data-badge="met"] { color: var(--obs-teal-dark, #075560); }

.gate-badge[data-badge="not-met"] { color: var(--obs-red, #b52720); }

.gate-badge[data-badge="unclear"] { color: #7a4a00; background: rgba(240, 169, 47, 0.2); }
