:root {
  --green: #4caf50;
  --green-dark: #3d8b40;
  --cream: #f7f5ef;
  --ink: #223;
  --muted: #6b7280;
  --border: #e0ded5;
  --danger: #b3261e;
}

* { box-sizing: border-box; }

button, input, select, textarea {
  font-family: inherit;
}

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--cream);
  color: var(--ink);
}

.app-header {
  background: var(--green);
  color: white;
  padding: 1rem 1rem 0 1rem;
}

.app-header h1 {
  margin: 0 0 0.75rem 0;
  font-family: "Montserrat", "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 1.8rem;
  font-weight: 800;
}

.header-icon {
  font-size: 1.7em;
  vertical-align: middle;
  line-height: 1;
}

.tabs {
  display: flex;
  gap: 0;
}

.tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.75);
  padding: 0.6rem 0.5rem;
  font-size: 0.95rem;
  cursor: pointer;
  border-bottom: 3px solid transparent;
}

.tab-btn:not(:last-child) {
  border-right: 2px solid rgba(255, 255, 255, 0.45);
}

.tab-btn.active {
  color: white;
  border-bottom-color: white;
  font-weight: 600;
}

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 1rem;
}

.screen { display: none; }
.screen.active { display: block; }

h2 { margin-top: 0; margin-bottom: 1.5rem; }

.setup-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 1.5rem;
  margin-bottom: 1.75rem;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}

.setup-card-par {
  margin-top: 2.5rem;
}

.setup-card-title {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--green-dark);
  margin-bottom: 1.1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.field-group {
  margin-bottom: 1.25rem;
}

.setup-card .field-group:last-child {
  margin-bottom: 0;
}

label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
  color: var(--muted);
}

select, input[type="text"], input[type="number"] {
  width: 100%;
  padding: 0.7rem 0.9rem;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  background: white;
  color: var(--ink);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

select:focus, input[type="text"]:focus, input[type="number"]:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.15);
}

select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.9rem center;
  background-size: 14px;
  padding-right: 2.5rem;
  cursor: pointer;
}

.player-names input {
  margin-bottom: 0.6rem;
}

.player-names input:last-child {
  margin-bottom: 0;
}

.player-names input::placeholder {
  color: var(--muted);
  opacity: 1;
}

.par-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.par-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
  gap: 0.6rem;
  margin-top: 0.25rem;
}

.par-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--cream);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.5rem;
}

.par-cell span {
  font-size: 0.7rem;
  color: var(--muted);
  font-weight: 600;
}

.par-cell input {
  width: 100%;
  text-align: center;
  padding: 0.35rem;
  margin-top: 0.25rem;
}

.primary-btn {
  background: var(--green);
  color: white;
  border: none;
  padding: 0.75rem 1.25rem;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
}

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

.secondary-btn {
  background: white;
  color: var(--ink);
  border: 1px solid var(--border);
  padding: 0.75rem 1.25rem;
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
  width: 100%;
  margin-top: 0.5rem;
}

.link-btn {
  background: none;
  border: none;
  color: var(--green);
  text-decoration: underline;
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0;
}

.link-btn.danger { color: var(--danger); }

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

.course-heading {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--green-dark);
  margin-bottom: 1rem;
}

/* ---------- Scorecard: totals strip ---------- */

.totals-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  position: sticky;
  top: 0;
  z-index: 5;
  padding: 0.5rem 0;
  background: var(--cream);
}

.total-card {
  flex: 1 1 150px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem 1.25rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.total-card .player-name {
  font-size: 1.15rem;
  color: var(--ink);
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.total-card .player-total {
  font-size: 2.6rem;
  font-weight: 800;
  color: var(--green-dark);
  line-height: 1.25;
}

.total-card .player-vs-par {
  font-size: 0.8rem;
  color: var(--muted);
}

/* ---------- Scorecard: hole cards ---------- */

.section-label {
  font-weight: 700;
  font-size: 1rem;
  margin: 1.25rem 0 0.75rem;
  color: var(--green-dark);
}

.section-label:first-child {
  margin-top: 0;
}

.holes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 2rem;
}

.hole-card {
  grid-column: span 1;
  background: white;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 1.5rem;
  box-shadow: 0 2px 6px rgba(0,0,0,0.07);
}

.hole-card-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 1.1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.hole-card-header .hole-number {
  font-size: 1.7rem;
  font-weight: 700;
}

.hole-card-header .hole-par {
  font-size: 0.95rem;
  color: var(--muted);
  background: #eef3ea;
  border-radius: 999px;
  padding: 0.3rem 0.8rem;
}

.player-score-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 0;
}

.player-score-row + .player-score-row {
  border-top: 1px dashed var(--border);
}

.player-score-row .score-player-name {
  font-size: 1rem;
  font-weight: 400;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-stepper {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.score-stepper button {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: white;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  color: var(--green-dark);
}

.score-stepper button:active { background: #eef3ea; }

.score-stepper .score-input {
  width: 3rem;
  height: 2.4rem;
  text-align: center;
  padding: 0;
  font-size: 1.15rem;
  font-weight: 600;
}

/* Score color scale: how good a hole score was, from best (dark green) to worst (dark red).
   Combined with the element's own class so it outranks input[type="number"]'s color rule. */
.score-input.score-dark-green,
.score-value-display.score-dark-green { color: #1b5e20; }

.score-input.score-light-green,
.score-value-display.score-light-green { color: #66bb6a; }

.score-input.score-lighter-green,
.score-value-display.score-lighter-green { color: #a5d6a7; }

.score-input.score-light-red,
.score-value-display.score-light-red { color: #ef5350; }

.score-input.score-dark-red,
.score-value-display.score-dark-red { color: #b3261e; }

.subtotal-card {
  grid-column: 1 / -1;
  background: #eef3ea;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 1.25rem 1.75rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 2rem;
}

.subtotal-card .subtotal-title {
  font-weight: 800;
  font-size: 1.25rem;
  color: var(--green-dark);
  margin-right: auto;
}

.subtotal-card .subtotal-item {
  font-size: 1.15rem;
}

.subtotal-card .subtotal-item strong {
  color: var(--green-dark);
  font-size: 1.4rem;
}

.round-total-card {
  background: var(--green);
}

.round-total-card .subtotal-title {
  color: white;
}

.round-total-card .subtotal-item {
  color: rgba(255,255,255,0.9);
}

.round-total-card .subtotal-item strong {
  color: white;
  font-size: 1.6rem;
}

.scorecard-actions {
  margin-top: 1.5rem;
}

.last-scores {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 2rem;
}

.last-score-chip {
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.last-score-chip strong { display: block; font-size: 1.5rem; margin-top: 0.15rem; color: var(--green); }

.history-card {
  position: relative;
  background: white;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 2px 6px rgba(0,0,0,0.07);
}

.history-delete-btn {
  position: absolute;
  top: 0.9rem;
  right: 0.9rem;
  width: 1.9rem;
  height: 1.9rem;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: white;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.history-delete-btn:hover {
  background: var(--danger);
  border-color: var(--danger);
  color: white;
}

.history-card .history-date {
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 1.1rem;
  padding-bottom: 0.9rem;
  padding-right: 2rem;
  border-bottom: 1px solid var(--border);
}

.history-card .history-scores {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.history-score {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  font-size: 1.1rem;
  padding: 0.7rem 1rem;
  border-radius: 12px;
  background: #f5f4ee;
}

.history-score.is-winner {
  background: #eef3ea;
  font-weight: 700;
}

.history-score .history-score-value {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--ink);
}

.history-score.is-winner .history-score-value {
  color: var(--green-dark);
}

.history-score .history-score-vspar {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--muted);
  margin-left: 0.4rem;
}

/* ---------- Winner celebration overlay ---------- */

.winner-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 30, 20, 0.82);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

#confettiCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.winner-card {
  position: relative;
  z-index: 1;
  background: white;
  border-radius: 24px;
  padding: 2.5rem 2rem;
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,0.35);
}

.winner-title {
  font-size: 1.9rem;
  font-weight: 800;
  color: var(--green-dark);
  margin: 0 0 1.5rem;
}

.winner-scores {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1.75rem;
}

.winner-score-row {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  text-align: left;
  font-size: 1.3rem;
  padding: 0.9rem 1.1rem;
  border-radius: 14px;
  background: #f5f4ee;
}

.winner-score-row.is-winner {
  background: #eef3ea;
  font-weight: 700;
  color: var(--green-dark);
}

.winner-score-main {
  display: flex;
  justify-content: space-between;
}

.winner-score-row small {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.85em;
}

.winner-score-stats {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.winner-score-avg {
  font-size: 1rem;
  font-weight: 700;
  color: var(--muted);
}

.winner-score-detail {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
}

.winner-score-row.is-winner .winner-score-avg,
.winner-score-row.is-winner .winner-score-detail {
  color: var(--green-dark);
  opacity: 0.9;
}

/* ---------- Full results overlay ---------- */

.full-results-card {
  position: relative;
  z-index: 1;
  background: var(--cream);
  border-radius: 22px;
  padding: 2rem;
  max-width: 780px;
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  text-align: left;
  box-shadow: 0 12px 40px rgba(0,0,0,0.35);
}

.full-results-title {
  margin: 0 0 0.4rem;
  font-size: 1.7rem;
  color: var(--green-dark);
}

.full-results-meta {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 1.5rem;
}

.full-results-card .totals-strip {
  position: static;
  background: transparent;
  padding: 0;
}

#fullResultsDoneBtn {
  margin-top: 1.5rem;
}

.score-value-display {
  min-width: 2.6rem;
  text-align: center;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--ink);
}
