/* Frontier Story Panel. Three themes: Book (the default), Dark and Light, chosen in the
   footer; each is one token set, and Book adds a few texture rules at the end.
   Fonts are bundled (SIL OFL, see fonts/) because the server may have no internet. Monocraft
   is the display face - titles, labels, buttons - and is a pixel font on a grid of nine units
   per em-ninth, so it is only ever set at 9, 18 or 27px, where every pixel lands on one. */

@font-face { font-family: "Monocraft"; src: url(fonts/monocraft.woff2) format("woff2"); font-display: swap; }
@font-face { font-family: "IBM Plex Sans"; src: url(fonts/ibm-plex-sans.woff2) format("woff2"); font-weight: 100 700; font-display: swap; }
@font-face { font-family: "JetBrains Mono"; src: url(fonts/jetbrains-mono.woff2) format("woff2"); font-weight: 100 800; font-display: swap; }

:root {
  --bg: #13161c; --panel: #1a1e26; --raise: #222733; --line: #2e3542; --fg: #e6e9ef; --muted: #8d96a8;
  --state: #e0a83a; --talk: #4f8cf0; --act: #3fb37f; --stop: #7b8496; --warn: #e2584d; --step: #a377e6;
  --accent: #4f8cf0; --wire: #3a4352; --shadow: rgb(0 0 0 / .3);
  --display: "Monocraft", ui-monospace, monospace;
  --pixel: "Monocraft", ui-monospace, monospace;
  --body: "IBM Plex Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #eef1f6; --panel: #ffffff; --raise: #f4f6fa; --line: #d5dbe5; --fg: #18202c; --muted: #5d687b;
    --state: #b77d0f; --talk: #2f6fd8; --act: #1f8a5b; --stop: #6a7386; --warn: #c23a2f; --step: #7a4fc4;
    --accent: #2f6fd8; --wire: #b9c2d0; --shadow: rgb(20 30 50 / .14);
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #eef1f6; --panel: #ffffff; --raise: #f4f6fa; --line: #d5dbe5; --fg: #18202c; --muted: #5d687b;
  --state: #b77d0f; --talk: #2f6fd8; --act: #1f8a5b; --stop: #6a7386; --warn: #c23a2f; --step: #7a4fc4;
  --accent: #2f6fd8; --wire: #b9c2d0; --shadow: rgb(20 30 50 / .14);
  color-scheme: light;
}

/* Book: a written book's pages on a leather binding. Ink colours re-tuned to read on cream. */
:root[data-theme="book"] {
  --bg: #efe2c2; --panel: #f9f1dc; --raise: #ecdfbd; --line: #a88b5c; --fg: #2a1b0c; --muted: #5f4728;
  --state: #8f5300; --talk: #1d4a94; --act: #2c6626; --stop: #59554c; --warn: #a12a20; --step: #643a8a;
  --accent: #1d4a94; --wire: #3a2814; --shadow: rgb(70 45 15 / .2);
  --leather: #5b3a21; --leather-dark: #3b2513; --leather-fg: #f4e6c6; --leather-muted: #d7bf92; --stitch: #c8a266;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { background: var(--bg); color: var(--fg); font: 14px/1.45 var(--body); margin: 0; overflow: hidden; }
a { color: var(--accent); }
code, .mono { font-family: var(--mono); font-size: 12px; }
h2, h3, h4 { font-family: var(--display); }
p { margin: 0; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.warn { color: var(--warn); }
.spacer { flex: 1; }
.skip { position: absolute; left: -999px; top: 0; z-index: 99; background: var(--accent); color: #fff; padding: 6px 10px; }
.skip:focus { left: 8px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- shell ---- */
.app { display: grid; grid-template-columns: 210px minmax(0, 1fr) 360px; grid-template-rows: auto minmax(0, 1fr) auto; height: 100%; }
.top { grid-column: 1 / -1; display: flex; gap: 14px; align-items: center; padding: 9px 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { font: 700 18px var(--display); letter-spacing: .01em; white-space: nowrap; }
.brand small { display: block; font: 400 10.5px var(--mono); color: var(--muted); letter-spacing: .06em; }
.search-box { position: relative; width: min(380px, 40vw); }
.search-box input { width: 100%; }
.stage { all: unset; cursor: pointer; display: flex; align-items: center; gap: 8px; font: 12px var(--mono); color: var(--muted); padding: 6px 8px; border-radius: 6px; }
.stage:hover { background: var(--raise); }
.stage:focus-visible { outline: 2px solid var(--accent); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--state); flex: none; }
.dot.live { background: var(--act); }
.dot.bad { background: var(--warn); }

.rail { border-right: 1px solid var(--line); background: var(--panel); padding: 10px 8px 20px; overflow: auto; }
.rail h3 { font: 600 10.5px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 14px 8px 5px; }
.rail a { display: flex; justify-content: space-between; gap: 6px; padding: 5px 8px; border-radius: 6px; color: var(--fg); text-decoration: none; font-size: 13px; }
.rail a .l { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail a .m { font: 11px var(--mono); color: var(--muted); flex: none; }
.rail a:hover { background: var(--raise); }
.rail a.on { background: var(--raise); box-shadow: inset 3px 0 0 var(--accent); }
.rail a.staged .l::after { content: " •"; color: var(--state); }

.main { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }
.head { padding: 10px 16px 10px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px; }
.head-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.head h2 { font: 700 21px var(--display); margin: 0; text-wrap: balance; }
.head-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-left: auto; align-items: center; }
.head .desc { color: var(--muted); max-width: 80ch; font-size: 13px; }
.crumbs { font: 12px var(--mono); color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--fg); text-decoration: underline; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font: 11px var(--mono); color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.legend.vert { flex-direction: column; gap: 6px; }
.view { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; outline: none; }

.aside { border-left: 1px solid var(--line); background: var(--panel); overflow: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.foot { grid-column: 1 / -1; display: flex; gap: 14px; align-items: center; padding: 4px 14px; border-top: 1px solid var(--line); background: var(--panel); font: 11px var(--mono); color: var(--muted); }
.theme-pick { display: inline-flex; gap: 6px; align-items: center; }
.theme-pick select { padding: 2px 6px; font-size: 12px; }
.link.live::before { content: "● "; color: var(--act); }
.link.lost::before { content: "● "; color: var(--warn); }

/* ---- controls ---- */
.btn { all: unset; box-sizing: border-box; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 6px; border: 1px solid var(--line); font: 500 13px var(--body); color: var(--fg); background: var(--raise); white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.small { padding: 4px 9px; font-size: 12px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--warn); }
.btn.danger:hover { border-color: var(--warn); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn[disabled], .icon[disabled] { opacity: .45; cursor: default; pointer-events: none; }
.btn[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
a.btn { text-decoration: none; }
.icon { all: unset; cursor: pointer; width: 24px; height: 24px; display: inline-grid; place-items: center; border-radius: 5px; color: var(--muted); font-size: 14px; }
.icon:hover { background: var(--raise); color: var(--fg); }
.icon:focus-visible { outline: 2px solid var(--accent); }
.linkish { all: unset; cursor: pointer; color: var(--accent); font-weight: 500; }
.linkish:focus-visible { outline: 2px solid var(--accent); }
input[type=text], input[type=search], input[type=number], select, textarea {
  font: 13px var(--body); color: var(--fg); background: var(--raise); border: 1px solid var(--line); border-radius: 6px; padding: 6px 9px; min-width: 0;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 35%, transparent); }
input.num { width: 84px; }
textarea { resize: vertical; width: 100%; font-family: var(--mono); font-size: 12.5px; line-height: 1.5; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label, .extras > label { font: 600 10.5px var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.field > input, .field > select { width: 100%; }
.hint { font-size: 11.5px; color: var(--muted); }
.hint.warn { color: var(--warn); }
label.inline { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 30px; height: 17px; border-radius: 99px; background: var(--line); position: relative; flex: none; transition: background .15s; }
.switch .track i { position: absolute; top: 2px; left: 2px; width: 13px; height: 13px; border-radius: 50%; background: var(--fg); transition: transform .15s; }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track i { transform: translateX(13px); background: #fff; }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch.small { font-size: 12px; }
.chip { font: 600 10px var(--mono); letter-spacing: .04em; padding: 2px 7px; border-radius: 99px; border: 1px solid currentColor; white-space: nowrap; color: var(--c, var(--muted)); }
.stage-chip { --c: var(--talk); white-space: normal; text-align: left; background: transparent; cursor: pointer; border-radius: 8px; padding: 4px 8px; }
.tag { font: 600 9.5px var(--mono); letter-spacing: .04em; padding: 1px 5px; border-radius: 4px; background: var(--raise); color: var(--muted); text-transform: none; margin-left: 5px; border: 1px solid var(--line); }
.tag.gate, .gate-chip { color: var(--state); border-color: color-mix(in srgb, var(--state) 50%, transparent); }
.tag.warn, .warn-chip { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 50%, transparent); }
.tag.staged { position: absolute; top: 8px; right: 8px; color: var(--state); }
.badge { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 99px; font: 700 10.5px var(--mono); color: #fff; margin-left: 6px; }
.badge.broken { background: var(--warn); }
.badge.suspect { background: var(--state); color: #1b1300; }
.mini .ph { font-family: var(--mono); font-size: .92em; padding: 0 3px; border-radius: 3px; background: color-mix(in srgb, var(--talk) 20%, transparent); }

/* picker */
.picker { all: unset; box-sizing: border-box; cursor: pointer; display: flex; align-items: center; gap: 8px; width: 100%; min-height: 32px; padding: 5px 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--raise); font-size: 13px; }
.picker:hover { border-color: var(--accent); }
.picker:focus-visible { outline: 2px solid var(--accent); }
.picker code { margin-left: auto; color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; }
.picker::after { content: "▾"; color: var(--muted); font-size: 11px; }
.picker-fallback input { width: 100%; }
.popover { position: fixed; z-index: 50; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 10px 30px var(--shadow); padding: 6px; display: flex; flex-direction: column; gap: 6px; max-height: 340px; }
.popover input { width: 100%; }
.popover ul, ul.search-pop { list-style: none; margin: 0; padding: 0; overflow: auto; }
.popover li { display: flex; gap: 8px; align-items: baseline; padding: 5px 8px; border-radius: 5px; cursor: pointer; font-size: 13px; }
.popover li code { margin-left: auto; color: var(--muted); font-size: 11px; }
.popover li small { color: var(--muted); }
.popover li[aria-selected="true"] { background: var(--raise); box-shadow: inset 2px 0 0 var(--accent); }
.popover li.group { font: 600 10px var(--mono); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); cursor: default; padding-top: 8px; }
.popover li.empty { color: var(--muted); cursor: default; }
.popover li.muted { color: var(--muted); }
.search-pop { position: absolute; top: calc(100% + 4px); left: 0; right: 0; }
.search-pop .kind { font: 600 10px var(--mono); text-transform: uppercase; color: var(--muted); width: 74px; flex: none; }

/* inspector */
.insp { display: flex; flex-direction: column; gap: 14px; }
.insp > .btn, .insp > a.btn, .replies > .btn, .aside > .btn, .aside > a.btn { align-self: flex-start; }
.insp h4 { font: 700 18px var(--display); margin: 0; color: var(--c, var(--fg)); display: flex; align-items: center; }
.insp .id { font: 11.5px var(--mono); color: var(--muted); word-break: break-all; }
.note { font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 12px; }
.preview { background: #0d0f13; color: #fff; border-radius: 6px; padding: 7px 10px; font: 13px var(--body); display: flex; flex-direction: column; gap: 2px; }
.lines { display: flex; flex-direction: column; gap: 6px; }
.problems { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.problems li { border-left: 3px solid var(--state); background: var(--raise); padding: 6px 9px; border-radius: 0 6px 6px 0; font-size: 12.5px; }
.problems li.broken { border-color: var(--warn); }
.problems li.quiet { border-color: var(--stop); }
.problems li b { font: 700 10px var(--mono); letter-spacing: .05em; }
/* The problems page: grouped by severity, then by kind. */
.problems-link { position: relative; }
.badge.quiet { background: var(--stop); }
.problems-page { padding: 18px 22px 40px; display: flex; flex-direction: column; gap: 22px; }
.prob-group h3 { display: flex; align-items: center; gap: 8px; margin: 0 0 6px; font-size: 15px; }
.prob-kind { margin: 14px 0 6px; font: 600 12px var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.prob-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.prob-row { display: block; border: 1px solid var(--line); border-left: 4px solid var(--state); background: var(--panel); border-radius: 0 6px 6px 0; padding: 8px 12px; color: var(--fg); text-decoration: none; }
a.prob-row:hover, a.prob-row:focus-visible { border-color: var(--accent); border-left-color: var(--accent); outline: none; background: var(--raise); }
.prob-row.broken { border-left-color: var(--warn); }
.prob-row.quiet { border-left-color: var(--stop); }
.prob-row.plain { opacity: .92; }
.prob-what { font-weight: 600; font-size: 13.5px; }
.prob-where { font: 11.5px var(--mono); color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }
.prob-fix { font-size: 12.5px; margin-top: 4px; }
/* Find and replace. */
.find-page { padding: 16px 22px 90px; display: flex; flex-direction: column; gap: 14px; }
.find-form { display: flex; flex-direction: column; gap: 8px; }
.find-inputs { display: grid; grid-template-columns: auto minmax(0, 1fr) auto minmax(0, 1fr) auto; gap: 8px; align-items: center; }
.find-inputs label { font: 600 11px var(--mono); text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.find-summary { font-size: 13px; color: var(--muted); min-height: 1.2em; }
.find-entry { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 8px 12px; margin-bottom: 10px; }
.find-entry.locked { opacity: .65; }
.find-entry h4 { margin: 0 0 6px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 14px; }
.find-hit { display: flex; gap: 8px; padding: 5px 0; border-top: 1px dashed var(--line); align-items: flex-start; }
.find-hit input { margin-top: 3px; }
.find-body { min-width: 0; flex: 1; font-size: 12.5px; }
.find-ctx { font: 12px var(--mono); overflow-wrap: anywhere; white-space: pre-wrap; }
.find-ctx mark { background: color-mix(in srgb, var(--state) 45%, transparent); color: inherit; border-radius: 2px; padding: 0 1px; }
.find-new { margin-top: 2px; }
.find-staged { font-size: 11.5px; color: var(--muted); }
.find-staged.warn { color: var(--warn); font-weight: 600; }
.find-bar { position: sticky; bottom: 0; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; box-shadow: 0 -4px 14px var(--shadow); }
.find-bar:empty { display: none; }
.find-bar .spacer { flex: 1; }
/* Read-only cards: dark like a game tooltip, so a name's own colours read as they do in game. */
.card-pop { position: fixed; z-index: 60; width: 260px; max-width: calc(100vw - 16px); padding: 10px 12px; border-radius: 6px; background: #160b1f; color: #f1ecf7; border: 2px solid #3b1d5e; box-shadow: 0 6px 24px rgb(0 0 0 / .45); pointer-events: none; font: 13px var(--body); }
.card-head { display: flex; gap: 10px; align-items: center; }
.card-tile { flex: none; width: 36px; height: 36px; display: grid; place-items: center; border: 2px solid; border-radius: 4px; font: 18px var(--pixel); color: #fff; text-shadow: 0 1px 0 rgb(0 0 0 / .5); image-rendering: pixelated; }
.card-name { font-weight: 600; font-size: 14px; overflow-wrap: anywhere; }
.card-tag { font: 10.5px var(--mono); letter-spacing: .06em; text-transform: uppercase; color: #b9a8d1; margin-top: 2px; }
.card-note { margin-top: 8px; font-size: 12px; color: #d3c8e2; font-style: italic; overflow-wrap: anywhere; }
.card-facts { margin: 8px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; font-size: 12px; }
.card-facts dt { color: #a898bd; }
.card-facts dd { margin: 0; text-align: right; font-family: var(--mono); overflow-wrap: anywhere; }
.replies { display: flex; flex-direction: column; gap: 6px; }
.reply-card { border: 1px solid var(--line); border-left: 3px solid var(--c); border-radius: 6px; background: var(--raise); }
.reply-sum { all: unset; box-sizing: border-box; cursor: pointer; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; width: 100%; padding: 7px 9px; }
.reply-sum:focus-visible { outline: 2px solid var(--accent); }
.reply-sum b { font-weight: 500; flex: 1 1 100%; }
.reply-card.open .reply-sum { border-bottom: 1px solid var(--line); }
.reply-body { padding: 9px; display: flex; flex-direction: column; gap: 10px; }
.gate { display: flex; flex-direction: column; gap: 6px; }
.req-body { display: flex; flex-direction: column; gap: 6px; }
.req-list { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.req-row { width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.req-head { display: flex; gap: 6px; }
.req-head select { flex: 1; }
.extras { display: flex; flex-direction: column; gap: 6px; }
.extras .row .picker { flex: 1; width: auto; }
.multi { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.multi .picker { width: auto; }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 4px 2px 9px; border-radius: 99px; background: var(--raise); border: 1px solid var(--line); font-size: 12.5px; }
.pill a { color: var(--fg); text-decoration: none; }
.x { all: unset; cursor: pointer; width: 18px; height: 18px; display: inline-grid; place-items: center; border-radius: 50%; color: var(--muted); }
.x:hover { background: var(--line); color: var(--fg); }
.x:focus-visible { outline: 2px solid var(--accent); }
ol.variants { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
ol.variants li { padding-left: 2px; }
ol.variants li > * { margin-right: 6px; }
ol.variants .row { display: inline-flex; float: right; }
ul.plain { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
details.more summary { cursor: pointer; font-size: 12px; color: var(--muted); }
details.more[open] { display: flex; flex-direction: column; gap: 6px; }
.reward { border: 1px solid var(--line); border-radius: 6px; padding: 7px; display: flex; flex-direction: column; gap: 6px; }
.reward .row .picker { flex: 1; width: auto; }
.reward-list { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.reward-list .reward { width: 100%; }

/* ---- canvases ---- */
.canvas { position: relative; flex: 1; min-height: 0; overflow: auto; background-image: radial-gradient(var(--line) 1px, transparent 1px); background-size: 22px 22px; }
.board { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.board.static { position: relative; }
svg.wires { position: absolute; left: 0; top: 0; pointer-events: none; overflow: visible; }
svg.wires path { fill: none; stroke: var(--wire); stroke-width: 1.7; }
svg.wires path.back { stroke-dasharray: 5 5; }
svg.wires path.gated { stroke-dasharray: 2 4; }
svg.wires path.broken { stroke: var(--warn); }
svg.wires path.hot { stroke: var(--accent); stroke-width: 2.8; }
svg.wires path.temp { stroke: var(--accent); stroke-width: 2; stroke-dasharray: 6 4; }
svg.wires text { font: 11px var(--mono); fill: var(--muted); paint-order: stroke; stroke: var(--bg); stroke-width: 4px; }
svg.wires text.hot { fill: var(--fg); }

.graph-wrap { position: relative; flex: 1; min-height: 0; display: flex; }
.canvas.graph { overflow: hidden; cursor: grab; touch-action: none; }
.canvas.graph.panning { cursor: grabbing; }
.zoom { position: absolute; right: 12px; bottom: 10px; font: 11px var(--mono); color: var(--muted); background: var(--panel); border: 1px solid var(--line); border-radius: 5px; padding: 2px 7px; pointer-events: none; }
.gnode { position: absolute; width: 250px; background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--c); border-radius: 8px; padding: 8px 0 6px 10px; cursor: pointer; box-shadow: 0 2px 6px var(--shadow); transition: box-shadow .15s, opacity .15s; user-select: none; }
.gnode.entry { width: 175px; padding-right: 10px; }
.gnode.term { width: 210px; padding-right: 10px; }
.gnode .k { font: 600 10px var(--mono); letter-spacing: .07em; text-transform: uppercase; color: var(--c); display: flex; align-items: center; flex-wrap: wrap; padding-right: 10px; }
.gnode .t { font: 600 13.5px var(--body); margin-top: 2px; padding-right: 10px; }
.gnode .s { font-size: 12px; color: var(--muted); margin-top: 3px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; padding-right: 10px; }
.gnode.sel { box-shadow: 0 0 0 2px var(--accent), 0 2px 6px var(--shadow); }
.gnode.hot { box-shadow: 0 0 0 3px var(--accent), 0 0 18px color-mix(in srgb, var(--accent) 45%, transparent); }
.gnode.dim { opacity: .5; }
.gnode.drop { box-shadow: 0 0 0 3px var(--act); }
.gnode:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.gnode ul.ports { list-style: none; margin: 7px 0 0; padding: 0; border-top: 1px dashed var(--line); }
.gnode ul.ports li { position: relative; display: flex; align-items: center; gap: 4px; padding: 3px 18px 3px 0; font-size: 12px; }
.gnode ul.ports li .rt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gnode ul.ports li .rt::before { content: "› "; color: var(--pc); }
.gnode ul.ports li:hover { background: var(--raise); }
.gnode .port { position: absolute; right: -7px; top: 50%; width: 12px; height: 12px; margin-top: -6px; border-radius: 50%; background: var(--panel); border: 2px solid var(--pc); cursor: crosshair; }
.gnode .port:hover { background: var(--pc); transform: scale(1.2); }

/* simulator */
.play { position: absolute; left: 14px; bottom: 14px; width: min(370px, calc(100% - 28px)); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px var(--shadow); display: flex; flex-direction: column; max-height: 58%; z-index: 3; }
.play .hd { display: flex; align-items: center; gap: 8px; padding: 8px 10px 8px 12px; border-bottom: 1px solid var(--line); font: 600 11px var(--mono); letter-spacing: .05em; text-transform: uppercase; color: var(--muted); flex-wrap: wrap; }
.play .hd select { margin-left: auto; font-size: 12px; padding: 3px 6px; text-transform: none; }
.play .hd .switch { text-transform: none; letter-spacing: 0; font-family: var(--body); }
.play .log { overflow: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; min-height: 70px; }
.play .say { font-size: 13px; }
.play .say.npc b { color: var(--state); }
.play .say.me { color: var(--muted); text-align: right; }
.play .say.me::before { content: "you: "; font: 11px var(--mono); }
.play .say.sys { font: 12px var(--mono); color: var(--act); }
.play .say.bad { color: var(--warn); }
.play .opts { display: flex; flex-direction: column; gap: 5px; padding: 10px 12px; border-top: 1px solid var(--line); }
.play .opts button { all: unset; cursor: pointer; padding: 6px 9px; border-radius: 6px; background: var(--raise); border: 1px solid var(--line); font-size: 13px; }
.play .opts button:hover { border-color: var(--accent); }
.play .opts button:focus-visible { outline: 2px solid var(--accent); }

/* storyboard */
.story-wrap { padding: 12px; }
.story { display: grid; grid-template-columns: 88px repeat(4, minmax(150px, 1fr)); gap: 10px; min-width: 736px; align-items: start; }
.colh { font: 700 15px var(--display); padding: 6px 2px; border-bottom: 2px solid var(--c); color: var(--c); display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.colh small { flex-basis: 100%; font: 400 11px var(--mono); color: var(--muted); }
.pchip { font: 600 10.5px var(--mono); padding: 1px 7px; border-radius: 99px; background: color-mix(in srgb, var(--c) 18%, transparent); color: var(--fg); margin-left: auto; }
.rowh { font: 600 10.5px var(--mono); letter-spacing: .07em; text-transform: uppercase; color: var(--muted); padding-top: 10px; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.card { position: relative; background: var(--panel); border: 1px solid var(--line); border-top: 3px solid var(--c); border-radius: 8px; padding: 9px 10px; cursor: pointer; text-align: left; font: inherit; color: inherit; }
.card:hover { border-color: color-mix(in srgb, var(--c) 60%, var(--line)); }
.card.sel { box-shadow: 0 0 0 2px var(--accent); }
.card.empty { border-style: dashed; border-top-width: 1px; color: var(--muted); background: transparent; }
.card p { margin: 3px 0; font-size: 13px; }
.card .card-k { font: 600 10px var(--mono); text-transform: uppercase; letter-spacing: .07em; color: var(--c); display: flex; align-items: center; flex-wrap: wrap; }
.card .rep { font-size: 12px; color: var(--muted); margin-top: 6px; display: flex; flex-direction: column; gap: 3px; }
.card .rep span::before { content: "› "; color: var(--c); }
.card .rep em { font-style: normal; }
.span3 { grid-column: span 3; }
button.add { all: unset; cursor: pointer; font: 12px var(--mono); color: var(--muted); padding: 4px 8px; border: 1px dashed var(--line); border-radius: 6px; align-self: flex-start; }
button.add:hover { color: var(--fg); border-color: var(--accent); }
button.add:focus-visible { outline: 2px solid var(--accent); }
.track { grid-column: 3 / 5; display: flex; flex-direction: column; gap: 6px; background: var(--panel); border: 1px dashed var(--step); border-radius: 8px; padding: 10px 12px; }
.track.small { grid-column: auto; }
.track-head { display: flex; gap: 8px; align-items: center; }
.step { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; gap: 8px; align-items: center; padding: 6px 8px; border-radius: 6px; background: var(--raise); border: 1px solid transparent; cursor: pointer; }
.step:hover { border-color: var(--step); }
.step.sel { box-shadow: 0 0 0 2px var(--accent); }
.step .step-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.step .tag { white-space: nowrap; }
.branches { grid-column: 2 / -1; display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-start; }
.branches .card { width: 220px; }
.flow { grid-column: 2 / -1; display: flex; justify-content: space-around; flex-wrap: wrap; gap: 8px; font: 12px var(--mono); color: var(--muted); }
.flow b { color: var(--act); font-weight: 600; }

/* map */
.filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 8px 16px; border-bottom: 1px solid var(--line); }
.filters input[type=search] { width: 220px; }
.map-wrap { padding: 0; }
.qcard { position: absolute; display: block; min-height: 100px; background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--c); border-radius: 8px; padding: 8px 10px; color: var(--fg); text-decoration: none; box-shadow: 0 2px 6px var(--shadow); transition: box-shadow .15s, opacity .15s; }
.qcard:hover, .qcard.sel { box-shadow: 0 0 0 2px var(--accent); }
.qcard.dim { opacity: .3; }
.qcard.off { border-style: dashed; }
.qcard .k { font: 600 10px var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--c); display: flex; align-items: center; flex-wrap: wrap; }
.qcard .t { font: 600 14px var(--body); margin-top: 2px; }
.qcard .s { font-size: 12px; color: var(--muted); }
.pchips { display: flex; gap: 4px; margin-top: 6px; }
.pc { font: 600 10.5px var(--mono); min-width: 24px; text-align: center; padding: 1px 6px; border-radius: 4px; background: var(--raise); }
.pc.offer { color: var(--state); }
.pc.active { color: var(--talk); }
.pc.ready { color: var(--step); }
.pc.done { color: var(--act); }

/* list views */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; padding: 16px; align-content: start; }
.lcard { all: unset; box-sizing: border-box; position: relative; cursor: pointer; background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--c); border-radius: 8px; padding: 9px 11px; box-shadow: 0 2px 6px var(--shadow); color: var(--fg); }
.lcard:hover, .lcard.sel { box-shadow: 0 0 0 2px var(--accent); }
.lcard:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.lcard .k { font: 600 10px var(--mono); text-transform: uppercase; letter-spacing: .07em; color: var(--c); }
.lcard .t { font: 600 14px var(--body); margin-top: 2px; }
.lcard .s { font-size: 12px; color: var(--muted); }
.empty-state { margin: 40px auto; max-width: 52ch; text-align: center; color: var(--muted); display: flex; flex-direction: column; gap: 10px; align-items: center; }
.empty-state h3 { color: var(--fg); margin: 0; }

/* cutscene */
.cut-wrap { padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.cut-top { display: flex; gap: 16px; align-items: stretch; flex-wrap: wrap; }
svg.flight { width: 260px; height: 160px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
svg.flight path { fill: none; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
svg.flight text { font: 10px var(--mono); fill: var(--muted); }
.cut-sum { display: flex; flex-direction: column; gap: 4px; justify-content: center; }
.cut-sum .big { font: 700 28px var(--display); }
ol.shots { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; max-width: 760px; }
.shot { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--c); border-radius: 8px; padding: 9px 12px; display: flex; flex-direction: column; gap: 8px; }
.shot-h { display: flex; gap: 10px; align-items: center; }
.shot-h .row { margin-left: auto; }
.shot-b { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }

/* dialogs and notices */
dialog.modal { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--fg); padding: 18px 20px; width: min(460px, calc(100vw - 32px)); box-shadow: 0 20px 60px var(--shadow); }
dialog.modal.wide { width: min(640px, calc(100vw - 32px)); }
/* The in-game view: a screen of GUI pixels, scaled whole so a pixel stays a pixel. */
dialog.modal.ingame { width: auto; max-width: calc(100vw - 32px); }
.ingame-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ingame-bar .spacer { flex: 1; }
.ingame-frame { width: fit-content; overflow: auto; max-width: calc(100vw - 72px); border-radius: 6px; border: 1px solid var(--line); background: #000; line-height: 0; }
.ingame-screen { display: block; image-rendering: pixelated; cursor: pointer; outline: none; }
.ingame-screen:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.ingame-status { display: flex; flex-direction: column; gap: 2px; min-height: 1.2em; }
dialog.modal::backdrop { background: rgb(0 0 0 / .45); }
dialog.modal h3 { margin: 0 0 10px; font-size: 18px; }
dialog.modal h4 { margin: 12px 0 6px; }
.modal-body { display: flex; flex-direction: column; gap: 10px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
ul.staged-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; max-height: 50vh; overflow: auto; }
ul.staged-list li { display: flex; gap: 6px; align-items: center; padding: 6px 8px; background: var(--raise); border-radius: 6px; }
ul.staged-list label.check { flex: 1; display: flex; gap: 8px; align-items: center; cursor: pointer; }
.toasts { position: fixed; right: 16px; bottom: 36px; display: flex; flex-direction: column; gap: 8px; z-index: 60; max-width: min(420px, calc(100vw - 32px)); }
.toast { display: flex; gap: 10px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--talk); border-radius: 8px; padding: 9px 10px 9px 12px; box-shadow: 0 8px 24px var(--shadow); font-size: 13px; }
.toast > span { flex: 1; }
.toast.tone-good { border-left-color: var(--act); }
.toast.tone-warn { border-left-color: var(--state); }
.toast.tone-bad { border-left-color: var(--warn); }

/* ---- the pixel face, crisp: 9, 18 and 27px only ---- */
.brand, .head h2, .insp h4, dialog.modal h3, dialog.modal h4, .colh, .cut-sum .big,
.gnode .t, .qcard .t, .lcard .t, .gnode .k, .qcard .k, .lcard .k, .card .card-k, .rowh,
.rail h3, .field > label, .extras > label, .legend, .btn, .play .hd > span, .shot-h b {
  font-family: var(--pixel); font-weight: 400; letter-spacing: 0;
  -webkit-font-smoothing: none; -moz-osx-font-smoothing: unset; font-smooth: never; text-rendering: optimizeSpeed;
}
.brand { font-size: 18px; }
.head h2, .cut-sum .big { font-size: 27px; line-height: 1.2; }
.insp h4, dialog.modal h3, .colh, .gnode .t, .qcard .t, .lcard .t, .shot-h b { font-size: 18px; line-height: 1.2; }
.gnode .k, .qcard .k, .lcard .k, .card .card-k, .rowh, .rail h3, .field > label, .extras > label,
.legend, .play .hd > span, dialog.modal h4 { font-size: 9px; line-height: 1.6; text-transform: none; }
.btn { font-size: 18px; line-height: 1; padding: 5px 10px; }
/* Toolbars and inspector actions: the in-game size, so a row of them fits one line. */
.btn.small { font-size: 9px; line-height: 1.6; padding: 4px 8px; }
.colh small { font-family: var(--mono); }

/* "Minecraft text everywhere": the body face too, at the same two sizes. */
:root[data-mc="all"] { --body: var(--pixel); --mono: var(--pixel); }
:root[data-mc="all"] body, :root[data-mc="all"] input, :root[data-mc="all"] select,
:root[data-mc="all"] textarea, :root[data-mc="all"] button, :root[data-mc="all"] .picker {
  -webkit-font-smoothing: none; font-smooth: never; letter-spacing: 0;
}
:root[data-mc="all"] body, :root[data-mc="all"] .card p,
:root[data-mc="all"] input, :root[data-mc="all"] select, :root[data-mc="all"] .picker,
:root[data-mc="all"] .say, :root[data-mc="all"] .opts button, :root[data-mc="all"] .toast,
:root[data-mc="all"] .head .desc, :root[data-mc="all"] .reply-sum b { font-size: 18px; }
:root[data-mc="all"] .small, :root[data-mc="all"] .hint, :root[data-mc="all"] .s,
:root[data-mc="all"] .rep, :root[data-mc="all"] textarea, :root[data-mc="all"] code,
:root[data-mc="all"] .chip, :root[data-mc="all"] .tag, :root[data-mc="all"] .pc,
:root[data-mc="all"] .pchip, :root[data-mc="all"] .id, :root[data-mc="all"] .crumbs,
:root[data-mc="all"] .foot, :root[data-mc="all"] .rail a, :root[data-mc="all"] .gnode ul.ports li,
:root[data-mc="all"] .preview, :root[data-mc="all"] .brand small, :root[data-mc="all"] .colh small { font-size: 9px; line-height: 1.6; }

/* ---- Book: parchment pages, leather binding ---- */
:root[data-theme="book"] body { background: var(--leather-dark); }
:root[data-theme="book"] .top, :root[data-theme="book"] .rail, :root[data-theme="book"] .foot {
  --fg: var(--leather-fg); --muted: var(--leather-muted); --raise: rgb(255 240 210 / .1); --line: rgb(20 10 0 / .45);
  color: var(--fg);
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .35 0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E"),
    linear-gradient(180deg, #6a4428, var(--leather) 40%, #4c301b);
}
:root[data-theme="book"] .top { border-bottom: 2px dashed var(--stitch); box-shadow: 0 3px 0 var(--leather-dark); }
:root[data-theme="book"] .foot { border-top: 2px dashed var(--stitch); }
:root[data-theme="book"] .rail { border-right: 2px dashed var(--stitch); box-shadow: 3px 0 0 var(--leather-dark); }
:root[data-theme="book"] .rail a.on { background: rgb(255 240 210 / .16); box-shadow: inset 3px 0 0 var(--stitch); }
:root[data-theme="book"] .top input[type=search] { background: #f6ecd3; color: #2a1b0c; border-color: var(--leather-dark); }
:root[data-theme="book"] .top .btn.primary[disabled] { opacity: .6; }
:root[data-theme="book"] .top .btn:not(.primary) { color: #2a1b0c; }
/* The pages: cream, a fibre of noise, darker toward the edges, and the spine's shadow. */
:root[data-theme="book"] .main, :root[data-theme="book"] .aside {
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='p'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.75 .18' numOctaves='3' seed='4' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .24 0 0 0 0 .1 0 0 0 .13 0'/%3E%3C/filter%3E%3Crect width='220' height='220' filter='url(%23p)'/%3E%3C/svg%3E"),
    radial-gradient(ellipse at 50% 45%, transparent 55%, rgb(120 80 30 / .16) 100%),
    var(--bg);
}
:root[data-theme="book"] .main { box-shadow: inset 14px 0 16px -12px rgb(60 35 10 / .55), inset -6px 0 10px -8px rgb(60 35 10 / .35); }
:root[data-theme="book"] .aside { border-left: 1px solid #c9b07f; box-shadow: inset 14px 0 16px -12px rgb(60 35 10 / .45); }
:root[data-theme="book"] .head { border-bottom-color: #c9b07f; }
:root[data-theme="book"] .canvas { background-image: repeating-linear-gradient(transparent 0 27px, rgb(120 90 50 / .11) 27px 28px); }
:root[data-theme="book"] .canvas.graph { background-image: none; }
:root[data-theme="book"] .gnode, :root[data-theme="book"] .card, :root[data-theme="book"] .qcard,
:root[data-theme="book"] .lcard, :root[data-theme="book"] .shot, :root[data-theme="book"] .play,
:root[data-theme="book"] .track, :root[data-theme="book"] svg.flight {
  background-color: var(--panel); border-color: var(--line); box-shadow: 1px 2px 0 rgb(90 60 25 / .18);
}
:root[data-theme="book"] svg.wires path { stroke: var(--wire); stroke-width: 1.4; }
:root[data-theme="book"] svg.wires path.hot { stroke: var(--accent); stroke-width: 2.6; }
:root[data-theme="book"] svg.wires text { stroke: var(--bg); }
:root[data-theme="book"] .badge.suspect { color: #fff; }
/* Chain colours are Minecraft's, picked for a dark chat line; on cream they are inked darker. */
:root[data-theme="book"] .qcard .k { color: color-mix(in srgb, var(--c) 50%, #2a1b0c); }
:root[data-theme="book"] dialog.modal { background: var(--panel); border: 2px solid var(--leather); }
:root[data-theme="book"] .btn { background: #e9dbb6; border-color: #8b6d42; }
:root[data-theme="book"] .btn.primary { background: var(--accent); border-color: #12305f; color: #fff; }
:root[data-theme="book"] .top .btn.primary { background: #2b5aa6; }

/* ---- narrower screens ---- */
@media (max-width: 1360px) {
  .app { grid-template-columns: 176px minmax(0, 1fr) 300px; }
}
@media (max-width: 960px) {
  body { overflow: auto; }
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(520px, 70vh) auto auto; height: auto; }
  .rail { display: flex; flex-wrap: wrap; gap: 2px 8px; border-right: 0; border-bottom: 1px solid var(--line); padding: 6px 10px; max-height: 120px; }
  .rail h3 { display: none; }
  .rail a { padding: 3px 7px; }
  .aside { border-left: 0; border-top: 1px solid var(--line); }
  .search-box { width: auto; flex: 1; }
  .top .spacer { display: none; }
  .top { flex-wrap: wrap; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
