:root {
  color-scheme: dark;
  --bg: #050a12;
  --panel: #0b1420;
  --panel-2: #101e2c;
  --line: #21384b;
  --text: #e7f5ff;
  --muted: #8fa8b8;
  --cyan: #20e6d0;
  --blue: #53a8ff;
  --gold: #f3c969;
  --red: #ff6f78;
  --green: #7ee787;
  --purple: #c69cff;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  color: var(--text);
  background:
    linear-gradient(rgba(32, 230, 208, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(32, 230, 208, .035) 1px, transparent 1px),
    radial-gradient(circle at 85% 0%, rgba(83, 168, 255, .13), transparent 30rem),
    var(--bg);
  background-size: 36px 36px, 36px 36px, auto, auto;
}

a { color: var(--cyan); }
code { color: #a7f3ea; font-size: .92em; }

.site-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 2rem;
  align-items: start;
  padding: 2.25rem clamp(1rem, 4vw, 4.5rem) 3.2rem;
  border-bottom: 1px solid var(--line);
  background: rgba(5, 10, 18, .82);
  backdrop-filter: blur(14px);
}

.back-link {
  display: inline-flex;
  padding: .55rem .7rem;
  border: 1px solid var(--line);
  text-decoration: none;
  font: 700 .76rem/1 ui-monospace, monospace;
  letter-spacing: .09em;
}

h1, h2, h3, p { margin-top: 0; }
h1 {
  max-width: 16ch;
  margin-bottom: .7rem;
  font-size: clamp(2.2rem, 6vw, 5.4rem);
  line-height: .9;
  letter-spacing: -.055em;
}
h2 { margin-bottom: .35rem; font-size: clamp(1.45rem, 3vw, 2.4rem); letter-spacing: -.03em; }
h3 { margin-bottom: .4rem; }
.lede { max-width: 70ch; margin-bottom: 0; color: var(--muted); font-size: 1.05rem; }
.eyebrow { margin-bottom: .55rem; color: var(--cyan); font: 700 .72rem/1.2 ui-monospace, monospace; letter-spacing: .13em; }
.muted { color: var(--muted); }

.site-header nav { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .75rem 1rem; max-width: 22rem; }
.site-header nav a { color: var(--muted); font: 700 .72rem/1.2 ui-monospace, monospace; text-decoration: none; text-transform: uppercase; letter-spacing: .08em; }
.site-header nav a:hover, .site-header nav a:focus-visible { color: var(--cyan); }

main { width: min(1480px, calc(100% - 2rem)); margin: 0 auto; }
section { padding: 4.5rem 0; border-bottom: 1px solid var(--line); }
.section-heading { display: flex; justify-content: space-between; gap: 2rem; align-items: end; margin-bottom: 1.6rem; }
.section-heading > p { max-width: 58ch; margin-bottom: .15rem; color: var(--muted); }

.callout { margin: 2rem 0 0; padding: 1.2rem; border: 1px solid var(--line); background: linear-gradient(135deg, rgba(32, 230, 208, .08), rgba(83, 168, 255, .04)); }
.callout.authority { display: grid; grid-template-columns: minmax(15rem, .75fr) minmax(20rem, 1.6fr) auto; gap: 2rem; align-items: center; }
.callout p { margin-bottom: 0; color: var(--muted); }
.callout.error { color: #ffd7da; border-color: rgba(255, 111, 120, .5); background: rgba(255, 111, 120, .08); }

.metric-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); }
.metric { min-height: 8rem; padding: 1rem; background: var(--panel); }
.metric strong { display: block; margin-bottom: .35rem; color: var(--cyan); font-size: clamp(1.6rem, 3vw, 2.5rem); }
.metric span { color: var(--muted); font-size: .82rem; }

.split-panel { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(19rem, .75fr); gap: 1rem; }
.control-panel, .formula-card { padding: 1.25rem; border: 1px solid var(--line); background: rgba(11, 20, 32, .88); }
label { color: var(--muted); font: 700 .75rem/1.3 ui-monospace, monospace; letter-spacing: .06em; text-transform: uppercase; }
select, input {
  width: 100%;
  margin-top: .45rem;
  padding: .72rem .8rem;
  color: var(--text);
  border: 1px solid var(--line);
  background: #07111c;
  font: inherit;
}
select:focus, input:focus { outline: 2px solid var(--cyan); outline-offset: 2px; }
.ship-identity { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: 1.2rem 0; }
.ship-identity h3 { width: 100%; margin: 0; font-size: 1.45rem; }
.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .7rem; }
.stat { padding: .85rem; border: 1px solid var(--line); background: var(--panel-2); }
.stat strong { display: block; color: var(--gold); font-size: 1.2rem; }
.stat span { color: var(--muted); font-size: .72rem; }
.formula { display: grid; grid-template-columns: 1fr; gap: .45rem; align-items: center; margin: 1.4rem 0; text-align: center; }
.formula span { padding: .75rem .6rem; border: 1px solid var(--line); color: var(--cyan); font-weight: 700; }
.formula strong { font-size: 1.15rem; line-height: .7; transform: rotate(90deg); }
.divider { height: 1px; margin: 1.5rem 0; background: var(--line); }
.estimate { color: var(--gold); font-size: 1.55rem; font-weight: 800; }

.legend, .filters { display: flex; flex-wrap: wrap; gap: .7rem; align-items: end; margin-bottom: 1rem; }
.decision-note { margin: 0 0 1rem; padding: .8rem 1rem; color: var(--muted); border-left: 3px solid var(--gold); background: rgba(243, 201, 105, .06); font-size: .84rem; }
.decision-note strong { color: var(--gold); }
.badge { display: inline-flex; align-items: center; width: fit-content; padding: .28rem .48rem; border: 1px solid currentColor; font: 700 .68rem/1 ui-monospace, monospace; text-transform: uppercase; letter-spacing: .05em; }
.badge.direct-yield, .status-fully-derivable { color: var(--green); }
.badge.direct-consumption, .status-partially-derivable { color: var(--gold); }
.badge.indirect-throughput, .status-runtime-only { color: var(--blue); }
.status-missing { color: var(--red); }
.authority-ses-source, .authority-ses-derived { color: var(--cyan); }
.authority-program-runtime { color: var(--blue); }
.authority-external-service { color: var(--purple); }
.authority-missing { color: var(--red); }

.table-shell { max-height: 34rem; overflow: auto; border: 1px solid var(--line); background: var(--panel); scrollbar-gutter: stable; scrollbar-color: var(--cyan) #07111c; }
.table-shell::-webkit-scrollbar { width: 11px; height: 11px; }
.table-shell::-webkit-scrollbar-track { background: #07111c; }
.table-shell::-webkit-scrollbar-thumb { border: 2px solid #07111c; background: var(--cyan); }
.table-shell::-webkit-scrollbar-corner { background: #07111c; }
table { width: 100%; border-collapse: collapse; font-size: .82rem; }
th { position: sticky; top: 0; z-index: 1; padding: .8rem; color: var(--cyan); background: #0c1723; text-align: left; font: 700 .7rem/1.2 ui-monospace, monospace; letter-spacing: .06em; text-transform: uppercase; }
td { padding: .8rem; border-top: 1px solid var(--line); vertical-align: top; }
td small { display: block; margin-top: .25rem; color: var(--muted); }
.effect-list { display: grid; gap: .65rem; min-width: 26rem; }
.effect-item { display: grid; grid-template-columns: minmax(16rem, 1.2fr) minmax(13rem, 1fr); gap: .75rem; align-items: center; padding-bottom: .65rem; border-bottom: 1px solid rgba(33, 56, 75, .65); }
.effect-item:last-child { padding-bottom: 0; border-bottom: 0; }
.effect-item > div { display: flex; flex-wrap: wrap; gap: .45rem; align-items: center; }
.effect-item > span { color: var(--muted); font-size: .76rem; }
.effect-item code { overflow-wrap: anywhere; }
tr:hover td { background: rgba(83, 168, 255, .035); }
.filters label { min-width: min(18rem, 100%); }
.filters label:nth-child(2) { min-width: 7rem; }
.filters .muted { margin-left: auto; padding-bottom: .7rem; }
.resource-table { max-height: 42rem; }

.journey-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .8rem; }
.journey-card, .lineage-card { min-width: 0; padding: 1rem; border: 1px solid var(--line); background: rgba(11, 20, 32, .88); }
.journey-card header { display: flex; justify-content: space-between; gap: .8rem; align-items: start; }
.journey-card p { color: var(--muted); font-size: .86rem; }
.journey-card ul { margin: .8rem 0 0; padding-left: 1.15rem; color: #b9ccd8; font-size: .78rem; }
.lineage-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .8rem; }
.lineage-card code { display: block; margin: .7rem 0; padding: .65rem; overflow-wrap: anywhere; border: 1px solid var(--line); background: #07111c; }
.lineage-card dl { display: grid; grid-template-columns: 6.2rem minmax(0, 1fr); gap: .45rem .8rem; min-width: 0; margin: .8rem 0 0; font-size: .8rem; }
.lineage-card dt { color: var(--muted); }
.lineage-card dd { min-width: 0; margin: 0; overflow-wrap: anywhere; }

.config-controls { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .8rem; }
.stat { min-width: 0; }
.stat .delta { display: block; margin-top: .42rem; overflow-wrap: anywhere; font: 650 .66rem/1.3 ui-monospace, monospace; }
.delta.up, .delta.down { color: var(--gold); }
.delta.neutral { color: var(--muted); }
.configuration-detail { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(13rem, .6fr); gap: 1rem; margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.config-effect-groups { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; }
.config-effect-chip { min-width: 0; padding: .65rem; border: 1px solid var(--line); background: #07111c; }
.config-effect-chip strong, .config-effect-chip span { display: block; overflow-wrap: anywhere; }
.config-effect-chip strong { color: var(--cyan); font-size: .78rem; }
.config-effect-chip span { margin-top: .25rem; color: var(--muted); font-size: .68rem; }
.empty-state { grid-column: 1 / -1; margin: 0; padding: .8rem; color: var(--muted); border: 1px dashed var(--line); font-size: .78rem; }
.config-metadata { display: grid; grid-template-columns: minmax(5.5rem, auto) minmax(0, 1fr); align-content: start; gap: .4rem .6rem; margin: 1.2rem 0 0; font-size: .72rem; }
.config-metadata dt { color: var(--muted); }
.config-metadata dd { min-width: 0; margin: 0; overflow-wrap: anywhere; }

.scenario-layout { display: grid; grid-template-columns: minmax(20rem, .8fr) minmax(0, 1.2fr); gap: 1rem; }
.scenario-form, .scenario-results-wrap { min-width: 0; padding: 1rem; border: 1px solid var(--line); background: rgba(11, 20, 32, .88); }
.scenario-config-note { margin-bottom: 1rem; color: var(--muted); }
.scenario-config-note strong { color: var(--text); }
.scenario-inputs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; }
.scenario-form > .muted { margin: 1rem 0 0; font-size: .78rem; }
.scenario-results { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px; border: 1px solid var(--line); background: var(--line); }
.scenario-results article { min-width: 0; min-height: 7.25rem; padding: .85rem; background: var(--panel-2); }
.scenario-results strong, .scenario-results span { display: block; overflow-wrap: anywhere; }
.scenario-results strong { color: var(--gold); font-size: 1.05rem; }
.scenario-results span { margin-top: .35rem; color: var(--muted); font-size: .7rem; }
.scenario-assumptions { margin: 1rem 0 0; padding: .75rem; color: var(--muted); border-left: 3px solid var(--blue); background: rgba(83, 168, 255, .05); font-size: .77rem; }
.editor-links { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .7rem; margin-top: 1rem; }
.editor-links a { min-width: 0; padding: .85rem; border: 1px solid var(--line); background: rgba(11, 20, 32, .88); text-decoration: none; }
.editor-links strong, .editor-links span { display: block; overflow-wrap: anywhere; }
.editor-links strong { color: var(--cyan); font-size: .82rem; }
.editor-links span { margin-top: .4rem; color: var(--muted); font-size: .7rem; }
.editor-links a:hover, .editor-links a:focus-visible { border-color: var(--cyan); background: rgba(32, 230, 208, .06); }

footer { display: flex; justify-content: space-between; gap: 1rem; padding: 2rem clamp(1rem, 4vw, 4.5rem); color: var(--muted); font: 700 .72rem/1.2 ui-monospace, monospace; text-transform: uppercase; letter-spacing: .06em; }
footer p { margin: 0; }
footer div { display: flex; flex-wrap: wrap; gap: 1rem; }

@media (max-width: 1050px) {
  .site-header { grid-template-columns: auto 1fr; }
  .site-header nav { grid-column: 1 / -1; justify-content: flex-start; max-width: none; }
  .metric-grid { grid-template-columns: repeat(3, 1fr); }
  .split-panel, .scenario-layout { grid-template-columns: 1fr; }
  .editor-links { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .journey-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 680px) {
  .site-header { gap: 1rem; padding: 1.2rem 1rem 2rem; }
  main { width: min(100% - 1rem, 1480px); }
  section { padding: 3.2rem 0; }
  .section-heading, .callout.authority { display: block; }
  .section-heading > p, .callout.authority > * { margin-top: 1rem; }
  .metric-grid, .stats-grid, .journey-grid, .lineage-grid { grid-template-columns: 1fr 1fr; }
  .config-controls, .configuration-detail { grid-template-columns: 1fr; }
  .scenario-results { grid-template-columns: 1fr 1fr; }
  .scenario-results article:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .editor-links { grid-template-columns: 1fr 1fr; }
  .formula { grid-template-columns: 1fr; }
  .formula strong { transform: rotate(90deg); }
  footer { display: block; }
  footer div { margin-top: 1rem; }
}

@media (max-width: 440px) {
  .metric-grid, .stats-grid, .journey-grid, .lineage-grid, .scenario-inputs, .config-effect-groups, .editor-links { grid-template-columns: 1fr; }
  .scenario-results article { min-height: 5.8rem; }
}
