:root {
  color-scheme: dark;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #ffffff;
  background: #111315;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
  --red: #ed2948;
  --red-dark: #a51630;
  --surface: #1c2024;
  --surface-raised: #272c31;
  --line: #444b52;
  --muted: #b3bac1;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
}

button,
input {
  font: inherit;
}

button {
  min-height: 48px;
  border: 0;
  border-radius: 12px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

.app {
  width: min(100%, 1100px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 18px max(32px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 30px;
}

.topbar h1,
h2,
p {
  margin-top: 0;
}

.topbar h1 {
  margin-bottom: 0;
  font-size: 2rem;
  line-height: 1;
}

.eyebrow {
  margin-bottom: 6px;
  color: var(--red);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.13em;
}

.header-actions {
  display: flex;
  margin-left: auto;
  gap: 10px;
}

.icon-button {
  display: grid;
  width: 50px;
  height: 50px;
  padding: 0;
  place-items: center;
  color: var(--red);
  background: var(--surface-raised);
}

.icon-button svg {
  width: 21px;
  height: 21px;
  fill: currentColor;
}

.editor h2,
.display h2 {
  margin-bottom: 16px;
  font-size: 1.25rem;
}

.add-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 76px 140px auto;
  gap: 10px;
}

.add-form input,
.add-form select {
  width: 100%;
  min-width: 0;
  min-height: 54px;
  padding: 0 15px;
  border: 1px solid #555d65;
  border-radius: 12px;
  color: #ffffff;
  background: var(--surface);
  font-size: 1rem;
}

.add-form input:focus-visible,
button:focus-visible {
  outline: 3px solid #e7ac42;
  outline-offset: 2px;
}

.add-button {
  flex: 0 0 auto;
  padding: 0 18px;
  color: #ffffff;
  background: var(--red-dark);
}

@media (max-width: 640px) {
  .add-form {
    grid-template-columns: minmax(0, 1fr) 90px;
  }

  .add-form select,
  .add-button {
    grid-column: 1 / -1;
  }
}

.hint,
.display-heading > p:last-child {
  margin: 12px 0 18px;
  color: var(--muted);
  font-size: 0.9rem;
}

.player-list,
.display-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.player-row {
  display: grid;
  grid-template-columns: 48px 44px minmax(0, 1fr) 52px;
  align-items: center;
  min-height: 64px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}

.player-row.is-dragging {
  opacity: 0.45;
}

.drag-handle,
.remove-button {
  display: grid;
  width: 100%;
  height: 100%;
  min-height: 62px;
  place-items: center;
  border-radius: 0;
  color: var(--muted);
  background: transparent;
}

.drag-handle {
  color: var(--muted);
  font-size: 1.35rem;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.drag-handle:active {
  cursor: grabbing;
}

.player-name {
  overflow: hidden;
  font-size: 1.05rem;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-details,
.display-player-details {
  display: grid;
  min-width: 0;
  gap: 3px;
}

.player-meta {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 650;
}

.remove-button {
  color: var(--red);
  font-size: 1.6rem;
}

.empty-state {
  padding: 26px 16px;
  border: 1px dashed #555d65;
  border-radius: 14px;
  color: var(--muted);
  text-align: center;
}

.display-heading {
  text-align: center;
}

.display-heading h2 {
  margin-bottom: 4px;
  font-size: clamp(1.6rem, 6vw, 2.1rem);
}

.at-bat {
  display: flex;
  min-height: 34px;
  align-items: baseline;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px 10px;
  margin: 8px 0 0;
  padding: 4px 0;
  color: var(--muted);
  text-align: center;
}

.at-bat-label {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.14em;
}

.at-bat strong {
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.1;
}

.at-bat-meta {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.display-list {
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
}

.display-player {
  display: flex;
  min-height: 76px;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 2px solid transparent;
  border-radius: 15px;
  color: #ffffff;
  background: var(--surface-raised);
  text-align: left;
}

.display-player.is-selected {
  border-color: var(--red);
  background: #421923;
}

.order-number {
  display: grid;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 50%;
  color: #ffffff;
  background: var(--red-dark);
  font-weight: 800;
}

.display-player-name {
  overflow-wrap: anywhere;
  font-size: clamp(1.05rem, 2.2vw, 1.5rem);
  font-weight: 700;
}

.display-player .player-meta {
  font-size: clamp(0.95rem, 1.8vw, 1.2rem);
}

html:fullscreen body {
  height: 100%;
  overflow: hidden;
  background: #111315;
}

html:fullscreen .app {
  display: flex;
  width: 100%;
  height: 100%;
  min-height: 0;
  max-width: none;
  flex-direction: column;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

html:fullscreen .topbar {
  flex: 0 0 auto;
  margin-bottom: 12px;
}

html:fullscreen .display {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
}

html:fullscreen .display-heading {
  flex: 0 0 auto;
}

html:fullscreen .display-heading .eyebrow,
html:fullscreen .display-heading > p:last-child {
  display: none;
}

html:fullscreen .display-heading h2 {
  margin-bottom: 6px;
}

html:fullscreen .at-bat {
  flex: 0 0 auto;
  min-height: 30px;
  margin: 4px 0 0;
  padding: 2px 0;
  gap: 4px;
}

html:fullscreen .display-list {
  min-height: 0;
  flex: 1;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: repeat(var(--lineup-count), minmax(0, 1fr));
  gap: clamp(1px, 0.4vh, 4px);
  overflow: hidden;
  padding: 0 2px;
}

html:fullscreen .display-player {
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: 2px 12px;
  gap: 10px;
}

html:fullscreen .display-player-details {
  display: flex;
  min-width: 0;
  align-items: baseline;
  gap: 12px;
}

html:fullscreen .order-number {
  width: clamp(22px, 3.6vh, 36px);
  height: clamp(22px, 3.6vh, 36px);
  font-size: clamp(0.95rem, 2.8vh, 1.35rem);
}

html:fullscreen .display-player-name {
  min-width: 0;
  overflow: hidden;
  font-size: clamp(1rem, 4vh, 2.2rem);
  text-overflow: ellipsis;
  white-space: nowrap;
}

html:fullscreen .display-player .player-meta {
  flex: 0 0 auto;
  font-size: clamp(0.8rem, 2.1vh, 1.1rem);
}

html:fullscreen .at-bat strong {
  font-size: clamp(0.85rem, 1.8vh, 1rem);
}

html:fullscreen .at-bat-meta {
  font-size: clamp(0.75rem, 1.5vh, 0.85rem);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  clip-path: inset(50%);
}

[hidden] {
  display: none !important;
}

@media (max-width: 420px) {
  .app {
    padding-right: 14px;
    padding-left: 14px;
  }

  .topbar {
    flex-wrap: wrap;
  }

}

@media (max-height: 560px) and (orientation: landscape) {
  .app {
    padding-top: 10px;
    padding-bottom: 10px;
  }

  .topbar {
    margin-bottom: 12px;
  }

}
