:root {
  /* "paper white": reads as white until it sits next to true #fff/#000 */
  --bg: #fafaf7;
  --box: #ffffff;
  --ink: #14181d;
  --ink-2: #59626d;
  --ink-3: #99a1ab;
  --rule: #e6e9ed;
  --rule-strong: #14181d;
  --accent: #2158a8;
  --serif: "New York", ui-serif, Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", sans-serif;
  --pad: clamp(16px, 4.5vw, 28px);
  --measure: 680px; /* reading width (reader overlay) */
  --page: 680px;    /* app frame width; widens on desktop */
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101214;
    --box: #191c1f;
    --ink: #e7e9ec;
    --ink-2: #a2a9b1;
    --ink-3: #6d7580;
    --rule: #2a2e33;
    --rule-strong: #e7e9ec;
    --accent: #7cb0f5;
  }
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body.reader-open { overflow: hidden; }

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
a { color: inherit; }

/* ---------- Masthead ---------- */
.masthead {
  max-width: var(--page);
  margin: 0 auto;
  padding: 16px var(--pad) 0;
  border-bottom: 1px solid var(--rule);
}

.masthead-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.wordmark {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 19px;
  letter-spacing: -0.2px;
  text-decoration: none;
  white-space: nowrap;
}

.masthead-controls {
  display: flex;
  align-items: center;
  gap: 4px;
}

.date-nav {
  display: flex;
  align-items: center;
  font-size: 12px;
  color: var(--ink-2);
  white-space: nowrap;
}

.tab-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.rate-strip {
  display: flex;
  gap: 12px;
  font-size: 11px;
  color: var(--ink-2);
  text-decoration: none;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  padding-bottom: 4px;
}

.rate-strip.off { display: none; }
.rate-strip:hover { color: var(--accent); }
.rate-strip .rs-item b { font-weight: 700; color: var(--ink-3); margin-right: 3px; font-size: 10px; }
.rs-val.up { color: #1e8e3e; font-weight: 700; }
.rs-val.down { color: #d23f31; font-weight: 700; }

@media (prefers-color-scheme: dark) {
  .rs-val.up { color: #5bd07f; }
  .rs-val.down { color: #ff7b6e; }
}

/* On narrow screens the strip becomes its own slim data bar under the tabs */
@media (max-width: 700px) {
  .tab-row { flex-direction: column; align-items: stretch; gap: 0; }
  .rate-strip {
    justify-content: space-between;
    gap: 0;
    border-top: 1px solid var(--rule);
    padding: 8px 0;
    font-size: 11.5px;
  }
}

#toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  font-size: 12px;
  padding: 7px 15px;
  border-radius: 99px;
  z-index: 600;
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
  white-space: nowrap;
}

#toast.show { opacity: 1; }

.date-nav.off { visibility: hidden; }

#current-date { min-width: 84px; text-align: center; font-variant-numeric: tabular-nums; }

.nav-arrow { font-size: 18px; line-height: 1; color: var(--ink-2); padding: 8px 10px; margin: -6px 0; }
.nav-arrow:hover:not(:disabled) { color: var(--accent); }
.nav-arrow:disabled { opacity: 0.25; cursor: default; }

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 22px;
  margin-top: 10px;
}

.tabs a {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--ink-3);
  padding: 6px 0 9px;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tabs a.active { color: var(--ink); border-bottom-color: var(--accent); }
.tabs a:hover { color: var(--ink); }

/* ---------- Layout ---------- */
main {
  max-width: var(--page);
  margin: 0 auto;
  padding: 20px var(--pad) 60px;
}

.story-group {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

/* ---------- Lede ---------- */
#lede { font-size: 14.5px; line-height: 1.55; }

#key-points {
  list-style: none;
  margin-top: 12px;
  border-top: 1px solid var(--rule);
}

#key-points li {
  position: relative;
  padding: 7px 0 7px 16px;
  border-bottom: 1px solid var(--rule);
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--ink-2);
}

#key-points li::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 13px;
  width: 5px;
  height: 5px;
  background: var(--accent);
}

/* ---------- Feed ---------- */
.section-head {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 1.8px;
  text-transform: uppercase;
  color: var(--ink-3);
  margin: 24px 0 8px;
}

.section-head:first-child { margin-top: 20px; }

.story {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--box);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 13px 15px;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.12s ease;
}

.story h3 {
  font-weight: 600;
  font-size: 14.5px;
  line-height: 1.35;
  letter-spacing: -0.1px;
}

.story.lead h3 { font-size: 16px; }

.story p {
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--ink-2);
  margin-top: 4px;
}

/* ---------- Chips (taxonomy tags) ---------- */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 9px;
}

.chip {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 600;
  line-height: 1;
  color: var(--ink-2);
  border: 1px solid var(--rule);
  border-radius: 99px;
  padding: 4px 8px;
  white-space: nowrap;
}

.chip-value {
  color: var(--ink);
  border-color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

/* ---------- Controls (filter + group bar) ---------- */
.controls {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--rule);
}

.type-chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.type-chips::-webkit-scrollbar { display: none; }

.chip-filter {
  cursor: pointer;
  background: var(--box);
  transition: border-color 0.1s ease;
  padding: 6px 10px;
  font-size: 11px;
}

.chip-filter:hover { border-color: var(--ink-3); }
.chip-filter.on { color: #fff; }
.chip-filter.dim { opacity: 0.4; }

.ctl-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.ctl-select {
  font: inherit;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink-2);
  background: var(--box);
  border: 1px solid var(--rule);
  border-radius: 99px;
  padding: 5px 8px;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.ctl-clear {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--accent);
  padding: 5px 6px;
}

.ctl-tally {
  margin-left: auto;
  font-size: 11px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

.story .meta {
  margin-top: 8px;
  font-size: 9.5px;
  letter-spacing: 1.1px;
  text-transform: uppercase;
  color: var(--ink-3);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}

.story .meta .cadence { color: var(--accent); font-weight: 700; }

.story .meta-open { color: var(--accent); font-weight: 700; white-space: nowrap; }

.story .meta-source {
  color: var(--ink-3);
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  padding: 4px 0 4px 8px; /* generous tap target */
}

.story .meta-source:hover { color: var(--accent); }

.story.static { cursor: default; }

@media (hover: hover) {
  .story:not(.static):hover { border-color: var(--ink-3); }
  .story:not(.static):hover h3 { color: var(--accent); }
}

.story:not(.static):active h3 { color: var(--accent); }

/* ---------- Notes / colophon ---------- */
#day-notes {
  margin-top: 24px;
  font-size: 12px;
  font-style: italic;
  color: var(--ink-2);
}

.colophon {
  margin-top: 24px;
  padding-top: 10px;
  border-top: 1px solid var(--rule);
  font-size: 11px;
  color: var(--ink-3);
}

#empty-state { font-style: italic; color: var(--ink-2); padding: 50px 0; text-align: center; }

/* ---------- Map ---------- */
.map-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.map-title { font-size: 12.5px; color: var(--ink-2); }

.map-toggle {
  display: flex;
  border: 1px solid var(--rule);
  border-radius: 6px;
  overflow: hidden;
}

.map-toggle button {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.4px;
  padding: 5px 11px;
  color: var(--ink-3);
  background: var(--box);
}

.map-toggle button.on { background: var(--ink); color: var(--bg); }

#map-canvas {
  height: min(62vh, 560px);
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--box);
  z-index: 1;
}

.map-hint { margin-top: 8px; font-size: 11px; color: var(--ink-3); }

.map-legend {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  margin-bottom: 10px;
  padding-bottom: 4px;
  scrollbar-width: none;
}

.map-legend::-webkit-scrollbar { display: none; }

.emoji-pin-wrap { background: none; border: none; }

.emoji-pin {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--box);
  border: 2.5px solid var(--ink-3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  line-height: 1;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}

.map-popup h4 { font-size: 12.5px; line-height: 1.3; margin: 0; cursor: pointer; }
.map-popup h4:hover { color: var(--accent); }
.map-popup .pop-meta { font-size: 10px; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.8px; margin-top: 4px; }
.map-popup .pop-loc { font-size: 11px; color: var(--ink-2); margin-top: 3px; }

.leaflet-container { font-family: var(--sans); }
.leaflet-popup-content-wrapper { background: var(--box); color: var(--ink); border-radius: 8px; }
.leaflet-popup-tip { background: var(--box); }

@media (prefers-color-scheme: dark) {
  .leaflet-control-attribution { background: rgba(16,18,20,0.7) !important; color: var(--ink-3) !important; }
}

/* ---------- Rates ---------- */
.rate-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 8px;
}

.rate-tile {
  background: var(--box);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 14px 16px;
}

.rt-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--ink-3);
}

.rt-value {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}

.rt-sub { font-size: 10.5px; color: var(--ink-3); margin-top: 2px; }

.rate-tile.clickable { cursor: pointer; transition: border-color 0.12s ease; }
.rate-tile.clickable:hover { border-color: var(--ink-3); }
.rate-tile.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

.rt-chg {
  font-size: 10.5px;
  font-weight: 700;
  margin-top: 3px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.rt-chg.up { color: #1e8e3e; }
.rt-chg.down { color: #d23f31; }
.rt-chg .rt-pct { font-weight: 600; color: var(--ink-3); }

@media (prefers-color-scheme: dark) {
  .rt-chg.up { color: #5bd07f; }
  .rt-chg.down { color: #ff7b6e; }
}

/* Chart header: identical geometry in every mode. Row 1 = title left, badge
   pinned right. Row 2 = controls, always their own row. Nothing shifts with
   title length. */
.chart-head {
  display: block;
  margin: 22px 0 8px;
}

.chart-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.chart-title-row .section-head {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.chart-controls {
  margin-top: 8px;
  display: inline-flex;
}

.chart-badge {
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 1.2px;
  padding: 3px 7px;
  border-radius: 99px;
  white-space: nowrap;
  flex: none;
}

.chart-badge.proj { background: var(--accent); color: var(--bg); }
.chart-badge.actual { border: 1px solid var(--rule); color: var(--ink-3); }

/* On phones the control row spans the full width with even-width buttons */
@media (max-width: 700px) {
  .chart-controls { display: flex; width: 100%; }
  .chart-controls button { flex: 1 1 0; padding: 6px 0; text-align: center; }
}

.curve-wrap {
  background: var(--box);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 14px 10px 6px;
}

.curve-wrap svg { width: 100%; height: auto; display: block; }

.cv-grid { stroke: var(--rule); stroke-width: 1; }
.cv-grid.minor { opacity: 0.45; }
.cv-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.cv-dot { fill: var(--box); stroke: var(--accent); stroke-width: 2; }
.cv-dot.key { fill: var(--accent); }
.cv-hit { fill: transparent; cursor: default; }
.cv-ylabel, .cv-xlabel { font-size: 10px; fill: var(--ink-3); font-family: var(--sans); }
.cv-vlabel { font-size: 11px; font-weight: 700; fill: var(--ink); font-family: var(--sans); }

.rates-note { margin-top: 18px; font-size: 11.5px; color: var(--ink-3); }

/* Rates page compresses to a single phone screen: one row of tiles per band,
   tighter heads, no subs */
@media (max-width: 700px) {
  #view-rates .section-head { margin: 14px 0 6px; }
  #view-rates .section-head:first-child { margin-top: 4px; }
  .rate-tiles.quads { grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .rate-tiles.thirds { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .rate-tile { padding: 8px 9px; }
  .rt-label { font-size: 8px; letter-spacing: 0.8px; }
  .rt-value { font-size: 16px; margin-top: 2px; }
  .rt-sub { display: none; }
  .rt-chg { font-size: 8.5px; }
  .rt-chg .rt-pct { display: none; } /* bp only in the tight 4-across tiles */
  .chart-head { margin: 14px 0 6px; }
  .curve-wrap { padding: 8px 6px 2px; }
  .rates-note { margin-top: 10px; font-size: 10px; }
}

/* ---------- Weekly ---------- */
.week-label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 1.8px;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 8px;
}

#weekly-content .week-overview { font-size: 14.5px; line-height: 1.55; margin-bottom: 18px; }

.theme-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.theme {
  background: var(--box);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 13px 15px;
}

.theme h3 { font-size: 13.5px; font-weight: 600; }
.theme p { font-size: 12.5px; color: var(--ink-2); margin-top: 4px; line-height: 1.5; }

.week-stories { margin-top: 20px; }

.week-story {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 0;
  border-bottom: 1px solid var(--rule);
}

.week-story h4 { font-size: 13px; font-weight: 600; line-height: 1.35; }
.week-story:hover h4 { color: var(--accent); }
.week-story .meta { font-size: 9.5px; letter-spacing: 1.1px; text-transform: uppercase; color: var(--ink-3); margin-top: 3px; }

.week-notes { margin-top: 18px; font-size: 12px; font-style: italic; color: var(--ink-2); }

/* ---------- History ---------- */
#history-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.day-card {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--box);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 13px 15px;
}

.day-card h3 { font-size: 13.5px; font-weight: 600; }
.day-card:hover h3 { color: var(--accent); }
.day-card p { font-size: 12.5px; color: var(--ink-2); margin-top: 4px; line-height: 1.5; }
.day-card .meta { margin-top: 8px; font-size: 9.5px; letter-spacing: 1.1px; text-transform: uppercase; color: var(--ink-3); }

/* ---------- Reader ---------- */
#reader {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: var(--bg);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.reader-bar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  border-bottom: 1px solid var(--rule);
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: var(--measure);
  margin: 0 auto;
  padding: 9px var(--pad);
}

#reader-back { font-size: 13px; color: var(--ink-2); padding: 6px 10px 6px 0; }
#reader-back:hover { color: var(--accent); }

#reader-original, #reader-original-end {
  font-size: 12.5px;
  color: var(--accent);
  text-decoration: none;
  padding: 6px 0;
}

#reader-original:hover, #reader-original-end:hover { text-decoration: underline; }

.reader-article {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 24px var(--pad) 80px;
}

.reader-kicker {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 1.8px;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 8px;
}

.reader-article h1 {
  font-weight: 700;
  font-size: clamp(20px, 5.4vw, 26px);
  line-height: 1.25;
  letter-spacing: -0.3px;
}

.reader-meta { margin-top: 10px; font-size: 12px; color: var(--ink-3); }

.reader-hero { margin: 18px 0 0; }

.reader-hero img, .reader-body img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 6px;
}

.reader-body {
  margin-top: 22px;
  font-size: 15px;
  line-height: 1.68;
}

.reader-body > * + * { margin-top: 0.9em; }

.reader-body h2, .reader-body h3 { font-size: 1.1em; line-height: 1.3; margin-top: 1.5em; }

.reader-body blockquote {
  border-left: 2px solid var(--rule-strong);
  padding-left: 14px;
  font-style: italic;
  color: var(--ink-2);
}

.reader-body ul, .reader-body ol { padding-left: 1.3em; }

.reader-body figure { margin: 1.5em 0; }
.reader-body figure img { margin: 0; }
.reader-body img { margin: 1.5em 0; }

.reader-body figcaption {
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--ink-3);
  margin-top: 7px;
}

.reader-fallback { font-style: italic; color: var(--ink-2); }

.reader-end { margin-top: 40px; padding-top: 14px; border-top: 1px solid var(--rule); }

/* ---------- Desktop ---------- */
@media (min-width: 960px) {
  :root { --page: 1100px; }

  /* lede and key points share the top band */
  #lede-block {
    display: grid;
    grid-template-columns: 1.15fr 1fr;
    gap: 32px;
    align-items: start;
  }

  #lede { font-size: 16px; }

  #key-points { margin-top: 2px; }
  #key-points li:first-child { padding-top: 0; }
  #key-points li:first-child::before { top: 6px; }

  /* two-across cards; the lead story spans the row */
  .story-group { grid-template-columns: repeat(2, 1fr); }
  .story-group.featured .story.lead { grid-column: 1 / -1; }
  .story-group.featured .story.lead p { max-width: 72ch; }

  #map-canvas { height: min(70vh, 660px); }

  .theme-grid { grid-template-columns: repeat(2, 1fr); }
  #history-list { grid-template-columns: repeat(2, 1fr); }

  #weekly-content .week-overview { max-width: 72ch; }
}
