:root {
  --bg: #f4f2ec;
  --card: #ffffff;
  --ink: #1d2721;
  --muted: #69736c;
  --line: #e2ddd2;
  --primary: #2e6b4f;
  --primary-soft: #e3efe8;
  --primary-ink: #ffffff;
  --ok: #2f9e5d;
  --ok-soft: #dff3e6;
  --warn: #b5671f;
  --warn-soft: #fbeedd;
  --danger: #b3362f;
  --input: #faf9f6;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131815; --card: #1c2420; --ink: #e9eee9; --muted: #9aa59d; --line: #2d3832;
    --primary: #5fb08a; --primary-soft: #23342b; --primary-ink: #0f1712;
    --ok: #59c483; --ok-soft: #1f3a2a; --warn: #e3a35c; --warn-soft: #3a2c1c; --danger: #ef7d75;
    --input: #151c18; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131815; --card: #1c2420; --ink: #e9eee9; --muted: #9aa59d; --line: #2d3832;
  --primary: #5fb08a; --primary-soft: #23342b; --primary-ink: #0f1712;
  --ok: #59c483; --ok-soft: #1f3a2a; --warn: #e3a35c; --warn-soft: #3a2c1c; --danger: #ef7d75;
  --input: #151c18; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }

/* ---- Barra de arriba ---- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 4px;
  padding: calc(8px + env(safe-area-inset-top)) 8px 8px;
  background: var(--primary); color: var(--primary-ink);
}
.top-title { flex: 1; font-weight: 700; font-size: 19px; padding-left: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 44px; height: 44px; border: 0; border-radius: 12px; background: transparent;
  display: grid; place-items: center; cursor: pointer; color: inherit;
}
.icon-btn:active { background: rgba(255,255,255,.15); }

/* ---- Pestañas de abajo ---- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 10px; color: var(--muted); font-size: 13px; font-weight: 600;
}
.tabs a.on { color: var(--primary); }

/* ---- Contenido ---- */
main { max-width: 640px; margin: 0 auto; padding: 16px; }
h1 { font-size: 24px; margin: 4px 0 4px; line-height: 1.2; }
h2 { font-size: 19px; margin: 24px 0 10px; }
.sub { color: var(--muted); margin: 0 0 14px; }
.small { font-size: 14px; color: var(--muted); }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 14px 16px; box-shadow: var(--shadow); margin-bottom: 12px;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 12px; }
.chip {
  display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 14px; font-weight: 600;
  background: var(--primary-soft); color: var(--primary);
}
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.nota { background: var(--warn-soft); color: var(--ink); border-radius: 12px; padding: 10px 12px; font-size: 15px; margin-bottom: 12px; }
.nota.ok { background: var(--ok-soft); }

/* ---- Botones ---- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 52px; padding: 12px 16px; border-radius: 14px; border: 0;
  background: var(--primary); color: var(--primary-ink); font-weight: 700; font-size: 18px; cursor: pointer;
}
.btn:active { filter: brightness(.95); transform: translateY(1px); }
.btn.ok { background: var(--ok); color: #fff; }
.btn.sec { background: var(--card); color: var(--ink); border: 1.5px solid var(--line); font-weight: 600; }
.btn.peligro { background: transparent; color: var(--danger); border: 1.5px solid var(--line); font-weight: 600; }
.btn[disabled] { opacity: .6; }
.btns { display: grid; gap: 10px; margin-top: 16px; }

/* ---- Inicio: meses y semanas ---- */
.actual { display: block; background: var(--primary); color: var(--primary-ink); border-color: transparent; }
.actual .small { color: inherit; opacity: .85; }
.actual-fila { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.actual-num { font-size: 22px; font-weight: 800; }
.mes { margin-bottom: 10px; }
.mes > summary {
  list-style: none; cursor: pointer; padding: 12px 4px; font-weight: 800; font-size: 20px;
  display: flex; justify-content: space-between; align-items: center; text-transform: capitalize;
}
.mes > summary::-webkit-details-marker { display: none; }
.mes > summary::after { content: "›"; font-size: 26px; color: var(--muted); transition: transform .15s; }
.mes[open] > summary::after { transform: rotate(90deg); }
.semana {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; margin-bottom: 8px;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
}
.semana.hoy { border: 2px solid var(--primary); }
.semana .info { flex: 1; min-width: 0; }
.semana .t { font-weight: 700; }
.puntos { display: flex; gap: 4px; margin-top: 6px; }
.punto { width: 12px; height: 12px; border-radius: 50%; background: var(--line); }
.punto.si { background: var(--ok); }
.flecha { color: var(--muted); font-size: 26px; line-height: 1; }
.completa { color: var(--ok); font-weight: 800; font-size: 14px; }

/* ---- Semana: lista de entrenos ---- */
.entreno-fila {
  display: flex; align-items: center; gap: 14px; padding: 14px; margin-bottom: 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
}
.tick {
  flex: none; width: 36px; height: 36px; border-radius: 50%; border: 2.5px solid var(--line);
  display: grid; place-items: center; color: transparent;
}
.tick.si { background: var(--ok); border-color: var(--ok); color: #fff; }
.entreno-fila .info { flex: 1; min-width: 0; }
.entreno-fila .t { font-weight: 700; font-size: 18px; }
.nav-semanas { display: flex; gap: 10px; margin-top: 16px; }
.nav-semanas .btn { font-size: 16px; }

/* ---- Entreno: ejercicios ---- */
.ej-pos { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.ej-nombre { font-size: 19px; font-weight: 750; margin: 2px 0 0; line-height: 1.25; }
.ej-nota { font-size: 14px; color: var(--muted); }
.ej-pres { display: inline-block; margin-top: 6px; font-weight: 800; color: var(--primary); font-size: 17px; }
.ultima { font-size: 14px; color: var(--muted); margin-top: 2px; }
.casillas { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; align-items: flex-end; }
.parte-t { width: 100%; font-size: 14px; font-weight: 700; margin-top: 4px; }
.casilla { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.casilla label { font-size: 12px; color: var(--muted); }
.casilla input {
  width: 66px; height: 48px; text-align: center; font-size: 19px; font-weight: 700;
  border: 1.5px solid var(--line); border-radius: 12px; background: var(--input);
}
.casilla input:focus { outline: none; border-color: var(--primary); background: var(--card); }
.casilla input::placeholder { color: var(--muted); opacity: .55; font-weight: 600; }
.unidad { font-size: 14px; color: var(--muted); padding-bottom: 14px; }
.otras { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--line); }
.otras .small { margin-bottom: 6px; }
.op-btn {
  display: block; width: 100%; text-align: left; margin-top: 6px; padding: 10px 12px;
  border: 1.5px solid var(--line); border-radius: 12px; background: transparent; cursor: pointer; font-size: 15px;
}
.op-btn::before { content: "○  "; color: var(--muted); }
.cardio-det { margin: 8px 0 0; padding-left: 20px; }
.cardio-det li { margin: 4px 0; }

/* ---- Cuerpo ---- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px; text-align: center; }
.stat .v { font-size: 22px; font-weight: 800; }
.stat .l { font-size: 13px; color: var(--muted); }
.grafica svg { width: 100%; height: auto; display: block; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.campo { display: flex; flex-direction: column; gap: 4px; }
.campo.ancho { grid-column: 1 / -1; }
.campo label { font-size: 14px; font-weight: 600; color: var(--muted); }
.campo input {
  height: 50px; padding: 0 12px; font-size: 18px; border: 1.5px solid var(--line);
  border-radius: 12px; background: var(--input); width: 100%;
}
.campo input:focus { outline: none; border-color: var(--primary); }
.hist { width: 100%; border-collapse: collapse; font-size: 15px; }
.hist th, .hist td { padding: 8px 4px; border-bottom: 1px solid var(--line); text-align: right; }
.hist th:first-child, .hist td:first-child { text-align: left; }
.hist th { font-size: 13px; color: var(--muted); font-weight: 600; }
.tabla-scroll { overflow-x: auto; }
.borrar { border: 0; background: none; color: var(--danger); cursor: pointer; font-size: 18px; padding: 4px 6px; }

/* ---- Entrada ---- */
.login { max-width: 420px; margin: 0 auto; padding-top: calc(32px + env(safe-area-inset-top)); }
.login .logo { width: 84px; height: 84px; border-radius: 22px; display: block; margin: 0 auto 12px; }
.login h1 { text-align: center; }
.quien { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 18px 0; }
.quien button {
  min-height: 64px; border-radius: 16px; border: 2px solid var(--line); background: var(--card);
  font-size: 20px; font-weight: 700; cursor: pointer;
}
.quien button.on { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.error { color: var(--danger); font-weight: 600; margin-top: 10px; text-align: center; }

/* ---- Aviso flotante ---- */
.aviso {
  position: fixed; left: 16px; right: 16px; bottom: calc(86px + env(safe-area-inset-bottom)); z-index: 10;
  max-width: 480px; margin: 0 auto; padding: 12px 16px; border-radius: 14px;
  background: var(--ink); color: var(--bg); font-weight: 600; text-align: center;
}
.cargando { text-align: center; color: var(--muted); padding: 40px 0; }
