/* style.css — the look of the app */

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #0b1f12;
  color: #f5f7f5;
}

.hidden { display: none !important; }

/* Respect users who prefer less motion. */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* Clear keyboard-focus outline everywhere interactive. */
:focus-visible { outline: 3px solid #ffd47a; outline-offset: 2px; }

/* ---------- Top bar / controls ---------- */
.topbar {
  padding: 16px 20px 12px;
  background: #10261a;
  border-bottom: 3px solid #1c4a2e;
}
.topbar h1 { margin: 0 0 4px; font-size: 22px; }
.tagline { margin: 0 0 12px; color: #a9c3b3; font-size: 14px; }

/* Controls are stacked in rows: Offense, then Defense, then the buttons. */
.controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.control-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
}
.row-tag {
  align-self: center;
  min-width: 70px;
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.offense-row .row-tag { background: #d98a0026; color: #ffcf7a; border-left: 3px solid #d98a00; }
.defense-row .row-tag { background: #1f7ad926; color: #9cd2ff; border-left: 3px solid #1f7ad9; }

.controls label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1 1 160px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #a9c3b3;
}
.controls select {
  width: 100%;
  min-width: 0;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid #2c5a3c;
  background: #eefaf1;
  color: #10261a;
  font-size: 15px;
  font-weight: 600;
}
#refresh,
#reset {
  padding: 10px 16px;
  border-radius: 8px;
  border: none;
  background: #2e7d46;
  color: white;
  font-weight: 700;
  cursor: pointer;
}
#refresh:hover,
#reset:hover { background: #379a55; }
#reset { background: #3a4a41; }
#reset:hover { background: #4a5d52; }

.legend {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: #a9c3b3;
}

/* ---------- Status line ---------- */
.status {
  text-align: center;
  padding: 8px;
  margin: 0;
  min-height: 20px;
  color: #ffd47a;
  font-size: 14px;
}
.status .retry { margin-left: 8px; background: #17442a; color: #eaf2ec; border: 1px solid #2c5c3d; border-radius: 8px; padding: 4px 12px; font-size: 12px; font-weight: 600; cursor: pointer; }
.stale-banner { max-width: 640px; margin: 0 auto 8px; padding: 8px 14px; border-radius: 8px; background: #3a2a0e; color: #f0cd8a; border: 1px solid #6b501a; font-size: 13px; text-align: center; }
.stale-banner.hidden { display: none; }
.updated { margin-left: 10px; font-size: 11px; color: #9fb0a4; white-space: nowrap; }
.field.loading { opacity: 0.5; transition: opacity 0.15s ease; }

/* ---------- The field ---------- */
/* On narrow screens the field is wider than the viewport, so it scrolls
   sideways inside this wrapper instead of squishing the players together. */
.field-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain; /* a sideways swipe on the field stays in the field — no page back-nav / bounce on mobile */
}
.field {
  position: relative;
  max-width: 900px;
  container-type: inline-size; /* chips size off the field width (no edge clipping on narrow) */
  margin: 8px auto 40px;
  border: 4px solid #ffffff33;
  border-radius: 10px;
  overflow: hidden;
  background:
    repeating-linear-gradient(
      to bottom,
      #1f7a3d 0px,
      #1f7a3d 48px,
      #1b6e37 48px,
      #1b6e37 96px
    );
}
.field-half {
  position: relative;
  height: 300px;
}
.formation-label {
  position: absolute;
  left: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px 5px 8px;
  background: #00000088;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: #ffffff;
  text-shadow: 0 1px 2px #000000cc;
  z-index: 3;
}
.formation-label img { height: 26px; width: 26px; object-fit: contain; }
.formation-label .updated { font-weight: 500; opacity: 0.85; font-size: 11px; }
.formation-label .band-next { font-weight: 600; opacity: 0.82; font-size: 11px; white-space: nowrap; }
@media (max-width: 620px) { .formation-label .band-next { display: none; } }
/* Defense sits on top of the field, offense on the bottom, so their labels
   hug the outer edges (away from the line of scrimmage in the middle). */
.defense-half .formation-label { top: 10px; }
.offense-half .formation-label { bottom: 10px; }

/* A faint wash of the team's color over each half. */
.tint { position: absolute; inset: 0; z-index: 1; pointer-events: none; }

/* container that holds absolutely-positioned player chips */
.players { position: absolute; inset: 0; z-index: 2; }

/* the line of scrimmage in the middle */
.midline {
  position: relative;
  height: 0;
  border-top: 3px dashed #ffffffaa;
  text-align: center;
}
.midline span {
  position: absolute;
  left: 50%;
  top: -9px;
  transform: translateX(-50%);
  background: #0b1f12;
  padding: 0 10px;
  font-size: 10px;
  letter-spacing: 0.15em;
  color: #ffffffaa;
}

/* ---------- Player chips ---------- */
.chip {
  position: absolute;
  transform: translate(-50%, -50%);
  width: clamp(60px, 10cqw, 88px);
  padding: 4px 5px 5px;
  border-radius: 10px;
  background: #ffffff;
  color: #10261a;
  text-align: center;
  cursor: grab;
  box-shadow: 0 2px 6px #00000055;
  border: 2px solid transparent;
  transition: border-color 0.08s ease, box-shadow 0.08s ease;
  /* let us drag with touch/mouse without the page scrolling or selecting text */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.chip:hover { border-color: #ffd47a; }
/* while being dragged, lift it above the others and show the grabbing cursor */
.chip.dragging {
  cursor: grabbing;
  z-index: 20;
  box-shadow: 0 6px 16px #000000aa;
  border-color: #ffd47a;
  transition: none; /* transform-drag: don't animate the live translate */
  will-change: transform; /* promote only the in-flight chip to its own layer so per-frame drag is compositor-only (no surface re-raster on low-end phones) */
}
/* Search-dim: chips whose starter doesn't match the query fade back and stop taking taps. */
.chip.chip-dim { opacity: 0.25; filter: grayscale(1); pointer-events: none; }
.offense-half .chip { border-top: 4px solid #d98a00; }
.defense-half .chip { border-top: 4px solid #1f7ad9; }

.chip .pos {
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #4a6a56;
}
.chip .name {
  font-size: clamp(9.5px, 1.5cqw, 11.5px);
  font-weight: 700;
  line-height: 1.12;
  margin-top: 1px;
}
.chip .depth-count {
  font-size: 8.5px;
  color: #566b60; /* darker for readable contrast on the white chip */
  margin-top: 2px;
}

/* ---------- Injury badges ---------- */
.badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  color: #10261a;
}
.badge.out { background: #d1382f; color: #fff; } /* darker red -> passes WCAG AA */
.badge.questionable { background: #ffd166; }
.badge.other { background: #c7d3cc; }
.chip .badge { margin-top: 3px; }

/* ---------- Depth chart popover ---------- */
.popover {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(360px, 92vw);
  max-height: 80vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: #10261a;
  border: 2px solid #2e7d46;
  border-radius: 12px;
  box-shadow: 0 12px 40px #000000aa;
  z-index: 301; /* ABOVE the sticky site-nav (200) so its tall mobile rows can't hide the ✕ */
}
.popover.hidden { display: none; }
.popover-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid #2c5a3c;
  font-weight: 800;
  position: sticky; /* keep the ✕ visible no matter how many players scroll past */
  top: 0;
  z-index: 1;
  background: #10261a;
}
.popover-head > span:first-child { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#popover-close {
  flex: 0 0 auto;    /* never shrink / get pushed off by a long title */
  background: #17442a;
  border: 1px solid #2c5a3c;
  color: #eaf2ec;
  font-size: 18px;
  cursor: pointer;
  min-width: 44px;   /* comfortable tap target */
  min-height: 44px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px;
}
#popover-close:hover { background: #1e5836; }
/* Prev/next steppers flanking the title — same 44px touch target as the ✕, lighter weight. */
.popover-nav {
  flex: 0 0 auto;
  background: #17442a;
  border: 1px solid #2c5a3c;
  color: #eaf2ec;
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px;
}
.popover-nav:hover { background: #1e5836; }
.popover-nav[hidden] { display: none; }
.popover ol { margin: 0; padding: 8px 0; list-style: none; }
.popover li {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 8px 14px;
}
.popover .p-main { display: flex; align-items: center; gap: 8px; }
.popover .p-bio { font-size: 11px; color: #8fb0a0; padding-left: 28px; } /* height · weight · college · exp */
.popover .p-injury { font-size: 11px; color: #f0b37e; padding-left: 42px; margin-top: 2px; } /* ⚕ what + expected return */
.popover li.starter { background: #16351f; }
.popover .rank {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #2e7d46;
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.popover li.starter .rank { background: #ffd166; color: #10261a; }
.popover .p-num { color: #a9c3b3; font-size: 12px; width: 30px; }
.popover .p-name { flex: 1; font-weight: 600; }
.popover .p-ovr {
  color: #10261a;
  background: #ffd166;
  font-weight: 800;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 6px;
  min-width: 46px;
  text-align: center;
}
.popover .p-age { color: #a9c3b3; font-size: 12px; min-width: 42px; text-align: right; }
/* Rich popover parity with the other sports: headshot, ESPN link, lazy stat line. */
.popover .p-photo { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; background: #0c2416; border: 1px solid #29513a; flex: 0 0 auto; }
.popover li.starter .p-photo { width: 46px; height: 46px; }
.popover .p-photo-blank { display: inline-flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 800; color: #a9c3b3; }
.popover .p-espn { color: #7fd4a1; text-decoration: none; font-weight: 800; font-size: 14px; padding: 0 2px; }
.popover .p-espn:hover { color: #eaf2ec; }
.popover .p-stats { display: flex; flex-wrap: wrap; gap: 14px; padding: 3px 0 2px 42px; font-size: 12px; color: #a9c3b3; }
.popover .p-stats[data-loading] { opacity: 0.55; font-style: italic; }
.popover .p-stats .stat b { color: #eaf2ec; font-size: 15px; font-weight: 800; margin-right: 3px; }
/* [U1] Non-starter rows expand to reveal a stat line; a caret + pointer signal it. */
.popover li.p-expandable { cursor: pointer; }
.popover li.p-expandable:hover .p-name { color: #eaf2ec; }
.popover li.p-expandable:hover .p-main::after { color: #a9c3b3; }
.popover li.p-expandable .p-main::after { content: "\25B8"; color: #5f7a6c; font-size: 11px; flex: none; transition: transform 0.15s ease; }
.popover li.p-expandable[aria-expanded="true"] .p-main::after { transform: rotate(90deg); color: #7fd4a1; }
.popover-note {
  padding: 8px 14px 12px;
  font-size: 10px;
  color: #7a8f83;
  border-top: 1px solid #2c5a3c;
}

/* click-catcher behind the popover */
.backdrop {
  position: fixed;
  inset: 0;
  background: #000000aa;
  z-index: 300; /* above the sticky site-nav (200) so tap-to-close works over the whole screen */
}
.backdrop.hidden { display: none; }

/* ---------- View toggle (Field / List) — sits up top for quick access ---------- */
.view-toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 12px;
}
.view-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #a9c3b3;
}
.view-toggle {
  display: inline-flex;
  border: 1px solid #2c5a3c;
  border-radius: 8px;
  overflow: hidden;
}
.view-toggle button {
  border: none;
  background: #16351f;
  color: #cfe0d6;
  font-weight: 700;
  padding: 10px 18px;
  cursor: pointer;
}
.view-toggle button.active { background: #2e7d46; color: #fff; }
/* Find-a-player box: styled like the other controls, ~150px, subtle. */
.player-search { width: 150px; max-width: 40vw; background: #eefaf1; color: #10261a; border: 1px solid #2c5a3c; border-radius: 8px; padding: 7px 10px; font-size: 13px; }
.player-search::placeholder { color: #6d8577; }
.player-search:focus-visible { outline: 2px solid #ffd47a; outline-offset: 1px; }

/* ---------- Scroll hint (mobile field view) ---------- */
.scroll-hint {
  display: none;
  text-align: center;
  margin: -4px 12px 12px;
  font-size: 12px;
  color: #a9c3b3;
}

/* ---------- List view ---------- */
.list-view { max-width: 640px; margin: 8px auto 40px; padding: 0 12px; }
.list-section { margin-bottom: 18px; content-visibility: auto; contain-intrinsic-size: auto 600px; } /* skip layout/paint of the offscreen (offense) section at first paint */
.list-section h2 {
  font-size: 14px;
  margin: 0 0 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #16351f;
}
.list-section.offense h2 { border-left: 4px solid #d98a00; }
.list-section.defense h2 { border-left: 4px solid #1f7ad9; }
.list-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  text-align: left;
  padding: 8px 12px;
  margin-bottom: 6px;
  border: 1px solid #2c5a3c;
  border-radius: 10px;
  background: #ffffff;
  color: #10261a;
  font-size: 14px;
  cursor: pointer;
}
.list-row:hover { border-color: #ffd47a; }
.list-row.search-hidden { display: none !important; } /* filtered out by the player search */
.list-photo { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; flex: 0 0 auto; }
.list-photo-blank { background: #0002; }
.list-row .list-pos {
  font-size: 11px;
  font-weight: 800;
  color: #4a6a56;
  min-width: 52px;
}
.list-row .list-name { flex: 1; font-weight: 700; }
.list-row .list-num { color: #566b60; font-weight: 500; font-size: 12px; }
.list-row .list-depth { color: #566b60; font-size: 12px; }
/* Video-game overall rating on list rows (parity with the other sports). */
.list-row .list-ovr { font-size: 12px; font-weight: 900; color: #241a00; background: linear-gradient(180deg, #ffd85a, #e8b500); padding: 1px 7px; border-radius: 6px; border: 1px solid #b98f00; }

/* ---------- Loading skeletons (first cold load) ---------- */
/* Neutral tinted blocks that stand in for chips/rows until data arrives. The shimmer
   only runs when the user hasn't asked for reduced motion (see the media query below). */
.skeleton { background: #ffffff14; border-color: #ffffff14 !important; color: transparent !important; box-shadow: none; pointer-events: none; }
.skeleton * { visibility: hidden; }
.list-row.skeleton { min-height: 44px; }
@media (prefers-reduced-motion: no-preference) {
  .skeleton { animation: skeleton-pulse 1.2s ease-in-out infinite; }
  @keyframes skeleton-pulse { 0%, 100% { opacity: 0.5; } 50% { opacity: 0.85; } }
}

/* ---------- Compare drawer (player vs player) ---------- */
/* Ported from surface/style.css; surface's var(--ink)/var(--muted) are inlined here
   (this stylesheet has no :root vars) as the equivalent NFL-theme colors. */
.compare-drawer { position: fixed; left: 0; right: 0; bottom: 0; z-index: 90; background: #0e2719; border-top: 2px solid #2c5c3d; box-shadow: 0 -10px 30px #0009; padding: 12px 14px calc(16px + env(safe-area-inset-bottom)); }
.cmp-close { position: absolute; top: 6px; right: 12px; background: transparent; border: 0; color: #a9c3b3; font-size: 18px; cursor: pointer; }
.cmp-grid { max-width: 720px; margin: 0 auto; display: grid; grid-template-columns: 1fr auto 1fr; align-items: start; gap: 12px; }
.cmp-vs { align-self: center; color: #a9c3b3; font-weight: 800; font-size: 13px; }
.cmp-col { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 3px; }
.cmp-col.cmp-empty { color: #a9c3b3; font-size: 12px; padding: 28px 0; justify-content: center; }
.cmp-photo { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; background: #0c2416; border: 1px solid #29513a; }
.cmp-name { font-weight: 800; font-size: 14px; }
.cmp-team { color: #a9c3b3; font-size: 11px; }
.cmp-ovr { font-size: 13px; font-weight: 900; color: #241a00; background: linear-gradient(180deg, #ffd85a, #e8b500); padding: 1px 7px; border-radius: 7px; }
.cmp-ovr i { font-style: normal; font-size: 8px; opacity: 0.75; margin-left: 2px; }
.cmp-bio { color: #8fb0a0; font-size: 11px; }
.cmp-stats { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; font-size: 12px; color: #a9c3b3; margin-top: 3px; }
.cmp-stats[data-loading] { opacity: 0.55; font-style: italic; }
.cmp-stats .stat b { color: #eaf2ec; font-weight: 800; margin-right: 2px; }
.cmp-stats .stat.better b { color: #7fd4a1; }
/* [U3] A pinned player reads as "locked in" — the photo gets a green ring. */
.cmp-col.cmp-selected .cmp-photo { border-color: #7fd4a1; box-shadow: 0 0 0 2px rgba(127, 212, 161, 0.45); }
#compare.active { color: #06140b; background: #3ea06a; border-color: #3ea06a; }

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  /* Reserve space so the fixed compare drawer never hides the last players/rows. */
  body.cmp-open { padding-bottom: 210px; }
  .topbar { padding: 12px 14px 10px; }
  .topbar h1 { font-size: 18px; }
  .tagline { font-size: 13px; margin-bottom: 10px; }

  /* Two controls per row on phones; the row tag sits on its own line. */
  .row-tag { flex-basis: 100%; min-width: 0; }
  .controls label { flex: 1 1 130px; }
  .control-row.actions button { flex: 1 1 auto; }
  /* Big, obvious toggle up top so switching to Field is one easy tap. */
  .view-toggle { flex: 1; }
  .view-toggle button { flex: 1; padding: 13px 12px; font-size: 15px; }

  /* Keep the field readable by giving it a fixed width and letting the wrapper
     scroll sideways; the hint tells the user there's more to the sides. */
  .field {
    min-width: 660px;
    margin: 8px 12px 8px;
  }
  .field-half { height: 260px; }
  .scroll-hint:not(.hidden) { display: block; }

  /* Slightly smaller but still tappable chips. */
  .chip { width: 74px; min-height: 44px; }
  .chip .name { font-size: 11px; }

  /* Depth popover as a bottom sheet on phones: full width, anchored to the bottom, ✕
     header pinned at the top and always visible however many players a position has. */
  .popover {
    top: auto; bottom: 0; left: 0; right: 0; transform: none;
    width: 100%; max-width: 100%; max-height: 85vh;
    border-radius: 16px 16px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* iOS Safari auto-zooms the viewport when a focused form control is under 16px. Bump the
   controls (team/personnel/formation/season selects + the player-search input) to 16px on
   phones so focusing them doesn't yank the layout; pinch-zoom stays allowed. */
@media (max-width: 760px) {
  select, input, textarea, .player-search { font-size: 16px !important; }
}
