:root {
  --bg: #0f1317; --surface: #1a2027; --surface2: #232b34; --line: #2f3944;
  --text: #eef1f4; --muted: #94a1ae; --accent: #c6f432; --on-accent: #141a05;
  --danger: #ff6b5e; --ok: #5fd38d;
  --tabs-h: 62px;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f4f0; --surface: #ffffff; --surface2: #eceee7; --line: #d9dcd2;
    --text: #171b14; --muted: #5d6657; --accent: #4f7d0c; --on-accent: #ffffff;
    --danger: #c0392b; --ok: #2e8b57;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px);
  overscroll-behavior-y: contain;
}
body.has-timer { padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 110px); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
h1, h2, h3, p { margin: 0; }

svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.t, .s { display: block; }
[hidden] { display: none !important; }

/* Cabecera */
#top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 10px; background: var(--bg);
  border-bottom: 1px solid var(--line); min-height: 56px;
}
#top h1 { font-size: 19px; font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#top .sub { display: block; font-size: 12.5px; font-weight: 500; color: var(--muted); }
#top .sub::first-letter { text-transform: uppercase; }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; flex: none; }
.icon-btn:active { background: var(--surface2); }
.icon-btn svg, #tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

main { padding: 14px 12px; max-width: 640px; margin: 0 auto; }

/* Pestañas */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); height: calc(var(--tabs-h) + env(safe-area-inset-bottom));
}
#tabs button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11.5px; color: var(--muted); }
#tabs button.on { color: var(--accent); font-weight: 600; }

/* Bloques */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; margin-bottom: 10px; overflow: hidden; }
.pad { padding: 14px; }
.row { display: flex; align-items: center; gap: 12px; padding: 14px; width: 100%; text-align: left; min-height: 60px; }
.row:active { background: var(--surface2); }
.row + .row { border-top: 1px solid var(--line); }
.grow { flex: 1; min-width: 0; }
.t { font-weight: 600; overflow-wrap: anywhere; }
.s { font-size: 13.5px; color: var(--muted); overflow-wrap: anywhere; }
.badge { flex: none; min-width: 46px; height: 46px; padding: 0 8px; border-radius: 12px; background: var(--surface2); color: var(--accent); display: grid; place-items: center; font-weight: 800; font-size: 14px; letter-spacing: .3px; }
.chev { color: var(--muted); flex: none; }
.section { font-size: 12.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .8px; margin: 18px 4px 8px; }
.section:first-child { margin-top: 2px; }
.empty { text-align: center; color: var(--muted); padding: 34px 16px; }

.btn { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 50px; padding: 0 16px; border-radius: 14px; background: var(--surface2); font-weight: 650; margin-bottom: 10px; border: 1px solid var(--line); }
.btn:active { filter: brightness(1.15); }
.btn.primary { background: var(--accent); color: var(--on-accent); border-color: transparent; }
.btn.danger { color: var(--danger); background: none; }
.btn.ghost { background: none; border-style: dashed; color: var(--muted); }
.btns { display: flex; gap: 10px; }
.btns .btn { flex: 1; }
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 0 12px; border-radius: 999px; background: var(--surface2); border: 1px solid var(--line); font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.chip:active { filter: brightness(1.2); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; background: var(--surface2); font-size: 12px; font-weight: 700; color: var(--accent); margin-right: 4px; }

/* Entreno en curso */
.item-head { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 14px; min-height: 64px; }
.prog { flex: none; width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 700; background: var(--surface2); color: var(--muted); font-variant-numeric: tabular-nums; }
.prog.done { background: var(--accent); color: var(--on-accent); }
.item-body { padding: 0 14px 14px; }
.meta { font-size: 13.5px; color: var(--muted); margin-bottom: 10px; }
.last { font-size: 13.5px; background: var(--surface2); border-radius: 10px; padding: 8px 10px; margin-bottom: 10px; overflow-wrap: anywhere; }
.last b { color: var(--muted); font-weight: 600; }
.set { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.set .n { flex: none; width: 34px; text-align: center; font-size: 13px; font-weight: 700; color: var(--muted); }
.fld { flex: 1; min-width: 0; position: relative; display: block; }
.fld input { width: 100%; height: 50px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); text-align: center; font-size: 19px; font-weight: 650; padding: 0 4px 12px; font-variant-numeric: tabular-nums; }
.fld input::placeholder { color: var(--muted); opacity: .55; font-weight: 500; }
.fld input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.fld span { position: absolute; left: 0; right: 0; bottom: 4px; text-align: center; font-size: 10.5px; color: var(--muted); pointer-events: none; text-transform: uppercase; letter-spacing: .5px; }
.tick { flex: none; width: 54px; height: 50px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface2); display: grid; place-items: center; color: var(--muted); }
.tick svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.set.done .tick { background: var(--accent); color: var(--on-accent); border-color: transparent; }
.set.done .fld input { border-color: transparent; background: var(--surface2); }
.set.wide .tick { flex: 1; width: auto; gap: 8px; display: flex; align-items: center; justify-content: center; font-weight: 650; }
.item-tools { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
textarea, .inp, select.inp { width: 100%; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); padding: 12px; min-height: 48px; }
textarea { min-height: 48px; resize: vertical; display: block; }
textarea:focus, .inp:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.link { color: var(--danger); font-size: 14px; font-weight: 600; padding: 10px 4px; }
.datechip { position: relative; }
.datechip input { position: absolute; inset: 0; opacity: 0; width: 100%; }

/* Temporizador */
#timer {
  position: fixed; left: 8px; right: 8px; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 8px); z-index: 7;
  background: var(--surface2); border: 1px solid var(--accent); border-radius: 18px; padding: 10px 12px;
  display: flex; align-items: center; gap: 10px; box-shadow: 0 8px 28px rgba(0,0,0,.4); overflow: hidden;
  max-width: 624px; margin: 0 auto;
}
#timer[hidden] { display: none; }
#timer .bar { position: absolute; left: 0; bottom: 0; height: 4px; background: var(--accent); transition: width .25s linear; }
#timer .clock { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }
#timer .tl { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
#timer .lbl { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#timer button { min-width: 48px; height: 44px; border-radius: 12px; background: var(--bg); font-weight: 700; font-size: 14px; padding: 0 10px; }
#timer.fin { background: var(--accent); color: var(--on-accent); }
#timer.fin .lbl { color: var(--on-accent); font-size: 15px; font-weight: 700; }
#timer.fin .bar { display: none; }

/* Formularios */
.form label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 12px 0 6px; }
.form .two { display: flex; gap: 10px; }
.form .two > div { flex: 1; min-width: 0; }
.check { display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 0 4px; }
.check input { width: 24px; height: 24px; accent-color: var(--accent); flex: none; }
.search { margin-bottom: 12px; }

/* Modal y avisos */
#modal { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; justify-content: center; }
#modal[hidden] { display: none; }
.sheet { background: var(--bg); width: 100%; max-width: 640px; max-height: 88vh; border-radius: 20px 20px 0 0; display: flex; flex-direction: column; padding-bottom: env(safe-area-inset-bottom); }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 14px 12px 8px 16px; }
.sheet-head h2 { flex: 1; font-size: 18px; }
.sheet-body { overflow-y: auto; padding: 4px 12px 16px; }
#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 20px); z-index: 30; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 600; max-width: 90vw; text-align: center; }
#toast[hidden] { display: none; }

/* Detalle de historial */
.hist-item { padding: 12px 14px; }
.hist-item + .hist-item { border-top: 1px solid var(--line); }
.hist-sets { font-size: 14.5px; color: var(--text); font-variant-numeric: tabular-nums; margin-top: 2px; overflow-wrap: anywhere; }
.note { font-size: 13.5px; color: var(--muted); font-style: italic; margin-top: 4px; overflow-wrap: anywhere; }
