:root {
  color-scheme: light;
  --ink: #18211f;
  --muted: #64716d;
  --line: #d8dfdc;
  --paper: #f7f8f5;
  --panel: #ffffff;
  --green: #0f7b58;
  --green-dark: #0a553e;
  --blue: #315ea8;
  --amber: #d78b1d;
  --red: #b33a3a;
  --shadow: 0 18px 50px rgba(28, 42, 38, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

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

button,
input,
textarea {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(280px, 380px) minmax(0, 1fr);
  gap: 24px;
  width: min(1440px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px;
}

.control-panel,
.schedule-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.control-panel {
  align-self: start;
  position: sticky;
  top: 24px;
  padding: 24px;
}

.schedule-panel {
  min-width: 0;
  padding: 24px;
  scroll-margin-top: 16px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--green);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 12px;
  font-size: clamp(2rem, 4vw, 3rem);
  line-height: 1;
}

h2 {
  margin-bottom: 0;
  font-size: 1.45rem;
}

.intro {
  color: var(--muted);
  line-height: 1.55;
}

.setup-form {
  display: grid;
  gap: 16px;
  margin-top: 24px;
}

label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.85rem;
  font-weight: 800;
}

textarea,
input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  color: var(--ink);
  outline: none;
}

textarea {
  min-height: 220px;
  padding: 14px;
  resize: vertical;
  line-height: 1.45;
}

.control-panel.has-schedule textarea {
  min-height: 72px;
  max-height: 96px;
}

input {
  height: 44px;
  padding: 0 12px;
}

textarea:focus,
input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(15, 123, 88, 0.14);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.recent-players {
  display: grid;
  gap: 8px;
}

.recent-player-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.recent-player-chip {
  display: inline-flex;
  align-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #e9eeeb;
}

.recent-player-add,
.recent-player-delete {
  min-height: 36px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 0.84rem;
  font-weight: 800;
}

.recent-player-add {
  padding: 0 10px 0 13px;
}

.recent-player-delete {
  width: 32px;
  border-left: 1px solid #cfd8d3;
  color: var(--muted);
  font-size: 1rem;
}

.recent-player-chip:hover {
  border-color: var(--green);
  background: #dce9e2;
}

.recent-player-delete:hover {
  background: #f4dede;
  color: var(--red);
}

.button-row,
.panel-header,
.panel-actions,
.round-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.button-row {
  flex-wrap: wrap;
}

.panel-header {
  justify-content: space-between;
  margin-bottom: 20px;
}

.panel-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 800;
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.primary-button {
  padding: 0 18px;
  background: var(--green);
  color: white;
}

.primary-button:hover {
  background: var(--green-dark);
}

.ghost-button {
  padding: 0 16px;
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
}

.ghost-button:hover {
  border-color: #aeb9b5;
}

.compact {
  min-height: 36px;
}

.message {
  min-height: 24px;
  margin-top: 18px;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.4;
}

.message.error {
  color: var(--red);
  font-weight: 700;
}

.summary-panel {
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  overflow: hidden;
}

.summary-panel h3 {
  margin: 0;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 0.98rem;
}

.summary-table-wrap {
  max-height: 280px;
  overflow: auto;
}

.summary-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.summary-table th,
.summary-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.summary-table th {
  position: sticky;
  top: 0;
  background: #f1f5f2;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.summary-table tbody tr {
  cursor: pointer;
}

.summary-table tbody tr:hover {
  background: #eef8f3;
}

.summary-table tbody tr:focus-visible {
  outline: 3px solid rgba(15, 123, 88, 0.28);
  outline-offset: -3px;
}

.summary-table td:first-child {
  color: var(--green);
  font-weight: 900;
}

.summary-table tr:last-child td {
  border-bottom: 0;
}

.service-panel {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfa;
}

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

.service-buttons {
  display: flex;
  gap: 6px;
}

.service-start {
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
  font-size: 0.82rem;
}

.service-start.active {
  border-color: var(--green);
  background: var(--green);
  color: white;
}

.server-select-label {
  margin: 0;
}

.server-select {
  width: 100%;
  height: 38px;
  margin-top: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  padding: 0 10px;
}

.service-status {
  margin: 0;
  color: var(--muted);
  line-height: 1.35;
}

.round-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

.empty-state {
  display: grid;
  min-height: 280px;
  place-items: center;
  border: 1px dashed #b9c3bf;
  color: var(--muted);
  text-align: center;
}

.round-card {
  position: relative;
  display: grid;
  gap: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fff;
}

.round-card.complete {
  border-color: rgba(15, 123, 88, 0.35);
  background: #f3faf6;
}

.game-banner {
  position: absolute;
  inset: 14px 14px auto auto;
  transform: translateY(-8px) scale(0.92);
  opacity: 0;
  pointer-events: none;
  border-radius: 999px;
  background: var(--green);
  color: white;
  padding: 8px 14px;
  font-weight: 900;
  box-shadow: 0 10px 22px rgba(15, 123, 88, 0.28);
}

.round-card.game-ended .game-banner {
  animation: game-pop 1.3s ease both;
}

@keyframes game-pop {
  0% {
    opacity: 0;
    transform: translateY(-8px) scale(0.92);
  }
  18% {
    opacity: 1;
    transform: translateY(0) scale(1.08);
  }
  36% {
    transform: translateY(0) scale(1);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.round-topline {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.round-topline h3 {
  margin: 0;
  font-size: 1.05rem;
}

.scorekeeper {
  max-width: 45%;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  text-align: right;
}

.rest-list {
  margin: -8px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.35;
}

.matchup {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: stretch;
  gap: 10px;
}

.team {
  display: grid;
  gap: 7px;
  min-height: 94px;
  border-radius: 8px;
  padding: 12px;
  align-content: center;
}

.team-one {
  background: #eef6ff;
  border: 1px solid #cfe2fb;
}

.team-two {
  background: #fff6e8;
  border: 1px solid #f3d8ad;
}

.team-label {
  color: var(--muted);
  font-size: 0.73rem;
  font-weight: 900;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.team strong {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  line-height: 1.32;
}

.player-name {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.server-indicator {
  display: none;
  line-height: 1;
}

.player-name.is-serving .server-indicator {
  display: inline;
}

.player-divider {
  color: var(--muted);
}

.versus {
  align-self: center;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.scoreboard {
  display: grid;
  grid-template-columns: 42px minmax(56px, 1fr) 42px 42px minmax(56px, 1fr) 42px;
  gap: 8px;
  align-items: center;
  touch-action: manipulation;
}

.score {
  display: grid;
  min-height: 48px;
  place-items: center;
  border-radius: 8px;
  background: #f0f3f1;
  font-size: 1.6rem;
  font-weight: 900;
}

.score-button {
  width: 42px;
  min-height: 42px;
  background: #e8eeeb;
  color: var(--ink);
  font-size: 1.2rem;
  touch-action: manipulation;
}

.score-button:hover {
  background: #dce6e1;
}

.point-record {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfa;
}

.point-record[hidden] {
  display: none;
}

.point-list {
  width: 100%;
  overflow: auto;
}

.score-record-table {
  border-collapse: collapse;
  min-width: max-content;
  background: white;
}

.score-record-table th,
.score-record-table td {
  width: 34px;
  min-width: 34px;
  height: 28px;
  border: 2px solid #1f2926;
  text-align: center;
  vertical-align: middle;
}

.score-record-table th {
  height: 24px;
  background: #ffffff;
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 900;
}

.point-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #78df6f;
}

.round-actions {
  justify-content: space-between;
}

.mark-complete {
  flex: 1;
  background: var(--blue);
  color: white;
}

.reset-score {
  flex: 1;
  border: 1px solid var(--line);
  background: white;
}

.fairness-panel {
  margin-top: 16px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
  color: var(--muted);
}

.fairness-panel summary {
  width: fit-content;
  cursor: pointer;
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 900;
}

.fairness-panel p {
  margin: 8px 0 0;
  line-height: 1.45;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    padding: 14px;
  }

  .control-panel {
    position: static;
  }
}

@media (max-width: 520px) {
  .control-panel,
  .schedule-panel {
    padding: 18px;
  }

  .field-row,
  .matchup {
    grid-template-columns: 1fr;
  }

  .versus {
    text-align: center;
  }

  .scorekeeper {
    max-width: 55%;
  }

  .scoreboard {
    grid-template-columns: 42px 1fr 42px;
  }

}

@media print {
  body {
    background: white;
  }

  .control-panel,
  .scoreboard,
  .round-actions,
  .panel-actions {
    display: none;
  }

  .app-shell,
  .schedule-panel,
  .round-grid {
    display: block;
    box-shadow: none;
    border: 0;
    padding: 0;
  }

  .round-card {
    break-inside: avoid;
    margin-bottom: 10px;
  }
}
