:root {
  color-scheme: light;
  --bg: #f5efe3;
  --card: #fffcf5;
  --ink: #2a241e;
  --muted: #74695d;
  --line: #e2d8c6;
  --accent: #8a2b25; /* rojo de rúbrica */
  --on-accent: #fffaf2;
  --done: #4f6b45;
  --skip: #a06a12;
  --skip-bg: #f6e9cc;
  --track: #e6dccb;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --nav-h: 60px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #16130f;
    --card: #211c17;
    --ink: #ece3d5;
    --muted: #a3978a;
    --line: #362e26;
    --accent: #e09a8b;
    --on-accent: #1d1410;
    --done: #9dbb8f;
    --skip: #dcae58;
    --skip-bg: #3a2e17;
    --track: #332b23;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #16130f;
  --card: #211c17;
  --ink: #ece3d5;
  --muted: #a3978a;
  --line: #362e26;
  --accent: #e09a8b;
  --on-accent: #1d1410;
  --done: #9dbb8f;
  --skip: #dcae58;
  --skip-bg: #3a2e17;
  --track: #332b23;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 var(--sans);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#view:focus { outline: none; }

#view {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 20px) 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 28px);
  min-height: 100dvh;
}
.loading { color: var(--muted); padding-top: 30vh; text-align: center; }

/* Cabeceras */
.eyebrow {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 650;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--accent);
}
h1 {
  margin: 2px 0 4px;
  font: 600 1.85rem/1.15 var(--serif);
  text-wrap: balance;
}
h2 {
  margin: 30px 0 10px;
  font: 600 1.15rem/1.25 var(--serif);
}
.sub { margin: 0; color: var(--muted); font-size: 0.93rem; }
.head { margin-bottom: 18px; }
.head-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 44px; margin: -8px 0 4px; }
.back, .step {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 44px; height: 44px; padding: 0 10px;
  border: 0; border-radius: 12px; background: none;
  color: var(--accent); font-weight: 600; text-decoration: none;
}
.back { margin-left: -10px; }
.step[aria-disabled="true"] { opacity: 0.3; pointer-events: none; }
.steps { display: flex; margin-right: -10px; }
.step svg, .back svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Tarjetas */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
}
.card + .card, .about + .card { margin-top: 14px; }
.pad { padding: 16px; }

/* Lecturas del día: cada fila es un botón entero */
.reading {
  display: flex; align-items: center; gap: 14px;
  width: 100%; min-height: 72px; padding: 12px 16px;
  border: 0; border-top: 1px solid var(--line);
  background: none; text-align: left;
}
.reading:first-child { border-top: 0; }
.reading .what { flex: 1; min-width: 0; }
.reading .label { display: block; font-size: 0.74rem; font-weight: 650; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.reading .text { display: block; font: 500 1.32rem/1.25 var(--serif); }
.reading[aria-pressed="true"] .text { color: var(--muted); }
.reading:active { background: color-mix(in srgb, var(--ink) 5%, transparent); }

.check {
  flex: none; display: grid; place-items: center;
  width: 32px; height: 32px; border-radius: 50%;
  border: 2px solid var(--muted);
  transition: background 0.15s, border-color 0.15s;
}
.check svg { width: 18px; height: 18px; fill: none; stroke: var(--card); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; opacity: 0; }
[aria-pressed="true"] > .check, .check.on { background: var(--done); border-color: var(--done); }
[aria-pressed="true"] > .check svg, .check.on svg { opacity: 1; }

.tag {
  display: inline-block; padding: 2px 9px; border-radius: 99px;
  font-size: 0.78rem; font-weight: 600;
  background: var(--skip-bg); color: var(--skip);
}
.tag.plain { background: var(--track); color: var(--muted); }

/* Nota */
.note label { display: block; font-size: 0.86rem; font-weight: 600; margin-bottom: 6px; }
.note textarea {
  display: block; width: 100%; min-height: 76px; padding: 10px 12px; resize: vertical;
  border: 1px solid var(--line); border-radius: 12px; background: var(--bg);
  font: 1rem/1.4 var(--serif);
}
.note .saved { margin: 6px 0 0; min-height: 1.2em; font-size: 0.8rem; color: var(--muted); }

/* Avisos y acciones */
.notice { border-color: color-mix(in srgb, var(--skip) 45%, var(--line)); }
.notice p { margin: 0 0 12px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.btn {
  flex: 1 1 auto; min-height: 46px; padding: 10px 16px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--card); font-weight: 600; text-align: center; text-decoration: none; color: var(--ink);
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.quiet { flex: none; border-color: transparent; background: none; color: var(--accent); padding-inline: 4px; }
.btn:active { filter: brightness(0.94); }
.btn:disabled { opacity: 0.5; }
.about { margin: 14px 2px 0; color: var(--muted); font-size: 0.93rem; }
.about strong { color: var(--ink); font-weight: 600; }
.sunday { font: 500 1.3rem/1.35 var(--serif); margin: 0; text-wrap: balance; }

/* Lista de días (calendario y recuperación) */
.week { margin: 26px 0 8px; display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.week h2 { margin: 0; font-size: 1rem; }
.week span { color: var(--muted); font-size: 0.85rem; }
.block-start { margin: 22px 2px 0; padding-top: 14px; border-top: 2px solid var(--accent); }
.block-start .eyebrow { font-size: 0.72rem; }
.block-start strong { font: 600 1.1rem/1.2 var(--serif); }
.row { display: flex; align-items: stretch; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; }
.row .open {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px;
  padding: 10px 4px 10px 14px; min-height: 58px;
  color: inherit; text-decoration: none;
}
.row .date { flex: none; width: 40px; text-align: center; line-height: 1.1; }
.row .date b { display: block; font: 600 1.2rem/1 var(--serif); }
.row .date small { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.row .texts { min-width: 0; }
.row .texts b { display: block; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .texts small { display: block; color: var(--muted); font-size: 0.84rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .mark { flex: none; display: grid; place-items: center; width: 60px; border: 0; background: none; }
.row.is-today { background: color-mix(in srgb, var(--accent) 9%, transparent); }
.row.is-today .date b { color: var(--accent); }
.row.is-future .check { border-color: var(--line); }
.row.is-skipped .check { border-style: dashed; border-color: var(--skip); }
.row.is-started .check { background: linear-gradient(to top, color-mix(in srgb, var(--done) 55%, transparent) 50%, transparent 50%); }
.toolbar { position: sticky; top: 0; z-index: 2; margin: 0 -16px; padding: calc(env(safe-area-inset-top) + 8px) 16px 8px; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.toolbar h1 { margin: 0; font-size: 1.4rem; }
.toolbar .btn { flex: none; min-height: 40px; padding: 6px 14px; }
#view.has-toolbar { padding-top: 0; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 4px 2px 0; font-size: 0.8rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--muted); }
.legend i.on { background: var(--done); border-color: var(--done); }
.legend i.sk { border-style: dashed; border-color: var(--skip); }

/* Progreso */
.big { display: flex; align-items: baseline; gap: 12px; }
.big b { font: 600 3.4rem/1 var(--serif); letter-spacing: -0.02em; }
.big span { color: var(--muted); }
.bar { height: 8px; border-radius: 99px; background: var(--track); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: inherit; background: var(--done); min-width: 0; transition: width 0.3s; }
.big + .bar { margin-top: 14px; height: 10px; }
.meter { padding: 12px 16px; border-top: 1px solid var(--line); }
.meter:first-child { border-top: 0; }
.meter .top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 7px; }
.meter .name { min-width: 0; font-weight: 550; }
.meter .name small { display: block; font-weight: 400; color: var(--muted); font-size: 0.82rem; }
.meter .num { flex: none; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 0.9rem; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }
.chips li { padding: 4px 11px; border-radius: 99px; background: var(--card); border: 1px solid var(--line); font-size: 0.9rem; }
.empty { color: var(--muted); margin: 0; }

/* Ajustes */
.setting { padding: 14px 16px; border-top: 1px solid var(--line); }
.setting:first-child { border-top: 0; }
.setting h3 { margin: 0 0 2px; font-size: 1rem; }
.setting p { margin: 0 0 10px; color: var(--muted); font-size: 0.9rem; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg button { flex: 1; min-height: 44px; border: 0; border-left: 1px solid var(--line); background: none; font-weight: 550; }
.seg button:first-child { border-left: 0; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }

/* Entrada */
.login { max-width: 340px; margin: 0 auto; padding-top: 16vh; text-align: center; }
.login img { width: 84px; height: 84px; border-radius: 20px; }
.login h1 { margin-top: 18px; }
.login form { margin-top: 26px; display: grid; gap: 10px; text-align: left; }
.login label { font-size: 0.86rem; font-weight: 600; }
.login input { width: 100%; min-height: 48px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); font-size: 1.05rem; }
.login .error { min-height: 1.4em; margin: 0; color: var(--accent); font-size: 0.9rem; }

/* Barra inferior */
#tabs {
  position: fixed; inset: auto 0 0 0; z-index: 5;
  display: flex; justify-content: center;
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--card) 94%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}
#tabs[hidden] { display: none; }
#tabs a {
  flex: 1; max-width: 140px; height: var(--nav-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); text-decoration: none; font-size: 0.72rem; font-weight: 600;
}
#tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#tabs a[aria-current="page"] { color: var(--accent); }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 14px); z-index: 6;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 14px;
  width: max-content; max-width: calc(100vw - 32px);
  padding: 10px 16px; border-radius: 14px;
  background: var(--ink); color: var(--bg); font-size: 0.93rem;
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.25);
}
#toast[hidden] { display: none; }
#toast button { flex: none; min-height: 34px; border: 0; background: none; color: inherit; font-weight: 700; text-decoration: underline; padding: 0 2px; }

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