/* ============================================================================
   Nifty 500 · 10-Year Backtest — design system
   Dark-first "research terminal" aesthetic. No external font/CDN dependencies.
   ========================================================================== */

:root {
  --bg:        #080b11;
  --bg-grid:   #0d1219;
  --surface:   #101722;
  --surface-2: #151d2b;
  --surface-3: #1b2536;
  --border:    #1f2b3d;
  --border-2:  #2a3852;
  --text:      #e9eff7;
  --text-2:    #c2cede;
  --muted:     #7d8da3;
  --muted-2:   #5d6b7e;

  --pos:       #2fd18a;
  --pos-dim:   #1c6b4b;
  --neg:       #ff5f56;
  --neg-dim:   #7a2b28;
  --accent:    #5aa9ff;
  --accent-2:  #7c8cff;
  --warn:      #e8b93c;
  --warn-bg:   #2a2210;
  --violet:    #b083f0;
  --gold:      #e0b040;
  --silver:    #9fb0c4;

  --radius: 3px;
  --maxw: 1280px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
}

[data-theme="light"] {
  --bg:        #f6f8fb;
  --bg-grid:   #eef2f7;
  --surface:   #ffffff;
  --surface-2: #f4f7fb;
  --surface-3: #e9eef6;
  --border:    #d8e0ea;
  --text:      #0d1622;
  --text-2:    #2c3a4d;
  --muted:     #5f7085;
  --muted-2:   #8595a8;
  --pos:       #0f9d58;
  --pos-dim:   #a8e6c4;
  --neg:       #d93025;
  --neg-dim:   #f6c9c5;
  --accent:    #1a6fe0;
  --accent-2:  #4b57d6;
  --warn:      #9a6b00;
  --warn-bg:   #fdf5e0;
  --violet:    #7a45c9;
  --gold:      #a9791a;
  --silver:    #6c7d92;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.num, .mono, table td, table th {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }

.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 22px; }

/* ---------------- header ---------------- */
header.site {
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 50;
}
.hdr {
  display: flex; align-items: center; gap: 22px;
  height: 58px;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 650; letter-spacing: -0.01em; color: var(--text);
  white-space: nowrap; text-decoration: none;
}
.brand:hover { text-decoration: none; }
.brand .mark {
  width: 22px; height: 22px; flex: 0 0 22px;
  border: 1px solid var(--accent); border-radius: 2px;
  display: grid; place-items: center;
  font-family: var(--mono); font-size: 10px; font-weight: 700; color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}
.brand .sub { color: var(--muted); font-weight: 500; font-size: 12px; letter-spacing: 0.02em; }

nav.main { margin-left: auto; display: flex; align-items: center; gap: 3px; overflow-x: auto; scrollbar-width: none; }
nav.main::-webkit-scrollbar { display: none; }
nav.main a {
  color: var(--muted); font-size: 13px; font-weight: 550;
  padding: 6px 10px; border-radius: var(--radius); white-space: nowrap;
}
nav.main a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
nav.main a.on { color: var(--text); background: var(--surface-3); }

.theme-btn {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted);
  border-radius: var(--radius); cursor: pointer; padding: 6px 9px; font-size: 13px;
  font-family: var(--mono); line-height: 1;
}
.theme-btn:hover { color: var(--text); border-color: var(--muted-2); }

/* ---------------- persistent bias strip ---------------- */
.bias-strip {
  background: var(--warn-bg);
  border-bottom: 1px solid color-mix(in srgb, var(--warn) 35%, transparent);
  font-size: 12.5px; color: var(--text-2);
}
.bias-strip .in {
  display: flex; align-items: baseline; gap: 9px; padding: 8px 22px;
  max-width: var(--maxw); margin: 0 auto;
}
.bias-strip .tag {
  flex: 0 0 auto; font-family: var(--mono); font-size: 10px; font-weight: 700;
  letter-spacing: 0.06em; color: var(--warn);
  border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent);
  padding: 1px 5px; border-radius: 2px; text-transform: uppercase;
  position: relative; top: -1px;
}
.bias-strip strong { color: var(--text); font-weight: 620; }

/* ---------------- layout / typography ---------------- */
main { padding: 34px 0 70px; }

.page-head { margin-bottom: 30px; }
.eyebrow {
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.11em;
  text-transform: uppercase; color: var(--accent); margin-bottom: 10px;
}
h1 {
  font-size: 34px; line-height: 1.18; margin: 0 0 12px;
  letter-spacing: -0.022em; font-weight: 660;
}
h2 {
  font-size: 20px; margin: 44px 0 14px; letter-spacing: -0.014em; font-weight: 640;
  padding-bottom: 9px; border-bottom: 1px solid var(--border);
}
h3 { font-size: 15.5px; margin: 26px 0 10px; font-weight: 630; letter-spacing: -0.008em; }
h4 { font-size: 13px; margin: 18px 0 8px; font-weight: 620; color: var(--text-2); }
p { margin: 0 0 13px; color: var(--text-2); }
.lede { font-size: 16.5px; color: var(--muted); max-width: 78ch; line-height: 1.62; }
.small { font-size: 12.5px; }
.tiny { font-size: 11.5px; }
strong { color: var(--text); font-weight: 620; }
ul.tight { margin: 0 0 13px; padding-left: 20px; color: var(--text-2); }
ul.tight li { margin-bottom: 5px; }
code {
  font-family: var(--mono); font-size: 12.5px;
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 1px 5px; border-radius: 2px; color: var(--text);
}

/* ---------------- grids ---------------- */
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
@media (max-width: 900px) { .g3, .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 620px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } }

/* ---------------- cards ---------------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 17px 18px;
}
.card.pad-lg { padding: 22px 24px; }
.card .k {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 7px;
}

/* stat tiles */
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat .lab { font-size: 11.5px; color: var(--muted); margin-bottom: 5px; }
.stat .val { font-family: var(--mono); font-size: 22px; font-weight: 600; letter-spacing: -0.02em; }
.stat .sub { font-size: 11.5px; color: var(--muted-2); margin-top: 3px; }

.pos { color: var(--pos); }
.neg { color: var(--neg); }
.dim { color: var(--muted); }
.muted { color: var(--muted); }
.warnc { color: var(--warn); }
.violetc { color: var(--violet); }

/* ---------------- confidence pills ---------------- */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--mono); font-size: 10px; font-weight: 700;
  letter-spacing: 0.06em; text-transform: uppercase;
  padding: 3px 7px; border-radius: 2px; border: 1px solid; white-space: nowrap;
}
.pill.strong { color: var(--pos); border-color: color-mix(in srgb, var(--pos) 45%, transparent); background: color-mix(in srgb, var(--pos) 11%, transparent); }
.pill.mixed  { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); background: color-mix(in srgb, var(--warn) 11%, transparent); }
.pill.weak   { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, transparent); background: color-mix(in srgb, var(--accent) 11%, transparent); }
.pill.none   { color: var(--neg); border-color: color-mix(in srgb, var(--neg) 45%, transparent); background: color-mix(in srgb, var(--neg) 11%, transparent); }

/* ---------------- callouts ---------------- */
.note {
  border-left: 3px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 7%, transparent);
  padding: 13px 16px; border-radius: 0 var(--radius) var(--radius) 0; margin: 16px 0;
  font-size: 13.5px; color: var(--text-2);
}
.note.warn {
  border-left-color: var(--warn);
  background: var(--warn-bg);
}
.note.bad {
  border-left-color: var(--neg);
  background: color-mix(in srgb, var(--neg) 8%, transparent);
}
.note.good {
  border-left-color: var(--pos);
  background: color-mix(in srgb, var(--pos) 8%, transparent);
}
.note .h {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 6px; display: block;
}
.note p:last-child { margin-bottom: 0; }

/* ---------------- tables ---------------- */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
thead th {
  text-align: left; padding: 9px 12px; font-family: var(--mono);
  font-size: 10.5px; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--muted); border-bottom: 1px solid var(--border);
  background: var(--surface-2); position: sticky; top: 0; white-space: nowrap;
}
thead th.sortable { cursor: pointer; user-select: none; }
thead th.sortable:hover { color: var(--text); }
thead th .ar { opacity: 0.35; font-size: 9px; }
thead th.act .ar { opacity: 1; color: var(--accent); }
tbody td { padding: 8px 12px; border-bottom: 1px solid var(--border); color: var(--text-2); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
tbody td.sym { font-family: var(--mono); color: var(--text); font-weight: 500; }
tbody td.r { text-align: right; }
tbody tr.hi td { background: color-mix(in srgb, var(--accent) 8%, transparent); }
tbody tr.negrow td { background: color-mix(in srgb, var(--neg) 6%, transparent); }

/* ---------------- heatmap ---------------- */
.hm-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table.hm { border-collapse: separate; border-spacing: 2px; font-size: 11px; width: auto; min-width: 100%; }
table.hm th { position: static; background: transparent; border: 0; padding: 4px 6px; font-size: 10px; }
table.hm thead th { background: transparent; border: 0; position: static; }
table.hm th.rowhead {
  text-align: left; font-family: var(--sans); font-size: 11.5px; letter-spacing: 0;
  text-transform: none; color: var(--text-2); white-space: nowrap; padding-right: 10px;
  position: sticky; left: 0; background: var(--surface); z-index: 2; font-weight: 550;
}
table.hm td.cell {
  text-align: center; padding: 6px 5px; border-radius: 2px; border: 0;
  font-family: var(--mono); font-size: 10.5px; color: var(--text); min-width: 52px;
  cursor: default;
}
table.hm td.cell.empty { background: var(--surface-2); color: var(--muted-2); }

.hm-legend { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 11.5px; color: var(--muted); flex-wrap: wrap; }
.hm-scale { display: flex; height: 11px; width: 190px; border-radius: 2px; overflow: hidden; border: 1px solid var(--border); }
.hm-scale span { flex: 1; }

/* ---------------- charts ---------------- */
.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px 12px; }
.chart-title { font-size: 13px; font-weight: 620; color: var(--text); margin-bottom: 3px; }
.chart-sub { font-size: 11.5px; color: var(--muted); margin-bottom: 14px; }
svg.chart { display: block; width: 100%; height: auto; overflow: visible; }
svg.chart text { font-family: var(--mono); font-size: 9.5px; fill: var(--muted); }
svg.chart .axis { stroke: var(--border); stroke-width: 1; }
svg.chart .gridline { stroke: var(--border); stroke-width: 1; stroke-dasharray: 2 4; opacity: 0.6; }
svg.chart .zeroline { stroke: var(--muted-2); stroke-width: 1; }
svg.chart .barpos { fill: var(--pos); }
svg.chart .barneg { fill: var(--neg); }
svg.chart .lbl { fill: var(--muted); }
svg.chart .val-lbl { fill: var(--text); font-size: 9px; font-weight: 600; }
svg.chart .series-1 { fill: none; stroke-width: 2; }
svg.chart .dot { stroke: var(--surface); stroke-width: 1.5; }

.legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 10px; font-size: 11.5px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 11px; height: 3px; border-radius: 2px; display: inline-block; }
.legend i.sq { width: 9px; height: 9px; border-radius: 2px; }

/* ---------------- controls ---------------- */
.controls { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; margin: 16px 0; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.seg button {
  background: var(--surface); border: 0; color: var(--muted); cursor: pointer;
  padding: 7px 13px; font-size: 12.5px; font-family: inherit; font-weight: 550;
  border-right: 1px solid var(--border);
}
.seg button:last-child { border-right: 0; }
.seg button:hover { color: var(--text); background: var(--surface-2); }
.seg button.on { background: var(--surface-3); color: var(--text); }
input.search, select.sel {
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius); padding: 7px 11px; font-size: 13px; font-family: inherit;
}
input.search { min-width: 210px; }
input.search::placeholder { color: var(--muted-2); }
input.search:focus, select.sel:focus { outline: 1px solid var(--accent); border-color: var(--accent); }

/* ---------------- comparison panels ---------------- */
.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 0; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.compare > div { padding: 18px 20px; background: var(--surface); }
.compare > div:first-child { border-right: 1px solid var(--border); }
.compare .ttl { font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.07em; text-transform: uppercase; margin-bottom: 9px; }
.compare .big { font-family: var(--mono); font-size: 34px; font-weight: 620; letter-spacing: -0.03em; line-height: 1.05; }
.compare .cap { font-size: 12.5px; color: var(--muted); margin-top: 8px; }
@media (max-width: 720px) { .compare { grid-template-columns: 1fr; } .compare > div:first-child { border-right: 0; border-bottom: 1px solid var(--border); } }

/* ---------------- misc ---------------- */
.kv { display: flex; justify-content: space-between; gap: 14px; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.kv:last-child { border-bottom: 0; }
.kv .k2 { color: var(--muted); }
.kv .v2 { font-family: var(--mono); color: var(--text); text-align: right; }

.finding { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: 20px 22px; }
.finding .top { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 9px; }
.finding .idx { font-family: var(--mono); font-size: 11px; color: var(--muted-2); }
.finding h3 { margin: 0; font-size: 16.5px; line-height: 1.3; }
.finding .fig { font-family: var(--mono); font-size: 15px; color: var(--accent); margin: 9px 0; letter-spacing: -0.01em; }
.finding .caveat {
  margin-top: 13px; padding-top: 12px; border-top: 1px dashed var(--border);
  font-size: 12.5px; color: var(--muted);
}
.finding .caveat b { color: var(--warn); font-weight: 640; }

footer.site { border-top: 1px solid var(--border); margin-top: 60px; padding: 26px 0 40px; color: var(--muted); font-size: 12.5px; }
footer.site .fnote { background: var(--warn-bg); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent); border-radius: var(--radius); padding: 13px 16px; margin-bottom: 18px; color: var(--text-2); }
footer.site .frow { display: flex; gap: 20px; flex-wrap: wrap; justify-content: space-between; }

.loading { padding: 40px; text-align: center; color: var(--muted); font-family: var(--mono); font-size: 12.5px; }
details.det { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); margin-bottom: 10px; }
details.det > summary { cursor: pointer; padding: 11px 15px; font-weight: 580; font-size: 13.5px; color: var(--text); list-style: none; }
details.det > summary::-webkit-details-marker { display: none; }
details.det > summary::before { content: "▸ "; color: var(--muted); font-family: var(--mono); }
details.det[open] > summary::before { content: "▾ "; }
details.det > summary:hover { color: var(--accent); }
details.det .body { padding: 0 15px 15px; border-top: 1px solid var(--border); padding-top: 13px; }
