/* --- Mobile polish for iOS Safari --- */
/* =========================================================
   1) Design Tokens / Base
   ========================================================= */
:root {
  --gap-xxs: 6px; --gap-xs: 10px; --gap-s: 12px; --gap-m: 16px; --gap-l: 20px; --gap-xl: 26px;
  --radius: 10px;
  --card: rgba(255,255,255,0.06);
  --card-b: rgba(255,255,255,0.10);
  --muted: rgba(255,255,255,0.65);
  /* accent used in buttons; fallback provided where referenced */
}

html { -webkit-text-size-adjust: 100%; }

label { font-size: 12px; color: var(--muted); }

select,
input[type="text"],
input[type="number"] {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--card-b);
  background: rgba(255,255,255,0.04);
  color: inherit;
  -webkit-appearance: none;
}

input[type="number"] { text-align: center; min-width: 54px; }

/* =========================================================
   2) Containers / Panels
   ========================================================= */
section, .section {
  margin: var(--gap-l) 0;
  padding: var(--gap-m);
  background: var(--card);
  border: 1px solid var(--card-b);
  border-radius: var(--radius);
}

/* =========================================================
   3) Roster
   ========================================================= */
.roster-controls{
  padding: 12px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--card-b);
  border-radius: 12px;
  margin-bottom: var(--gap-m);
  gap: 12px;
  display: grid;
  grid-auto-rows: minmax(44px, auto);
}
.roster-controls::before{
  content: "Settings";
  display: block;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--muted);
  letter-spacing: .2px;
}

/* Cards */
.card, .player-card {
  margin-bottom: var(--gap-m);
  padding: var(--gap-m);
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--card-b);
  border-radius: var(--radius);
}
.card .grid, .player-card__fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap-s) var(--gap-m);
}
.card .grid .field, .player-card__fields .field {
  display: grid;
  gap: var(--gap-xxs);
}

/* =========================================================
   4) Game Setup
   ========================================================= */
.setup-block { display: grid; gap: var(--gap-m); }

.role-row {
  display: grid;
  grid-template-columns: minmax(0,1fr) 120px 120px auto;
  gap: var(--gap-m);
  align-items: end;
  padding-top: 12px;
}
.role-row + .role-row{
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px dashed var(--card-b);
}
.role-row .cell { display: grid; gap: var(--gap-xxs); }
.role-row .cell:first-child label{
  font-weight: 700;
  font-size: 14px;
  letter-spacing: .2px;
  color: #e7edf6;
}

/* Normalize control & row heights for perfect column alignment */
.row select,
.row input[type="number"],
.row input[type="text"] {
  height: 44px;
  line-height: 44px; /* keeps text vertically centered */
}
.twocol .row {
  align-items: center;   /* center labels vs controls */
  min-height: 64px;      /* equalize pitcher/catcher rows */
}

/* Rest-day pill (spacing + look) */
.pill {
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  line-height: 1.2;
  border: 1px solid var(--card-b);
  background: rgba(255,255,255,0.08);
  text-align: center;
  white-space: nowrap;
  margin: 10px 6px 14px 6px;
  display: inline-block;
}

/* Rest-day badges + catcher spacers (keep exact same footprint) */
.badge { padding: 8px 12px; }
.row .badge {
  margin-top: 12px;
  margin-bottom: 24px;
  display: inline-block;
}
.badge.spacer {
  display: inline-block;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--card-b);
  margin-top: 12px;
  margin-bottom: 24px;
  min-width: 88px;  /* prevents collapse */
  opacity: 0;       /* invisible but reserves space */
}

/* Inning tracker bar */
.bar {
  height: 8px;
  background: #0e1627;
  border-radius: 8px;
  overflow: hidden;
  margin-top: 8px; /* space between text and green bar */
}
.bar > span { display: block; height: 8px; background: #22c55e; }

/* =========================================================
   5) Buttons
   ========================================================= */
/* Brighter, larger buttons with accent glow */
button, .btn, .actions button {
  padding: 12px 18px;
  border-radius: 12px;
  font-weight: 700;
  border: 1px solid var(--accent, #69a6ff);
  background: rgba(105,166,255,0.18); /* fallback */
  background: color-mix(in oklab, var(--accent) 18%, transparent);
  box-shadow:
    0 0 0 1px rgba(105,166,255,0.28) inset,
    0 8px 20px rgba(105,166,255,0.18);
  transition: background .15s ease, box-shadow .15s ease, transform .05s ease;
  color: #ffffff; /* default white text */
}
button:hover, .btn:hover, .actions button:hover {
  background: rgba(105,166,255,0.28);
  background: color-mix(in oklab, var(--accent) 28%, transparent);
  box-shadow:
    0 0 0 1px rgba(105,166,255,0.38) inset,
    0 10px 28px rgba(105,166,255,0.25);
}
button:active, .btn:active, .actions button:active { transform: translateY(1px); }

/* Force white for key action buttons (guards against overrides) */
#buildBtn,
#toggleEdit,
.actions button { color: #ffffff !important; }

/* =========================================================
   6) Responsive
   ========================================================= */
/* Mobile (phones) */
@media (max-width: 720px) {
  .roster-controls { grid-template-columns: 1fr; }
  .card .grid, .player-card__fields { grid-template-columns: 1fr 1fr; }
  .role-row { grid-template-columns: 1fr !important; }
  .role-row > .cell { margin-bottom: 12px; }
  .role-row + .role-row { margin-top: 24px; padding-top: 20px; }
  .setup-block { display: flex; flex-direction: column; gap: 18px; }
  .panel h2 + .flex { flex-direction: column; gap: 12px; }
}

/* Desktop (wider) */
@media (min-width: 721px) {
  .card .grid, .player-card__fields { grid-template-columns: repeat(4, minmax(0,1fr)); }
  .role-row { grid-template-columns: minmax(280px,2fr) 120px 120px auto; }
}

/* Larger desktop refinements */
@media (min-width: 900px) {
  .twocol {
    grid-template-columns: 1fr 1fr;
    column-gap: 48px;
    align-items: start;
  }
  .twocol > div h3 { margin-top: 0; }
  .row { align-items: center; }
  .row select, .row input { height: 42px; } /* consistent control height */
}

/* Prevent select text from clipping; let iOS render natural line-height */
.row select {
  line-height: normal;          /* undo the 44px line-height for selects */
  padding-top: 10px;            /* keep the visual height you like */
  padding-bottom: 10px;
  white-space: nowrap;          /* don't wrap player names */
}

/* Make the select take priority width in the row */
.row select {
  flex: 1 1 280px;              /* grow, and don't shrink below ~280px */
  min-width: 220px;             /* absolute floor so names remain visible */
}

/* Give the number inputs a bit less width so select has room */
@media (min-width: 900px) {
  .row input[type="number"] {
    min-width: 54px;            /* was larger; trims a few px */
    flex: 0 0 54px;             /* fixed so it won't steal width */
  }
  .row .mini { min-width: auto; } /* let "Innings"/"Pitches" labels flex */
}

/* Keep the overall control height consistent, without forcing line-height on selects */
.row select,
.row input[type="number"],
.row input[type="text"] {
  height: 44px;
}

/* --- FIX iOS SELECT CLIPPING & CENTERING --- */
/* 1) Stop forcing a fixed line-height on selects */
.row select {
  height: auto !important;     /* let iOS size it naturally */
  min-height: 44px;            /* keep tap target big */
  line-height: normal !important;
  padding-top: 10px;
  padding-bottom: 10px;
  display: block;              /* avoids inline-box quirks */
  white-space: nowrap;         /* don't wrap names */
  -webkit-appearance: menulist;/* restore native metrics */
  background-clip: padding-box;/* prevent border clipping */
}

/* 2) Keep fixed height only on inputs, not selects */
.row input[type="number"],
.row input[type="text"] {
  height: 44px;
  line-height: 44px;
}

/* Optional: crisper focus ring without shifting layout */
.row select:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(105,166,255,.55);
}

/* ================================
   Unified SELECT style (app look)
   — no clipping, matches inputs
   ================================ */
.row select {
  /* Use custom look, not the grey iOS menulist */
  -webkit-appearance: none !important;
  appearance: none !important;

  /* Size: do NOT force line-height == height */
  height: 44px;
  min-height: 44px;
  line-height: 1.2;                 /* natural text baseline (prevents clipping) */
  padding: 10px 36px 10px 12px;     /* extra right room for caret */

  /* Match your input visuals */
  border-radius: 10px;
  border: 1px solid var(--card-b);
  background: rgba(255,255,255,0.04);
  color: inherit;

  /* Keep single-line names and avoid wrap */
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;

  /* Custom caret to replace the native one */
  background-image:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%69a6ff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 14px;
  background-clip: padding-box;      /* avoids border artifacts */
}

/* Focus style to match buttons/inputs */
.row select:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(105,166,255,.45);
  border-color: rgba(105,166,255,.65);
}

/* Give selects width priority so names stay visible */
.row select { flex: 1 1 280px; min-width: 220px; }

/* Inputs keep fixed height (for row alignment) */
.row input[type="number"],
.row input[type="text"] {
  height: 44px;
  line-height: 44px;
}

/* Desktop tweak: number inputs don’t steal width from the select */
@media (min-width: 900px) {
  .row input[type="number"] { flex: 0 0 54px; min-width: 54px; }
  .row .mini { min-width: auto; }
}

/* === SELECT: app look, no clipping, overrides previous !important rules === */
.twocol .row select,
.row select,
select {
  /* take back control from earlier menulist !important */
  -webkit-appearance: none !important;
  appearance: none !important;

  /* iOS-safe sizing (no fixed line-height) */
  height: auto !important;
  min-height: 44px !important;
  line-height: normal !important;
  font-size: 16px;                 /* prevents iOS zoom + baseline quirks */
  box-sizing: border-box !important;
  display: block;

  /* visual match with inputs */
  padding: 10px 36px 10px 12px !important;  /* space for caret */
  border-radius: 10px !important;
  border: 1px solid var(--card-b) !important;
  background-color: rgba(255,255,255,0.04) !important;
  color: inherit !important;

  /* single-line label */
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;

  /* custom caret (encoded # as %23) */
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2369a6ff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat !important;
  background-position: right 10px center !important;
  background-size: 14px !important;
  background-clip: padding-box !important;
}

.row select:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(105,166,255,.45);
  border-color: rgba(105,166,255,.65);
}

/* keep inputs fixed for row alignment (do NOT apply to selects) */
.row input[type="number"],
.row input[type="text"] {
  height: 44px;
  line-height: 44px;
}

/* ensure the select has width priority so names stay visible */
.row select { flex: 1 1 280px; min-width: 220px; }
@media (min-width: 900px) {
  .row input[type="number"] { flex: 0 0 54px; min-width: 54px; }
  .row .mini { min-width: auto; }
}

/* === MOBILE LAYOUT: stack fields again (select on its own line, labels/inputs below) === */
@media (max-width: 720px) {
  .twocol .row {
    display: grid !important;
    grid-template-columns: 1fr !important;  /* one column -> everything stacks */
    gap: 10px !important;
    align-items: stretch !important;
  }
  .twocol .row .mini { margin-top: 2px; }   /* small breathing room for "Innings" / "Pitches" labels */
}

/* === SELECT: match input look, no clipping, no grey iOS style === */
.twocol .row select,
.row select,
select {
  -webkit-appearance: none !important;
  appearance: none !important;

  /* iOS-safe sizing: never force line-height == height */
  height: 44px !important;
  min-height: 44px !important;
  line-height: normal !important;
  padding: 10px 36px 10px 12px !important;  /* room for caret on the right */

  /* match your input visuals */
  border-radius: 10px !important;
  border: 1px solid var(--card-b) !important;
  background-color: rgba(255,255,255,0.04) !important;
  color: inherit !important;

  /* long names behave */
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;

  /* custom caret that fits the theme (# -> %23) */
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2369a6ff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat !important;
  background-position: right 10px center !important;
  background-size: 14px !important;
  background-clip: padding-box !important;

  /* keep selects the width priority in multi-control rows */
  flex: 1 1 280px !important;
  min-width: 220px !important;
}

/* Keep inputs fixed to align rows, but DO NOT re-apply to selects */
.twocol .row input[type="number"],
.twocol .row input[type="text"] {
  height: 44px !important;
  line-height: 44px !important;
}

/* Desktop: number inputs don't steal width from the select */
@media (min-width: 900px) {
  .twocol .row input[type="number"] { flex: 0 0 54px !important; min-width: 54px !important; }
  .twocol .row .mini { min-width: auto !important; }
}

/* Player card field sizing: prevent overflow & keep controls inside the card */
.player-card__fields,
.card .grid {
  grid-template-columns: repeat(2, minmax(0, 1fr)); /* strong minmax on mobile */
}

.player-card__fields .field,
.card .grid .field {
  min-width: 0;                 /* allow shrinking inside grid columns */
}

.player-card__fields .field select,
.player-card__fields .field input,
.card .grid .field select,
.card .grid .field input {
  width: 100%;
  box-sizing: border-box;       /* include padding/border in width calc */
  min-height: 44px;             /* consistent tap target */
  font-size: 16px;              /* avoids iOS zoom */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* On wider screens, return to 4-up grid but keep minmax to avoid overflow */
@media (min-width: 721px) {
  .player-card__fields,
  .card .grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

/* === Fix player card dropdown width inside cards === */
.card .grid,
.player-card__fields {
  grid-template-columns: 1fr 1fr;     /* always split evenly in two */
  gap: 12px;                          /* tighten gap so both fit */
}

.card .grid .field,
.player-card__fields .field {
  min-width: 0;                       /* let children shrink */
}

.card .grid select,
.player-card__fields select,
.card .grid input,
.player-card__fields input {
  width: 100%;                        /* stay inside grid column */
  max-width: 100%;                    /* never overflow card */
  box-sizing: border-box;             /* borders + padding inside width */
  min-height: 44px;
  font-size: 16px;                    /* iOS zoom-safe */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;            /* cut off long words nicely */
}

/* On wider screens, restore 4 columns but still clamp widths */
@media (min-width: 721px) {
  .card .grid,
  .player-card__fields {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* --- iOS fix: keep player-card controls inside the card --- */

/* 1) Clip anything that paints outside rounded cards */
.card,
.player-card {
  overflow: hidden;                 /* clips the select's painted area */
}

/* 2) Also clip at the field level (safer focus/hover states) */
.card .grid .field,
.player-card__fields .field {
  min-width: 0;                     /* allow shrinking inside grid */
  overflow: hidden;                 /* prevent control bleed past column */
  position: relative;               /* create a clipping context */
  contain: layout paint style;      /* isolate painting on iOS */
}

/* 3) Constrain controls to their column */
.card .grid select,
.player-card__fields select,
.card .grid input,
.player-card__fields input {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  min-height: 44px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 4) Tighten mobile card grid so both columns fit comfortably */
.card .grid,
.player-card__fields {
  grid-template-columns: 1fr 1fr;
  gap: 10px;                        /* slightly smaller than 12px */
}

@media (min-width: 721px) {
  .card .grid,
  .player-card__fields {
    grid-template-columns: repeat(4, minmax(0,1fr));
  }
}

/* --- Player card fields: always fit 4 controls inside the card --- */

/* Base: 2×2 grid inside each card (Rank | Avail) / (Primary | Secondary) */
.player-card__fields,
.card .grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr)); /* columns can shrink */
  gap: 10px 12px;                                   /* tight but readable */
}

/* Let items actually shrink and clip safely inside rounded cards */
.player-card,
.card { overflow: hidden; }
.player-card__fields .field,
.card .grid .field {
  min-width: 0;           /* critical for grid shrinkage on iOS */
  overflow: hidden;       /* stop any paint bleed */
  position: relative;
}

/* Controls stay within their column and adapt to width */
.player-card__fields .field select,
.player-card__fields .field input,
.card .grid .field select,
.card .grid .field input {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  min-height: 44px;
  padding: 10px 12px;     /* slightly tighter on mobile than global */
  font-size: 16px;        /* avoids iOS zoom */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Very small phones: reduce padding a hair so two columns still fit */
@media (max-width: 390px) {
  .player-card__fields,
  .card .grid { gap: 8px 10px; }

  .player-card__fields .field select,
  .player-card__fields .field input,
  .card .grid .field select,
  .card .grid .field input {
    min-height: 42px;
    padding: 8px 10px;
    font-size: 15px;
  }
}

/* Ultra-narrow edge case: stack to a single column so nothing overflows */
@media (max-width: 340px) {
  .player-card__fields,
  .card .grid { grid-template-columns: 1fr; }
}

/* Desktop/wide screens: can show 4-up layout again if desired */
@media (min-width: 721px) {
  .player-card__fields,
  .card .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

/* === Player card controls: never overlap === */

/* Auto-fit grid: each control gets at least 180px; if not available, it wraps */
.player-card__fields,
.card .grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

/* Allow grid children to actually shrink; prevent paint bleed on iOS */
.player-card,
.card { overflow: hidden; }

.player-card__fields .field,
.card .grid .field {
  min-width: 0;                /* critical so children can shrink */
  overflow: hidden;            /* clip any focus/paint overflow */
  position: relative;
  contain: layout paint style; /* iOS/WebKit isolation */
}

/* Inputs/selects are constrained to their cell */
.player-card__fields .field select,
.player-card__fields .field input,
.card .grid .field select,
.card .grid .field input {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  min-height: 44px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Fine-tune for very small phones: slightly tighter spacing & padding */
@media (max-width: 390px) {
  .player-card__fields,
  .card .grid { gap: 10px; }
  .player-card__fields .field select,
  .player-card__fields .field input,
  .card .grid .field select,
  .card .grid .field input {
    min-height: 42px;
    padding: 8px 10px;
    font-size: 15px;
  }
}

/* Wide screens: comfortably show 4 across, still respecting min width */
@media (min-width: 960px) {
  .player-card__fields,
  .card .grid {
    grid-template-columns: repeat(4, minmax(160px, 1fr));
  }
}