@import '/theme/tokens.css';

:root {
  color-scheme: light;
  --paper: #f5f6f0; --surface: #fffefa; --ink: #233d35; --muted: #596a61;
  --line: #dce2d9; --green: #1a6346; --green-soft: #e6efe3; --mint: #cef0b9;
  --orange: #b24926; --orange-soft: #fff0e5; --red: #a33b31; --grid: #dbe1d6;
  --blip: 1.2s;
  font-family: 'Avenir Next', Avenir, 'Segoe UI', sans-serif;
  font-synthesis: none;
}
html[data-theme='dark'] {
  color-scheme: dark;
  --paper: #18251f; --surface: #203029; --ink: #e8eee4; --muted: #adbbb0;
  --line: #3d5143; --green: #b2e0a9; --green-soft: #304c3b; --mint: #b5e4a3;
  --orange: #f2b48c; --orange-soft: #442f24; --red: #ffaaa0; --grid: #34483b;
}

/* ---------------- base ---------------- */
* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--paper); font-size: 16px; line-height: 1.5; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }
a { color: var(--green); text-underline-offset: 3px; }
:focus-visible { outline: 3px solid var(--orange); outline-offset: 3px; }
h1, h2, h3, p { margin: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.skip-link { position: fixed; z-index: 30; left: 12px; top: -80px; background: var(--surface); padding: 12px 18px; border: 2px solid var(--green); }
.skip-link:focus { top: 12px; }
.small { font-size: 14px; color: var(--muted); }
.eyebrow { font-size: 12px; font-weight: 750; letter-spacing: 1.2px; color: var(--muted); }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 5px; min-height: 42px; border: 1px solid var(--line); border-radius: 8px; font-size: 15px; font-weight: 650; background: var(--surface); padding: 8px 14px; text-decoration: none; white-space: nowrap; }
.button:hover:not(:disabled) { border-color: var(--green); background: var(--green-soft); }
.button.primary { background: var(--green); color: var(--surface); border-color: var(--green); }
.button.primary:hover:not(:disabled) { filter: brightness(1.12); background: var(--green); }
.button.compact { min-height: 36px; font-size: 14px; padding: 6px 12px; }
.text-button { background: none; border: 0; padding: 6px 0; font-weight: 650; font-size: 15px; color: var(--green); }
.text-button:hover { text-decoration: underline; }

/* ---------------- top bar ---------------- */
.topbar { min-height: 60px; padding: 8px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 20px; background: var(--surface); }
.wordmark { color: var(--ink); text-decoration: none; font-size: 18px; font-weight: 750; display: flex; align-items: center; gap: 10px; }
.wordmark-light { font-weight: 450; }
.wordmark small { font-size: 14px; font-weight: 450; color: var(--muted); margin-left: 6px; }
.brand-mark { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; background: var(--green); color: var(--surface); font-size: 22px; }
.topbar nav { display: flex; align-items: center; gap: 22px; }
.topbar nav a { color: var(--muted); font-size: 15px; text-decoration: none; }
.topbar .text-button span { display: inline-grid; place-items: center; border: 1px solid var(--line); border-radius: 50%; width: 22px; height: 22px; margin-left: 5px; }

/* ---------------- one-screen layout ---------------- */
/* The game fills the viewport below the site chrome (game.js sets --game-top), so the brief,
   the controls, the map and the details are all visible together. */
#game-app { display: grid; grid-template-columns: minmax(340px, 400px) minmax(0, 1fr); gap: 14px; padding: 12px 16px 14px; height: calc(100dvh - var(--game-top, 140px)); min-height: 640px; outline: 0; }
.loading, .noscript { padding: 40px; }

/* ---------------- left: brief ---------------- */
.brief { display: flex; flex-direction: column; min-height: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; position: relative; }
.brief-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 10px; }
.brief h2 { font-size: 22px; line-height: 1.2; letter-spacing: -.4px; }
.story { font-size: 15px; color: var(--muted); line-height: 1.55; }
.teach { font-size: 14px; line-height: 1.55; padding: 9px 11px; border-radius: 10px; background: var(--green-soft); }
.teach b { color: var(--green); }
.objective { font-size: 15px; line-height: 1.5; }
.objective b { color: var(--green); margin-right: 6px; }

/* Level bar, Flexbox Froggy style: ◀ Level 3 of 12 ▶ with a pop-out grid. */
.levelbar { display: flex; align-items: center; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--green-soft) 55%, var(--surface)); }
.lv-arrow { width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); font-size: 13px; }
.lv-arrow:hover:not(:disabled) { border-color: var(--green); }
.lv-current { flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px; height: 36px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); font-weight: 750; font-size: 16px; }
.lv-current small { font-weight: 450; color: var(--muted); font-size: 14px; }
.lv-current i { font-style: normal; color: var(--muted); font-size: 12px; }
.lv-progress { font-size: 13px; font-weight: 650; color: var(--green); white-space: nowrap; padding-left: 4px; }
.level-picker { position: absolute; z-index: 20; top: 57px; left: 8px; right: 8px; max-height: calc(100% - 66px); overflow-y: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 18px 50px #10261933; padding: 14px; display: grid; gap: 12px; }
.lp-tier p { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.lp-tier p b { color: var(--ink); font-size: 14px; margin-right: 4px; }
.lp-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.lp-cell { display: grid; justify-items: start; gap: 1px; text-align: left; padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.lp-cell b { font: 700 15px ui-monospace, monospace; }
.lp-cell small { font-size: 12px; color: var(--muted); line-height: 1.25; }
.lp-cell i { font-style: normal; color: var(--green); font-size: 12px; min-height: 15px; }
.lp-cell:hover { border-color: var(--green); }
.lp-cell.done { background: var(--green-soft); border-color: color-mix(in srgb, var(--green) 40%, var(--line)); }
.lp-cell.current, .lp-free.current { outline: 2px solid var(--green); outline-offset: 1px; }
.lp-free { text-align: left; padding: 9px 11px; border: 1px dashed var(--line); border-radius: 8px; background: transparent; }
.lp-free small { color: var(--muted); font-size: 13px; }

/* Goals: always visible, update live while the run plays. */
.goals { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.goals li { display: grid; grid-template-columns: 24px 1fr auto; gap: 8px; align-items: center; padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px; font-size: 14px; line-height: 1.35; }
.g-mark { display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--line); color: var(--muted); font-weight: 800; font-size: 13px; }
.g-val { font: 650 13px ui-monospace, monospace; white-space: nowrap; color: var(--muted); }
.goals li.pass { border-color: color-mix(in srgb, var(--green) 45%, var(--line)); background: var(--green-soft); }
.goals li.pass .g-mark { background: var(--green); border-color: var(--green); color: var(--surface); }
.goals li.pass .g-val { color: var(--green); }
.goals li.fail { border-color: color-mix(in srgb, var(--red) 45%, var(--line)); background: color-mix(in srgb, var(--red) 7%, var(--surface)); }
.goals li.fail .g-mark { background: var(--red); border-color: var(--red); color: var(--surface); }
.goals li.fail .g-val { color: var(--red); }

/* Result appears right under the goals, in the same view. */
.result { padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--paper); display: grid; gap: 8px; }
.result.won { background: var(--green-soft); border-color: color-mix(in srgb, var(--green) 45%, var(--line)); }
.result-top { display: flex; align-items: center; gap: 10px; }
.result-top h3 { font-size: 18px; }
.stars { color: var(--green); font-size: 22px; letter-spacing: 1px; white-space: nowrap; }
.stars > span { color: var(--muted); }
.result p { font-size: 15px; line-height: 1.55; }
.result-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; }
.result-actions a { font-size: 15px; }

/* Design as a config file: each safeguard is one editable line. */
.design { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.design-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 12px; background: var(--paper); border-bottom: 1px solid var(--line); }
.design-head h3 { font-size: 15px; }
.design-head h3 small { font: 400 13px ui-monospace, monospace; color: var(--muted); margin-left: 6px; }
.cfg-cost { font: 700 16px ui-monospace, monospace; white-space: nowrap; }
.cfg-cost small { font-weight: 400; color: var(--muted); font-size: 13px; }
.cfg-cost.over { color: var(--red); }
.cfg { list-style: none; margin: 0; padding: 6px 0; background: color-mix(in srgb, var(--paper) 40%, var(--surface)); }
.cfg-line { padding: 6px 12px; display: grid; gap: 2px; }
.cfg-code { display: flex; align-items: center; flex-wrap: wrap; gap: 2px 4px; font: 14px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; cursor: pointer; border-radius: 6px; padding: 3px 6px; margin: 0 -6px; }
.cfg-code:hover { background: var(--green-soft); }
.cfg-code input { position: absolute; opacity: 0; pointer-events: none; }
.cfg-code:has(input:focus-visible) { outline: 3px solid var(--orange); }
.cfg-code .k { color: var(--muted); }
.cfg-code .v { padding: 0 6px; border-radius: 5px; font-weight: 700; border: 1px solid var(--line); }
.cfg-code .v.off { color: var(--orange); background: var(--orange-soft); border-color: color-mix(in srgb, var(--orange) 30%, var(--line)); }
.cfg-code .v.on { color: var(--green); background: var(--green-soft); border-color: color-mix(in srgb, var(--green) 35%, var(--line)); }
.cfg-flip { margin-left: auto; color: var(--muted); font-size: 14px; }
.cfg-cmt { font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); }
.cfg-cmt b { color: var(--green); font-weight: 650; }
.cfg-line.locked { opacity: .75; }
.cfg-line.locked .cfg-code { cursor: default; }
.cfg-line.locked .cfg-code:hover { background: none; }
.cfg-help { padding: 6px 12px 0; }
.cfg-inherited { border-top: 1px solid var(--line); }
.cfg-inherited summary, .faults summary { padding: 8px 12px; font-size: 14px; color: var(--muted); cursor: pointer; }
.faults { border-top: 1px solid var(--line); padding-bottom: 6px; }
.faults label { display: flex; align-items: center; gap: 8px; padding: 4px 12px; font-size: 14px; cursor: pointer; }
.reset-design { margin: 2px 12px 8px; font-size: 14px; }
.hint summary { cursor: pointer; color: var(--green); font-weight: 650; font-size: 15px; }
.hint p { margin-top: 6px; font-size: 15px; color: var(--muted); line-height: 1.55; }

/* ---------------- right: board ---------------- */
.board { position: relative; display: flex; flex-direction: column; min-height: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.tb-buttons { display: flex; align-items: center; gap: 8px; }
.icon-button { width: 42px; padding: 0; }
.speed { font-size: 14px; color: var(--muted); display: flex; align-items: center; gap: 6px; margin-left: 6px; }
.speed select { min-height: 36px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); padding: 0 6px; }
.tb-stats { display: flex; gap: 6px; flex-wrap: wrap; }
.tb-stats > span { display: grid; padding: 4px 10px; border: 1px solid var(--line); border-radius: 8px; min-width: 84px; }
.tb-stats small { font-size: 12px; color: var(--muted); line-height: 1.2; }
.tb-stats b { font: 700 16px/1.3 ui-monospace, monospace; }
.tb-stats > span.bad { border-color: color-mix(in srgb, var(--red) 50%, var(--line)); background: color-mix(in srgb, var(--red) 7%, var(--surface)); }
.tb-stats > span.bad small, .tb-stats > span.bad b { color: var(--red); }
.tb-clock { background: var(--paper); }
.incident { margin: 8px 14px 0; display: flex; align-items: center; gap: 9px; padding: 7px 11px; border-radius: 8px; background: var(--orange-soft); color: var(--orange); border: 1px solid color-mix(in srgb, var(--orange) 18%, transparent); font-size: 14px; }
.incident-icon { border: 1px solid currentColor; border-radius: 50%; width: 18px; height: 18px; display: grid; place-items: center; font: 700 12px/1 monospace; flex-shrink: 0; }
.incident-label { margin-left: auto; font-size: 12px; letter-spacing: 1px; font-weight: 700; white-space: nowrap; }
.incident.live-failure { background: color-mix(in srgb, var(--red) 11%, var(--surface)); color: var(--red); border-color: color-mix(in srgb, var(--red) 40%, transparent); }
.dirty-note { margin: 6px 14px 0; font-size: 14px; color: var(--orange); font-weight: 600; }

/* Map scales with the space it gets. */
.map { flex: 1 1 auto; min-height: 0; padding: 18px 10px 24px; background-image: radial-gradient(var(--grid) 1px, transparent 1px); background-size: 17px 17px; overflow: hidden; }
.service-map { position: relative; width: 100%; height: 100%; min-height: 260px; isolation: isolate; }
.connections { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.connection { stroke: var(--line); stroke-width: 2.5; fill: none; color: var(--muted); vector-effect: non-scaling-stroke; }
.connection.async { stroke-dasharray: 6 6; }
.connection.active { stroke: var(--green); stroke-width: 4; }
.event-token { fill: var(--green); stroke: var(--surface); stroke-width: 2; }
.application-boundary { position: absolute; inset: 9% 12% 8% 20%; border: 1px dashed var(--line); border-radius: 15px; background: color-mix(in srgb, var(--green-soft) 35%, transparent); z-index: -1; }
.application-boundary > span { position: absolute; bottom: -9px; left: 12px; color: var(--muted); background: var(--surface); padding: 0 6px; font-size: 11px; letter-spacing: 1px; }
.application-boundary.failed { border: 1.5px dashed var(--red); background: color-mix(in srgb, var(--red) 6%, transparent); }
.application-boundary.failed > span { color: var(--red); font-weight: 700; animation: fail-blink var(--blip, 1.2s) ease-in-out infinite; animation-delay: var(--blip-delay, 0s); }
.is-isolated .application-boundary { background: none; border-color: transparent; }
.service-node { position: absolute; left: var(--x); top: var(--y); transform: translate(-50%, -50%); width: 14%; min-width: 104px; max-width: 150px; height: clamp(86px, 24%, 112px); display: flex; flex-direction: column; align-items: center; justify-content: center; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); box-shadow: 0 3px 0 color-mix(in srgb, var(--line) 55%, transparent); padding: 6px 4px; text-align: center; }
.service-node:hover { border-color: var(--green); }
.service-node.selected { border-color: var(--green); box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 20%, transparent); }
.node-icon { position: relative; color: var(--green); }
.node-icon svg { width: 26px; height: 26px; display: block; }
.health-dot { position: absolute; width: 7px; height: 7px; border: 1px solid var(--surface); background: var(--green); border-radius: 50%; top: -2px; right: -6px; }
.service-node.bad .node-icon, .service-node.bad small { color: var(--red); }
.service-node.bad .health-dot { background: var(--red); }
.service-node.warn .health-dot { background: var(--orange); }
.service-node.event-active .node-icon { animation: node-pulse 1s ease-in-out infinite; }
.service-node b { font-size: 14px; font-weight: 650; margin-top: 3px; }
.service-node small { font-size: 12px; color: var(--muted); line-height: 1.25; margin-top: 2px; }
.db-links { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 0; pointer-events: none; overflow: visible; }
.db-links path { fill: none; stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 3 4; opacity: .55; vector-effect: non-scaling-stroke; }
.db-links.failed path { stroke: var(--red, #d33); opacity: .9; animation: fail-blink var(--blip, 1.2s) ease-in-out infinite; animation-delay: var(--blip-delay, 0s); }
.shared-db { position: absolute; left: var(--x); top: var(--y); transform: translate(-50%, -50%); z-index: 1; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 5px 8px; max-width: 128px; text-align: center; background: var(--surface); border: 1px dashed var(--line); border-radius: 10px; font-size: 12px; line-height: 1.2; }
.shared-db b { font-size: 12.5px; }
.shared-db small { color: var(--muted); font-size: 11px; }
.db-cyl { width: 22px; height: 18px; border: 2px solid currentColor; border-radius: 11px / 5px; position: relative; color: var(--muted); margin-bottom: 2px; }
.db-cyl::after { content: ''; position: absolute; left: -2px; right: -2px; top: 2px; height: 6px; border-bottom: 2px solid currentColor; border-radius: 0 0 11px 5px / 0 0 5px 5px; }
.shared-db.failed { border: 1.5px solid var(--red, #d33); color: var(--red, #d33); animation: fail-blink var(--blip, 1.2s) ease-in-out infinite; animation-delay: var(--blip-delay, 0s); }
.shared-db.failed .db-cyl, .shared-db.failed small { color: var(--red, #d33); }
.database-label { position: absolute; top: calc(100% + 4px); background: var(--surface); padding: 1px 6px; border: 1px solid var(--line); border-radius: 6px; font-size: 11px; white-space: nowrap; color: var(--muted); }

/* Dock: events, the selected order, or the selected service. */
.dock { flex: 0 0 clamp(160px, 30%, 300px); display: flex; flex-direction: column; min-height: 0; border-top: 1px solid var(--line); }
.dock-tabs { display: flex; align-items: center; gap: 2px; padding: 0 10px; border-bottom: 1px solid var(--line); background: var(--paper); }
.dock-tabs button { border: 0; background: none; padding: 10px 12px; font-size: 14px; font-weight: 650; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.dock-tabs button[aria-selected='true'] { color: var(--ink); border-bottom-color: var(--green); }
.dock-tabs small { font: 400 12px ui-monospace, monospace; }
.tab-alert { font-style: normal; display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 50%; background: var(--red); color: var(--surface); font-size: 11px; animation: fail-blink var(--blip) ease-in-out infinite; animation-delay: var(--blip-delay, 0s); }
.dock-tip { margin-left: auto; font-size: 13px; color: var(--muted); }
.dock-body { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 14px; }
.dock-filter { font-size: 14px; float: right; }
.empty { color: var(--muted); font-size: 15px; padding: 10px 0; }
.events { list-style: none; margin: 0; padding: 0; }
.event-row { display: grid; grid-template-columns: 44px 10px minmax(0, 1fr); gap: 8px; padding: 5px 6px; border-radius: 7px; }
.event-time { font: 13px/1.6 ui-monospace, monospace; color: var(--muted); }
.event-dot { width: 8px; height: 8px; margin-top: 7px; border-radius: 50%; background: var(--muted); }
.event-row.bad .event-dot { background: var(--red); }
.event-row.warn .event-dot { background: var(--orange); }
.event-row.good .event-dot { background: var(--green); }
.event-text { font-size: 15px; line-height: 1.45; }
.event-text small { display: inline; color: var(--muted); font-size: 13px; margin-left: 8px; }
.order-view { display: grid; gap: 10px; }
.order-tabs { display: flex; gap: 6px; }
.order-tabs button { flex: 1; min-height: 36px; background: transparent; border: 1px solid var(--line); border-radius: 7px; font: 14px ui-monospace, monospace; }
.order-tabs button[aria-pressed='true'] { border-color: var(--green); background: var(--green-soft); }
.order-tabs button.settled::after { content: ' ✓'; color: var(--green); }
.order-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; }
.order-states { margin: 0; }
.order-states > div { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; font-size: 14px; border-bottom: 1px dashed var(--line); }
.order-states dt { color: var(--muted); }
.order-states dd { margin: 0; text-align: right; font-weight: 650; }
.order-side { display: grid; gap: 8px; align-content: start; }
.money-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 8px 10px; background: var(--paper); border-radius: 8px; }
.money-row span { font-size: 12px; color: var(--muted); }
.money-row b { display: block; font-size: 16px; color: var(--ink); font-weight: 650; }
.service-view { display: grid; grid-template-columns: auto 1fr; gap: 14px; align-items: start; }
.service-view p { font-size: 15px; line-height: 1.55; }
.service-view p + p, .service-view .issue-list + p { margin-top: 6px; }
.service-view .button { margin-top: 8px; }
.sv-head { display: grid; justify-items: center; gap: 4px; min-width: 90px; }
.sv-head b { font-size: 15px; }
.service-view.failed .sv-head { color: var(--red); }
.service-view.failed .node-icon { color: var(--red); }

/* ---------------- dialog ---------------- */
dialog { max-width: 560px; width: calc(100% - 32px); max-height: calc(100dvh - 50px); overflow: auto; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 30px; box-shadow: 0 30px 100px #10261955; }
dialog::backdrop { background: #13291f70; backdrop-filter: blur(3px); }
dialog h2 { font: 30px/1.15 Georgia, serif; margin: 10px 0 18px; }
dialog ol { padding-left: 20px; }
dialog li { margin-bottom: 12px; font-size: 16px; line-height: 1.6; }
dialog p:not(.eyebrow) { margin: 14px 0; font-size: 15px; color: var(--muted); }
.dialog-close { position: absolute; right: 14px; top: 10px; border: 0; background: none; font-size: 28px; color: var(--muted); }

/* ---------------- failure highlighting (shared clock, see game.js) ---------------- */
@keyframes blink { 50% { opacity: .35; } }
@keyframes node-pulse { 50% { transform: translateY(-2px); } }
@keyframes fail-ring { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--red) 60%, transparent); } 70%, 100% { box-shadow: 0 0 0 9px color-mix(in srgb, var(--red) 0%, transparent); } }
@keyframes fail-blink { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
.fail-tag { display: inline-block; padding: 1px 5px; border-radius: 4px; background: var(--red); color: var(--surface); font: 700 11px/1.5 ui-monospace, monospace; letter-spacing: .6px; vertical-align: middle; animation: fail-blink var(--blip) ease-in-out infinite; animation-delay: var(--blip-delay, 0s); }
.service-node .fail-tag { position: absolute; top: -9px; left: 50%; transform: translateX(-50%); }
.service-node.failed { border-color: var(--red); border-width: 2px; background: color-mix(in srgb, var(--red) 9%, var(--surface)); animation: fail-ring var(--blip) ease-out infinite; animation-delay: var(--blip-delay, 0s); }
.service-node.failed .node-icon, .service-node.failed small { color: var(--red); }
.service-node.failed .health-dot { background: var(--red); width: 8px; height: 8px; animation: fail-blink var(--blip) steps(2, jump-none) infinite; animation-delay: var(--blip-delay, 0s); }
.connection.failed { stroke: var(--red); stroke-width: 4; color: var(--red); animation: fail-blink var(--blip) ease-in-out infinite; animation-delay: var(--blip-delay, 0s); }
.incident.live-failure .incident-icon { animation: fail-ring var(--blip) ease-out infinite; animation-delay: var(--blip-delay, 0s); }
.goals li.fail.live .g-mark { animation: fail-ring var(--blip) ease-out infinite; animation-delay: var(--blip-delay, 0s); }
.tb-stats > span.bad b { animation: fail-blink var(--blip) ease-in-out infinite; animation-delay: var(--blip-delay, 0s); }
.order-tabs button.failed { border-color: var(--red); color: var(--red); background: color-mix(in srgb, var(--red) 8%, transparent); animation: fail-ring var(--blip) ease-out infinite; animation-delay: var(--blip-delay, 0s); }
.order-tabs button.failed::after { content: ' !'; font-weight: 700; }
.order-tabs button.failed[aria-pressed='true'] { background: color-mix(in srgb, var(--red) 16%, transparent); }
.order-states > div.state-failed dt, .order-states > div.state-failed dd { color: var(--red); }
.order-states > div.state-failed dd::before { content: '● '; animation: fail-blink var(--blip) ease-in-out infinite; animation-delay: var(--blip-delay, 0s); }
.order-states > div.state-pending dd { color: var(--orange); }
.money-row span.state-failed, .money-row span.state-failed b { color: var(--red); }
.money-row span.state-failed b { animation: fail-blink var(--blip) ease-in-out infinite; animation-delay: var(--blip-delay, 0s); }
.issue-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 4px; }
.issue-list li { position: relative; padding: 5px 8px 5px 20px; border-radius: 6px; background: color-mix(in srgb, var(--red) 9%, var(--surface)); color: var(--red); font-size: 14px; line-height: 1.45; }
.issue-list li::before { content: ''; position: absolute; left: 8px; top: 11px; width: 6px; height: 6px; border-radius: 50%; background: var(--red); animation: fail-blink var(--blip) ease-in-out infinite; animation-delay: var(--blip-delay, 0s); }
.event-row.failure-active { background: color-mix(in srgb, var(--red) 9%, transparent); }
.event-row.failure-active .event-dot { background: var(--red); animation: fail-ring var(--blip) ease-out infinite; animation-delay: var(--blip-delay, 0s); }
.event-row.failure-active .event-text { color: var(--red); font-weight: 600; }
.event-row.failure-past .event-dot { background: var(--red); opacity: .55; }

/* ---------------- smaller screens: stack and scroll normally ---------------- */
@media (max-width: 1100px) {
  #game-app { grid-template-columns: minmax(300px, 340px) minmax(0, 1fr); gap: 10px; padding: 10px; }
  .tb-stats > span { min-width: 70px; }
}
@media (max-width: 860px), (max-height: 560px) {
  #game-app { display: flex; flex-direction: column; height: auto; min-height: 0; }
  .brief, .board { overflow: visible; }
  .brief-scroll { overflow: visible; }
  .dock { flex: none; }
  .map { overflow-x: auto; }
  .service-map { min-width: 640px; height: 420px; }
  .dock-body { max-height: 360px; }
  .order-body { grid-template-columns: 1fr; }
  .dock-tip { display: none; }
  .topbar nav { gap: 12px; }
  .wordmark small { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .event-token { display: none; }
  .service-node.failed, .order-tabs button.failed { box-shadow: 0 0 0 3px color-mix(in srgb, var(--red) 30%, transparent); }
}

@media (max-height: 820px) and (min-width: 861px) {
  .service-node { height: 78px; }
  .service-node small { font-size: 11px; }
  .node-icon svg { width: 22px; height: 22px; }
  .toolbar { padding: 8px 12px; }
}
@media (max-width: 600px) {
  .topbar { padding: 8px 12px; }
  .topbar nav { gap: 10px; }
  .topbar nav a:nth-child(2) { display: none; }
  .topbar nav a, .text-button { font-size: 14px; }
  .speed { margin-left: 0; }
  .tb-buttons { flex-wrap: wrap; }
}
/* Idle: no order has reached this service yet (often because something upstream failed). */
.service-node.idle { border-style: dashed; background: color-mix(in srgb, var(--paper) 70%, var(--surface)); }
.service-node.idle .node-icon { color: var(--muted); opacity: .7; }
.service-node.idle .health-dot { background: var(--line); }
.service-node.idle small { color: var(--muted); font-style: italic; }
.idle-why { padding: 7px 10px; border-radius: 7px; background: var(--paper); border-left: 3px solid var(--muted); margin-bottom: 6px; }

/* Result popup when a run finishes */
.result-dialog { max-width: 520px; padding: 0; border-radius: 18px; }
.result-dialog .result { border: 0; border-radius: 0; padding: 28px 28px 24px; gap: 12px; }
.result-dialog .result.won { background: var(--green-soft); }
.result-dialog .result-top { flex-direction: column; align-items: flex-start; gap: 6px; }
.result-dialog .stars { font-size: 38px; letter-spacing: 4px; }
.result-dialog .result.won .stars { animation: star-pop .5s ease-out both; }
.result-dialog h3 { font-size: 24px; }
.result-dialog .result p { font-size: 16px; line-height: 1.6; }
.result-dialog .dialog-close { z-index: 1; }
.result-checks { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 15px; }
.result-checks li { padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line); }
.result-checks li.pass { color: var(--green); background: var(--green-soft); }
.result-checks li.fail { color: var(--red); background: color-mix(in srgb, var(--red) 8%, var(--surface)); border-color: color-mix(in srgb, var(--red) 35%, var(--line)); }
.result-dialog .result-actions { gap: 10px 14px; margin-top: 4px; }
@keyframes star-pop { 0% { transform: scale(.4); opacity: 0; } 70% { transform: scale(1.15); opacity: 1; } 100% { transform: scale(1); } }
/* Compact summary that stays in the brief after the popup closes */
.result.compact { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 12px; }
.result.compact .stars { font-size: 18px; }
.result.compact b { font-size: 15px; }
.result.compact .text-button { margin-left: auto; font-size: 14px; }

/* What each level teaches */
.learns { border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; background: var(--surface); }
.learns summary { cursor: pointer; padding: 7px 0; font-weight: 650; font-size: 14px; display: flex; align-items: center; gap: 8px; list-style: none; }
.learns summary::-webkit-details-marker { display: none; }
.learns .learns-label { white-space: nowrap; }
.learns .concept-chip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.learns .learns-chev { margin-left: auto; font-size: 12px; font-weight: 700; color: var(--green, currentColor); white-space: nowrap; }
.learns .learns-chev::after { content: 'Show ▾'; }
.learns[open] .learns-chev::after { content: 'Hide ▴'; }
.learns:not([open]):hover { border-color: color-mix(in srgb, var(--green, #2f6b4f) 45%, var(--line)); }
.concept-chip { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--green-soft); color: var(--green); border: 1px solid color-mix(in srgb, var(--green) 30%, var(--line)); }
.learns ul, .learned ul { margin: 0 0 8px; padding-left: 18px; display: grid; gap: 5px; font-size: 14px; line-height: 1.5; }
.learns .real { font-size: 14px; color: var(--muted); padding: 7px 0 10px; border-top: 1px dashed var(--line); line-height: 1.5; }
.learns .real b { color: var(--ink); }
.learned { padding: 10px 12px; border-radius: 10px; background: var(--surface); border: 1px solid color-mix(in srgb, var(--green) 30%, var(--line)); }
.learned .eyebrow { color: var(--green); margin-bottom: 6px; }
.learned ul { margin: 0; font-size: 15px; }

/* "What this level teaches": a button in the incident bar opens a panel over the map. */
.incident.calm { background: var(--green-soft); color: var(--green); border-color: color-mix(in srgb, var(--green) 22%, transparent); }
.learn-btn { flex-shrink: 0; font: inherit; font-size: 13px; font-weight: 700; padding: 4px 10px; border-radius: 999px; border: 1px solid color-mix(in srgb, var(--green) 40%, var(--line)); background: var(--surface); color: var(--green); cursor: pointer; white-space: nowrap; }
.learn-btn:hover, .learn-btn.on { background: var(--green); color: var(--surface); border-color: var(--green); }
.incident-label + .learn-btn { margin-left: 4px; }
.incident { position: relative; }
.learns-pop { position: absolute; right: 0; top: calc(100% + 8px); z-index: 20; color: var(--ink); font-weight: 400; width: min(400px, 92vw); max-height: 60vh; overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; box-shadow: 0 12px 32px rgba(0,0,0,.16); }
.lp-head { position: relative; display: flex; align-items: center; gap: 6px 8px; flex-wrap: wrap; margin-bottom: 8px; padding-right: 28px; font-size: 15px; }
.lp-close { position: absolute; top: -2px; right: -4px; border: 0; background: none; font-size: 15px; cursor: pointer; color: var(--muted); padding: 2px 6px; }
.learns-pop ul { margin: 0 0 8px; padding-left: 18px; display: grid; gap: 5px; font-size: 14px; line-height: 1.5; }
.learns-pop .real { margin: 0; font-size: 14px; color: var(--muted); padding-top: 7px; border-top: 1px dashed var(--line); line-height: 1.5; }
.learns-pop .real b { color: var(--ink); }
@media (max-width: 860px) { .incident { flex-wrap: wrap; } .learns-pop { position: fixed; top: auto; bottom: 12px; right: 12px; left: 12px; width: auto; max-height: 70vh; } }
