:root {
  color-scheme: light;
  --ink: #17201c;
  --muted: #68736f;
  --line: #c9d7d0;
  --panel: #ffffff;
  --paper: #f5f7f4;
  --field: #175c45;
  --field-dark: #0d3b2d;
  --clay: #b9522d;
  --gold: #f1c74b;
  --blue: #1d5d9b;
  --focus: #0e74d6;
  --shadow: 0 10px 26px rgba(23, 32, 28, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--paper);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
.file-button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

button.primary {
  border-color: var(--field);
  background: var(--field);
  color: #fff;
}

button.danger {
  border-color: #b83d32;
  color: #8e251d;
  background: #fff5f3;
}

.pin-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.45);
}

.pin-overlay[hidden] {
  display: none;
}

.pin-dialog {
  width: min(360px, 100%);
  padding: 22px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 18px 45px rgba(15, 23, 42, 0.22);
}

.pin-dialog h2 {
  margin: 0 0 14px;
  color: var(--green-dark);
}

.pin-dialog input {
  margin-top: 6px;
  text-align: center;
  font-size: 1.4rem;
  letter-spacing: 0.3rem;
}

.pin-error {
  min-height: 1.2rem;
  margin: 8px 0 12px;
  color: #8e251d;
  font-weight: 700;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus) 30%, transparent);
  outline-offset: 2px;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px clamp(14px, 3vw, 28px);
  background: linear-gradient(90deg, var(--field-dark), var(--field));
  color: #fff;
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 3px;
  color: #d8f2e9;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1,
h2 {
  margin: 0;
  line-height: 1.1;
}

h1 {
  font-size: clamp(1.35rem, 3vw, 2rem);
}

h2 {
  font-size: 1.1rem;
}

.dark {
  color: var(--field);
}

.header-actions,
.button-row,
.export-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.app-header button {
  border-color: rgba(255, 255, 255, 0.45);
}

main {
  display: grid;
  gap: 14px;
  padding: 14px clamp(10px, 2.5vw, 24px) 32px;
  min-width: 0;
}

main > * {
  min-width: 0;
}

.setup-panel,
.setup-card,
.line-score,
.toolbar,
.roster-layout,
.export-grid,
#summaryOutput {
  width: 100%;
  max-width: 1420px;
  margin: 0 auto;
}

.setup-card {
  display: grid;
  gap: 14px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.setup-view {
  display: none;
}

.setup-open .setup-view.active-view {
  display: block;
}

.setup-open .game-only,
.setup-open .game-view,
.setup-open .admin-view,
.game-started .setup-view {
  display: none;
}

.admin-view {
  display: none;
}

.admin-open .admin-view.active-view {
  display: grid;
  gap: 14px;
}

.admin-open .setup-view,
.admin-open .game-only,
.admin-open .game-view {
  display: none;
}

.admin-layout,
.admin-card {
  width: 100%;
  max-width: 1420px;
  margin: 0 auto;
}

.admin-card {
  display: grid;
  gap: 10px;
  padding: 16px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.setup-panel {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 10px;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
}

.schedule-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr);
}

.setup-lineups {
  display: grid;
  grid-template-columns: repeat(2, minmax(260px, 1fr));
  gap: 14px;
}

.setup-lineup-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 10px;
}

.lineup-entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(86px, auto);
  align-items: end;
  gap: 8px;
}

.sub-select-control {
  grid-column: 1 / -1;
}

.sub-select-control select {
  min-height: 96px;
}

.setup-actions {
  display: flex;
  justify-content: flex-end;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 650;
}

.pitcher-check {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f9fbf8;
  color: var(--field-dark);
  white-space: nowrap;
}

.pitcher-check input {
  width: auto;
  min-height: 0;
  margin: 0;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 8px 10px;
}

textarea {
  min-height: 260px;
  resize: vertical;
}

.wide {
  grid-column: span 2;
}

.line-score {
  overflow-x: auto;
  padding-bottom: 2px;
}

.line-score-table {
  width: 100%;
  min-width: 680px;
  border-collapse: separate;
  border-spacing: 2px;
  table-layout: fixed;
}

.line-score-table th,
.line-score-table td {
  height: 38px;
  padding: 6px 8px;
  background: #fff;
  border: 1px solid var(--line);
  text-align: center;
  font-weight: 800;
}

.line-score-table thead th {
  height: 28px;
  color: var(--muted);
  font-size: 0.72rem;
}

.line-score-table .team-col {
  width: min(26vw, 210px);
  text-align: left;
  font-size: 0.92rem;
}

.line-score-table tbody .team-col {
  border-left: 5px solid var(--clay);
  color: var(--field-dark);
}

.line-score-table .total-col {
  width: 54px;
  background: #f9fbf8;
  color: var(--field-dark);
}

.line-score-table tbody .total-col {
  font-size: 1.15rem;
}

.line-score-table tr.batting th,
.line-score-table tr.batting td {
  box-shadow: inset 0 -3px 0 rgba(29, 93, 155, 0.32);
}

.game-status {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.segmented {
  display: inline-grid;
  grid-template-columns: repeat(3, minmax(92px, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.segmented button {
  border: 0;
  border-radius: 0;
}

.segmented .active {
  background: var(--blue);
  color: #fff;
}

.status {
  color: var(--muted);
  font-size: 0.85rem;
}

.view {
  display: none;
  min-width: 0;
}

.active-view {
  display: block;
}

.play-layout {
  width: 100%;
  max-width: 1420px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(520px, 0.82fr) minmax(360px, 1fr);
  gap: 12px;
}

.play-panel,
.side-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.play-panel {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.play-head,
.play-actions,
.play-player-row,
.play-detail-grid {
  display: grid;
  gap: 10px;
}

.play-head {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.play-count {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.play-count span {
  min-width: 86px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef7f2;
  text-align: center;
  font-weight: 800;
}

.play-player-row {
  grid-template-columns: 92px minmax(170px, 260px);
}

.result-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}

.result-buttons button {
  min-height: 48px;
  border-color: #b9c9c1;
  font-weight: 700;
}

.result-buttons button.active {
  border-color: var(--field);
  background: var(--field);
  color: #fff;
}

.play-detail-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: end;
}

.rbi-control {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.rbi-buttons {
  display: grid;
  grid-template-columns: repeat(5, minmax(38px, 1fr));
  gap: 6px;
}

.rbi-buttons button {
  width: 100%;
  min-width: 0;
  min-height: 40px;
  padding: 0;
  font-weight: 800;
}

.rbi-buttons button.active {
  border-color: var(--field);
  background: var(--field);
  color: #fff;
}

.toggle-line {
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-size: 0.9rem;
}

.toggle-line input {
  width: 20px;
  min-height: 20px;
}

.runner-panel {
  display: grid;
  gap: 8px;
}

.runner-events {
  display: grid;
  gap: 8px;
}

.runner-event {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(120px, 180px) auto;
  gap: 8px;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbf9;
}

.runner-event button {
  min-width: 42px;
  padding: 0 10px;
}

.runner-event input[readonly] {
  background: #fff;
  font-weight: 800;
}

.runner-base-label {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: end;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #eef7f2;
  color: var(--field-dark);
  font-weight: 900;
}

.empty-runner-state {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.play-actions {
  grid-template-columns: minmax(82px, auto) minmax(82px, auto) minmax(100px, auto) minmax(100px, auto) minmax(170px, 240px);
  justify-content: end;
}

.play-side {
  display: grid;
  align-content: start;
  gap: 12px;
}

.side-card {
  padding: 16px;
}

.side-card p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.diamond-card {
  overflow: hidden;
}

.base-diamond {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  margin-top: 10px;
  border-radius: 8px;
  background-color: #23714f;
  background-image: none;
  border: 1px solid var(--line);
}

.base-path {
  position: absolute;
  inset: 19% 19%;
  transform: rotate(45deg);
  border: 3px solid rgba(255, 255, 255, 0.72);
}

.base {
  position: absolute;
  width: 54px;
  height: 54px;
  transform: translate(-50%, -50%) rotate(45deg);
  border: 2px solid #fff;
  background: #f9f4d5;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.18);
  min-height: 54px;
  padding: 0;
  cursor: pointer;
}

.base span {
  display: block;
  transform: rotate(-45deg);
  color: var(--field-dark);
  font-size: 0.7rem;
  font-weight: 900;
  line-height: 50px;
  text-align: center;
}

.base.active {
  background: var(--gold);
  border-color: var(--field-dark);
  box-shadow: 0 0 0 4px rgba(241, 199, 75, 0.34), 0 3px 10px rgba(0, 0, 0, 0.18);
}

.base-home {
  left: 50%;
  top: 83%;
}

.base-first {
  left: 82%;
  top: 52%;
}

.base-second {
  left: 50%;
  top: 20%;
}

.base-third {
  left: 18%;
  top: 52%;
}

.runner-token {
  position: absolute;
  width: clamp(72px, 18%, 104px);
  min-height: 44px;
  transform: translate(-50%, -50%);
  border: 3px solid #fff;
  border-radius: 8px;
  background: var(--gold);
  color: #111;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.22);
  font-weight: 900;
  padding: 0 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  cursor: pointer;
  overflow: hidden;
  text-align: center;
}

.runner-token span {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: clamp(0.62rem, 1.6vw, 0.78rem);
  line-height: 1.05;
}

.runner-token small {
  font-size: 0.58rem;
  line-height: 1;
}

.runner-token.pending {
  background: #fff;
  border-color: var(--gold);
  border-style: dashed;
}

.runner-token.ghost {
  border-style: dashed;
}

.runner-token.scored {
  background: var(--blue);
  color: #fff;
}

.runner-token.out {
  background: var(--clay);
  color: #fff;
}

.runner-first {
  left: 76%;
  top: 45%;
}

.runner-second {
  left: 50%;
  top: 30%;
}

.runner-third {
  left: 24%;
  top: 45%;
}

.runner-home,
.runner-scored {
  left: 50%;
  top: 73%;
}

.runner-out {
  left: 50%;
  top: 50%;
}

.scorebook-wrap {
  width: 100%;
  max-width: 1420px;
  min-width: 0;
  max-height: calc(100vh - 320px);
  min-height: 430px;
  margin: 0 auto;
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.scorebook-title {
  width: min(100%, 1420px);
  margin: 16px auto 8px;
  font-size: 1.05rem;
}

.scorebook {
  width: 100%;
  min-width: 1260px;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}

.scorebook th,
.scorebook td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 5px;
  vertical-align: top;
}

.scorebook th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--field);
  color: #fff;
  font-size: 0.78rem;
}

.slot-col {
  width: 46px;
  text-align: center;
}

.player-col {
  width: 210px;
}

.inning-col {
  width: 108px;
}

.total-col {
  width: 70px;
  text-align: center;
}

.scorebook td:first-child,
.scorebook th:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
}

.scorebook td:first-child {
  background: #f3faf5;
  font-weight: 800;
  text-align: center;
}

.scorebook th:first-child {
  z-index: 5;
}

.player-cell {
  position: sticky;
  left: 46px;
  z-index: 2;
  background: #fff;
}

.player-cell select {
  margin-bottom: 4px;
}

.scorebook-pitcher {
  min-height: 30px;
  padding: 4px 8px;
  font-size: 0.72rem;
}

.scorebook th.player-cell {
  z-index: 5;
  background: var(--field);
}

.atbat {
  display: grid;
  grid-template-columns: 1fr 38px;
  gap: 4px;
}

.atbat select,
.atbat input {
  min-height: 32px;
  padding: 4px 6px;
  font-size: 0.85rem;
}

.atbat-note {
  grid-column: span 2;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.25;
}

.atbat label {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
}

.atbat input[type="checkbox"] {
  width: 18px;
  min-height: 18px;
}

.mini-row {
  grid-column: span 2;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 4px;
}

.atbat .run-check {
  flex-direction: column;
  justify-content: center;
  gap: 1px;
  text-align: center;
}

.totals-row th,
.totals-row td {
  background: #fff7da;
  font-weight: 800;
}

.key {
  width: min(100%, 1420px);
  margin: 10px auto 0;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.key span {
  padding: 5px 8px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.78rem;
}

.roster-layout {
  display: grid;
  grid-template-columns: minmax(220px, 320px) 1fr;
  gap: 12px;
}

.roster-list,
.roster-editor,
#exportsView {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.install-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbf9;
}

.install-panel p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.35;
}

.install-panel button:disabled {
  opacity: 0.55;
  cursor: default;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.team-list {
  display: grid;
  gap: 6px;
}

.team-list button {
  justify-content: flex-start;
}

.team-list button.active {
  background: #e8f4ee;
  border-color: var(--field);
}

.hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

#exportsView {
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
}

.file-button input {
  display: none;
}

#summaryOutput {
  display: block;
  margin-top: 12px;
  min-height: 220px;
}

@media (max-width: 900px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .setup-panel {
    grid-template-columns: repeat(2, minmax(130px, 1fr));
  }

  .setup-lineups {
    grid-template-columns: 1fr;
  }

  .line-score-table {
    min-width: 620px;
  }

  .roster-layout {
    grid-template-columns: 1fr;
  }

  .play-layout {
    grid-template-columns: 1fr;
  }

  .scorebook-wrap {
    max-height: none;
  }
}

@media (max-width: 560px) {
  .setup-panel,
  .setup-lineup-list {
    grid-template-columns: 1fr;
  }

  .lineup-entry {
    grid-template-columns: 1fr;
  }

  .wide {
    grid-column: span 1;
  }

  .segmented {
    width: 100%;
    grid-template-columns: 1fr;
  }

  .play-head,
  .play-player-row,
  .play-detail-grid,
  .runner-event,
  .play-actions,
  .install-panel {
    grid-template-columns: 1fr;
  }

  .play-count {
    justify-content: stretch;
  }

  .play-count span {
    flex: 1;
  }

  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }
}

@media print {
  .app-header,
  .toolbar,
  .key,
  #adminView,
  #exportsView {
    display: none !important;
  }

  body {
    background: #fff;
  }

  main {
    padding: 0;
  }

  .setup-panel,
  .line-score,
  .scorebook-wrap {
    box-shadow: none;
    border-radius: 0;
  }
}
