:root {
  --bg: #f6f1e7;
  --surface: #fffdf8;
  --surface-2: #efe8da;
  --ink: #1f1b16;
  --muted: #6f665a;
  --line: #e0d7c6;
  --accent: #c2410c;
  --accent-ink: #fff;
  --ok: #0f766e;
  --shadow: 0 1px 2px rgba(60, 40, 10, .06), 0 8px 24px rgba(60, 40, 10, .08);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15130f;
    --surface: #1f1c17;
    --surface-2: #2a261f;
    --ink: #f1eadc;
    --muted: #a59a88;
    --line: #38332a;
    --accent: #f97316;
    --accent-ink: #1a0f05;
    --ok: #2dd4bf;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 0; text-wrap: balance; }
h1 { font-size: 2rem; }
p { margin: 0; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- layout ---------- */
.shell { min-height: 100dvh; }
main {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 16px calc(96px + env(safe-area-inset-bottom));
  outline: none;
}
.nav {
  position: fixed; inset: auto 0 0 0; z-index: 10;
  display: flex; justify-content: space-around; align-items: stretch;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav .brand, .nav .sync { display: none; }
.nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 4px 8px; text-decoration: none;
  font-size: .72rem; color: var(--muted);
}
.nav a svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.nav a.active { color: var(--accent); font-weight: 600; }

/* 840px: el iPhone Duo abierto en horizontal mide 890 puntos de ancho y usa la barra lateral. */
@media (min-width: 840px) {
  .shell { display: grid; grid-template-columns: calc(200px + env(safe-area-inset-left)) 1fr; }
  .nav {
    position: sticky; top: 0; inset: auto; height: 100dvh;
    flex-direction: column; justify-content: flex-start; gap: 4px;
    border-top: 0; border-right: 1px solid var(--line);
    padding: 24px 12px 24px calc(12px + env(safe-area-inset-left)); background: transparent; backdrop-filter: none;
  }
  .nav .brand { display: flex; align-items: center; gap: 10px; font: 600 1.25rem var(--serif); padding: 0 12px 20px; }
  .nav a { flex: none; flex-direction: row; gap: 12px; padding: 10px 12px; border-radius: 10px; font-size: .95rem; }
  .nav a:hover { background: var(--surface-2); }
  .nav a.active { background: var(--surface-2); }
  .nav .sync { display: flex; margin-top: auto; padding: 12px; }
  main { padding: 40px 24px 64px; }
}

/* ---------- táctil / iOS ---------- */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { overscroll-behavior-y: none; -webkit-tap-highlight-color: transparent; }
a, button, label, .opt { touch-action: manipulation; }
.nav, .btn, .chip, .tabs { -webkit-user-select: none; user-select: none; }
main { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
.nav { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }

/* ---------- common ---------- */
.top { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 24px; }
.eyebrow { font-size: .78rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.stack { display: grid; gap: 16px; }
.section-title { font: 600 .8rem var(--sans); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 28px 0 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 18px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface);
  cursor: pointer; text-decoration: none; font-weight: 550;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.danger { color: #b91c1c; }
.btn[disabled] { opacity: .55; cursor: progress; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: .78rem; padding: 3px 10px; border-radius: 999px;
  background: color-mix(in srgb, var(--c, var(--accent)) 14%, transparent);
  color: color-mix(in srgb, var(--c, var(--accent)) 70%, var(--ink));
  border: 0; text-decoration: none;
}
button.chip { cursor: pointer; }
button.chip.on { background: var(--c, var(--accent)); color: #fff; }
.chip.big { font-size: .92rem; padding: 8px 14px; background: var(--surface-2); color: var(--ink); }
.tag { font-size: .8rem; color: var(--muted); }
.notice.err { margin-bottom: 16px; border-left: 4px solid #dc2626; }
.notice.reto { display: flex; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 16px; border-left: 4px solid var(--accent); }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: .88rem; border-radius: 9px; flex: none; }
.tools { display: flex; gap: 4px; margin: 18px -12px -8px; padding-top: 10px; border-top: 1px dashed var(--line); }
.card.takeaway .body { font-size: 1.35rem; font-style: italic; line-height: 1.5; }
.opts { display: grid; gap: 10px; margin-top: 6px; }
.opt {
  text-align: left; padding: 13px 16px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--line); background: var(--bg); font-size: 1.02rem;
}
.opt:hover:not(:disabled) { border-color: var(--accent); }
.opt:disabled { cursor: default; opacity: .6; }
.opt.right { opacity: 1; border-color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, transparent); font-weight: 600; }
.opt.wrong { opacity: 1; border-color: #dc2626; background: color-mix(in srgb, #dc2626 12%, transparent); }
.explain { margin-top: 16px; }
.answer { white-space: pre-wrap; font: 1.02rem/1.6 var(--serif); }
.kv { row-gap: 18px; }

/* ---------- pantallas anchas de teléfono (iPhone Duo abierto: 626 × 890) ---------- */
@media (min-width: 600px) {
  .card { padding: 36px 36px 28px; }
  .card h2 { font-size: 1.9rem; }
  .card .body { font-size: 1.2rem; }
  #list .list { grid-template-columns: 1fr 1fr; align-items: start; }
  .cols { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
}
@media (min-width: 840px) {
  .actions { bottom: 0; }
  #toast { bottom: 24px; }
}
/* ---------- pantallas bajas (Duo plegado: 466 × 678; abierto en horizontal: 890 × 626) ---------- */
@media (max-height: 720px) {
  main { padding-top: 14px; }
  .top { margin-bottom: 14px; }
  h1 { font-size: 1.6rem; }
  .ring, .ring svg { width: 46px; height: 46px; }
  .streak b { font-size: 1.25rem; }
  .card { padding: 20px 20px 18px; border-radius: 16px; }
  .card-meta { margin-bottom: 12px; }
  .card h2 { font-size: 1.35rem; margin-bottom: 10px; }
  .card .body { font-size: 1.05rem; line-height: 1.55; }
  .card.takeaway .body { font-size: 1.2rem; }
  .tools { margin-top: 12px; padding-top: 6px; }
  .nav a { padding: 7px 4px 5px; }
  .actions { bottom: calc(52px + env(safe-area-inset-bottom)); padding: 8px 0; }
  .remaining { margin-top: 4px; }
  .empty { padding: 32px 16px; }
}
@media (max-height: 720px) and (min-width: 840px) {
  .actions { bottom: 0; }
  .nav { padding-top: 14px; }
  .nav .brand { padding-bottom: 10px; }
  .nav a { padding: 8px 12px; }
}
.item.dim h3, .item.dim p { opacity: .6; }
.steps { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 2px; counter-reset: step; }
.steps li { counter-increment: step; position: relative; padding: 8px 0 8px 36px; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 12px; }
.steps li::before {
  content: counter(step); position: absolute; left: 0; top: 8px; width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center; font-size: .75rem; font-weight: 650;
  background: var(--surface-2); color: var(--muted);
}
.steps li.done::before { content: "✓"; background: var(--ok); color: var(--surface); }
.steps li.next::before { background: var(--accent); color: var(--accent-ink); }
.steps li.next { font-weight: 600; }
.steps li.next > span.small { color: var(--accent); }
.steps li.todo { color: var(--muted); }
.steps li p { flex-basis: 100%; font-weight: 400; }

/* ---------- today ---------- */
.stats { display: flex; align-items: center; gap: 14px; }
.ring { position: relative; width: 56px; height: 56px; }
.ring svg { width: 56px; height: 56px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 5; }
.ring .track { stroke: var(--surface-2); }
.ring .bar { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset .5s ease; }
.ring span { position: absolute; inset: 0; display: grid; place-items: center; font-size: .8rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.streak { text-align: center; line-height: 1.1; }
.streak b { display: block; font: 600 1.5rem var(--serif); }
.streak small { color: var(--muted); font-size: .72rem; }

.card {
  position: relative; background: var(--surface); border-radius: 20px;
  padding: 28px 24px 24px; box-shadow: var(--shadow);
  border-top: 6px solid var(--c, var(--accent));
  animation: rise .25s ease;
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
@media (prefers-reduced-motion: reduce) { .card { animation: none; } .ring .bar { transition: none; } }
.card-meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 18px; }
.card h2 { font-size: 1.6rem; margin-bottom: 14px; }
.card .body { font: 1.12rem/1.65 var(--serif); white-space: pre-wrap; }
.card .src { margin-top: 14px; color: var(--muted); font-style: italic; }
.card .tags { margin-top: 10px; display: flex; gap: 10px; flex-wrap: wrap; }
.card .recall { padding: 24px 0 8px; color: var(--muted); font-style: italic; }
.note { display: grid; gap: 6px; margin-top: 22px; padding-top: 18px; border-top: 1px dashed var(--line); font-size: .85rem; color: var(--muted); }
/* Los botones quedan siempre a la vista, sobre la barra inferior, aunque la tarjeta sea larga. */
.actions {
  display: flex; gap: 10px; margin-top: 8px; padding: 10px 0;
  position: sticky; bottom: calc(60px + env(safe-area-inset-bottom)); z-index: 5;
  background: linear-gradient(to top, var(--bg) 75%, transparent);
}
.actions:empty { display: none; }
.card.swipe { touch-action: pan-y; will-change: transform; }
.card[data-dir="save"] { box-shadow: 0 0 0 3px var(--ok), var(--shadow); }
.card[data-dir="pass"] { opacity: .55; }
.actions .btn { flex: 1; }
.actions .btn.ghost { flex: 0 0 auto; }
.remaining { text-align: center; margin-top: 14px; }
.empty { text-align: center; padding: 56px 16px; background: var(--surface); border-radius: 20px; border: 1px dashed var(--line); }
.empty h2 { margin-bottom: 8px; }
.empty .row { justify-content: center; margin-top: 20px; }

/* ---------- forms ---------- */
label.field { display: grid; gap: 6px; font-size: .85rem; color: var(--muted); }
input[type=text], input[type=search], input[type=number], select, textarea {
  width: 100%; padding: 11px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
textarea { resize: vertical; min-height: 96px; line-height: 1.5; }
textarea.tall { min-height: 180px; }
.grid2 { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 560px) { .grid2 { grid-template-columns: 1fr 1fr; } }
.tabs { display: inline-flex; background: var(--surface-2); border-radius: 12px; padding: 4px; margin-bottom: 20px; }
.tabs button { border: 0; background: transparent; padding: 8px 16px; border-radius: 9px; cursor: pointer; color: var(--muted); font-weight: 550; }
.tabs button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .1); }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 20px; }
.notice { background: var(--surface-2); border-radius: 12px; padding: 14px 16px; font-size: .92rem; }
.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatches label { cursor: pointer; }
.swatches input { position: absolute; opacity: 0; }
.swatches span { display: block; width: 32px; height: 32px; border-radius: 50%; background: var(--c); border: 3px solid var(--surface); box-shadow: 0 0 0 1px var(--line); }
.swatches input:checked + span { box-shadow: 0 0 0 2px var(--ink); }
.swatches input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 3px; }

/* ---------- library ---------- */
.cols { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.col {
  display: block; text-decoration: none; background: var(--surface);
  border-radius: 14px; padding: 16px; border: 1px solid var(--line);
  border-left: 6px solid var(--c);
}
.col:hover { border-color: var(--c); }
.col h3 { font-size: 1.05rem; margin-bottom: 4px; overflow-wrap: anywhere; }
.list { display: grid; gap: 8px; }
.item {
  display: block; width: 100%; text-align: left; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 14px 16px;
}
.item:hover { border-color: var(--muted); }
.item h3 { font-size: 1.05rem; margin-bottom: 4px; }
.item p { color: var(--muted); font-size: .9rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.item .row { margin-top: 8px; }
.gen-item { display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: start; cursor: pointer; }
.gen-item input { margin-top: 6px; width: 18px; height: 18px; accent-color: var(--accent); }

/* ---------- dialog / toast / sync ---------- */
dialog {
  width: min(640px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  border: 0; border-radius: 18px; padding: 24px;
  background: var(--bg); color: var(--ink); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(20, 15, 5, .5); }
dialog h2 { margin-bottom: 18px; }
#toast {
  position: fixed; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  font-size: .9rem; opacity: 0; pointer-events: none; transition: .25s; z-index: 30; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.sync { align-items: center; gap: 8px; font-size: .8rem; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--ok); }
.dot.busy { background: #d97706; }
.dot.err { background: #dc2626; }
.kv { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; text-align: center; }
.kv b { display: block; font: 600 1.6rem var(--serif); }
.kv small { color: var(--muted); }
