:root {
  --bg: #e8e9ea;
  --surface: #ffffff;
  --surface-alt: #f1f3f5;

  --text: #111417;
  --muted: #6c737a;

  --accent: #3a6ea5;
  --accent-strong: #2c5480;

  --border: #e5e7eb;
  --border-strong: #d6d9de;

  --danger: #b13a2e;

  --radius: 16px;
  --radius-sm: 14px;

  --shadow: 0 1px 2px rgba(17, 20, 23, 0.03), 0 6px 16px rgba(17, 20, 23, 0.035);
  --button-shadow: 0 1px 2px rgba(17, 20, 23, 0.04), 0 3px 10px rgba(17, 20, 23, 0.035);

  --space-1: 8px;
  --space-2: 12px;
  --space-3: 16px;
  --space-4: 20px;
  --space-5: 24px;

  --font-sans: "Avenir Next", "Segoe UI", sans-serif;

  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.5rem;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

a,
button,
input {
  font: inherit;
}

a {
  color: inherit;
}

.app {
  width: min(720px, 100%);
  margin: 0 auto;
  padding: var(--space-3);
}

#appShell.hidden {
  display: none;
}

.hidden {
  display: none !important;
}

.app-header,
.top-bar {
  display: grid;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.app-header-copy {
  display: grid;
  gap: 4px;
}

.app-kicker,
.section-label,
.label {
  margin: 0;
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.app-title,
.top-bar h1,
.welcome-title {
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.2;
  font-weight: 700;
}

h2 {
  margin: 0;
  font-size: var(--text-lg);
  line-height: 1.2;
}

.welcome-card,
.card,
.about-legal-card,
.hole-header,
.table-wrap,
.score-row {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.welcome-card,
.card,
.about-legal-card,
.hole-header {
  padding: var(--space-4);
}

.welcome-card {
  display: grid;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.welcome-kicker {
  margin: 0;
  color: var(--muted);
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.welcome-copy {
  margin: 0;
  color: var(--muted);
  font-size: var(--text-base);
  line-height: 1.5;
}

.welcome-cta {
  width: 100%;
  min-height: 56px;
}

.about-legal {
  width: min(720px, 100%);
  margin: 0 auto var(--space-4);
  padding: 0 var(--space-3);
}

.about-legal-card p {
  margin: 0 0 var(--space-2);
  color: var(--muted);
  font-size: var(--text-sm);
  line-height: 1.6;
}

.about-legal-card p:last-child {
  margin-bottom: 0;
}

.copyright-line {
  margin-top: var(--space-3);
  font-weight: 400;
}

.copyright-copy {
  font-size: 0.52rem;
  color: var(--muted);
}

button,
.button-link {
  min-height: 48px;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 0 var(--space-3);
  background: var(--accent);
  color: #ffffff;
  font-weight: 600;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--button-shadow);
}

button:hover:not(:disabled),
.button-link:hover {
  background: var(--accent-strong);
  box-shadow: 0 1px 2px rgba(28, 36, 43, 0.05), 0 5px 12px rgba(28, 36, 43, 0.045);
}

button:active:not(:disabled),
.button-link:active {
  background: var(--accent-strong);
}

button:focus-visible,
.button-link:focus-visible,
.footer-text-link:focus-visible {
  outline: 2px solid rgba(47, 93, 98, 0.22);
  outline-offset: 2px;
}

button:disabled {
  opacity: 0.45;
  cursor: default;
}

button.ghost,
.ghost-link {
  background: var(--surface-alt);
  color: var(--accent);
}

button.danger {
  background: #f3ece7;
  color: var(--danger);
}

button.ghost:hover:not(:disabled),
.ghost-link:hover {
  background: #e8e3dc;
  color: var(--accent);
}

button.danger:hover:not(:disabled) {
  background: #eee4dc;
  color: var(--danger);
}

.footer-links {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex-wrap: wrap;
}

.footer-text-link {
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: var(--text-sm);
  font-weight: 400;
  text-decoration: none;
}

.footer-text-link:hover {
  background: transparent;
  color: var(--text);
}

.footer-text-button {
  box-shadow: none;
}

.footer-separator {
  color: var(--border-strong);
  font-size: var(--text-sm);
}

.top-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-2);
}

.top-actions button {
  font-size: var(--text-sm);
}

.utility-btn {
  min-height: 42px;
  padding: 0 14px;
  width: 100%;
  justify-self: stretch;
}

.utility-btn-players {
  background: #ece7e0;
  color: var(--accent-strong);
}

.utility-btn-players:hover:not(:disabled) {
  background: #e4ddd4;
}

.utility-btn-new-round {
  background: #e7efef;
  color: var(--accent);
}

.utility-btn-new-round:hover:not(:disabled) {
  background: #dbe7e7;
}

.setup-card {
  display: grid;
  gap: var(--space-3);
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: var(--space-2);
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: var(--text-sm);
  line-height: 1.5;
}

.add-player-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--space-2);
}

input {
  width: 100%;
  min-height: 52px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0 var(--space-3);
  font-size: var(--text-base);
  background: var(--surface-alt);
  color: var(--text);
}

#setupView input {
  background: var(--surface);
  border-color: var(--border);
}

input::placeholder {
  color: var(--muted);
}

input:focus-visible {
  outline: none;
  border-color: var(--border-strong);
  background: var(--surface);
}

.players-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--space-2);
}

.players-list li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--space-2);
  align-items: center;
  padding: var(--space-2) var(--space-3);
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
}

.player-item-name {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.remove-player-btn {
  min-width: 34px;
  min-height: 34px;
  padding: 0;
  background: transparent;
  color: var(--danger);
  box-shadow: inset 0 0 0 1px rgba(140, 61, 51, 0.12);
  border-radius: 10px;
  font-size: 0.9rem;
}

.setup-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-2);
}

.setup-primary-action {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-2);
}

.game-panel {
  display: grid;
  gap: var(--space-3);
}

.hole-header {
  display: grid;
  gap: var(--space-2);
}

.hole-nav {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) 56px;
  gap: var(--space-2);
  align-items: center;
}

.nav-btn {
  padding: 0;
  min-height: 56px;
  min-width: 56px;
  font-size: 1.8rem;
  line-height: 1;
  background: var(--surface-alt);
  color: var(--accent-strong);
}

.nav-btn:hover:not(:disabled) {
  background: #e4ddd4;
  color: var(--accent-strong);
}

.hole-current {
  min-width: 0;
  text-align: center;
}

.hole-caption {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: var(--text-sm);
}

#holeTitle {
  margin: 0;
  font-size: 2rem;
  line-height: 1;
  letter-spacing: -0.03em;
}

.score-rows {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--space-2);
}

.score-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--space-2);
  align-items: center;
  padding: 14px;
}

.player-meta {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.player-name {
  margin: 0;
  font-size: var(--text-base);
  font-weight: 700;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.player-total {
  margin: 0;
  color: var(--muted);
  font-size: var(--text-sm);
}

.counter {
  display: grid;
  grid-template-columns: repeat(3, 48px);
  align-items: stretch;
  background: transparent;
  border-radius: 0;
  gap: 6px;
  padding: 0;
}

.counter button {
  min-height: 48px;
  border-radius: 12px;
  padding: 0;
  background: var(--surface-alt);
  color: var(--accent);
  box-shadow: none;
}

.counter button:hover:not(:disabled),
.counter button:active:not(:disabled) {
  background: rgba(47, 93, 98, 0.08);
}

.dec,
.inc {
  font-size: 1.4rem;
  font-weight: 700;
}

.score-value {
  width: 48px;
  min-width: 48px;
  height: 48px;
  background: var(--surface);
  color: var(--text);
  font-size: 1.35rem;
  font-weight: 700;
  border-radius: 999px;
  box-shadow: inset 1px 0 0 var(--border), inset -1px 0 0 var(--border);
}

.score-value:hover:not(:disabled),
.score-value:active:not(:disabled) {
  background: var(--surface);
}

.score-value.score-edited {
  background: var(--accent);
  color: #ffffff;
  box-shadow: inset 1px 0 0 rgba(255, 255, 255, 0.08), inset -1px 0 0 rgba(255, 255, 255, 0.08);
}

.row-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-2);
}

.row-next-btn {
  min-height: 56px;
  font-size: var(--text-base);
}

.report {
  display: grid;
  gap: var(--space-2);
}

.report-only-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

#exitReportOnlyBtn {
  background: var(--accent);
  color: #ffffff;
}

#exitReportOnlyBtn:hover:not(:disabled) {
  background: var(--accent-strong);
}

.report-only-bar.hidden {
  display: none;
}

.report-only-mode #holeHeader,
.report-only-mode #scoreRows,
.report-only-mode #rowActions {
  display: none;
}

.confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: var(--space-3);
  background: rgba(28, 36, 43, 0.32);
}

.confirm-dialog {
  width: min(100%, 420px);
  background: var(--surface);
  border-radius: 20px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.14);
  padding: var(--space-4);
  display: grid;
  gap: var(--space-3);
}

.confirm-title {
  margin: 0;
  font-size: var(--text-lg);
  color: var(--text);
}

.confirm-message {
  margin: 0;
  color: var(--muted);
  font-size: var(--text-base);
  line-height: 1.5;
}

.confirm-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-2);
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.9rem;
}

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

th {
  background: var(--surface-alt);
  color: var(--muted);
  font-size: var(--text-sm);
  font-weight: 700;
}

th:nth-child(1),
td:nth-child(1),
th:nth-child(2),
td:nth-child(2),
th:nth-child(3),
td:nth-child(3) {
  position: sticky;
  background: var(--surface);
  box-shadow: 1px 0 0 var(--surface-alt);
}

th:nth-child(1),
td:nth-child(1) {
  left: 0;
  min-width: 44px;
  width: 44px;
  z-index: 4;
}

th:nth-child(2),
td:nth-child(2) {
  left: 44px;
  min-width: 96px;
  max-width: 96px;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  z-index: 3;
}

th:nth-child(3),
td:nth-child(3) {
  left: 140px;
  min-width: 56px;
  width: 56px;
  font-weight: 800;
  z-index: 2;
}

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

.hole-score-cell {
  font-weight: 700;
}

.hole-score-1 {
  background: var(--accent-strong);
  color: #ffffff;
}

.hole-score-2 {
  background: var(--accent);
  color: #ffffff;
}

.hole-score-3 {
  background: #dbe8f5;
}

.hole-score-4 {
  background: #eef3f8;
}

.hole-score-5 {
  background: #e7edf4;
}

.hole-score-6 {
  background: #dde5ee;
}

.hole-score-7 {
  background: #d2dbe6;
}

.hole-score-8 {
  background: #c2ccd8;
}

.hole-score-9 {
  background: #aebac8;
  color: #ffffff;
}

.hole-score-10 {
  background: #97a5b5;
  color: #ffffff;
}

.hole-score-11 {
  background: #7f8fa1;
  color: #ffffff;
}

.hole-score-12plus {
  background: #69798d;
  color: #ffffff;
}

.hole-header-cell {
  padding: 4px 6px;
  background: var(--surface) !important;
  color: var(--muted);
}

.hole-col-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.delete-hole-btn {
  min-width: 28px;
  min-height: 28px;
  padding: 0;
  background: transparent;
  color: var(--danger);
  box-shadow: inset 0 0 0 1px rgba(140, 61, 51, 0.12);
  border-radius: 8px;
  font-size: 0.75rem;
}

#gameView:not(.report-only-mode) #reportSection table {
  font-size: 0.82rem;
}

#gameView:not(.report-only-mode) #reportSection th,
#gameView:not(.report-only-mode) #reportSection td {
  padding: 6px 5px;
}

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

@media (min-width: 700px) {
  .app {
    padding: var(--space-5);
  }

  .about-legal {
    padding: 0 var(--space-5);
  }

  .app-header,
  .top-bar {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
  }

  .top-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hole-header {
    padding: var(--space-5);
  }

  .row-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: center;
  }

  .confirm-overlay {
    align-items: center;
  }
}

@media (max-width: 440px) {
  .setup-actions {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 380px) {
  .app {
    padding: var(--space-2);
  }

  #holeTitle {
    font-size: 1.75rem;
  }

  .counter {
    grid-template-columns: 40px 52px 40px;
  }

  .counter button {
    min-height: 44px;
  }

  .score-value {
    min-width: 52px;
    font-size: 1.2rem;
  }
}
