:root {
  --green-950: #0b2418;
  --green-900: #123524;
  --green-800: #1a4b33;
  --green-700: #236341;
  --green-100: #e8f2ec;
  --cream: #f7f4ea;
  --paper: #fffef9;
  --ink: #1f2924;
  --muted: #66736c;
  --line: #d7dfda;
  --danger: #a43131;
  --shadow: 0 18px 50px rgba(13, 43, 29, 0.14);
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  background: var(--cream);
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--ink);
  background:
    radial-gradient(circle at top right, rgba(35, 99, 65, .12), transparent 35rem),
    var(--cream);
}

button, input {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.view {
  min-height: 100vh;
  min-height: 100dvh;
}

.welcome-view {
  display: grid;
  place-items: center;
  padding: max(24px, env(safe-area-inset-top)) 18px max(24px, env(safe-area-inset-bottom));
}

.welcome-card {
  width: min(100%, 520px);
  padding: 34px 26px;
  text-align: center;
  background: rgba(255, 254, 249, .96);
  border: 1px solid rgba(18, 53, 36, .12);
  border-radius: 28px;
  box-shadow: var(--shadow);
}

.logo-mark {
  display: grid;
  place-items: center;
  width: 84px;
  height: 84px;
  margin: 0 auto 18px;
  font-size: 42px;
  background: var(--green-100);
  border: 1px solid rgba(18, 53, 36, .13);
  border-radius: 24px;
}

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

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

h1 {
  margin-bottom: 10px;
  color: var(--green-950);
  font-size: clamp(2rem, 8vw, 3rem);
  line-height: 1;
}

h2 {
  margin-bottom: 0;
  color: var(--green-950);
  font-size: 1.35rem;
}

h3 {
  margin-bottom: 2px;
  color: var(--green-950);
}

.welcome-copy {
  max-width: 39ch;
  margin: 0 auto 24px;
  color: var(--muted);
  line-height: 1.55;
}

.round-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 15px;
}

.round-choice {
  min-height: 116px;
  color: white;
  background: linear-gradient(145deg, var(--green-800), var(--green-950));
  border: 0;
  border-radius: 20px;
  box-shadow: 0 8px 24px rgba(11, 36, 24, .18);
  transition: transform .16s ease, box-shadow .16s ease;
}

.round-choice:active {
  transform: translateY(2px);
}

.round-choice strong,
.round-choice span {
  display: block;
}

.round-choice strong {
  font-size: 2.2rem;
  line-height: 1;
}

.round-choice span {
  margin-top: 6px;
  font-size: .82rem;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.privacy-note {
  margin: 18px auto 0;
  color: var(--muted);
  font-size: .78rem;
  line-height: 1.45;
}

.wide { width: 100%; }

.app-header {
  position: sticky;
  z-index: 20;
  top: 0;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  padding: max(13px, env(safe-area-inset-top)) max(15px, env(safe-area-inset-right)) 13px max(15px, env(safe-area-inset-left));
  color: white;
  background: rgba(11, 36, 24, .96);
  box-shadow: 0 4px 16px rgba(0,0,0,.16);
  backdrop-filter: blur(12px);
}

.app-header .eyebrow { color: #b9dac7; }
.app-header h1 {
  margin: 0;
  overflow: hidden;
  color: white;
  font-size: 1.08rem;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-shell {
  width: min(100%, 1180px);
  margin: 0 auto;
  padding: 18px 12px calc(32px + env(safe-area-inset-bottom));
}

.panel {
  margin-bottom: 16px;
  padding: 18px;
  background: rgba(255, 254, 249, .96);
  border: 1px solid rgba(18, 53, 36, .11);
  border-radius: 20px;
  box-shadow: 0 8px 26px rgba(13, 43, 29, .07);
}

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

.players-heading {
  align-items: end;
  margin-top: 18px;
}

.players-heading p,
.table-help {
  margin-bottom: 0;
  color: var(--muted);
  font-size: .82rem;
}

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

label {
  display: grid;
  gap: 6px;
  color: #425048;
  font-size: .78rem;
  font-weight: 750;
}

input {
  width: 100%;
  min-height: 44px;
  padding: 10px 11px;
  color: var(--ink);
  background: white;
  border: 1px solid #cbd5cf;
  border-radius: 10px;
  outline: none;
}

input:focus {
  border-color: var(--green-700);
  box-shadow: 0 0 0 3px rgba(35, 99, 65, .13);
}

.player-editor {
  display: grid;
  gap: 10px;
}

.player-row {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(100px, .7fr) auto;
  align-items: end;
  gap: 9px;
  padding: 11px;
  background: #f4f7f5;
  border: 1px solid var(--line);
  border-radius: 13px;
}

.primary,
.secondary,
.install-button,
.danger-text,
.icon-button,
.file-label {
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 11px;
  font-weight: 800;
}

.primary {
  color: white;
  background: var(--green-800);
  border: 1px solid var(--green-800);
}

.secondary,
.file-label {
  color: var(--green-900);
  background: white;
  border: 1px solid #bfcac3;
}

.install-button {
  color: var(--green-950);
  background: #d6f0df;
  border: 1px solid #aad1b9;
}

.install-button.compact {
  min-height: 38px;
  padding: 8px 11px;
  font-size: .82rem;
}

.danger-text {
  min-height: auto;
  padding: 5px 0;
  color: var(--danger);
  background: transparent;
  border: 0;
}

.icon-button {
  display: grid;
  place-items: center;
  min-width: 44px;
  padding: 0;
  color: inherit;
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.18);
  font-size: 1.8rem;
  line-height: 1;
}

.player-row .icon-button {
  color: var(--danger);
  background: #fff;
  border-color: #e1caca;
}

.table-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-inline: contain;
}

table {
  width: max-content;
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  background: white;
}

th,
td {
  width: 58px;
  min-width: 58px;
  height: 54px;
  padding: 6px 4px;
  text-align: center;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

th:last-child,
td:last-child {
  border-right: 0;
}

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

thead th {
  position: sticky;
  z-index: 4;
  top: 0;
  color: white;
  background: var(--green-900);
  font-size: .72rem;
  letter-spacing: .03em;
  white-space: nowrap;
}

.player-column,
.player-name-cell {
  position: sticky;
  left: 0;
  z-index: 5;
  width: 142px;
  min-width: 142px;
  max-width: 142px;
  padding-inline: 10px;
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.handicap-column,
.handicap-cell {
  position: sticky;
  left: 142px;
  z-index: 5;
  width: 58px;
  min-width: 58px;
}

thead .player-column,
thead .handicap-column {
  z-index: 7;
  background: var(--green-950);
}

tbody .player-name-cell {
  color: var(--green-950);
  background: #eef4f0;
  font-size: .82rem;
  font-weight: 850;
}

tbody .handicap-cell {
  color: var(--green-950);
  background: #f4f7f5;
  font-weight: 850;
}

.meta-row .player-name-cell,
.meta-row .handicap-cell {
  background: #e3ece6;
}

.meta-row td {
  background: #f6f8f7;
  font-weight: 750;
}

.par-row td {
  background: #eff5f1;
}

.total-column,
.total-cell {
  width: 68px;
  min-width: 68px;
  background: #edf3ef;
  font-weight: 900;
}

thead .total-column {
  background: var(--green-800);
}

.player-score-row:nth-child(even) td:not(.score-cell):not(.handicap-cell) {
  background: #fbfcfb;
}

table input {
  width: 46px;
  min-width: 46px;
  min-height: 40px;
  padding: 6px 2px;
  text-align: center;
  border-radius: 7px;
}

.meta-input-cell input {
  min-height: 36px;
  font-size: .82rem;
  font-weight: 800;
}

.score-cell {
  position: relative;
  width: 58px;
  min-width: 58px;
  padding: 4px;
}

.score-cell input {
  padding-bottom: 15px;
  font-size: 1rem;
  font-weight: 900;
}

.net-mini {
  position: absolute;
  right: 0;
  bottom: 3px;
  left: 0;
  color: var(--green-700);
  font-size: .61rem;
  font-weight: 900;
  pointer-events: none;
}

.net-total {
  color: var(--green-700);
}

.relative-total {
  color: var(--green-950);
}

.over-par {
  background: #fff4f2;
}

.under-par {
  background: #eff8f0;
}

.even-par {
  background: #f8f8f5;
}

.legend {
  display: flex;
  gap: 12px;
  color: var(--muted);
  font-size: .74rem;
  font-weight: 750;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.legend-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 999px;
}

.gross-dot { background: var(--green-950); }
.net-dot { background: #66a27c; }

.table-help {
  margin-top: 10px;
  line-height: 1.45;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(185px, 1fr));
  gap: 11px;
}

.summary-card {
  padding: 15px;
  background: #f3f7f4;
  border: 1px solid var(--line);
  border-radius: 14px;
}

.summary-card h3 {
  overflow: hidden;
  margin-bottom: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.summary-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.stat {
  padding: 9px;
  background: white;
  border: 1px solid #dde5e0;
  border-radius: 10px;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.stat strong {
  display: block;
  margin-top: 2px;
  color: var(--green-950);
  font-size: 1.25rem;
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.file-label {
  place-items: center;
  cursor: pointer;
}

.file-label input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.toast {
  position: fixed;
  z-index: 100;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  max-width: min(360px, calc(100vw - 32px));
  padding: 12px 15px;
  color: white;
  background: rgba(11,36,24,.96);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,.24);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity .18s ease, transform .18s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 760px) {
  .form-grid,
  .action-grid {
    grid-template-columns: 1fr;
  }

  .panel {
    padding: 15px;
    border-radius: 17px;
  }

  .score-heading {
    align-items: start;
  }

  .players-heading {
    align-items: center;
  }
}

@media (max-width: 480px) {
  .welcome-card {
    padding: 28px 18px;
    border-radius: 23px;
  }

  .round-grid {
    gap: 7px;
  }

  .round-choice {
    min-height: 102px;
    border-radius: 16px;
  }

  .round-choice strong {
    font-size: 1.8rem;
  }

  .player-row {
    grid-template-columns: 1fr 110px auto;
    padding: 9px;
  }

  .player-row label {
    font-size: .7rem;
  }

  .section-heading {
    align-items: flex-start;
  }

  .legend {
    display: none;
  }
}

@media print {
  body { background: white; }
  .app-header,
  .setup-panel .section-heading button,
  .players-heading button,
  .remove-player,
  .actions-panel,
  .table-help {
    display: none !important;
  }
  .app-shell {
    width: 100%;
    padding: 0;
  }
  .panel {
    box-shadow: none;
    break-inside: avoid;
  }
  .setup-panel input {
    border: 0;
    padding: 0;
    min-height: 24px;
  }
  .table-scroll {
    overflow: visible;
  }
  table {
    width: 100%;
    min-width: 0;
    font-size: 8px;
    table-layout: fixed;
  }
  th,
  td,
  .total-column,
  .total-cell,
  .handicap-column,
  .handicap-cell {
    position: static;
    width: auto;
    min-width: 0;
    height: auto;
    padding: 3px 1px;
  }
  .player-column,
  .player-name-cell {
    position: static;
    width: 74px;
    min-width: 74px;
    max-width: 74px;
    padding-inline: 3px;
  }
  table input {
    width: 100%;
    min-width: 0;
    min-height: 22px;
    padding: 1px;
    border: 0;
    font-size: 8px;
  }
  .net-mini {
    display: none;
  }
}

.version-badge {
  display: inline-block;
  margin-left: 5px;
  padding: 2px 6px;
  color: var(--green-900);
  background: var(--green-100);
  border: 1px solid #c6dacf;
  border-radius: 999px;
  font-size: .65rem;
  vertical-align: middle;
}
