/* ============================================================
   MECHANISTIC ITERATION — quiet cream skin
   Follows the main site: paper palette, Instrument Serif for
   titles, Inter Tight for labels, Lora for prose, plain system
   monospace for machine text. Thin rules, no ornament.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Instrument+Serif:ital@0;1&family=Lora:ital,wght@0,400;0,500;1,400&family=Inter+Tight:wght@400;500&display=swap');

:root {
  --paper:      #F4EEE2;
  --paper-2:    #ECE4D3;
  --paper-3:    #E2D7BF;
  --ink:        #1E1B16;
  --graphite:   #4A463D;
  --graphite-2: #6E6A60;
  --chalk:      #9A9587;
  --moss:       #3E5542;
  --moss-deep:  #2A3B2E;
  --gold:       #C89A3E;
  --brick:      #A34A2A;

  --rule:       rgba(30, 27, 22, 0.16);
  --rule-soft:  rgba(30, 27, 22, 0.07);

  --display: 'Instrument Serif', 'Times New Roman', Georgia, serif;
  --serif:   'Lora', Georgia, serif;
  --meta:    'Inter Tight', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono:    ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--meta);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 90rem;
  margin: 0 auto;
  padding: 0 1.5rem;
}

button { font-family: var(--meta); cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.45; }

/* ============ Head ============ */
.head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 2rem;
  padding: 1.2rem 0 1rem;
  border-bottom: 1px solid var(--rule);
  flex-wrap: wrap;
}
.head-id { display: flex; flex-direction: column; gap: 0.15rem; }
.head-back {
  font-size: 0.72rem;
  color: var(--graphite-2);
  text-decoration: none;
}
.head-back:hover { color: var(--ink); }
.head-name {
  font-family: var(--display);
  font-weight: 400;
  font-size: 1.9rem;
  line-height: 1.1;
  margin: 0;
  color: var(--ink);
}
.head-name em { font-style: italic; color: var(--moss); }
.head-sub {
  margin: 0.25rem 0 0;
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.85rem;
  color: var(--graphite-2);
}

.head-controls {
  display: flex;
  align-items: flex-end;
  gap: 1rem;
  flex-wrap: wrap;
}
.ctl { display: flex; flex-direction: column; gap: 0.25rem; }
.ctl-label {
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--graphite-2);
}
.ctl select {
  font-family: var(--meta);
  font-size: 0.8rem;
  color: var(--ink);
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 0.35rem 0.5rem;
  max-width: 21rem;
}
.ctl select:focus { outline: 1px solid var(--gold); }

#power {
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  color: var(--paper);
  background: var(--ink);
  border: 1px solid var(--ink);
  border-radius: 2px;
  padding: 0.42rem 1.1rem;
  transition: background 140ms, border-color 140ms;
}
#power:hover:not(:disabled) { background: var(--moss); border-color: var(--moss); }

/* Status lamp */
.lamp {
  width: 12px; height: 12px;
  border-radius: 50%;
  border: 1px solid var(--rule);
  background: var(--paper-3);
  margin-bottom: 0.6rem;
  flex: none;
}
.lamp.warm { background: var(--gold); animation: pulse 1.2s ease-in-out infinite; }
.lamp.on   { background: var(--moss); }
.lamp.run  { background: var(--gold); animation: pulse 0.8s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }

/* ============ Status strip ============ */
.strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--rule-soft);
  min-height: 2.3rem;
}
#boot-status { display: flex; align-items: center; gap: 1rem; flex: 1; min-width: 0; }
.boot-line {
  font-size: 0.74rem;
  color: var(--graphite);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.boot-line.ok  { color: var(--moss-deep); }
.boot-line.err { color: var(--brick); white-space: normal; }
.boot-bar {
  flex: 0 0 12rem;
  height: 5px;
  background: var(--paper-3);
  border: 1px solid var(--rule);
  border-radius: 2px;
  overflow: hidden;
}
.boot-fill { display: block; height: 100%; background: var(--gold); transition: width 200ms; }
.strip-right { display: flex; align-items: center; gap: 1rem; flex: none; }
#mode-blurb {
  font-size: 0.7rem;
  color: var(--chalk);
  text-align: right;
  max-width: 30rem;
}
#grammar-toggle {
  font-size: 0.66rem;
  letter-spacing: 0.1em;
  color: var(--graphite);
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 0.3rem 0.7rem;
}
#grammar-toggle:hover { color: var(--ink); border-color: var(--ink); }

/* ============ Grammar inspector ============ */
#grammar-panel {
  grid-template-columns: minmax(18rem, 2fr) minmax(20rem, 3fr);
  gap: 1.5rem;
  padding: 1rem 0 1.1rem;
  border-bottom: 1px solid var(--rule);
  max-height: 22rem;
  overflow-y: auto;
}
#grammar-panel h3 {
  font-size: 0.64rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--graphite-2);
  margin: 0 0 0.6rem;
}
.tool-row {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  padding: 0.45rem 0.6rem;
  border-left: 2px solid var(--moss);
  background: var(--paper-2);
  margin-bottom: 0.45rem;
}
.tool-row code { font-family: var(--mono); font-size: 0.74rem; color: var(--moss-deep); }
.tool-row span { font-size: 0.7rem; color: var(--graphite); }
.grammar-note {
  font-family: var(--serif);
  font-size: 0.74rem;
  color: var(--graphite-2);
  font-style: italic;
  margin: 0.6rem 0 0;
}
#grammar-schema pre {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.7rem;
  line-height: 1.55;
  color: var(--graphite);
  background: var(--paper-2);
  border: 1px solid var(--rule-soft);
  border-radius: 2px;
  padding: 0.7rem 0.85rem;
  overflow-x: auto;
}

/* ============ Bench ============ */
.bench {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(24rem, 5fr) minmax(20rem, 4fr);
  min-height: 0;
}

/* ------------ Probe log ------------ */
.probes {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--rule);
  padding-right: 1.5rem;
}
#probes-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 1.2rem 0.25rem 1rem 0;
}
#probes-empty {
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.9rem;
  color: var(--chalk);
  padding: 1.5rem 0.25rem;
}

#steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }

.step {
  display: grid;
  grid-template-columns: 2.4rem 1fr;
  position: relative;
}
.step-rail { position: relative; display: flex; justify-content: center; }
.step-rail::before {
  content: '';
  position: absolute;
  top: 0; bottom: 0;
  left: 50%;
  border-left: 1px solid var(--rule);
}
.step:first-child .step-rail::before { top: 0.9rem; }
.step:last-child .step-rail::before { bottom: auto; height: 0.9rem; }
.step-num {
  position: relative;
  z-index: 1;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 50%;
  width: 1.8rem; height: 1.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.64rem;
  color: var(--graphite);
  margin-top: 0.6rem;
  flex: none;
}
.step.done .step-num  { border-color: var(--moss); color: var(--moss-deep); }
.step.error .step-num { border-color: var(--brick); color: var(--brick); }

.step-body {
  background: var(--paper-2);
  border: 1px solid var(--rule-soft);
  border-radius: 2px;
  margin: 0.45rem 0;
  padding: 0.75rem 0.95rem 0.85rem;
}
.step.error .step-body { border-color: rgba(163, 74, 42, 0.4); }

.step-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}
.step-instruction {
  margin: 0;
  font-family: var(--serif);
  font-size: 0.9rem;
  color: var(--ink);
  white-space: pre-wrap;
}
.step-status {
  flex: none;
  font-size: 0.58rem;
  letter-spacing: 0.14em;
  padding: 0.14rem 0.5rem;
  border: 1px solid currentColor;
  border-radius: 2px;
}
.s-working { color: var(--gold); animation: pulse 1s ease-in-out infinite; }
.s-done  { color: var(--moss-deep); }
.s-error { color: var(--brick); }

.step-tabs {
  display: flex;
  gap: 1rem;
  margin: 0.6rem 0 0.5rem;
  border-bottom: 1px solid var(--rule-soft);
}
.step-tab {
  background: none;
  border: none;
  padding: 0 0 0.3rem;
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  color: var(--graphite-2);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.step-tab:hover { color: var(--ink); }
.step-tab.active { color: var(--ink); border-bottom-color: var(--gold); }

.panel-wait { margin: 0.2rem 0 0; font-size: 0.74rem; color: var(--graphite-2); font-style: italic; }
.panel-wait.err { color: var(--brick); }
.emit-meter { color: var(--gold); font-style: normal; }

/* Tool-call chips */
.chips { display: flex; flex-wrap: wrap; gap: 0.45rem; padding-top: 0.15rem; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 0.3rem 0.6rem;
  color: var(--ink);
  transition: border-color 120ms, background 120ms;
}
.chip:hover { border-color: var(--ink); }
.chip.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.chip-glyph { color: var(--moss); }
.chip.active .chip-glyph { color: var(--paper); }
.chip-tool { color: var(--graphite-2); font-size: 0.62rem; }
.chip.active .chip-tool { color: var(--paper-3); }
.chip-size { color: var(--chalk); font-size: 0.62rem; }
.chip-note { color: var(--graphite-2); background: transparent; border-style: dashed; }
.chip-note .chip-glyph { color: var(--chalk); }

.retry {
  margin-top: 0.6rem;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--ink);
  border-radius: 2px;
  padding: 0.35rem 0.9rem;
  transition: background 140ms, color 140ms;
}
.retry:hover:not(:disabled) { background: var(--ink); color: var(--paper); }

.trace-note {
  margin: 0 0 0.4rem;
  font-family: var(--serif);
  font-size: 0.72rem;
  color: var(--chalk);
  font-style: italic;
}
.trace-text {
  margin: 0;
  max-height: 14rem;
  overflow-y: auto;
  font-family: var(--mono);
  font-size: 0.72rem;
  line-height: 1.6;
  color: var(--graphite);
  background: var(--paper);
  border: 1px dashed var(--rule);
  border-radius: 2px;
  padding: 0.6rem 0.75rem;
  white-space: pre-wrap;
  word-break: break-word;
}
.trace-text.err { color: var(--brick); border-color: rgba(163, 74, 42, 0.5); margin-top: 0.5rem; }
.trace-text.live { margin-top: 0.5rem; max-height: 9rem; border-style: solid; border-color: var(--gold); }

/* Scratchpad panel */
.scratch { display: flex; flex-direction: column; gap: 0.5rem; }
.scratch-plan {
  font-family: var(--serif);
  font-size: 0.82rem;
  color: var(--ink);
  background: var(--paper);
  border-left: 2px solid var(--gold);
  padding: 0.45rem 0.7rem;
  white-space: pre-wrap;
}
.scratch-plan span {
  display: block;
  font-family: var(--meta);
  font-size: 0.58rem;
  letter-spacing: 0.14em;
  color: var(--graphite-2);
  margin-bottom: 0.15rem;
}
.scratch-thoughts {
  margin: 0;
  padding-left: 1.2rem;
  font-family: var(--serif);
  font-size: 0.8rem;
  color: var(--graphite);
}
.scratch-thoughts li { margin-bottom: 0.45rem; white-space: pre-wrap; }
.scratch-none { list-style: none; margin-left: -1.2rem; font-style: italic; color: var(--chalk); }

/* ------------ Feed ------------ */
#feed {
  border-top: 1px solid var(--rule);
  padding: 0.85rem 0 1.1rem;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.6rem;
  align-items: end;
}
.feed-label {
  grid-column: 1 / -1;
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--graphite-2);
}
#instruction {
  font-family: var(--serif);
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 0.55rem 0.7rem;
  min-height: 3.4rem;
  resize: vertical;
  width: 100%;
}
#instruction:focus { outline: 1px solid var(--gold); }
#instruction::placeholder { color: var(--chalk); font-style: italic; }

.feed-buttons { display: flex; flex-direction: column; gap: 0.4rem; }
#run {
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  color: var(--paper);
  background: var(--ink);
  border: 1px solid var(--ink);
  border-radius: 2px;
  padding: 0.5rem 1.2rem;
  transition: background 140ms, border-color 140ms;
}
#run:hover:not(:disabled) { background: var(--moss); border-color: var(--moss); }
#stop, #reset {
  font-size: 0.64rem;
  letter-spacing: 0.08em;
  color: var(--graphite);
  background: none;
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 0.3rem 0.7rem;
}
#stop:hover, #reset:hover { border-color: var(--brick); color: var(--brick); }

/* ------------ Findings inspector ------------ */
.inspector {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 1.2rem 0 1.1rem 1.5rem;
}
.inspector-head {
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--graphite-2);
  margin-bottom: 0.6rem;
}
#inspector-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.55rem;
}
.insp-tab {
  font-family: var(--mono);
  font-size: 0.68rem;
  background: var(--paper-2);
  border: 1px solid var(--rule-soft);
  border-radius: 2px;
  padding: 0.3rem 0.65rem;
  color: var(--graphite);
}
.insp-tab:hover { color: var(--ink); border-color: var(--rule); }
.insp-tab.active {
  background: var(--paper);
  color: var(--ink);
  border-color: var(--ink);
  border-bottom-color: var(--gold);
}

.inspector-body {
  flex: 1;
  min-height: 0;
  position: relative;
  border: 1px solid var(--rule);
  border-radius: 2px;
  background: var(--paper);
  overflow: hidden;
}
#inspector-empty {
  position: absolute; inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.9rem;
  color: var(--chalk);
}
#file-view {
  margin: 0;
  height: 100%;
  overflow: auto;
  padding: 1rem 1.1rem;
  font-family: var(--mono);
  font-size: 0.74rem;
  line-height: 1.65;
  white-space: pre;
  color: var(--ink);
  display: none;
}
#preview {
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
  display: none;
}

/* ============ Responsive ============ */
@media (max-width: 980px) {
  #app { height: auto; min-height: 100vh; }
  .bench { grid-template-columns: 1fr; }
  .probes { border-right: 0; padding-right: 0; }
  .inspector {
    padding-left: 0;
    border-top: 1px solid var(--rule);
    min-height: 26rem;
  }
  .inspector-body { min-height: 22rem; }
  #mode-blurb { display: none; }
  #grammar-panel { grid-template-columns: 1fr; }
}
