/* Palette roles. Dark values are declared under both the OS media query and the
   [data-theme] scope so the in-page toggle wins in either direction. */
:root {
  color-scheme: light;
  --plane:        #f9f9f7;
  --surface:      #fcfcfb;
  --text:         #0b0b0b;
  --text-2:       #52514e;
  --muted:        #898781;
  --hairline:     #e1e0d9;
  --border:       rgba(11, 11, 11, 0.10);
  --up:           #006300;
  --down:         #d03b3b;
  --warning:      #ec835a;
  --accent:       #2a78d6;
  --hover:        rgba(11, 11, 11, 0.04);

  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --plane:      #0d0d0d;
    --surface:    #1a1a19;
    --text:       #ffffff;
    --text-2:     #c3c2b7;
    --muted:      #898781;
    --hairline:   #2c2c2a;
    --border:     rgba(255, 255, 255, 0.10);
    --up:         #0ca30c;
    --down:       #e66767;
    --warning:    #ec835a;
    --accent:     #3987e5;
    --hover:      rgba(255, 255, 255, 0.05);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --plane:      #0d0d0d;
  --surface:    #1a1a19;
  --text:       #ffffff;
  --text-2:     #c3c2b7;
  --muted:      #898781;
  --hairline:   #2c2c2a;
  --border:     rgba(255, 255, 255, 0.10);
  --up:         #0ca30c;
  --down:       #e66767;
  --warning:    #ec835a;
  --accent:     #3987e5;
  --hover:      rgba(255, 255, 255, 0.05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--plane);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px max(16px, env(safe-area-inset-left)) 10px;
  max-width: 1100px;
  margin: 0 auto;
}

.topbar h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.topbar-meta {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
}

.status {
  font-size: 12.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
}

.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn:active { transform: translateY(1px); }

.icon-btn svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- tabs ---------- */

.tabs {
  display: flex;
  gap: 6px;
  padding: 0 max(16px, env(safe-area-inset-left)) 12px;
  max-width: 1100px;
  margin: 0 auto;
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar { display: none; }

.tab {
  flex: 0 0 auto;
  padding: 7px 14px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-size: 14px;
  font-weight: 550;
  cursor: pointer;
}

.tab:hover { background: var(--hover); }

.tab[aria-selected="true"] {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

/* ---------- layout ---------- */

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 max(16px, env(safe-area-inset-left)) max(32px, env(safe-area-inset-bottom));
  outline: none;
}

.group { margin-bottom: 22px; }

.group-title {
  margin: 0 0 8px;
  padding-left: 2px;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.empty, .error-banner {
  padding: 14px 16px;
  color: var(--text-2);
  font-size: 14px;
}

.error-banner {
  border: 1px solid var(--border);
  border-left: 3px solid var(--warning);
  border-radius: var(--radius);
  background: var(--surface);
  margin-bottom: 16px;
}

/* ---------- quote rows ---------- */

.row {
  display: grid;
  align-items: center;
  gap: 4px 12px;
  padding: 11px 14px;
  border-top: 1px solid var(--hairline);
  grid-template-columns: minmax(0, 1fr) 92px 108px 104px 104px;
  grid-template-areas: "name spark price day ytd";
}

.row:first-child, .row.head + .row { border-top: none; }

.row.head {
  padding-top: 9px;
  padding-bottom: 7px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.row.stale { opacity: 0.55; }

.r-name  { grid-area: name; min-width: 0; }
.r-spark { grid-area: spark; }
.r-price { grid-area: price; text-align: right; }
.r-day   { grid-area: day;   text-align: right; }
.r-ytd   { grid-area: ytd;   text-align: right; }

.name {
  font-weight: 550;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* The link carries the row's identity, so it stays ink-coloured and only
   announces itself on hover and focus. */
.name-link {
  color: inherit;
  border-radius: 3px;
  /* A quiet underline rather than none: on touch there is no hover to reveal
     the affordance, so the link has to look like one at rest. */
  text-decoration: underline;
  text-decoration-color: var(--muted);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.name-link:hover {
  color: var(--accent);
  text-decoration-color: currentColor;
}

.name-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sub {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.price {
  font-variant-numeric: tabular-nums;
  font-weight: 550;
  white-space: nowrap;
}

.ccy {
  font-size: 11px;
  color: var(--muted);
  margin-left: 3px;
}

.delta {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  font-weight: 550;
}

.delta .abs {
  display: block;
  font-size: 11.5px;
  font-weight: 450;
  color: var(--muted);
}

.up   { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--text-2); }

/* The arrow is the redundant channel, so sign never rests on color alone. */
.arrow { font-size: 10px; margin-right: 2px; }

.na { color: var(--muted); font-size: 12.5px; }

.cap { display: none; }

.badge {
  display: inline-block;
  margin-left: 6px;
  padding: 0 5px;
  border-radius: 5px;
  border: 1px solid var(--border);
  color: var(--warning);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.03em;
  cursor: help;
  vertical-align: 1px;
}

/* ---------- sparkline ---------- */

.spark { display: block; width: 92px; height: 26px; overflow: visible; }
.spark .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.spark .base { stroke: var(--hairline); stroke-width: 1; stroke-dasharray: 2 3; }

/* ---------- mobile ---------- */

@media (max-width: 640px) {
  body { font-size: 15px; }

  /* Fixed track widths, not auto: each row is its own grid, so auto tracks
     would size per row and the numbers would not line up down the card. */
  .row {
    grid-template-columns: minmax(0, 1fr) 76px 108px;
    grid-template-areas:
      "name  name price"
      "spark day  ytd";
    gap: 6px 10px;
    padding: 12px 14px;
  }

  .row.head { display: none; }
  .row:first-child { border-top: none; }

  .r-day, .r-ytd { text-align: right; }
  .r-spark { align-self: end; }

  .cap {
    display: block;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--muted);
  }

  .delta .abs { display: none; }
  .spark { width: 76px; height: 24px; }
  .topbar h1 { font-size: 16px; }
}
