:root {
  --bg: #0b0f14;
  --bg2: #111823;
  --card: #151e2b;
  --card2: #1b2636;
  --line: #243247;
  --text: #e8eef6;
  --muted: #8ea0b8;
  --accent: #22d3a6;
  --accent-ink: #04120d;
  --good: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 18px;
  --tabbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --shadow: 0 8px 28px rgba(0, 0, 0, .35);
}
:root[data-theme="light"] {
  --bg: #f3f6fa;
  --bg2: #e9eef5;
  --card: #ffffff;
  --card2: #f0f4f9;
  --line: #d6dfeb;
  --text: #0f1b2d;
  --muted: #5b6b82;
  --accent-ink: #ffffff;
  --shadow: 0 8px 24px rgba(20, 40, 80, .12);
}
@media (prefers-color-scheme: light) {
  :root[data-theme="auto"] {
    --bg: #f3f6fa; --bg2: #e9eef5; --card: #ffffff; --card2: #f0f4f9; --line: #d6dfeb;
    --text: #0f1b2d; --muted: #5b6b82; --accent-ink: #ffffff; --shadow: 0 8px 24px rgba(20, 40, 80, .12);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 600px at 80% -10%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 60%), var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: contain;
}
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.15; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 .6em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
button, input, select, textarea { font: inherit; color: inherit; }

/* Layout */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + var(--safe-t)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .02em; }
.logo {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), #0ea5e9); color: var(--accent-ink); font-weight: 800;
}
.top-actions { display: flex; align-items: center; gap: 8px; }
main {
  max-width: 760px; margin: 0 auto;
  padding: 16px 16px calc(var(--tabbar-h) + var(--safe-b) + 24px);
  outline: none;
}
.view-enter { animation: rise .35s cubic-bezier(.2, .8, .2, 1) both; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* Tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--bg2) 92%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.tabbar button {
  background: none; border: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; color: var(--muted); font-size: .72rem; cursor: pointer; transition: color .2s, transform .2s;
}
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button[aria-current="page"] { color: var(--accent); }
.tabbar button[aria-current="page"] svg { transform: translateY(-2px) scale(1.08); }
.tabbar button:active { transform: scale(.94); }

/* Cards & controls */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.card.flat { box-shadow: none; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stack > * + * { margin-top: 10px; }

.btn {
  appearance: none; border: 0; cursor: pointer; border-radius: 14px; padding: 12px 16px; font-weight: 650;
  background: var(--accent); color: var(--accent-ink); transition: transform .12s, filter .2s, box-shadow .2s;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 35%, transparent);
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: scale(.97); }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); box-shadow: none; }
.btn.danger { background: var(--bad); color: #2b0606; box-shadow: none; }
.btn.small { padding: 7px 12px; border-radius: 11px; font-size: .85rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:focus-visible, input:focus-visible, select:focus-visible, .tabbar button:focus-visible, .seg button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

label.field { display: block; font-size: .82rem; color: var(--muted); }
.field input, .field select, .field textarea {
  display: block; width: 100%; margin-top: 4px; padding: 11px 12px; border-radius: 12px;
  background: var(--card2); border: 1px solid var(--line); color: var(--text);
}
.field input[type="color"] { padding: 3px; height: 44px; }
.field input[type="checkbox"] { width: auto; display: inline-block; margin-right: 8px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: .75rem; font-weight: 650;
  background: var(--card2); border: 1px solid var(--line); color: var(--muted);
}
.chip.ok { color: var(--good); border-color: color-mix(in srgb, var(--good) 40%, var(--line)); }
.chip.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); }
.chip.bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 50%, var(--line)); }

.seg { display: flex; background: var(--card2); border: 1px solid var(--line); border-radius: 14px; padding: 4px; gap: 4px; overflow-x: auto; }
.seg button {
  flex: 1; border: 0; background: transparent; padding: 8px 10px; border-radius: 10px; color: var(--muted); cursor: pointer; white-space: nowrap;
  font-weight: 600; transition: background .2s, color .2s;
}
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

.alert { border-radius: 14px; padding: 12px 14px; font-size: .92rem; border: 1px solid var(--line); background: var(--card2); }
.alert.warn { border-color: var(--warn); background: color-mix(in srgb, var(--warn) 12%, var(--card)); }
.alert.bad { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 14%, var(--card)); }
.alert.info { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); }

/* Rings */
.rings { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.ring { position: relative; width: 100%; max-width: 132px; margin: 0 auto; aspect-ratio: 1; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .track { fill: none; stroke: var(--card2); stroke-width: 10; }
.ring .bar {
  fill: none; stroke: var(--ringc, var(--accent)); stroke-width: 10; stroke-linecap: round;
  stroke-dasharray: 289; stroke-dashoffset: 289; transition: stroke-dashoffset 1.1s cubic-bezier(.2, .8, .2, 1);
}
.ring .val { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 800; font-size: 1.15rem; }
.ring .val small { display: block; font-weight: 500; font-size: .68rem; color: var(--muted); }
.ring-label { font-size: .78rem; color: var(--muted); margin-top: 6px; }

/* Stat tiles */
.stat { background: var(--card2); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.stat .k { font-size: .75rem; color: var(--muted); }
.stat .v { font-size: 1.4rem; font-weight: 800; letter-spacing: -.01em; }
.stat .u { font-size: .75rem; color: var(--muted); font-weight: 500; margin-left: 3px; }

/* Charts */
.chart-wrap { position: relative; width: 100%; height: 190px; }
.chart-wrap canvas { width: 100%; height: 100%; display: block; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: .75rem; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list .grow { flex: 1; min-width: 0; }
.iconbtn { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 6px; border-radius: 8px; }
.iconbtn:hover { color: var(--bad); }

/* Routines */
.routine { display: grid; grid-template-columns: 54px 1fr auto; gap: 12px; align-items: center; cursor: pointer; transition: transform .15s, border-color .2s; }
.routine:hover { border-color: var(--accent); }
.routine:active { transform: scale(.985); }
.routine .emoji { width: 54px; height: 54px; border-radius: 16px; display: grid; place-items: center; font-size: 1.6rem; background: var(--card2); }
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; text-align: center; }
.week .d { padding: 8px 0; border-radius: 12px; background: var(--card2); font-size: .72rem; color: var(--muted); border: 1px solid transparent; }
.week .d b { display: block; font-size: 1rem; color: var(--text); }
.week .d.done { background: color-mix(in srgb, var(--accent) 22%, var(--card2)); border-color: var(--accent); }
.week .d.today { border-color: var(--text); }

/* Meals */
.meal { display: grid; grid-template-columns: 38px 1fr auto; gap: 10px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.meal:first-of-type { border-top: 0; }
.meal .ico { width: 38px; height: 38px; border-radius: 12px; background: var(--card2); display: grid; place-items: center; }
.check { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }
.check.done span.t { text-decoration: line-through; color: var(--muted); }
.check .qty { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--muted); }
.cat-title { margin: 14px 0 2px; font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); }
.progress { height: 8px; border-radius: 999px; background: var(--card2); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width .6s cubic-bezier(.2, .8, .2, 1); }

/* Workout player */
.player {
  position: fixed; inset: 0; z-index: 60; display: flex; flex-direction: column; padding: calc(16px + var(--safe-t)) 20px calc(20px + var(--safe-b));
  background: var(--bg); color: var(--text); transition: background .4s;
}
.player[hidden] { display: none; }
.player.work { background: radial-gradient(800px 500px at 50% 30%, color-mix(in srgb, var(--accent) 24%, transparent), transparent 70%), var(--bg); }
.player.rest { background: radial-gradient(800px 500px at 50% 30%, rgba(14, 165, 233, .22), transparent 70%), var(--bg); }
.player .phase { text-transform: uppercase; letter-spacing: .12em; font-size: .78rem; color: var(--muted); }
.player .name { font-size: clamp(1.7rem, 7vw, 2.4rem); font-weight: 800; margin: 6px 0; }
.player .tip { color: var(--muted); min-height: 2.6em; }
.timer { position: relative; width: min(72vw, 320px); aspect-ratio: 1; margin: auto; }
.timer svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.timer .track { fill: none; stroke: var(--card2); stroke-width: 8; }
.timer .bar { fill: none; stroke: var(--accent); stroke-width: 8; stroke-linecap: round; stroke-dasharray: 289; stroke-dashoffset: 0; transition: stroke-dashoffset .25s linear, stroke .3s; }
.player.rest .timer .bar { stroke: #0ea5e9; }
.timer .num { position: absolute; inset: 0; display: grid; place-items: center; font-size: clamp(3.6rem, 18vw, 5.6rem); font-weight: 800; font-variant-numeric: tabular-nums; }
.timer .num.pulse { animation: pulse .5s ease; }
@keyframes pulse { 50% { transform: scale(1.12); } }
.player .controls { display: grid; grid-template-columns: 1fr 1.4fr 1fr; gap: 10px; }
.player .next { text-align: center; color: var(--muted); font-size: .9rem; margin: 10px 0 14px; min-height: 1.4em; }
.player .total { height: 6px; }

/* Modal & toast */
dialog { border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 22px; padding: 18px; width: min(92vw, 460px); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0, 0, 0, .55); backdrop-filter: blur(3px); }
#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 14px); transform: translate(-50%, 20px); opacity: 0; z-index: 80;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-weight: 600; font-size: .9rem; pointer-events: none;
  transition: opacity .25s, transform .25s; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch { width: 38px; height: 38px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; }
.swatch[aria-pressed="true"] { border-color: var(--text); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
@media (min-width: 720px) {
  .grid3.wide { grid-template-columns: repeat(4, 1fr); }
}

/* Ejercicios: figura animada, pasos y video */
.fig { display: block; width: 100%; max-width: 220px; height: auto; margin: 0 auto; }
.fig polyline, .fig path, .fig line { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.fig .fig-near { stroke: var(--accent); stroke-width: 4.5; }
.fig .fig-far { stroke: color-mix(in srgb, var(--accent) 45%, var(--muted)); stroke-width: 4; opacity: .7; }
.fig .fig-head { fill: var(--accent); }
.fig .fig-ground { stroke: var(--line); stroke-width: 2; }
.player .p-fig { margin: 4px auto 0; }
.player .p-fig .fig { max-width: 170px; }
.player .p-help { justify-content: center; gap: 8px; margin-top: 6px; }
.player .timer { margin-top: 6px; width: min(50vw, 230px); }
.player { overflow-y: auto; }
.ex-block { margin: 14px 0 6px; font-size: .95rem; color: var(--muted); }
.ex-card { border: 1px solid var(--line); border-radius: 14px; padding: 8px 12px; margin: 6px 0; background: var(--card2); }
.ex-card summary { cursor: pointer; font-weight: 700; padding: 4px 0; }
.ex-card .fig { max-width: 200px; margin: 6px auto; }
.ex-steps { margin: 6px 0 10px; padding-left: 1.3em; }
.ex-steps li { margin: 4px 0; }
a.btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
dialog { max-height: 88vh; overflow-y: auto; }

/* acceso */
body.noauth .tabbar{display:none}
body.noauth main{padding-bottom:24px}
.auth{max-width:420px;margin:0 auto}
.auth-logo{display:flex;justify-content:center;margin:12px 0 16px}
.linkbtn{background:none;border:0;padding:6px 0;color:var(--accent,#2563eb);text-decoration:underline;font:inherit;cursor:pointer}
.temp-pw{font-size:1.3em;letter-spacing:.05em;user-select:all}
.row.between{justify-content:space-between}
.grow{flex:1;min-width:0}
.actions{display:flex;flex-wrap:wrap;gap:8px}
