/* From Shelf to Supply — story view.
   Palette taken from the subject: ink-navy shop lettering, signage yellow,
   phin-coffee brown, tile blue for anything the viewer can act on. */
:root {
  --navy: #14213d;
  --tile: #0040ff;
  --sign: #ffc72c;
  --phin: #5b3a29;
  --ice: #eef2f4;
  --milk: #ffffff;
  --out: #d6304a;
  --soft: rgba(20, 33, 61, 0.62);
  --hair: rgba(20, 33, 61, 0.16);
  --face: "Be Vietnam Pro", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--ice); color: var(--navy); font-family: var(--face); }
button { font-family: inherit; }
:focus-visible { outline: 3px solid var(--tile); outline-offset: 2px; }

.bar { height: 56px; display: flex; align-items: center; gap: 28px; padding: 0 24px; background: var(--navy); color: #fff; }
.bar .brand { display: flex; align-items: baseline; gap: 12px; white-space: nowrap; }
.bar .brand strong { font-size: 19px; font-weight: 700; letter-spacing: -0.01em; }
.bar .brand span { font-size: 13px; opacity: 0.7; }
.views { display: flex; gap: 4px; }
.views button { font-size: 14px; font-weight: 500; color: #fff; background: transparent; border: 0; padding: 8px 14px; border-radius: 999px; cursor: pointer; }
.views button.on { background: #fff; color: var(--navy); }
.flag { margin: 0 0 0 auto; font-size: 13px; font-weight: 500; background: var(--sign); color: var(--navy); padding: 6px 12px; border-radius: 3px; }

.story { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(360px, 1fr); grid-template-rows: 1fr auto; height: calc(100vh - 56px); min-height: 640px; }
.story[hidden], .engine[hidden] { display: none; }
.stage { position: relative; padding: 12px 8px 0 20px; min-height: 0; }
#map { width: 100%; height: calc(100% - 30px); display: block; }
.maplegend { margin: 0; height: 30px; font-size: 12px; color: var(--soft); display: flex; align-items: center; gap: 6px; }
.maplegend .k { display: inline-block; width: 18px; height: 0; border-top: 3px solid var(--navy); margin-left: 14px; }
.maplegend .k:first-child { margin-left: 0; }
.maplegend .k.demo { border-color: var(--tile); }
.maplegend .k.prop { border-top-style: dashed; border-color: var(--soft); }

/* map pieces */
.street { fill: #dfe6ea; }
.streetname { font-size: 12px; fill: var(--soft); }
.plot { fill: var(--milk); stroke: var(--navy); stroke-width: 1.5; transition: opacity 0.4s; }
.awning { fill: var(--navy); }
.awning.pos { fill: var(--phin); }
.shopname { font-size: 15px; font-weight: 700; fill: #fff; }
.shopsub { font-size: 11.5px; fill: var(--soft); }
.node-label { font-size: 13px; font-weight: 600; fill: var(--navy); }
.node-sub { font-size: 11px; fill: var(--soft); }
.engine-box { fill: var(--tile); stroke: var(--tile); }
.engine-box + text, .on-blue { fill: #fff; }
.dashed { stroke-dasharray: 6 5; }
.person { fill: var(--navy); }
.flow { fill: none; stroke: var(--hair); stroke-width: 2.5; stroke-linecap: round; transition: stroke 0.4s, stroke-width 0.4s; }
.flow.live { stroke: var(--tile); stroke-width: 3.5; }
.flow.live.built { stroke: var(--navy); }
.flow.prop { stroke-dasharray: 7 6; }
.flow.live.prop { stroke: var(--soft); }
.dim { opacity: 0.28; }
g[data-node] { transition: opacity 0.4s; }
.token circle { fill: var(--sign); stroke: var(--navy); stroke-width: 1.5; }
.token text { font-size: 11px; font-weight: 600; fill: var(--navy); }
.tin-track { fill: var(--ice); stroke: var(--hair); }
.tin-fill { fill: var(--phin); transition: y 0.9s ease, height 0.9s ease, fill 0.3s; }
.tin-fill.low { fill: #b9772f; }
.tin-fill.out { fill: var(--out); }
.tin-mark { stroke: var(--navy); stroke-width: 1.5; stroke-dasharray: 2 2; }
.tin-name { font-size: 9.5px; fill: var(--soft); }
.tin-val { font-size: 10px; font-weight: 600; fill: var(--navy); font-variant-numeric: tabular-nums; }
.callout { font-size: 12px; font-weight: 600; fill: var(--navy); }
.callout-bg { fill: var(--sign); }
.truck { transition: opacity 0.3s; }

/* narrative column */
.narr { background: var(--milk); border-left: 1px solid var(--navy); padding: 18px 26px 12px; overflow-y: auto; min-height: 0; }
.scenario { border-bottom: 1px solid var(--hair); padding-bottom: 14px; margin-bottom: 16px; }
.scenario .q { font-size: 13px; color: var(--soft); margin: 0 0 8px; }
.scenario .opts { display: flex; gap: 6px; flex-wrap: wrap; }
.scenario .opts button { font-size: 13px; font-weight: 500; padding: 7px 12px; border: 1.5px solid var(--navy); background: #fff; color: var(--navy); border-radius: 999px; cursor: pointer; }
.scenario .opts button.on { background: var(--navy); color: #fff; }
.scenario .knob { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; margin-top: 12px; font-size: 13px; }
.scenario .knob input { grid-column: 1 / -1; width: 100%; accent-color: var(--tile); }
.scenario .knob output { font-weight: 700; font-variant-numeric: tabular-nums; }
.scenario .blurb { font-size: 13px; color: var(--soft); margin: 8px 0 0; }

#chapter .where { font-size: 13px; color: var(--soft); margin: 0 0 6px; font-variant-numeric: tabular-nums; }
#chapter h1 { font-size: 27px; line-height: 1.15; letter-spacing: -0.02em; margin: 0 0 10px; font-weight: 700; max-width: 22ch; }
#chapter .lede { font-size: 15.5px; line-height: 1.5; margin: 0 0 14px; max-width: 46ch; }
.status { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 3px; margin: 0 6px 12px 0; }
.status.built { background: var(--navy); color: #fff; }
.status.demo { background: var(--tile); color: #fff; }
.status.prop { border: 1.5px dashed var(--navy); }
.status.syn { background: var(--sign); }
.art { border: 1.5px solid var(--navy); border-radius: 4px; padding: 12px 14px; font-size: 13.5px; margin-bottom: 10px; }
.art h2 { font-size: 13px; margin: 0 0 8px; font-weight: 600; }
.art table { width: 100%; border-collapse: collapse; font-size: 13px; }
.art td, .art th { padding: 4px 0; border-bottom: 1px solid var(--hair); text-align: left; font-weight: 400; vertical-align: top; }
.art th { color: var(--soft); font-size: 12px; text-transform: none; letter-spacing: 0; font-family: var(--face); }
.art tr:last-child td { border-bottom: 0; }
.art .n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; padding-left: 10px; }
.art .big { font-size: 34px; font-weight: 700; letter-spacing: -0.03em; line-height: 1; }
.art.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.art pre { font: 12px/1.55 ui-monospace, "SF Mono", Menlo, monospace; white-space: pre-wrap; margin: 6px 0 0; background: var(--ice); padding: 8px 10px; border-left: 3px solid var(--tile); }
.pill { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 1px 7px; border-radius: 999px; border: 1.5px solid currentColor; white-space: nowrap; }
.pill.ok { color: #0b7a4b; } .pill.warn { color: #8a5a00; } .pill.bad { color: var(--out); }
.fine { font-size: 12px; color: var(--soft); margin: 6px 0 0; line-height: 1.45; }
.act { font-size: 14px; font-weight: 600; padding: 9px 16px; border: 1.5px solid var(--navy); background: #fff; color: var(--navy); border-radius: 4px; cursor: pointer; margin: 8px 8px 0 0; }
.act.primary { background: var(--tile); border-color: var(--tile); color: #fff; }
.act:disabled { opacity: 0.35; cursor: not-allowed; }
.act.done:disabled { opacity: 1; cursor: default; background: #e7f4ec; border-color: #0b7a4b; color: #0b7a4b; }
.act.done::before { content: "✓ "; }
.who { font-size: 13px; padding: 5px 8px; border: 1.5px solid var(--navy); border-radius: 4px; background: #fff; font-family: inherit; color: var(--navy); }
.msg { font-size: 13px; margin: 8px 0 0; font-weight: 500; }
.msg.err { color: var(--out); }
.msg.good { color: #0b7a4b; }

/* ten-day replay strip */
.strip { display: grid; grid-template-columns: 96px repeat(10, 1fr); gap: 3px; align-items: center; font-size: 11.5px; margin-top: 6px; }
.strip .h { color: var(--soft); text-align: center; font-variant-numeric: tabular-nums; }
.strip .h.hit { color: var(--navy); font-weight: 700; border-bottom: 3px solid var(--sign); }
.strip .rowname { color: var(--soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.strip .grp { grid-column: 1 / -1; font-weight: 600; font-size: 12.5px; margin-top: 8px; }
.cell { display: block; height: 15px; background: var(--phin); border-radius: 2px; }
.cell.v0 { background: var(--out); } .cell.v1 { background: #f0a35e; } .cell.v2 { background: #f3d68a; } .cell.v3 { background: #b9dcc4; }
.cell.now { outline: 2px solid var(--tile); outline-offset: 1px; }
.key { display: flex; gap: 12px; font-size: 11.5px; color: var(--soft); margin-top: 8px; align-items: center; flex-wrap: wrap; }
.key i.cell { display: inline-block; width: 12px; height: 12px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.versus { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 4px 0 2px; }
.versus .big { font-size: 30px; }
.versus p { margin: 2px 0 0; font-size: 12.5px; color: var(--soft); }

/* timeline */
.timeline { grid-column: 1 / -1; display: flex; align-items: center; gap: 14px; padding: 10px 24px; background: var(--milk); border-top: 1px solid var(--navy); }
.play { font-size: 14px; font-weight: 600; min-width: 84px; padding: 9px 16px; background: var(--navy); color: #fff; border: 0; border-radius: 999px; cursor: pointer; }
.step { font-size: 13px; font-weight: 500; padding: 8px 12px; background: #fff; border: 1.5px solid var(--navy); color: var(--navy); border-radius: 999px; cursor: pointer; }
.clock { font-size: 13px; font-variant-numeric: tabular-nums; color: var(--soft); min-width: 86px; }
#stops { list-style: none; margin: 0; padding: 0; display: flex; flex: 1; gap: 4px; }
#stops li { flex: 1; }
#stops button { width: 100%; text-align: left; font-size: 12px; font-weight: 500; color: var(--soft); background: none; border: 0; border-top: 4px solid var(--hair); padding: 6px 2px 0; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#stops li.done button { border-top-color: var(--navy); }
#stops li.on button { border-top-color: var(--tile); color: var(--navy); font-weight: 700; }

@media (max-width: 980px) {
  .story { grid-template-columns: 1fr; height: auto; }
  .narr { border-left: 0; border-top: 1px solid var(--navy); }
  .bar { height: auto; flex-wrap: wrap; padding: 10px 16px; gap: 10px; }
  .flag { margin-left: 0; }
  #stops button { font-size: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .tin-fill, .flow, g[data-node] { transition: none; }
}

.art details { margin-top: 8px; }
.art summary { cursor: pointer; font-size: 13px; font-weight: 600; }
