:root {
  color-scheme: light;
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #efede8;
  --text: #1d1f23;
  --muted: #676b73;
  --line: #dcd9d2;
  --accent: #c2571a;
  --accent-text: #ffffff;
  --share: #2263cf;
  --share-text: #ffffff;
  --curve: #c2571a;
  --ok: #2e7d4f;
  --warn: #b3261e;
  --anc: #d9731f;
  --desc: #2f7fd0;
  --heat-lo: #f3ede2;
  --heat-hi: #7a1f3d;
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #16171a;
    --surface: #1f2125;
    --surface-2: #2a2c31;
    --text: #e6e4df;
    --muted: #9a9ea6;
    --line: #34373d;
    --accent: #f08a3e;
    --accent-text: #1b1206;
    --share: #4a92ee;
    --share-text: #06101d;
    --curve: #f59a52;
    --ok: #6cc28f;
    --warn: #ff8a80;
    --anc: #f5a052;
    --desc: #6fb2f5;
    --heat-lo: #2a2c31;
    --heat-hi: #f0a04b;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #16171a;
  --surface: #1f2125;
  --surface-2: #2a2c31;
  --text: #e6e4df;
  --muted: #9a9ea6;
  --line: #34373d;
  --accent: #f08a3e;
  --accent-text: #1b1206;
  --curve: #f59a52;
  --ok: #6cc28f;
  --warn: #ff8a80;
  --anc: #f5a052;
  --desc: #6fb2f5;
  --heat-lo: #2a2c31;
  --heat-hi: #f0a04b;
  --share: #4a92ee;
  --share-text: #06101d;
}
:root[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); padding: 0 16px 32px; }
body.dropping::after {
  content: "Drop rcs-export.txt to import it"; position: fixed; inset: 12px; display: grid; place-items: center;
  border: 3px dashed var(--accent); border-radius: 12px; background: color-mix(in oklab, var(--bg) 85%, transparent);
  font-size: 1.4rem; font-weight: 600; pointer-events: none; z-index: 10;
}
a { color: var(--accent); }
code { font: 0.92em ui-monospace, "SF Mono", Menlo, monospace; background: var(--surface-2); padding: 0.05em 0.3em; border-radius: 3px; overflow-wrap: anywhere; }
.muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
[hidden] { display: none !important; }

.top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 0 12px; max-width: 1400px; margin: 0 auto; }
.brand h1 { margin: 0; font-size: 1.5rem; letter-spacing: -0.01em; }
.brand p { margin: 2px 0 0; }
.load { display: flex; flex-wrap: wrap; gap: 8px; }

.button, button.button, select.button {
  font: inherit; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: 6px 12px; border-radius: 6px; cursor: pointer; white-space: nowrap;
}
.button:hover { border-color: var(--muted); }
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.link { font: inherit; background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; text-decoration: underline; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; }
textarea { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px; width: 100%; resize: vertical; }

.sample-banner {
  --warn-bg: #ffd84d; --warn-ink: #231c00; --warn-edge: #1f1a0a;
  max-width: 1400px; margin: 0 auto 14px; padding: 18px 22px; border-radius: 12px;
  background: var(--warn-bg); color: var(--warn-ink);
  border: 3px solid var(--warn-edge); box-shadow: 0 0 0 4px color-mix(in oklab, var(--warn-bg) 40%, transparent);
  display: flex; flex-wrap: wrap; gap: 16px 28px; align-items: center; justify-content: space-between;
}
.sample-banner code { background: rgb(0 0 0 / 0.1); color: inherit; }
.sample-text { flex: 1 1 520px; min-width: 0; }
.sample-kicker { margin: 0; font-size: 12px; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; }
.sample-banner h2 { margin: 2px 0 6px; font-size: 1.6rem; line-height: 1.15; letter-spacing: -0.01em; }
.sample-banner p, .sample-banner ol { margin: 0 0 6px; }
.sample-banner ol { padding-left: 1.3em; }
.sample-banner li { margin: 2px 0; }
.sample-actions { display: flex; flex-direction: column; gap: 8px; flex: 0 0 auto; }
.sample-banner .button.primary { background: var(--warn-ink); border-color: var(--warn-ink); color: var(--warn-bg); }
.sample-banner .button:not(.primary) { background: transparent; border: 2px solid var(--warn-ink); color: var(--warn-ink); }
.button.big { font-size: 1.05rem; padding: 10px 18px; text-align: center; }
.sample-pill { background: #ffd84d; color: #231c00; font-weight: 800; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; padding: 2px 8px; border-radius: 999px; }
.banner { max-width: 1400px; margin: 0 auto 10px; padding: 10px 14px; border-radius: 8px; background: var(--surface); border: 1px solid var(--line); }
.banner.error, .error-text { color: var(--warn); }
.banner.error { border-color: var(--warn); }
.source { max-width: 1400px; margin: 0 auto 12px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline; }
.source strong { color: var(--text); }
.source details { display: inline-block; position: relative; }
.source summary { cursor: pointer; color: var(--accent); }
.source ul { position: absolute; z-index: 5; margin: 4px 0 0; padding: 8px 12px 8px 26px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; max-height: 50vh; overflow: auto; min-width: 220px; }

main { max-width: 1400px; margin: 0 auto; }
.curve-panel { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
@media (max-width: 900px) { .curve-panel { grid-template-columns: minmax(0, 1fr); } }
.chart-wrap { position: relative; min-width: 0; }
#chart { width: 100%; height: auto; display: block; touch-action: none; user-select: none; }
.hint { margin: 4px 0 0; font-size: 12.5px; }
.curve-side { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.curve-side > label { font-weight: 600; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.fields label { display: flex; flex-direction: column; gap: 3px; color: var(--muted); font-size: 12.5px; }
.fields input { width: 100%; }
.stats { display: grid; gap: 8px; margin-top: 4px; }
.stat { display: grid; background: var(--surface-2); border-radius: 8px; padding: 8px 10px; }
.stat span { color: var(--muted); font-size: 12px; }
.stat b { font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.stat small { color: var(--muted); }
.stats p { margin: 0; font-size: 13px; }
.ok { color: var(--ok); }
.warn { color: var(--warn); }

/* chart */
#chart .grid line { stroke: var(--line); }
#chart .grid line.minor { stroke-dasharray: 2 4; }
#chart .grid line.unity { stroke: var(--muted); stroke-dasharray: 5 4; }
#chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
#chart .tick.y { text-anchor: end; }
#chart .tick.x { text-anchor: middle; }
#chart .axis-label { fill: var(--muted); font-size: 12px; text-anchor: middle; }
#chart .milestone { stroke-width: 1.5; stroke-dasharray: 3 3; opacity: 0.85; }
#chart .milestone-label { fill: var(--muted); font-size: 11px; }
#chart .rug line { stroke-width: 1.4; opacity: 0.9; }
#chart .curve { fill: none; stroke: var(--curve); stroke-width: 3; stroke-linejoin: round; }
#chart .inf-line { stroke: var(--curve); stroke-width: 2; stroke-dasharray: 6 4; }
#chart .inf-label { fill: var(--curve); font-size: 11px; text-anchor: end; }
#chart .hover-layer { fill: transparent; cursor: crosshair; }
#chart .cursor { stroke: var(--muted); stroke-width: 1; pointer-events: none; }
#chart .handle { cursor: grab; }
#chart .handle .hit { fill: transparent; }
#chart .handle .dot { fill: var(--surface); stroke: var(--curve); stroke-width: 3; }
#chart .handle:hover .dot, #chart .handle.active .dot { fill: var(--curve); }
#chart .handle-label { fill: var(--text); font-size: 11.5px; font-weight: 600; paint-order: stroke; stroke: var(--surface); stroke-width: 4px; }
.tip { position: absolute; pointer-events: none; background: var(--text); color: var(--bg); font-size: 12px; padding: 6px 9px; border-radius: 6px; max-width: 280px; z-index: 4; }
.tip .muted { color: color-mix(in oklab, var(--bg) 70%, var(--text)); }

/* tabs */
.tabs { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; margin: 18px 0 10px; border-bottom: 1px solid var(--line); }
.tabs [data-tab] { font: inherit; background: none; border: 0; border-bottom: 3px solid transparent; padding: 8px 12px; color: var(--muted); cursor: pointer; margin-bottom: -1px; }
.tabs [data-tab][aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.tabs .spm { margin-left: auto; color: var(--muted); padding-bottom: 6px; }
.tabs .spm input { width: 90px; }

/* tree */
.tree-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; }
.tree-tools .spacer { flex: 1; }
#tree-search, #tech-filter { min-width: 220px; }
.tree-area { position: relative; }
.tree { height: min(72vh, 760px); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.tree-svg { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; user-select: none; }
.tree-svg:active { cursor: grabbing; }
.tree-panel { position: absolute; top: 10px; right: 10px; width: 290px; max-width: calc(100% - 20px); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; box-shadow: 0 4px 18px rgb(0 0 0 / 0.12); font-size: 13px; }
.tree-panel h3 { margin: 0 0 4px; font-size: 14px; display: flex; justify-content: space-between; gap: 8px; overflow-wrap: anywhere; }
.tree-panel h4 { margin: 10px 0 2px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.tree-panel p { margin: 0 0 4px; }
.anc-key { color: var(--anc); }
.desc-key { color: var(--desc); }
@media (max-width: 700px) { .tree-panel { position: static; width: auto; max-width: none; margin-top: 8px; } }

.edges path { fill: none; stroke: var(--line); stroke-width: 1.3; }
.node .box { fill: var(--surface-2); stroke: var(--line); stroke-width: 1; }
.node-name { font-size: 12.5px; font-weight: 600; fill: var(--text); pointer-events: none; }
.node-cost { font-size: 11.5px; fill: var(--muted); font-variant-numeric: tabular-nums; pointer-events: none; }
.node .box[style*="rgb"] ~ .node-name { fill: #2a1a08; }
.node .box[style*="rgb"] ~ .node-cost { fill: rgb(42 26 8 / 0.78); }
.node.hot .node-name { fill: #fff !important; }
.node.hot .node-cost { fill: rgb(255 255 255 / 0.85) !important; }
.node { cursor: pointer; }
.node:hover > .box { stroke: var(--text); }
.has-selection .node { opacity: 0.28; }
.has-selection .node.sel, .has-selection .node.anc, .has-selection .node.desc { opacity: 1; }
.node.sel > .box { stroke: var(--text); stroke-width: 3; }
.node.anc > .box { stroke: var(--anc); stroke-width: 2.5; }
.node.desc > .box { stroke: var(--desc); stroke-width: 2.5; }
.has-selection .edges path { opacity: 0.25; }
.edges path.up { stroke: var(--anc); stroke-width: 2.2; opacity: 1; }
.edges path.down { stroke: var(--desc); stroke-width: 2.2; opacity: 1; }
.legend { margin: 6px 0 0; font-size: 12.5px; }
.key { display: inline-block; width: 14px; height: 4px; border-radius: 2px; vertical-align: middle; margin: 0 4px 0 10px; }
.key.anc { background: var(--anc); margin-left: 0; }
.key.desc { background: var(--desc); }

/* tables */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 6px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { position: sticky; top: 0; background: var(--surface); font-weight: 600; color: var(--muted); white-space: nowrap; }
#tech-table th { cursor: pointer; user-select: none; }
#tech-table th.asc::after { content: " ▲"; font-size: 9px; }
#tech-table th.desc::after { content: " ▼"; font-size: 9px; }
#tech-table tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
tr.differs td { background: color-mix(in oklab, var(--warn) 14%, transparent); }
.chips { display: inline-flex; gap: 2px; vertical-align: middle; }
.chips i { width: 9px; height: 9px; border-radius: 2px; display: inline-block; outline: 1px solid rgb(0 0 0 / 0.15); }
.set-name { color: var(--muted); margin-left: 4px; }

footer { max-width: 1400px; margin: 24px auto 0; font-size: 12.5px; }

dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--text); width: min(640px, calc(100vw - 32px)); padding: 18px; }
dialog::backdrop { background: rgb(0 0 0 / 0.4); }
dialog h2 { margin: 0 0 6px; font-size: 1.1rem; }
dialog .field { display: flex; flex-direction: column; gap: 4px; margin: 10px 0; font-weight: 600; }
dialog .field input { font-weight: 400; width: 100%; }
#share-url { font-family: ui-monospace, "SF Mono", Menlo, monospace; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }

/* quiet header buttons (theme, sound) */
.button.quiet { background: transparent; color: var(--muted); border-color: transparent; }
.button.quiet:hover { color: var(--text); border-color: var(--line); }

/* shared run: the title is the showcase */
.hero {
  max-width: 1400px; margin: 4px auto 16px; padding: 26px 20px 22px; text-align: center;
  border-radius: 14px; border: 1px solid var(--line);
  background: radial-gradient(120% 140% at 50% 0%, color-mix(in oklab, var(--accent) 16%, var(--surface)), var(--surface) 70%);
}
.hero-kicker { margin: 0; font-size: 12px; font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase; color: var(--accent); }
.hero h2 { margin: 4px 0 8px; font-size: clamp(1.8rem, 4.5vw, 3rem); line-height: 1.1; letter-spacing: -0.02em; overflow-wrap: anywhere; }
.hero-meta { margin: 0 0 8px; color: var(--muted); font-size: 1rem; }
.hero-meta details { display: inline-block; position: relative; text-align: left; }
.hero-note { margin: 0; color: var(--muted); font-size: 12.5px; }

/* mod lists */
details.mods summary { cursor: pointer; color: var(--accent); }
details.mods ul { position: absolute; z-index: 6; margin: 4px 0 0; padding: 8px 12px 8px 26px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; max-height: 50vh; overflow: auto; min-width: 240px; box-shadow: 0 6px 20px rgb(0 0 0 / 0.18); }
details.mods li { margin: 2px 0; }
details.mods a { color: var(--share); font-weight: 600; text-decoration: none; display: inline-flex; align-items: center; gap: 3px; }
details.mods a:hover { text-decoration: underline; text-underline-offset: 2px; }
details.mods a .ext { width: 12px; height: 12px; opacity: 0.8; }
details.mods li.built-in { color: var(--muted); }
details.mods li.built-in.first { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--line); }

/* tree colour switch and legend */
.seg { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg-label { padding: 0 10px; color: var(--muted); font-size: 12.5px; }
.seg button { font: inherit; border: 0; border-left: 1px solid var(--line); background: transparent; color: var(--text); padding: 6px 12px; cursor: pointer; }
.seg button[aria-checked="true"] { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.tree-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; margin: 0 0 8px; font-size: 13px; }
.legend-what { font-weight: 600; }
.legend-scale { display: inline-flex; align-items: center; gap: 8px; font-variant-numeric: tabular-nums; }
.legend-scale i { display: inline-block; width: 180px; max-width: 40vw; height: 12px; border-radius: 6px; }
.legend-pack { display: inline-flex; align-items: center; gap: 5px; }
.legend-pack i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

/* change feedback: pulse the curve, flash the totals, show the delta */
#chart .curve.pulse { animation: curve-pulse 520ms ease-out; }
@keyframes curve-pulse { from { stroke-width: 7; } to { stroke-width: 3; } }
.stats.flash .stat { animation: stat-flash 900ms ease-out; }
@keyframes stat-flash { from { background: color-mix(in oklab, var(--accent) 28%, var(--surface-2)); } to { background: var(--surface-2); } }
.delta { font-style: normal; font-weight: 700; font-size: 11.5px; margin-left: 6px; padding: 1px 6px; border-radius: 999px; opacity: 0; }
.delta.up, .delta.down { animation: delta-fade 2.6s ease-out forwards; }
.delta.up { background: color-mix(in oklab, var(--accent) 22%, transparent); color: var(--text); }
.delta.down { background: color-mix(in oklab, var(--desc) 22%, transparent); color: var(--text); }
@keyframes delta-fade { 0% { opacity: 0; transform: translateY(3px); } 12% { opacity: 1; transform: none; } 75% { opacity: 1; } 100% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  #chart .curve.pulse, .stats.flash .stat { animation: none; }
  .delta.up, .delta.down { animation: none; opacity: 1; }
}

/* icons */
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -3px; }
.button, label.button { display: inline-flex; align-items: center; gap: 7px; }
.button.icon-only { padding: 6px 8px; }
.button.icon-only .icon { width: 18px; height: 18px; }
button.link { display: inline-flex; align-items: center; gap: 4px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 42px; height: 42px; flex: none; filter: drop-shadow(0 2px 6px rgb(0 0 0 / 0.25)); }
.load { align-items: center; }
.load-sep { width: 1px; align-self: stretch; background: var(--line); margin: 2px 2px; }
.select-button { position: relative; padding-right: 8px; }
.select-button select { font: inherit; color: inherit; background: transparent; border: 0; padding: 0 2px; cursor: pointer; }
.select-button select option { color: var(--text); background: var(--surface); }

/* share stands apart from the orange import/copy actions */
.button.share { background: var(--share); border-color: var(--share); color: var(--share-text); font-weight: 600; }
.button.share:hover { border-color: var(--text); }

/* recent runs */
.recent-wrap { position: relative; }
.recent-panel { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; width: min(420px, calc(100vw - 32px)); max-height: 65vh; overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgb(0 0 0 / 0.3); padding: 6px; }
.recent-panel ul { list-style: none; margin: 0; padding: 0; }
.recent-panel li { display: flex; align-items: stretch; gap: 2px; border-radius: 8px; }
.recent-panel li:hover { background: var(--surface-2); }
.recent-panel > p { margin: 8px 10px; }
.recent-item { flex: 1; min-width: 0; display: grid; gap: 2px; text-align: left; font: inherit; color: var(--text); background: none; border: 0; padding: 8px 10px; cursor: pointer; }
.recent-top { display: flex; align-items: center; gap: 8px; min-width: 0; }
.recent-top b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-meta { color: var(--muted); font-size: 12px; }
.recent-curve { font-size: 11.5px; color: var(--muted); background: none; padding: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-remove { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 0 10px; border-radius: 8px; }
.recent-remove:hover { color: var(--warn); }
.kind { font-size: 10.5px; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; padding: 1px 7px; border-radius: 999px; flex: none; }
.kind-saved { background: color-mix(in oklab, var(--accent) 25%, transparent); }
.kind-shared { background: color-mix(in oklab, var(--share) 30%, transparent); }
.kind-opened { background: var(--surface-2); color: var(--muted); }

/* dismissible sample banner */
.sample-banner { position: relative; }
.sample-close { position: absolute; top: 8px; right: 8px; background: none; border: 0; color: var(--warn-ink); cursor: pointer; padding: 6px; border-radius: 6px; opacity: 0.7; }
.sample-close:hover { opacity: 1; background: rgb(0 0 0 / 0.08); }
.sample-close .icon { width: 20px; height: 20px; }
.source .link .icon { width: 14px; height: 14px; }

/* a tech's own cost, first in the panel */
.own-big { font-size: 1.1rem; font-variant-numeric: tabular-nums; margin: 2px 0 4px !important; }
.small { font-size: 12px; }
.lvl { color: var(--muted); font-size: 11px; margin-left: 2px; }
.tree-panel h3 .link { color: var(--muted); }

/* the curve on screen vs the one the game uses */
.preview-notice, .switch-notice { font-size: 13px; border-radius: 8px; padding: 8px 10px; line-height: 1.45; }
.preview-notice { background: color-mix(in oklab, #f0a030 16%, var(--surface)); border: 1px solid color-mix(in oklab, #f0a030 60%, transparent); }
.switch-notice { background: color-mix(in oklab, var(--share) 12%, var(--surface)); border: 1px solid color-mix(in oklab, var(--share) 50%, transparent); }
.preview-notice code { overflow-wrap: anywhere; }
.in-game { margin: 0 0 4px; padding: 4px 8px; border-left: 3px solid #f0a030; background: color-mix(in oklab, #f0a030 10%, transparent); font-size: 12.5px; }
