:root {
  color-scheme: dark;
  --page-bg: #0f172a;
  --panel-bg: #111827;
  --panel-deep: #020617;
  --border: #334155;
  --muted: #94a3b8;
  --text: #e5e7eb;
  --accent: #2563eb;
  --danger: #dc2626;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--page-bg);
  color: var(--text);
}

a { color: #93c5fd; }

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

button {
  min-height: 48px;
  padding: 12px 16px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
}

button:hover { filter: brightness(1.08); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid #60a5fa;
  outline-offset: 2px;
}

input,
select,
textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-deep);
  color: #fff;
  font-size: 16px;
}

textarea { resize: vertical; }
label { display: block; margin: 10px 0; color: #cbd5e1; }
code {
  display: block;
  padding: 12px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-deep);
}

.login-card {
  width: min(420px, calc(100% - 32px));
  margin: 90px auto;
  padding: 30px;
  border: 2px solid var(--border);
  border-radius: 20px;
  background: var(--panel-bg);
}

.login-card button {
    display: block;
    width: 70%;
    margin: 18px auto 0 auto;
    padding: 14px 0;
    font-size: 18px;
    font-weight: 700;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-deep);
}

.topbar h1 { margin: 0; }
.subtle, .small { color: var(--muted); font-size: 14px; }

.control-shell { max-width: 1500px; margin: 0 auto; }
.panel {
  margin: 20px;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--panel-bg);
}
.panel h2:first-child { margin-top: 0; }

/* Compact, always-visible preview */
.preview-panel {
  position: sticky;
  top: 76px;
  z-index: 80;
  padding: 8px 14px;
  overflow: hidden;
  background: rgba(17, 24, 39, .98);
  backdrop-filter: blur(8px);
}
.preview-panel .small,
.preview-panel code { display: none; }
.overlay-preview-wrap {
  position: relative;
  width: min(100%, 920px);
  aspect-ratio: 930 / 320;
  margin: 0 auto;
  overflow: hidden;
}
.overlay-preview-wrap iframe {
  position: absolute;
  inset: 0 auto auto 0;
  width: 930px;
  height: 320px;
  border: 0;
  background: transparent;
  transform-origin: top left;
}
@media (min-width: 970px) {
  .overlay-preview-wrap iframe { transform: scale(.989); }
}
@media (max-width: 969px) {
  .overlay-preview-wrap iframe { transform: scale(calc((100vw - 56px) / 930)); }
}

.grid-form,
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  align-items: end;
}
.import-form { margin-top: 12px; }

.control-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}
.score-card,
.atbat-card > div,
.play-menu,
.toggle-row {
  border: 1px solid var(--border);
  background: var(--panel-deep);
}
.score-card { padding: 16px; border-radius: 16px; }
.score-card h3 { margin-top: 0; }
.score-row { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.score-row button { width: 64px; height: 64px; padding: 0; font-size: 28px; }
.score-row strong { min-width: 72px; text-align: center; font-size: 44px; }

.mini-grid,
.big-button-grid,
.toggle-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}
.big-button-grid button { min-height: 76px; font-size: 22px; }
.play-menu { margin-top: 18px; padding: 16px; border-radius: 16px; }
.hidden { display: none !important; }

.atbat-card {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.atbat-card > div { padding: 14px; border-radius: 14px; }
.atbat-card .label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.atbat-card strong { display: block; margin-top: 6px; font-size: 24px; }

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  margin: 0;
  padding: 14px;
  border-radius: 12px;
}
.toggle-row input,
.check input { width: auto; margin-right: 8px; transform: scale(1.35); }
.settings-toggle { align-self: end; }
.inline-form { display: flex; gap: 8px; }
.danger { background: var(--danger); }

table { width: 100%; margin-top: 16px; border-collapse: collapse; }
th, td { padding: 12px; border-bottom: 1px solid var(--border); text-align: left; }
.log-box {
  max-height: 80vh;
  margin: 20px;
  padding: 20px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel-deep);
}

/* Overlay */
.overlay {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: transparent;
  color: #fff;
  font-family: Arial, Helvetica, sans-serif;
}

.score-title {
  position: absolute;
  top: 3px;
  z-index: 5;
  height: 34px;
  padding: 2px 14px;
  overflow: hidden;
  border-bottom: 2px solid #b91c1c;
  background: transparent;
  color: #fff;
  text-align: center;
  font-size: 25px;
  font-weight: 900;
  line-height: 30px;
  text-shadow: 2px 2px 2px #000;
}
.score-title span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.banner-logo { display: block; width: 100%; height: 28px; object-fit: contain; }

.allstar-board {
  position: absolute;
  left: 8px;
  top: 36px;
  width: var(--board-width);
  height: 158px;
  display: grid;
  grid-template-columns: 185px 72px 108px var(--bases-width) var(--count-width) var(--pitcher-width);
  grid-template-rows: 79px 79px;
  overflow: hidden;
  border: 2px solid #707070;
  border-radius: 10px;
  background: #050505;
  box-shadow: 0 0 12px rgba(0,0,0,.9);
}
.team-col {
  grid-column: 1;
  grid-row: 1 / span 2;
  display: grid;
  grid-template-rows: 1fr 1fr;
  border-right: 2px solid #333;
}
.team-logo-row { display: flex; align-items: center; justify-content: center; overflow: hidden; }
.team-logo-row img { width: 72px; height: 68px; object-fit: contain; }
.team-logo-row span { padding: 8px; text-align: center; font-size: 21px; font-weight: 900; }
.away-bg { background: var(--away-logo-bg); }
.home-bg { background: var(--home-logo-bg); }

.score-col {
  grid-column: 2;
  grid-row: 1 / span 2;
  display: grid;
  grid-template-rows: 1fr 1fr;
  border-right: 2px solid #333;
}
.score-col div {
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 2px solid #333;
  color: #fff;
  font-size: 58px;
  font-weight: 900;
  text-shadow: 2px 2px 3px #777;
}
.score-col div:last-child { border-bottom: 0; }

.inning-col {
  grid-column: 3;
  grid-row: 1 / span 2;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border-right: 2px solid #333;
}
.inning-number { font-size: 74px; font-weight: 900; text-shadow: 2px 2px 3px #777; }
.inning-arrows { position: absolute; top: 40px; right: 8px; display: grid; gap: 45px; }
.arrow-up, .arrow-down { display: block; width: 0; height: 0; opacity: .35; }
.arrow-up { border-right: 13px solid transparent; border-bottom: 17px solid #777; border-left: 13px solid transparent; }
.arrow-down { border-top: 17px solid #777; border-right: 13px solid transparent; border-left: 13px solid transparent; }
.arrow-up.active { border-bottom-color: #ffe100; opacity: 1; }
.arrow-down.active { border-top-color: #ffe100; opacity: 1; }

.bases-col {
  grid-column: 4;
  grid-row: 1 / span 2;
  position: relative;
  border-right: 2px solid #333;
}
.diamond {
  position: absolute;
  width: 46px;
  height: 46px;
  border: 4px solid #d1d5db;
  border-radius: 3px;
  background: transparent;
  transform: rotate(45deg);
}
.diamond.on { border-color: #ffe100; background: #ffe100; }
.diamond.second { left: 78px; top: 30px; }
.diamond.third { left: 43px; top: 66px; }
.diamond.first { left: 113px; top: 66px; }

.count-outs-col,
.pitcher-col {
  grid-row: 1 / span 2;
  display: grid;
  grid-template-rows: 1fr 1fr;
  border-right: 2px solid #333;
}
.count-outs-col { grid-column: 5; }
.pitcher-col { grid-column: 6; }
.count-outs-col.single-stat,
.pitcher-col.single-stat { grid-template-rows: 1fr; }

.stat-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-bottom: 2px solid #333;
}
.stat-box:last-child,
.single-stat .stat-box { border-bottom: 0; }
.stat-box span { font-size: 15px; font-weight: 900; letter-spacing: 1px; }
.stat-box strong { font-size: 34px; font-weight: 900; text-shadow: 2px 2px 2px #777; }
.pitcher-box strong {
  max-width: 120px;
  overflow: hidden;
  font-size: 25px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pitches-box strong { font-size: 58px; }
.outs-dots { display: flex; gap: 8px; margin-top: 7px; }
.outs-dots i { display: block; width: 29px; height: 29px; border: 3px solid #d1d5db; border-radius: 50%; }
.outs-dots i.on { border-color: #ffe100; background: #ffe100; }

.atbat-strip,
.commentary-strip {
  position: absolute;
  left: 8px;
  width: var(--board-width);
  border: 2px solid #707070;
  border-radius: 8px;
  background: linear-gradient(#111, #030303);
  box-shadow: 0 0 12px rgba(0,0,0,.9);
}
.atbat-strip {
  top: 202px;
  height: 51px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 24px;
}
.atbat-label { color: #ef233c; font-size: 25px; font-weight: 900; }
.atbat-name, .today, .avg { font-size: 20px; font-weight: 900; }
.avg em { font-size: 16px; font-style: italic; font-weight: 400; }
.divider { width: 2px; height: 34px; background: #aaa; }
.commentary-strip {
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 24px;
  text-align: center;
  font-size: 24px;
  font-weight: 900;
}
.commentary-strip.below-atbat { top: 262px; }
.commentary-strip.without-atbat { top: 202px; }

@media (min-width: 1100px) {
  .control-shell { display: grid; grid-template-columns: 1fr 1fr; align-items: start; }
  .preview-panel { grid-column: 1 / -1; }
}

@media (max-width: 700px) {
  .topbar { padding: 14px; }
  .panel { margin: 12px; padding: 14px; }
  .preview-panel { top: 68px; }
  .score-row button { width: 58px; height: 58px; }
  table { font-size: 14px; }
  th, td { padding: 8px; }
}


/* Roster current-batter controls */
.current-batter-row {
  background: rgba(37, 99, 235, 0.16);
}

.at-bat-button {
  min-width: 88px;
}

.at-bat-button:disabled {
  cursor: default;
  background: #166534;
  opacity: 1;
}

/* ===== Dual Home/Away lineup layout ===== */
.control-shell {
  display: block;
}

.game-flow-panel,
.shared-controls-panel {
  width: auto;
}

.team-control-columns {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
  margin: 20px;
}

.team-control-columns > .panel {
  margin: 0;
  min-width: 0;
}

.team-control-panel {
  border-top-width: 5px;
}

.away-team-panel {
  border-top-color: var(--away-accent, #991b1b);
}

.home-team-panel {
  border-top-color: var(--home-accent, #1d4ed8);
}

.team-panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.team-panel-heading h2 {
  margin: 0;
}

.team-panel-heading span {
  border-radius: 999px;
  background: #1e293b;
  padding: 6px 10px;
  color: #cbd5e1;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .06em;
}

.team-score-row {
  justify-content: center;
  margin: 12px 0 22px;
}

.team-lineup-form,
.import-form {
  grid-template-columns: minmax(150px, 1fr) minmax(100px, .45fr) auto;
}

.import-form {
  grid-template-columns: minmax(180px, 1fr) auto;
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
}

.lineup-table {
  min-width: 700px;
}

@media (min-width: 1100px) {
  .control-shell {
    display: block;
  }

  .preview-panel {
    width: auto;
  }
}

@media (max-width: 1000px) {
  .team-control-columns {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  .team-control-columns {
    gap: 12px;
    margin: 12px;
  }

  .team-lineup-form,
  .import-form {
    grid-template-columns: 1fr;
  }
}

.pitch-count-summary {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  color: #cbd5e1;
  font-size: 14px;
}

.pitch-count-summary span {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid #334155;
  border-radius: 10px;
  background: #0f172a;
  text-align: center;
}


/* Collapsible sticky overlay preview */
.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 920px;
  margin: 0 auto 8px;
}
.preview-header h2 {
  margin: 0;
  font-size: 16px;
}
.preview-toggle {
  min-height: 38px;
  padding: 7px 14px;
}
.preview-content {
  width: 100%;
}
.preview-panel.collapsed {
  padding-top: 8px;
  padding-bottom: 8px;
}
.preview-panel.collapsed .preview-content {
  display: none;
}
.preview-panel.collapsed .preview-header {
  margin-bottom: 0;
}

/* ===== Roster / active-lineup management ===== */
.roster-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin: 14px 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel-deep);
}

.lineup-size-form {
  display: flex;
  align-items: end;
  gap: 10px;
}

.lineup-size-form label {
  margin: 0;
}

.lineup-size-form input {
  width: 110px;
}

.roster-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.roster-actions form {
  margin: 0;
}

.secondary-button {
  background: #475569;
}

.button-link.secondary-button {
  min-height: 48px;
}

.team-control-panel h4 {
  margin: 20px 0 8px;
  color: #e2e8f0;
  font-size: 16px;
}

.drag-handle {
  width: 38px;
  cursor: grab;
  color: #94a3b8;
  text-align: center;
  font-size: 20px;
  user-select: none;
}

.draggable-player.dragging {
  opacity: .45;
  background: rgba(37, 99, 235, .22);
}

.bench-row {
  background: rgba(15, 23, 42, .55);
}

.substitution-form {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.empty-row {
  padding: 20px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 700px) {
  .roster-toolbar,
  .lineup-size-form,
  .roster-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .lineup-size-form input {
    width: 100%;
  }

  .substitution-form {
    grid-template-columns: 1fr;
  }

  .drag-handle {
    display: none;
  }
}


/* Overlay URL controls */
.overlay-link-row {
  width: min(100%, 920px);
  margin: 10px auto 0;
  display: grid;
  grid-template-columns: minmax(240px, 1fr) auto auto;
  gap: 10px;
  align-items: end;
}

.overlay-url-label {
  grid-column: 1 / -1;
  margin: 0;
  color: #cbd5e1;
  font-size: 13px;
  font-weight: 700;
}

.overlay-link-row input {
  min-width: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

.overlay-link-row .button-link {
  min-height: 48px;
  white-space: nowrap;
}

@media (max-width: 800px) {
  .overlay-link-row {
    grid-template-columns: 1fr;
  }

  .overlay-url-label {
    grid-column: 1;
  }
}
