:root {
  --noite: #131a31;
  --tinta: #1d2647;
  --tinta-2: #26315a;
  --linea: #34406e;
  --papel: #ede7da;
  --bruma: #9aa2c0;
  --lampada: #f4c95d;
  --lampada-suave: rgba(244, 201, 93, 0.14);
  --mar: #67b8ad;
  --coral: #e98a7a;
  --serif: 'Fraunces', Georgia, serif;
  --sans: 'Figtree', system-ui, sans-serif;
  --r-s: 6px;
  --r-m: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--noite);
  background-image: radial-gradient(ellipse 90% 50% at 50% -10%, rgba(244, 201, 93, 0.09), transparent 70%);
  background-attachment: fixed;
  color: var(--papel);
  font: 400 1rem/1.55 var(--sans);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--lampada); }
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--lampada); outline-offset: 3px; border-radius: 4px; }
[hidden] { display: none !important; }

/* Estructura */
#app { max-width: 640px; margin: 0 auto; padding: 0 16px calc(88px + env(safe-area-inset-bottom)); }
#view { padding-top: 28px; }
.page-title { font: 600 1.75rem/1.2 var(--serif); margin: 0 0 4px; letter-spacing: -0.01em; }
.page-sub { color: var(--bruma); margin: 0 0 28px; }
h2 { font: 600 1.15rem/1.3 var(--serif); margin: 0 0 12px; }
.muted { color: var(--bruma); }
.small { font-size: 0.875rem; }

/* Navegación inferior */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center; gap: 4px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: rgba(19, 26, 49, 0.94); backdrop-filter: blur(10px);
  border-top: 1px solid var(--linea);
}
.tabs a {
  flex: 1; max-width: 140px; text-decoration: none; color: var(--bruma);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 4px; border-radius: var(--r-s); font-size: 0.78rem; font-weight: 500;
}
.tabs a svg { width: 22px; height: 22px; }
.tabs a[aria-current="page"] { color: var(--lampada); }

/* Botones */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--linea); background: var(--tinta); color: var(--papel);
  padding: 11px 18px; border-radius: 999px; cursor: pointer; font-weight: 600;
  text-decoration: none; min-height: 44px;
}
.btn:hover { background: var(--tinta-2); }
.btn-primary { background: var(--lampada); color: #1a1f33; border-color: var(--lampada); }
.btn-primary:hover { background: #f7d67f; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--bruma); }
.btn-ghost:hover { background: transparent; color: var(--papel); }
.btn-danger { color: var(--coral); border-color: rgba(233, 138, 122, 0.4); background: transparent; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* Bloques */
.block { background: var(--tinta); border-radius: var(--r-m); padding: 18px; margin-bottom: 14px; }
.block-flat { padding: 4px 0 20px; margin-bottom: 20px; border-bottom: 1px solid var(--linea); }

/* Login */
.login { min-height: 92dvh; display: flex; flex-direction: column; justify-content: center; padding: 24px 4px; }
.login .lamp { width: 64px; height: 64px; margin-bottom: 28px; }
.login h1 { font: 600 clamp(2.2rem, 9vw, 3.2rem)/1.05 var(--serif); margin: 0 0 18px; letter-spacing: -0.02em; }
.login p { color: var(--bruma); max-width: 32em; margin: 0 0 32px; font-size: 1.05rem; }
.login .error { color: var(--coral); margin-bottom: 18px; }

/* Repaso nocturno (wizard) */
.wizard { min-height: calc(100dvh - 140px); display: flex; flex-direction: column; }
.progress { height: 3px; background: var(--linea); border-radius: 2px; overflow: hidden; margin-bottom: 10px; }
.progress span { display: block; height: 100%; background: var(--lampada); transition: width 0.3s ease; }
.wizard-meta { display: flex; justify-content: space-between; color: var(--bruma); font-size: 0.85rem; margin-bottom: 40px; }
.question { flex: 1; animation: rise 0.35s ease both; }
.question h1 { font: 500 clamp(1.7rem, 6.5vw, 2.3rem)/1.18 var(--serif); margin: 0 0 12px; letter-spacing: -0.015em; }
.question .hint { color: var(--bruma); margin: 0 0 26px; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.answer {
  width: 100%; min-height: 160px; resize: vertical;
  background: transparent; border: 0; border-bottom: 1px solid var(--linea);
  padding: 0; font: 400 1.1rem/1.65 var(--serif); color: var(--papel);
  background-image: repeating-linear-gradient(transparent, transparent calc(1.65em - 1px), rgba(52, 64, 110, 0.55) calc(1.65em - 1px), rgba(52, 64, 110, 0.55) 1.65em);
  background-size: 100% 1.65em; line-height: 1.65em;
}
.answer:focus { outline: none; border-bottom-color: var(--lampada); }
.answer::placeholder { color: #5d6790; font-style: italic; }

.scale { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.scale button {
  border: 1px solid var(--linea); background: var(--tinta); border-radius: var(--r-m);
  padding: 14px 4px 10px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.scale button b { font: 600 1.5rem/1 var(--serif); }
.scale button span { font-size: 0.72rem; color: var(--bruma); }
.scale button[aria-pressed="true"] { background: var(--lampada-suave); border-color: var(--lampada); }
.scale button[aria-pressed="true"] b { color: var(--lampada); }

.number { display: flex; align-items: center; gap: 14px; }
.number button { width: 52px; height: 52px; border-radius: 50%; border: 1px solid var(--linea); background: var(--tinta); font-size: 1.4rem; cursor: pointer; }
.number output { font: 600 3.4rem/1 var(--serif); min-width: 3.2ch; text-align: center; color: var(--lampada); }
.number .unit { color: var(--bruma); }

.check-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.check-list label {
  display: flex; gap: 14px; align-items: flex-start; padding: 14px 16px; cursor: pointer;
  background: var(--tinta); border: 1px solid var(--linea); border-radius: var(--r-m);
}
.check-list input { width: 22px; height: 22px; accent-color: var(--lampada); margin: 1px 0 0; flex: none; }
.check-list input:checked + span { color: var(--bruma); text-decoration: line-through; text-decoration-color: var(--lampada); }

.prio-inputs { display: grid; gap: 12px; }
.prio-inputs label { display: flex; align-items: center; gap: 12px; }
.prio-inputs .n { font: 600 1.4rem/1 var(--serif); color: var(--lampada); width: 1.2em; flex: none; }
.prio-inputs input {
  flex: 1; background: transparent; border: 0; border-bottom: 1px solid var(--linea);
  padding: 10px 0; font: 400 1.1rem var(--serif);
}
.prio-inputs input:focus { outline: none; border-bottom-color: var(--lampada); }

.wizard-nav { display: flex; justify-content: space-between; gap: 10px; padding: 28px 0 8px; }
.wizard-nav .btn-primary { min-width: 140px; }

.done-screen { text-align: left; padding-top: 12vh; }
.done-screen .big { font: 600 clamp(2.6rem, 12vw, 4rem)/1 var(--serif); color: var(--lampada); margin: 0 0 6px; }
.done-screen p { color: var(--bruma); margin: 0 0 30px; font-size: 1.05rem; }

/* Lectura de un día */
.read-item { margin-bottom: 22px; }
.read-item h3 { font: 500 0.95rem var(--sans); color: var(--bruma); margin: 0 0 4px; }
.read-item p { font: 400 1.08rem/1.6 var(--serif); margin: 0; white-space: pre-wrap; }
.pills { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 24px; }
.pill { background: var(--tinta); border-radius: 999px; padding: 6px 12px; font-size: 0.88rem; }
.pill b { color: var(--lampada); font-weight: 600; }

/* Panel */
.streak { margin: 0 0 26px; }
.streak .num { font: 600 clamp(3.4rem, 16vw, 5rem)/0.95 var(--serif); color: var(--lampada); letter-spacing: -0.03em; }
.streak .lbl { font: 500 1.15rem/1.3 var(--serif); margin-top: 6px; }
.cta-today {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--lampada-suave); border: 1px solid rgba(244, 201, 93, 0.35);
  border-radius: var(--r-m); padding: 16px 18px; margin-bottom: 22px; color: var(--papel); text-decoration: none;
}
.cta-today strong { font: 600 1.05rem var(--serif); display: block; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1px; background: var(--linea); border-radius: var(--r-m); overflow: hidden; margin-bottom: 22px; }
.stats div { background: var(--tinta); padding: 14px 16px; }
.stats b { font: 600 1.6rem/1.1 var(--serif); display: block; }
.stats span { color: var(--bruma); font-size: 0.85rem; }

.month { display: grid; grid-template-columns: repeat(10, 1fr); gap: 6px; }
.month a { aspect-ratio: 1; border-radius: 50%; background: var(--tinta-2); display: block; }
.month a.on { background: var(--lampada); }
.month a.today { box-shadow: 0 0 0 2px var(--noite), 0 0 0 3px var(--bruma); }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .axis { fill: var(--bruma); font-size: 10px; font-family: var(--sans); }
.legend { display: flex; gap: 16px; color: var(--bruma); font-size: 0.82rem; margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }

.plan-list { margin: 0; padding-left: 1.3em; }
.plan-list li { margin-bottom: 6px; font-family: var(--serif); font-size: 1.05rem; }
.plan-list li::marker { color: var(--lampada); font-weight: 600; }

.history { list-style: none; margin: 0; padding: 0; }
.history a { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--linea); color: var(--papel); text-decoration: none; }
.history a span:last-child { color: var(--bruma); font-size: 0.88rem; white-space: nowrap; }
.history .excerpt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Informes semanales */
.report { margin-bottom: 36px; }
.report-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.score { font: 600 2.6rem/1 var(--serif); color: var(--lampada); white-space: nowrap; }
.score small { font-size: 1rem; color: var(--bruma); }
.report .resumen { font: 400 1.12rem/1.6 var(--serif); margin: 0 0 18px; }
.report h3 { font: 600 1rem var(--sans); margin: 22px 0 8px; }
.report ul { margin: 0; padding-left: 1.2em; }
.report li { margin-bottom: 8px; }
.ok li::marker { color: var(--mar); }
.blockers { list-style: none; padding: 0 !important; }
.blockers li { border-left: 2px solid var(--coral); padding-left: 12px; margin-bottom: 12px; }
.blockers .fix { color: var(--bruma); display: block; margin-top: 2px; }
.blockers .fix::before { content: '→ '; color: var(--mar); }
.next-week { background: var(--noite); border: 1px solid rgba(244, 201, 93, 0.35); border-radius: var(--r-m); padding: 16px 18px; margin-top: 18px; }
.next-week .foco { font: 600 1.15rem/1.35 var(--serif); margin: 0 0 10px; }
.question-box { font: italic 400 1.1rem/1.5 var(--serif); border-left: 2px solid var(--lampada); padding-left: 14px; margin-top: 20px; }

/* Ajustes */
.field { margin-bottom: 20px; }
.field label { display: block; font-weight: 600; margin-bottom: 6px; }
.field .help { color: var(--bruma); font-size: 0.88rem; margin: 0 0 8px; }
.input {
  width: 100%; background: var(--noite); border: 1px solid var(--linea); border-radius: var(--r-s);
  padding: 11px 12px; min-height: 44px;
}
textarea.input { min-height: 120px; resize: vertical; line-height: 1.5; }
.input:focus { outline: none; border-color: var(--lampada); }
.switch { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.switch input { width: 20px; height: 20px; accent-color: var(--lampada); }
.user-row { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.user-row img { width: 48px; height: 48px; border-radius: 50%; }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--papel); color: var(--noite); padding: 10px 18px; border-radius: 999px; font-weight: 600;
  z-index: 20; max-width: calc(100% - 32px); animation: rise 0.25s ease both;
}
.toast.err { background: var(--coral); }
.spinner { width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { padding: 28px 0; color: var(--bruma); }
.empty p { margin: 0 0 16px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (min-width: 560px) {
  .stats { grid-template-columns: repeat(4, 1fr); }
  #view { padding-top: 44px; }
}
