/* App de la abuela.
   VOZ      cotidiana y tierna: pocos colores, mucho aire, letra muy grande.
   IDEA     la hoja del calendario de la cocina + una conversación de sobremesa.
   PICTURE  la hoja de calendario (día, hora y tiempo) y el gran botón para hablar.
   COLOUR   papel crema, verde botella dominante, teja para "te escucho", mostaza del tiempo.
   TYPE     Fraunces para el día de la semana; Atkinson Hyperlegible (hecha para baja visión).
   LAYOUT   una sola pantalla: hoja arriba, conversación en medio, "Hoy" y botón abajo. */
:root {
  --papel: #fbf4e9;
  --tarjeta: #fffdf8;
  --tinta: #1f2a24;
  --suave: #5c6158;
  --verde: #1f4d3d;
  --verde-claro: #2f6b55;
  --verde-fondo: #e3eee6;
  --teja: #c8553d;
  --teja-fondo: #f8e1d8;
  --mostaza: #e0a526;
  --linea: #e6dccb;
  --sombra: 0 1px 2px rgba(60, 40, 10, .06), 0 8px 24px rgba(60, 40, 10, .08);
  --tipo: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --titular: "Fraunces", Georgia, "Times New Roman", serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --papel: #15191a;
    --tarjeta: #1f2523;
    --tinta: #f4efe6;
    --suave: #b9b8ae;
    --verde: #1f4d3d;
    --verde-claro: #6fbf9a;
    --verde-fondo: #20352c;
    --teja: #ec7a60;
    --teja-fondo: #3a2520;
    --mostaza: #f0bd4f;
    --linea: #343b38;
    --sombra: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--papel);
  color: var(--tinta);
  font-family: var(--tipo);
  font-size: 20px;
  line-height: 1.35;
  display: flex;
  flex-direction: column;
  max-width: 620px;
  margin: 0 auto;
  padding: env(safe-area-inset-top, 0) max(16px, env(safe-area-inset-right, 0))
           env(safe-area-inset-bottom, 0) max(16px, env(safe-area-inset-left, 0));
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  overflow: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- Hoja de calendario ---------- */
#hoja {
  position: relative;
  margin-top: 14px;
  background: var(--verde);
  color: #fbf4e9;
  border-radius: 22px;
  box-shadow: var(--sombra);
  flex: none;
}
.anillas {
  position: absolute; top: -7px; left: 0; right: 0;
  display: flex; justify-content: center; gap: 70px;
}
.anillas i {
  width: 12px; height: 18px; border-radius: 6px;
  background: var(--papel); border: 3px solid #0f2d23;
}
.hoja-cuerpo {
  display: flex; align-items: stretch; justify-content: space-between; gap: 12px;
  padding: 20px 20px 16px;
}
.hoja-fecha { display: flex; flex-direction: column; min-width: 0; }
#dia-semana {
  font-family: var(--titular); font-weight: 700;
  font-size: clamp(40px, 12vw, 58px); line-height: 1; letter-spacing: -.02em;
}
.hoja-num { font-size: 24px; margin-top: 6px; opacity: .92; }
.hoja-num b { font-size: 30px; }
.hoja-lado {
  display: flex; flex-direction: column; align-items: flex-end; justify-content: space-between;
  text-align: right; flex: none;
}
#reloj {
  font-size: clamp(34px, 10vw, 44px); font-weight: 700; line-height: 1;
  font-variant-numeric: tabular-nums; letter-spacing: -.01em;
}
#tiempo { display: flex; align-items: center; gap: 6px; font-size: 19px; margin-top: 6px; }
#tiempo b { font-size: 24px; }
#tiempo-icono svg { width: 34px; height: 34px; display: block; }
#momento { font-size: 17px; opacity: .8; margin-top: 2px; }

/* Durante la charla diaria la hoja se sustituye por una banda neutra. */
#banda-test {
  margin-top: 14px; padding: 14px 18px; border-radius: 18px;
  background: var(--verde-fondo); color: var(--verde-claro);
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  font-weight: 700; font-size: 20px; flex: none;
}
#progreso { display: flex; gap: 6px; }
#progreso i { width: 11px; height: 11px; border-radius: 50%; background: currentColor; opacity: .25; }
#progreso i.hecho { opacity: 1; }

#estado {
  margin-top: 10px; padding: 8px 14px; border-radius: 12px; text-align: center;
  background: var(--teja-fondo); color: var(--tinta); font-size: 17px; flex: none;
}

/* ---------- Conversación ---------- */
#conversacion {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column; justify-content: center; gap: 12px;
  padding: 14px 0 10px;
}
#tu {
  align-self: flex-end; max-width: 85%; margin: 0;
  background: var(--verde-fondo); color: var(--tinta);
  padding: 10px 16px; border-radius: 20px 20px 6px 20px;
  font-size: 19px; overflow: hidden; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
#burbuja {
  position: relative;
  background: var(--tarjeta);
  border: 1px solid var(--linea);
  border-radius: 28px 28px 28px 8px;
  box-shadow: var(--sombra);
  padding: 22px 24px;
  min-height: 0; overflow-y: auto; scrollbar-width: thin;
  -webkit-user-select: text; user-select: text;
}
#texto {
  margin: 0;
  font-size: clamp(27px, 7.2vw, 36px);
  line-height: 1.3;
  text-wrap: pretty;
}
#texto.largo { font-size: clamp(23px, 6vw, 30px); }
#texto.entra { animation: entra .35s ease-out; }
@keyframes entra { from { opacity: 0; transform: translateY(6px); } }
body.alerta #burbuja { border-color: var(--teja); background: var(--teja-fondo); }

#pensando { display: flex; gap: 8px; padding: 10px 0 2px; }
#pensando i {
  width: 14px; height: 14px; border-radius: 50%; background: var(--verde-claro);
  animation: salto 1.1s infinite ease-in-out;
}
#pensando i:nth-child(2) { animation-delay: .15s; }
#pensando i:nth-child(3) { animation-delay: .3s; }
@keyframes salto { 0%, 70%, 100% { transform: translateY(0); opacity: .35; } 35% { transform: translateY(-8px); opacity: 1; } }

#aviso-familia {
  align-self: flex-start; display: flex; align-items: center; gap: 8px;
  background: var(--teja); color: #fff; font-weight: 700; font-size: 18px;
  padding: 8px 16px; border-radius: 999px;
}
#aviso-familia svg { width: 20px; height: 20px; fill: currentColor; }

/* ---------- Caras del ánimo ---------- */
#caras { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; padding-bottom: 12px; flex: none; }
#caras button {
  border: 2px solid var(--linea); background: var(--tarjeta); border-radius: 20px;
  padding: 8px 2px 6px; display: flex; flex-direction: column; align-items: center; gap: 4px;
  box-shadow: var(--sombra);
}
#caras button:active { transform: scale(.96); }
#caras svg { width: 100%; max-width: 64px; height: auto; }
#caras span { font-size: 15px; color: var(--suave); line-height: 1.1; text-align: center; }

/* ---------- Cuenta atrás (fluidez) ---------- */
#cuenta { position: relative; display: grid; place-items: center; padding-bottom: 8px; flex: none; }
#cuenta svg { width: 150px; height: 150px; transform: rotate(-90deg); }
#cuenta circle { fill: none; stroke-width: 10; }
#cuenta .pista { stroke: var(--linea); }
#cuenta .arco { stroke: var(--teja); stroke-linecap: round; stroke-dasharray: 326.7; transition: stroke-dashoffset 1s linear; }
#cuenta-num {
  position: absolute; top: 0; height: 150px; display: grid; place-items: center;
  font-size: 54px; font-weight: 700; color: var(--teja); font-variant-numeric: tabular-nums;
}
#cuenta small { font-size: 17px; color: var(--suave); text-align: center; }

/* ---------- Hoy ---------- */
#hoy { flex: none; padding-bottom: 4px; }
#hoy h2 { font-size: 16px; font-weight: 700; color: var(--suave); margin: 0 0 6px 4px; }
#hoy-lista {
  list-style: none; margin: 0; padding: 2px 2px 8px;
  display: flex; gap: 10px; overflow-x: auto; scroll-snap-type: x proximity;
  scrollbar-width: none;
}
#hoy-lista::-webkit-scrollbar { display: none; }
#hoy-lista li {
  flex: none; scroll-snap-align: start;
  display: flex; align-items: center; gap: 10px;
  background: var(--tarjeta); border: 1px solid var(--linea); border-radius: 16px;
  padding: 10px 14px; max-width: 78vw;
}
#hoy-lista li.siguiente { border: 2px solid var(--verde-claro); }
#hoy-lista li.hecho { opacity: .55; }
#hoy-lista .ic { width: 30px; height: 30px; flex: none; }
#hoy-lista .hora { font-weight: 700; font-size: 20px; font-variant-numeric: tabular-nums; }
#hoy-lista .tit { font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#hoy-lista .ok { color: var(--verde-claro); font-weight: 700; }
#hoy-lista li.vacio { color: var(--suave); }

/* ---------- Botón de hablar ---------- */
#mandos {
  flex: none; position: relative;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 8px 0 18px;
}
#hablar {
  grid-column: 2; position: relative;
  width: 132px; height: 132px; border-radius: 50%; border: none;
  background: var(--verde); color: #fbf4e9;
  display: grid; place-items: center;
  box-shadow: 0 10px 26px rgba(31, 77, 61, .35), inset 0 -4px 0 rgba(0, 0, 0, .18);
  transition: background .2s, transform .1s;
}
#hablar:active { transform: scale(.96); }
.micro { width: 58px; height: 58px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; position: relative; }
.micro rect { fill: currentColor; stroke: none; }
.ondas, .ondas i { position: absolute; inset: 0; border-radius: 50%; }
.ondas i { border: 3px solid var(--teja); opacity: 0; }
body[data-fase="escuchando"] #hablar { background: var(--teja); box-shadow: 0 10px 26px rgba(200, 85, 61, .4); }
body[data-fase="escuchando"] .ondas i { animation: onda 1.8s infinite ease-out; }
body[data-fase="escuchando"] .ondas i:nth-child(2) { animation-delay: .9s; }
@keyframes onda { from { transform: scale(1); opacity: .7; } to { transform: scale(1.55); opacity: 0; } }
body[data-fase="pensando"] #hablar { opacity: .6; }
#hablar-txt {
  grid-column: 1 / -1; text-align: center; margin-top: 10px;
  font-size: 21px; font-weight: 700; color: var(--verde-claro);
}
body[data-fase="escuchando"] #hablar-txt { color: var(--teja); }
.redondo {
  grid-column: 1; justify-self: start;
  width: 58px; height: 58px; border-radius: 50%;
  border: 1px solid var(--linea); background: var(--tarjeta); color: var(--suave);
  display: grid; place-items: center;
}
.redondo svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }

/* ---------- Recordatorio de medicación ---------- */
#toma {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(20, 30, 25, .45);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 16px max(16px, env(safe-area-inset-right, 0)) calc(20px + env(safe-area-inset-bottom, 0)) max(16px, env(safe-area-inset-left, 0));
  animation: aparece .25s ease-out;
}
@keyframes aparece { from { opacity: 0; } }
.toma-tarjeta {
  width: 100%; max-width: 560px;
  background: var(--tarjeta); border-radius: 28px; padding: 26px 22px 22px;
  box-shadow: var(--sombra); display: flex; flex-direction: column; gap: 14px; align-items: center;
  animation: sube .3s ease-out;
}
@keyframes sube { from { transform: translateY(40px); } }
.pastilla { width: 110px; height: 55px; }
.pastilla .p-a { fill: var(--teja-fondo); stroke: var(--teja); stroke-width: 2.5; }
.pastilla .p-b { fill: var(--teja); }
.pastilla .brillo { fill: #fff; opacity: .7; }
#toma-texto { margin: 0; font-size: 30px; line-height: 1.25; text-align: center; font-weight: 700; }
.boton {
  width: 100%; min-height: 78px; border-radius: 22px; border: none;
  font-size: 25px; font-weight: 700;
}
.boton.si { background: var(--verde); color: #fbf4e9; }
.boton.no { background: transparent; border: 2px solid var(--linea); color: var(--tinta); min-height: 64px; }

/* ---------- Teclado ---------- */
#teclado {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 11;
  background: var(--tarjeta); border-top: 1px solid var(--linea);
  box-shadow: 0 -8px 24px rgba(0, 0, 0, .12);
  padding: 16px max(16px, env(safe-area-inset-right, 0)) calc(16px + env(safe-area-inset-bottom, 0)) max(16px, env(safe-area-inset-left, 0));
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
#entrada {
  grid-column: 1 / -1; font: inherit; font-size: 24px;
  padding: 14px 16px; border-radius: 16px; border: 2px solid var(--linea);
  background: var(--papel); color: var(--tinta);
  -webkit-user-select: text; user-select: text;
}
#teclado .boton { min-height: 62px; font-size: 22px; }

/* Durante el test: sin hoja ni "Hoy" (son respuestas de orientación). */
body.en-test #hoja, body.en-test #hoy { display: none; }

/* Pantallas bajas: compactar. */
@media (max-height: 700px) {
  .hoja-cuerpo { padding: 16px 16px 12px; }
  #dia-semana { font-size: 40px; }
  #hablar { width: 112px; height: 112px; }
  #mandos { padding-bottom: 10px; }
  #hablar-txt { margin-top: 6px; font-size: 19px; }
  #hoy h2 { display: none; }
  #texto { font-size: clamp(24px, 6.4vw, 32px); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
