:root {
  --bg: #f5f4f0;
  --card: #ffffff;
  --ink: #16181d;
  --ink-2: #3b3f47;
  --muted: #6b7079;
  --line: #e6e3dc;
  --line-2: #d6d2c8;
  --accent: #e8590c;
  --accent-ink: #ffffff;
  --accent-soft: #fdebdf;
  --ok: #2f9e6b;
  --ok-soft: #e2f4ea;
  --warn: #b7791f;
  --warn-soft: #fbf1dc;
  --err: #c92a2a;
  --err-soft: #fbe4e4;
  --k-warmup: #3aa17e;
  --k-active: #e8590c;
  --k-recovery: #74a3d9;
  --k-rest: #a9aeb8;
  --k-cooldown: #4b72c9;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(22, 24, 29, 0.05), 0 2px 8px rgba(22, 24, 29, 0.04);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --card: #1a1d23;
    --ink: #eceae6;
    --ink-2: #c9c6c0;
    --muted: #9a9ea7;
    --line: #2a2e36;
    --line-2: #383d47;
    --accent: #ff7a33;
    --accent-ink: #16181d;
    --accent-soft: #3a2418;
    --ok: #4cc28d;
    --ok-soft: #173326;
    --warn: #e0a84a;
    --warn-soft: #382c16;
    --err: #ff6b6b;
    --err-soft: #3a1c1c;
    --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: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
a { color: inherit; }
h1, h2, h3 { line-height: 1.2; margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 0.98rem; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.num { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--ink);
  color: #fff;
}
@media (prefers-color-scheme: dark) { .topbar { background: #0b0c0f; border-bottom: 1px solid var(--line); } }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.05rem; text-decoration: none; letter-spacing: -0.02em; }
.nav { display: flex; gap: 4px; margin-left: 8px; }
.nav a { text-decoration: none; padding: 6px 12px; border-radius: 999px; color: rgba(255, 255, 255, 0.72); font-weight: 550; font-size: 0.92rem; }
.nav a.on { background: rgba(255, 255, 255, 0.14); color: #fff; }
.user-chip { margin-left: auto; font-size: 0.85rem; color: rgba(255, 255, 255, 0.7); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }

@media (max-width: 720px) {
  .nav {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    margin: 0;
    justify-content: space-around;
    padding: 6px 8px calc(6px + var(--safe-b));
    background: var(--card);
    border-top: 1px solid var(--line);
    z-index: 20;
  }
  .nav a { color: var(--muted); flex: 1; text-align: center; padding: 8px; }
  .nav a.on { background: var(--accent-soft); color: var(--accent); }
  body.has-nav .app { padding-bottom: calc(84px + var(--safe-b)); }
}

/* ---------------------------------------------------------------- layout */
.app { max-width: 1180px; margin: 0 auto; padding: 18px 16px 48px; outline: none; }
.loading { color: var(--muted); padding: 40px 0; text-align: center; }
.stack { display: grid; gap: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card > * + * { margin-top: 12px; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); text-decoration: none; font-weight: 550; margin-bottom: 12px; padding: 4px 0; }
.back:hover { color: var(--ink); }
.eyebrow { font-size: 0.78rem; font-weight: 650; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }

/* ---------------------------------------------------------------- forms */
label { display: grid; gap: 6px; font-size: 0.86rem; font-weight: 600; color: var(--ink-2); }
input, select, textarea {
  font: inherit;
  font-size: 16px; /* evita zoom en iOS */
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  min-width: 0;
  width: 100%;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input.invalid { border-color: var(--err); background: var(--err-soft); }
.grid2 { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .grid2 { grid-template-columns: 180px 1fr; } }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-weight: 600;
  font-size: 0.92rem;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-2);
  background: var(--card);
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: background-color 120ms ease, border-color 120ms ease, transform 80ms ease;
}
.btn:hover { border-color: var(--muted); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: progress; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--err); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: 6px 10px; font-size: 0.84rem; }
.btn.icon { width: 38px; height: 38px; padding: 0; font-size: 1.2rem; }
.btn.block { width: 100%; }

.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: 11px; padding: 3px; gap: 2px; }
.seg button, .seg label {
  font: inherit; font-weight: 600; font-size: 0.9rem;
  border: 0; background: transparent; color: var(--muted);
  padding: 7px 14px; border-radius: 8px; cursor: pointer; display: flex; align-items: center; gap: 6px;
}
.seg input { position: absolute; opacity: 0; pointer-events: none; width: 1px; }
.seg .on, .seg label:has(input:checked) { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.seg.full { display: flex; }
.seg.full > * { flex: 1; justify-content: center; }

/* ---------------------------------------------------------------- auth */
.auth { max-width: 420px; margin: 6vh auto 0; display: grid; gap: 18px; }
.auth h1 { font-size: 1.9rem; letter-spacing: -0.03em; }
.auth .card { display: grid; gap: 14px; }
.auth .card > * + * { margin-top: 0; }

/* ---------------------------------------------------------------- badges */
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 0.74rem; font-weight: 650; padding: 2px 8px; border-radius: 999px; background: var(--bg); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.err { background: var(--err-soft); color: var(--err); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }

.banner { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 12px 14px; border-radius: var(--radius); background: var(--warn-soft); color: var(--ink); border: 1px solid transparent; font-size: 0.9rem; }
.banner.info { background: var(--accent-soft); }
.banner.ok { background: var(--ok-soft); }
.banner.err { background: var(--err-soft); }
.banner a { font-weight: 650; }
.banner > span { flex: 1; min-width: 200px; }

/* ---------------------------------------------------------------- week */
.week-head { display: grid; gap: 12px; margin-bottom: 14px; }
.week-nav { display: flex; align-items: center; gap: 10px; }
.week-title { flex: 1; display: flex; flex-direction: column; align-items: center; }
.week-title strong { font-size: 1.12rem; letter-spacing: -0.01em; }
.week-title a { font-size: 0.8rem; color: var(--accent); font-weight: 650; text-decoration: none; }
.week-stats { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; font-size: 0.84rem; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.stat b { color: var(--ink); }

.days { display: grid; gap: 10px; }
@media (min-width: 1040px) {
  .days { grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; align-items: start; }
  .day { min-height: 180px; }
}
.day { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; display: grid; gap: 8px; align-content: start; }
.day.today { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.day.past { background: color-mix(in srgb, var(--card) 70%, var(--bg)); }
.day-head { display: flex; align-items: center; gap: 8px; }
.day-name { font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.day-num { font-weight: 700; font-variant-numeric: tabular-nums; }
.day.today .day-name, .day.today .day-num { color: var(--accent); }
.day-add { margin-left: auto; width: 30px; height: 30px; display: grid; place-items: center; border-radius: 8px; text-decoration: none; color: var(--muted); font-size: 1.25rem; line-height: 1; border: 1px dashed var(--line-2); }
.day-add:hover { color: var(--accent); border-color: var(--accent); }
.day-empty { font-size: 0.82rem; color: var(--muted); padding: 2px 2px 4px; }

.wcard { display: grid; grid-template-columns: 4px 1fr; gap: 10px; text-decoration: none; padding: 10px 10px 10px 0; border-radius: 10px; background: var(--bg); border: 1px solid transparent; transition: border-color 120ms ease; }
.wcard:hover { border-color: var(--line-2); }
.wcard .stripe { border-radius: 4px; background: var(--k-active); }
.wcard.sport-strength .stripe { background: var(--k-cooldown); }
.wcard.status-done .stripe { background: var(--ok); }
.wcard.status-skipped { opacity: 0.6; }
.wcard.status-skipped .stripe { background: var(--k-rest); }
.wbody { display: grid; gap: 3px; min-width: 0; }
.wtop { display: flex; align-items: center; gap: 6px; font-size: 0.74rem; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.wtop svg { flex: none; }
.wtitle { font-weight: 650; overflow-wrap: anywhere; }
.wmeta { font-size: 0.84rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.wbadges { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 2px; }

.activity { display: flex; gap: 8px; align-items: flex-start; font-size: 0.8rem; color: var(--ink-2); padding: 6px 8px; border-radius: 8px; border: 1px dashed var(--line-2); font-variant-numeric: tabular-nums; }
.activity .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); margin-top: 6px; flex: none; }

.week-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.coach-pick { display: flex; gap: 8px; align-items: center; }
.coach-pick select { width: auto; min-width: 200px; font-weight: 600; }

/* ---------------------------------------------------------------- detail */
.detail { display: grid; gap: 16px; max-width: 760px; }
.detail-head { display: grid; gap: 6px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { display: grid; gap: 1px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; min-width: 92px; }
.chip span { font-size: 0.74rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.chip b { font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.notes { white-space: pre-wrap; background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: var(--radius-sm); padding: 12px 14px; overflow-wrap: anywhere; }

.profile { width: 100%; height: 72px; display: block; border-radius: 10px; background: var(--card); border: 1px solid var(--line); }
.profile .k-warmup { fill: var(--k-warmup); }
.profile .k-active { fill: var(--k-active); }
.profile .k-recovery { fill: var(--k-recovery); }
.profile .k-rest { fill: var(--k-rest); }
.profile .k-cooldown { fill: var(--k-cooldown); }

.steps, .steps ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.step { display: grid; grid-template-columns: 5px 1fr; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 11px; padding: 10px 12px 10px 0; }
.step .bar { border-radius: 0 4px 4px 0; background: var(--k-active); }
.step.k-warmup .bar { background: var(--k-warmup); }
.step.k-recovery .bar { background: var(--k-recovery); }
.step.k-rest .bar { background: var(--k-rest); }
.step.k-cooldown .bar { background: var(--k-cooldown); }
.step-body { display: grid; gap: 2px; }
.step-body strong { font-size: 0.95rem; }
.step-body span { font-variant-numeric: tabular-nums; color: var(--ink-2); }
.step-body em { font-style: normal; font-size: 0.85rem; color: var(--muted); }
.repeat { border: 1.5px solid var(--line-2); border-radius: 13px; padding: 8px; display: grid; gap: 6px; background: color-mix(in srgb, var(--accent-soft) 35%, transparent); }
.repeat-head { display: flex; align-items: center; gap: 8px; font-weight: 650; padding: 2px 4px; }
.times { background: var(--accent); color: var(--accent-ink); border-radius: 7px; padding: 1px 8px; font-variant-numeric: tabular-nums; }

.ex-table { display: grid; gap: 6px; }
.ex-item { display: grid; gap: 2px; background: var(--card); border: 1px solid var(--line); border-radius: 11px; padding: 10px 12px; }
.ex-item span { font-variant-numeric: tabular-nums; color: var(--ink-2); }
.ex-item em { font-style: normal; font-size: 0.85rem; color: var(--muted); }

.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions .dup { display: flex; gap: 6px; align-items: center; }
.actions .dup input { width: auto; padding: 7px 9px; }

.rpe { display: flex; gap: 4px; flex-wrap: wrap; }
.rpe label { display: block; }
.rpe input { position: absolute; opacity: 0; width: 1px; pointer-events: none; }
.rpe span { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 9px; border: 1px solid var(--line-2); font-weight: 650; cursor: pointer; font-variant-numeric: tabular-nums; }
.rpe input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.rpe input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.ex-log { display: grid; gap: 6px; }
.ex-log h3 small { font-weight: 500; color: var(--muted); }
.set-row { display: grid; grid-template-columns: 22px 1fr 1fr 44px; gap: 6px; align-items: center; }
.set-row > span { color: var(--muted); font-weight: 650; font-variant-numeric: tabular-nums; text-align: center; }
.set-row input[type="text"] { padding: 7px 9px; }
.check { display: grid; place-items: center; }
.check input { width: 22px; height: 22px; accent-color: var(--ok); }
.set-head { font-size: 0.74rem; color: var(--muted); font-weight: 650; text-transform: uppercase; letter-spacing: 0.05em; }

/* ---------------------------------------------------------------- editor */
.editor-wrap { display: grid; gap: 18px; }
@media (min-width: 1000px) {
  .editor-wrap { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
  .preview { position: sticky; top: 72px; }
}
.editor { display: grid; gap: 14px; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.presets .muted { margin-right: 4px; }

.b-list, .b-list ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.b-step { background: var(--card); border: 1px solid var(--line); border-left: 5px solid var(--k-active); border-radius: 11px; padding: 10px; display: grid; gap: 8px; }
.b-step.k-warmup { border-left-color: var(--k-warmup); }
.b-step.k-recovery { border-left-color: var(--k-recovery); }
.b-step.k-rest { border-left-color: var(--k-rest); }
.b-step.k-cooldown { border-left-color: var(--k-cooldown); }
.b-row { display: grid; gap: 8px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .b-row.main { grid-template-columns: 178px minmax(170px, 1fr) minmax(220px, 1.4fr); } .b-row.extra { grid-template-columns: 1fr 1.6fr auto; } }
.b-pair { display: grid; grid-template-columns: auto 1fr; gap: 6px; align-items: center; }
.b-pair select { width: auto; }
.b-target { display: flex; gap: 6px; align-items: center; }
.b-target select:first-child { width: auto; flex: none; }
.b-target input { width: 72px; flex: none; }
.b-target .unit { color: var(--muted); font-size: 0.85rem; }
.b-tools { display: flex; gap: 2px; justify-content: flex-end; }
.b-tools button { width: 34px; height: 34px; border-radius: 8px; border: 1px solid transparent; background: transparent; color: var(--muted); font: inherit; cursor: pointer; }
.b-tools button:hover { background: var(--bg); color: var(--ink); border-color: var(--line); }
.b-tools button.del:hover { color: var(--err); }
.b-repeat { border: 1.5px dashed var(--line-2); border-radius: 13px; padding: 10px; display: grid; gap: 8px; background: color-mix(in srgb, var(--accent-soft) 30%, transparent); }
.b-repeat-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-weight: 650; }
.b-repeat-head input[data-f="times"] { width: 72px; }
.b-repeat-head input[data-f="label"] { flex: 1; min-width: 140px; width: auto; }
.b-add { display: flex; gap: 8px; flex-wrap: wrap; }

.b-ex { background: var(--card); border: 1px solid var(--line); border-left: 5px solid var(--k-cooldown); border-radius: 11px; padding: 10px; display: grid; gap: 8px; }
.ex-nums { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 640px) { .ex-nums { grid-template-columns: 90px 110px 1fr 120px; } }
.ex-nums label { font-size: 0.76rem; }

.preview { display: grid; gap: 12px; }
.preview pre { margin: 0; white-space: pre-wrap; font: 0.82rem/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--bg); border-radius: 9px; padding: 10px; max-height: 360px; overflow: auto; }
.preview details summary { cursor: pointer; font-weight: 600; font-size: 0.88rem; color: var(--ink-2); }
.preview .chips .chip { flex: 1; }
.pv-error { color: var(--err); font-size: 0.88rem; font-weight: 600; }
.save-bar { display: flex; gap: 8px; align-items: center; }
@media (max-width: 720px) {
  .save-bar { position: sticky; bottom: calc(68px + var(--safe-b)); background: var(--bg); padding: 10px 0; z-index: 5; }
  .save-bar .btn.primary { flex: 1; }
}

/* ---------------------------------------------------------------- settings */
.settings { display: grid; gap: 16px; max-width: 760px; }
.steps-howto { margin: 0; padding-left: 20px; display: grid; gap: 6px; color: var(--ink-2); }
.howto > summary, .watch > summary { cursor: pointer; font-weight: 650; color: var(--ink); }
.howto[open] > summary { margin-bottom: 10px; }
.howto > p { margin: 10px 0 0; }
.watch { margin-top: 8px; padding: 8px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg); }
.watch[open] > summary { margin-bottom: 8px; }
.watch ol { margin: 0; padding-left: 18px; display: grid; gap: 6px; }
.note { margin: 10px 0 0; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--warn-soft); color: var(--ink); font-size: 0.85rem; }
.code-big { font: 700 1.6rem/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: 0.08em; background: var(--bg); border: 1px dashed var(--line-2); border-radius: 12px; padding: 14px 16px; text-align: center; user-select: all; }
.list { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.list li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 11px; background: var(--bg); }
.list li .grow { flex: 1; min-width: 0; }
.list li .grow small { display: block; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }

/* ---------------------------------------------------------------- toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-b));
  transform: translate(-50%, 16px);
  opacity: 0;
  pointer-events: none;
  background: var(--ink);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 0.9rem;
  max-width: min(92vw, 520px);
  z-index: 50;
  transition: opacity 180ms ease, transform 180ms ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--err); color: #fff; }
@media (max-width: 720px) { body.has-nav .toast { bottom: calc(80px + var(--safe-b)); } }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
