/* Morning Breakfast — layered on Pico CSS.
   LIGHT FIRST. You read this at 09:10 with the sun up; a bright, calm surface
   is easier on the eye than a dark one and makes the colour signals (green,
   amber, red) carry more weight because they sit against paper, not ink.

   Design goals, in priority order:
     1. Zero ambiguity. One glance = one decision.
     2. Hierarchy: symbol > gap > option > liquidity > detail.
     3. Fast. Text-node updates, contained layout, no animated shadows. */

:root {
  --pico-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --pico-border-radius: 12px;

  /* --- surfaces: warm off-white, not clinical grey --- */
  --bg: #fbfaf7;
  --surface: #ffffff;
  --surface-2: #f4f2ee;
  --hairline: #e6e2da;

  /* --- ink --- */
  --ink: #23201b;
  --ink-soft: #6f6960;

  /* --- signals: muted enough to live together, clear enough to read fast --- */
  --up: #1a7f4b;
  --up-bg: #e8f5ed;
  --down: #c4342f;
  --down-bg: #fbecea;
  --warn: #a86a00;
  --warn-bg: #fdf2e0;
  --info: #1f6bb8;
  --info-bg: #e9f1fa;
  --flat: #9a948a;

  --pico-background-color: var(--bg);
  --pico-color: var(--ink);
  --pico-muted-color: var(--ink-soft);
  --pico-card-background-color: var(--surface);
  --pico-muted-border-color: var(--hairline);
}

/* Dark is still available for anyone who forces it, but light is the default
   and the design target. */
[data-theme="dark"] {
  --bg: #0f1216;
  --surface: #171b21;
  --surface-2: #1e242c;
  --hairline: #2a313a;
  --ink: #e8e6e3;
  --ink-soft: #9aa0a8;
  --up: #4ade80; --up-bg: #12291d;
  --down: #f87171; --down-bg: #2b1717;
  --warn: #fbbf24; --warn-bg: #2a2113;
  --info: #60a5fa; --info-bg: #14212f;
  --flat: #6b7280;
}

* { -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  font-size: 15px;
  background: var(--bg);
  color: var(--ink);
  padding-bottom: env(safe-area-inset-bottom);
  overflow-x: hidden;
  /* Fill the viewport so a short page does not leave a bright unpainted
     block below the footer. */
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main.wrap { flex: 1 0 auto; }
.footer { flex: 0 0 auto; }

/* ============ top bar ============ */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--hairline);
  padding: calc(0.6rem + env(safe-area-inset-top)) 1rem 0.55rem;
}
.topbar-row { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.brand { display: flex; align-items: center; gap: .55rem; font-size: 1rem; letter-spacing: -.01em; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--flat); flex: 0 0 auto; }
.dot.live { background: var(--up); box-shadow: 0 0 0 3px var(--up-bg); }
.dot.stale { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-bg); }
.dot.dead { background: var(--down); box-shadow: 0 0 0 3px var(--down-bg); }

.clock {
  font-variant-numeric: tabular-nums;
  font-weight: 600; font-size: 1.05rem; letter-spacing: -.01em;
  color: var(--ink);
}

/* phase track — the label sits BELOW the rail in its own reserved band, so it
   can never collide with the status line underneath it. */
.track {
  display: flex; gap: 3px;
  margin: .7rem 0 .35rem; padding-bottom: 15px;  /* reserved label band */
}
.seg { flex: 1; height: 3px; border-radius: 2px; background: var(--hairline); position: relative; }
.seg.done { background: var(--up); opacity: .45; }
.seg.now { background: var(--info); }
.seg .lbl {
  position: absolute; top: 6px; left: 50%; transform: translateX(-50%);
  font-size: 9px; letter-spacing: .04em; text-transform: uppercase;
  color: var(--ink-soft); white-space: nowrap; opacity: 0;
}
.seg.now .lbl { opacity: 1; color: var(--info); font-weight: 700; }
/* Keep the first and last labels inside the viewport rather than centred
   off the edge. */
.seg:first-child .lbl { left: 0; transform: none; }
.seg:last-child .lbl { left: auto; right: 0; transform: none; }

.meta-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: .6rem; font-size: 11px; color: var(--ink-soft);
}
.meta-row + .meta-row { margin-top: .35rem; }
#status { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.feed {
  font-size: 10px; font-weight: 700; letter-spacing: .03em;
  padding: 2px 8px; border-radius: 20px;
  border: 1px solid var(--hairline); white-space: nowrap; color: var(--ink-soft);
}
.feed.on { color: var(--up); background: var(--up-bg); border-color: transparent; }
.feed.err { color: var(--down); background: var(--down-bg); border-color: transparent; }

.token.warn { color: var(--warn); font-weight: 600; }
.token.bad { color: var(--down); font-weight: 600; }

.hdr-links { display: flex; gap: .7rem; align-items: center; flex: 0 0 auto; }
.hdr-links a {
  font-size: 11px; color: var(--ink-soft); text-decoration: none;
  border-bottom: 1px solid var(--hairline);
}
.hdr-links a:hover { color: var(--info); border-bottom-color: var(--info); }

/* call to action when the token is missing */
.cta {
  display: block; margin-top: .6rem; padding: .55rem .8rem;
  background: var(--info-bg); color: var(--info);
  border-radius: 9px; font-size: .82rem; font-weight: 600;
  text-decoration: none; text-align: center;
}
.cta:hover { filter: brightness(.97); }

/* ============ tabs ============ */
.tabbar {
  position: sticky; top: var(--top-h, 120px); z-index: 19;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--surface); border-bottom: 1px solid var(--hairline);
}
.tabbtn {
  all: unset; text-align: center; padding: .78rem .3rem;
  font-size: .84rem; font-weight: 600; color: var(--ink-soft);
  cursor: pointer; border-bottom: 2px solid transparent;
}
.tabbtn.is-active { color: var(--ink); border-bottom-color: var(--info); }
.count {
  display: inline-block; min-width: 1.2rem; padding: 0 .35rem;
  border-radius: 20px; background: var(--surface-2); color: var(--ink-soft);
  font-size: .7rem; font-variant-numeric: tabular-nums;
}
.tabbtn.is-active .count { background: var(--info-bg); color: var(--info); }

/* ============ filters ============ */
.filterbar { display: flex; gap: .4rem; padding: .7rem 1rem .25rem; flex-wrap: wrap; }
.chip {
  all: unset; padding: .3rem .68rem; border-radius: 20px; cursor: pointer;
  font-size: .71rem; font-weight: 600; letter-spacing: .01em;
  border: 1px solid var(--hairline); color: var(--ink-soft); background: var(--surface);
}
.chip.is-on { color: var(--ink); border-color: var(--info); background: var(--info-bg); }
.chip.is-on[data-tag="GOOD"] { color: var(--up); background: var(--up-bg); border-color: transparent; }
.chip.is-on[data-tag="THIN"] { color: var(--warn); background: var(--warn-bg); border-color: transparent; }
.chip.is-on[data-tag="ILLIQUID"] { color: var(--down); background: var(--down-bg); border-color: transparent; }

/* ============ layout ============ */
.wrap { padding: .6rem 1rem 2rem; max-width: 1500px; margin: 0 auto; }
.pane { display: none; }
.pane.is-active { display: block; }
.deck { display: grid; gap: .65rem; }

/* ============ card ============ */
.card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-left: 3px solid var(--flat);
  border-radius: var(--pico-border-radius);
  padding: .8rem .85rem;
  contain: content;
}
.card.g-HIGH { border-left-color: var(--up); }
.card.g-MEDIUM { border-left-color: var(--warn); }
.card.g-LOW { border-left-color: var(--hairline); }

.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: .5rem; }
.sym { font-size: 1.08rem; font-weight: 700; letter-spacing: -.01em; }
.gap { font-size: 1.08rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.gap.up { color: var(--up); } .gap.down { color: var(--down); }

.badges { display: flex; gap: .32rem; flex-wrap: wrap; margin-top: .5rem; }
.b {
  font-size: 9.5px; font-weight: 700; letter-spacing: .04em;
  padding: 3px 7px; border-radius: 5px; text-transform: uppercase;
  background: var(--surface-2); color: var(--ink-soft);
}
.b-grade.HIGH { color: var(--up); background: var(--up-bg); }
.b-grade.MEDIUM { color: var(--warn); background: var(--warn-bg); }
.b-CE { color: var(--info); background: var(--info-bg); }
.b-PE { color: #7c4dbe; background: #f1ebfa; }
.b-GOOD { color: var(--up); background: var(--up-bg); }
.b-THIN { color: var(--warn); background: var(--warn-bg); }
.b-ILLIQUID { color: var(--down); background: var(--down-bg); }
.b-live { color: var(--up); background: var(--up-bg); }

[data-theme="dark"] .b-PE { color: #c4a3f5; background: #241a33; }

/* metric grid */
.metrics {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .4rem; margin-top: .65rem;
}
.m { background: var(--surface-2); border-radius: 8px; padding: .38rem .5rem; min-width: 0; }
.m .k {
  display: block; font-size: 8.5px; letter-spacing: .06em;
  text-transform: uppercase; color: var(--ink-soft);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.m .v {
  display: block; font-size: .86rem; font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.v.good { color: var(--up); } .v.warn { color: var(--warn); } .v.bad { color: var(--down); }
.v.flash { animation: flash .5s ease-out; }
@keyframes flash { from { background: var(--info-bg); } to { background: transparent; } }

/* bid/ask row */
.book {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: .5rem; margin-top: .4rem;
  background: var(--surface-2); border-radius: 8px; padding: .38rem .6rem;
}
.book .k { font-size: 8.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-soft); }
.bidask { font-variant-numeric: tabular-nums; font-size: .86rem; }
.bidask b { font-weight: 600; }
.bidask i { color: var(--ink-soft); font-style: normal; padding: 0 .2rem; }

/* score meter */
.meter { display: flex; align-items: center; gap: .55rem; margin-top: .6rem; }
.meter-rail { flex: 1; height: 4px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.meter-fill { height: 100%; border-radius: 3px; background: var(--info); transform-origin: left; transition: transform .25s ease; }
.meter-val { font-size: .72rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; }

.parts { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .45rem; font-size: 9.5px; color: var(--ink-soft); }
.parts b { font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }

.notes { margin-top: .5rem; font-size: 11px; color: var(--ink-soft); line-height: 1.55; }
.notes div::before { content: "› "; color: var(--warn); font-weight: 700; }

/* ============ live / observe ============ */
.state-strip {
  display: flex; align-items: center; gap: .4rem;
  margin-top: .55rem; padding: .4rem .6rem; border-radius: 8px;
  background: var(--surface-2); color: var(--ink-soft);
  font-size: .76rem; font-weight: 700; letter-spacing: .01em;
}
.state-strip.up { color: var(--up); background: var(--up-bg); }
.state-strip.down { color: var(--down); background: var(--down-bg); }

.range { margin-top: .6rem; }
.range-rail { position: relative; height: 22px; border-radius: 7px; background: var(--surface-2); overflow: hidden; }
.range-band { position: absolute; top: 0; bottom: 0; background: var(--info-bg); }
.range-mark { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--ink); }
.range-mark.up { background: var(--up); } .range-mark.down { background: var(--down); }
.range-lbl { display: flex; justify-content: space-between; font-size: 9px; color: var(--ink-soft); margin-top: .25rem; font-variant-numeric: tabular-nums; }

.spark { display: flex; align-items: flex-end; gap: 1px; height: 30px; margin-top: .55rem; }
.spark i { flex: 1 1 0; min-width: 0; background: var(--info); border-radius: 1px; opacity: .55; }
.spark i.up { background: var(--up); opacity: .8; }
.spark i.down { background: var(--down); opacity: .8; }

.empty { text-align: center; padding: 3rem 1rem; color: var(--ink-soft); font-size: .85rem; line-height: 1.8; }

.footer { padding: 1.2rem 1rem 2.2rem; text-align: center; display: flex; flex-direction: column; gap: .3rem; }
.footer small { font-size: 10px; color: var(--ink-soft); }
.muted { opacity: .75; }

/* ============ auth pages ============ */
.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1rem; background: var(--bg); }
.auth-wrap { width: 100%; max-width: 440px; }
.auth-card { background: var(--surface); border: 1px solid var(--hairline); border-radius: 16px; padding: 1.8rem 1.5rem; }
.auth-card h1 { font-size: 1.2rem; margin: 0 0 .25rem; letter-spacing: -.015em; }
.auth-sub { font-size: .79rem; color: var(--ink-soft); line-height: 1.65; margin: .5rem 0 1.1rem; }
.auth-card label { font-size: .79rem; font-weight: 600; }
.auth-card input, .auth-card textarea { margin-top: .3rem; margin-bottom: .95rem; font-size: .9rem; }
.auth-card textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .75rem; resize: vertical; }
.auth-card button { width: 100%; margin-top: .2rem; }
.auth-err { background: var(--down-bg); color: var(--down); border-radius: 9px; padding: .6rem .75rem; font-size: .81rem; font-weight: 600; margin: 0 0 1rem; }
.auth-ok { background: var(--up-bg); color: var(--up); border-radius: 9px; padding: .6rem .75rem; font-size: .81rem; font-weight: 600; margin: 0 0 1rem; }
.auth-card a { color: var(--info); }

/* ============ wider screens ============ */
/* Metric cells stay 3-up at every width: a 4th column truncates prices, and
   the number IS the content. Wider viewports get more CARDS per row instead. */
@media (min-width: 700px) { .deck { grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); } }
@media (min-width: 1250px) { .deck { grid-template-columns: repeat(auto-fill, minmax(390px, 1fr)); } }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
