:root {
  color-scheme: light;
  --page:       #f9f9f7;
  --surface:    #fcfcfb;
  --ink:        #0b0b0b;
  --ink-2:      #52514e;
  --muted:      #898781;
  --grid:       #e1e0d9;
  --baseline:   #c3c2b7;
  --border:     rgba(11,11,11,0.10);
  --series-1:   #2a78d6;
  --pl-up:      #006300;
  --pl-down:    #d03b3b;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page:     #0d0d0d;
    --surface:  #1a1a19;
    --ink:      #ffffff;
    --ink-2:    #c3c2b7;
    --muted:    #898781;
    --grid:     #2c2c2a;
    --baseline: #383835;
    --border:   rgba(255,255,255,0.10);
    --series-1: #3987e5;
    --pl-up:    #0ca30c;
    --pl-down:  #e66767;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--ink);
}

/* ---- navigation ---- */
.nav {
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  padding: 0 24px; min-height: 52px;   /* min-, not fixed: wrapping must not clip */
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.nav .brand {
  font-size: 14px; font-weight: 700; letter-spacing: -0.2px;
  color: var(--ink); text-decoration: none; white-space: nowrap;
}
.navlinks { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; min-width: 0; }
.navlinks a {
  font-size: 13px; color: var(--ink-2); text-decoration: none;
  padding: 6px 11px; border-radius: 7px;
}
.navlinks a:hover { background: var(--page); color: var(--ink); }
.navlinks a.active { color: var(--series-1); font-weight: 600; }
.navright { display: flex; align-items: center; gap: 12px; }
.navnote { font-size: 11px; color: var(--muted); white-space: nowrap; }
.market {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--ink-2); white-space: nowrap;
  border: 1px solid var(--border); border-radius: 7px; padding: 5px 10px;
}
.market .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); flex: none; }
.market.open { color: var(--pl-up); border-color: var(--pl-up); }
.market.open .dot { background: var(--pl-up); animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) { .market.open .dot { animation: none; } }
.tzpick { position: relative; display: inline-flex; align-items: center; }
.tzpick > span {
  font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums;
  border: 1px solid var(--border); border-radius: 7px; padding: 5px 22px 5px 9px;
  white-space: nowrap;
}
.tzpick select {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; cursor: pointer; font-size: 13px;
}
.tzpick:hover > span { border-color: var(--series-1); color: var(--series-1); }
.tzpick::after {
  content: ''; position: absolute; right: 9px; pointer-events: none;
  border-left: 3.5px solid transparent; border-right: 3.5px solid transparent;
  border-top: 4px solid var(--muted);
}

.page { padding: 22px 24px 32px; }
h1 { font-size: 18px; margin: 0 0 4px; }
.sub { color: var(--ink-2); font-size: 13px; margin-bottom: 18px; }
.sub a, .card h2 a { color: var(--series-1); text-decoration: none; }
.sub a:hover, .card h2 a:hover { text-decoration: underline; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 20px; }
.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}
.tile .label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.tile .value { font-size: 22px; font-weight: 600; }
.tile .value.up   { color: var(--pl-up); }
.tile .value.down { color: var(--pl-down); }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 20px;
}
.card h2 { font-size: 14px; margin: 0 0 12px; color: var(--ink-2); font-weight: 600; }
.chart-wrap { position: relative; }
#equity-chart { display: block; width: 100%; height: 260px; }
#equity-chart:focus { outline: 2px solid var(--series-1); outline-offset: 2px; }
.chart { display: block; width: 100%; height: 220px; }
.chart:focus { outline: 2px solid var(--series-1); outline-offset: 2px; }
#pl-chart { display: block; width: 100%; height: 240px; }
#pl-chart:focus { outline: 2px solid var(--series-1); outline-offset: 2px; }
.rangebar { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }
.rangebar a {
  padding: 6px 13px; border: 1px solid var(--border); border-radius: 8px;
  color: var(--ink-2); text-decoration: none; font-size: 13px;
}
.rangebar a:hover { background: var(--surface); }
.rangebar a.active { background: var(--series-1); color: #fff; border-color: var(--series-1); }
.rangeform { display: flex; gap: 6px; align-items: center; margin-left: 6px; font-size: 13px; color: var(--muted); }
.rangeform input {
  background: var(--surface); color: var(--ink); border: 1px solid var(--baseline);
  border-radius: 8px; padding: 5px 8px; font-size: 13px; font-family: inherit;
}
.rangeform button {
  background: var(--surface); color: var(--ink-2); border: 1px solid var(--baseline);
  border-radius: 8px; padding: 6px 12px; font-size: 13px; cursor: pointer; font-family: inherit;
}
.rangeform button:hover { border-color: var(--series-1); color: var(--series-1); }
.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  display: none;
  white-space: nowrap;
}
.tooltip .val { font-weight: 600; font-size: 14px; }
.tooltip .when { color: var(--ink-2); margin-top: 2px; }
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th {
  text-align: left; color: var(--muted); font-weight: 500;
  border-bottom: 1px solid var(--baseline); padding: 6px 10px;
}
td { padding: 6px 10px; border-bottom: 1px solid var(--grid); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.up   { color: var(--pl-up); }
td.down { color: var(--pl-down); }
.side-buy  { color: var(--pl-up); font-weight: 600; }
.side-sell { color: var(--pl-down); font-weight: 600; }
.empty { color: var(--muted); font-size: 13px; padding: 12px 0; }
.footnote { color: var(--muted); font-size: 12px; margin: -8px 0 20px; }
.notice {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 16px; color: var(--ink-2);
}
.filters { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.filters input, .filters select {
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--baseline); border-radius: 8px;
  padding: 7px 10px; font-size: 13px; font-family: inherit;
}
.filters button {
  background: var(--series-1); color: #fff; border: none;
  border-radius: 8px; padding: 8px 14px; font-size: 13px; cursor: pointer;
}
.pager { display: flex; gap: 12px; align-items: center; margin-top: 14px; font-size: 13px; color: var(--ink-2); }
.pager a {
  color: var(--series-1); text-decoration: none;
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px;
}
.pager a:hover { background: var(--page); }
.pager .disabled { color: var(--muted); border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px; }
.article { max-width: 780px; }
.kicker { text-transform: uppercase; font-size: 11px; letter-spacing: 1.2px; font-weight: 600; margin-bottom: 8px; }
.kicker.up   { color: var(--pl-up); }
.kicker.down { color: var(--pl-down); }
.kicker.flat { color: var(--series-1); }
.headline { font-size: 26px; font-weight: 700; margin: 0 0 6px; line-height: 1.25; }
.byline { color: var(--muted); font-size: 12px; margin-bottom: 18px; }
.article p { font-size: 14px; line-height: 1.7; margin: 0 0 14px; }
.statgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin: 18px 0; }
.stat { background: var(--page); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.stat .label { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.stat .value { font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat .value.up   { color: var(--pl-up); }
.stat .value.down { color: var(--pl-down); }
.readlink { color: var(--series-1); text-decoration: none; }
.readlink:hover { text-decoration: underline; }

/* ---------- phones and small tablets ---------- */
@media (max-width: 720px) {
  /* Two rows: brand + status/timezone on top, page links underneath.
     The links row scrolls sideways rather than wrapping into a tall
     sticky bar that eats the screen. */
  .nav { padding: 8px 14px; gap: 8px 10px; }
  .nav .brand { font-size: 15px; }
  .navright { margin-left: auto; gap: 8px; }
  .navnote { display: none; }              /* "auto-refresh 2m" is noise here */
  .mnext { display: none; }                /* just Open/Closed, not the next-open time */

  .navlinks {
    order: 3; flex-basis: 100%; flex-wrap: nowrap;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    scrollbar-width: none; margin: 0 -14px; padding: 0 14px 2px;
  }
  .navlinks::-webkit-scrollbar { display: none; }
  .navlinks a { padding: 5px 10px; white-space: nowrap; }

  .page { padding: 16px 14px 28px; }
  h1 { font-size: 17px; }
  .tiles { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
  .tile { padding: 11px 12px; }
  .tile .value { font-size: 19px; }
  .card { padding: 13px; margin-bottom: 14px; }

  /* the timeframe buttons need to stay tappable but stop hogging rows */
  .rangebar { gap: 5px; }
  .rangebar a { padding: 6px 10px; font-size: 12px; }
  .rangeform { margin-left: 0; flex-basis: 100%; }
  .rangeform input { flex: 1; min-width: 0; }

  .headline { font-size: 21px; }
  table { font-size: 12px; }
  th, td { padding: 6px 8px; }
  #equity-chart { height: 210px; }
  #pl-chart { height: 200px; }
  .chart { height: 190px; }
}

@media (max-width: 380px) {
  .mlabel { display: none; }               /* badge shrinks to "open" / "closed" */
  .nav { gap: 6px 8px; }
}
