/* Shell styles. Ochre is UI-only: it never appears inside a neatline,
   where only data colours live (so it can't be read as "hot"). */
:root {
  --paper: #F6F2EA;
  --paper-2: #EEE8DC;
  --ink: #2F2D28;
  --ink-2: #6E685C;
  --rule: #D9D1C1;
  --dark: #2F2D28;
  --dark-2: #45413A;
  --on-dark: #E9E4D8;
  --on-dark-2: #A89F8C;
  --ochre: #B9773C;
  --neat: #2F2D28;
  --sans: "Noto Sans SC", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --H: 520px;          /* height of the working area; ui.js sets the real value */
  /* --M (main map side) is also set by ui.js: as tall as --H allows, as wide as the row allows. */
  --cap: 50px;         /* small-map caption height */
}

* { box-sizing: border-box; }
html, body { margin: 0; }
/* The whole app fits one screen: header / working area / footer, no page scroll. */
body {
  background: var(--paper);
  color: var(--ink);
  font: 14px/1.5 var(--sans);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100vh;
  overflow: hidden;
}
h1 { font-size: 16px; font-weight: 700; margin: 0; letter-spacing: .02em; }
h2 {
  font-size: 11px; font-weight: 500; letter-spacing: .12em; text-transform: uppercase;
  color: var(--ink-2); margin: 14px 0 6px;
}
h2:first-child { margin-top: 0; }

/* ---------- Geometric blocks: mid-tone fill, dark text, white on hover ---------- */
.block {
  font: 500 13px/1 var(--sans);
  color: var(--ink);
  background: var(--paper-2);
  border: 0;
  padding: 8px 12px;
  cursor: pointer;
  transition: color .12s, background .12s, box-shadow .12s;
}
.block:hover { color: #fff; background: var(--ink-2); }
.block.on { box-shadow: inset 0 0 0 2px var(--neat); }
.block.ochre { background: var(--ochre); color: #fff; }
.block.ochre:hover { background: var(--on-dark); color: var(--ochre); }
.seg { display: flex; gap: 2px; }
.seg .block { flex: 1; }

/* ---------- Dark bars (header + footer) ---------- */
.dark { background: var(--dark); color: var(--on-dark); }
.dark .block { background: var(--dark-2); color: var(--on-dark); }
.dark .block:hover { background: var(--on-dark); color: var(--dark); }
.dark .block.on { box-shadow: inset 0 0 0 2px var(--on-dark); }
.dark .block.ochre { background: var(--ochre); color: #fff; }
.dark .block.ochre:hover { background: var(--on-dark); color: var(--ochre); }

.top { display: flex; align-items: center; gap: 14px; padding: 10px 16px; }
.title { display: flex; align-items: center; gap: 10px; }
.mark { width: 14px; height: 14px; background: var(--ochre); }
.spacer { flex: 1; }
.top .seg { width: 220px; }

/* ---------- Working area ---------- */
.layout {
  display: flex; justify-content: center; gap: 16px;
  padding: 14px 16px; min-height: 0; overflow: hidden;
}
.tools { width: 200px; flex: none; overflow-y: auto; }

.palette { display: grid; gap: 2px; }
.palette .block {
  display: flex; align-items: center; gap: 8px; text-align: left; width: 100%;
  background: var(--c);
}
.palette .block:hover { background: var(--c); color: #fff; }
.palette .glyph { width: 18px; font-family: var(--mono); opacity: .8; }
/* Water is part of the natural base: shown for the legend, not selectable. */
.palette .block.locked { cursor: default; background-image: repeating-linear-gradient(135deg, transparent 0 6px, rgba(255,255,255,.18) 6px 8px); }
.palette .block.locked:hover { color: #fff; }

.constraints { display: grid; gap: 8px; }
.meter { font-size: 12px; }
.meter .row { display: flex; justify-content: space-between; }
.meter .row b { font: 500 12px var(--mono); }
.meter .bar { height: 5px; background: var(--paper-2); margin-top: 3px; }
.meter .bar i { display: block; height: 100%; background: var(--ink-2); }
.meter.ok .bar i { background: #6E9A6A; }

/* ---------- Neatline: every map and chart sits in a dark frame ---------- */
figure { margin: 0; }
.neatline { position: relative; border: 1.5px solid var(--neat); background: #fff; }
.neatline canvas { display: block; }
figcaption {
  font-size: 12px; color: var(--ink-2); padding: 5px 8px; height: var(--cap);
  border-top: 1px solid var(--rule); background: var(--paper);
}

/* Main map: a square as tall as the working area allows. */
.mapwrap { flex: none; display: flex; flex-direction: column; align-items: center; }
.main canvas { width: var(--M, 480px); height: var(--M, 480px); cursor: crosshair; }
.north {
  position: absolute; top: 8px; right: 8px; font: 500 11px var(--mono);
  display: flex; flex-direction: column; align-items: center; line-height: 1;
  background: rgba(255,255,255,.75); padding: 4px 6px;
}
.north span { font-size: 9px; }
.scale {
  position: absolute; left: 8px; bottom: 8px; display: flex; align-items: center; gap: 6px;
  font: 11px var(--mono); background: rgba(255,255,255,.75); padding: 4px 6px;
}
.scale span { width: 60px; height: 5px; border: 1px solid var(--ink); border-top: 0;
  background: linear-gradient(90deg, var(--ink) 50%, #fff 50%); }
.scale em { font-style: normal; }
.hint { font-size: 12px; color: var(--ink-2); height: 24px; padding-top: 4px; }

/* Small maps: 2 × 2, each tile sized so two rows fill the working area. */
.panel { flex: none; }
.smalls { display: grid; grid-template-columns: auto auto; gap: 10px; }
.smalls canvas { width: var(--T, 150px); height: var(--T, 150px); }   /* --T set by ui.js */
.small figcaption { display: grid; gap: 2px; width: 0; min-width: 100%; }
.small .name { color: var(--ink); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.legend { display: flex; align-items: center; gap: 6px; font: 10px var(--mono); color: var(--ink-2); }
.legend i { flex: 1; height: 6px; }

/* ---------- Footer: trade-off · readouts · agent log ---------- */
.term {
  display: grid; grid-template-columns: auto 380px minmax(0, 1fr); gap: 16px;
  height: 150px; padding: 12px 16px; font: 12px/1.6 var(--mono);
}
.trade { border-color: var(--on-dark); }
.trade canvas { width: 124px; height: 124px; }

.readouts { display: grid; gap: 2px; align-content: start; }
.readout {
  display: grid; grid-template-columns: 1fr 56px 52px 64px; align-items: center; gap: 8px;
  padding: 2px 8px; background: var(--dark-2); font: 12px/1.5 var(--sans);
}
.readout em { font: 12px var(--mono); font-style: normal; text-align: right; }
.readout.better { animation: flashG 1.4s ease-out; } .readout.better em { color: #A9D6A0; }
.readout.worse { animation: flashR 1.4s ease-out; } .readout.worse em { color: #F0A58A; }
@keyframes flashG { from { background: #4E7A4A; } to { background: var(--dark-2); } }
@keyframes flashR { from { background: #8C3A28; } to { background: var(--dark-2); } }
.readout b { font: 500 12px var(--mono); text-align: right; color: #fff; }
.readout canvas { width: 64px; height: 16px; }

.logwrap { display: flex; flex-direction: column; min-height: 0; }
.termhead { display: flex; justify-content: space-between; color: var(--on-dark-2); margin-bottom: 2px; gap: 12px; }
.termhead em { font-style: normal; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#log { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
#log li::before { content: "> "; color: var(--ochre); }
#log .t { color: #8E8676; margin-right: 8px; }
#log .warn { color: #E7B07A; }
#log .good { color: #A9D6A0; }
/* Revealed tile: a thicker neatline marks observed data, not model output. */
.small.observed { border-width: 3px; }
#log .act { cursor: pointer; }
#log .act:hover { color: #fff; background: var(--dark-2); }
.ask { width: 100%; margin-top: 16px; padding: 10px 12px; }
.blockpanel { font-size: 12px; display: grid; gap: 8px; }
.blockpanel .muted { color: var(--ink-2); }
.blockpanel .head { display: flex; align-items: center; gap: 8px; }
.blockpanel .sw { width: 12px; height: 12px; }
.slider { display: grid; gap: 2px; }
.slider .row { display: flex; justify-content: space-between; }
.slider .row b { font: 500 12px var(--mono); }
.slider input { width: 100%; accent-color: var(--ochre); }
.slider input:disabled { opacity: .4; }
.meter.bad .bar i { background: #C8541A; }
.ask:disabled { opacity: .6; cursor: wait; }

/* ---------- Agent evaluation view ---------- */
.layout { position: relative; }
.av { position: absolute; inset: 0; background: var(--paper); z-index: 5; display: flex; flex-direction: column;
  padding: 12px 16px; gap: 10px; animation: avIn .25s ease-out; }
.av.hidden { display: none; }
@keyframes avIn { from { opacity: 0; transform: scale(.985); } to { opacity: 1; transform: none; } }
.avhead { display: flex; justify-content: space-between; align-items: center; font: 500 13px var(--mono); letter-spacing: .12em; }
.avhead span::before { content: "▶ "; color: var(--ochre); }
.avbody { display: flex; gap: 16px; min-height: 0; flex: 1; }
.avgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; width: calc(var(--H) - 130px); flex: none; align-content: start; }
.avgrid canvas { width: 100%; height: auto; aspect-ratio: 1; }
.avgrid figcaption { height: auto; padding: 3px 8px; font-size: 12px; }
.avgrid figure { opacity: .45; transition: opacity .3s, border-width .3s; }
.avgrid figure.now, .avgrid figure.done { opacity: 1; }
.avgrid figure.now { border-width: 3px; }
.avside { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 10px; overflow-y: auto; }
#avSteps { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 14px; }
#avSteps li { padding: 8px 10px; background: var(--paper-2); border-left: 4px solid var(--rule); animation: avIn .3s ease-out; }
#avSteps li.now { border-left-color: var(--ochre); background: #fff; }
.avsc canvas { width: 100%; height: auto; }
#avCards { display: grid; gap: 8px; }
.card { background: #fff; border: 1.5px solid var(--neat); padding: 10px 12px; font-size: 13px; display: grid; gap: 8px; animation: avIn .3s ease-out; }
.card .n { font: 500 12px var(--mono); color: var(--ochre); }
.card .block { justify-self: start; }
.palette h2 { margin-top: 10px; }
#rain .block { padding: 7px 4px; font-size: 12px; }
.tool-cost { margin-left: auto; font: 11px var(--mono); opacity: .75; }

/* ---------- Block popup ---------- */
.popup { position: absolute; z-index: 3; width: 250px; background: #fff; border: 1.5px solid var(--neat);
  box-shadow: 0 6px 20px rgba(47,45,40,.18); padding: 10px 12px; animation: avIn .15s ease-out; }
.popup.hidden { display: none; }
.popup .head { justify-content: space-between; }
.popup .head b { flex: 1; font-weight: 500; }
.popup .x { border: 0; background: none; font-size: 18px; line-height: 1; cursor: pointer; color: var(--ink-2); }
.popup .x:hover { color: var(--ink); }
.deltas { display: grid; grid-template-columns: 1fr auto 52px; gap: 3px 8px; font-size: 12px;
  border-top: 1px solid var(--rule); padding-top: 8px; align-items: baseline; }
.deltas b { font: 500 12px var(--mono); text-align: right; }
.deltas i { font: 12px var(--mono); font-style: normal; text-align: right; color: var(--ink-2); }
.deltas i.up { color: #4E8A4A; } .deltas i.down { color: #B5462A; }

/* ---------- Change view (difference maps) ---------- */
.cvsum { font-size: 14px; padding: 8px 10px; background: #fff; border-left: 4px solid var(--ochre); }
.cvgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; min-height: 0; }
.cvgrid canvas { width: 100%; height: auto; aspect-ratio: 1; }
.cvgrid figcaption { height: auto; display: grid; gap: 2px; }
.cvgrid .d { font: 500 13px var(--mono); }
.cvgrid .d.up { color: #B5462A; } .cvgrid .d.down { color: #2F6E8F; }

/* ---------- On-map change toast ---------- */
.toast { position: absolute; z-index: 4; display: grid; gap: 1px; padding: 6px 9px; background: rgba(47,45,40,.92);
  color: #fff; font: 12px var(--mono); pointer-events: none; animation: toast 2.6s ease-out forwards; }
.toast .good { color: #A9D6A0; } .toast .bad { color: #F0A58A; }
@keyframes toast { 0% { opacity: 0; transform: translateY(6px); } 10%, 75% { opacity: 1; transform: none; } 100% { opacity: 0; transform: translateY(-8px); } }
