:root {
  --canvas: #E8EAF2; --surface: #F6F7FB; --surface-2: #FFFFFF; --ink: #121522; --muted: #5B6075; --line: rgba(18, 21, 34, .09);
  --accent: #3B82F6; --accent-deep: #1D4ED8; --danger: #DC2626; --ok: #16A34A; --warn: #B45309;
  --shadow: 0 10px 24px -14px rgba(19, 26, 63, .35), 0 2px 6px -3px rgba(19, 26, 63, .15);
  --radius: 20px; --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --canvas: #0C0F14; --surface: #11151B; --surface-2: #171C24; --ink: #EEF0F6; --muted: #9AA1B2; --line: rgba(255, 255, 255, .08);
    --shadow: 0 0 0 1px rgba(255, 255, 255, .05); color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--canvas); color: var(--ink); }
body { font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
button:disabled { opacity: .45; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tnum { font-variant-numeric: tabular-nums; }

/* Estructura */
.shell { max-width: 1100px; margin: 0 auto; padding: calc(var(--safe-t) + 14px) 16px calc(var(--safe-b) + 92px); }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.top h1 { font-size: 26px; font-weight: 800; }
.top .date { font-size: 14px; color: var(--muted); }
.pills { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 6px 10px; border-radius: 999px; background: var(--surface); box-shadow: var(--shadow); font-size: 13px; font-weight: 600; white-space: nowrap; }
.pill svg { width: 15px; height: 15px; }
.sync { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.sync.busy { background: var(--accent); animation: pulse 1s infinite; }
.sync.off { background: var(--danger); }
@keyframes pulse { 50% { opacity: .3; } }

.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; justify-content: center; gap: 4px; padding: 8px 10px calc(var(--safe-b) + 8px);
  background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); border-top: 1px solid var(--line); }
.tabs button { flex: 1; max-width: 140px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 4px; border-radius: 12px; font-size: 12px; font-weight: 600; color: var(--muted); }
.tabs button svg { width: 24px; height: 24px; }
.tabs button[aria-current="page"] { color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.section { margin: 22px 0 10px; display: flex; align-items: baseline; justify-content: space-between; gap: 4px 8px; flex-wrap: wrap; }
.section h2 { font-size: 18px; }

/* Siguiente pausa */
.next { position: relative; overflow: hidden; color: #fff; background: linear-gradient(135deg, var(--g, #3B82F6), var(--gd, #1D4ED8)); }
.next .eyebrow { font-size: 13px; font-weight: 700; opacity: .85; text-transform: uppercase; letter-spacing: .06em; }
.next h2 { font-size: 22px; margin: 4px 0 2px; }
.next .row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.next.idle { color: var(--ink); background: var(--surface); }
.next.due::after { content: ""; position: absolute; inset: 0; border-radius: inherit; box-shadow: inset 0 0 0 3px rgba(255, 255, 255, .7); animation: pulse 1.6s infinite; pointer-events: none; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 10px 16px; border-radius: 14px; font-weight: 700; background: var(--surface-2); box-shadow: var(--shadow); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.light { background: rgba(255, 255, 255, .95); color: #111; box-shadow: none; }
.btn.ghost { background: rgba(255, 255, 255, .18); color: inherit; box-shadow: none; }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn svg { width: 18px; height: 18px; }

.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.stat { background: var(--surface); border-radius: 16px; padding: 12px; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }

/* Tarjetas de ejercicio */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 12px; }
.ex { --g: #84CC16; --gd: #47740B; position: relative; display: grid; grid-template-columns: 96px 1fr; gap: 12px; align-items: center; padding: 12px;
  background: linear-gradient(160deg, color-mix(in srgb, var(--g) 13%, var(--surface)), var(--surface) 60%); border: 1px solid color-mix(in srgb, var(--g) 22%, transparent); }
.ex .photo { position: relative; width: 96px; height: 96px; border-radius: 16px; background: color-mix(in srgb, var(--g) 18%, var(--surface-2)); display: grid; place-items: center; overflow: hidden; }
.ex .photo img { width: 100%; height: 100%; object-fit: contain; }
.ex .photo .initial { font-size: 34px; font-weight: 800; color: var(--gd); }
.ex .group { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--gd); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .ex .group { color: color-mix(in srgb, var(--g) 65%, white); } }
.ex h3 { font-size: 17px; line-height: 1.2; margin: 2px 0 6px; }
.bar { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--g), var(--gd)); transition: width .5s cubic-bezier(.2, .8, .2, 1); }
.ex .meta { display: flex; justify-content: space-between; gap: 6px; font-size: 13px; color: var(--muted); margin-top: 5px; }
.ex .actions { grid-column: 1 / -1; display: flex; gap: 8px; }
.ex .actions .btn.primary { flex: 1; background: linear-gradient(135deg, var(--g), var(--gd)); }
.ex .actions .minus { width: 48px; padding: 0; }
.ex.done .photo::after { content: "✓"; position: absolute; top: 8px; left: 8px; width: 26px; height: 26px; display: grid; place-items: center; border-radius: 50%; background: var(--ok); color: #fff; font-weight: 800; font-size: 15px; }
.ex.omitted { opacity: .6; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 700; background: var(--line); }
.badge.ok { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.badge.warn { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.badge.danger { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.pop { animation: pop .45s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes pop { 40% { transform: scale(1.04); } }

/* Agenda */
.list { display: flex; flex-direction: column; gap: 8px; }
.item { display: grid; grid-template-columns: 58px 1fr auto; gap: 10px; align-items: center; padding: 12px; }
.item .time { font-weight: 800; font-variant-numeric: tabular-nums; }
.item .name { font-weight: 650; }
.item .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--g, var(--muted)); margin-right: 6px; }
.item.past { opacity: .55; }
.item .acts { display: flex; gap: 4px; }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; background: var(--surface-2); }
.icon-btn svg { width: 19px; height: 19px; }

/* Progreso */
.chart { display: flex; align-items: flex-end; gap: 6px; height: 140px; padding-top: 10px; }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.chart .col i { width: 100%; max-width: 26px; border-radius: 6px 6px 3px 3px; background: linear-gradient(180deg, var(--accent), var(--accent-deep)); min-height: 3px; }
.chart .col i.empty { background: var(--line); }
.chart .col span { font-size: 11px; color: var(--muted); }
.history .day { font-size: 13px; font-weight: 700; color: var(--muted); margin: 14px 0 6px; }
.rec { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; }

/* Ajustes */
.form-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.form-row:last-child { border-bottom: 0; }
.form-row.nowrap { flex-wrap: nowrap; }
.form-row.nowrap > div { min-width: 0; }
.form-row .icon-btn { flex-shrink: 0; }
input[type="time"], input[type="number"], input[type="password"], input[type="text"], select {
  min-height: 42px; padding: 8px 10px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); min-width: 0; }
input[type="number"] { width: 96px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { min-width: 40px; min-height: 40px; padding: 6px 12px; border-radius: 12px; background: var(--surface-2); font-weight: 700; border: 1px solid var(--line); }
.chip[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: transparent; }
.spans { display: flex; flex-direction: column; gap: 6px; }
.span-row { display: flex; align-items: center; gap: 6px; }
.token { font-family: ui-monospace, Menlo, monospace; font-size: 12px; word-break: break-all; padding: 10px; border-radius: 12px; background: var(--surface-2); }
.notice { padding: 12px 14px; border-radius: 14px; background: color-mix(in srgb, var(--accent) 10%, transparent); font-size: 14px; }
.notice.warn { background: color-mix(in srgb, var(--warn) 12%, transparent); }

/* Hojas modales */
.sheet-back { position: fixed; inset: 0; z-index: 40; background: rgba(5, 8, 15, .45); display: flex; align-items: flex-end; justify-content: center; animation: fade .2s; }
.sheet { width: 100%; max-width: 560px; max-height: 92dvh; overflow: auto; background: var(--surface); border-radius: 24px 24px 0 0; padding: 20px 16px calc(var(--safe-b) + 20px); animation: up .25s cubic-bezier(.2, .8, .2, 1); }
@media (min-width: 700px) { .sheet-back { align-items: center; } .sheet { border-radius: 24px; } }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet h2 { margin-bottom: 6px; }

/* Temporizador */
.timer { text-align: center; }
.ring { position: relative; width: min(72vw, 280px); aspect-ratio: 1; margin: 18px auto; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .track { stroke: var(--line); }
.ring .prog { stroke: var(--g, var(--accent)); stroke-linecap: round; transition: stroke-dashoffset .25s linear; }
.ring .label { position: absolute; inset: 0; display: grid; place-items: center; font-size: clamp(48px, 16vw, 76px); font-weight: 800; font-variant-numeric: tabular-nums; }
.timer .row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* Login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px; padding: 24px; }
.login img { width: 72px; height: 72px; border-radius: 18px; }

#toast { position: fixed; left: 50%; bottom: calc(var(--safe-b) + 90px); transform: translateX(-50%); z-index: 60; max-width: calc(100% - 32px); padding: 12px 16px; border-radius: 14px; background: #111827; color: #fff; font-size: 14px; font-weight: 600; box-shadow: 0 10px 30px rgba(0, 0, 0, .3); }
#toast.error { background: var(--danger); }

/* Celebración */
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 70; overflow: hidden; }
.confetti i { position: absolute; top: -12px; width: 9px; height: 14px; border-radius: 2px; animation: fall 1.6s ease-in forwards; }
@keyframes fall { to { transform: translateY(105vh) rotate(540deg); opacity: .7; } }

@media (min-width: 900px) { .ex { grid-template-columns: 120px 1fr; } .ex .photo { width: 120px; height: 120px; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
