/* ── Reset & Base ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  color-scheme: dark;
  --bg:         #0a0e0f;
  --bg2:        #0f1517;
  --bg3:        #161d1f;
  --border:     #1e2a2d;
  --border2:    #243034;
  --green:      #00e676;   /* brand accent: UI chrome, highlights */
  --green-dim:  #00c853;
  --green-dark: #003d1f;
  --red:        #ff1744;
  --amber:      #ffab00;
  --text:       #cfd8dc;
  --text-dim:   #8a9ba5;
  --text-bright:#eceff1;

  /* Chart roles (validated against --bg2: lightness band, CVD, contrast) */
  --mark:       #00b060;   /* the model */
  --mark-muted: #607d8b;   /* baselines / context */
  --grid:       #1b2528;
  --axis:       #2c3a3e;

  --font-display: 'Rajdhani', sans-serif;
  --font-mono:    'IBM Plex Mono', monospace;
  --font-body:    'IBM Plex Sans', system-ui, sans-serif;
}

html { scroll-behavior: smooth; }

body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  overflow-x: hidden;
}

a { color: var(--green); text-underline-offset: 3px; }
a:hover { color: var(--text-bright); }
:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ── Scanlines overlay ─────────────────────────────────────────────── */
.scanlines {
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(0,0,0,0.06) 2px, rgba(0,0,0,0.06) 4px);
  pointer-events: none;
  z-index: 9999;
}

/* ── Header ────────────────────────────────────────────────────────── */
header {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 60px;
  max-width: 1200px;
  margin: 0 auto;
}

.logo { display: flex; align-items: center; gap: 12px; text-decoration: none; min-width: 0; }

.logo-icon {
  font-size: 24px;
  filter: drop-shadow(0 0 8px rgba(0,230,118,0.5));
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-3px); }
}

.logo-text { display: flex; flex-direction: column; min-width: 0; }

.logo-title {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  color: var(--text-bright);
  letter-spacing: 3px;
  line-height: 1.1;
}

.logo-sub {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--green);
  letter-spacing: 2px;
  opacity: 0.85;
  white-space: nowrap;
}

.model-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  text-align: right;
}

.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
}
.status-dot.live  { background: var(--green); box-shadow: 0 0 6px var(--green); animation: pulse 2s infinite; }
.status-dot.error { background: var(--red); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

/* ── Tabs (desktop top nav) ────────────────────────────────────────── */
.tabs {
  display: flex;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
}
.tabs-inner { display: flex; max-width: 1200px; margin: 0 auto; width: 100%; }

.tab {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 2px;
  color: var(--text-dim);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  padding: 12px 20px;
  transition: color 0.2s, border-color 0.2s;
  text-transform: uppercase;
}
.tab:hover  { color: var(--text); }
.tab.active { color: var(--green); border-bottom-color: var(--green); }

/* ── Page layout ───────────────────────────────────────────────────── */
.tab-content { display: none; padding: 28px 24px 48px; max-width: 1200px; margin: 0 auto; }
.tab-content.active { display: block; }

.page-head { margin-bottom: 24px; }
.page-head h1 {
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--text-bright);
  line-height: 1.15;
}
.page-sub { color: var(--text-dim); margin-top: 6px; max-width: 760px; }
.page-sub.lead { color: var(--text); font-size: 16px; }

.panel {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 20px 22px;
  margin-bottom: 20px;
  min-width: 0;
}
.panel h2 {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--text-bright);
}
.panel-sub { color: var(--text-dim); font-size: 13.5px; margin: 4px 0 14px; max-width: 720px; }
.panel > p { max-width: 760px; }
.panel > p + p { margin-top: 10px; }
.panel-row { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.panel-row .panel { margin-bottom: 20px; }

.callout { border-color: #00522a; background: linear-gradient(180deg, rgba(0,61,31,0.35), var(--bg2) 70%); }
.callout h2 { margin-bottom: 8px; }
.callout strong { color: var(--text-bright); }

.note {
  font-size: 13.5px;
  color: var(--text);
  background: var(--bg3);
  border-left: 2px solid var(--amber);
  padding: 10px 14px;
  border-radius: 0 4px 4px 0;
  margin-bottom: 18px;
  max-width: 820px;
}
.note:empty { display: none; }

.loading, .empty-state, .error-state {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 1px;
  color: var(--text-dim);
  padding: 40px 0;
  text-align: center;
}
.error-state { color: var(--red); }

/* ── Stat tiles ────────────────────────────────────────────────────── */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.kpi {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 14px 18px;
}
.kpi.highlight { border-color: #00522a; background: var(--green-dark); }
.kpi-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  text-transform: uppercase;
}
.kpi-value {
  font-family: var(--font-body);
  font-size: 30px;
  font-weight: 600;
  color: var(--text-bright);
  line-height: 1.2;
  margin-top: 4px;
}
.kpi.highlight .kpi-value { color: var(--green); }
.kpi-detail { font-size: 12.5px; color: var(--text-dim); margin-top: 2px; }

/* ── Off-season / empty day ────────────────────────────────────────── */
.offseason {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 32px 28px;
  text-align: center;
}
.offseason .big {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 700;
  color: var(--text-bright);
}
.offseason p { color: var(--text-dim); margin: 8px auto 18px; max-width: 560px; }
.offseason .actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.btn-primary, .btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 2px;
  padding: 9px 20px;
  border-radius: 3px;
  cursor: pointer;
  text-transform: uppercase;
  text-decoration: none;
  min-height: 44px;
}
.btn-primary { background: var(--green); color: #000; border: none; }
.btn-primary:hover { background: var(--green-dim); color: #000; }
.btn-secondary { background: transparent; color: var(--text); border: 1px solid var(--border2); }
.btn-secondary:hover { border-color: var(--green); color: var(--green); }

/* ── Game cards ────────────────────────────────────────────────────── */
.games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 440px), 1fr));
  gap: 16px;
}

.game-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  animation: cardIn 0.3s ease both;
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.game-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 16px;
  background: var(--bg3);
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.5px;
}
.game-state.live { color: var(--green); }
.game-state.live::before { content: '●'; margin-right: 6px; animation: pulse 2s infinite; }

.game-card-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 14px; }

.teams { display: grid; grid-template-columns: 1fr auto; row-gap: 6px; column-gap: 12px; align-items: baseline; }
.team-name {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 700;
  color: var(--text-bright);
  letter-spacing: 0.5px;
  line-height: 1.2;
}
.team-name .role { font-family: var(--font-mono); font-size: 10px; color: var(--text-dim); letter-spacing: 1px; margin-left: 8px; font-weight: 400; }
.team-name.pick::after { content: 'PICK'; font-family: var(--font-mono); font-size: 9px; letter-spacing: 1.5px; color: #000; background: var(--green); padding: 2px 5px; border-radius: 2px; margin-left: 10px; vertical-align: 3px; }
.team-prob { font-family: var(--font-mono); font-size: 15px; color: var(--text); text-align: right; font-variant-numeric: tabular-nums; }
.team-prob.pick { color: var(--text-bright); font-weight: 500; }
.team-score { font-family: var(--font-mono); font-size: 15px; color: var(--text-bright); margin-left: 12px; font-variant-numeric: tabular-nums; }

/* Win probability bar: away share on the left, home on the right */
.prob-bar { display: flex; height: 8px; gap: 2px; }
.prob-bar span { display: block; height: 100%; background: var(--mark-muted); opacity: 0.45; }
.prob-bar span:first-child { border-radius: 4px 0 0 4px; }
.prob-bar span:last-child  { border-radius: 0 4px 4px 0; }
.prob-bar span.pick { background: var(--mark); opacity: 1; }

.pitchers { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; font-size: 12.5px; }
.kv-key { font-family: var(--font-mono); font-size: 9.5px; letter-spacing: 1.5px; color: var(--text-dim); text-transform: uppercase; }
.kv-val { color: var(--text); }
.kv-val .muted { color: var(--text-dim); }

.factors { border-top: 1px solid var(--border); padding-top: 12px; }
.factors-title { font-family: var(--font-mono); font-size: 9.5px; letter-spacing: 1.5px; color: var(--text-dim); text-transform: uppercase; margin-bottom: 8px; }
.factor { display: grid; grid-template-columns: minmax(0, 1fr) 70px auto; gap: 10px; align-items: center; font-size: 12.5px; padding: 3px 0; }
.factor-name { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.factor-name .toward { color: var(--text-dim); }
.factor-bar { height: 6px; background: var(--bg3); border-radius: 3px; overflow: hidden; }
.factor-bar span { display: block; height: 100%; background: var(--mark); border-radius: 0 3px 3px 0; }
.factor-val { font-family: var(--font-mono); font-size: 11.5px; color: var(--text-dim); text-align: right; font-variant-numeric: tabular-nums; min-width: 52px; }

.card-foot { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-family: var(--font-mono); font-size: 10.5px; color: var(--text-dim); letter-spacing: 0.5px; }

.result-chip { font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 1px; padding: 2px 8px; border-radius: 3px; }
.result-chip.correct { background: var(--green-dark); color: var(--green); }
.result-chip.missed  { background: #3d0010; color: #ff6b81; }

/* ── Track record ──────────────────────────────────────────────────── */
.segmented { display: inline-flex; border: 1px solid var(--border2); border-radius: 4px; overflow: hidden; margin-bottom: 14px; }
.segmented button {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  padding: 8px 18px;
  min-height: 40px;
  cursor: pointer;
}
.segmented button + button { border-left: 1px solid var(--border2); }
.segmented button[aria-pressed="true"] { background: var(--green-dark); color: var(--green); }
.segmented button:disabled { opacity: 0.45; cursor: not-allowed; }

.filters { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: flex-end; margin-bottom: 12px; }
.filters label { display: flex; flex-direction: column; gap: 4px; font-family: var(--font-mono); font-size: 10px; letter-spacing: 1.5px; color: var(--text-dim); text-transform: uppercase; }
.filters select {
  background: var(--bg3);
  border: 1px solid var(--border2);
  color: var(--text-bright);
  font-family: var(--font-body);
  font-size: 14px;
  padding: 8px 10px;
  border-radius: 3px;
  min-height: 40px;
  max-width: 100%;
}
.filter-count { font-family: var(--font-mono); font-size: 11px; color: var(--text-dim); margin-left: auto; padding-bottom: 10px; }

.table-wrap { overflow-x: auto; position: relative; }
.name-short { display: none; }
.log-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.log-table th {
  text-align: left;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  font-weight: 400;
  text-transform: uppercase;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border2);
  white-space: nowrap;
}
.log-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; font-variant-numeric: tabular-nums; }
.log-table tbody tr:hover td { background: var(--bg3); }
.log-table .muted { color: var(--text-dim); }
.result-badge { display: inline-block; width: 22px; text-align: center; font-weight: 600; }
.result-badge.correct { color: var(--green); }
.result-badge.missed  { color: #ff6b81; }
#showMore { margin-top: 14px; }

/* ── How it works ──────────────────────────────────────────────────── */
.pipeline { list-style: none; display: grid; gap: 14px; margin-top: 12px; counter-reset: none; }
.pipeline li { display: grid; grid-template-columns: 32px 1fr; gap: 12px; align-items: start; }
.pipeline strong { color: var(--text-bright); font-weight: 600; }
.pipeline p { color: var(--text-dim); font-size: 14px; margin-top: 2px; max-width: 760px; }
.step-n {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 1px solid #00522a;
  background: var(--green-dark);
  color: var(--green);
  font-family: var(--font-mono);
  font-size: 12px;
  display: grid; place-items: center;
}

.stack { list-style: none; display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 8px 20px; margin: 12px 0 10px; font-size: 14px; }
.stack strong { display: block; font-family: var(--font-mono); font-size: 10px; letter-spacing: 1.5px; color: var(--text-dim); text-transform: uppercase; font-weight: 400; }

/* ── Charts ────────────────────────────────────────────────────────── */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { font-family: var(--font-mono); font-size: 11px; fill: var(--text-dim); }
.chart .label-strong { fill: var(--text-bright); font-size: 12px; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axis     { stroke: var(--axis); stroke-width: 1; }
.chart .ref      { stroke: var(--mark-muted); stroke-width: 1; opacity: 0.7; }
.chart .hit      { fill: transparent; cursor: crosshair; }
.chart .hit:focus { outline: none; }
.chart .hit:focus-visible { stroke: var(--green); stroke-width: 1; }
.chart .crosshair { stroke: var(--text-dim); stroke-width: 1; opacity: 0.6; pointer-events: none; }
.chart .hovered { filter: brightness(1.25); }

.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 12.5px; color: var(--text); margin-bottom: 10px; }
.legend-item { display: inline-flex; align-items: center; gap: 8px; }
.legend-key { display: inline-block; width: 16px; height: 2px; border-radius: 1px; }
.legend-key.dot { width: 9px; height: 9px; border-radius: 50%; }

.table-view { margin-top: 12px; }
.table-view summary { cursor: pointer; font-family: var(--font-mono); font-size: 11px; letter-spacing: 1px; color: var(--text-dim); list-style: none; display: inline-block; padding: 4px 0; }
.table-view summary::-webkit-details-marker { display: none; }
.table-view summary::before { content: '▸ '; }
.table-view[open] summary::before { content: '▾ '; }
.table-view summary:hover { color: var(--text); }
.table-view table { margin-top: 8px; }

.tooltip {
  position: fixed;
  z-index: 10000;
  pointer-events: none;
  background: #0b1112;
  border: 1px solid var(--border2);
  border-radius: 4px;
  padding: 8px 10px;
  font-size: 12px;
  color: var(--text);
  box-shadow: 0 6px 20px rgba(0,0,0,0.45);
  max-width: 260px;
}
.tooltip .tt-title { font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 1px; color: var(--text-dim); margin-bottom: 4px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 8px; line-height: 1.6; }
.tooltip .tt-key { width: 12px; height: 2px; border-radius: 1px; flex-shrink: 0; }
.tooltip .tt-val { font-weight: 600; color: var(--text-bright); font-variant-numeric: tabular-nums; }
.tooltip .tt-name { color: var(--text-dim); }

/* ── Footer ────────────────────────────────────────────────────────── */
footer { border-top: 1px solid var(--border); padding: 20px 24px 28px; text-align: center; font-size: 12px; color: var(--text-dim); }

/* ── Mobile bottom navigation ──────────────────────────────────────── */
.bottom-nav { display: none; }

@media (max-width: 860px) {
  .panel-row { grid-template-columns: 1fr; gap: 0; }
}

@media (max-width: 640px) {
  header { padding: 0 16px; }
  .logo-sub { display: none; }
  .model-status { font-size: 10px; max-width: 45%; }
  .tabs { display: none; }
  .tab-content { padding: 20px 16px calc(84px + env(safe-area-inset-bottom)); }
  .page-head h1 { font-size: 25px; }
  .panel { padding: 16px; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpi { padding: 12px 14px; }
  .kpi-value { font-size: 24px; }
  .pitchers { grid-template-columns: 1fr; }
  .factor { grid-template-columns: minmax(0, 1fr) 48px auto; }
  .filter-count { margin-left: 0; width: 100%; padding-bottom: 0; }
  .name-full { display: none; }
  .name-short { display: inline; }
  .log-table td, .log-table th { padding: 8px 6px; }
  footer { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }

  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: var(--bg2);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 200;
  }
  .bottom-nav .nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 10px 4px;
    min-height: 56px;
    color: var(--text-dim);
    text-decoration: none;
    font-family: var(--font-display);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
  }
  .bottom-nav .nav-item.active { color: var(--green); }
  .bottom-nav .nav-icon { font-size: 18px; }
}

@media (max-width: 380px) {
  .kpis { grid-template-columns: 1fr; }
}

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