/* ==========================================================================
   Calendario de Frases - hoja de estilos unica

   Los colores y las tipografias entran como variables desde el servidor
   (Appearance::styleBlock). Lo que hay aqui son solo los valores de respaldo,
   por si el bloque de tema no llegara a cargar.
   ========================================================================== */

:root {
  --paper: #F6F1E2;
  --ink: #2B241D;
  --ink-soft: #6B6154;
  --accent: #A5312B;
  --brass: #9C8552;
  --bg-1: #332B22;
  --bg-2: #241E17;
  --app-background: linear-gradient(180deg, #332B22, #241E17);
  --on-bg: #F2EEE6;

  --font-display: 'Fraunces', Georgia, serif;
  --font-label: 'IBM Plex Mono', ui-monospace, monospace;
  --font-phrase: 'Fraunces', Georgia, serif;
  --font-ui: 'Work Sans', system-ui, -apple-system, sans-serif;

  --wa: #25D366;
  --wa-dark: #20BD5A;
  --tg: #229ED9;
  --tg-dark: #1B87BA;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-ui);
  color: var(--on-bg);
  background: var(--app-background) fixed;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

/* ------------------------------------------------------------------ Header */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 20px;
  border-bottom: 1px solid color-mix(in srgb, var(--brass) 35%, transparent);
}

.topbar__brand {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 17px;
  margin: 0;
}

.topbar__brand span {
  display: block;
  font-family: var(--font-label);
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
  opacity: .65;
  font-weight: 400;
  margin-top: 2px;
}

.topbar__nav { display: flex; align-items: center; gap: 8px; font-size: 13px; flex-wrap: wrap; }

.topbar__user {
  font-family: var(--font-label);
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  opacity: .65;
  margin-right: 4px;
}

/* ------------------------------------------------------------------ Avisos */

.banner {
  margin: 14px auto 0;
  max-width: 620px;
  width: calc(100% - 32px);
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 55%, transparent);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.45;
}

.banner a { font-weight: 600; }

/* -------------------------------------------------------------- Calendario */

.stage { display: flex; flex-direction: column; align-items: center; padding: 30px 16px 48px; }

.cal-perspective { perspective: 1600px; position: relative; width: 280px; }

.cal-rings {
  position: absolute;
  top: -11px; left: 0; right: 0;
  display: flex;
  justify-content: space-evenly;
  z-index: 5;
  padding: 0 28px;
}

.cal-ring {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--bg-2);
  border: 2px solid var(--brass);
  box-shadow: inset 0 0 0 3px var(--paper);
}

body.no-rings .cal-rings { display: none; }

.cal-stack { position: relative; }

.cal-stack::before,
.cal-stack::after {
  content: "";
  position: absolute;
  left: 6px; right: 6px;
  background: color-mix(in srgb, var(--paper) 88%, #000);
  border-radius: 4px;
}

.cal-stack::before { bottom: -6px; height: 100%; transform: scale(.97); opacity: .8; }
.cal-stack::after { bottom: -11px; height: 100%; transform: scale(.94); opacity: .55; }

body.no-stack .cal-stack::before,
body.no-stack .cal-stack::after { display: none; }

/* El z-index importa: .cal-stack::after es un pseudoelemento del padre y, por
   orden de pintado, va por encima de los hijos. Sin esto, la sombra del taco
   queda como un velo translucido sobre la hoja y apaga texto y colores. */
.cal-flipwrap {
  position: relative;
  z-index: 1;
  width: 280px;
  height: 340px;
  transform-style: preserve-3d;
}

.cal-page {
  position: absolute;
  inset: 0;
  background: var(--paper);
  border-radius: 4px;
  box-shadow: 0 18px 30px rgba(0, 0, 0, .35);
  backface-visibility: hidden;
  transform-origin: top center;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 26px 20px 20px;
  text-align: center;
  color: var(--ink);
}

.cal-page.top { z-index: 3; }
.cal-page.bottom { z-index: 2; }

.cal-page.top::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 4px;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(0, 0, 0, .55), rgba(0, 0, 0, 0) 55%);
  opacity: 0;
}

.cal-weekday {
  font-family: var(--font-label);
  font-size: 12px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.cal-day {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 96px;
  line-height: 1;
  color: var(--accent);
  margin: 2px 0 0;
}

.cal-monthyear {
  font-family: var(--font-label);
  font-size: 12px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 10px;
}

.cal-rule { width: 44px; height: 2px; background: var(--brass); border: none; margin: 6px 0 14px; }

.cal-phrase {
  font-family: var(--font-phrase);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  max-height: 150px;
  overflow: hidden;
  padding: 0 4px;
  white-space: pre-line;
}

body.font-clasico .cal-phrase { font-style: italic; }

/* ================================================================ Animaciones

   Dos cosas distintas se mueven, y conviene no mezclarlas:

   - El volteo de hoja es siempre el mismo y no se configura: ocurre al cambiar
     de dia.
   - La animacion de la frase si se elige, y es la que se graba en el GIF. De
     esa hay una version aqui, para la pantalla, y otra en
     assets/js/animations.js, para el lienzo. Si cambias una, cambia la otra.
   ========================================================================== */

@keyframes animFlip {
  from { transform: rotateX(0deg); }
  to   { transform: rotateX(-180deg); }
}

@keyframes animShade {
  0%        { opacity: 0; }
  42%, 58%  { opacity: 1; }
  100%      { opacity: 0; }
}

.cal-flipwrap.is-flipping .cal-page.top {
  animation: animFlip .9s cubic-bezier(.62, .04, .32, 1) forwards;
}

.cal-flipwrap.is-flipping .cal-page.top::after {
  animation: animShade .9s cubic-bezier(.62, .04, .32, 1);
}

/* --- Como entra la frase ------------------------------------------------- */

@keyframes phraseFade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes phraseRise {
  from { opacity: 0; transform: translateY(26px); }
  to   { opacity: 1; transform: none; }
}

@keyframes phraseZoom {
  from { opacity: 0; transform: scale(.86); }
  to   { opacity: 1; transform: scale(1); }
}

.cal-phrase.phrase-fade { animation: phraseFade 1.2s ease forwards; }
.cal-phrase.phrase-rise { animation: phraseRise 1.2s cubic-bezier(.22, .7, .3, 1) forwards; }
.cal-phrase.phrase-zoom { animation: phraseZoom 1.2s cubic-bezier(.22, .7, .3, 1) forwards; }

/* Palabra por palabra y linea por linea: cada trozo entra por su cuenta. */
.cal-phrase .w {
  display: inline-block;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity .34s ease, transform .34s cubic-bezier(.22, .7, .3, 1);
}

.cal-phrase .w.is-in { opacity: 1; transform: none; }

@keyframes caretBlink { 50% { opacity: 0; } }

.cal-phrase.is-typing::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--accent);
  vertical-align: -.15em;
  margin-left: 2px;
  animation: caretBlink .7s steps(1, end) infinite;
}

/* --- Hoja sin fecha ------------------------------------------------------ */

body.no-date .cal-weekday,
body.no-date .cal-day,
body.no-date .cal-monthyear { display: none; }

body.no-date .cal-page { justify-content: center; }
body.no-date .cal-rule { margin: 0 0 20px; }

body.no-date .cal-phrase {
  font-size: 22px;
  line-height: 1.45;
  max-height: 236px;
}

/* ------------------------------------------------------------------ Botones */

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 28px;
  max-width: 360px;
}

.btn {
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  border-radius: 20px;
  padding: 9px 15px;
  cursor: pointer;
  border: 1px solid var(--brass);
  background: transparent;
  color: var(--on-bg);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background .15s, opacity .15s;
}

.btn:hover:not(:disabled) { background: rgba(255, 255, 255, .08); }
.btn:disabled { opacity: .5; cursor: progress; }

.btn--wa { background: var(--wa); border-color: var(--wa); color: #0B3B21; font-weight: 600; }
.btn--wa:hover:not(:disabled) { background: var(--wa-dark); }

.btn--tg { background: var(--tg); border-color: var(--tg); color: #04283A; font-weight: 600; }
.btn--tg:hover:not(:disabled) { background: var(--tg-dark); }

/* Accion destacada. Toma sus colores de --on-bg, que ya viene calculado para
   contrastar con el fondo: sirva el tema que sirva, siempre se lee. */
.btn--primary {
  background: var(--on-bg);
  border-color: var(--on-bg);
  color: var(--bg-1);
  font-weight: 600;
}

.btn--primary:hover:not(:disabled) { background: var(--on-bg); filter: brightness(.92); }

.btn--ghost { border-color: color-mix(in srgb, var(--brass) 55%, transparent); font-size: 12px; padding: 7px 12px; }

.note {
  font-family: var(--font-label);
  font-size: 11px;
  opacity: .7;
  margin-top: 16px;
  letter-spacing: .04em;
  text-align: center;
}

.toast { text-align: center; font-size: 12.5px; opacity: .85; margin-top: 10px; min-height: 18px; padding: 0 16px; }
.toast--error { color: #F0B3AE; opacity: 1; }

/* ----------------------------------------------------------------- Paneles */

.sheet {
  display: none;
  margin-top: 26px;
  width: 100%;
  max-width: 460px;
  background: var(--paper);
  border-radius: var(--radius);
  padding: 20px 20px 16px;
  color: var(--ink);
  box-shadow: 0 20px 40px rgba(0, 0, 0, .35);
}

.sheet.is-open { display: block; }

.sheet h2 { font-family: var(--font-display); font-size: 19px; font-weight: 600; margin: 0 0 4px; }
.sheet .hint { font-size: 13px; color: var(--ink-soft); margin: 0 0 14px; line-height: 1.45; }

.field { margin-bottom: 10px; }

.field label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-soft);
  margin-bottom: 4px;
}

.input,
.textarea,
.select {
  width: 100%;
  font-family: var(--font-ui);
  font-size: 14px;
  padding: 9px 10px;
  border: 1px solid color-mix(in srgb, var(--ink) 20%, var(--paper));
  border-radius: 8px;
  background: #fff;
  color: #2B241D;
}

.textarea { resize: vertical; min-height: 70px; line-height: 1.45; }

.input:focus,
.textarea:focus,
.select:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.counter { font-size: 11px; color: var(--ink-soft); text-align: right; margin-top: 2px; }

.form-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin: 14px 0;
  flex-wrap: wrap;
}

.btn-solid {
  font-family: var(--font-ui);
  font-weight: 500;
  font-size: 13px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  cursor: pointer;
}

.btn-solid:hover:not(:disabled) { filter: brightness(.9); }
.btn-solid:disabled { opacity: .6; cursor: progress; }

.link-btn {
  font-size: 13px;
  color: var(--ink-soft);
  background: none;
  border: none;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}

.form-error { font-size: 12.5px; color: var(--accent); margin: -2px 0 8px; display: none; line-height: 1.4; }
.form-error.is-visible { display: block; }

.list {
  max-height: 220px;
  overflow-y: auto;
  border-top: 1px solid color-mix(in srgb, var(--ink) 12%, var(--paper));
  padding-top: 8px;
}

.list__item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid color-mix(in srgb, var(--ink) 8%, var(--paper));
  font-size: 13px;
}

.list__item.is-today { background: color-mix(in srgb, var(--brass) 16%, transparent); border-radius: 6px; padding: 8px 6px; }

.list__date { font-family: var(--font-label); font-size: 11px; color: var(--ink-soft); white-space: nowrap; padding-top: 2px; }
.list__text { flex: 1; line-height: 1.4; white-space: pre-line; }
.list__actions { display: flex; gap: 6px; }

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--ink-soft);
  font-size: 15px;
  line-height: 1;
  padding: 3px;
  border-radius: 4px;
}

.icon-btn:hover { color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }

.list__empty { font-size: 13px; color: var(--ink-soft); padding: 12px 0; line-height: 1.45; }
.sheet__close { display: block; margin: 12px auto 0; }

/* --------------------------------------------------------- Panel apariencia */

.sheet__group { margin-bottom: 18px; }

.sheet__group > h3 {
  font-family: var(--font-label);
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 0 0 8px;
  font-weight: 500;
}

.presets { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; }

.preset {
  border: 1px solid color-mix(in srgb, var(--ink) 18%, var(--paper));
  border-radius: 10px;
  padding: 7px;
  background: none;
  cursor: pointer;
  text-align: left;
  font-family: var(--font-ui);
  font-size: 11px;
  color: var(--ink-soft);
  line-height: 1.25;
}

.preset:hover { border-color: var(--accent); }
.preset.is-active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; color: var(--ink); }

.preset__chips { display: flex; gap: 3px; margin-bottom: 5px; }
.preset__chip { width: 100%; height: 16px; border-radius: 3px; }

.colors { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 8px 10px; }

.color-field { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-soft); }

.color-field input[type="color"] {
  width: 34px;
  height: 26px;
  padding: 0;
  border: 1px solid color-mix(in srgb, var(--ink) 20%, var(--paper));
  border-radius: 6px;
  background: none;
  cursor: pointer;
  flex: none;
}

.switches { display: flex; flex-wrap: wrap; gap: 14px; }

.switch { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink); cursor: pointer; }
.switch input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

/* ------------------------------------------------- Vista previa compartida */

.preview {
  display: none;
  margin-top: 22px;
  width: 100%;
  max-width: 460px;
  background: rgba(0, 0, 0, .25);
  border: 1px solid color-mix(in srgb, var(--brass) 45%, transparent);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}

.preview.is-open { display: block; }
.preview img { max-width: 100%; border-radius: 8px; display: block; margin: 0 auto 12px; }
.preview__actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }

.preview__hint {
  font-size: 12.5px;
  line-height: 1.5;
  opacity: .8;
  margin: 14px 0 0;
}

.preview__link {
  font-family: var(--font-label);
  font-size: 11px;
  opacity: .7;
  word-break: break-all;
  margin-top: 10px;
  line-height: 1.5;
}

/* ------------------------------------------------------------ Login / auth */

.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }

.auth__card {
  width: 100%;
  max-width: 380px;
  background: var(--paper);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 28px 26px 22px;
  box-shadow: 0 24px 50px rgba(0, 0, 0, .4);
}

.auth__title { font-family: var(--font-display); font-size: 22px; font-weight: 600; margin: 0 0 2px; }

.auth__sub {
  font-family: var(--font-label);
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 0 0 20px;
}

.auth__submit { width: 100%; margin-top: 6px; padding: 11px; font-size: 14px; }

.alert { border-radius: 8px; padding: 10px 12px; font-size: 13px; line-height: 1.45; margin-bottom: 14px; }

.alert--error { background: color-mix(in srgb, var(--accent) 12%, transparent); border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent); color: var(--accent); }
.alert--ok { background: rgba(37, 211, 102, .12); border: 1px solid rgba(32, 150, 80, .5); color: #1B6B3C; }
.alert--info { background: color-mix(in srgb, var(--brass) 16%, transparent); border: 1px solid color-mix(in srgb, var(--brass) 50%, transparent); color: var(--ink-soft); }

.alert code { font-family: var(--font-label); font-size: 12.5px; }

.auth__back { display: block; text-align: center; margin-top: 16px; font-size: 12.5px; color: var(--ink-soft); }

/* ------------------------------------------------ Pagina publica de enlace */

.share { max-width: 520px; margin: 0 auto; padding: 40px 20px 60px; text-align: center; }

.share__card {
  background: var(--paper);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 20px 45px rgba(0, 0, 0, .35);
}

.share__card img { max-width: 100%; border-radius: 8px; display: block; margin: 0 auto; }

.share__caption { font-family: var(--font-phrase); font-size: 16px; line-height: 1.55; margin: 16px 4px 4px; }
body.font-clasico .share__caption { font-style: italic; }

.share__date {
  font-family: var(--font-label);
  font-size: 11px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.share__actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 22px; }

/* ------------------------------------------------------------- Utilidades  */

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.render-canvas { display: none; }

@media (max-width: 380px) {
  .cal-perspective { width: 244px; }
  .cal-flipwrap { width: 244px; height: 300px; }
  .cal-day { font-size: 78px; }
  .cal-phrase { font-size: 15px; }
}

@media (prefers-reduced-motion: reduce) {
  .cal-flipwrap .cal-page,
  .cal-flipwrap .cal-page::after,
  .cal-phrase { animation-duration: .01ms !important; }
  .cal-phrase .w { transition-duration: .01ms !important; }
}
