:root {
  --bg: #eef3ee;
  --card: #ffffff;
  --card-soft: #f6faf7;
  --primary: #15803d;
  --primary-dark: #116030;
  --primary-soft: #e7f4ec;
  --text: #0f1c15;
  --muted: #4c5f56;
  --border: #d9e3db;
  --danger: #b91c1c;
  --danger-soft: #fdecec;
  --topbar-bg: rgba(238, 243, 238, .93);
  --shadow: 0 1px 2px rgba(20, 33, 26, .05), 0 10px 30px rgba(20, 33, 26, .07);
  --radius: 20px;
  --radius-sm: 14px;
  --fs-base: 18px;
  --fs-big: 62px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --vv-top: 0px;
  --vv-height: 100dvh;
}

html[data-theme="dark"] {
  --bg: #0e1512;
  --card: #17211c;
  --card-soft: #1e2b24;
  --primary: #1f9b52;
  --primary-dark: #4ade80;
  --primary-soft: rgba(74, 222, 128, .15);
  --text: #e9f2ec;
  --muted: #9db0a5;
  --border: #29372f;
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, .14);
  --topbar-bg: rgba(14, 21, 18, .93);
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html {
  scroll-behavior: smooth;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: var(--fs-base);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body { min-height: 100dvh; }

.app {
  max-width: 660px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: var(--safe-bottom);
}

/* ---------- Barra superior ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(13px + var(--safe-top)) 18px 13px;
  background: var(--topbar-bg);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 750;
  letter-spacing: -.01em;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.brand-dot {
  flex: 0 0 auto;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--primary); box-shadow: inset 0 0 0 3px var(--card);
  outline: 2px solid var(--primary);
}

.topbar-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }

.icon-btn {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  padding: 0;
  font-family: inherit;
  font-size: 19px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
}
.icon-btn:active { background: var(--card-soft); }

.pill {
  font-size: 14px; font-weight: 650;
  padding: 7px 12px; border-radius: 999px;
  background: var(--primary-soft); color: var(--primary-dark);
}

.pill-install {
  border: none;
  font-family: inherit;
  cursor: pointer;
  background: var(--primary);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  padding: 9px 14px;
  border-radius: 999px;
  box-shadow: 0 4px 12px rgba(21, 128, 61, .3);
}
.pill-install:active { background: var(--primary-dark); }

.net-dot {
  width: 13px; height: 13px; border-radius: 50%;
  background: var(--primary);
  flex: 0 0 auto;
}
.net-dot.is-offline { background: #d97706; }

.content {
  flex: 1;
  padding: 20px 18px 36px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.screen { display: flex; flex-direction: column; gap: 20px; }

/* ---------- Botones ---------- */
.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 16px 20px;
  font-size: 18px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: transform .06s ease, background .15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
}
.btn:active { transform: scale(.985); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 6px 16px rgba(21, 128, 61, .26); }
.btn-ghost { background: var(--card); border-color: var(--border); color: var(--text); }
.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-soft); }
.btn-text { background: transparent; border-color: transparent; color: var(--muted); box-shadow: none; font-weight: 650; }
.btn-text:active { background: var(--card-soft); }
.btn-xl { padding: 20px; font-size: 20px; border-radius: var(--radius); }
.btn-row { display: flex; gap: 12px; }
.btn-row .btn { flex: 1; }

.controls { display: flex; flex-direction: column; gap: 12px; }

/* ---------- Inicio ---------- */
.hero {
  background: linear-gradient(160deg, var(--card), var(--card-soft));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  box-shadow: var(--shadow);
}
.hero h1 { margin: 0 0 12px; font-size: 34px; letter-spacing: -.03em; }
.hero p { margin: 0; color: var(--muted); font-size: 18px; }
.hint { color: var(--muted); font-size: 16px; text-align: center; margin: 0; }
.credit { margin: 0; text-align: center; font-size: 14px; color: var(--muted); }
.credit a { color: var(--primary-dark); font-weight: 700; text-decoration: none; }
.credit a:active { text-decoration: underline; }

/* ---------- Nombre de la cancha (resumen) ---------- */
.course-name {
  margin: 0;
  font-size: 19px;
  font-weight: 750;
  color: var(--primary-dark);
  letter-spacing: -.01em;
  text-align: center;
}

/* ---------- Tarjetas de estadísticas ---------- */
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.stat {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  text-align: center;
}
.stat.wide { grid-column: 1 / -1; }
.stat-label {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  font-weight: 700;
  line-height: 1.25;
  min-height: 2.5em;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.stat-value { font-size: 34px; font-weight: 800; letter-spacing: -.02em; }
.big-number { font-size: var(--fs-big); font-weight: 800; line-height: 1; letter-spacing: -.03em; color: var(--primary-dark); }
.stat-hero { padding: 20px 16px; }
.stat-small { padding: 16px; }
.stat-small .stat-value { font-size: 32px; }
.stat-small .stat-club { font-size: 16px; }
.stat-meta { font-size: 15px; font-weight: 650; color: var(--muted); }
.stat-inline { padding: 12px 16px; gap: 4px; }
.stat-inline .stat-label { min-height: auto; font-size: 12px; }
.stat-inline-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Listas de golpes ---------- */
.list-block {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.list-block h2 { margin: 0 0 14px; font-size: 18px; }
.list-block h2:has(+ .list-subtitle) { margin-bottom: 2px; }
.list-subtitle { margin: 0 0 14px; font-size: 15px; color: var(--muted); }
.stroke-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.stroke-list li {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 13px 14px;
  background: var(--card-soft);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.s-index {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--primary-soft); color: var(--primary-dark);
  font-size: 16px; font-weight: 800;
  display: grid; place-items: center;
}
.s-club { font-size: 18px; font-weight: 650; }
.s-dist { font-size: 18px; font-variant-numeric: tabular-nums; font-weight: 800; color: var(--primary-dark); }

/* ---------- Tira de hoyos jugados ---------- */
.hole-strip {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 6px;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
}
.hole-chip {
  flex: 0 0 auto;
  min-width: 116px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  background: var(--card-soft);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 4px;
  scroll-snap-align: start;
}
.hole-chip-active { background: var(--primary-soft); border-color: var(--primary); }
.hole-chip-num { font-size: 16px; font-weight: 700; color: var(--muted); }
.hole-chip-strokes { font-size: 24px; font-weight: 800; color: var(--text); letter-spacing: -.01em; }
.hole-chip-active .hole-chip-num { color: var(--primary-dark); }

/* ---------- Lista de partidas jugadas ---------- */
.round-list { display: flex; flex-direction: column; gap: 10px; }
.round-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 15px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card-soft);
  color: var(--text);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
}
.round-item:active { background: var(--primary-soft); border-color: var(--primary); }
.round-item-main { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.round-item-course {
  font-size: 18px;
  font-weight: 750;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.round-item-date { font-size: 15px; color: var(--muted); }
.round-item-strokes { font-size: 18px; font-weight: 800; color: var(--primary-dark); white-space: nowrap; }
.round-item-chevron { font-size: 26px; color: var(--muted); line-height: 1; }

/* ---------- Filas de estadísticas (promedio por palo) ---------- */
.stat-rows { display: flex; flex-direction: column; gap: 10px; }
.stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card-soft);
}
.stat-row-name { font-size: 17px; font-weight: 700; }
.stat-row-value { font-size: 17px; font-weight: 800; color: var(--primary-dark); white-space: nowrap; }

/* ---------- Resumen ---------- */
.summary-head { display: flex; flex-direction: column; gap: 6px; }
.summary-head h1 { margin: 0; font-size: 32px; letter-spacing: -.02em; text-align: center; }
.section-title { font-size: 15px; margin: 8px 0 0; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; }
.stroke-block {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.stroke-block-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; gap: 12px; }
.stroke-block-head strong { font-size: 18px; }
.stroke-block-head span { color: var(--muted); font-size: 16px; font-weight: 650; }

/* ---------- Tablas ---------- */
.table-wrap {
  overflow-x: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.data-table { width: 100%; border-collapse: collapse; font-size: 18px; }
.data-table th, .data-table td { padding: 15px 16px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table th { font-size: 14px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 750; background: var(--card-soft); }
.data-table td { font-weight: 600; }
.data-table td.num, .data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table tr:last-child td { border-bottom: none; }
.data-table .total-row td { font-weight: 800; background: var(--primary-soft); }

/* Tabla "Por palo": columnas de números ajustadas al contenido */
.club-table th { font-size: 12px; }
.club-table th.num, .club-table td.num { width: 1px; white-space: nowrap; }
.club-table th.num:first-child, .club-table td.num:first-child { text-align: center; }
.club-table .club-name { white-space: normal; }

/* Listados del resumen con el mismo estilo de tarjeta que "Distancia de cada golpe" */
.rows-table { padding: 6px 8px 14px; }
.rows-table table { border-collapse: separate; border-spacing: 0 10px; }
.rows-table thead th { background: transparent; border-bottom: none; padding: 4px 4px 0; }
.rows-table tbody td {
  background: var(--card-soft);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 13px 4px;
}
.rows-table tbody td:first-child {
  border-left: 1px solid var(--border);
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  padding-left: 10px;
}
.rows-table tbody td:last-child {
  border-right: 1px solid var(--border);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding-right: 10px;
}
.rows-table tbody tr:last-child td { border-bottom: 1px solid var(--border); }

/* En pantallas muy estrechas, la tabla por palo reduce un punto la tipografía
   para seguir entrando sin desplazamiento horizontal */
@media (max-width: 359px) {
  .club-table { font-size: 15px; }
  .club-table th { font-size: 11px; }
}

/* ---------- Utilidades ---------- */
.muted { color: var(--muted); }
.small { font-size: 16px; }

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--vv-top);
  height: var(--vv-height);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(8, 14, 11, .5);
  padding: 16px;
  backdrop-filter: blur(2px);
}
@media (min-width: 560px) { .modal { align-items: center; } }
.modal-card {
  width: 100%;
  max-width: 500px;
  background: var(--card);
  border-radius: 24px;
  padding: 22px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
  max-height: 100%;
  overflow-y: auto;
}
.modal-card h3 { margin: 0 0 8px; font-size: 23px; }
.modal-card label { display: block; font-size: 16px; font-weight: 700; color: var(--muted); margin: 16px 0 8px; }
.modal-card input {
  width: 100%;
  font-family: inherit;
  font-size: 26px;
  font-weight: 700;
  text-align: center;
  padding: 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card-soft);
  color: var(--text);
}
.modal-card input[type="text"] { font-size: 21px; text-align: left; }
.modal-card input::placeholder { font-weight: 500; color: var(--muted); opacity: .7; }
.modal-card input:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.modal-actions { display: flex; gap: 12px; margin-top: 20px; }
.modal-actions .btn { flex: 1; }

.club-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 16px; }
.club-btn {
  font-family: inherit;
  border: 1px solid var(--border);
  background: var(--card-soft);
  border-radius: var(--radius-sm);
  padding: 15px 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text);
  min-height: 74px;
}
.club-btn:active { background: var(--primary-soft); border-color: var(--primary); }
.club-btn-label { font-size: 19px; font-weight: 800; }
.club-btn-name { font-size: 12px; color: var(--muted); min-height: 14px; line-height: 1.1; text-align: center; }

/* ---------- Ajustes ---------- */
.settings-group { margin-top: 20px; }
.settings-group h4 { margin: 0 0 10px; font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.segmented { display: flex; gap: 8px; }
.segmented button {
  flex: 1;
  font-family: inherit;
  font-size: 17px;
  font-weight: 700;
  padding: 15px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card-soft);
  color: var(--text);
  cursor: pointer;
}
.segmented button.is-active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
  bottom: calc(24px + var(--safe-bottom));
  z-index: 60;
  max-width: min(92vw, 540px);
  background: #12201a;
  color: #fff;
  padding: 16px 20px;
  border-radius: 16px;
  font-size: 17px;
  font-weight: 650;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .35);
  text-align: center;
}
.toast-ok { background: var(--primary-dark); color: #06210f; }
.toast-error { background: #9f1d1d; color: #fff; }

/* ---------- Overlay de carga ---------- */
.busy {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: var(--topbar-bg);
  backdrop-filter: blur(3px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  font-size: 18px;
  font-weight: 700;
  color: var(--primary-dark);
}
.spinner {
  width: 42px; height: 42px; border-radius: 50%;
  border: 4px solid var(--primary-soft);
  border-top-color: var(--primary);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Instalación (PWA) ---------- */
.install-steps {
  margin: 10px 0 0;
  padding-left: 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-size: 17px;
}
.install-steps li { padding-left: 4px; }

.install-banner {
  position: fixed;
  left: 50%;
  bottom: calc(16px + var(--safe-bottom));
  z-index: 45;
  width: min(94vw, 560px);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 18px 44px rgba(0, 0, 0, .28);
  transform: translateX(-50%);
  animation: banner-in .28s ease-out;
}
@keyframes banner-in {
  from { opacity: 0; transform: translate(-50%, 16px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
.install-banner-icon { width: 50px; height: 50px; border-radius: 13px; flex: 0 0 auto; }
.install-banner-body { flex: 1 1 180px; display: flex; flex-direction: column; gap: 4px; }
.install-banner-title { font-size: 18px; font-weight: 800; letter-spacing: -.01em; }
.install-banner-hint { font-size: 16px; color: var(--muted); line-height: 1.35; }
.install-banner-actions { display: flex; gap: 10px; flex: 1 1 100%; }
.install-banner-actions .btn { flex: 1; padding: 14px 16px; font-size: 17px; white-space: nowrap; }

@media (min-width: 480px) {
  .install-banner-actions { flex: 0 0 auto; }
  .install-banner-actions .btn { padding: 13px 18px; }
}

/* El aviso de instalación nunca se superpone a un modal */
body:has(.modal:not([hidden])) .install-banner { display: none; }

/* El toast sube cuando el aviso de instalación está visible */
body.has-install-banner:not(:has(.modal:not([hidden]))) .toast {
  bottom: calc(36px + var(--safe-bottom) + var(--banner-h, 0px));
}

/* ---------- Animaciones ---------- */
@keyframes screen-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes pop-in {
  from { opacity: 0; transform: translateY(16px) scale(.97); }
  to { opacity: 1; transform: none; }
}
@keyframes item-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 14px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.screen { animation: screen-in .3s ease-out both; }
.modal { animation: fade-in .2s ease-out both; }
.modal-card { animation: pop-in .26s cubic-bezier(.2, .8, .3, 1) both; }
.toast { animation: toast-in .24s ease-out both; }
.stroke-list li { animation: item-in .2s ease-out both; }
.hole-chip { animation: item-in .22s ease-out both; }
.round-item { animation: item-in .22s ease-out both; }
.stat-row { animation: item-in .22s ease-out both; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .screen, .modal, .modal-card, .toast, .stroke-list li, .hole-chip, .round-item, .stat-row, .install-banner, .spinner {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
  }
  .btn { transition: none; }
}

/* ---------- Pantallas anchas ---------- */
@media (min-width: 560px) {
  .content { padding: 24px 24px 40px; }
}
