/* ----------------------------------------------------------------------
   What New York owes -- a ledger for the city's five pension funds.
   Visual language: warm ledger paper, ink rules, tabular figures.
   Chart colors are the validated palettes (see METHODOLOGY.md).
   ---------------------------------------------------------------------- */

:root {
  color-scheme: light;

  --paper:        #f2eee3;
  --paper-2:      #ebe6d8;
  --paper-3:      #e2dccb;
  --ink:          #191510;
  --ink-2:        #4a423a;
  --ink-3:        #7b7062;
  --rule:         rgba(25, 21, 16, 0.16);
  --rule-strong:  rgba(25, 21, 16, 0.42);

  --assets:       #1a77b5;
  --liability:    #b2372f;
  --gap-wash:     rgba(178, 55, 47, 0.13);

  --f-nycers:     #9d4ba5;
  --f-trs:        #1c8560;
  --f-police:     #1a77b5;
  --f-fire:       #b93f67;
  --f-bers:       #8e6b17;

  --shadow:       0 1px 0 rgba(25, 21, 16, 0.06);

  --serif: "Archivo", ui-sans-serif, system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --wrap: 1140px;
}

:root[data-theme="dark"],
:root:where(:not([data-theme="light"])) {
  /* placeholder so the cascade order below is explicit */
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --paper:       #17130f;
    --paper-2:     #201b16;
    --paper-3:     #2a231c;
    --ink:         #f4efe4;
    --ink-2:       #c3b9a8;
    --ink-3:       #8d8375;
    --rule:        rgba(244, 239, 228, 0.17);
    --rule-strong: rgba(244, 239, 228, 0.45);

    --assets:      #218dd4;
    --liability:   #cc5346;
    --gap-wash:    rgba(204, 83, 70, 0.18);

    --f-nycers:    #b163b9;
    --f-trs:       #239d72;
    --f-police:    #218dd4;
    --f-fire:      #cd597c;
    --f-bers:      #a77f1e;

    --shadow:      0 1px 0 rgba(0, 0, 0, 0.4);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --paper:       #17130f;
  --paper-2:     #201b16;
  --paper-3:     #2a231c;
  --ink:         #f4efe4;
  --ink-2:       #c3b9a8;
  --ink-3:       #8d8375;
  --rule:        rgba(244, 239, 228, 0.17);
  --rule-strong: rgba(244, 239, 228, 0.45);

  --assets:      #218dd4;
  --liability:   #cc5346;
  --gap-wash:    rgba(204, 83, 70, 0.18);

  --f-nycers:    #b163b9;
  --f-trs:       #239d72;
  --f-police:    #218dd4;
  --f-fire:      #cd597c;
  --f-bers:      #a77f1e;

  --shadow:      0 1px 0 rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.55;
  font-feature-settings: "kern" 1;
  -webkit-font-smoothing: antialiased;
}

.wrap { width: min(100% - 2.5rem, var(--wrap)); margin-inline: auto; }

/* ---------- masthead ---------- */

.masthead {
  border-bottom: 2px solid var(--ink);
  padding-top: 1.6rem;
  background:
    repeating-linear-gradient(
      to bottom,
      transparent 0 27px,
      color-mix(in srgb, var(--ink) 3%, transparent) 27px 28px
    );
}

.masthead-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.eyebrow {
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.19em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin: 0;
}

h1 {
  font-size: clamp(2.35rem, 6.4vw, 4.15rem);
  line-height: 0.94;
  letter-spacing: -0.033em;
  font-weight: 800;
  margin: 0.32rem 0 0;
  max-width: 16ch;
}

.standfirst {
  margin: 0.85rem 0 1.5rem;
  font-size: clamp(1rem, 1.9vw, 1.14rem);
  color: var(--ink-2);
  max-width: 62ch;
  line-height: 1.5;
}

.standfirst strong { color: var(--ink); font-weight: 600; }

.theme-toggle {
  border: 1px solid var(--rule-strong);
  background: transparent;
  color: var(--ink-2);
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  padding: 0.42rem 0.7rem;
  cursor: pointer;
  border-radius: 0;
}
.theme-toggle:hover { background: var(--paper-2); color: var(--ink); }

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

.tabs {
  display: flex;
  gap: 0;
  overflow-x: auto;
  border-bottom: 1px solid var(--rule);
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--paper);
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  appearance: none;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--ink-3);
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  padding: 0.95rem 1.05rem;
  cursor: pointer;
  white-space: nowrap;
  font-weight: 500;
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] {
  color: var(--ink);
  border-bottom-color: var(--ink);
  font-weight: 600;
}

.panel { padding: 2.3rem 0 4rem; }
.panel[hidden] { display: none; }

/* ---------- section furniture ---------- */

h2 {
  font-size: clamp(1.35rem, 2.7vw, 1.72rem);
  letter-spacing: -0.02em;
  font-weight: 700;
  margin: 0 0 0.3rem;
}

h3 {
  font-size: 1.02rem;
  font-weight: 600;
  letter-spacing: -0.008em;
  margin: 0 0 0.35rem;
}

.section { margin-bottom: 3.2rem; }
.section-note {
  color: var(--ink-2);
  max-width: 68ch;
  margin: 0 0 1.35rem;
  font-size: 0.95rem;
}
.section-note a, .prose a { color: inherit; text-decoration-color: var(--rule-strong); }

.rule-label {
  font-family: var(--mono);
  font-size: 0.63rem;
  letter-spacing: 0.19em;
  text-transform: uppercase;
  color: var(--ink-3);
  border-top: 1px solid var(--ink);
  padding-top: 0.42rem;
  margin: 0 0 1.05rem;
  display: block;
}

/* ---------- stat tiles ---------- */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(215px, 1fr));
  gap: 0;
  border: 1px solid var(--ink);
  margin-bottom: 2.3rem;
  background: var(--paper-2);
}

.tile {
  padding: 1.15rem 1.25rem 1.25rem;
  border-right: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  gap: 0.16rem;
}
.tile:last-child { border-right: 0; }

.tile-label {
  font-family: var(--mono);
  font-size: 0.63rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.tile-value {
  font-family: var(--mono);
  font-size: clamp(1.75rem, 4.1vw, 2.35rem);
  font-weight: 600;
  letter-spacing: -0.035em;
  line-height: 1.02;
  font-variant-numeric: tabular-nums;
  margin-top: 0.18rem;
}

.tile-delta {
  font-family: var(--mono);
  font-size: 0.73rem;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
  margin-top: 0.2rem;
}
.tile-delta .up { color: var(--liability); }
.tile-delta .down { color: var(--assets); }

.tile-sub { font-size: 0.78rem; color: var(--ink-3); margin-top: 0.3rem; line-height: 1.35; }

/* ---------- figures & charts ---------- */

figure {
  margin: 0 0 2.1rem;
  border: 1px solid var(--ink);
  background: var(--paper-2);
}

figcaption {
  padding: 1rem 1.15rem 0.15rem;
}

.fig-title { font-weight: 700; font-size: 1.04rem; letter-spacing: -0.012em; }
.fig-sub { color: var(--ink-2); font-size: 0.87rem; margin-top: 0.16rem; max-width: 74ch; }

.chart-host { padding: 0.5rem 0.6rem 0.7rem; position: relative; }
.chart-host svg { display: block; width: 100%; height: auto; overflow: visible; }

.fig-source {
  border-top: 1px solid var(--rule);
  padding: 0.6rem 1.15rem 0.75rem;
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.03em;
  color: var(--ink-3);
  line-height: 1.5;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1.15rem;
  padding: 0.3rem 1.15rem 0.15rem;
}
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.79rem;
  color: var(--ink-2);
}
.legend-swatch { width: 15px; height: 3px; flex: none; border-radius: 2px; }
.legend-swatch.block { height: 11px; width: 11px; border-radius: 2px; }

/* axis + grid */
.grid-line { stroke: var(--rule); stroke-width: 1; }
.axis-line { stroke: var(--rule-strong); stroke-width: 1; }
.tick-text {
  font-family: var(--mono);
  font-size: 10.5px;
  fill: var(--ink-3);
  font-variant-numeric: tabular-nums;
}
.series-label {
  font-family: var(--serif);
  font-size: 11.5px;
  font-weight: 600;
  fill: var(--ink-2);
}

/* tooltip */
.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--ink);
  color: var(--paper);
  border-radius: 3px;
  padding: 0.5rem 0.62rem;
  font-size: 0.76rem;
  line-height: 1.45;
  z-index: 20;
  min-width: 132px;
  opacity: 0;
  transition: opacity 0.09s;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.22);
}
.tooltip.on { opacity: 1; }
.tt-head {
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  opacity: 0.72;
  margin-bottom: 0.28rem;
}
.tt-row { display: flex; align-items: center; gap: 0.42rem; justify-content: space-between; }
.tt-row .k { display: inline-flex; align-items: center; gap: 0.36rem; }
.tt-dot { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.tt-v { font-family: var(--mono); font-variant-numeric: tabular-nums; font-weight: 500; }

/* ---------- data table (accessible alternative) ---------- */

.table-toggle {
  appearance: none;
  border: 1px solid var(--rule-strong);
  background: transparent;
  color: var(--ink-2);
  font-family: var(--mono);
  font-size: 0.63rem;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  padding: 0.34rem 0.6rem;
  margin: 0 1.15rem 0.9rem;
  cursor: pointer;
}
.table-toggle:hover { background: var(--paper-3); color: var(--ink); }

.data-table-host { padding: 0 1.15rem 1rem; overflow-x: auto; }
table.data {
  border-collapse: collapse;
  width: 100%;
  font-family: var(--mono);
  font-size: 0.76rem;
  font-variant-numeric: tabular-nums;
  min-width: 520px;
}
table.data th, table.data td {
  text-align: right;
  padding: 0.34rem 0.55rem;
  border-bottom: 1px solid var(--rule);
  white-space: nowrap;
}
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data thead th {
  border-bottom: 1px solid var(--ink);
  color: var(--ink-3);
  font-weight: 500;
  font-size: 0.66rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

/* ---------- fund cards ---------- */

.fund-list { border: 1px solid var(--ink); background: var(--paper-2); }

.fund {
  border-bottom: 1px solid var(--rule);
}
.fund:last-child { border-bottom: 0; }

.fund-head {
  display: grid;
  grid-template-columns: 6px minmax(0, 2.1fr) repeat(3, minmax(0, 1fr)) auto;
  gap: 0 1rem;
  align-items: center;
  width: 100%;
  background: transparent;
  border: 0;
  color: inherit;
  font: inherit;
  text-align: left;
  padding: 0.95rem 1.15rem 0.95rem 0;
  cursor: pointer;
}
.fund-head:hover { background: var(--paper-3); }

.fund-stripe { width: 6px; align-self: stretch; }

.fund-name { font-weight: 600; font-size: 0.98rem; letter-spacing: -0.01em; }
.fund-abbr {
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.13em;
  color: var(--ink-3);
  text-transform: uppercase;
}

.fund-metric { text-align: right; }
.fund-metric .m-label {
  font-family: var(--mono);
  font-size: 0.58rem;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--ink-3);
  display: block;
}
.fund-metric .m-value {
  font-family: var(--mono);
  font-size: 1.02rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.chev { color: var(--ink-3); font-size: 0.8rem; transition: transform 0.15s; padding-right: 0.2rem; }
.fund-head[aria-expanded="true"] .chev { transform: rotate(90deg); }

.fund-body { padding: 0.35rem 1.15rem 1.5rem 1.15rem; border-top: 1px dashed var(--rule); }
.fund-body[hidden] { display: none; }
.fund-who { color: var(--ink-2); font-size: 0.9rem; max-width: 70ch; margin: 0.9rem 0 1.1rem; }

.kv {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(148px, 1fr));
  gap: 0.9rem 1.4rem;
}
.kv div { border-top: 1px solid var(--rule); padding-top: 0.42rem; }
.kv .k {
  font-family: var(--mono);
  font-size: 0.6rem;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--ink-3);
  display: block;
}
.kv .v {
  font-family: var(--mono);
  font-size: 1.02rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.kv .n { font-size: 0.72rem; color: var(--ink-3); display: block; margin-top: 0.1rem; }

/* ---------- controls ---------- */

.controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(232px, 1fr));
  gap: 1.3rem 1.9rem;
  border: 1px solid var(--ink);
  background: var(--paper-2);
  padding: 1.3rem 1.35rem;
  margin-bottom: 2rem;
}

.control label {
  font-family: var(--mono);
  font-size: 0.63rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-3);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}
.control label .val {
  font-size: 0.95rem;
  color: var(--ink);
  letter-spacing: -0.02em;
  font-weight: 600;
  text-transform: none;
}
.control input[type="range"] {
  width: 100%;
  accent-color: var(--assets);
  margin: 0;
}
.control .hint { font-size: 0.73rem; color: var(--ink-3); margin-top: 0.4rem; line-height: 1.4; }

.seg { display: flex; flex-wrap: wrap; border: 1px solid var(--rule-strong); }
.seg button {
  flex: 1 1 auto;
  min-width: 0;
  appearance: none;
  border: 0;
  border-right: 1px solid var(--rule-strong);
  border-bottom: 1px solid var(--rule-strong);
  background: transparent;
  color: var(--ink-2);
  font-family: var(--mono);
  font-size: 0.63rem;
  letter-spacing: 0.05em;
  padding: 0.42rem 0.5rem;
  cursor: pointer;
  text-transform: uppercase;
  white-space: nowrap;
}
.seg button:last-child { border-right: 0; }
.seg button { border-bottom: 0; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); font-weight: 600; }

.reset {
  appearance: none;
  border: 1px solid var(--rule-strong);
  background: transparent;
  color: var(--ink-2);
  font-family: var(--mono);
  font-size: 0.63rem;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  padding: 0.42rem 0.75rem;
  cursor: pointer;
}
.reset:hover { background: var(--paper-3); color: var(--ink); }

/* ---------- scenario readout ---------- */

.readout {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  border: 1px solid var(--ink);
  background: var(--paper-2);
  margin-bottom: 2rem;
}
.readout > div {
  padding: 1.05rem 1.15rem;
  border-right: 1px solid var(--rule);
}
.readout > div:last-child { border-right: 0; }
.readout .k {
  font-family: var(--mono);
  font-size: 0.61rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-3);
  display: block;
  margin-bottom: 0.3rem;
}
.readout .v {
  display: block;
  font-family: var(--mono);
  font-size: 1.62rem;
  font-weight: 600;
  letter-spacing: -0.035em;
  font-variant-numeric: tabular-nums;
  line-height: 1.05;
}
.readout .n {
  display: block;
  font-size: 0.75rem;
  color: var(--ink-3);
  margin-top: 0.28rem;
  line-height: 1.35;
}

.callout {
  border-left: 3px solid var(--ink);
  padding: 0.15rem 0 0.15rem 1rem;
  margin: 1.6rem 0 2rem;
  color: var(--ink-2);
  font-size: 0.93rem;
  max-width: 74ch;
}
.callout strong { color: var(--ink); }

/* ---------- methodology prose ---------- */

.prose { max-width: 74ch; }
.prose p { color: var(--ink-2); }
.prose h3 { color: var(--ink); margin-top: 1.9rem; }
.prose ul { color: var(--ink-2); padding-left: 1.1rem; }
.prose li { margin-bottom: 0.5rem; }
.prose code {
  font-family: var(--mono);
  font-size: 0.85em;
  background: var(--paper-3);
  padding: 0.08em 0.32em;
  border-radius: 2px;
}
.prose .formula {
  font-family: var(--mono);
  font-size: 0.8rem;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  padding: 0.85rem 1rem;
  overflow-x: auto;
  line-height: 1.75;
  color: var(--ink);
}

/* ---------- AI caution ---------- */

.footer {
  border-top: 2px solid var(--ink);
  padding: 2rem 0 3.5rem;
  margin-top: 1rem;
}
.footer p { color: var(--ink-3); font-size: 0.85rem; max-width: 70ch; }

.caution-wrap { position: relative; display: inline-block; margin-top: 0.6rem; }
.caution-btn {
  appearance: none;
  border: 0;
  background: #7d1d22;
  color: #fff;
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.09em;
  padding: 0.55rem 0.9rem;
  cursor: pointer;
  border-radius: 2px;
}
.caution-btn:hover { background: #661619; }
.caution-pop {
  position: absolute;
  bottom: calc(100% + 0.55rem);
  left: 0;
  width: min(84vw, 470px);
  background: #131c33;
  color: #eef1f7;
  padding: 1rem 1.1rem;
  font-size: 0.83rem;
  line-height: 1.55;
  border-radius: 3px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  z-index: 40;
}
.caution-pop[hidden] { display: none; }
.caution-pop p { color: #eef1f7; margin: 0 0 0.7rem; font-size: 0.83rem; }
.caution-pop p:last-child { margin-bottom: 0; }

/* ---------- responsive ---------- */

@media (max-width: 860px) {
  .fund-head {
    grid-template-columns: 6px minmax(0, 1fr) minmax(0, 0.8fr) auto;
    row-gap: 0.5rem;
  }
  .fund-metric.hide-sm { display: none; }
  .tile { border-right: 0; border-bottom: 1px solid var(--rule); }
  .readout > div { border-right: 0; border-bottom: 1px solid var(--rule); }
}

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