/* ==========================================================================
   Lineup — Apple-style baseball lineup planner
   Colors follow the iOS system palette (light + dark).
   ========================================================================== */

:root {
  --bg: #F2F2F7;
  --bg-elevated: #FFFFFF;
  --card: #FFFFFF;
  --card-2: #F2F2F7;
  --label: #000000;
  --label-2: rgba(60, 60, 67, 0.6);
  --label-3: rgba(60, 60, 67, 0.3);
  --sep: rgba(60, 60, 67, 0.18);
  --sep-opaque: #C6C6C8;
  --fill: rgba(120, 120, 128, 0.2);
  --fill-2: rgba(120, 120, 128, 0.16);
  --fill-3: rgba(118, 118, 128, 0.12);
  --blue: #007AFF;
  --green: #34C759;
  --red: #FF3B30;
  --orange: #FF9500;
  --yellow: #FFCC00;
  --teal: #30B0C7;
  --indigo: #5856D6;
  --gray: #8E8E93;
  --bar: rgba(249, 249, 249, 0.78);
  --chip: rgba(255, 255, 255, 0.92);
  --chip-text: #000;
  --scrim: rgba(0, 0, 0, 0.32);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-chip: 0 2px 8px rgba(0, 0, 0, 0.18), 0 0 0 0.5px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.18);
  --grass-1: #4CAF61;
  --grass-2: #43A157;
  --dirt: #D4A373;
  --dirt-2: #C8925F;
  --simple-bg: #E9F1FB;
  --simple-line: rgba(0, 122, 255, 0.28);
  --nav-h: 52px;
  --radius: 12px;
  --radius-lg: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --bg-elevated: #1C1C1E;
    --card: #1C1C1E;
    --card-2: #2C2C2E;
    --label: #FFFFFF;
    --label-2: rgba(235, 235, 245, 0.6);
    --label-3: rgba(235, 235, 245, 0.3);
    --sep: rgba(84, 84, 88, 0.6);
    --sep-opaque: #38383A;
    --fill: rgba(120, 120, 128, 0.36);
    --fill-2: rgba(120, 120, 128, 0.32);
    --fill-3: rgba(118, 118, 128, 0.24);
    --blue: #0A84FF;
    --green: #30D158;
    --red: #FF453A;
    --orange: #FF9F0A;
    --yellow: #FFD60A;
    --teal: #40C8E0;
    --indigo: #5E5CE6;
    --gray: #8E8E93;
    --bar: rgba(22, 22, 24, 0.78);
    --chip: rgba(44, 44, 46, 0.92);
    --chip-text: #fff;
    --scrim: rgba(0, 0, 0, 0.5);
    --shadow-chip: 0 2px 10px rgba(0, 0, 0, 0.5), 0 0 0 0.5px rgba(255, 255, 255, 0.08);
    --grass-1: #2F7D40;
    --grass-2: #2A7139;
    --dirt: #A87A50;
    --dirt-2: #976B44;
    --simple-bg: #0E1A2A;
    --simple-line: rgba(10, 132, 255, 0.4);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #000000;
  --bg-elevated: #1C1C1E;
  --card: #1C1C1E;
  --card-2: #2C2C2E;
  --label: #FFFFFF;
  --label-2: rgba(235, 235, 245, 0.6);
  --label-3: rgba(235, 235, 245, 0.3);
  --sep: rgba(84, 84, 88, 0.6);
  --sep-opaque: #38383A;
  --fill: rgba(120, 120, 128, 0.36);
  --fill-2: rgba(120, 120, 128, 0.32);
  --fill-3: rgba(118, 118, 128, 0.24);
  --blue: #0A84FF;
  --green: #30D158;
  --red: #FF453A;
  --orange: #FF9F0A;
  --yellow: #FFD60A;
  --teal: #40C8E0;
  --indigo: #5E5CE6;
  --gray: #8E8E93;
  --bar: rgba(22, 22, 24, 0.78);
  --chip: rgba(44, 44, 46, 0.92);
  --chip-text: #fff;
  --scrim: rgba(0, 0, 0, 0.5);
  --shadow-chip: 0 2px 10px rgba(0, 0, 0, 0.5), 0 0 0 0.5px rgba(255, 255, 255, 0.08);
  --grass-1: #2F7D40;
  --grass-2: #2A7139;
  --dirt: #A87A50;
  --dirt-2: #976B44;
  --simple-bg: #0E1A2A;
  --simple-line: rgba(10, 132, 255, 0.4);
  color-scheme: dark;
}

/* ---------- Base ---------- */

*, *::before, *::after { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

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

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--label);
  font: 17px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", system-ui, sans-serif;
  letter-spacing: -0.012em;
  -webkit-font-smoothing: antialiased;
  transition: background-color 300ms ease;
}

button { font: inherit; color: inherit; background: none; border: 0; padding: 0; margin: 0; cursor: pointer; letter-spacing: inherit; }
button:disabled { cursor: default; }
input, textarea, select { font: inherit; color: inherit; letter-spacing: inherit; }
a { color: var(--blue); text-decoration: none; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--blue) 55%, transparent); outline-offset: 2px; border-radius: 8px; }

.ic { width: 22px; height: 22px; flex: none; display: block; }
.ic-sm { width: 16px; height: 16px; }
.ic-xs { width: 13px; height: 13px; }
.ic-lg { width: 26px; height: 26px; }

.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Press feedback — instant, on pointer-down */
.pressable { transition: transform 120ms ease-out, opacity 120ms ease-out, background-color 150ms ease; }
.pressable:active:not(:disabled) { transform: scale(0.97); }

/* ---------- Navigation bar (translucent material) ---------- */

.navbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: calc(var(--nav-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid transparent;
  transition: border-color 200ms ease;
}
.navbar.scrolled { border-bottom-color: var(--sep); }

.nav-left, .nav-right { display: flex; align-items: center; gap: 4px; min-width: 0; }
.nav-right { justify-content: flex-end; }

.nav-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 40px; padding: 0 8px; border-radius: 10px;
  color: var(--blue); font-size: 17px;
}
.nav-btn:active { opacity: 0.4; }
.nav-icon { width: 40px; justify-content: center; padding: 0; }

.nav-title {
  font-size: 17px; font-weight: 600; letter-spacing: -0.02em;
  max-width: 48vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  opacity: 0; transform: translateY(4px);
  transition: opacity 200ms ease, transform 200ms ease;
  pointer-events: none;
}
.navbar.scrolled .nav-title { opacity: 1; transform: none; pointer-events: auto; }

/* ---------- Layout ---------- */

.layout { display: block; }
.main {
  width: 100%;
  max-width: 880px;
  margin: 0 auto;
  padding: 4px max(16px, env(safe-area-inset-right)) calc(40px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

@media (min-width: 900px) {
  .layout { display: grid; grid-template-columns: 340px minmax(0, 1fr); }
  .roster-toggle { display: none !important; }
  .sidebar {
    position: sticky;
    top: calc(var(--nav-h) + env(safe-area-inset-top));
    height: calc(100dvh - var(--nav-h) - env(safe-area-inset-top));
    overflow-y: auto;
    border-right: 0.5px solid var(--sep);
    background: var(--bg);
    padding-left: env(safe-area-inset-left);
  }
  .sidebar-close { display: none !important; }
  .main { padding-top: 8px; }
}

@media (max-width: 899px) {
  .sidebar {
    position: fixed;
    z-index: 60;
    top: 0; left: 0; bottom: 0;
    width: min(360px, 88vw);
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--bg);
    padding-top: env(safe-area-inset-top);
    padding-left: env(safe-area-inset-left);
    transform: translate3d(-102%, 0, 0);
    box-shadow: var(--shadow-lg);
    visibility: hidden;
  }
  .sidebar.open, .sidebar.dragging { visibility: visible; }
}

.drawer-scrim {
  position: fixed; inset: 0; z-index: 55;
  background: var(--scrim);
  opacity: 0;
}

/* ---------- Typography ---------- */

.large-title { font-size: 34px; line-height: 1.12; font-weight: 700; letter-spacing: -0.025em; }
.title-1 { font-size: 28px; line-height: 1.15; font-weight: 700; letter-spacing: -0.022em; }
.title-2 { font-size: 22px; line-height: 1.2; font-weight: 700; letter-spacing: -0.02em; }
.headline { font-size: 17px; font-weight: 600; }
.subhead { font-size: 15px; color: var(--label-2); letter-spacing: -0.01em; }
.footnote { font-size: 13px; color: var(--label-2); letter-spacing: -0.005em; }
.caption { font-size: 12px; color: var(--label-2); }
.dim { color: var(--label-2); font-weight: 500; }

/* ---------- Hero (large title) ---------- */

.hero { padding: 6px 0 16px; }
.hero-title {
  display: flex; align-items: center; gap: 12px; text-align: left; width: 100%;
  border-radius: 14px;
}
.hero-title:active .large-title { opacity: 0.6; }
.hero-text { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.hero-text .large-title { display: flex; align-items: center; gap: 6px; }
.hero-text .large-title span { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.hero-text .large-title .ic { color: var(--label-3); width: 22px; height: 22px; }

.logo {
  flex: none; display: grid; place-items: center;
  width: 52px; height: 52px; border-radius: 13px;
  background: var(--card); box-shadow: var(--shadow-sm), inset 0 0 0 0.5px var(--sep);
  font-size: 30px; overflow: hidden;
}
.logo img { width: 100%; height: 100%; object-fit: cover; }
.logo.sm { width: 34px; height: 34px; border-radius: 9px; font-size: 20px; }
.logo.xl { width: 72px; height: 72px; border-radius: 18px; font-size: 42px; }

/* ---------- Grouped lists (Inset grouped) ---------- */

.section { margin: 0 0 24px; }
.section-header {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 12px;
  padding: 0 16px 7px; min-height: 22px;
  font-size: 13px; color: var(--label-2); text-transform: uppercase; letter-spacing: 0;
}
.section-header.plain { text-transform: none; font-size: 20px; font-weight: 700; color: var(--label); letter-spacing: -0.02em; padding-left: 4px; }
.section-footer { padding: 7px 16px 0; font-size: 13px; color: var(--label-2); line-height: 1.4; }

.group {
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  list-style: none; margin: 0; padding: 0;
}

.row {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  min-height: 44px; padding: 8px 16px;
  width: 100%; text-align: left;
  background: var(--card);
}
.row + .row::before, .row + .row-wrap::before, .row-wrap + .row::before {
  content: ""; position: absolute; top: 0; right: 0; left: var(--inset, 16px);
  border-top: 0.5px solid var(--sep);
}
button.row:active:not(:disabled), .row.tappable:active { background: var(--fill-3); }
.row .label { flex: none; }
.row .grow { flex: 1; min-width: 0; }
.row .value { color: var(--label-2); margin-left: auto; text-align: right; }
.row .chev { color: var(--label-3); width: 14px; height: 14px; margin-left: 2px; }
.row.blue-text { color: var(--blue); }
.row.destructive { color: var(--red); }
.row.center { justify-content: center; }
.row:disabled { opacity: 0.4; }
.row .row-icon {
  flex: none; width: 29px; height: 29px; border-radius: 7px; display: grid; place-items: center;
  color: #fff; background: var(--c, var(--blue));
}
.row .row-icon .ic { width: 18px; height: 18px; }

.row input[type="text"], .row input[type="date"], .row input[type="search"], .row input:not([type]) {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; padding: 0;
  font-size: 17px; text-align: right; color: var(--label);
}
.row input.left { text-align: left; }
.row input::placeholder, textarea::placeholder { color: var(--label-3); }
.row input[type="date"] { min-height: 28px; color: var(--blue); -webkit-appearance: none; appearance: none; }
.row input[type="date"]::-webkit-date-and-time-value { text-align: right; }

.row textarea {
  width: 100%; min-height: 110px; border: 0; outline: 0; resize: vertical; background: transparent;
  font-size: 17px; line-height: 1.4; padding: 4px 0;
}

/* ---------- Controls ---------- */

.segmented {
  position: relative; display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: var(--fill-3); border-radius: 9px; padding: 2px; gap: 0;
  font-size: 13px; font-weight: 500;
}
.segmented button {
  position: relative; z-index: 1;
  height: 28px; padding: 0 12px; border-radius: 7px; white-space: nowrap;
  transition: background-color 200ms ease, box-shadow 200ms ease;
}
.segmented button[aria-pressed="true"] {
  background: var(--bg-elevated); font-weight: 600;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.12), 0 3px 1px rgba(0, 0, 0, 0.04), 0 0 0 0.5px rgba(0, 0, 0, 0.04);
}
:root[data-theme="dark"] .segmented button[aria-pressed="true"] { background: #636366; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .segmented button[aria-pressed="true"] { background: #636366; } }
.segmented button:disabled { opacity: 0.4; }
.segmented.full { display: grid; width: 100%; }

.switch {
  position: relative; flex: none; width: 51px; height: 31px; border-radius: 16px;
  background: var(--fill); transition: background-color 250ms ease;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15), 0 3px 1px rgba(0, 0, 0, 0.06);
  transition: transform 300ms cubic-bezier(0.3, 1.3, 0.5, 1);
}
.switch[aria-checked="true"] { background: var(--green); }
.switch[aria-checked="true"]::after { transform: translateX(20px); }

.stepper {
  flex: none; display: inline-flex; align-items: center;
  background: var(--fill-3); border-radius: 9px; height: 32px;
}
.stepper button { width: 46px; height: 32px; display: grid; place-items: center; color: var(--label); }
.stepper button:active:not(:disabled) { background: var(--fill-2); border-radius: 9px; }
.stepper button:disabled { color: var(--label-3); }
.stepper .divider { width: 0.5px; height: 18px; background: var(--sep-opaque); }
.stepper .ic { width: 18px; height: 18px; }
.stepper-label { font-size: 15px; color: var(--label-2); font-variant-numeric: tabular-nums; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px; padding: 0 20px; border-radius: 14px;
  font-size: 17px; font-weight: 600; letter-spacing: -0.02em;
  transition: transform 120ms ease-out, opacity 150ms ease, background-color 150ms ease;
}
.btn:active:not(:disabled) { transform: scale(0.97); opacity: 0.85; }
.btn:disabled { opacity: 0.35; }
.btn.filled { background: var(--blue); color: #fff; }
.btn.green { background: var(--green); color: #fff; }
.btn.tinted { background: color-mix(in srgb, var(--blue) 15%, transparent); color: var(--blue); }
.btn.gray { background: var(--fill-3); color: var(--label); }
.btn.small { min-height: 34px; padding: 0 14px; border-radius: 17px; font-size: 15px; }
.btn.block { width: 100%; }

.capsule {
  display: inline-flex; align-items: center; gap: 4px;
  height: 22px; padding: 0 8px; border-radius: 11px;
  font-size: 12px; font-weight: 600; letter-spacing: 0;
  background: var(--fill-3); color: var(--label-2);
}
.capsule.green { background: color-mix(in srgb, var(--green) 18%, transparent); color: var(--green); }
.capsule.red { background: color-mix(in srgb, var(--red) 15%, transparent); color: var(--red); }
.capsule.orange { background: color-mix(in srgb, var(--orange) 18%, transparent); color: var(--orange); }
.capsule.blue { background: color-mix(in srgb, var(--blue) 15%, transparent); color: var(--blue); }
.capsule .ic { width: 12px; height: 12px; }

.badge {
  flex: none; display: inline-grid; place-items: center;
  min-width: 26px; height: 22px; padding: 0 5px; border-radius: 6px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.01em; color: #fff;
  background: var(--c, var(--gray));
  font-variant-numeric: tabular-nums;
}

/* ---------- Matchup ---------- */

.matchup .row .label { min-width: 84px; }

/* ---------- Inning selector ---------- */

.inning-bar { display: flex; align-items: center; gap: 12px; margin: 0 0 14px; }
.inning-tabs {
  flex: 1; min-width: 0; display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
  padding: 2px; margin: -2px;
}
.inning-tabs::-webkit-scrollbar { display: none; }
.inning-tab {
  position: relative; flex: none;
  width: 40px; height: 40px; border-radius: 20px;
  display: grid; place-items: center;
  font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums;
  background: var(--card); color: var(--label);
  box-shadow: var(--shadow-sm);
  transition: background-color 200ms ease, color 200ms ease, transform 120ms ease-out;
}
.inning-tab:active { transform: scale(0.92); }
@media (max-width: 520px) {
  .inning-bar { gap: 8px; }
  .inning-tabs { gap: 4px; }
  .inning-tab { flex: 1 1 0; width: auto; min-width: 26px; max-width: 44px; height: 38px; border-radius: 19px; font-size: 16px; }
  .inning-bar .stepper button { width: 36px; }
  .large-title { font-size: 28px; }
  .logo { width: 46px; height: 46px; font-size: 26px; border-radius: 12px; }
}
.inning-tab[aria-selected="true"] { background: var(--blue); color: #fff; }
.inning-tab.done::after {
  content: ""; position: absolute; right: 1px; top: 1px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--green); border: 2px solid var(--bg);
}

/* ---------- Field card ---------- */

.card { background: var(--card); border-radius: var(--radius-lg); overflow: hidden; }
.field-card { margin-bottom: 24px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px 12px; flex-wrap: wrap; }
.card-head .title-2 { display: flex; align-items: baseline; gap: 6px; }
.card-head .status { display: flex; gap: 6px; margin-top: 4px; min-height: 22px; flex-wrap: wrap; }

.field-viewport { position: relative; overflow: hidden; touch-action: pan-y; }
.field-stage { position: relative; will-change: transform; }

.field {
  position: relative; width: 100%;
  aspect-ratio: 4 / 3; min-height: 330px;
  user-select: none; -webkit-user-select: none;
}
.field svg.field-art { position: absolute; inset: 0; width: 100%; height: 100%; }

.pos-chip {
  position: absolute; transform: translate(-50%, -50%);
  display: inline-flex; align-items: center; gap: 6px;
  max-width: 132px; height: 34px; padding: 0 11px 0 4px; border-radius: 17px;
  background: var(--chip); color: var(--chip-text);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  box-shadow: var(--shadow-chip);
  font-size: 14px; font-weight: 600; letter-spacing: -0.02em;
  transition: transform 140ms ease-out, box-shadow 200ms ease;
}
.pos-chip:active:not(:disabled) { transform: translate(-50%, -50%) scale(0.94); }
.pos-chip .badge { min-width: 26px; height: 26px; border-radius: 13px; }
.pos-chip .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pos-chip.empty .name { color: var(--label-2); font-weight: 500; }
.pos-chip.empty { background: color-mix(in srgb, var(--chip) 70%, transparent); }
.pos-chip.injured .name { color: var(--red); text-decoration: line-through; }
.pos-chip.locked { box-shadow: var(--shadow-chip), 0 0 0 2px var(--orange); }
.pos-chip .lock { color: var(--orange); }
.pos-chip:disabled { cursor: default; }
@media (max-width: 480px) {
  .pos-chip { max-width: 104px; height: 30px; padding-right: 9px; gap: 4px; font-size: 13px; }
  .pos-chip .badge { min-width: 24px; height: 24px; font-size: 10.5px; }
}
.grip svg, .roster-main svg { pointer-events: none; }

.field-overlay {
  position: absolute; inset: 0; z-index: 3; display: grid; place-items: center; pointer-events: none;
  background: color-mix(in srgb, var(--card) 35%, transparent);
}
.field-overlay .capsule { height: 34px; padding: 0 14px; border-radius: 17px; font-size: 15px; background: var(--chip); color: var(--label); box-shadow: var(--shadow-chip); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); }
.field-overlay .capsule .ic { width: 16px; height: 16px; color: var(--green); }

.field-label {
  position: absolute; left: 14px; top: 10px; z-index: 2;
  font-size: 13px; font-weight: 600; color: rgba(255, 255, 255, 0.92);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}
.field.simple .field-label { color: var(--label-2); text-shadow: none; }

.card-foot {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px; flex-wrap: wrap;
  border-top: 0.5px solid var(--sep);
}
.card-foot .spacer { flex: 1; }
.chip-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 12px; border-radius: 16px;
  background: var(--fill-3); font-size: 15px; font-weight: 500;
}
.chip-btn:active:not(:disabled) { background: var(--fill); }
.chip-btn .ic { width: 16px; height: 16px; }
.chip-btn.on { background: color-mix(in srgb, var(--orange) 18%, transparent); color: var(--orange); }
.chip-btn:disabled { opacity: 0.4; }

.pos-list .row .badge { min-width: 34px; }

/* ---------- Bench ---------- */

.bench-row .grow { display: flex; flex-direction: column; }
.bench-row .who { font-size: 17px; }
.bench-row .who.empty { color: var(--label-3); }
.bench-row .who.injured { color: var(--red); text-decoration: line-through; }
.icon-btn {
  flex: none; width: 36px; height: 36px; border-radius: 18px; display: grid; place-items: center;
  color: var(--label-2); background: var(--fill-3);
}
.icon-btn:active:not(:disabled) { background: var(--fill); }
.icon-btn.on { background: var(--red); color: #fff; }
.icon-btn .ic { width: 18px; height: 18px; }

/* ---------- Action buttons ---------- */

.actions { display: grid; gap: 10px; margin-bottom: 28px; }
.actions .pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 420px) { .actions .pair { grid-template-columns: 1fr; } }

.app-footer { text-align: center; padding: 8px 0 12px; font-size: 12px; color: var(--label-3); }

/* ---------- Sidebar / Roster ---------- */

.sidebar-inner { padding: 12px 16px calc(24px + env(safe-area-inset-bottom)); }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 4px 12px; }
.sidebar-head .title-1 { margin: 0; }

.add-player { display: flex; align-items: center; gap: 10px; }
.add-player input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font-size: 17px; padding: 0; }
.add-player .add-btn { color: var(--blue); display: grid; place-items: center; width: 30px; height: 30px; }
.add-player .add-btn:disabled { color: var(--label-3); }
.add-player .add-btn .ic { width: 26px; height: 26px; }

.roster-list { touch-action: pan-y; }
.roster-row { --inset: 52px; padding: 0 4px 0 12px; gap: 8px; transition: background-color 150ms ease; }
.roster-row.lifted { z-index: 5; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2); border-radius: 10px; transition: none; }
.roster-row.lifted::before { display: none; }
.roster-row.shifting { transition: transform 220ms cubic-bezier(0.2, 0.9, 0.3, 1); }
.roster-row .order {
  flex: none; width: 28px; height: 28px; border-radius: 14px; display: grid; place-items: center;
  background: var(--fill-3); font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--label-2);
}
.roster-main { flex: 1; min-width: 0; padding: 10px 0; text-align: left; display: flex; flex-direction: column; gap: 1px; }
.roster-main:active { opacity: 0.5; }
.roster-main .pname { font-size: 17px; display: flex; align-items: center; gap: 6px; }
.roster-main .pname span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.roster-main .pname.injured span { color: var(--red); }
.roster-main .pmeta { font-size: 13px; color: var(--label-2); display: flex; align-items: center; gap: 6px; }
.roster-main .pmeta .ic { width: 13px; height: 13px; }
.grip {
  flex: none; width: 40px; height: 44px; display: grid; place-items: center;
  color: var(--label-3); cursor: grab; touch-action: none;
}
.grip:active { cursor: grabbing; color: var(--label-2); }
.grip .ic { width: 20px; height: 20px; }

.sidebar-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 4px; }

.legend { display: flex; gap: 12px; flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 8px; height: 8px; border-radius: 4px; background: var(--c); display: inline-block; }

/* ---------- Sheets ---------- */

#overlays { position: relative; z-index: 80; }

.sheet-layer {
  position: fixed; inset: 0;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet-layer .scrim { position: absolute; inset: 0; background: var(--scrim); opacity: 0; }

.sheet {
  --y: 100%; --s: 1;
  position: relative;
  width: 100%; max-height: calc(100dvh - env(safe-area-inset-top) - 12px);
  display: flex; flex-direction: column;
  background: var(--bg);
  border-radius: 14px 14px 0 0;
  box-shadow: 0 -2px 30px rgba(0, 0, 0, 0.15);
  transform: translate3d(0, var(--y), 0) scale(var(--s));
  transform-origin: 50% 0;
  will-change: transform;
  outline: none;
}
.sheet.tall { height: calc(100dvh - env(safe-area-inset-top) - 12px); }
.sheet-layer.behind .sheet { --s: 0.94; filter: brightness(0.92); transition: transform 300ms ease, filter 300ms ease; }

@media (min-width: 700px) and (min-height: 600px) {
  .sheet-layer { align-items: center; padding: 24px; }
  .sheet { max-width: 560px; border-radius: 14px; max-height: min(820px, calc(100dvh - 48px)); box-shadow: var(--shadow-lg); transform-origin: 50% 50%; }
  .sheet.tall { height: min(820px, calc(100dvh - 48px)); }
  .sheet.wide { max-width: 820px; }
}

.grabber { flex: none; width: 36px; height: 5px; border-radius: 3px; background: var(--fill); margin: 6px auto 0; }
.sheet-head {
  flex: none; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  min-height: 50px; padding: 0 8px; touch-action: none; cursor: grab;
}
.sheet-title { margin: 0; font-size: 17px; font-weight: 600; text-align: center; letter-spacing: -0.02em; max-width: 60vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-sub { display: block; font-size: 12px; font-weight: 500; color: var(--label-2); }
.sh-left { justify-self: start; }
.sh-right { justify-self: end; }
.sheet-head .nav-btn.bold { font-weight: 600; }
.sheet-body {
  flex: 1; overflow-y: auto; overscroll-behavior: contain;
  padding: 8px 16px calc(28px + env(safe-area-inset-bottom));
  -webkit-overflow-scrolling: touch;
}

/* Picker */
.picker-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 20px; }
.picker-actions .btn { min-height: 44px; font-size: 15px; border-radius: 12px; }
.picker-actions .btn.locked { background: color-mix(in srgb, var(--orange) 18%, transparent); color: var(--orange); }
.pick-row .check { color: var(--blue); margin-left: auto; }
.pick-row.current { color: var(--blue); }
.pick-row .meta { font-size: 13px; color: var(--label-2); }
.pick-row .injured-tag { color: var(--red); }

/* Positions grid (player editor) */
.pos-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; padding: 12px 16px; }
.pos-toggle {
  position: relative; height: 44px; border-radius: 10px; background: var(--fill-3);
  font-weight: 600; font-size: 15px;
  transition: background-color 150ms ease, color 150ms ease, transform 120ms ease-out;
}
.pos-toggle:active { transform: scale(0.94); }
.pos-toggle[aria-pressed="true"] { background: var(--c); color: #fff; }
.pos-toggle .rank {
  position: absolute; top: -5px; right: -5px; width: 18px; height: 18px; border-radius: 9px;
  background: var(--label); color: var(--bg); font-size: 11px; display: grid; place-items: center;
}

/* Teams list */
.team-row { --inset: 62px; }
.team-row .tname { font-size: 17px; display: flex; align-items: center; gap: 6px; }
.team-row .tname span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.team-row .tmeta { font-size: 13px; color: var(--label-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.team-row .star { color: var(--label-3); width: 40px; height: 40px; display: grid; place-items: center; flex: none; }
.team-row .star.on { color: var(--orange); }
.team-row .check { color: var(--blue); }

.tag-chips { display: flex; gap: 8px; flex-wrap: wrap; padding: 10px 16px; }
.tag-chips button { height: 32px; padding: 0 14px; border-radius: 16px; background: var(--fill-3); font-size: 15px; }
.tag-chips button[aria-pressed="true"] { background: var(--blue); color: #fff; }

.logo-edit { display: flex; align-items: center; gap: 16px; padding: 14px 16px; }
.logo-edit .grow { display: flex; flex-direction: column; gap: 8px; }
.emoji-input { width: 100%; border: 0; outline: 0; background: var(--fill-3); border-radius: 10px; padding: 8px 12px; font-size: 17px; }

/* Share */
.share-preview {
  background: var(--card); border-radius: var(--radius); padding: 14px 16px;
  font-size: 14px; line-height: 1.45; white-space: pre-wrap; color: var(--label);
  max-height: 220px; overflow-y: auto; margin-bottom: 8px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12.5px;
}

/* Game card (export preview + print) */
.gamecard { background: #fff; color: #000; border-radius: 12px; padding: 16px; overflow-x: auto; }
.gc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 12px; }
.gc-title { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; margin: 0; }
.gc-sub { font-size: 12px; color: #555; margin-top: 2px; }
.gc-logo { font-size: 32px; line-height: 1; }
.gc-logo img { width: 44px; height: 44px; object-fit: cover; border-radius: 10px; }
.gc-grid { display: grid; grid-template-columns: 200px 1fr; gap: 16px; align-items: start; }
@media (max-width: 640px) { .gc-grid { grid-template-columns: 1fr; } }
.gc-table { width: 100%; border-collapse: collapse; font-size: 11.5px; }
.gc-table th, .gc-table td { border-bottom: 1px solid #e5e5ea; padding: 5px 6px; text-align: left; vertical-align: top; }
.gc-table th { background: #f2f2f7; font-weight: 700; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.02em; color: #3c3c43; }
.gc-defense { table-layout: fixed; min-width: 560px; }
.gc-defense td { overflow-wrap: anywhere; }
.gc-table td.pos { font-weight: 700; white-space: nowrap; background: #fafafa; }
.gc-table tr.bench td { background: #fff4e5; color: #8a4b00; font-weight: 600; }
.gc-table .open { color: #aaa; font-style: italic; }
.gc-table .inj { color: #c00; text-decoration: line-through; }
.gc-order td:first-child { width: 22px; color: #666; font-variant-numeric: tabular-nums; }

/* ---------- Alerts ---------- */

.alert-layer { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 24px; }
.alert-layer .scrim { position: absolute; inset: 0; background: var(--scrim); animation: fadeIn 200ms ease both; }
.alert {
  position: relative; width: 270px; border-radius: 14px; overflow: hidden;
  background: color-mix(in srgb, var(--bg-elevated) 88%, transparent);
  -webkit-backdrop-filter: blur(30px) saturate(180%); backdrop-filter: blur(30px) saturate(180%);
  text-align: center;
  animation: alertIn 300ms cubic-bezier(0.2, 0.9, 0.3, 1.1) both;
}
.alert-body { padding: 19px 16px 15px; }
.alert-title { font-size: 17px; font-weight: 600; margin: 0 0 3px; letter-spacing: -0.02em; }
.alert-msg { font-size: 13px; line-height: 1.38; margin: 0; }
.alert-input { margin-top: 14px; width: 100%; border: 0.5px solid var(--sep-opaque); border-radius: 7px; padding: 7px 8px; font-size: 14px; background: var(--card); outline: 0; }
.alert-buttons { display: flex; border-top: 0.5px solid var(--sep); }
.alert-buttons.stack { flex-direction: column; }
.alert-buttons button { flex: 1; min-height: 44px; color: var(--blue); font-size: 17px; }
.alert-buttons:not(.stack) button + button { border-left: 0.5px solid var(--sep); }
.alert-buttons.stack button + button { border-top: 0.5px solid var(--sep); }
.alert-buttons button.bold { font-weight: 600; }
.alert-buttons button.destructive { color: var(--red); }
.alert-buttons button:active { background: var(--fill-3); }
.alert-layer.out .alert, .alert-layer.out .scrim { animation: fadeOut 160ms ease both; }

/* ---------- Menu (context menu) ---------- */

.menu-layer { position: fixed; inset: 0; z-index: 90; }
.menu {
  position: fixed; min-width: 250px; border-radius: 13px; overflow: hidden;
  background: color-mix(in srgb, var(--bg-elevated) 84%, transparent);
  -webkit-backdrop-filter: blur(30px) saturate(180%); backdrop-filter: blur(30px) saturate(180%);
  box-shadow: 0 10px 50px rgba(0, 0, 0, 0.22), 0 0 0 0.5px var(--sep);
  animation: menuIn 260ms cubic-bezier(0.2, 0.9, 0.3, 1.15) both;
}
.menu button {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; width: 100%;
  min-height: 44px; padding: 0 16px; font-size: 17px; text-align: left;
}
.menu button + button { border-top: 0.5px solid var(--sep); }
.menu button.sep-above { border-top: 8px solid var(--fill-3); }
.menu button:active { background: var(--fill-3); }
.menu button.destructive { color: var(--red); }
.menu .ic { width: 20px; height: 20px; }
.menu-layer.out .menu { animation: fadeOut 140ms ease both; }

/* ---------- Toast ---------- */

.toast {
  position: fixed; z-index: 120; left: 50%; top: calc(10px + env(safe-area-inset-top));
  transform: translate(-50%, -140%);
  display: flex; align-items: center; gap: 8px;
  max-width: calc(100vw - 32px); padding: 10px 18px; border-radius: 24px;
  background: color-mix(in srgb, var(--bg-elevated) 86%, transparent);
  -webkit-backdrop-filter: blur(24px) saturate(180%); backdrop-filter: blur(24px) saturate(180%);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.16), 0 0 0 0.5px var(--sep);
  font-size: 15px; font-weight: 600; letter-spacing: -0.02em;
  transition: transform 450ms cubic-bezier(0.2, 0.9, 0.3, 1.15), opacity 300ms ease;
  opacity: 0; pointer-events: none;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast .ic { color: var(--green); width: 20px; height: 20px; }

/* ---------- Help ---------- */

.help-list { margin: 0; padding: 0; list-style: none; }
.help-list li { display: flex; gap: 14px; padding: 12px 16px; align-items: flex-start; }
.help-list li + li { border-top: 0.5px solid var(--sep); }
.help-list .row-icon { flex: none; width: 29px; height: 29px; border-radius: 7px; display: grid; place-items: center; color: #fff; background: var(--c); }
.help-list .row-icon .ic { width: 18px; height: 18px; }
.help-list p { margin: 2px 0 0; font-size: 15px; color: var(--label-2); line-height: 1.4; }
.help-list strong { font-weight: 600; color: var(--label); }

/* ---------- Animations ---------- */

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }
@keyframes alertIn { from { opacity: 0; transform: scale(1.12); } to { opacity: 1; transform: none; } }
@keyframes menuIn { from { opacity: 0; transform: scale(0.6); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
}
@media (prefers-reduced-transparency: reduce) {
  .navbar { background: var(--bg); -webkit-backdrop-filter: none; backdrop-filter: none; }
  .alert, .menu, .toast { background: var(--bg-elevated); }
}

/* ---------- Print ---------- */

#print-root { display: none; }

@media print {
  @page { size: landscape; margin: 10mm; }
  body { background: #fff !important; }
  #app, #overlays, .toast, .drawer-scrim { display: none !important; }
  #print-root { display: block; }
  #print-root .gamecard { padding: 0; border-radius: 0; overflow: visible; }
  .gc-grid { grid-template-columns: 190px 1fr !important; }
}
