:root {
  color-scheme: light;
  --ink: #17201b;
  --muted: #607069;
  --line: #d9e3de;
  --paper: #f7faf8;
  --panel: #ffffff;
  --green: #1c7c54;
  --green-dark: #115d3d;
  --gold: #b77b14;
  --blue: #2d6cdf;
  --red: #c84630;
  --shadow: 0 18px 50px rgba(22, 54, 38, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(28, 124, 84, 0.12), rgba(45, 108, 223, 0.06)),
    var(--paper);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-header,
.app-shell {
  width: min(1440px, calc(100% - 10px));
  margin-inline: auto;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 28px 0 20px;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.mode-picker {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 900;
}

.mode-picker select {
  min-width: 110px;
}

body[data-mode="player"] .admin-only,
body[data-mode="player"] #sampleScores,
body[data-mode="player"] #resetDemo,
body[data-mode="player"] #pairingLockButton,
body[data-mode="player"] #pairingLockStatus,
body[data-mode="player"] #addPlayerForm {
  display: none;
}

body[data-locked-player="true"] #modePicker {
  display: none;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--green-dark);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

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

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

.ghost-button,
.add-player-form button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-weight: 800;
  box-shadow: 0 8px 18px rgba(22, 54, 38, 0.08);
}

.ghost-button {
  padding: 0 18px;
}

.app-shell {
  padding-bottom: 28px;
}

.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 12px;
}

.tab-button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-weight: 900;
  padding: 0 16px;
  white-space: nowrap;
}

.tab-button.active {
  border-color: var(--green);
  background: var(--green);
  color: #fff;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.score-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
  align-items: start;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
  padding: 18px;
}

.table-panel {
  margin-top: 18px;
}

.scorecard-panel {
  padding: 14px;
}

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

.section-heading.compact {
  margin-bottom: 12px;
}

.hole-picker,
.money-input,
.course-picker {
  display: grid;
  gap: 6px;
  min-width: 116px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 800;
}

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

.hole-summary,
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.scorecard-count {
  min-width: 116px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fcfa;
  padding: 9px 12px;
}

.scorekeeper-badge {
  min-width: 128px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fcfa;
  padding: 9px 12px;
}

.scorekeeper-badge strong {
  display: block;
  margin-top: 2px;
  font-size: 1.05rem;
}

.scorecard-count strong {
  display: block;
  margin-top: 2px;
  font-size: 1.05rem;
}

.hole-summary div,
.stat-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fcfa;
  padding: 12px;
}

.summary-label {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
}

.hole-summary strong,
.stat-card strong {
  display: block;
  margin-top: 3px;
  font-size: 1.35rem;
}

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

.player-score,
.leader-row,
.foursome,
.closest-card,
.pairing-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.player-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.player-name {
  min-width: 0;
  font-weight: 900;
}

.player-meta {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.score-controls {
  display: grid;
  grid-template-columns: 44px minmax(56px, 1fr) 44px;
  gap: 8px;
  align-items: center;
}

.score-controls button {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 8px;
  background: var(--green);
  color: #fff;
  font-size: 1.35rem;
  font-weight: 900;
}

.score-controls output {
  display: grid;
  min-height: 44px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 1.45rem;
  font-weight: 950;
}

.leaderboard,
.foursomes,
.pairing-cards,
.closest-grid {
  display: grid;
  gap: 9px;
}

.leader-row {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  gap: 10px;
  align-items: center;
}

.rank {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 50%;
  background: #e8f4ee;
  color: var(--green-dark);
  font-weight: 900;
}

.leader-score {
  font-size: 1.15rem;
  font-weight: 950;
}

.under {
  color: var(--blue);
}

.over {
  color: var(--red);
}

.even {
  color: var(--green-dark);
}

.winner {
  color: var(--gold);
  font-weight: 950;
}

.add-player-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 70px;
  gap: 8px;
  margin-bottom: 12px;
}

.add-player-form button {
  background: var(--green);
  color: #fff;
}

.saved-player-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 12px;
  padding: 10px;
}

.saved-player-heading {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  margin-bottom: 8px;
  text-transform: uppercase;
}

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

.saved-player-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-weight: 800;
}

button:disabled,
input:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.lock-status {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 12px;
  padding: 10px 12px;
  font-size: 0.9rem;
  font-weight: 900;
}

.lock-status.locked {
  border-color: #14834f;
  background: #f2fff7;
  color: #0d4d30;
}

.lock-status.unlocked {
  background: #fffaf0;
  color: #7a5700;
}

.foursome h3,
.closest-card h3,
.pairing-card h3 {
  margin-bottom: 8px;
  font-size: 0.95rem;
}

.foursome ul,
.pairing-card ul {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--muted);
  font-weight: 700;
}

.foursome li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
}

.foursome-player-name {
  min-width: 0;
}

.empty-foursome {
  color: var(--muted);
  font-style: italic;
}

.group-add-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-top: 10px;
}

.group-add-form button {
  background: var(--green);
  color: #fff;
}

.quota-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f9fcfa;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  padding: 4px 8px;
}

.remove-player-button {
  border: 1px solid #f1c2bf;
  border-radius: 8px;
  background: #fff5f3;
  color: var(--red);
  font-size: 0.72rem;
  font-weight: 900;
  padding: 5px 8px;
}

.closest-card {
  display: grid;
  gap: 10px;
}

.closest-won {
  border-color: #14834f;
  background: #f2fff7;
}

.closest-winner {
  color: #0d4d30;
  font-size: 1.1rem;
}

.closest-pending {
  color: #7a5700;
  font-size: 1.1rem;
}

.closest-card label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 800;
}

.scorekeeper-grid {
  display: grid;
  gap: 12px;
}

.scorekeeper-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 800;
}

.course-form {
  display: grid;
  gap: 16px;
}

.course-name-field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 800;
}

.course-par-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(110px, 1fr));
  gap: 10px;
}

.course-hole-card {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}

.course-hole-card legend {
  color: var(--green-dark);
  font-size: 0.78rem;
  font-weight: 900;
  padding: 0 4px;
}

.course-hole-card label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
}

.course-hole-card input {
  text-align: center;
  font-weight: 900;
}

.course-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.course-actions button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--green);
  color: #fff;
  font-weight: 900;
  padding: 0 16px;
}

.course-actions .danger-button {
  border-color: #c84630;
  background: #c84630;
  color: #fff;
}

.live-status {
  border: 1px solid var(--line);
  border-radius: 8px;
  min-width: 130px;
  padding: 12px;
  text-align: center;
  font-weight: 900;
}

.live-status.online {
  border-color: #14834f;
  background: #f2fff7;
  color: #0d4d30;
}

.live-status.offline {
  background: #fffaf0;
  color: #7a5700;
}

.live-grid {
  display: grid;
  gap: 14px;
  margin-bottom: 16px;
}

.live-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 800;
}

.live-config-field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  color: var(--ink);
  font: 0.85rem ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  resize: vertical;
}

.live-details {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
  margin-top: 14px;
  padding: 10px 12px;
}

.share-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  margin-top: 14px;
}

.share-box label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 800;
}

.quota-key {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.quota-key span {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  padding: 7px 10px;
}

.table-scroll {
  overflow-x: auto;
}

.scorecard-scroll {
  max-height: calc(100vh - 215px);
  min-height: 520px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  text-align: center;
  white-space: nowrap;
}

th:first-child,
td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: #fff;
  text-align: left;
}

thead th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.total-cell {
  font-weight: 950;
}

.scorecard-table {
  min-width: 870px;
  table-layout: fixed;
}

.slot-col {
  width: 32px;
}

.player-col {
  width: 132px;
}

.hole-col {
  width: 32px;
}

.total-col {
  width: 46px;
}

.scorecard-table th,
.scorecard-table td {
  height: 36px;
  padding: 2px;
}

.scorecard-table thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #f5faf7;
}

.scorecard-table th:first-child,
.scorecard-table td:first-child {
  width: 32px;
  min-width: 32px;
  z-index: 4;
}

.scorecard-table th:nth-child(2),
.scorecard-table td:nth-child(2) {
  position: sticky;
  left: 32px;
  z-index: 2;
  width: 132px;
  min-width: 132px;
  background: #fff;
  text-align: left;
}

.scorecard-table thead th:nth-child(2) {
  z-index: 5;
  background: #f5faf7;
}

.slot-cell,
.slot-head {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
}

.player-cell strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}

.scorecard-table th span,
.scorecard-table th small {
  display: block;
  line-height: 1.05;
}

.scorecard-table th small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.58rem;
  font-weight: 800;
}

.score-square-cell {
  width: 32px;
  vertical-align: top;
}

.score-square {
  width: 28px;
  height: 28px;
  min-height: 28px;
  border-radius: 5px;
  padding: 0;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 900;
}

.score-square::-webkit-inner-spin-button,
.score-square::-webkit-outer-spin-button {
  appearance: none;
  margin: 0;
}

.score-square {
  appearance: textfield;
}

.net-score {
  display: block;
  margin-top: 2px;
  color: var(--green-dark);
  font-size: 0.58rem;
  font-weight: 900;
  line-height: 1;
}

.score-square:focus {
  border-color: var(--green);
  outline: 2px solid rgba(28, 124, 84, 0.18);
}

.locked-score-row .player-cell {
  color: #89968f;
}

.locked-score-row .score-square {
  background: #f3f6f4;
  color: #9aa9a2;
}

.score-square.low-pending {
  border-color: #d7a20f;
  background: #fff2b8;
  color: #5f4300;
}

.score-square.low-final {
  border-color: #14834f;
  background: #c8f2d8;
  color: #0d4d30;
}

.empty-row td {
  color: #9aa9a2;
  background: #fbfdfc;
}

.empty-row td:nth-child(2) {
  background: #fbfdfc;
}

.muted-slot {
  color: #9aa9a2;
  font-size: 0.82rem;
  font-weight: 800;
}

.leaderboard-wide {
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
}

.loading-cell {
  height: 140px;
  color: var(--muted);
  font-weight: 900;
  text-align: center;
}

.empty-message {
  height: 90px;
  color: var(--muted);
  font-weight: 900;
  text-align: center;
}

@media (max-width: 900px) {
  .score-layout {
    grid-template-columns: 1fr;
  }

  .score-grid,
  .hole-summary,
  .stat-grid {
    grid-template-columns: 1fr;
  }

  .course-par-grid {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }
}

@media (max-width: 560px) {
  .course-par-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .app-header,
  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .header-actions,
  .add-player-form,
  .share-box {
    display: grid;
    grid-template-columns: 1fr;
  }
}
