:root {
  --bg: #eeeeee;
  --surface: #ffffff;
  --ink: #222;
  --muted: #777;
  --border: #d8d8d8;
  --primary: #013369;       /* NFL navy */
  --accent:  #d50a0a;       /* NFL red */
  --hover-tint: rgba(187,187,187,0.55);
  --header-tint: #fff36b;   /* sticky-header hover yellow */
  --select-ring: magenta;
  --col-count: 9;       /* dynamic — number of position columns currently displayed */
  --cell-w: 56px;
  --cell-h: 14px;
  --label-w: 44px;
  --header-h: 28px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

header {
  padding: 24px 24px 8px;
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 12px 20px;
}
header h1 {
  font-family: 'Arvo', serif;
  font-weight: 700;
  font-size: 2.2em;
  margin: 0;
  letter-spacing: 0.02em;
}
.subtitle { margin: 0; color: var(--muted); }

.controls {
  display: flex;
  gap: 18px;
  align-items: center;
  padding: 8px 24px 16px;
  flex-wrap: wrap;
}
.toggle { display: flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }
.era-buttons { display: flex; gap: 4px; }
.era-buttons button {
  background: white;
  border: 1px solid var(--border);
  padding: 4px 10px;
  font: inherit;
  cursor: pointer;
  border-radius: 4px;
}
.era-buttons button.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.splits {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.splits-label {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 600;
}
.splits .toggle { font-size: 13px; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 280px) min-content minmax(0, 360px);
  gap: 28px;
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 24px 24px;
  align-items: start;
}
main#chart {
  padding: 0;
}
.rail { font-size: 13px; }
.rail--left {
  position: sticky;
  top: 12px;
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.rail--right {
  position: relative;
  min-height: var(--grid-height, auto);
}

/* === LATEST DRAFTIGAMI hero card === */
.latest-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 4px solid var(--accent);
  border-radius: 6px;
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.latest-card .eyebrow {
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}
.latest-card .eyebrow::before { content: "🟥  "; }
.latest-card .coord {
  font-family: 'Arvo', serif;
  font-size: 22px;
  line-height: 1.1;
  letter-spacing: 0.02em;
}
.latest-card .player { font-weight: 600; font-size: 15px; }
.latest-card .meta { color: var(--muted); font-size: 12px; line-height: 1.5; }
.latest-card .jump-btn {
  margin-top: 4px;
  align-self: flex-start;
  background: var(--primary);
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 4px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.latest-card .jump-btn:hover { background: #002558; }

/* === stat tiles === */
.stat-tiles {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat-tile .num {
  font-family: 'Arvo', serif;
  font-size: 22px;
  line-height: 1;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.stat-tile .lbl {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.stat-tile.full { grid-column: 1 / -1; }
.stat-tile.full .num { font-size: 17px; }
.stat-tile.full .num a { color: var(--primary); text-decoration: none; }
.stat-tile.full .num a:hover { text-decoration: underline; }
.grid {
  display: grid;
  grid-template-rows: var(--header-h);
  grid-auto-rows: var(--cell-h);
  font-size: 11px;
  background: var(--surface);
  border: 1px solid var(--border);
  width: max-content;
}
.col-headers,
.row {
  display: contents;
}
.col-header,
.row-label {
  background: var(--surface);
  font-weight: 600;
  color: var(--ink);
  padding: 0 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  position: sticky;
}
.col-header {
  top: 0;
  height: var(--header-h);
  width: var(--cell-w);
  font-size: 13px;
  font-family: 'Arvo', serif;
  letter-spacing: 0.04em;
  color: var(--ink);
  background: var(--surface);
  z-index: 10;
  box-shadow: 0 1px 0 var(--border);
}
.row-label {
  left: 0;
  width: var(--label-w);
  justify-content: flex-end;
  padding-right: 8px;
  background: var(--surface);
  z-index: 5;
  font-variant-numeric: tabular-nums;
  font-size: 10px;
  color: var(--muted);
}
.row-label--dim { color: #c0c0c0; }
.col-header.hi, .row-label.hi { background: var(--header-tint); color: black; }
.corner-cell {
  position: sticky;
  top: 0;
  left: 0;
  z-index: 15;
  width: var(--label-w);
  height: var(--header-h);
  background: var(--surface);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.cell {
  width: var(--cell-w);
  height: var(--cell-h);
  border-right: 1px solid #f1f1f1;
  border-bottom: 1px solid #f1f1f1;
  background: white;
  position: relative;
}
.cell.has { background: var(--primary); }
.cell.cross { box-shadow: inset 0 0 0 9999px var(--hover-tint); }
.cell.selected { box-shadow: inset 0 0 0 3px var(--select-ring); }
.cell[data-annotated="true"] { box-shadow: inset -3px 0 0 var(--accent); }
.cell[data-annotated="true"].selected { box-shadow: inset -3px 0 0 var(--accent), inset 0 0 0 3px var(--select-ring); }

/* === editorial annotations (right rail) === */
.rail--right .ann {
  position: absolute;
  left: 0;
  width: 100%;
  padding: 8px 12px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 0 4px 4px 0;
  cursor: pointer;
  font-size: 12px;
  line-height: 1.45;
  transition: box-shadow 120ms ease, transform 120ms ease;
}
.rail--right .ann:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  transform: translateX(1px);
}
.rail--right .ann-coord {
  font-family: 'Arvo', serif;
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.rail--right .ann h3 {
  margin: 4px 0 6px;
  font-family: 'Arvo', serif;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
}
.rail--right .ann p { margin: 0; color: #444; }
.rail--right .ann::before {
  content: "";
  position: absolute;
  left: -16px;
  top: 14px;
  width: 13px;
  border-top: 1px dashed var(--accent);
}

.loading { color: var(--muted); padding: 24px 0; }

dialog#cell-modal {
  border: none;
  border-radius: 8px;
  padding: 20px 24px;
  max-width: 480px;
  width: 90vw;
  box-shadow: 0 12px 40px rgba(0,0,0,0.25);
}
dialog#cell-modal::backdrop { background: rgba(0,0,0,0.4); }
dialog .close {
  position: absolute; top: 8px; right: 12px;
  background: none; border: none; font-size: 22px; cursor: pointer;
}
dialog h2 { font-family: 'Arvo', serif; margin: 0 0 4px; font-size: 1.1em; }
dialog .muted { color: var(--muted); margin: 0 0 12px; }
dialog ul { margin: 0; padding: 0; list-style: none; max-height: 300px; overflow-y: auto; }
dialog li {
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
}
dialog li .yr { color: var(--muted); font-variant-numeric: tabular-nums; }
dialog #copy-link {
  margin-top: 12px;
  background: var(--primary);
  color: white;
  border: none;
  padding: 8px 14px;
  border-radius: 4px;
  cursor: pointer;
  font: inherit;
}

.faq { padding: 24px; max-width: 720px; }
.faq h2 { font-family: 'Arvo', serif; font-size: 1.2em; }
.faq details { border-top: 1px solid var(--border); padding: 8px 0; }
.faq summary { cursor: pointer; font-weight: 600; }
.faq details[open] summary { margin-bottom: 8px; }
.video-embed {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  margin: 12px 0;
  background: #000;
  border-radius: 4px;
  overflow: hidden;
}
.video-embed iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

footer {
  padding: 16px 24px 32px;
  color: var(--muted);
  font-size: 12px;
  border-top: 1px solid var(--border);
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: minmax(0, 720px);
    justify-content: center;
    gap: 20px;
  }
  .rail--left {
    position: static;
    max-height: none;
    flex-direction: row;
    flex-wrap: wrap;
  }
  .rail--left .latest-card { flex: 1 1 240px; }
  .rail--left .stat-tiles { flex: 2 1 320px; }
  /* IMPORTANT: no overflow on main here. overflow creates a new sticky containing
     block which breaks the position-sticky col-headers. Cells are sized via the
     <600px breakpoint to fit narrow viewports without needing horizontal scroll. */
  main#chart { order: 2; max-width: 100%; }
  .rail--right { order: 3; min-height: 0; }
  .rail--right .ann {
    position: static;
    margin-bottom: 12px;
  }
  .rail--right .ann::before { display: none; }
}

/* Phone viewports: cells stretch to fill the viewport edge-to-edge so the chart
   takes the full L-to-R real estate. Cell width is clamped to a sane range —
   on tiny phones cells shrink to 28px, on bigger phones they grow up toward 56px,
   always summing to roughly (viewport - label - layout-padding). Body is the only
   scrolling ancestor → sticky col-headers pin to viewport top. */
@media (max-width: 600px) {
  :root {
    --cell-w: clamp(24px, calc((100vw - 40px - 24px) / var(--col-count)), 56px);
    --cell-h: 20px;
    --label-w: 40px;
    --header-h: 34px;
  }
  .grid { font-size: 12px; }
  .col-header { font-size: 14px; letter-spacing: 0.04em; }
  .row-label { font-size: 11px; padding-right: 6px; }
  .stat-tiles { grid-template-columns: 1fr 1fr; }
  .latest-card .coord { font-size: 20px; }
  .latest-card .player { font-size: 16px; }
  .latest-card .meta { font-size: 13px; }
  .stat-tile .num { font-size: 20px; }
  .stat-tile .lbl { font-size: 12px; }
  .controls { padding: 6px 12px 12px; gap: 12px; font-size: 14px; }
  .era-buttons button { padding: 6px 12px; font-size: 14px; }
  header { padding: 16px 12px 4px; }
  header h1 { font-size: 1.7em; }
  .layout { padding: 0 12px 24px; gap: 16px; }
  .rail--right .ann { font-size: 13px; line-height: 1.5; }
  .rail--right .ann h3 { font-size: 15px; }
}
