/* Luscinia: nightingale / dusk. Tokens first, everything else reads them. */
:root {
  --bg: #f3eee4;
  --surface: #fbf8f1;
  --surface2: #ece5d6;
  --line: #d8cfbb;
  --text: #1f2433;
  --muted: #5d6272;
  --accent: #9c4a1a;
  --accent-ink: #fffaf2;
  --moon: #2a6680;
  --ok: #2e6b46;
  --warn: #86570a;
  --bad: #a3322b;
  --c0: #9c4a1a; --c1: #2a6680; --c2: #5b7f3a; --c3: #8a4f7d;
  --c4: #a8841a; --c5: #3d5a9e; --c6: #a3322b; --c7: #5f6b73;
  --shadow: 0 1px 0 rgba(31,36,51,.04), 0 6px 18px -12px rgba(31,36,51,.35);
  --f-display: "Newsreader", Georgia, "Times New Roman", serif;
  --f-body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1320; --surface: #151c2d; --surface2: #1c2540; --line: #2a3552;
    --text: #e9e5db; --muted: #a2a8ba; --accent: #e0a070; --accent-ink: #1a1208;
    --moon: #8ec3d6; --ok: #7fc79a; --warn: #e3b45a; --bad: #f08a80;
    --c0: #e0a070; --c1: #8ec3d6; --c2: #a3c97e; --c3: #c79ac0;
    --c4: #e3c35a; --c5: #8fa6e6; --c6: #f08a80; --c7: #a9b4bb;
    --shadow: 0 1px 0 rgba(0,0,0,.3), 0 8px 20px -12px rgba(0,0,0,.7);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1320; --surface: #151c2d; --surface2: #1c2540; --line: #2a3552;
  --text: #e9e5db; --muted: #a2a8ba; --accent: #e0a070; --accent-ink: #1a1208;
  --moon: #8ec3d6; --ok: #7fc79a; --warn: #e3b45a; --bad: #f08a80;
  --c0: #e0a070; --c1: #8ec3d6; --c2: #a3c97e; --c3: #c79ac0;
  --c4: #e3c35a; --c5: #8fa6e6; --c6: #f08a80; --c7: #a9b4bb;
  --shadow: 0 1px 0 rgba(0,0,0,.3), 0 8px 20px -12px rgba(0,0,0,.7);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 var(--f-body); overflow-x: hidden;
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--f-display); font-weight: 500; margin: 0; letter-spacing: .005em; }
h2 { font-size: 1.55rem; line-height: 1.2; }
h3 { font-size: 1.15rem; }
a { color: var(--moon); }
code, .mono { font-family: var(--f-mono); font-size: .86em; }
.muted { color: var(--muted); }
.boot { padding: 48px 16px; text-align: center; color: var(--muted); font-family: var(--f-display); font-style: italic; font-size: 1.2rem; }
:focus-visible { outline: 2px solid var(--moon); outline-offset: 2px; border-radius: 3px; }

/* ---------- shell ---------- */
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.topbar { position: sticky; top: 0; z-index: 20; background: var(--bg); border-bottom: 1px solid var(--line); }
.topbar .wrap { display: flex; align-items: center; gap: 12px; min-height: 56px; }
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; min-width: 0; }
.brand svg { width: 28px; height: 28px; flex: none; }
.brand .moon { fill: var(--accent); }
.brand .staff { stroke: var(--muted); stroke-width: 1; }
.brand-name { font-family: var(--f-display); font-style: italic; font-size: 1.5rem; line-height: 1; }
.brand-sub { font: 500 .68rem/1 var(--f-mono); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.who { font: .78rem var(--f-mono); color: var(--muted); max-width: 22ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: none; }
.badge { font: 500 .7rem/1 var(--f-mono); letter-spacing: .08em; text-transform: uppercase; padding: 5px 8px; border: 1px solid currentColor; border-radius: 3px; }
.badge.owner { color: var(--accent); } .badge.editor { color: var(--moon); }
.badge.viewer { color: var(--muted); } .badge.pending { color: var(--warn); }
.btn {
  border: 1px solid var(--line); background: var(--surface); padding: 8px 12px; border-radius: 4px;
  cursor: pointer; min-height: 38px; line-height: 1.2;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 32px; padding: 4px 9px; font-size: .86rem; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

.tabs { display: flex; gap: 2px; }
.tab {
  background: none; border: 0; border-bottom: 2px solid transparent; padding: 10px 14px;
  color: var(--muted); cursor: pointer; font-weight: 500;
}
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.tab:hover { color: var(--text); }
@media (max-width: 759px) {
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--surface);
    border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(5, 1fr); gap: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tab { padding: 13px 0 12px; font-size: .78rem; border-bottom: 0; border-top: 2px solid transparent; text-align: center; }
  .tab[aria-selected="true"] { border-top-color: var(--accent); }
  main.wrap { padding-bottom: 88px; }
}
@media (min-width: 760px) {
  .who { display: block; }
  .subbar { border-bottom: 1px solid var(--line); background: var(--bg); }
  .subbar .wrap { display: flex; }
}
main.wrap { padding-top: 20px; padding-bottom: 48px; }

/* page headings carry a faint stave: five lines, a nod to the song */
.page-head { margin-bottom: 18px; }
.kicker { font: 500 .7rem/1 var(--f-mono); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.stave {
  height: 14px; margin-top: 10px; opacity: .55;
  background: repeating-linear-gradient(to bottom, var(--line) 0 1px, transparent 1px 3.5px);
}

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.grid { display: grid; gap: 14px; }
.grid.stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.two { grid-template-columns: minmax(0, 1fr); }
.grid.cards { grid-template-columns: minmax(0, 1fr); }
@media (min-width: 760px) {
  .grid.stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.stat .n { font: 500 2rem/1.1 var(--f-display); }
.stat .l { font: .72rem var(--f-mono); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin-top: 4px; }
section.block { margin-top: 22px; }
section.block > h3 { margin-bottom: 10px; }

/* empty states */
.empty { border: 1px dashed var(--line); border-radius: 6px; padding: 28px 18px; text-align: center; color: var(--muted); background: transparent; }
.empty svg { width: 54px; height: 54px; margin-bottom: 8px; }
.empty svg .a { stroke: var(--muted); fill: none; stroke-width: 1.2; }
.empty svg .b { fill: var(--accent); opacity: .85; }
.empty h3 { color: var(--text); margin-bottom: 4px; }
.empty p { margin: 4px auto 0; max-width: 56ch; }

/* bars (overview) */
.bars { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: minmax(70px, 120px) 1fr auto; gap: 10px; align-items: center; }
.bar-row .lab { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row svg { width: 100%; height: 12px; display: block; }
.bar-row .track { fill: var(--surface2); }
.bar-row .fill { fill: var(--c0); } .bar-row .fill.t1 { fill: var(--c1); } .bar-row .fill.t2 { fill: var(--c2); }
.bar-row .fill.t3 { fill: var(--c3); } .bar-row .fill.t4 { fill: var(--c4); } .bar-row .fill.t5 { fill: var(--c5); }
.bar-row .fill.t6 { fill: var(--c6); } .bar-row .fill.t7 { fill: var(--c7); }
.bar-row .num { font-family: var(--f-mono); font-size: .85rem; min-width: 3ch; text-align: right; }

/* chips + lists */
.chip { display: inline-flex; align-items: center; gap: 6px; font: .74rem/1 var(--f-mono); padding: 4px 7px; border: 1px solid var(--line); border-radius: 3px; background: var(--surface2); white-space: nowrap; }
.chip i { width: 8px; height: 8px; border-radius: 50%; background: var(--c0); display: inline-block; }
.chip i.t1 { background: var(--c1); } .chip i.t2 { background: var(--c2); } .chip i.t3 { background: var(--c3); }
.chip i.t4 { background: var(--c4); } .chip i.t5 { background: var(--c5); } .chip i.t6 { background: var(--c6); } .chip i.t7 { background: var(--c7); }
button.chip { cursor: pointer; }
button.chip[aria-pressed="false"] { opacity: .5; }
.list { list-style: none; margin: 0; padding: 0; }
.list li + li { border-top: 1px solid var(--line); }
.row-btn {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; width: 100%; text-align: left; background: none; border: 0;
  padding: 10px 6px; cursor: pointer; border-radius: 4px; align-items: center;
}
.row-btn:hover, .row-btn[aria-current="true"] { background: var(--surface2); }
.row-btn .nm { font-weight: 500; overflow-wrap: anywhere; }
.row-btn .sub { grid-column: 1 / -1; font: .76rem var(--f-mono); color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- forms ---------- */
.field { display: grid; gap: 4px; margin-bottom: 12px; }
.field > label, .field > .lbl { font: 500 .72rem var(--f-mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.field .hint { font-size: .8rem; color: var(--muted); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], select, textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 9px 10px; min-height: 40px;
}
textarea { font-family: var(--f-mono); font-size: .86rem; min-height: 150px; resize: vertical; }
.filters { display: grid; gap: 8px; grid-template-columns: minmax(0, 1fr); margin-bottom: 12px; }
@media (min-width: 560px) { .filters.row { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.msg { padding: 10px 12px; border-radius: 4px; border: 1px solid var(--line); margin: 10px 0; font-size: .92rem; overflow-wrap: anywhere; }
.msg.err { border-color: var(--bad); color: var(--bad); }
.msg.ok { border-color: var(--ok); color: var(--ok); }
.msg.warn { border-color: var(--warn); color: var(--warn); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; margin-bottom: 14px; }
.seg button { border: 0; background: var(--surface); padding: 8px 14px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

/* auth */
.auth { max-width: 440px; margin: 0 auto; padding: 36px 16px 60px; }
.auth .brand-big { font: italic 500 2.8rem/1 var(--f-display); margin-bottom: 4px; }
.auth .tag { color: var(--muted); margin-bottom: 22px; }
.center-screen { max-width: 520px; margin: 0 auto; padding: 56px 16px; text-align: center; }
.center-screen h2 { margin: 10px 0; }

/* ---------- kv ---------- */
dl.kv { display: grid; grid-template-columns: minmax(70px, max-content) minmax(0, 1fr); gap: 3px 12px; margin: 0; }
dl.kv dt { font: .78rem var(--f-mono); color: var(--muted); overflow-wrap: anywhere; }
dl.kv dd { margin: 0; overflow-wrap: anywhere; min-width: 0; }
dl.kv dl.kv { padding-left: 10px; border-left: 1px solid var(--line); margin: 2px 0; }
.val { white-space: pre-wrap; }

/* ---------- knowledge ---------- */
.kn { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 900px) { .kn { grid-template-columns: minmax(280px, 360px) minmax(0, 1fr); align-items: start; } }
@media (max-width: 899px) {
  .kn.has-sel .kn-list { display: none; }
  .kn:not(.has-sel) .kn-detail { display: none; }
}
@media (min-width: 900px) { .back-only { display: none; } .kn-list { position: sticky; top: 72px; max-height: calc(100vh - 90px); overflow: auto; } }
.conf { display: inline-flex; align-items: center; gap: 6px; font: .76rem var(--f-mono); }
.conf svg { width: 44px; height: 6px; }
.conf .track { fill: var(--surface2); } .conf .fill { fill: var(--moon); }
.detail-head { display: flex; gap: 10px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; }
.detail-head h2 { overflow-wrap: anywhere; min-width: 0; }
.timeline { list-style: none; padding: 0; margin: 0; border-left: 2px solid var(--line); margin-left: 6px; }
.timeline li { padding: 0 0 14px 14px; position: relative; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 2px solid var(--accent); }
.timeline .when { font: .76rem var(--f-mono); color: var(--muted); }
details > summary { cursor: pointer; color: var(--moon); }
.rel-line { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; padding: 6px 0; border-top: 1px solid var(--line); }
.rel-line:first-child { border-top: 0; }
.rel-type { font: .76rem var(--f-mono); color: var(--accent); }
.link-btn { background: none; border: 0; padding: 0; color: var(--moon); cursor: pointer; text-align: left; text-decoration: underline; text-underline-offset: 3px; overflow-wrap: anywhere; }

dialog { border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); padding: 0; width: min(640px, calc(100vw - 24px)); max-height: calc(100vh - 24px); }
dialog::backdrop { background: rgba(8, 10, 18, .6); }
dialog form { padding: 18px 16px; }
dialog h3 { margin-bottom: 12px; }
.err-list { margin: 6px 0 0; padding-left: 18px; }

/* ---------- graph ---------- */
.graph-box { padding: 0; overflow: hidden; }
.graph-box svg { display: block; width: 100%; height: auto; max-height: 72vh; background: var(--bg); touch-action: manipulation; }
.graph-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.edge { stroke: var(--muted); stroke-opacity: .4; stroke-width: 1; }
.node { cursor: pointer; }
.node circle { stroke: var(--bg); stroke-width: 1.5; }
.node text { font: 11px var(--f-body); fill: var(--text); paint-order: stroke; stroke: var(--bg); stroke-width: 3px; stroke-linejoin: round; pointer-events: none; }
.node.t0 circle { fill: var(--c0); } .node.t1 circle { fill: var(--c1); } .node.t2 circle { fill: var(--c2); } .node.t3 circle { fill: var(--c3); }
.node.t4 circle { fill: var(--c4); } .node.t5 circle { fill: var(--c5); } .node.t6 circle { fill: var(--c6); } .node.t7 circle { fill: var(--c7); }
svg.dim .node:not(.hl) { opacity: .25; } svg.dim .edge:not(.hl) { stroke-opacity: .06; }
svg.dim .edge.hl { stroke-opacity: .9; stroke: var(--accent); stroke-width: 1.6; }
.node:focus-visible circle { stroke: var(--moon); stroke-width: 3; }

/* ---------- trading ---------- */
.paper {
  display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; padding: 10px 12px; margin-bottom: 16px;
  border: 1px solid var(--warn); border-left-width: 5px; border-radius: 4px; background: var(--surface);
}
.paper strong { font: 600 .78rem var(--f-mono); letter-spacing: .08em; text-transform: uppercase; color: var(--warn); }
.paper .sync { font-size: .88rem; }
.paper .sync.stale { color: var(--bad); font-weight: 600; }
.chart-card h3 { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; align-items: baseline; }
.readout { font: .8rem var(--f-mono); color: var(--muted); min-height: 1.4em; }
.chart svg { width: 100%; height: auto; display: block; touch-action: pan-y; }
.chart .grid-l { stroke: var(--line); stroke-width: 1; }
.chart .axis-t { font: 13px var(--f-mono); fill: var(--muted); }
.chart .line { fill: none; stroke: var(--c0); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--c0); opacity: .12; stroke: none; }
.chart .dot { fill: var(--c0); stroke: var(--bg); stroke-width: 2; }
.chart .cross { stroke: var(--muted); stroke-dasharray: 3 3; }
.chart.t1 .line, .chart.t1 .area, .chart.t1 .dot { stroke: var(--c1); } .chart.t1 .area, .chart.t1 .dot { fill: var(--c1); stroke: none; }
.chart.t2 .line { stroke: var(--c2); } .chart.t2 .area, .chart.t2 .dot { fill: var(--c2); }
.chart.t3 .line { stroke: var(--c3); } .chart.t3 .area, .chart.t3 .dot { fill: var(--c3); }
.chart.t4 .line { stroke: var(--c4); } .chart.t4 .area, .chart.t4 .dot { fill: var(--c4); }
.chart.t5 .line { stroke: var(--c5); } .chart.t5 .area, .chart.t5 .dot { fill: var(--c5); }
.chart .dot { stroke: var(--bg); stroke-width: 2; }
.up { color: var(--ok); } .down { color: var(--bad); }
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); max-width: 100%; }
table { border-collapse: collapse; width: 100%; font-size: .86rem; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font: 500 .7rem var(--f-mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); background: var(--surface2); position: sticky; top: 0; white-space: nowrap; }
td.num { text-align: right; font-family: var(--f-mono); white-space: nowrap; }
td.note { min-width: 180px; max-width: 360px; overflow-wrap: anywhere; }
td.ts { font-family: var(--f-mono); white-space: nowrap; }
.side { font: 600 .74rem var(--f-mono); letter-spacing: .06em; }
.side.buy { color: var(--ok); } .side.sell { color: var(--bad); }
.snap h3 { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.snap .when { font: .74rem var(--f-mono); color: var(--muted); }
.snap dl.kv { margin-top: 10px; }

#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: 84px; z-index: 60; pointer-events: none; display: grid; gap: 8px; width: min(440px, calc(100vw - 32px)); }
#toast .t { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 4px; font-size: .9rem; box-shadow: var(--shadow); overflow-wrap: anywhere; }
@media (min-width: 760px) { #toast { bottom: 24px; } }
@media (prefers-reduced-motion: no-preference) {
  .card, .empty { animation: rise .25s ease-out both; }
  @keyframes rise { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
}
