/* Layout: one target picked at the top drives the page: its price card, a route from the stash, live offers, the map. */
:root {
  --bg: #eceef1;
  --panel: #f8f9fb;
  --line: #d3d8df;
  --fg: #1d232b;
  --muted: #5d6773;
  --rune: #b5650d;
  --rune-soft: #f3e3cf;
  --good: #1f7a4a;
  --good-soft: #d9efe2;
  --bad: #b23a2e;
  --bad-soft: #f6dcd8;
  --edge: #8a96a3;
  --f-display: "Spectral SC", "Palatino Linotype", Georgia, serif;
  --f-body: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161b; --panel: #1a2027; --line: #2c343e; --fg: #e3e7ec; --muted: #8f9aa6;
    --rune: #e39a45; --rune-soft: #3a2a17; --good: #5cc48a; --good-soft: #173225; --bad: #ec7a6c; --bad-soft: #3b1e1a;
    --edge: #6b7784; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12161b; --panel: #1a2027; --line: #2c343e; --fg: #e3e7ec; --muted: #8f9aa6;
  --rune: #e39a45; --rune-soft: #3a2a17; --good: #5cc48a; --good-soft: #173225; --bad: #ec7a6c; --bad-soft: #3b1e1a;
  --edge: #6b7784; color-scheme: dark;
}
[hidden] { display: none !important; }  /* layout rules below must not resurrect hidden elements */
body { background: var(--bg); color: var(--fg); font-family: var(--f-body); font-size: 14px; line-height: 1.5; }
.wrap { max-width: 1180px; margin: 0 auto; padding-block: 28px 64px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); display: grid; grid-template-columns: minmax(0, 1fr); gap: 36px; }
h1, h2, h3 { font-family: var(--f-display); font-weight: 700; text-wrap: balance; margin: 0; letter-spacing: .01em; }
h1 { font-size: 30px; line-height: 1.15; }
h2 { font-size: 21px; }
h3 { font-size: 17px; }
a { color: var(--rune); }
.muted { color: var(--muted); }
.num { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
.label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
header { display: flex; flex-wrap: wrap; gap: 16px 32px; align-items: end; justify-content: space-between; }
header .meta { display: grid; gap: 4px; min-width: 0; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--panel); }
.seg button { font: inherit; padding: 7px 14px; border: 0; background: none; color: var(--muted); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--rune); color: var(--panel); font-weight: 600; }
.seg button:focus-visible, button:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--rune); outline-offset: 2px; }
section { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; min-width: 0; }
.section-head { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: baseline; justify-content: space-between; }
.section-head p { margin: 0; max-width: 70ch; }

.targets { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 20px; }
#route-out, #s-target { grid-template-columns: minmax(0, 1fr); }
.target { grid-template-columns: minmax(0, 1fr); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 20px; display: grid; gap: 16px; min-width: 0; }
.target-top { display: flex; gap: 16px; align-items: center; }
.glyph { width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; background: var(--rune-soft); color: var(--rune); font-family: var(--f-display); font-size: 20px; font-weight: 700; flex: none; border: 1px solid var(--rune); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(140px, 100%), 1fr)); gap: 12px; }
.kpi { display: grid; gap: 2px; min-width: 0; }
.kpi .v { font-family: var(--f-mono); font-size: 20px; font-weight: 500; font-variant-numeric: tabular-nums; }
.equiv { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-family: var(--f-mono); font-size: 12px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg); white-space: nowrap; }
.pill { display: inline-block; font-family: var(--f-mono); font-size: 12px; padding: 1px 7px; border-radius: 999px; white-space: nowrap; font-weight: 500; }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.even { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 4px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }

.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; background: var(--panel); position: sticky; top: 0; white-space: nowrap; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--fg); }
tr:last-child td { border-bottom: 0; }
td.r, th.r { text-align: right; }
tbody tr:hover td { background: color-mix(in srgb, var(--rune-soft) 40%, transparent); }
.give { color: var(--bad); }
.get { color: var(--good); }

.route { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.route .arrow { color: var(--muted); }

.map-box { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px; display: grid; gap: 10px; min-width: 0; }
.map-scroll { overflow-x: auto; }
.map-scroll svg { display: block; min-width: 760px; width: 100%; height: auto; }
.map-tools { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; font-size: 13px; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 18px; height: 3px; vertical-align: middle; margin-right: 6px; border-radius: 2px; }
svg text { font-family: var(--f-body); }
.node { cursor: pointer; }
.node circle { stroke: var(--panel); stroke-width: 1.5; }
.node.focus circle { stroke: var(--fg); stroke-width: 2.5; }
.node.dim { opacity: .28; }
.edge { fill: none; stroke-linecap: round; }
.edge-hit { fill: none; stroke: transparent; stroke-width: 10; cursor: pointer; }
.tip { font-size: 13px; min-height: 2.6em; }

.calc { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.calc input, .calc select { font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--fg); }
.calc input { width: 80px; font-family: var(--f-mono); }
.calc .out { font-family: var(--f-mono); font-size: 15px; }

.two { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 20px; }
.notes { font-size: 13px; color: var(--muted); max-width: 80ch; display: grid; gap: 6px; }
.notes p { margin: 0; }
details summary { cursor: pointer; color: var(--muted); font-size: 12px; }
.empty { padding: 16px; color: var(--muted); }
@media (max-width: 520px) { h1 { font-size: 24px; } .kpi .v { font-size: 17px; } }
@media (prefers-reduced-motion: no-preference) { .node circle, .edge { transition: opacity .15s; } }
.picker { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center;
  background: var(--panel); border: 1px solid var(--rune); border-radius: 10px; padding: 12px 16px; box-shadow: 0 4px 14px color-mix(in srgb, var(--fg) 8%, transparent); }
.picker label.big { font-family: var(--f-display); font-weight: 700; font-size: 17px; color: var(--rune); }
.picker input { font: inherit; padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--fg); }
#t-input { width: min(340px, 100%); font-size: 15px; }
#t-qty { width: 70px; font-family: var(--f-mono); }
.picker .quick { display: flex; flex-wrap: wrap; gap: 6px; }
.picker .quick button { font: inherit; font-size: 12px; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg); color: var(--fg); cursor: pointer; }
.picker .quick button[aria-pressed="true"] { border-color: var(--rune); color: var(--rune); font-weight: 600; }
@media (max-width: 720px) { .picker { position: static; } }  /* on a phone a pinned picker would eat a quarter of the screen */
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--bg); }
tbody tr.pick { cursor: pointer; }
header { position: relative; }
header .meta { padding-right: 52px; }
.gear { position: absolute; top: 0; right: 0; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel); color: var(--muted); cursor: pointer; }
.gear:hover, .gear[aria-expanded="true"] { color: var(--rune); border-color: var(--rune); }
.menu { box-sizing: border-box; position: absolute; top: 48px; right: 0; z-index: 20; width: min(380px, calc(100vw - 32px)); display: grid; gap: 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; box-shadow: 0 10px 30px color-mix(in srgb, var(--fg) 18%, transparent); }
.menu .row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.menu .block { display: grid; gap: 8px; }
.menu .block + .block { border-top: 1px solid var(--line); padding-top: 14px; }
.menu p { margin: 0; font-size: 13px; }
.btn { font: inherit; font-size: 13px; padding: 5px 12px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); color: var(--fg); cursor: pointer; }
.btn.primary { background: var(--rune); border-color: var(--rune); color: var(--panel); font-weight: 600; }
.btn:disabled { opacity: .5; cursor: default; }
dialog { box-sizing: border-box; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--fg); padding: 22px; width: min(400px, calc(100vw - 32px)); }
dialog::backdrop { background: color-mix(in srgb, #000 45%, transparent); }
dialog form { display: grid; gap: 12px; }
dialog label { display: grid; gap: 4px; font-size: 13px; }
dialog label.check { display: flex; gap: 8px; align-items: flex-start; }
dialog input:not([type]), dialog input[type="password"] { font: inherit; padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--fg); }
dialog .why { margin: 0; font-size: 12px; }
dialog .row { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.err { color: var(--bad); }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; margin-top: -14px; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { font: inherit; font-family: var(--f-display); font-weight: 700; font-size: 16px; padding: 10px 14px; border: 0; border-bottom: 2px solid transparent;
  margin-bottom: -1px; background: none; color: var(--muted); white-space: nowrap; cursor: pointer; }
.tabs button:hover { color: var(--fg); }
.tabs button[aria-selected="true"] { color: var(--rune); border-bottom-color: var(--rune); }
.tabs .count { font-family: var(--f-mono); font-size: 11px; font-weight: 500; margin-left: 6px; color: var(--muted); }
.panel { display: grid; grid-template-columns: minmax(0, 1fr); gap: 36px; min-width: 0; }
.kpis.wide { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px 20px; gap: 16px 24px; }
.kpi .sub { font-size: 12px; color: var(--muted); }
.tools { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; font-size: 13px; }
.tools select { font: inherit; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--fg); }
.seg.small { max-width: 100%; overflow-x: auto; scrollbar-width: thin; }
.seg.small button { padding: 4px 10px; font-size: 12px; white-space: nowrap; flex: none; }
#market td.num, #mine-cur td.num { white-space: nowrap; }
.quote { display: inline-flex; gap: 6px; align-items: baseline; white-space: nowrap; }
#cross td, #cross th { padding: 6px 8px; font-size: 12px; }
#cross th.row { position: sticky; left: 0; z-index: 1; text-align: left; }
#cross td.self { color: var(--muted); }
#cross td.base, #cross th.base { background: var(--rune-soft); }
details.notes > summary { font-family: var(--f-display); font-size: 15px; font-weight: 700; color: var(--fg); }
details.notes[open] > summary { margin-bottom: 6px; }
@media (max-width: 520px) { .menu { position: fixed; top: 64px; left: 16px; right: 16px; width: auto; } }
