:root {
  color-scheme: light;
  --ink: #10221c;
  --muted: #607069;
  --green-950: #082f25;
  --green-900: #0b3d2e;
  --green-700: #176647;
  --green-100: #e4f2e9;
  --cream: #f7f3e8;
  --paper: #fffdf7;
  --clay: #d4673e;
  --clay-dark: #a94224;
  --line: #d9dfd9;
  --shadow: 0 14px 40px rgb(11 61 46 / 0.12);
  font-family: Inter, ui-rounded, "SF Pro Rounded", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--cream);
  color: var(--ink);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--green-950); }
body { margin: 0; min-width: 320px; min-height: 100vh; background: linear-gradient(165deg, #f9f6ed 0%, #edf3e9 100%); }
button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible { outline: 3px solid #f3ae66; outline-offset: 2px; }

.app-shell { min-height: 100vh; min-height: 100dvh; padding-bottom: env(safe-area-inset-bottom); }
.topbar { min-height: calc(72px + env(safe-area-inset-top)); padding: calc(12px + env(safe-area-inset-top)) clamp(16px, 4vw, 36px) 12px; display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--green-950); color: white; }
.brand { appearance: none; border: 0; background: transparent; color: inherit; display: flex; align-items: center; gap: 11px; padding: 0; text-align: left; cursor: pointer; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 1rem; letter-spacing: .01em; }
.brand small { margin-top: 1px; color: #b9d5c8; font-size: .72rem; }
.ball-mark { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; color: var(--clay); background: var(--paper); transform: rotate(45deg); box-shadow: inset 0 0 0 2px rgb(212 103 62 / .25); }
.offline-badge { padding: 7px 10px; border: 1px solid rgb(255 255 255 / .18); border-radius: 999px; color: #d8e9df; font-size: .72rem; white-space: nowrap; }
main { width: min(100%, 920px); margin: 0 auto; padding: clamp(22px, 5vw, 48px) clamp(16px, 4vw, 32px) 48px; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(2rem, 8vw, 3.6rem); line-height: .98; letter-spacing: -.045em; }
h2 { font-size: clamp(1.35rem, 5vw, 2rem); letter-spacing: -.025em; }
.lede { max-width: 560px; color: var(--muted); font-size: 1.05rem; line-height: 1.55; }
.eyebrow { margin-bottom: 8px; color: var(--clay-dark); font-size: .75rem; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
.section-heading { display: flex; justify-content: space-between; align-items: end; gap: 16px; margin-bottom: 18px; }
.section-heading h1, .section-heading h2 { margin-bottom: 0; }
.card { border: 1px solid rgb(16 34 28 / .1); border-radius: 22px; background: rgb(255 253 247 / .9); box-shadow: var(--shadow); }
.home-actions { display: grid; gap: 14px; margin-top: 32px; }
.action-card { min-height: 128px; padding: 22px; display: flex; align-items: center; justify-content: space-between; gap: 18px; border: 0; border-radius: 22px; text-align: left; cursor: pointer; box-shadow: var(--shadow); }
.action-card strong, .action-card small { display: block; }
.action-card strong { margin-bottom: 5px; font-size: 1.25rem; }
.action-card small { line-height: 1.4; opacity: .78; }
.action-card.primary { color: white; background: var(--green-700); }
.action-card.secondary { color: var(--ink); background: var(--paper); border: 1px solid var(--line); }
.arrow { font-size: 1.75rem; }
.status-strip { margin-top: 18px; padding: 15px 17px; display: flex; justify-content: space-between; gap: 14px; border-radius: 16px; background: var(--green-100); color: var(--green-900); font-weight: 700; }
.button { min-height: 50px; padding: 12px 18px; border: 0; border-radius: 14px; font-weight: 800; cursor: pointer; }
.button.primary { background: var(--green-700); color: white; }
.button.secondary { border: 1px solid var(--line); background: var(--paper); color: var(--ink); }
.button.danger { background: #a6332a; color: white; }
.button.ghost { background: transparent; color: var(--green-700); }
.button:disabled { cursor: not-allowed; opacity: .45; }
.button.full { width: 100%; }
.empty-state { padding: 42px 24px; text-align: center; }
.empty-state .empty-symbol { width: 58px; height: 58px; margin: 0 auto 16px; display: grid; place-items: center; border-radius: 50%; background: var(--green-100); color: var(--green-700); font-size: 1.65rem; }
.empty-state p { color: var(--muted); }
.player-list, .selection-list, .order-list, .upcoming-list { margin: 0; padding: 0; list-style: none; }
.player-row, .selection-row, .order-row { min-height: 66px; padding: 10px 12px 10px 16px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); }
.player-row:last-child, .selection-row:last-child, .order-row:last-child { border-bottom: 0; }
.player-info { min-width: 0; flex: 1; }
.player-info strong, .player-info small { display: block; }
.player-info strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-info small { margin-top: 2px; color: var(--muted); }
.status-dot { width: 10px; height: 10px; flex: 0 0 auto; border-radius: 50%; background: #79a18d; }
.status-dot.inactive { background: #b7bbb8; }
.row-actions { display: flex; gap: 6px; }
.icon-button { width: 46px; height: 46px; display: grid; place-items: center; border: 0; border-radius: 12px; background: #eef2ed; color: var(--ink); font-size: 1.15rem; cursor: pointer; }
.setup-grid { display: grid; gap: 20px; }
.setup-section { overflow: hidden; }
.setup-section > header { padding: 18px 18px 10px; display: flex; align-items: center; justify-content: space-between; }
.count-pill { min-width: 32px; padding: 5px 9px; border-radius: 999px; background: var(--green-100); color: var(--green-900); text-align: center; font-weight: 800; }
.selection-row label { display: flex; align-items: center; gap: 13px; width: 100%; min-height: 46px; cursor: pointer; }
.selection-row input { width: 24px; height: 24px; accent-color: var(--green-700); }
.setup-footer { position: sticky; bottom: 0; z-index: 2; margin: 24px -8px 0; padding: 14px 8px calc(14px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--cream) 18%); }
.validation { min-height: 24px; margin: 0 0 8px; color: #922f27; text-align: center; font-weight: 700; }
.stepper { display: flex; gap: 7px; }
.stepper button { width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 12px; background: white; font-size: 1.15rem; }
.drag-handle { color: #829088; font-size: 1.2rem; touch-action: none; cursor: grab; }
.order-row.dragging { opacity: .45; }
.setup-options { display: grid; gap: 14px; margin-top: 20px; }
.starter-choice { padding: 18px; }
.starter-choice fieldset, fieldset { margin: 0; padding: 0; border: 0; }
.starter-choice legend, fieldset legend { margin-bottom: 10px; font-weight: 800; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { min-height: 48px; display: grid; place-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: white; font-weight: 800; cursor: pointer; }
.segmented input:checked + span { border-color: var(--green-700); background: var(--green-100); color: var(--green-900); box-shadow: inset 0 0 0 1px var(--green-700); }

.game-page { margin: calc(clamp(22px, 5vw, 48px) * -1) calc(clamp(16px, 4vw, 32px) * -1) -48px; min-height: calc(100dvh - 72px); padding: 20px clamp(16px, 4vw, 32px) calc(28px + env(safe-area-inset-bottom)); background: var(--green-950); color: white; }
.game-meta { display: flex; justify-content: space-between; align-items: center; gap: 12px; color: #bed4c8; font-weight: 700; }
.game-meta .button { color: #f4d7ca; }
.scoreboard { margin: 12px 0 16px; padding: 12px; display: grid; grid-template-columns: 1fr 1fr 1.35fr; gap: 8px; border: 1px solid rgb(255 255 255 / .16); border-radius: 18px; background: rgb(255 255 255 / .08); }
.score-team, .game-situation, .outs-display { min-height: 62px; display: flex; flex-direction: column; justify-content: center; }
.score-team { padding: 6px 10px; border-radius: 12px; background: rgb(255 255 255 / .07); }
.score-team span, .outs-display > span:first-child { color: #a9c4b7; font-size: .68rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.score-team strong { font-size: 1.8rem; line-height: 1; }
.game-situation { padding-left: 5px; }
.game-situation strong { font-size: .95rem; }
.game-situation span { margin-top: 4px; color: #bed4c8; font-size: .74rem; }
.outs-display { grid-column: 1 / -1; min-height: auto; flex-direction: row; align-items: center; gap: 8px; padding: 3px 6px 0; }
.outs-display strong { font-size: 1rem; }
.out-dots { display: flex; gap: 6px; margin-left: auto; }
.out-dots i { width: 13px; height: 13px; border: 1px solid #91aa9e; border-radius: 50%; }
.out-dots i.active { border-color: var(--clay); background: var(--clay); }
.batter-card { margin-top: 12px; padding: clamp(24px, 7vw, 42px) 20px; border-radius: 26px; background: var(--paper); color: var(--ink); text-align: center; box-shadow: 0 18px 50px rgb(0 0 0 / .22); }
.batter-card .eyebrow { margin-bottom: 12px; }
.batter-name { margin-bottom: 10px; font-size: clamp(2.65rem, 13vw, 5.5rem); line-height: .92; overflow-wrap: anywhere; }
.gender-chip { display: inline-flex; padding: 7px 13px; border-radius: 999px; background: var(--green-100); color: var(--green-900); font-weight: 800; }
.on-deck { margin: 16px 0; padding: 15px 18px; display: flex; justify-content: space-between; align-items: center; border: 1px solid rgb(255 255 255 / .16); border-radius: 16px; background: rgb(255 255 255 / .08); }
.on-deck span { color: #bed4c8; font-size: .78rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.on-deck strong { font-size: 1.2rem; }
.complete-button { width: 100%; min-height: 84px; border: 0; border-radius: 20px; background: var(--clay); color: white; font-size: clamp(1.2rem, 5vw, 1.55rem); font-weight: 900; box-shadow: 0 8px 0 #9c3f22; cursor: pointer; }
.complete-button:active { transform: translateY(5px); box-shadow: 0 3px 0 #9c3f22; }
.score-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }
.counter-control { padding: 10px; border: 1px solid rgb(255 255 255 / .14); border-radius: 17px; background: rgb(255 255 255 / .07); }
.counter-label { display: block; margin-bottom: 7px; color: #bed4c8; font-size: .7rem; font-weight: 800; letter-spacing: .06em; text-align: center; text-transform: uppercase; }
.counter-row { display: grid; grid-template-columns: minmax(48px, 1fr) minmax(38px, auto) minmax(54px, 1.15fr); align-items: center; gap: 6px; }
.counter-row output { color: white; font-size: 1.45rem; font-weight: 900; text-align: center; }
.counter-button { min-height: 54px; border: 0; border-radius: 12px; color: white; font-size: 1.65rem; font-weight: 900; cursor: pointer; }
.counter-button.decrement { border: 1px solid rgb(255 255 255 / .25); background: transparent; color: #d9e5df; }
.counter-button.increment.run { background: #237a50; }
.counter-button.increment.out { background: #7d3e2d; }
.counter-button:disabled { cursor: not-allowed; opacity: .32; }
.game-actions { margin: 12px 0 24px; }
.game-actions .button.secondary { background: transparent; border-color: rgb(255 255 255 / .22); color: white; }
.undo-button { width: 100%; }
.upcoming-title { margin-bottom: 10px; color: #bed4c8; font-size: .77rem; letter-spacing: .11em; text-transform: uppercase; }
.upcoming-list { overflow: hidden; border: 1px solid rgb(255 255 255 / .13); border-radius: 18px; }
.upcoming-list li { min-height: 52px; padding: 9px 14px; display: grid; grid-template-columns: 30px 1fr auto; align-items: center; gap: 10px; border-bottom: 1px solid rgb(255 255 255 / .1); }
.upcoming-list li:last-child { border-bottom: 0; }
.upcoming-list .number { color: #82aa97; font-weight: 800; }
.upcoming-list small { color: #a9c4b7; }
.opponent-zone { display: grid; gap: 16px; }
.opponent-card { padding: clamp(26px, 7vw, 44px) 22px; border-radius: 24px; background: var(--paper); color: var(--ink); text-align: center; box-shadow: 0 18px 50px rgb(0 0 0 / .22); }
.opponent-card h1 { margin-bottom: 12px; font-size: clamp(2rem, 9vw, 4rem); }
.opponent-card > p:not(.eyebrow) { max-width: 480px; margin: 0 auto; color: var(--muted); line-height: 1.5; }
.opponent-outs { margin-top: 24px; display: flex; align-items: baseline; justify-content: center; gap: 8px; }
.opponent-outs strong { font-size: 3.5rem; line-height: 1; color: var(--clay-dark); }
.opponent-outs span { color: var(--muted); font-weight: 800; }
dialog { width: min(calc(100% - 28px), 460px); padding: 0; border: 0; border-radius: 22px; background: transparent; box-shadow: 0 24px 70px rgb(0 0 0 / .35); }
dialog::backdrop { background: rgb(4 21 16 / .72); backdrop-filter: blur(3px); }
.dialog-card { display: grid; gap: 18px; padding: 24px; background: var(--paper); color: var(--ink); }
.dialog-card h2 { margin-bottom: 0; }
.dialog-card label { display: grid; gap: 8px; font-weight: 800; }
.dialog-card input[type="text"], .dialog-card input:not([type]) { width: 100%; min-height: 52px; padding: 12px 14px; border: 1px solid #b7c2bb; border-radius: 12px; background: white; font-size: 1rem; }
.dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-error { min-height: 20px; margin: 0; color: #922f27; font-weight: 700; }
.danger-icon { width: 50px; height: 50px; display: grid; place-items: center; border-radius: 50%; background: #f8ded9; color: #922f27; font-size: 1.5rem; font-weight: 900; }
.muted-note { color: var(--muted); font-size: .88rem; }

@media (min-width: 680px) {
  .home-actions, .setup-grid { grid-template-columns: 1fr 1fr; }
  .setup-options { grid-template-columns: 1fr 1fr; }
  .home-actions .action-card:first-child { grid-column: 1 / -1; }
  .game-page { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(270px, .8fr); grid-template-rows: auto auto auto 1fr; gap: 0 24px; }
  .game-meta { grid-column: 1 / -1; }
  .scoreboard { grid-column: 1 / -1; grid-template-columns: 1fr 1fr 1.5fr 1fr; }
  .outs-display { grid-column: auto; min-height: 62px; flex-direction: column; align-items: flex-start; padding: 0 8px; gap: 3px; }
  .out-dots { margin-left: 0; }
  .batter-zone { grid-column: 1; grid-row: 3 / 5; }
  .queue-zone { grid-column: 2; grid-row: 3 / 5; padding-top: 12px; }
  .opponent-zone { grid-column: 1 / -1; grid-template-columns: 1.2fr .8fr; align-items: start; }
.opponent-zone .score-controls { margin-top: 0; }
  .opponent-zone .game-actions { grid-column: 2; margin-top: -4px; }
}

@media (prefers-reduced-motion: no-preference) {
  .card, .batter-card { animation: rise .25s ease-out; }
  @keyframes rise { from { opacity: 0; transform: translateY(8px); } }
}
