:root {
  color-scheme: dark;
  --bg: #0b1220; --panel: #131e30; --panel2: #1b2940; --line: #2a3a53; --muted: #9aabc2; --text: #f3f6fb;
  --accent: #83e0bd; --accent2: #b8f3df; --accent-ink: #10221e; --danger: #ff8b8b; --warn: #ffc76b;
  --card-top: #f0f2f4; --card-bottom: #d9e0e5; --card-ink: #172333; --photo-bg: #e9edf1; --sil: #c5ced4;
  --photo: clamp(200px, min(40vh, 72vw), 380px);
  --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100dvh; color: var(--text);
  background: radial-gradient(ellipse at 50% -20%, #233b50 0%, var(--bg) 55%) fixed, var(--bg);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: var(--safe-top) max(12px, env(safe-area-inset-right)) var(--safe-bottom) max(12px, env(safe-area-inset-left));
}
button, input, select { font: inherit; color: inherit; }
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; padding: 10px 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--text); font-weight: 650; text-decoration: none; cursor: pointer;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
button:hover, .btn:hover { border-color: #65809f; }
button:disabled { opacity: .4; cursor: default; }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.ghost, .btn.ghost { background: transparent; }
button.danger { color: var(--danger); }
button.link { min-height: 0; padding: 2px 6px; border: 0; background: none; color: var(--accent); text-decoration: underline; }
button.big, .btn.big { min-height: 56px; padding: 12px 24px; font-size: 17px; }
select, input {
  min-height: 48px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: #0e1828; color: var(--text);
}
select:disabled { opacity: .7; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- top bar ---------- */
.topbar { max-width: 1120px; margin: 0 auto; padding: 14px 0 10px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; }
.logo { width: 40px; height: 40px; border-radius: 12px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 900; font-size: 20px; }
.brand-name { font-weight: 800; font-size: 20px; letter-spacing: -.3px; }
.picker { display: flex; gap: 8px; flex-wrap: wrap; }
.picker select { min-width: 150px; font-weight: 650; }
#leagueSelect { min-width: 0; }
/* team: a button that opens a searchable list (a plain <select> can't be searched) */
.team-picker { position: relative; }
.team-btn { width: 100%; min-width: 230px; max-width: 340px; justify-content: space-between; background: #0e1828; padding: 10px 12px; }
.team-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.team-btn .chev { color: var(--muted); font-size: 13px; }
.team-btn[aria-expanded="true"] { border-color: var(--accent); }
.team-panel {
  position: absolute; z-index: 20; top: calc(100% + 6px); left: 0; width: min(360px, calc(100vw - 24px));
  display: grid; gap: 8px; padding: 8px; border: 1px solid var(--line); border-radius: 16px; background: var(--panel);
  box-shadow: 0 18px 50px #000a;
}
.team-panel input { width: 100%; }
.team-list { list-style: none; margin: 0; padding: 0; max-height: min(60vh, 470px); overflow-y: auto; overscroll-behavior: contain; }
.team-opt { display: flex; align-items: center; min-height: 46px; padding: 8px 12px; border-radius: 10px; cursor: pointer; }
.team-opt:hover, .team-opt.active { background: var(--panel2); }
.team-opt[aria-selected="true"] { color: var(--accent); font-weight: 700; }
.team-opt[aria-selected="true"]::after { content: "✓"; margin-left: auto; }
.team-group { padding: 12px 12px 4px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.team-none { padding: 12px; color: var(--muted); }
.top-actions { display: flex; gap: 8px; }
.topbar-title { margin: 0 auto 0 0; font-size: 20px; }

/* ---------- practice ---------- */
.practice-main { max-width: 1120px; margin: 0 auto; display: grid; gap: 18px; padding-bottom: 24px; }
.stage { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.counter { margin: 0; min-height: 1.45em; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 15px; text-align: center; }
.no-clue { margin: 40px 0; max-width: 460px; text-align: center; color: var(--warn); font-size: 18px; }
.card {
  width: min(520px, 100%); padding: 18px 18px 14px; border-radius: 22px;
  background: linear-gradient(145deg, var(--card-top), var(--card-bottom)); color: var(--card-ink);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  box-shadow: 0 18px 50px #0006; cursor: pointer; user-select: none; -webkit-user-select: none;
  touch-action: pan-y; transition: transform .18s ease-out; -webkit-tap-highlight-color: transparent;
}
.part { position: relative; }
.face-part { width: var(--photo); aspect-ratio: 1; border-radius: 16px; overflow: hidden; background: var(--photo-bg); }
.face-part img { display: block; width: 100%; height: 100%; object-fit: cover; -webkit-user-drag: none; }
.silhouette { position: absolute; inset: 0; display: none; place-items: center; background: var(--photo-bg); }
.silhouette-svg { width: 78%; height: 78%; fill: var(--sil); margin-top: 22%; }
.no-photo-label { position: absolute; bottom: 10px; font-size: 13px; color: #6b7a89; font-weight: 700; display: none; }
.face-part.is-hidden img, .face-part.no-photo img { visibility: hidden; }
.face-part.is-hidden .silhouette, .face-part.no-photo .silhouette { display: grid; }
.face-part.no-photo:not(.is-hidden) .no-photo-label { display: block; }
.name-part, .number-part { width: 100%; display: flex; align-items: center; justify-content: center; text-align: center; }
.name-part { min-height: 2.3em; font-size: clamp(24px, 4.2vw, 38px); line-height: 1.1; font-weight: 850; letter-spacing: -.5px; }
.number-part { min-height: 1.15em; font-size: clamp(46px, 7.6vw, 72px); line-height: 1.05; font-weight: 900; font-variant-numeric: tabular-nums; }
.mask {
  position: absolute; inset: 4px 12%; display: none; place-items: center; border-radius: 12px;
  background: repeating-linear-gradient(135deg, #cfd7de 0 10px, #c7d0d8 10px 20px); color: #5f6f7f;
  font-size: 18px; font-weight: 800; letter-spacing: .5px;
}
.number-part .mask { inset: 6px 32%; }
.part.is-hidden .value { visibility: hidden; }
.part.is-hidden .mask { display: grid; }
.nav-row { display: flex; align-items: center; gap: 16px; }
.nav-row .round { width: 68px; height: 68px; min-height: 68px; border-radius: 50%; padding: 0; font-size: 36px; line-height: 1; }
.nav-row .reveal { min-width: 170px; min-height: 60px; font-size: 18px; }

.modes { background: linear-gradient(160deg, #18263a, #101b2b); border: 1px solid var(--line); border-radius: 20px; padding: 16px; align-self: start; }
.modes h2 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.modes h2 + div { margin-bottom: 16px; }
.toggles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.quick-modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.quick-modes button { font-size: 15px; padding: 8px; }
.toggles button[aria-pressed="false"] { color: var(--muted); text-decoration: line-through; }
.toggles button[aria-pressed="true"], .quick-modes button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); background: #173329; }
.hint { margin: 0; color: var(--muted); font-size: 13px; }

/* iPad landscape and desktop: modes beside the card */
@media (min-width: 1000px) and (min-aspect-ratio: 1/1) {
  .practice-main { grid-template-columns: minmax(0, 1fr) 320px; align-items: start; }
  .quick-modes { grid-template-columns: 1fr 1fr; }
  .modes { margin-top: 30px; }
}
@media (max-width: 560px) {
  .quick-modes { grid-template-columns: 1fr 1fr; }
  /* phone: team on its own row, league and season side by side under it */
  .picker { width: 100%; order: 3; display: grid; grid-template-columns: 1fr 1fr; }
  .picker select { min-width: 0; }
  .team-picker { grid-column: 1 / -1; order: -1; }
  .team-btn { min-width: 0; max-width: none; }
  .team-panel { width: 100%; }
  .nav-row .reveal { min-width: 130px; }
}

.empty { max-width: 520px; margin: 12vh auto; text-align: center; }
.empty h1 { margin: 0 0 8px; }
.empty p { color: var(--muted); }

/* ---------- manage ---------- */
.manage-body { max-width: 960px; margin: 0 auto; padding-bottom: 40px; display: grid; gap: 16px; }
.panel { background: linear-gradient(160deg, #18263a, #101b2b); border: 1px solid var(--line); border-radius: 20px; padding: 18px; }
.panel h2 { margin: 0 0 12px; font-size: 20px; }
.muted { color: var(--muted); }
.warn { color: var(--warn); }
.ok { color: var(--accent); }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.season { color: var(--accent); font-weight: 700; }
.deck-list, .player-list { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 10px; }
.deck-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: #0e1828; }
.deck-info { flex: 1 1 240px; display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: baseline; }
.deck-info small { flex-basis: 100%; color: var(--muted); }
.deck-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.deck-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }
.deck-head h2 { margin: 0 auto 0 0; }
.back { color: var(--accent); text-decoration: none; font-weight: 700; min-height: 48px; display: inline-flex; align-items: center; }
.player-row { display: grid; grid-template-columns: 76px 1fr auto; gap: 12px; align-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 14px; background: #0e1828; }
.thumb img, .thumb-empty { width: 76px; height: 76px; border-radius: 10px; display: block; object-fit: cover; background: var(--photo-bg); }
.thumb-empty { display: grid; place-items: center; }
.thumb-empty .silhouette-svg { width: 70%; height: 70%; margin-top: 20%; }
.fields { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; }
.fields label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 14px; }
.f-name input { width: min(260px, 52vw); }
.f-number input { width: 74px; }
.fields small { flex-basis: 100%; }
.flag { flex-basis: 100%; color: var(--warn); font-size: 14px; }
.player-row.attention { border-color: #6b5a2c; box-shadow: inset 4px 0 0 var(--warn); }
.list-tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 4px 0 12px; }
.list-search { flex: 1 1 260px; min-width: 0; }
button.chip { min-height: 44px; padding: 8px 14px; border-radius: 999px; font-size: 14px; color: var(--warn); }
button.chip[aria-pressed="true"] { background: #3a2d14; border-color: var(--warn); }
.list-heading { margin: 18px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.attention-all { display: flex; gap: 6px 12px; flex-wrap: wrap; align-items: center; margin: 0 0 12px; }
.attention-btn { color: var(--warn); border-color: #6b5a2c; }
.team-heading { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; justify-content: space-between; margin: 20px 0 8px; font-size: 18px; }
.team-heading a { color: var(--accent); font-size: 14px; font-weight: 700; text-decoration: none; min-height: 44px; display: inline-flex; align-items: center; }
.row-actions { display: flex; flex-direction: column; gap: 6px; }
.row-actions button { min-height: 40px; padding: 6px 12px; font-size: 14px; }
@media (max-width: 700px) {
  .player-row { grid-template-columns: 64px 1fr; }
  .row-actions { grid-column: 1 / -1; flex-direction: row; flex-wrap: wrap; }
  .thumb img, .thumb-empty { width: 64px; height: 64px; }
}

/* ---------- dialog, toast ---------- */
dialog { width: min(520px, calc(100vw - 24px)); border: 1px solid var(--line); border-radius: 20px; padding: 20px; background: var(--panel); color: var(--text); }
dialog.wide { width: min(760px, calc(100vw - 24px)); }
dialog::backdrop { background: #000a; }
dialog h2 { margin: 0 0 10px; }
.dialog-buttons { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 16px; }
.stack { display: grid; gap: 6px; margin-bottom: 12px; color: var(--muted); }
.callout { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: #0e1828; }
.preview-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.preview-grid figure { margin: 0; }
.preview-grid img, .preview-grid .thumb-empty { width: 100%; height: auto; aspect-ratio: 1; border-radius: 10px; display: block; object-fit: cover; background: var(--photo-bg); }
.preview-grid figcaption { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toast { position: fixed; left: 50%; bottom: calc(18px + var(--safe-bottom)); transform: translate(-50%, 30px); opacity: 0; pointer-events: none;
  background: #e5fff4; color: var(--accent-ink); padding: 12px 18px; border-radius: 12px; font-weight: 700; box-shadow: 0 8px 30px #0006; transition: .2s; z-index: 10; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.fatal { max-width: 520px; margin: 20vh auto; padding: 16px; border-radius: 14px; background: #3a1d24; color: #ffd9d9; text-align: center; }
