/* ── Reset & tokens ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:       #2e7d32;
  --primary-dark:  #1b5e20;
  --primary-light: #e8f5e9;
  --surface:       #f4f6f4;
  --card:          #ffffff;
  --divider:       #e2e6e2;
  --text-primary:  #1c241c;
  --text-muted:    #6b766b;
  --error:         #c62828;
  --on-primary:    #ffffff;
  --r-sm:   6px;
  --r-md:   12px;
  --r-lg:   16px;
  --r-pill: 999px;
  --touch-min:  48px;
  --input-height: 52px;
  --nav-bar-height: 64px;
}

html, body {
  height: 100%;
  background: var(--surface);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  color: var(--text-primary);
}

/* ── App shell ──────────────────────────────────────────── */
#app {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  overflow: hidden;
}

/* ── App header ─────────────────────────────────────────── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 56px;
  background: var(--card);
  border-bottom: 1px solid var(--divider);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 9px; }
.brand__logo { width: 26px; height: 26px; flex-shrink: 0; }
.brand__title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}
.settings-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--divider);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  outline: none;
  flex-shrink: 0;
}
.settings-btn svg { width: 19px; height: 19px; fill: var(--text-muted); }

/* ── Main / views ───────────────────────────────────────── */
#main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.view[hidden] { display: none; }

/* ── Picker strip (Putten) ──────────────────────────────── */
.picker-strip {
  height: 52px;
  background: var(--card);
  border-bottom: 1px solid var(--divider);
  display: flex;
  align-items: center;
  padding: 0 16px;
  flex-shrink: 0;
}
.picker-strip__chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1.5px solid var(--divider);
  border-radius: var(--r-md);
  padding: 0 14px;
  height: 36px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
}
.picker-strip__caret { font-size: 11px; color: var(--text-muted); margin-left: 2px; }

/* ── Record body ────────────────────────────────────────── */
.record-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 12px 12px 8px;
  gap: 10px;
  min-height: 0;
}
.record-body--range {
  padding: 12px 16px 10px;
  gap: 0;
  overflow-y: auto;
}

/* ── Counter grid (Putten) ──────────────────────────────── */
.counter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-auto-rows: 1fr;
  gap: 10px;
  flex: 1;
  min-height: 0;
}
.counter-cell {
  background: var(--card);
  border-radius: var(--r-lg);
  border: 1.5px solid var(--divider);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px 8px;
  position: relative;
  min-height: 120px;
  transition: border-color 0.15s;
}
.counter-cell--active {
  border-color: var(--primary);
  background: linear-gradient(145deg, #ffffff 0%, #f6faf6 100%);
}
.counter-cell__label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.4px;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.counter-cell--active .counter-cell__label { color: var(--primary-dark); }
.counter-cell__controls {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}
.counter-btn {
  width: 48px;
  height: 48px;
  border-radius: var(--r-md);
  border: none;
  background: var(--surface);
  color: var(--text-primary);
  font-size: 22px;
  font-weight: 300;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.1s, transform 0.08s;
  -webkit-tap-highlight-color: transparent;
}
.counter-btn:active { background: var(--divider); transform: scale(0.94); }
.counter-btn:disabled { opacity: 0.3; cursor: default; }
.counter-btn--minus { color: var(--text-muted); }
.counter-btn--plus { color: var(--primary); background: var(--primary-light); }
.counter-btn--plus:active { background: #c8e6c9; }
.counter-cell--active .counter-btn--plus { background: var(--primary); color: #fff; }
.counter-cell--active .counter-btn--plus:active { background: var(--primary-dark); }
.counter-cell__value {
  font-size: 3rem;
  font-weight: 700;
  line-height: 1;
  color: var(--text-primary);
  min-width: 56px;
  text-align: center;
  letter-spacing: -2px;
  font-variant-numeric: tabular-nums;
}
.counter-cell--active .counter-cell__value { color: var(--primary-dark); }
.counter-cell--zero .counter-cell__value { color: var(--divider); }
.counter-cell__dot {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
  opacity: 0;
}
.counter-cell--active .counter-cell__dot { opacity: 1; }

/* ── Progress row ───────────────────────────────────────── */
.progress-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 28px;
  flex-shrink: 0;
}
.progress-bar-wrap {
  flex: 1;
  height: 4px;
  background: var(--divider);
  border-radius: var(--r-pill);
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: var(--r-pill);
  transition: width 0.3s ease;
}
.progress-label { font-size: 12px; font-weight: 600; color: var(--text-muted); white-space: nowrap; }
.progress-label--complete { color: var(--primary); }
.progress-checkmark { font-size: 14px; color: var(--primary); }

/* ── Club strip / chips (Range) ─────────────────────────── */
.club-strip {
  height: 52px;
  background: var(--card);
  border-bottom: 1px solid var(--divider);
  display: flex;
  align-items: center;
  padding: 0 14px;
  flex-shrink: 0;
  overflow: hidden;
}
.club-row {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  width: 100%;
  height: 100%;
  scrollbar-width: none;
}
.club-row::-webkit-scrollbar { display: none; }
.club-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--surface);
  border: 1.5px solid var(--divider);
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  padding: 0 14px;
  height: 36px;
  border-radius: var(--r-pill);
  cursor: pointer;
  flex-shrink: 0;
  white-space: nowrap;
}
.club-chip--selected {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.club-chip__badge {
  background: rgba(255,255,255,0.22);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: var(--r-sm);
  letter-spacing: 0.2px;
}

/* ── Range summary line ─────────────────────────────────── */
.range-summary {
  text-align: center;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 12px;
  letter-spacing: 0.2px;
  min-height: 16px;
}

/* ── Distance buckets ───────────────────────────────────── */
.bucket-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-bottom: 10px;
}
.bucket {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 40px;
  border-radius: var(--r-md);
  border: 1.5px solid var(--divider);
  background: var(--card);
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  letter-spacing: 0.1px;
}
.bucket--selected {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  box-shadow: 0 3px 10px rgba(46,125,50,0.3);
}
.bucket--muted { opacity: 0.4; }

/* ── Exact override ─────────────────────────────────────── */
.exact-override {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  margin-bottom: 10px;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.exact-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #ffffff;
  border: 1px solid var(--divider);
  border-radius: var(--r-pill);
  padding: 6px 12px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  line-height: 1;
}
.exact-chip__pen { opacity: 0.5; font-size: 12px; }

/* ── Exact-value slider ─────────────────────────────────── */
.slider-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  margin: -2px 0 12px;
  padding: 10px 12px;
  background: var(--primary-light);
  border-radius: var(--r-md);
}
.slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: var(--r-pill);
  background: var(--divider);
  outline: none;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary);
  border: 3px solid #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
  cursor: pointer;
}
.slider::-moz-range-thumb {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary);
  border: 3px solid #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
  cursor: pointer;
}
.slider-out {
  min-width: 56px;
  text-align: right;
  font-size: 18px;
  font-weight: 700;
  color: var(--primary-dark);
  font-variant-numeric: tabular-nums;
}
.slider-wrap--muted { opacity: 0.4; }

/* ── Tag pills ──────────────────────────────────────────── */
.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0;
}
.tag-pill {
  border: 1px solid var(--divider);
  background: #fff;
  border-radius: var(--r-pill);
  padding: 6px 12px;
  font-size: 0.82rem;
  color: var(--text-primary);
  cursor: pointer;
}
.tag-pill.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* ── Direction toggle ───────────────────────────────────── */
.direction-toggle {
  display: flex;
  margin-bottom: 10px;
  border-radius: var(--r-md);
  overflow: hidden;
  border: 1.5px solid var(--divider);
}
.dir-btn {
  flex: 1;
  height: 48px;
  border: none;
  background: var(--card);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  letter-spacing: 0.1px;
  border-right: 1px solid var(--divider);
}
.dir-btn:last-child { border-right: none; }
.dir-btn--selected { background: var(--primary); color: #fff; }

/* ── Footer action bar ──────────────────────────────────── */
.footer-bar {
  background: var(--card);
  border-top: 1px solid var(--divider);
  padding: 12px 16px 12px;
  flex-shrink: 0;
}
.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: var(--input-height);
  background: var(--primary);
  color: var(--on-primary);
  font-size: 16px;
  font-weight: 700;
  border: none;
  border-radius: var(--r-pill);
  cursor: pointer;
  letter-spacing: 0.2px;
  transition: background 0.15s, transform 0.08s;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary:active { background: var(--primary-dark); transform: scale(0.97); }
.btn-primary:disabled { opacity: 0.4; cursor: default; }
.btn-primary:disabled:active { background: var(--primary); transform: none; }
.link-secondary {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 40px;
  margin-top: 2px;
  font-size: 13px;
  color: var(--text-muted);
  background: transparent;
  border: none;
  cursor: pointer;
  gap: 4px;
}
.link-secondary:hover { color: var(--primary); }

/* ── Green photo button + analysis sheet ────────────────── */
.photo-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  height: 44px;
  margin-top: 12px;
  font-size: 14px;
  font-weight: 500;
  color: var(--primary-dark);
  background: var(--primary-light);
  border: 1px solid var(--divider);
  border-radius: var(--r-pill);
  cursor: pointer;
}
.photo-btn:active { transform: scale(0.98); }

.analyze-img {
  width: 100%;
  border-radius: var(--r-md);
  display: block;
  margin-bottom: 12px;
}
.analyze-summary { display: flex; flex-direction: column; gap: 6px; }
.analyze-line { font-size: 15px; color: var(--text-primary); }
.analyze-line--muted { font-size: 13px; color: var(--text-muted); }
.analyze-zones { display: flex; gap: 8px; margin: 4px 0; }
.zone {
  flex: 1;
  text-align: center;
  padding: 8px 0;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 600;
  color: #fff;
}
.zone--good { background: #2e7d32; }
.zone--bad  { background: #ef8c00; }
.zone--mist { background: var(--error); }

.analyze-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 28px 0;
  color: var(--text-muted);
}
.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--divider);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

.analyze-error { color: var(--error); font-weight: 600; }
.analyze-error__detail { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

/* ── Stats views ────────────────────────────────────────── */
.view--stats { overflow: hidden; }
.sub-header {
  flex-shrink: 0;
  height: 52px;
  background: var(--card);
  border-bottom: 1px solid var(--divider);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 16px;
}
.header__back {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--primary);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  background: transparent;
  border: none;
  justify-self: start;
  padding: 0;
}
.sub-header__title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  text-align: center;
  white-space: nowrap;
}
.sub-header__right { justify-self: end; }
.stats-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.section-heading {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: -14px;
}

/* stat cards */
.stat-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.stat-card {
  background: var(--card);
  border-radius: var(--r-md);
  padding: 16px 14px 14px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06), 0 0 0 1px var(--divider);
}
.stat-card.highlight {
  background: var(--primary-light);
  box-shadow: 0 1px 3px rgba(46,125,50,.12), 0 0 0 1px rgba(46,125,50,.18);
}
.stat-card__number {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
  letter-spacing: -0.5px;
  font-variant-numeric: tabular-nums;
}
.stat-card.highlight .stat-card__number { color: var(--primary-dark); }
.stat-card__label { font-size: 12px; color: var(--text-muted); font-weight: 400; line-height: 1.3; }

/* chart card */
.chart-card {
  background: var(--card);
  border-radius: var(--r-md);
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06), 0 0 0 1px var(--divider);
}
.line-chart { width: 100%; height: auto; display: block; }
.chart-line { stroke: var(--primary); stroke-width: 2; vector-effect: non-scaling-stroke; }
.chart-dot { fill: var(--primary-dark); }
.chart-axis { stroke: var(--divider); stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart-tick { fill: var(--text-muted); font-size: 9px; }

/* history list */
.history-card {
  background: var(--card);
  border-radius: var(--r-md);
  box-shadow: 0 1px 3px rgba(0,0,0,.06), 0 0 0 1px var(--divider);
  overflow: hidden;
}
.history-row {
  display: grid;
  grid-template-columns: 72px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 13px 16px;
}
.history-row + .history-row { border-top: 1px solid var(--divider); }
.history-row__date { font-size: 13px; color: var(--text-muted); font-weight: 500; }
.history-row__dist { display: flex; flex-wrap: wrap; gap: 6px; }
.dist-chip {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: var(--primary-light);
  border-radius: var(--r-pill);
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 600;
  color: var(--primary-dark);
}
.dist-chip .chip-label { font-size: 10px; font-weight: 400; color: var(--text-muted); margin-left: 1px; }
.history-row__total { font-size: 20px; font-weight: 700; color: var(--text-primary); text-align: right; white-space: nowrap; }
.history-row__total span { font-size: 11px; font-weight: 400; color: var(--text-muted); display: block; text-align: right; }
.empty { color: var(--text-muted); font-size: 0.88rem; text-align: center; padding: 12px 0; }

/* ── Bottom tab bar ─────────────────────────────────────── */
.tab-bar {
  display: flex;
  flex-shrink: 0;
  background: var(--card);
  border-top: 1px solid var(--divider);
  height: var(--nav-bar-height);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
  padding: 0;
}
.tab-item--active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-item svg { stroke: currentColor; }

/* ── Bottom sheet ───────────────────────────────────────── */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 40;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.sheet-backdrop.sheet--open { opacity: 1; }
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 41;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  background: var(--card);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  padding: 8px 20px calc(20px + env(safe-area-inset-bottom));
  max-height: 85dvh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.2s ease;
}
.sheet.sheet--open { transform: translateY(0); }
.sheet__handle {
  width: 40px;
  height: 4px;
  border-radius: var(--r-pill);
  background: var(--divider);
  margin: 4px auto 12px;
}
.sheet__title { font-size: 18px; font-weight: 700; color: var(--text-primary); margin-bottom: 14px; }
.sheet__body { display: flex; flex-direction: column; }

/* sheet list rows (settings / pickers) */
.sheet-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--touch-min);
  padding: 10px 4px;
  border-bottom: 1px solid var(--divider);
  cursor: pointer;
  font-size: 15px;
  color: var(--text-primary);
}
.sheet-row__label { flex: 1; }
.sheet-row__check { color: var(--primary); font-size: 16px; font-weight: 700; }
.sheet-row__del {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 6px 8px;
}
.sheet-row__del:hover { color: var(--error); }
.sheet-add {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: var(--input-height);
  margin-top: 16px;
  background: var(--surface);
  border: 1.5px dashed var(--divider);
  border-radius: var(--r-md);
  color: var(--primary-dark);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

@media (prefers-reduced-motion: reduce) {
  .sheet, .sheet-backdrop, .progress-bar-fill,
  .counter-btn, .btn-primary, .counter-cell { transition: none; }
}
