/* Forest Change Explorer: one dataset, three readers.
   The structure below is shared; everything that gives a theme its character is a token,
   including every colour the map canvas draws (app.js reads them through readTheme()).

   Field sheet (default): a forestry survey sheet for a forester on site. Lichen paper,
     spruce-black ink, imagery printed as a map plate inside a neatline, loss in rust inks
     echoing the red-then-grey stages of beetle-killed spruce. Archivo, condensed for labels.
   Civic: a government analyst writing a report. White, high contrast, Public Sans, square
     corners, underlined links, a colour-blind-safe navy-to-teal loss sequence on a pale plate.
   Orbital: a commercial buyer looking at imagery. Deep night, glass chips, Sora, a blue
     night-vision plate with emissive loss that glows from hot red to gold. */

:root, [data-theme="field"] {
  --paper: #e6eae3;      /* page */
  --sheet: #f2f4ef;      /* chips, controls, raised surfaces (also the map's margin band) */
  --ink: #17201b;        /* text and map linework */
  --ink-2: #3d4a43;
  --muted: #66736b;
  --rule: #bfc8bf;
  --rule-soft: #d3d9d1;
  --spruce: #2e5b43;     /* living canopy */
  --accent: #17201b;     /* selection, current year, active controls */
  --on-accent: #f2f4ef;
  /* loss by first year, early to recent */
  --loss-0: #5c1913; --loss-1: #8c2618; --loss-2: #b23d1c; --loss-3: #cb5f24;
  --loss-4: #da8532; --loss-5: #e2aa4b; --loss-6: #e9c970;
  --nodata: #d3d9d1;
  --not-forest: #9aa59d;
  --plate-lo: 0.36;      /* imagery under the loss layer: lightness floor ... */
  --plate-span: 0.40;    /* ... range ... */
  --plate-tint: #f2fbef; /* ... and tint */
  --wash: rgba(242, 244, 239, 0.66);   /* outside a selected area */
  --font: "Archivo", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --narrow: 78;          /* label width on Archivo's wdth axis; ignored by other families */
  --wide: 112;
  --base: 15px;
  --r-ctl: 5px;
  --r-map: 0px;
  --r-chip: 3px;
  --ctl-line: 1px;
  --frame: 1.5px solid var(--ink);   /* the neatline */
  --chip-bg: var(--sheet);
  --chip-line: rgba(23, 32, 27, 0.28);
  --chip-blur: none;
  color-scheme: light;
}

[data-theme="civic"] {
  --paper: #ffffff;
  --sheet: #ffffff;
  --ink: #1b1b1b;
  --ink-2: #3a3a3a;
  --muted: #595959;
  --rule: #a9aeb1;
  --rule-soft: #dfe1e2;
  --spruce: #2e8540;
  --accent: #1a4480;
  --on-accent: #ffffff;
  /* lightness-ordered plum: readable with any colour vision, and never mistaken for water */
  --loss-0: #2a0a3a; --loss-1: #4b145e; --loss-2: #6b2080; --loss-3: #8a2e96;
  --loss-4: #a43e9f; --loss-5: #b9529d; --loss-6: #c96b98;
  --nodata: #e6e6e6;
  --not-forest: #a9aeb1;
  --plate-lo: 0.56;
  --plate-span: 0.36;
  --plate-tint: #ffffff;
  --wash: rgba(255, 255, 255, 0.72);
  --font: "Public Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --base: 16px;
  --r-ctl: 0px;
  --r-map: 0px;
  --r-chip: 0px;
  --ctl-line: 2px;
  --frame: 1px solid #a9aeb1;
  --chip-bg: #ffffff;
  --chip-line: #a9aeb1;
  color-scheme: light;
}

[data-theme="orbital"] {
  --paper: #05070d;
  --sheet: #0b111e;
  --ink: #eaf1ff;
  --ink-2: #b6c2d8;
  --muted: #7a87a1;
  --rule: rgba(255, 255, 255, 0.13);
  --rule-soft: rgba(255, 255, 255, 0.07);
  --spruce: #3fe0a2;
  --accent: #4de1ff;
  --on-accent: #02121a;
  --loss-0: #ff2d55; --loss-1: #ff4a3d; --loss-2: #ff712e; --loss-3: #ff982b;
  --loss-4: #ffbd3a; --loss-5: #ffdc63; --loss-6: #fff1a6;
  --nodata: #141b2a;
  --not-forest: #3a4459;
  --plate-lo: 0.03;
  --plate-span: 0.4;
  --plate-tint: #8fc4ff;
  --wash: rgba(5, 7, 13, 0.64);
  --font: "Sora", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --base: 15px;
  --r-ctl: 10px;
  --r-map: 16px;
  --r-chip: 10px;
  --ctl-line: 1px;
  --frame: 1px solid rgba(255, 255, 255, 0.14);
  --chip-bg: rgba(11, 17, 30, 0.6);
  --chip-line: rgba(255, 255, 255, 0.12);
  --chip-blur: blur(14px) saturate(140%);
  color-scheme: dark;
}

/* ================================================================ shared structure */
* { box-sizing: border-box; }
html, body { margin: 0; }
[hidden] { display: none !important; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 400 var(--base)/1.5 var(--font);
  font-variation-settings: "wdth" 100;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, [tabindex]:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, h3, p, dl, dd { margin: 0; }

/* labels: condensed, sentence case */
.label, .legend .lbl, .years-cap, .scale, .cmp, .readout, .film .fy, .chart text, .ledger dt, .spot .coords, .yr .ha, .yr .base, .statusbar, .crumbs, .area-meta {
  font-variation-settings: "wdth" var(--narrow);
}
.label { font-size: 0.8rem; font-weight: 500; color: var(--muted); }

.shell {
  padding-block: 18px 48px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: grid;
  gap: 16px;
  max-width: 1680px;
  margin: 0 auto;
}

/* ---------------------------------------------------------------- header */
.bar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 14px 24px; }
h1 {
  font-size: clamp(1.5rem, 1.15rem + 1.3vw, 2.1rem);
  font-weight: 700;
  font-variation-settings: "wdth" var(--wide);
  letter-spacing: -0.025em;
  line-height: 1.02;
}
.place { color: var(--ink-2); font-size: 0.92rem; margin-top: 6px; max-width: 60ch; text-wrap: pretty; }
.seg { display: inline-flex; border: var(--ctl-line) solid var(--ink); border-radius: var(--r-ctl); overflow: hidden; background: var(--sheet); }
.seg button { border: 0; background: none; padding: 7px 14px; font-size: 0.88rem; font-weight: 500; color: var(--ink-2); }
.seg button + button { border-left: 1px solid var(--rule); }
.seg button:hover { color: var(--ink); background: var(--paper); }
.seg button[aria-checked="true"] { background: var(--accent); color: var(--on-accent); }
.seg button[aria-checked="true"] + button { border-left-color: var(--accent); }
.tool { border: var(--ctl-line) solid var(--rule); background: var(--sheet); padding: 7px 14px; border-radius: var(--r-ctl); font-size: 0.88rem; font-weight: 500; }
.tool:hover { border-color: var(--ink); }
.tool[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

/* ---------------------------------------------------------------- stage */
.stage { display: grid; gap: 22px; }
.mapzone { display: grid; gap: 10px; min-width: 0; }
.map {
  position: relative;
  height: min(70vh, 580px);
  min-height: 320px;
  max-width: 100%;
  overflow: hidden;
  background: var(--sheet);
  border: var(--frame);
  border-radius: var(--r-map);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.map canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: crosshair; }
.map.panning canvas { cursor: grabbing; }

/* map furniture */
.readout, .hint, .cmp, .legend, .scale, .fit, .sim {
  position: absolute;
  background: var(--chip-bg);
  -webkit-backdrop-filter: var(--chip-blur);
  backdrop-filter: var(--chip-blur);
  border: 1px solid var(--chip-line);
  border-radius: var(--r-chip);
  color: var(--ink);
}
.readout {
  top: 26px; left: 8px; padding: 6px 9px; pointer-events: none;
  font-size: 0.76rem; line-height: 1.55;
  display: grid; grid-template-columns: auto auto; gap: 0 12px;
}
.readout span { color: var(--muted); }
.readout b { font-weight: 600; }
.hint {
  top: 26px; left: 50%; transform: translateX(-50%); padding: 5px 10px; font-size: 0.8rem; font-weight: 500;
  pointer-events: none; transition: opacity 0.5s; white-space: nowrap;
}
.cmp { top: 26px; padding: 4px 8px; font-size: 0.78rem; font-weight: 600; pointer-events: none; }
.cmp.left { left: 8px; }
.cmp.right { right: 26px; }
.legend { right: 26px; bottom: 8px; padding: 8px 10px 9px; font-size: 0.76rem; pointer-events: none; width: 214px; }
.legend .lbl { font-size: 0.78rem; font-weight: 600; }
.legend .ramp { display: flex; height: 9px; margin: 7px 0 3px; border: 1px solid var(--rule); overflow: hidden; border-radius: calc(var(--r-chip) / 2); }
.legend .ramp i { flex: 1; }
.legend .ramp.smooth { display: block; }
.legend .ends { display: flex; justify-content: space-between; font-size: 0.72rem; color: var(--muted); }
.legend .faded { display: flex; align-items: center; gap: 7px; margin-top: 7px; color: var(--ink-2); font-size: 0.74rem; }
.legend .faded i { flex: none; width: 18px; height: 9px; border: 1px solid var(--rule); }
.scale { left: 8px; bottom: 8px; padding: 4px 8px; display: flex; align-items: center; gap: 7px; font-size: 0.74rem; font-weight: 500; pointer-events: none; }
.scale-bar { height: 6px; border: 1.5px solid var(--ink); border-top: 0; display: inline-block; }
.fit { right: 26px; top: 26px; padding: 4px 10px; font-size: 0.8rem; font-weight: 500; display: none; }
.map.zoomed .fit { display: block; }
.map.zoomed.comparing .fit { top: 58px; }
.sim { left: 50%; bottom: 8px; transform: translateX(-50%); padding: 3px 8px; font-size: 0.74rem; font-weight: 700; color: var(--loss-1); }

/* ---------------------------------------------------------------- timeline: the loss chart is the year picker */
.timeline { display: flex; gap: 8px; align-items: stretch; }
.play {
  flex: none; width: 44px; border-radius: var(--r-ctl); border: var(--ctl-line) solid var(--ink); background: var(--sheet);
  display: grid; place-items: center;
}
.play:hover { background: var(--accent); border-color: var(--accent); }
.play:hover svg { fill: var(--on-accent); }
.play svg { width: 14px; height: 14px; fill: var(--ink); }
.years {
  flex: 1; min-width: 0;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 3px;
  padding: 8px 6px 6px; border-radius: var(--r-ctl); background: var(--sheet); border: 1px solid var(--rule);
  touch-action: none; outline: none; cursor: pointer;
}
.years:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.yr { display: grid; grid-template-rows: 54px auto 3px; gap: 5px; align-items: end; min-width: 0; }
.yr .col { height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 3px; }
.yr .loss { width: 100%; max-width: 46px; min-height: 1px; transition: opacity 0.25s; }
.yr .ha { font-size: 0.7rem; color: var(--ink-2); white-space: nowrap; }
.yr .base { font-size: 0.7rem; color: var(--muted); font-style: italic; }
.yr .y { text-align: center; font-size: 0.8rem; font-weight: 500; line-height: 1.75; color: var(--ink-2); border-radius: var(--r-chip); }
.yr .q { height: 3px; background: var(--rule-soft); overflow: hidden; }
.yr .q i { display: block; height: 100%; background: var(--muted); }
.yr.after .loss, .yr.after .ha { opacity: 0.25; }
.yr.on .y { color: var(--on-accent); background: var(--accent); font-weight: 600; }
.yr.on .q i { background: var(--accent); }
.years-cap { display: flex; justify-content: space-between; gap: 4px 12px; flex-wrap: wrap; color: var(--muted); font-size: 0.74rem; padding-left: 52px; }

/* ---------------------------------------------------------------- rail */
.rail { display: grid; align-content: start; min-width: 0; }
.panel { padding: 18px 0 22px; min-width: 0; border-top: 1px solid var(--rule); }
.panel:first-child { border-top: 2px solid var(--ink); }
.label-row { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.linkbtn { border: 0; background: none; padding: 0; color: var(--accent); font-size: 0.84rem; font-weight: 600; white-space: nowrap; text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
.linkbtn:hover { text-decoration-thickness: 2px; }

.verdict .q { font-size: 0.98rem; font-style: italic; color: var(--ink-2); margin-top: 12px; text-wrap: balance; }
.verdict .answer {
  margin-top: 10px;
  font-size: clamp(1.5rem, 1.3rem + 0.7vw, 1.85rem);
  font-weight: 600;
  font-variation-settings: "wdth" 104;
  letter-spacing: -0.022em;
  line-height: 1.12;
  text-wrap: balance;
}
.verdict .more { margin-top: 10px; font-size: 1rem; line-height: 1.45; color: var(--ink-2); text-wrap: pretty; max-width: 46ch; }
.ledger { margin-top: 18px; border-top: 1px solid var(--ink); }
.ledger > div { display: grid; grid-template-columns: 7.5rem minmax(0, 1fr); gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--rule-soft); align-items: baseline; }
.ledger dt { font-size: 0.82rem; font-weight: 500; color: var(--muted); }
.ledger dd { font-size: 1rem; font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ledger dd small { font-size: 0.86rem; color: var(--muted); font-weight: 400; }
.swatch { width: 11px; height: 11px; flex: none; border: 1px solid var(--rule); }
.meter { display: inline-flex; gap: 2px; }
.meter i { width: 14px; height: 6px; background: var(--rule-soft); }
.meter i.on { background: var(--spruce); }
.why { margin-top: 12px; font-size: 0.85rem; color: var(--muted); line-height: 1.5; max-width: 60ch; }

/* spot */
.spot .head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.spot h2 { font-size: 1.08rem; font-weight: 700; letter-spacing: -0.01em; }
.spot .coords { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 0.8rem; font-weight: 600; padding: 3px 9px 3px 7px; border: 1px solid var(--rule); background: var(--sheet); border-radius: var(--r-chip); white-space: nowrap; }
.chip i { width: 10px; height: 10px; border-radius: calc(var(--r-chip) / 3); }
.film { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 3px; margin-top: 14px; }
.film button { border: 0; padding: 0; background: none; display: grid; gap: 4px; min-width: 0; }
.film canvas { width: 100%; aspect-ratio: 1; display: block; outline: 2px solid transparent; outline-offset: 1px; background: var(--sheet); border-radius: calc(var(--r-chip) / 2); }
.film .fy { font-size: 0.7rem; color: var(--muted); text-align: center; }
.film .st { height: 4px; }
.film button.on canvas { outline-color: var(--accent); }
.film button.on .fy { color: var(--ink); font-weight: 700; }
.chart { margin-top: 16px; touch-action: pan-y; cursor: ew-resize; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { fill: var(--muted); font-size: 10.5px; font-family: var(--font); }
.chart .grid { stroke: var(--rule-soft); }
.chart .band { fill: var(--spruce); fill-opacity: 0.1; }
.chart .bandline { stroke: var(--spruce); stroke-opacity: 0.75; stroke-dasharray: 3 3; }
.chart .dot { fill: var(--ink); opacity: 0.22; }
.chart .dot.cur { opacity: 0.85; }
.chart .med { stroke-width: 4; stroke-linecap: butt; fill: none; }
.chart .gapc { fill: var(--rule-soft); }
.chart .clearc { fill: var(--ink-2); }
.chart .onset { stroke-width: 1.2; stroke-dasharray: 4 3; }
.chart .cursor { fill: var(--accent); opacity: 0.07; }
.chart .now { fill: var(--ink) !important; font-weight: 700; }
.spot .say { margin-top: 12px; font-size: 0.94rem; line-height: 1.5; max-width: 60ch; }
.spot .fine { margin-top: 8px; font-size: 0.8rem; color: var(--muted); line-height: 1.5; max-width: 60ch; }

.method summary { cursor: pointer; font-weight: 700; font-size: 1.02rem; list-style: none; display: flex; justify-content: space-between; align-items: baseline; }
.method summary::-webkit-details-marker { display: none; }
.method summary::after { content: "Show"; font-size: 0.84rem; font-weight: 600; color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.method[open] summary::after { content: "Hide"; }
.method p { margin-top: 10px; font-size: 0.88rem; color: var(--ink-2); line-height: 1.55; max-width: 64ch; }
.method strong { color: var(--ink); font-weight: 700; }

/* ================================================================ Civic: plain, accessible, report-ready */
[data-theme="civic"] h1 { letter-spacing: -0.015em; }
[data-theme="civic"] .place { color: var(--ink-2); }
[data-theme="civic"] .seg { border-color: var(--ink); }
[data-theme="civic"] .seg button { font-weight: 600; padding: 9px 16px; }
[data-theme="civic"] .seg button + button { border-left: 2px solid var(--ink); }
[data-theme="civic"] .seg button[aria-checked="true"] + button { border-left-color: var(--ink); }
[data-theme="civic"] .tool { border-color: var(--accent); color: var(--accent); font-weight: 600; padding: 9px 16px; }
[data-theme="civic"] .tool[aria-pressed="true"] { color: var(--on-accent); }
[data-theme="civic"] button:focus-visible,
[data-theme="civic"] [tabindex]:focus-visible,
[data-theme="civic"] summary:focus-visible { outline: 3px solid var(--ink); outline-offset: 0; box-shadow: 0 0 0 6px #ffd84a; }
[data-theme="civic"] .legend, [data-theme="civic"] .readout { box-shadow: 0 1px 0 var(--rule); }
[data-theme="civic"] .yr .base { font-style: normal; }
[data-theme="civic"] .years { border-color: var(--rule); }
[data-theme="civic"] .panel { border-top: 1px solid var(--rule); }
[data-theme="civic"] .panel:first-child { border-top: 5px solid var(--accent); }
[data-theme="civic"] .verdict .q { font-style: normal; font-weight: 700; color: var(--ink); font-size: 1rem; }
[data-theme="civic"] .verdict .answer { font-weight: 700; letter-spacing: -0.015em; line-height: 1.18; }
[data-theme="civic"] .verdict .more { color: var(--ink); }
[data-theme="civic"] .ledger { border: 1px solid var(--rule); border-top: 1px solid var(--rule); }
[data-theme="civic"] .ledger > div { padding: 10px 12px; border-bottom: 1px solid var(--rule); }
[data-theme="civic"] .ledger > div:last-child { border-bottom: 0; }
[data-theme="civic"] .ledger > div:nth-child(odd) { background: #f5f6f7; }
[data-theme="civic"] .ledger dt { color: var(--ink); font-weight: 600; }
[data-theme="civic"] .why { color: var(--ink-2); }
[data-theme="civic"] .chip { border-color: var(--ink); }
[data-theme="civic"] .chart .dot { opacity: 0.3; }
[data-theme="civic"] .method summary { color: var(--accent); }

/* ================================================================ Orbital: imagery-forward, glossy */
[data-theme="orbital"] body {
  background:
    radial-gradient(1200px 520px at 18% -8%, rgba(77, 225, 255, 0.12), transparent 60%),
    radial-gradient(900px 600px at 110% 10%, rgba(255, 74, 61, 0.08), transparent 60%),
    var(--paper);
  background-attachment: fixed;
}
[data-theme="orbital"] h1 { font-weight: 600; letter-spacing: -0.035em; }
[data-theme="orbital"] .place { color: var(--muted); }
[data-theme="orbital"] .seg { border-color: var(--rule); background: rgba(255, 255, 255, 0.04); padding: 3px; gap: 2px; }
[data-theme="orbital"] .seg button { border-radius: 8px; color: var(--muted); }
[data-theme="orbital"] .seg button + button { border-left: 0; }
@media (hover: hover) { [data-theme="orbital"] .seg button:not([aria-checked="true"]):hover { background: rgba(255, 255, 255, 0.06); color: var(--ink); } }
[data-theme="orbital"] .seg button[aria-checked="true"] { background: var(--accent); color: var(--on-accent); box-shadow: 0 0 22px -4px rgba(77, 225, 255, 0.7); font-weight: 600; }
[data-theme="orbital"] .tool { background: rgba(255, 255, 255, 0.04); border-color: var(--rule); }
[data-theme="orbital"] .tool:hover { border-color: rgba(255, 255, 255, 0.3); }
[data-theme="orbital"] .tool[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); box-shadow: 0 0 22px -4px rgba(77, 225, 255, 0.7); font-weight: 600; }
[data-theme="orbital"] .map {
  box-shadow: 0 0 0 1px rgba(77, 225, 255, 0.06), 0 40px 90px -40px rgba(77, 225, 255, 0.35);
}
[data-theme="orbital"] .play, [data-theme="orbital"] .years {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.015));
  border-color: var(--rule);
}
[data-theme="orbital"] .play:hover { box-shadow: 0 0 22px -4px rgba(77, 225, 255, 0.7); }
[data-theme="orbital"] .yr .loss { border-radius: 4px 4px 1px 1px; box-shadow: 0 0 14px -3px currentColor; }
[data-theme="orbital"] .yr.on .y { box-shadow: 0 0 18px -4px rgba(77, 225, 255, 0.8); }
[data-theme="orbital"] .rail { gap: 12px; }
[data-theme="orbital"] .panel, [data-theme="orbital"] .panel:first-child {
  border: 1px solid var(--rule);
  border-radius: 16px;
  padding: 18px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.055), rgba(255, 255, 255, 0.015));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}
[data-theme="orbital"] .verdict .q { font-style: normal; color: var(--muted); font-size: 0.92rem; }
[data-theme="orbital"] .verdict .answer { font-weight: 600; letter-spacing: -0.03em; }
[data-theme="orbital"] .ledger { border-top: 1px solid var(--rule); }
[data-theme="orbital"] .ledger dd { font-weight: 600; }
[data-theme="orbital"] .meter i { border-radius: 3px; }
[data-theme="orbital"] .meter i.on { box-shadow: 0 0 10px -2px var(--spruce); }
[data-theme="orbital"] .chip { background: rgba(255, 255, 255, 0.05); border-color: var(--rule); border-radius: 999px; }
[data-theme="orbital"] .chip i { border-radius: 50%; box-shadow: 0 0 8px currentColor; }
[data-theme="orbital"] .film canvas { border-radius: 6px; }
[data-theme="orbital"] .chart .dot { fill: var(--accent); opacity: 0.32; }
[data-theme="orbital"] .chart .dot.cur { opacity: 1; }
[data-theme="orbital"] .chart .med { stroke-linecap: round; }
[data-theme="orbital"] .method summary::after { text-decoration: none; }

/* ================================================================ product shell */
:root, [data-theme="field"] { --bar-bg: var(--sheet); --bar-ink: var(--ink); --bar-line: var(--ink); --bar-muted: var(--muted); --field-bg: var(--paper); }
[data-theme="civic"] { --bar-bg: #1a4480; --bar-ink: #ffffff; --bar-line: #162e51; --bar-muted: #c5d1e3; --field-bg: #ffffff; }
[data-theme="orbital"] { --bar-bg: rgba(8, 12, 22, 0.78); --bar-ink: var(--ink); --bar-line: rgba(255, 255, 255, 0.1); --bar-muted: var(--muted); --field-bg: rgba(255, 255, 255, 0.06); }

.app { min-height: 100vh; }
.only-narrow { display: none !important; }
svg { flex: none; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 14px;
  height: 54px; padding: 0 max(14px, env(safe-area-inset-right, 0px)) 0 max(14px, env(safe-area-inset-left, 0px));
  background: var(--bar-bg); color: var(--bar-ink);
  border-bottom: 1px solid var(--bar-line);
  -webkit-backdrop-filter: var(--chip-blur); backdrop-filter: var(--chip-blur);
}
.brandmark { display: inline-flex; align-items: center; gap: 8px; color: inherit; text-decoration: none; }
.brandmark svg { width: 22px; height: 22px; }
.brandmark .product { font-weight: 700; font-size: 1.08rem; letter-spacing: -0.02em; font-variation-settings: "wdth" var(--wide); }
.workspace { font-size: 0.86rem; color: var(--bar-muted); padding-left: 14px; border-left: 1px solid var(--bar-line); white-space: nowrap; }
.spacer { flex: 1; }
.icon-btn { position: relative; display: grid; place-items: center; width: 36px; height: 36px; border: 0; background: none; color: inherit; border-radius: var(--r-ctl); }
.icon-btn:hover { background: color-mix(in srgb, currentColor 10%, transparent); }
.icon-btn svg { width: 20px; height: 20px; }
.badge { position: absolute; top: 3px; right: 2px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: var(--loss-1); color: #fff; font-size: 0.66rem; font-weight: 700; line-height: 16px; text-align: center; }
[data-theme="civic"] .badge { background: #d83933; }
[data-theme="orbital"] .badge { background: var(--loss-0); box-shadow: 0 0 10px var(--loss-0); }

.search { position: relative; display: flex; align-items: center; gap: 8px; width: min(320px, 28vw); height: 34px; padding: 0 10px; background: var(--field-bg); border: 1px solid var(--bar-line); border-radius: var(--r-ctl); color: var(--bar-muted); }
[data-theme="civic"] .search { border-color: #ffffff; }
.search svg { width: 16px; height: 16px; }
.search input { flex: 1; min-width: 0; border: 0; background: none; color: var(--ink); font: inherit; font-size: 0.88rem; outline: none; }
[data-theme="civic"] .search input { color: #1b1b1b; }
.search:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
[data-theme="civic"] .search:focus-within { outline-color: #ffd84a; }

.pop-anchor { position: relative; }
.popover {
  position: absolute; z-index: 40; top: calc(100% + 8px); right: 0; width: min(360px, calc(100vw - 24px));
  background: var(--sheet); color: var(--ink); border: 1px solid var(--rule); border-radius: calc(var(--r-chip) * 1.5);
  box-shadow: 0 18px 48px -16px rgba(0, 0, 0, 0.35); padding: 8px;
}
[data-theme="orbital"] .popover { background: #0d1424; }
.search-results { left: 0; right: auto; width: 100%; }
.search-results button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: var(--r-chip); font-size: 0.9rem; }
.search-results button:hover, .search-results button:focus-visible { background: var(--paper); }
.popover .empty { padding: 8px 10px; font-size: 0.86rem; color: var(--muted); }
.notes h2 { font-size: 0.95rem; font-weight: 700; padding: 6px 8px 8px; }
.note { display: flex; gap: 10px; width: 100%; text-align: left; border: 0; background: none; padding: 9px 8px; border-radius: var(--r-chip); border-top: 1px solid var(--rule-soft); }
.note:not([disabled]):hover { background: var(--paper); }
.note[disabled] { cursor: default; }
.note i { flex: none; width: 8px; height: 8px; margin-top: 6px; border-radius: 50%; background: var(--muted); }
.note.hit i { background: var(--loss-1); }
.note.quiet i { background: var(--spruce); }
.note b { display: block; font-size: 0.88rem; font-weight: 600; }
.note small { display: block; font-size: 0.8rem; color: var(--muted); line-height: 1.45; margin-top: 2px; }

.profile { display: flex; align-items: center; gap: 10px; }
.profile .who { display: grid; text-align: right; line-height: 1.2; }
.profile .who b { font-size: 0.84rem; font-weight: 600; }
.profile .who small { font-size: 0.74rem; color: var(--bar-muted); }
.avatar { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--accent); color: var(--on-accent); font-size: 0.74rem; font-weight: 700; letter-spacing: 0.02em; }
[data-theme="civic"] .avatar { background: #ffffff; color: #1a4480; }
[data-theme="field"] .avatar, :root:not([data-theme]) .avatar { background: var(--spruce); color: var(--sheet); }

/* navigation rail */
.nav { display: none; }
.nav-item { position: relative; display: grid; justify-items: center; gap: 4px; width: 100%; padding: 10px 4px; border: 0; background: none; color: var(--muted); font-size: 0.7rem; font-weight: 600; border-radius: var(--r-ctl); }
.nav-item svg { width: 22px; height: 22px; }
.nav-item:hover { color: var(--ink); background: color-mix(in srgb, var(--ink) 6%, transparent); }
.nav-item[aria-current="page"] { color: var(--ink); }
.nav-item[aria-current="page"]::before { content: ""; position: absolute; left: -8px; top: 10px; bottom: 10px; width: 3px; background: var(--accent); border-radius: 2px; }
[data-theme="orbital"] .nav-item[aria-current="page"] svg { color: var(--accent); filter: drop-shadow(0 0 6px rgba(77, 225, 255, 0.6)); }
.count { position: absolute; top: 6px; right: 12px; min-width: 15px; height: 15px; padding: 0 4px; border-radius: 8px; background: var(--accent); color: var(--on-accent); font-size: 0.62rem; line-height: 15px; text-align: center; }

/* drawer */
.drawer {
  position: fixed; z-index: 35; top: 0; bottom: 0; left: 0; width: min(360px, 88vw);
  display: flex; flex-direction: column;
  background: var(--sheet); color: var(--ink); border-right: 1px solid var(--rule);
  box-shadow: 24px 0 60px -30px rgba(0, 0, 0, 0.45);
  padding-left: env(safe-area-inset-left, 0px);
}
[data-theme="orbital"] .drawer { background: #0b111e; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 12px 8px 18px; border-bottom: 1px solid var(--rule-soft); }
.drawer-head h2 { font-size: 1.05rem; font-weight: 700; }
.drawer-body { flex: 1; overflow-y: auto; padding: 14px 18px 24px; display: grid; gap: 12px; align-content: start; }
.drawer-sub { font-size: 0.82rem; font-weight: 600; color: var(--muted); }
.drawer-nav { padding: 8px 10px; border-bottom: 1px solid var(--rule-soft); display: grid; gap: 2px; }
.drawer-nav button { position: relative; display: flex; align-items: center; gap: 12px; padding: 10px 10px; border: 0; background: none; border-radius: var(--r-ctl); font-size: 0.95rem; font-weight: 500; text-align: left; }
.drawer-nav button svg { width: 20px; height: 20px; color: var(--muted); }
.drawer-nav button[aria-current="page"] { background: var(--paper); font-weight: 700; }
.drawer-nav .count { position: static; margin-left: auto; }
.drawer-ws { padding: 10px 10px 4px; font-size: 0.8rem; color: var(--muted); }
.scrim { position: fixed; inset: 0; z-index: 34; background: rgba(10, 14, 12, 0.32); }
.filter { display: flex; align-items: center; gap: 8px; height: 36px; padding: 0 10px; border: 1px solid var(--rule); border-radius: var(--r-ctl); background: var(--paper); color: var(--muted); }
.filter svg { width: 16px; height: 16px; }
.filter input { flex: 1; min-width: 0; border: 0; background: none; font: inherit; font-size: 0.9rem; color: var(--ink); outline: none; }
.area-list { display: grid; gap: 6px; }
.area-row { display: grid; gap: 4px; text-align: left; padding: 10px 12px; border: 1px solid var(--rule-soft); border-radius: var(--r-ctl); background: none; }
.area-row:hover { border-color: var(--rule); background: var(--paper); }
.area-row.on { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.area-name { font-weight: 600; font-size: 0.94rem; }
.area-meta { font-size: 0.8rem; color: var(--muted); }
.area-bar { height: 4px; background: var(--rule-soft); border-radius: 2px; overflow: hidden; }
.area-bar i { display: block; height: 100%; background: var(--loss-1); }
.drawer-note, .drawer-empty { font-size: 0.86rem; color: var(--ink-2); line-height: 1.5; }
.tool.wide { width: 100%; justify-content: center; }
.alert-list { display: grid; gap: 6px; }
.alert-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--rule-soft); border-radius: var(--r-ctl); }
.alert-row > div { flex: 1; display: grid; gap: 2px; }
.alert-row b { font-size: 0.92rem; }
.alert-row small { font-size: 0.8rem; color: var(--muted); }
.alert-row.hit { border-color: var(--loss-1); }
.alert-row.hit small { color: var(--ink-2); }

/* page header */
.crumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; font-size: 0.82rem; color: var(--muted); margin-bottom: 4px; }
.crumbs svg { width: 12px; height: 12px; }
.crumb { border: 0; background: none; padding: 0; color: var(--accent); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
[data-theme="field"] .crumb, :root:not([data-theme]) .crumb { color: var(--ink-2); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.tool { display: inline-flex; align-items: center; gap: 7px; }
.tool svg { width: 16px; height: 16px; }
.tool.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.tool.primary:hover { filter: brightness(1.1); }
[data-theme="civic"] .tool.primary { color: var(--on-accent); }
[data-theme="orbital"] .tool.primary { box-shadow: 0 0 22px -6px rgba(77, 225, 255, 0.8); }
.maptools { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.maptools-right { display: flex; gap: 6px; }

/* status bar */
.statusbar { display: flex; flex-wrap: wrap; gap: 4px 18px; align-items: center; padding: 8px 0 2px; border-top: 1px solid var(--rule-soft); font-size: 0.76rem; color: var(--muted); }
.statusbar .ok { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); font-weight: 600; }
.statusbar .ok i { width: 7px; height: 7px; border-radius: 50%; background: var(--spruce); }
[data-theme="orbital"] .statusbar .ok i { box-shadow: 0 0 8px var(--spruce); }

/* dialog */
.sheet {
  width: min(440px, calc(100vw - 32px)); padding: 22px; border: 1px solid var(--rule);
  border-radius: calc(var(--r-chip) * 2); background: var(--sheet); color: var(--ink);
  box-shadow: 0 30px 80px -30px rgba(0, 0, 0, 0.5);
}
[data-theme="orbital"] .sheet { background: #0d1424; }
.sheet::backdrop { background: rgba(10, 14, 12, 0.4); }
.sheet h2 { font-size: 1.2rem; font-weight: 700; }
.sheet-lead { margin-top: 8px; font-size: 0.92rem; color: var(--ink-2); line-height: 1.5; }
.field-row { display: grid; gap: 6px; margin-top: 16px; font-size: 0.9rem; font-weight: 600; }
.field-row select { font: inherit; font-weight: 500; padding: 9px 10px; border: var(--ctl-line) solid var(--rule); border-radius: var(--r-ctl); background: var(--paper); color: var(--ink); }
.sheet-fine { margin-top: 12px; font-size: 0.8rem; color: var(--muted); line-height: 1.5; }
.sheet-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* toast */
.toast {
  position: fixed; z-index: 60; left: 50%; bottom: 84px; transform: translateX(-50%);
  max-width: calc(100vw - 32px); padding: 10px 14px; border-radius: var(--r-ctl);
  background: var(--ink); color: var(--sheet); font-size: 0.88rem; font-weight: 500;
  box-shadow: 0 12px 30px -10px rgba(0, 0, 0, 0.4);
}

/* ================================================================ demo control: deliberately outside the product's look */
.demo {
  position: fixed; z-index: 50; left: 50%; bottom: max(14px, env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px; padding: 6px 6px 6px 14px;
  background: #121212; color: #f2f2f2; border: 1px dashed rgba(255, 255, 255, 0.35); border-radius: 999px;
  font: 500 0.8rem/1.2 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  box-shadow: 0 14px 40px -12px rgba(0, 0, 0, 0.55);
  white-space: nowrap;
}
.demo-label { color: #b9b9b9; }
.demo-picks { display: flex; gap: 2px; }
.demo-picks button { display: inline-flex; align-items: center; gap: 7px; border: 0; padding: 6px 11px 6px 7px; border-radius: 999px; background: none; color: #d6d6d6; font: inherit; }
.demo-picks button:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.demo-picks button[aria-checked="true"] { background: #f2f2f2; color: #121212; font-weight: 700; }
.demo-picks button:focus-visible { outline: 2px solid #fff; outline-offset: 2px; box-shadow: none; }
.demo-link { color: #f2f2f2; padding: 6px 12px 6px 10px; border-left: 1px solid rgba(255, 255, 255, 0.2); text-decoration: underline; text-underline-offset: 3px; }
.demo-link:hover { color: #fff; text-decoration-thickness: 2px; }
.sw { width: 16px; height: 16px; border-radius: 50%; border: 1px solid rgba(255, 255, 255, 0.4); }
.sw-field { background: linear-gradient(135deg, #e6eae3 50%, #8c2618 50%); }
.sw-civic { background: linear-gradient(135deg, #ffffff 50%, #1a4480 50%); }
.sw-orbital { background: linear-gradient(135deg, #05070d 50%, #ff4a3d 50%); }

/* ================================================================ layout */
.shell { padding-bottom: 88px; }
.bar { align-items: flex-end; }

@media (min-width: 1000px) {
  .app { display: grid; grid-template-columns: 80px minmax(0, 1fr); grid-template-rows: 54px minmax(0, 1fr); height: 100vh; }
  .topbar { grid-column: 1 / -1; }
  .nav { display: grid; align-content: start; gap: 4px; padding: 12px 8px; border-right: 1px solid var(--rule-soft); background: color-mix(in srgb, var(--sheet) 55%, transparent); }
  .drawer { top: 54px; left: 80px; border-left: 1px solid var(--rule-soft); }
  .scrim { top: 54px; left: 80px; background: rgba(10, 14, 12, 0.12); }
  .shell { height: calc(100vh - 54px); grid-template-rows: auto minmax(0, 1fr) auto; padding-block: 16px 12px; gap: 14px; max-width: none; margin: 0; }
  .stage { grid-template-columns: minmax(0, 1fr) 400px; gap: 28px; min-height: 0; }
  .mapzone { grid-template-rows: auto minmax(0, 1fr) auto auto; min-height: 0; }
  .map { height: auto; min-height: 0; }
  .rail { overflow-y: auto; min-height: 0; padding-right: 6px; padding-bottom: 60px; scrollbar-width: thin; scrollbar-color: var(--rule) transparent; }
  .panel:first-child { padding-top: 14px; }
  .demo { left: auto; right: 22px; transform: none; bottom: 18px; }
  .toast { bottom: 76px; }
}
@media (min-width: 1400px) { .stage { grid-template-columns: minmax(0, 1fr) 440px; } }
@media (max-width: 999px) {
  .only-wide { display: none !important; }
  .only-narrow { display: grid !important; }
  .drawer-nav.only-narrow { display: grid !important; }
  .profile .who { display: none; }
  .topbar { gap: 6px; }
  .brandmark { margin-left: 2px; }
}
@media (max-width: 520px) {
  .actions { width: 100%; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .actions .tool { justify-content: center; padding: 8px 4px; font-size: 0.82rem; }
  .maptools { display: grid; grid-template-columns: 1fr 1fr; }
  .maptools .seg { grid-column: 1 / -1; }
  .maptools .seg button { flex: 1; padding-inline: 4px; }
  .maptools-right { display: contents; }
  .maptools-right .tool { justify-content: center; }
  .yr { grid-template-rows: 46px auto 3px; }
  .yr .y { font-size: 0.72rem; }
  .yr .ha { display: none; }
  .years { gap: 2px; padding-inline: 4px; }
  .legend { width: 158px; padding: 6px 8px 7px; }
  .legend .ramp { margin: 5px 0 2px; }
  .years-cap { padding-left: 0; }
  .ledger > div { grid-template-columns: 6.5rem minmax(0, 1fr); }
  .demo { gap: 6px; padding-left: 12px; font-size: 0.76rem; }
  .demo-picks button { padding: 6px 9px 6px 6px; gap: 5px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ================================================================ printed report */
.print-head { display: none; }
@media print {
  @page { margin: 14mm; }
  .topbar, .nav, .drawer, .scrim, .demo, .toast, .maptools, .actions, .crumbs, .play, .years-cap, .hint, .fit, .readout, .statusbar { display: none !important; }
  .print-head { display: block; margin-bottom: 8mm; }
  .print-head p { font-size: 10pt; color: #444; }
  .print-head h1 { font-size: 18pt; margin: 2mm 0; }
  .bar { display: none; }
  .app, .shell, .stage, .mapzone, .rail { display: block !important; height: auto !important; overflow: visible !important; padding: 0 !important; }
  .map { height: 110mm !important; margin-bottom: 4mm; break-inside: avoid; }
  .timeline { margin-bottom: 6mm; }
  .panel { break-inside: avoid; border-radius: 0 !important; box-shadow: none !important; }
  body { background: #fff !important; }
}
