:root {
  color-scheme: light;
  --ink: #1d2722;
  --muted: #627069;
  --paper: #f6f4ed;
  --surface: #ffffff;
  --line: #d8ddd4;
  --green: #184f3c;
  --green-2: #2f7656;
  --fairway: #78b957;
  --sand: #e9d9a7;
  --gold: #d59a21;
  --red: #b84d45;
  --blue: #2d668a;
  --shadow: 0 12px 30px rgba(24, 79, 60, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

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

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

input:focus,
select:focus,
button:focus-visible {
  outline: 3px solid rgba(47, 118, 86, 0.24);
  outline-offset: 2px;
}

.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: rgba(246, 244, 237, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.topbar-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 12px 14px 10px;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border-radius: 8px;
  box-shadow: 0 5px 16px rgba(24, 79, 60, 0.18);
}

.brand-row h1 {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.1;
}

.brand-row p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.nav-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin-top: 12px;
}

.nav-tabs button {
  min-height: 40px;
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
}

.nav-tabs button.active {
  background: var(--green);
  color: white;
  box-shadow: 0 6px 16px rgba(24, 79, 60, 0.18);
}

.page {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 14px;
  flex: 1;
}

.hero-panel,
.tool-section,
.scorecard-shell,
.summary-grid > section,
.history-item,
.saved-item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.hero-panel {
  overflow: hidden;
}

.course-scene {
  position: relative;
  min-height: 154px;
  background:
    radial-gradient(circle at 75% 18%, #f8cf5a 0 26px, transparent 27px),
    linear-gradient(145deg, #d5ead5 0%, #b7d8c7 48%, #ebdfb7 49%, #ebdfb7 57%, #94c875 58%, #6aad59 100%);
}

.course-scene::before {
  content: "";
  position: absolute;
  left: 8%;
  right: 6%;
  bottom: 14px;
  height: 58px;
  border-radius: 50%;
  background: #f7f4e8;
  transform: rotate(-4deg);
}

.course-scene::after {
  content: "";
  position: absolute;
  left: 58%;
  bottom: 46px;
  width: 12px;
  height: 78px;
  background: var(--green);
  box-shadow: 14px 4px 0 -3px #e85f5c;
}

.hero-actions {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.hero-title {
  margin: 0;
  font-size: 1.18rem;
}

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

.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfaf6;
}

.metric strong {
  display: block;
  font-size: 1.2rem;
}

.metric span {
  color: var(--muted);
  font-size: 0.78rem;
}

.primary,
.secondary,
.quiet,
.danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
}

.primary {
  background: var(--green);
  color: white;
}

.secondary {
  background: #e6efe8;
  color: var(--green);
}

.quiet {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
}

.danger {
  background: #f7e5e2;
  color: #8d332c;
}

.section-stack {
  display: grid;
  gap: 14px;
}

.tool-section {
  padding: 14px;
}

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

.section-head h2,
.section-head h3 {
  margin: 0;
  font-size: 1rem;
}

.section-head p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.field-grid {
  display: grid;
  gap: 10px;
}

.field {
  display: grid;
  gap: 6px;
}

.money-input {
  position: relative;
}

.money-input span {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-weight: 800;
  pointer-events: none;
}

.money-input input {
  padding-left: 28px;
}

.field label,
.input-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf6;
}

.segmented.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.segmented button {
  min-height: 38px;
  background: transparent;
  color: var(--muted);
}

.segmented button.active {
  background: var(--green-2);
  color: white;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fbfaf6;
  color: var(--ink);
  font-weight: 700;
}

.check-row.disabled {
  color: var(--muted);
  opacity: 0.68;
}

.check-row input {
  width: 20px;
  min-height: 20px;
  accent-color: var(--green-2);
}

.hole-grid,
.score-list,
.player-list,
.saved-list {
  display: grid;
  gap: 8px;
}

.hole-row,
.score-row,
.player-row,
.saved-item {
  display: grid;
  gap: 8px;
  align-items: end;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfaf6;
}

.hole-row {
  grid-template-columns: 44px repeat(3, minmax(0, 1fr));
}

.hole-number {
  min-height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #e6efe8;
  color: var(--green);
  font-weight: 800;
}

.player-row {
  grid-template-columns: minmax(70px, 1fr) 46px 48px 38px;
  gap: 6px;
  align-items: end;
  padding: 8px;
}

.player-row .field {
  min-width: 0;
}

.player-name-field input,
.player-tee-field input,
.player-hcp-field input {
  min-width: 0;
  padding-left: 8px;
  padding-right: 8px;
}

.player-hcp-field input,
.player-tee-field input {
  text-align: center;
}

.icon-danger {
  width: 38px;
  min-width: 38px;
  min-height: 44px;
  padding: 0;
  border: 1px solid #e2b8b3;
  background: #f7e5e2;
  color: #8d332c;
  font-weight: 900;
  line-height: 1;
}

.icon-danger:hover {
  background: #f1d1cc;
}

.saved-item {
  grid-template-columns: minmax(0, 1fr) auto;
}

.saved-item strong {
  display: block;
}

.saved-item span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.82rem;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  min-height: 36px;
  padding: 0 10px;
  background: #fbfaf6;
  color: var(--ink);
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.button-row > button {
  flex: 1 1 auto;
}

.scorecard-shell {
  overflow: hidden;
}

.hole-hero {
  display: grid;
  gap: 12px;
  padding: 14px;
  background: var(--green);
  color: white;
}

.hole-hero-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.hole-hero h2 {
  margin: 0;
  font-size: 1.45rem;
}

.hole-pill {
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  padding: 8px 10px;
  color: white;
  font-size: 0.88rem;
}

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

.hole-stat {
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  padding: 10px;
}

.hole-stat strong {
  display: block;
  font-size: 1.08rem;
}

.hole-stat span {
  display: block;
  margin-top: 2px;
  color: rgba(255, 255, 255, 0.76);
  font-size: 0.76rem;
}

.scorecard-body {
  display: grid;
  gap: 14px;
  padding: 14px;
}

.score-row {
  grid-template-columns: minmax(0, 1fr) 82px 72px;
}

.score-row .player-name {
  align-self: center;
}

.player-name strong {
  display: block;
}

.player-name span {
  color: var(--muted);
  font-size: 0.82rem;
}

.net-box {
  min-height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #e6efe8;
  color: var(--green);
  font-weight: 800;
}

.result-banner {
  border: 1px solid var(--line);
  border-left: 6px solid var(--gold);
  border-radius: 8px;
  padding: 12px;
  background: #fffaf0;
}

.result-banner strong {
  display: block;
  margin-bottom: 4px;
}

.result-banner span {
  color: var(--muted);
}

.hole-picker {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 6px;
}

.hole-picker button {
  min-height: 36px;
  padding: 0;
  border: 1px solid var(--line);
  background: #fbfaf6;
  color: var(--ink);
}

.hole-picker button.active {
  background: var(--green);
  color: white;
}

.hole-picker button.complete {
  border-color: var(--green-2);
}

.totals-table {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
  border-radius: 8px;
}

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

.totals-table th:first-child,
.totals-table td:first-child {
  text-align: left;
  white-space: normal;
}

.totals-table th {
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
}

.money-positive {
  color: var(--green-2);
  font-weight: 800;
}

.money-negative {
  color: var(--red);
  font-weight: 800;
}

.summary-grid {
  display: grid;
  gap: 14px;
}

.summary-grid > section {
  padding: 14px;
}

.settlement-list {
  display: grid;
  gap: 8px;
}

.settlement-list div {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf6;
}

.toast {
  position: fixed;
  left: 14px;
  right: 14px;
  bottom: 14px;
  z-index: 10;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--ink);
  color: white;
  box-shadow: 0 16px 30px rgba(29, 39, 34, 0.24);
}

.empty-state {
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfaf6;
}

.mini-copy {
  color: var(--muted);
  font-size: 0.84rem;
}

@media (min-width: 720px) {
  .topbar-inner {
    display: grid;
    grid-template-columns: 1fr minmax(360px, 480px);
    align-items: center;
    gap: 20px;
    padding: 14px 20px;
  }

  .nav-tabs {
    margin-top: 0;
  }

  .page {
    padding: 20px;
  }

  .home-grid,
  .setup-grid,
  .summary-grid {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: start;
  }

  .setup-grid .wide,
  .summary-grid .wide {
    grid-column: 1 / -1;
  }

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

  .field-grid.three {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .scorecard-shell {
    display: grid;
    grid-template-columns: 320px minmax(0, 1fr);
  }

  .hole-hero {
    align-content: start;
  }

  .hole-stats {
    grid-template-columns: 1fr;
  }
}
