:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #efede7;
  --ink: #16181d;
  --muted: #5d636f;
  --line: #e2e0d8;
  --accent: #b9ea00;
  --accent-ink: #16181d;
  --now: #2f6fed;
  --done: #2a8f53;
  --danger: #c2412d;
  --radius: 16px;
  --tap: 44px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1f232c;
    --ink: #eceef2;
    --muted: #9aa1ad;
    --line: #2a2f39;
    --accent: #c8ff00;
    --accent-ink: #0f1115;
    --now: #6f9bff;
    --done: #4cc38a;
    --danger: #ff8a75;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115; --surface: #171a21; --surface-2: #1f232c; --ink: #eceef2; --muted: #9aa1ad; --line: #2a2f39;
  --accent: #c8ff00; --accent-ink: #0f1115; --now: #6f9bff; --done: #4cc38a; --danger: #ff8a75; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(150px + env(safe-area-inset-bottom));
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--now); outline-offset: 2px; }

/* Cabecera */
.top {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  padding: calc(10px + env(safe-area-inset-top)) 16px 12px;
  border-bottom: 1px solid var(--line);
}
.top__row { display: flex; align-items: center; gap: 8px; max-width: 640px; margin: 0 auto; }
.top__date { flex: 1; text-align: center; }
.top__eyebrow { margin: 0; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.top h1 { margin: 0; font-size: 20px; font-weight: 700; }
.block__head .check { flex: 1; min-height: 36px; padding: 0; font-weight: 650; }
.icon-btn {
  width: var(--tap); height: var(--tap); border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface); font-size: 22px; line-height: 1;
}
.progress { max-width: 640px; margin: 10px auto 0; }
.progress__bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.progress__fill { height: 100%; width: 0; background: var(--accent); border-radius: inherit; transition: width .3s ease; }
.progress__label { margin: 6px 0 0; font-size: 13px; color: var(--muted); text-align: center; }

/* Contenido */
.content { max-width: 640px; margin: 0 auto; padding: 8px 16px 0; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 22px 4px 10px; }
.banner { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; font-size: 14px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }

/* Línea de tiempo */
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.block { display: grid; grid-template-columns: 52px 1fr; gap: 10px; }
.block__time { font-size: 13px; color: var(--muted); padding-top: 15px; text-align: right; font-variant-numeric: tabular-nums; }
.block__body { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; min-width: 0; }
.block--past .block__body { opacity: .72; }
.block--now .block__body { border: 2px solid var(--now); box-shadow: 0 0 0 4px color-mix(in srgb, var(--now) 15%, transparent); }
.block__head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.block__title { margin: 0; font-size: 16px; font-weight: 650; overflow-wrap: anywhere; }
.block__meta { font-size: 12px; color: var(--muted); white-space: nowrap; }
.badge-now { font-size: 11px; font-weight: 700; color: var(--now); text-transform: uppercase; letter-spacing: .06em; }
.block__link { display: inline-block; margin-top: 6px; font-size: 14px; color: var(--now); }

/* Hábitos */
.habit { margin-top: 8px; }
.check {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: var(--tap);
  border: 0; background: transparent; padding: 4px 0; text-align: left;
}
.check__box {
  flex: none; width: 28px; height: 28px; border-radius: 9px; border: 2px solid var(--line);
  display: grid; place-items: center; font-size: 16px; font-weight: 800; color: transparent; transition: background .15s, border-color .15s;
}
.check[aria-pressed="true"] .check__box { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.check[aria-pressed="true"] .check__label { color: var(--muted); text-decoration: line-through; }
.check__label { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.check__count { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.subtasks { list-style: none; margin: 2px 0 0 14px; padding: 0 0 0 14px; border-left: 2px solid var(--line); }
.subtasks .check { min-height: 40px; }
.subtasks .check__box { width: 24px; height: 24px; border-radius: 8px; font-size: 14px; }

.number { display: grid; gap: 8px; }
.number__row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.number__value { font-weight: 650; font-variant-numeric: tabular-nums; }
.number__bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.number__fill { height: 100%; background: var(--done); width: 0; }
.number input { width: 120px; }

/* Formularios */
.journal { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
.field input, .field textarea, .field select {
  width: 100%; border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  border-radius: 12px; padding: 10px 12px; min-height: var(--tap); font-size: 16px;
}
.field textarea { resize: vertical; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice { border: 0; margin: 0; padding: 0; }
.choice legend { font-size: 14px; color: var(--muted); margin-bottom: 6px; padding: 0; }
.choice__row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: var(--tap); padding: 0 12px; border-radius: 99px; border: 1px solid var(--line);
  background: var(--bg); font-size: 15px;
}
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 650; }
.save-state { margin: 0; font-size: 13px; color: var(--muted); min-height: 1.2em; }

/* Botones */
.btn { min-height: var(--tap); padding: 0 18px; border-radius: 12px; border: 0; background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.btn--ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.fab {
  position: fixed; right: 16px; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 6;
  width: 58px; height: 58px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink);
  font-size: 30px; font-weight: 600; box-shadow: 0 8px 24px rgb(0 0 0 / .25);
}

/* Hoja inferior */
.sheet {
  width: min(560px, 100%); margin: auto auto 0; border: 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  border-radius: 20px 20px 0 0; background: var(--surface); color: var(--ink);
}
.sheet::backdrop { background: rgb(0 0 0 / .45); }
.sheet h2 { margin: 0 0 12px; font-size: 18px; }
.sheet form { display: grid; gap: 14px; }
.sheet__actions { display: flex; justify-content: flex-end; gap: 10px; }
.segmented { display: flex; gap: 8px; }
.segmented label { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; min-height: var(--tap); border: 1px solid var(--line); border-radius: 12px; }
.segmented input { accent-color: var(--now); }

.toast {
  position: fixed; left: 50%; bottom: calc(150px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 10;
  max-width: calc(100% - 32px);
}
.toast--error { background: var(--danger); color: #fff; }

/* Entrada */
.login { position: fixed; inset: 0; z-index: 20; background: var(--bg); display: grid; place-items: center; padding: 16px; }
.login[hidden] { display: none; }
.login__card { width: min(420px, 100%); display: grid; gap: 14px; }
.login__card h2 { margin: 0; font-size: 22px; }
.login__hint { margin: 0; color: var(--muted); font-size: 14px; }
.login__error { margin: 0; color: var(--danger); font-size: 14px; min-height: 1.2em; }

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

/* Barra de pestañas */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 7;
  display: grid; grid-template-columns: repeat(3, 1fr);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}
.tabbar__tab {
  display: grid; justify-items: center; gap: 2px; min-height: 52px; padding-top: 6px;
  font-size: 12px; color: var(--muted); text-decoration: none; border-radius: 12px;
}
.tabbar__tab span { font-size: 20px; line-height: 1; }
.tabbar__tab[aria-current="true"] { color: var(--ink); font-weight: 700; background: var(--surface-2); }

/* Accesos del hábito a su entreno */
.routine-links { display: flex; flex-wrap: wrap; gap: 6px; margin: 2px 0 4px 40px; }
.routine-link { display: inline-block; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; color: var(--now); text-decoration: none; padding: 4px 10px; border: 1px solid var(--line); border-radius: 99px; }

/* Entreno */
.routine { display: grid; gap: 10px; scroll-margin-top: 120px; }
.routine--done { border-color: var(--done); }
.routine__head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.routine__head h3 { margin: 0; font-size: 17px; }
.routine__details p { margin: 0 0 4px; font-size: 14px; color: var(--muted); }
.exercises { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; counter-reset: ex; }
.exercises li { display: grid; grid-template-columns: 34px 1fr; column-gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); }
.exercises__sets { grid-row: span 2; font-weight: 700; color: var(--done); font-variant-numeric: tabular-nums; }
.exercises__name { font-weight: 600; }
.exercises__detail { font-size: 13px; color: var(--muted); }
.week { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.week-row { display: grid; grid-template-columns: 92px 1fr; gap: 10px; width: 100%; min-height: var(--tap); padding: 10px 12px; text-align: left; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.week-row--active { border: 2px solid var(--now); }
.week-row__day { font-weight: 650; }
.week-row__routines { color: var(--muted); font-size: 14px; }

/* Notas y tareas */
.list { list-style: none; margin: 0; display: grid; gap: 2px; }
.task__due { color: var(--muted); font-weight: 400; }
.note h3 { margin: 0 0 4px; font-size: 16px; }
.note p { margin: 0; color: var(--muted); font-size: 14px; white-space: pre-line; overflow-wrap: anywhere; }
.empty { color: var(--muted); font-size: 14px; padding: 6px 0; list-style: none; }
.done-tasks summary { cursor: pointer; }

/* Captura rápida */
.sheet__head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.sheet__head h2 { margin: 0; }
.capture-menu { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.capture-menu__item {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 52px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--bg); font-size: 15px; text-align: left;
}
.capture-menu__item span { font-size: 20px; }
.capture-form { display: grid; gap: 14px; }
.sheet { max-height: 88vh; overflow-y: auto; }
