:root {
  --bg: #0e1117; --panel: #171c26; --panel2: #1f2632; --ink: #eef2f8; --muted: #93a1b8;
  --line: #2a3343; --team: #4cc2ff; --avg: #ffb15c; --accent: #43d6a0; --bad: #ff6b6b;
  --pitch1: #1f6b46; --pitch2: #1b5e3e;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink); position: relative;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 14px;
}
a { color: var(--team); }
h1 { margin: 0; font-size: 21px; letter-spacing: .2px; }
h2 { font-size: 15px; margin: 0 0 8px; color: var(--muted); font-weight: 600; }

/* min-height reserves room for the floating action buttons (.btn-stack, ~149px tall) so the
   stack doesn't spill across the header's bottom border into the pitch. Dropped on mobile,
   where the stack moves into normal flow at the page bottom. */
header { padding: 16px 270px 10px 22px; border-bottom: 1px solid var(--line); min-height: 156px; }
.head-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.meta { color: var(--muted); margin: 4px 0 0; font-size: 12.5px; }
/* Action buttons: pinned top-right on desktop, dropped to the page bottom on mobile. */
.btn-stack {
  position: absolute; top: 16px; right: 22px; z-index: 20;
  display: flex; flex-direction: column; gap: 8px; width: 232px;
}
.btn {
  display: block; text-align: center; text-decoration: none; font-weight: 700;
  padding: 10px 14px; border-radius: 9px; font-size: 13.5px; white-space: nowrap;
  border: 1px solid #00000033; transition: .12s; box-shadow: 0 2px 8px rgba(0,0,0,.18);
}
.btn:hover { filter: brightness(1.06); transform: translateY(-1px); }
.btn.coffee { background: #FFDD00; color: #1a1205; }
.btn.pro { background: var(--team); color: #042330; }
.btn.feedback { background: #ff4d94; color: #2a0716; }
.muted-note { color: var(--muted); }
@media (max-width: 760px) {
  .btn-stack {
    position: static; width: auto; gap: 10px; padding: 4px 16px 30px;
  }
  header { padding-right: 22px; min-height: 0; }
}
.demo-banner {
  background: #3a2a12; border: 1px solid #6b4e1f; color: #ffcf8f;
  padding: 7px 11px; border-radius: 8px; font-size: 12.5px; margin-top: 10px;
}

.controls { display: flex; align-items: center; gap: 14px; margin-top: 12px; flex-wrap: wrap; }
.controls label { color: var(--muted); display: flex; align-items: center; gap: 6px; font-size: 13px; }
select, input, button {
  background: var(--panel2); color: var(--ink); border: 1px solid var(--line);
  border-radius: 7px; padding: 7px 10px; font-size: 13px; font-family: inherit;
}
button { cursor: pointer; }
button:hover { border-color: #3a4458; }
button.primary { background: var(--accent); color: #06231a; border-color: transparent; font-weight: 700; }
.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 3px; }
.seg button { border: none; background: none; padding: 6px 14px; border-radius: 7px; color: var(--muted); }
.seg button.active { background: var(--team); color: #04222f; font-weight: 700; }
.status { color: var(--muted); font-size: 13px; margin-left: auto; }
.status:empty { display: none; } /* no phantom row when there's no status text */

/* minmax(0,…) (not 1fr) lets the main column shrink below its content width, so a too-wide
   pitch row scrolls *inside itself* (the carousel) instead of blowing the whole page sideways. */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; padding: 18px 22px; align-items: start; }
.card-col { position: sticky; top: 14px; }

/* Pitch */
.pitch-col { position: relative; } /* anchor for the desktop scoreboard overlay */
.pitch-wrap { position: relative; }
.scoreboard {
  position: absolute; top: 14px; right: 14px; display: flex; gap: 10px; z-index: 2;
}
.sb {
  background: rgba(8,12,18,.82); border: 1px solid #ffffff22; border-radius: 11px;
  padding: 8px 14px; text-align: right; backdrop-filter: blur(3px); min-width: 96px;
}
.sb b { display: block; font-size: 26px; font-weight: 800; line-height: 1.05; font-variant-numeric: tabular-nums; }
.sb.pts b { color: var(--team); }
.sb.cost b { color: #ffe08a; }
.sb span { display: block; font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin-top: 2px; }
.sb small { color: var(--muted); font-size: 12px; font-weight: 600; }

.pitch {
  background:
    repeating-linear-gradient(0deg, var(--pitch1) 0 9%, var(--pitch2) 9% 18%);
  border: 2px solid #2c8a5d44; border-radius: 14px; padding: 18px 10px;
  display: flex; flex-direction: column; justify-content: space-between; gap: 14px; min-height: 460px;
  box-shadow: inset 0 0 60px rgba(0,0,0,.25);
}
.pitch-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.chip {
  position: relative;
  background: rgba(13,18,26,.86); border: 1px solid #2f3a4d; border-radius: 9px;
  padding: 7px 9px; min-width: 96px; text-align: center; cursor: pointer; transition: .12s;
  /* manipulation = allow tap + scroll but kill Safari's double-tap-to-zoom, which otherwise
     hijacked taps on a chip (there's no hover on touch, so a tap must do the work). */
  touch-action: manipulation;
}
.chip:hover, .chip.active { border-color: var(--team); transform: translateY(-2px); }
.chip.captain { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.chip .nm { display: block; font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 110px; }
.chip .sub { display: block; font-size: 10.5px; color: var(--muted); margin-top: 2px; }
.chip .pts { display: block; font-size: 13px; font-weight: 700; color: var(--team); margin-top: 1px; }
/* Remove button — a real tap target in the corner, so a tap on the chip body previews instead
   of deleting. Sized ≥24px for touch. */
.chip .x {
  position: absolute; top: -8px; right: -8px; width: 24px; height: 24px; line-height: 1;
  border-radius: 50%; border: 1px solid var(--line); background: var(--panel2);
  color: var(--bad); font-size: 12px; font-weight: 700; padding: 0; cursor: pointer;
  display: flex; align-items: center; justify-content: center; box-shadow: 0 1px 4px rgba(0,0,0,.4);
}
.chip .x:hover { background: var(--bad); color: #2a0716; border-color: var(--bad); }
/* Empty formation slot — a dashed prompt that, when tapped, filters the add-list to its position. */
.chip.empty {
  background: rgba(13,18,26,.35); border: 1px dashed #3a4458; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  min-height: 52px;
}
.chip.empty:hover { border-color: var(--team); color: var(--ink); transform: none; }
.chip.empty .plus { font-size: 16px; line-height: 1; }
.bench { margin-top: 12px; }
.bench-head { color: var(--muted); font-size: 12.5px; font-weight: 700; margin-bottom: 6px; }
/* The bench reuses .pitch-row (so it carousels on mobile like the formation lines); left-align
   it instead of the centred pitch rows. */
.bench-row { justify-content: flex-start; }

/* Narrow screens: a full line (5 mids/defs) would wrap onto two rows — swipe it as a
   carousel instead, snapping chip-to-chip, so each line stays one tidy strip. Placed
   after the base .pitch-row rule so the nowrap override actually wins the cascade. */
@media (max-width: 620px) {
  .pitch-row {
    flex-wrap: nowrap; justify-content: flex-start; overflow-x: auto;
    scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch;
    /* overflow-x:auto forces overflow-y to auto, which would clip the corner ✕ — the top/right
       padding keeps the remove button visible inside the scroll box. */
    padding: 10px 8px 6px; scrollbar-width: thin;
  }
  .pitch-row::-webkit-scrollbar { height: 4px; }
  .pitch-row::-webkit-scrollbar-thumb { background: #ffffff2e; border-radius: 4px; }
  .pitch-row .chip { flex: 0 0 auto; scroll-snap-align: center; }
  /* Keep the formation selector on the same row as the mode toggle (build mode) instead of
     wrapping: drop the "Formation" word (the 3-4-3 dropdown is self-explanatory) and tighten. */
  .controls { gap: 10px; }
  .controls .seg button { padding: 6px 10px; }
  .formation-ctl .ctl-label { display: none; }
}

/* Player card */
.player-card-empty { background: var(--panel); border: 1px dashed var(--line); border-radius: 12px; padding: 22px; color: var(--muted); text-align: center; }
.pcard { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.pcard-head { padding: 12px 14px; background: linear-gradient(135deg, #20303f, #182230); }
.pcard-head .nm { font-size: 16px; font-weight: 700; }
.pcard-head .sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.pcard-head .tot { float: right; text-align: right; }
.pcard-head .tot b { font-size: 20px; color: var(--team); }
.pcard-note { padding: 8px 14px 0; color: var(--muted); font-size: 11.5px; line-height: 1.35; }
.pcard-body { padding: 10px 14px 14px; }
.brk { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.brk td { padding: 3px 0; border-bottom: 1px solid var(--line); }
.brk td:nth-child(2) { color: var(--muted); text-align: right; padding-right: 10px; }
.brk td:nth-child(3) { text-align: right; font-variant-numeric: tabular-nums; }
.brk .pos { color: var(--accent); }
.brk .neg { color: var(--bad); }
.spark-label { color: var(--muted); font-size: 11.5px; margin: 12px 0 2px; }
.spark { width: 100%; background: none; }
.spark .sbar { fill: var(--team); opacity: .85; }
.spark .sbaxis { stroke: var(--line); stroke-width: 1; }
.spark .sbtick { fill: var(--muted); font-size: 9px; text-anchor: middle; }

/* Distribution */
.dist-col { padding: 4px 22px 26px; }
svg { width: 100%; background: var(--panel); border-radius: 12px; }
.axis { stroke: var(--line); }
.tick, .chart-title { fill: var(--muted); font-size: 11px; text-anchor: middle; }
.series { fill: none; stroke-width: 2.5; }
.series.team { stroke: var(--team); }
.series.avg { stroke: var(--avg); stroke-dasharray: 4 3; }
.area.team { fill: var(--team); opacity: .12; stroke: none; }
.legend { color: var(--muted); font-size: 13px; margin-top: 6px; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin: 0 5px 0 14px; vertical-align: middle; }
.swatch.team { background: var(--team); } .swatch.avg { background: var(--avg); }

/* Build */
.build-actions { display: flex; gap: 8px; margin: 12px 0 8px; flex-wrap: wrap; }
.build-actions input { flex: 1; min-width: 160px; }
/* Position filter: without it the add-list (sorted by projected points) is all GK/DEF, since
   they out-project MID/FWD — so a browsing user could never reach a midfielder or forward. */
.pos-seg { display: flex; margin: 0 0 8px; }
.pos-seg button { flex: 1; padding: 6px 4px; border: none; background: none; border-radius: 7px; color: var(--muted); font-size: 12.5px; }
.pos-seg button.active { background: var(--team); color: #04222f; font-weight: 700; }
.suggest { font-size: 13px; }
.suggest .swap { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; margin-bottom: 6px; }
.suggest .swap b { color: var(--accent); }
.swap-head { color: var(--muted); margin: 4px 0 6px; font-size: 12.5px; }
.suggest .swap[data-idx] { display: flex; justify-content: space-between; align-items: center; gap: 10px; cursor: pointer; transition: .12s; }
.suggest .swap[data-idx]:hover { border-color: var(--team); transform: translateY(-1px); }
.suggest .swap em { color: var(--muted); font-style: normal; font-size: 11px; }
.suggest .swap .gain { color: var(--accent); font-weight: 700; margin-left: 6px; font-variant-numeric: tabular-nums; }
.player-list { max-height: 320px; overflow-y: auto; margin-top: 6px; border: 1px solid var(--line); border-radius: 9px; }
.pl-row { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-bottom: 1px solid var(--line); cursor: pointer; }
.pl-row:hover { background: var(--panel2); }
.pl-row.disabled { opacity: .55; cursor: default; }
.pl-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl-meta { color: var(--muted); font-size: 12px; white-space: nowrap; }
.pl-row em { color: var(--muted); font-style: normal; font-size: 11px; }
.pl-reason { color: var(--bad); font-size: 10.5px; border: 1px solid #ff6b6b55; border-radius: 5px; padding: 1px 5px; margin-left: 4px; white-space: nowrap; }
.add-btn {
  flex: 0 0 auto; width: 28px; height: 28px; padding: 0; border-radius: 7px;
  background: var(--accent); color: #06231a; border: none; font-size: 17px; font-weight: 700;
  line-height: 1; cursor: pointer; touch-action: manipulation;
}
.add-btn:hover { filter: brightness(1.08); }
.pl-empty { padding: 14px; color: var(--muted); text-align: center; font-size: 12.5px; }

footer { border-top: 1px solid var(--line); padding: 16px 22px 28px; color: var(--muted); font-size: 12.5px; }

@media (max-width: 880px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .card-col { position: static; }
  /* Single-column: the proj-pts/spend boxes become a bar above the pitch that sticks to the top
     of the screen, so the totals stay in view while you scroll down to add players. */
  .scoreboard {
    position: sticky; top: 0; z-index: 5; justify-content: flex-start; gap: 8px;
    background: var(--bg); padding: 8px 0 9px; margin-bottom: 10px; border-bottom: 1px solid var(--line);
  }
  .sb b { font-size: 20px; }
  .sb { padding: 6px 12px; }
}
