/* ============ Tokens ============ */
/* Tema claro (por defecto): blanco con botones azules */
:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f5f8fa;
  --text: #14171a;
  --muted: #657786;
  --line: #e1e8ed;
  --accent: #1da1f2;          /* azul clásico de Twitter */
  --accent-text: #ffffff;
  --accent-shadow: rgba(29, 161, 242, .45);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --nav-h: 62px;
  --kb: 0px;                  /* alto del teclado (lo actualiza app.js con visualViewport) */
  --danger: #e0245e;
  color-scheme: light;
}

/* Tema oscuro: negro con botones blancos */
:root[data-tema="oscuro"] {
  --bg: #000000;
  --surface: #0d0d0d;
  --surface-2: #1c1c1c;
  --text: #ffffff;
  --muted: #8b8b8b;
  --line: #2a2a2a;
  --accent: #ffffff;
  --accent-text: #000000;
  --accent-shadow: rgba(255, 255, 255, .22);
  color-scheme: dark;
}

/* ============ Base ============ */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  overflow: hidden;
}
button { font: inherit; color: inherit; border: none; background: none; cursor: pointer; touch-action: manipulation; }
[hidden] { display: none !important; }

/* ============ Vista Book ============ */
.view {
  height: calc(var(--vvh, 100dvh) - var(--nav-h) - var(--safe-bottom));
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-top) + 22px) 20px 0;
}
.book-head { margin-bottom: 14px; }
.book-head h1 {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -.01em;
  line-height: 1.2;
}
/* Encabezado de Notas: bloque sólido de ancho completo con el color de acento */
#viewBook { padding-top: 0; }
#viewBook .book-head {
  margin: 0 -20px 12px;
  padding: calc(var(--safe-top) + 10px) 20px 10px;
  background: var(--accent);
  color: var(--accent-text);
}
#viewBook .book-head h1 { color: var(--accent-text); font-size: 24px; line-height: 1.15; }
#viewBook .book-head p { color: var(--accent-text); opacity: .85; }
.book-head p { color: var(--muted); font-size: 14px; text-transform: capitalize; }

#bookText {
  flex: 1;
  width: 100%;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 18px;            /* 16px+ evita el zoom automático en iOS */
  line-height: 32px;          /* altura fija: las líneas de la libreta coinciden con cada renglón */
  padding: 0 0 90px;
  background-image: repeating-linear-gradient(to bottom, transparent 0, transparent 31px, var(--line) 31px, var(--line) 32px);
  background-attachment: local;   /* las líneas se mueven junto con el texto al hacer scroll */
}
#bookText::placeholder { color: var(--muted); opacity: .7; }

/* Botón flotante */
.fab {
  position: fixed;
  right: 22px;
  bottom: calc(var(--safe-bottom) + var(--nav-h) + 20px);
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  display: grid;
  place-items: center;
  box-shadow: 0 8px 22px var(--accent-shadow);
  transition: transform .12s, bottom .25s cubic-bezier(.2, .8, .2, 1);
  z-index: 10;
}
.fab:active { transform: scale(.92); }

/* ============ Inicio: cards por día ============ */
#viewInicio { position: relative; padding: 0; }

.cards {
  position: relative;
  flex: 1; min-height: 0;
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.cards::-webkit-scrollbar { display: none; }

.day-card {
  flex: 0 0 100%;                  /* una card = una pantalla completa */
  scroll-snap-align: center;
  scroll-snap-stop: always;
  display: flex; flex-direction: column;
  background: var(--bg);
  padding: calc(var(--safe-top) + 22px) 5% 20px;     /* los apuntes ocupan el 90% del ancho */
}

/* Flechas laterales */
.cards-arrow {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 5%; min-width: 20px; height: 72px;          /* caben en el margen del 5% */
  display: grid; place-items: center;
  color: var(--muted);
  z-index: 2;
}
.cards-arrow svg { width: 20px; height: 20px; }
.cards-arrow.prev { left: 0; }
.cards-arrow.next { right: 0; }
.cards-arrow:active { color: var(--accent); }

.day-card { position: relative; }

/* Solo "Hoy" lleva color; los días anteriores y posteriores van en grises (siguen siendo editables) */
.day-card:not(.hoy) {
  --accent: #8e949a;
  --accent-shadow: rgba(142, 148, 154, .35);
  --danger: #8e949a;
}
:root[data-tema="oscuro"] .day-card:not(.hoy) {
  --accent: #7a7a7a;
  --accent-shadow: rgba(122, 122, 122, .3);
  --danger: #7a7a7a;
}
.day-title, .day-info { padding-right: 64px; }       /* deja espacio al icono de libreta */

/* Icono de libreta con el número y el mes */
.day-icono {
  position: absolute; top: calc(var(--safe-top) + 18px); right: 5%;
  width: 50px; height: 54px; padding-left: 5px;
  border-radius: 10px 14px 14px 10px;
  background: var(--accent); color: var(--accent-text);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  line-height: 1;
  box-shadow: 0 4px 12px var(--accent-shadow);
  border: 0; cursor: pointer;
  transition: transform .12s;
}
.day-icono:active { transform: scale(.92); }
.day-icono::before {                                  /* argollas de la libreta */
  content: ""; position: absolute; left: -4px; top: 8px; bottom: 8px; width: 10px;
  background: radial-gradient(circle at center, var(--bg) 2.6px, var(--accent) 3px, var(--accent) 4.2px, transparent 4.6px) repeat-y;
  background-size: 10px 14px;
}
.day-icono b { font-size: 23px; font-weight: 800; letter-spacing: -.02em; }
.day-icono small { margin-top: 2px; font-size: 10.5px; font-weight: 700; text-transform: uppercase; }

/* Título de la card de hoy: el saludo (3 s) y "Hoy es …" (5 s) se alternan con efecto de cortinilla */
.saludo-nombre { color: var(--accent); }
.sal-wrap { display: grid; }
.sal { grid-area: 1 / 1; clip-path: inset(-6px 100% -6px 0); }          /* oculto, a la izquierda de la cortina */
.sal.in  { clip-path: inset(-6px 0 -6px 0); animation: cortina-in .6s cubic-bezier(.65, 0, .35, 1) .3s both; }
.sal.out { clip-path: inset(-6px 0 -6px 100%); animation: cortina-out .6s cubic-bezier(.65, 0, .35, 1) both; }
@keyframes cortina-in  { from { clip-path: inset(-6px 100% -6px 0); } to { clip-path: inset(-6px 0 -6px 0); } }
@keyframes cortina-out { from { clip-path: inset(-6px 0 -6px 0); }   to { clip-path: inset(-6px 0 -6px 100%); } }
@media (prefers-reduced-motion: reduce) { .sal { animation: none !important; } }

.day-title { font-size: 22px; font-weight: 800; line-height: 1.2; letter-spacing: -.01em; }
.day-card.hoy .day-title .rel { color: var(--accent); }

.day-body {
  flex: 1; min-height: 0; overflow-y: auto;
  margin-top: 16px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--muted); font-size: 15px; text-align: center;
}

.day-body.con-apuntes { padding-bottom: 90px; }   /* espacio para el botón flotante */
.day-body.con-apuntes {
  justify-content: flex-start; align-items: stretch;
  text-align: left; gap: 0;
}
.apunte-hora { font-size: 12.5px; font-weight: 700; color: var(--accent); }   /* hora en la hoja de opciones */

/* Resumen del día */
.day-info { margin-top: 6px; }
.day-resumen { font-size: 14px; font-weight: 600; color: var(--muted); }
.day-progreso { height: 6px; margin-top: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.day-progreso i {
  display: block; height: 100%; border-radius: 999px;
  background: var(--accent); transition: width .4s ease;
}

/* Línea de tiempo: hora · círculo · texto */
.apunte {
  position: relative; cursor: pointer;
  display: grid; grid-template-columns: 52px 28px minmax(0, 1fr); column-gap: 12px;
  align-items: start;
  padding: 10px 0;
  border-radius: 12px;
}
.apunte:active { background: var(--surface-2); }
.apunte::before {                       /* línea vertical que une los apuntes */
  content: ""; position: absolute; left: 77px; width: 2px; top: 0; bottom: 0;
  background: var(--line);
}
.apunte:first-child::before { top: 24px; }
.apunte:last-child::before { bottom: auto; height: 24px; }
.apunte:first-child:last-child::before { display: none; }

.t-hora { grid-column: 1; text-align: left; padding-top: 3px; line-height: 1.15; }   /* pegada al borde, alineada con el título */
.t-hora b { display: block; font-size: 17px; font-weight: 800; font-variant-numeric: tabular-nums; }
.t-hora small { font-size: 11.5px; font-weight: 600; color: var(--muted); }

.t-nodo {
  grid-column: 2; position: relative; z-index: 1;
  width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid var(--muted); background: var(--bg);
  display: grid; place-items: center;
  color: var(--accent-text);
  transition: background .15s, border-color .15s;
}
.t-nodo::after { content: ""; position: absolute; inset: -10px; }      /* zona de toque más grande */
.t-nodo svg { width: 16px; height: 16px; opacity: 0; }

.t-cuerpo { grid-column: 3; min-width: 0; padding-top: 3px; }
.t-texto { display: block; font-size: 16.5px; font-weight: 600; line-height: 1.35; word-break: break-word; }
.t-etiqueta { display: block; margin-bottom: 1px; font-size: 12px; font-weight: 800; color: var(--accent); }

/* Siguiente / atrasado / cumplido */
.apunte.siguiente .t-nodo { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-shadow); }
.apunte.siguiente .t-hora b { color: var(--accent); }
.apunte.atrasada .t-nodo { border-color: var(--danger); }
.apunte.atrasada .t-etiqueta { color: var(--danger); }

.apunte.cumplida .t-hora, .apunte.cumplida .t-cuerpo { opacity: .5; }
.apunte.cumplida .t-texto { text-decoration: line-through; text-decoration-thickness: 2px; }
.apunte.cumplida .t-nodo { background: var(--accent); border-color: var(--accent); }
.apunte.cumplida .t-nodo svg { opacity: 1; }
.apunte.recien .t-nodo svg { animation: palomita .28s cubic-bezier(.2, .9, .3, 1.4); }
@keyframes palomita { from { transform: scale(.3); opacity: 0; } to { transform: none; opacity: 1; } }

/* Día sin apuntes */
.day-body.vacio { gap: 4px; }
/* Mascota "Nota" (día sin apuntes). Los colores salen del tema, así sirve en claro y oscuro */
.mascota { width: 124px; height: 134px; margin-bottom: 6px; overflow: visible; }
.mascota .m-libro { fill: var(--accent); }
.mascota .m-pie { fill: var(--accent); }
.mascota .m-hoja { fill: var(--surface); }
.mascota .m-anillas circle { fill: var(--surface); stroke: var(--accent); stroke-width: 2; }
.mascota .m-ojo { fill: var(--text); }
.mascota .m-mejilla { fill: #ff8aa0; opacity: .55; }
.mascota .m-boca { fill: none; stroke: var(--text); stroke-width: 2.6; stroke-linecap: round; }
.mascota .m-renglon { fill: none; stroke: var(--accent-text); stroke-width: 2.4; stroke-linecap: round; opacity: .55; }
.mascota .m-brazo { fill: none; stroke: var(--accent); stroke-width: 7; stroke-linecap: round; }
.mascota .m-sombra { fill: var(--text); opacity: .1; transform-box: fill-box; transform-origin: center; }
.mascota .m-ojo, .mascota .m-ojos, .mascota .m-cuerpo { transform-box: fill-box; transform-origin: center; }
.mascota .m-brazo-lapiz { transform-origin: 94px 74px; }

/* Animaciones: solo corren en la card que se está viendo */
.mascota .m-cuerpo, .mascota .m-sombra, .mascota .m-ojo, .mascota .m-ojos, .mascota .m-brazo-lapiz { animation-play-state: paused; }
.day-card.active .mascota .m-cuerpo, .day-card.active .mascota .m-sombra, .day-card.active .mascota .m-ojo,
.day-card.active .mascota .m-ojos, .day-card.active .mascota .m-brazo-lapiz { animation-play-state: running; }
.mascota .m-cuerpo { animation: m-flota 2.6s ease-in-out infinite; }
.mascota .m-sombra { animation: m-sombra 2.6s ease-in-out infinite; }
.mascota .m-ojo { animation: m-parpadeo 4.5s infinite; }
.mascota .m-ojos { animation: m-mira 7s ease-in-out infinite; }
.mascota .m-brazo-lapiz { animation: m-saluda 3.2s ease-in-out infinite; }
@keyframes m-flota { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@keyframes m-sombra { 0%, 100% { transform: scaleX(1); opacity: .1; } 50% { transform: scaleX(.85); opacity: .06; } }
@keyframes m-parpadeo { 0%, 92%, 100% { transform: scaleY(1); } 95% { transform: scaleY(.08); } }
@keyframes m-mira { 0%, 35%, 100% { transform: translateX(0); } 45%, 60% { transform: translateX(3px); } 70%, 85% { transform: translateX(-3px); } }
@keyframes m-saluda {
  0%, 55%, 100% { transform: rotate(0); }
  63% { transform: rotate(-16deg); } 71% { transform: rotate(6deg); }
  79% { transform: rotate(-16deg); } 87% { transform: rotate(0); }
}
/* con la hoja abierta la mascota se queda quieta (menos trabajo mientras deslizas) */
body:has(#sheet:not([hidden])) .mascota * { animation-play-state: paused !important; }
@media (prefers-reduced-motion: reduce) { .mascota * { animation: none !important; } }
.vacio-t { font-size: 18px; font-weight: 800; color: var(--text); }
.vacio-s { font-size: 15px; color: var(--muted); }

/* Opciones del apunte */
.acc-info { padding: 2px 4px 14px; margin-bottom: 6px; border-bottom: 1px solid var(--line); }
.acc-texto { font-size: 18px; font-weight: 700; margin-top: 2px; word-break: break-word; }
.acc-list { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.acc-list.tres .acc-btn:last-child { grid-column: 1 / -1; }   /* con 3 opciones, la última ocupa todo el ancho */
.acc-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  height: 80px; padding: 0 8px; border-radius: 16px;
  background: var(--surface-2);
  font-size: 15px; font-weight: 700; text-align: center;
  transition: transform .1s;
}
.acc-btn svg { width: 26px; height: 26px; color: var(--accent); flex-shrink: 0; }
.acc-btn:active { transform: scale(.96); }
.acc-btn.danger, .acc-btn.danger svg { color: var(--danger); }

/* Editar apunte */
.edit-texto {
  width: 100%; min-height: 110px; resize: none;
  border: 1px solid var(--line); border-radius: 14px;
  background: var(--surface); color: var(--text);
  font: inherit; font-size: 17px; line-height: 1.4;
  padding: 12px 14px; outline: none;
}
.edit-texto:focus { border-color: var(--accent); }
.edit-filas { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.edit-fila {
  display: flex; flex-direction: column; gap: 2px;
  padding: 10px 14px; border-radius: 14px;
  background: var(--surface-2); text-align: left;
}
.edit-fila small { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.edit-fila b { font-size: 16px; font-weight: 700; color: var(--accent); }
#editFecha { text-transform: capitalize; }
.edit-fila:active { transform: scale(.98); }

/* Modal de confirmación */
.confirm {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(15, 22, 18, .55);
  backdrop-filter: blur(2px);
  display: grid; place-items: center;
  padding: 24px 24px calc(24px + var(--kb));
  transition: padding-bottom .25s cubic-bezier(.2, .8, .2, 1);
  animation: fade .2s ease;
}
.confirm-box {
  width: 100%; max-width: 340px;
  background: var(--surface);
  border-radius: 20px;
  padding: 22px 20px 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
  animation: pop .22s cubic-bezier(.2, .8, .2, 1);
}
@keyframes pop { from { opacity: 0; transform: scale(.94); } to { opacity: 1; transform: none; } }
.confirm-box h3 { font-size: 19px; font-weight: 800; line-height: 1.3; }
.confirm-box p { margin-top: 6px; color: var(--muted); font-size: 15px; line-height: 1.45; word-break: break-word; }
.confirm-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 20px; }
.confirm-btns button { height: 46px; border-radius: 999px; font-size: 16px; font-weight: 700; }
#confirmNo { background: var(--surface-2); color: var(--text); }
#confirmSi { background: var(--accent); color: var(--accent-text); }
#confirmSi.danger { background: var(--danger); color: #fff; }
.confirm-btns button:active { transform: scale(.97); }

/* ============ Pantalla de acceso ============ */
#viewAuth {
  height: var(--vvh, 100dvh);           /* sin menú inferior: ocupa toda la pantalla (o lo visible sobre el teclado) */
  overflow-y: auto;
  padding: calc(var(--safe-top) + 32px) 24px calc(var(--safe-bottom) + 28px);
}
.auth-wrap { width: 100%; max-width: 400px; margin: auto; }
.auth-logo {
  width: 68px; height: 68px; margin: 0 auto 18px; border-radius: 20px;
  background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center;
  box-shadow: 0 12px 28px var(--accent-shadow);
}
.auth-logo svg { width: 36px; height: 36px; }
.auth-title { text-align: center; font-size: 28px; font-weight: 800; letter-spacing: -.01em; line-height: 1.2; }
.auth-sub { text-align: center; margin-top: 6px; color: var(--muted); font-size: 15px; }

.auth-tabs {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  margin: 28px 0 20px; padding: 4px; border-radius: 16px;
  background: var(--surface-2);
}
.auth-tabs button {
  height: 44px; border-radius: 12px;
  font-size: 15px; font-weight: 700; color: var(--muted);
  transition: background .15s, color .15s;
}
.auth-tabs button.on { background: var(--accent); color: var(--accent-text); }

.input-wrap { position: relative; }
.field .input-wrap input, .field .input-wrap textarea { width: 100%; padding-left: 46px; padding-right: 50px; }   /* más específico que ".field input" para que respete el espacio del icono */
.input-wrap input::placeholder, .input-wrap textarea::placeholder { color: var(--muted); opacity: .7; }
.input-ico {
  position: absolute; left: 15px; top: 50%; transform: translateY(-50%);
  width: 20px; height: 20px; color: var(--muted); pointer-events: none;
  transition: color .15s;
}
.input-wrap:focus-within .input-ico { color: var(--accent); }
.eye {
  position: absolute; right: 3px; top: 50%; transform: translateY(-50%);
  width: 44px; height: 44px; display: grid; place-items: center;
  border-radius: 50%; color: var(--muted);
}
.eye svg { width: 22px; height: 22px; }
.eye.on { color: var(--accent); }
.eye:active { background: var(--surface-2); }

#viewAuth .auth-msg { text-align: center; }
#viewAuth .save { height: 54px; }
.auth-foot { margin-top: 20px; text-align: center; font-size: 15px; color: var(--muted); }
.link { color: var(--accent); font-weight: 800; padding: 4px 2px; }
.link:active { opacity: .6; }

/* ============ Nombre o apodo ============ */
.nombre-input {
  width: 100%; height: 52px; line-height: 50px; margin-top: 16px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: 14px;
  background: var(--surface); color: var(--text);
  font: inherit; font-size: 18px; font-weight: 600;
  outline: none;
}
.nombre-input:focus { border-color: var(--accent); }
.nombre-input::placeholder { color: var(--muted); font-weight: 400; opacity: .7; }
#nombreModal .auth-msg { margin-top: 6px; }
#nombreModal .confirm-btns { margin-top: 8px; grid-template-columns: 1fr; }
#nombreModal .confirm-btns.dos { grid-template-columns: 1fr 1fr; }
#nombreCancelar { background: var(--surface-2); color: var(--text); }
#nombreGuardar { background: var(--accent); color: var(--accent-text); }
#nombreGuardar:disabled { opacity: .4; pointer-events: none; }

/* ============ Vista Cuenta ============ */
/* Cuenta: scroll si no cabe, formulario y avisos */
.auth { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 13px; font-weight: 700; color: var(--muted); }
.field input, .field textarea.input-oneline {
  height: 50px; line-height: 48px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 14px;
  background: var(--surface); color: var(--text);
  font: inherit; font-size: 17px;           /* 16px+ evita el zoom en iOS */
  outline: none;
}
.field input:focus, .field textarea.input-oneline:focus { border-color: var(--accent); }
.auth-msg { min-height: 20px; font-size: 14px; color: var(--danger); }
.auth-msg.ok { color: var(--muted); }
.auth .save { margin-top: 0; }
.auth-alt {
  width: 100%; height: 52px; margin-top: 10px;
  border-radius: 999px; background: var(--surface-2); color: var(--text);
  font-size: 17px; font-weight: 700;
}
.auth-alt:active { transform: scale(.98); }
.auth-alt:disabled, .save:disabled { opacity: .4; pointer-events: none; }

#bookText.vacio::placeholder { color: var(--danger); opacity: 1; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--safe-bottom) + var(--nav-h) + 24px);
  max-width: calc(100% - 40px);
  padding: 12px 18px; border-radius: 999px;
  background: var(--text); color: var(--bg);
  font-size: 15px; font-weight: 600; text-align: center;
  z-index: 60; animation: fade .2s ease;
}

/* ============ Menú inferior (riel) ============ */
.rail {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
  display: flex;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  z-index: 15;
}
.rail::-webkit-scrollbar { display: none; }

.rail-item {
  flex: 0 0 auto;
  min-width: 92px;
  padding: 0 14px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px;
  position: relative;
  scroll-snap-align: center;
  color: var(--muted);
  font-size: 12px; font-weight: 600;
  transition: color .15s, background .15s;
}
/* centrado cuando caben todas; se alinean a la izquierda cuando hay scroll */
.rail-item:first-child { margin-left: auto; }
.rail-item:last-child { margin-right: auto; }
.rail-item svg { width: 24px; height: 24px; }
.rail-item::before {
  content: ""; position: absolute; top: 0; left: 22%; right: 22%; height: 3px;
  border-radius: 0 0 3px 3px; background: var(--accent);
  transform: scaleX(0); transition: transform .2s;
}
.rail-item.active { color: var(--accent); font-weight: 700; }
.rail-item.active::before { transform: scaleX(1); }
.rail-item:active { background: var(--surface-2); }

/* ============ Hoja inferior ============ */
.backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 22, 18, .55);   /* sin backdrop-filter: el desenfoque re-pintaba toda la pantalla en cada cuadro y causaba el lag */
  z-index: 20;
  animation: fade .2s ease;
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: var(--kb);
  transition: bottom .25s cubic-bezier(.2, .8, .2, 1);
  background: var(--surface);
  border-radius: 24px 24px 0 0;
  padding: 10px 18px calc(var(--safe-bottom) + 22px);
  max-height: min(88dvh, calc(var(--vvh, 100dvh) - 12px));
  overflow-y: auto;
  overscroll-behavior: contain;
  will-change: transform;               /* capa propia en la GPU: el arrastre no repinta */
  z-index: 30;
  box-shadow: 0 -12px 40px rgba(0, 0, 0, .2);
  animation: rise .26s cubic-bezier(.2, .8, .2, 1);
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { transform: translateY(100%); } to { transform: none; } }

/* ---- Elegir por número de días ---- */
.btn-en-dias { margin-top: 12px; height: 48px; }
.dias-field { margin-top: 8px; }
.dias-field input, .dias-field textarea.input-oneline { font-size: 22px; font-weight: 800; text-align: center; height: 60px; line-height: 58px; }
.dias-preview {
  min-height: 30px; margin-top: 14px;
  text-align: center; font-size: 20px; font-weight: 800;
  color: var(--muted); text-transform: capitalize;
}
.dias-preview.lista { color: var(--accent); }
.dias-preview.error { color: var(--danger); font-size: 15px; font-weight: 600; text-transform: none; }

.grab { width: 40px; height: 4px; border-radius: 4px; background: var(--line); margin: 0 auto 12px; }

.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px; gap: 8px;
}
.sheet-head h2 {
  font-size: 18px;
  font-weight: 800;
  text-transform: capitalize;
  text-align: center;
  flex: 1;
}
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%;
  font-size: 28px; line-height: 1; color: var(--text);
  display: grid; place-items: center;
  flex-shrink: 0;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn:disabled { opacity: .25; pointer-events: none; }
.icon-btn.ghost { pointer-events: none; }

/* ---- Selector de mes y año ---- */
.month-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 999px;
  font: inherit; text-transform: capitalize;
}
.month-btn:active { background: var(--surface-2); }
.month-btn svg { width: 16px; height: 16px; color: var(--muted); transition: transform .15s; }
.month-btn[aria-expanded="true"] svg { transform: rotate(180deg); }

.months { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 4px; }
.months button {
  height: 56px; border-radius: 14px;
  background: var(--surface-2);
  font-size: 16px; font-weight: 600; text-transform: capitalize;
  transition: transform .1s;
}
.months button:active { transform: scale(.95); }
.months button.actual { box-shadow: inset 0 0 0 2px var(--accent); }     /* mes en curso */
.months button.on { background: var(--accent); color: var(--accent-text); }  /* mes que se está viendo */
.months button:disabled { opacity: .28; pointer-events: none; }

/* ---- Calendario ---- */
.weekdays, .days { display: grid; grid-template-columns: repeat(7, 1fr); }
.weekdays span {
  text-align: center; font-size: 12px; font-weight: 600;
  color: var(--muted); padding: 6px 0;
}
.days { gap: 4px 0; touch-action: pan-y; user-select: none; -webkit-user-select: none; will-change: transform, opacity; }   /* pan-y: el scroll vertical sigue normal; lo horizontal lo maneja el deslizamiento de meses */
.day {
  height: 46px;
  display: grid; place-items: center;
  position: relative;
}
.day button {
  width: 42px; height: 42px; border-radius: 50%;
  font-size: 16px; font-weight: 500;
  display: grid; place-items: center;
  transition: background .12s, transform .1s;
}
.day button:active { transform: scale(.9); background: var(--surface-2); }
.cal-badge {                         /* globo rojo con la cantidad de pendientes del día */
  position: absolute; top: 0; left: calc(50% + 6px);
  min-width: 17px; height: 17px; padding: 2px 4px 0;   /* 2px arriba: baja el dígito para centrarlo a la vista */
  border-radius: 999px; background: #e5231b; color: #fff;
  display: grid; place-items: center;
  font-size: 10.5px; font-weight: 800; line-height: 1; text-align: center;
  pointer-events: none;
}
.cal-hint { margin-top: 10px; text-align: center; font-size: 13px; color: var(--muted); }
.day.today button { color: var(--accent); font-weight: 800; }   /* el día actual: número azul y en negritas */
.days.buscar .day.today button { background: var(--accent); color: var(--accent-text); border-radius: 10px; }   /* al buscar: hoy en un cuadrado sólido */
.days.buscar .day.sel button { border: 2px solid var(--accent); border-radius: 10px; font-weight: 800; }        /* día de la card donde estás: solo contorno */
.days.buscar .day.today.sel button { border-color: transparent; box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent); }   /* si es hoy: sólido con aro */
.day.anterior button { opacity: .4; }   /* días que ya pasaron: opacos, pero tocables al buscar */
.day.past button {
  opacity: .28;               /* días que ya pasaron, opacados */
  pointer-events: none;
}

/* ---- Hora ---- */
.label {
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: var(--muted); margin: 14px 2px 8px;
}
.grid { display: grid; gap: 8px; }
.time-preview {
  min-height: 30px; margin-bottom: 2px;
  text-align: center; font-size: 22px; font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--muted);                 /* incompleta */
}
.time-preview.lista { color: var(--accent); }   /* hora, minutos y a. m./p. m. ya elegidos */
.time-cols { display: grid; grid-template-columns: 1fr 1fr; }
.time-col:first-child { padding-right: 14px; }
.time-col + .time-col { padding-left: 14px; border-left: 1px solid var(--line); }   /* línea que separa las columnas */
.hours { grid-template-columns: repeat(3, 1fr); }    /* 12 horas: 3 × 4 */
.minutes { grid-template-columns: 1fr; }             /* 4 minutos: uno debajo de otro */
.grid button {
  height: 48px; border-radius: 14px;
  background: var(--surface-2);
  font-size: 17px; font-weight: 600;
  transition: background .12s, transform .1s;
}
.grid button:active { transform: scale(.94); }
.grid button.on { background: var(--accent); color: var(--accent-text); }


.save {
  width: 100%; height: 52px; margin-top: 18px;
  border-radius: 999px;
  background: var(--accent); color: var(--accent-text);
  font-size: 17px; font-weight: 800;
  transition: transform .1s, opacity .15s;
}
.save:active { transform: scale(.98); }
.save:disabled { opacity: .4; pointer-events: none; }

@media (max-height: 640px) {
  .day { height: 40px; }
  .day button { width: 38px; height: 38px; }
}

/* ============ Teclado abierto ============ */
/* body.kb lo pone app.js cuando el teclado en pantalla está visible */
.rail { transition: transform .25s cubic-bezier(.2, .8, .2, 1); }
body.kb .rail { transform: translateY(100%); }                 /* el menú inferior se esconde mientras se escribe */
body.kb .view { height: var(--vvh, 100dvh); }                  /* la vista solo ocupa lo que queda sobre el teclado */
body.kb #viewBook .fab { bottom: calc(var(--kb) + 16px); }     /* el botón "+" queda justo encima del teclado */
body.kb .toast { bottom: calc(var(--kb) + 16px); }
body.kb .sheet { padding-bottom: 18px; }                       /* ya no hay barra de gestos debajo */

/* Aviso de actualización: por encima de todo, con un solo botón */
#updateModal { z-index: 100; }
#updateModal .confirm-btns { grid-template-columns: 1fr; }
#updateBtn { background: var(--accent); color: var(--accent-text); }
#updateBtn:disabled { opacity: .6; pointer-events: none; }

/* Campos de una sola línea hechos con <textarea> (así el teclado no muestra la barra de autollenado) */
textarea.input-oneline { display: block; resize: none; overflow: hidden; white-space: nowrap; scrollbar-width: none; }

/* Contraseña en un <textarea>: se muestra con puntos igual que un input password */
textarea.pass-mask { -webkit-text-security: disc; text-security: disc; }
textarea.pass-mask.visible { -webkit-text-security: none; text-security: none; }

/* Ajuste de los <textarea> de una línea: el "font: inherit" de arriba reiniciaba la altura de línea
   y la regla general del campo pisaba el espacio para el icono */
.field textarea.input-oneline { line-height: 48px; }
.field .input-wrap textarea.input-oneline { padding-left: 46px; padding-right: 50px; }
.dias-field textarea.input-oneline { line-height: 58px; }
.nombre-input.input-oneline { line-height: 50px; }

/* Cada apunte parece una tira de libreta: líneas rectas arriba y abajo
   y argollas a la izquierda (se dibujan con máscaras SVG, así toman el color del tema) */
.day-body.con-apuntes { margin-inline: -5.5556%; padding-inline: 5.5556%; }   /* deja que el efecto llegue a los bordes de la card */
.apunte + .apunte { margin-top: 4px; }
.apunte::after {
  content: ""; position: absolute; top: 0; bottom: 0; left: -5.5556%; right: -5.5556%;
  background: color-mix(in srgb, var(--muted) 14%, transparent);
  pointer-events: none;
  -webkit-mask: linear-gradient(#000, #000) 0 0 / 100% 1.5px no-repeat, linear-gradient(#000, #000) 0 100% / 100% 1.5px no-repeat, url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 16 22%22%3E%3Cpath d=%22M14 2.5 C2 0.5 0.5 9 9 10.6 C0.5 12.4 2 21.5 14 19.5%22 fill=%22none%22 stroke=%22%23000%22 stroke-width=%221.5%22 stroke-linecap=%22round%22/%3E%3C/svg%3E") 0 0 / 16px 22px no-repeat round;
          mask: linear-gradient(#000, #000) 0 0 / 100% 1.5px no-repeat, linear-gradient(#000, #000) 0 100% / 100% 1.5px no-repeat, url("data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 16 22%22%3E%3Cpath d=%22M14 2.5 C2 0.5 0.5 9 9 10.6 C0.5 12.4 2 21.5 14 19.5%22 fill=%22none%22 stroke=%22%23000%22 stroke-width=%221.5%22 stroke-linecap=%22round%22/%3E%3C/svg%3E") 0 0 / 16px 22px no-repeat round;
}

/* Botón "Guardar" de la vista Notas: alargado en lugar del círculo con "+" */
.fab.fab-guardar {
  width: auto; height: 52px; padding: 0 30px;
  border-radius: 999px;
  font-size: 17px; font-weight: 800; letter-spacing: .01em;
}

/* Modal a. m. / p. m. */
#ampmModal { z-index: 60; }
#ampmOpts button { height: 52px; font-size: 18px; background: var(--surface-2); color: var(--text); }
#ampmOpts button.on { background: var(--accent); color: var(--accent-text); }
#ampmTitulo { font-weight: 400; font-size: 17px; color: var(--muted); }   /* texto suave, sin negritas */

/* Switch a. m. / p. m. junto a la hora */
.time-head { position: relative; display: flex; justify-content: center; align-items: center; }
.time-head .time-preview { margin: 0; }
.ampm-switch {
  position: absolute; right: 0; top: 50%; transform: translateY(-50%);
  width: 72px; height: 34px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--line);
  transition: background .2s, border-color .2s;
}
.ampm-switch .sw-knob {
  position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .3);
  transition: left .2s cubic-bezier(.3, .8, .3, 1);
}
.ampm-switch .sw-txt {
  position: absolute; top: 0; bottom: 0; right: 10px; display: grid; place-items: center;
  font-size: 13px; font-weight: 700; color: var(--muted); letter-spacing: .02em;
}
.ampm-switch.on { background: var(--accent); border-color: var(--accent); }
.ampm-switch.on .sw-knob { left: 41px; }
.ampm-switch.on .sw-txt { right: auto; left: 12px; color: var(--accent-text); }

.ampm-switch[data-ap="am"] .sw-knob { background: var(--accent); box-shadow: 0 1px 4px var(--accent-shadow); }   /* en a. m. la perilla va azul */

/* ============ Cuenta (estilo perfil) ============ */
:root { --portada-a: #1da1f2; --portada-b: #0b5fa5; --page: #f0f2f5; }
:root[data-tema="oscuro"] { --portada-a: #3a3a3a; --portada-b: #121212; --page: #0a0a0a; }

#viewCuenta {
  padding: 0 0 24px;
  background: var(--page);
  overflow-y: auto;
  gap: 8px;
}
.cuenta-portada {
  flex-shrink: 0;
  height: calc(var(--safe-top) + 150px);
  padding: calc(var(--safe-top) + 14px) 16px 0;
  background: linear-gradient(135deg, var(--portada-a), var(--portada-b));
  color: #fff;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
}
.cuenta-portada h1 { font-size: 20px; font-weight: 800; line-height: 36px; }
.portada-salir {
  height: 36px; padding: 0 14px;
  display: flex; align-items: center; gap: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .2);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  color: #fff; font-size: 14px; font-weight: 700;
}
.portada-salir svg { width: 18px; height: 18px; }
.portada-salir:active { background: rgba(255, 255, 255, .32); transform: scale(.97); }

.perfil {
  position: relative;
  flex-shrink: 0;
  display: flex; flex-direction: column; align-items: center;
  background: var(--surface);
  padding: 0 16px 8px;
  text-align: center;
}
.perfil-avatar {
  width: 104px; height: 104px; border-radius: 50%;
  margin-top: -52px;
  border: 4px solid var(--surface);
  background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center;
  font-size: 44px; font-weight: 800; line-height: 1;
}
.perfil-nombre {
  margin-top: 10px; font-size: 26px; font-weight: 800;
  letter-spacing: -.01em; line-height: 1.2; word-break: break-word;
}
.perfil-correo { color: var(--muted); font-size: 15px; word-break: break-all; }

.perfil-stats {
  width: 100%; margin-top: 16px; padding: 12px 0;
  display: grid; grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.perfil-stats > * + * { border-left: 1px solid var(--line); }
.perfil-stats b { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.perfil-stats span { font-size: 13px; color: var(--muted); }

.perfil-nombre-fila {
  margin-top: 10px; max-width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.perfil-nombre-fila .perfil-nombre { margin-top: 0; min-width: 0; }
.perfil-lapiz {
  width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
  display: grid; place-items: center;
  background: var(--surface-2); color: var(--text);
}
.perfil-lapiz svg { width: 18px; height: 18px; }
.perfil-lapiz:active { transform: scale(.92); }
.perfil-lapiz:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Interruptor claro / oscuro */
.tema-switch {
  position: absolute; top: 12px; right: 16px;
  width: 68px; height: 36px; border-radius: 999px;
  background: #eceff3;
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, .14), inset 0 -1px 0 #fff;
  transition: background .25s;
}
.tema-switch:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.ts-knob {
  position: absolute; top: 4px; left: 4px;
  width: 28px; height: 28px; border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .22);
  transition: transform .25s cubic-bezier(.4, 0, .2, 1), background .25s;
}
.tema-switch svg {
  position: absolute; top: 50%; width: 20px; height: 20px; margin-top: -10px;
  color: #9aa0a8; transition: opacity .2s;
}
.ts-sun { right: 8px; }
.ts-moon { left: 8px; opacity: 0; }

.tema-switch[aria-checked="true"] {
  background: #050505;
  box-shadow: inset 0 3px 7px rgba(0, 0, 0, .9), 0 0 0 1px var(--line);
}
.tema-switch[aria-checked="true"] .ts-knob { transform: translateX(32px); background: #3b3b3b; box-shadow: 0 2px 6px rgba(0, 0, 0, .6); }
.tema-switch[aria-checked="true"] .ts-sun { opacity: 0; }
.tema-switch[aria-checked="true"] .ts-moon { opacity: 1; }
@media (prefers-reduced-motion: reduce) {
  .ts-knob, .tema-switch, .tema-switch svg { transition: none; }
}

/* "Pendientes" tocable en el resumen del perfil */
.perfil-stats .stat-btn {
  display: flex; flex-direction: column; align-items: center;
  border-radius: 10px; color: inherit; text-align: center;
}
.perfil-stats .stat-btn:active { background: var(--surface-2); }
.perfil-stats .stat-btn span::after { content: " \203A"; }

/* Lista de pendientes */
.pend-bloque { margin-top: 18px; }
.pend-bloque:first-child { margin-top: 6px; }
.pend-dia {
  display: flex; align-items: center; gap: 10px;
  margin: 0 0 4px;
  font-size: 14px; font-weight: 800; color: var(--text);
}
.pend-dia span {
  flex-shrink: 0; max-width: 100%;
  padding: 4px 12px; border: 1.5px solid currentColor; border-radius: 999px;
  line-height: 1.2;
}
.pend-dia::after {                       /* línea que continúa hasta el borde */
  content: ""; flex: 1; min-width: 8px; height: 1.5px; background: var(--line);
}
.pend-dia.atrasada { color: var(--danger); }
.pend-item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 10px 4px; border-radius: 12px; cursor: pointer;
}
.pend-item:active { background: var(--surface-2); }
.pend-nodo {
  position: relative; flex-shrink: 0; margin-top: 1px;
  width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid var(--muted);
  display: grid; place-items: center;
  color: var(--accent-text);
  transition: background .15s, border-color .15s;
}
.pend-nodo::after { content: ""; position: absolute; inset: -10px; }
.pend-nodo svg { width: 16px; height: 16px; opacity: 0; }
.pend-item.hecho .pend-nodo { background: var(--accent); border-color: var(--accent); }
.pend-item.hecho .pend-nodo svg { opacity: 1; }
.pend-item.hecho .pend-txt { opacity: .5; text-decoration: line-through; }
.pend-txt { min-width: 0; transition: opacity .15s; }
.pend-txt p { font-size: 16px; font-weight: 400; line-height: 1.3; word-break: break-word; }
.pend-txt small { font-size: 13px; color: var(--muted); }
.pend-vacio { padding: 28px 0 12px; text-align: center; color: var(--muted); font-size: 15px; }

/* Hoja de listas (Pendientes / Concluidos / Total): siempre abre a la altura completa */
#pendSheet {
  height: min(88dvh, calc(var(--vvh, 100dvh) - 12px));
  display: flex; flex-direction: column;
  overflow: hidden;                      /* el título queda fijo y solo la lista se desplaza */
}
#pendSheet .grab, #pendSheet .sheet-head { flex-shrink: 0; }
#pendSheet .pend-lista {
  flex: 1; min-height: 0;
  overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column;
}
#pendSheet .pend-vacio { margin: auto 0; padding: 0 0 40px; }   /* mensaje vacío centrado en la hoja */
#pendSheet .pend-bloque { flex-shrink: 0; }

/* Modo oscuro: el encabezado de Notas va en negro con letras blancas */
:root[data-tema="oscuro"] #viewBook .book-head { background: #000; color: #fff; }
:root[data-tema="oscuro"] #viewBook .book-head h1,
:root[data-tema="oscuro"] #viewBook .book-head p { color: #fff; }