/* ============================================================
   Sleep Mode — full-screen immersive player
   Dark theme + timer + breathing animation
   Activated when user opens a sleep_routine audio
   ============================================================ */

.sleep-mode {
  position: fixed;
  inset: 0;
  /* Use the dynamic visual viewport so the modal hugs the safe area on iOS
     and Android (matters when the URL bar appears/disappears). */
  height: 100dvh;
  max-height: 100dvh;
  /* Above the .ar-screen hubs (235) + tab bar (240) so the sleep player shows on top
     when launched from the "Descansa en Él" hub (was 200 → opened behind it). */
  z-index: 250;
  background: radial-gradient(ellipse at center top,
              #1a2845 0%,
              #0a1426 70%,
              #050a13 100%);
  color: #e8ecf3;
  display: none;
  flex-direction: column;
  overflow: hidden;
}
/* Minimized → hidden but still `.open` (audio keeps playing, docked in the mini bar).
   !important beats the `.sleep-mode.open { display:flex }` rule below. */
.sleep-mode.minimized { display: none !important; }
.sleep-mode.open {
  display: flex;
  animation: sleepFadeIn 0.6s ease-out;
}

@keyframes sleepFadeIn {
  from { opacity: 0; transform: scale(0.96); }
  to   { opacity: 1; transform: scale(1); }
}

/* Decorative stars (CSS-only twinkle) */
.sleep-stars {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.sleep-stars::before,
.sleep-stars::after {
  content: "";
  position: absolute;
  width: 100%;
  height: 100%;
  background-image:
    radial-gradient(1px 1px at 17% 12%, #fff 50%, transparent 50%),
    radial-gradient(1px 1px at 38% 33%, #fff 50%, transparent 50%),
    radial-gradient(1px 1px at 63% 8%,  #fff 50%, transparent 50%),
    radial-gradient(1px 1px at 84% 28%, #fff 50%, transparent 50%),
    radial-gradient(2px 2px at 24% 64%, rgba(255,255,255,0.85) 50%, transparent 50%),
    radial-gradient(1px 1px at 49% 79%, #fff 50%, transparent 50%),
    radial-gradient(1px 1px at 73% 51%, rgba(255,255,255,0.7) 50%, transparent 50%),
    radial-gradient(2px 2px at 91% 68%, #fff 50%, transparent 50%),
    radial-gradient(1px 1px at 9% 85%,  rgba(255,255,255,0.6) 50%, transparent 50%);
  opacity: 0.55;
  animation: twinkle 6s ease-in-out infinite alternate;
}
.sleep-stars::after {
  background-image:
    radial-gradient(1px 1px at 31% 15%, #ffd 50%, transparent 50%),
    radial-gradient(1px 1px at 56% 27%, #ffd 50%, transparent 50%),
    radial-gradient(1px 1px at 78% 11%, #fff 50%, transparent 50%),
    radial-gradient(2px 2px at 12% 45%, rgba(255,255,255,0.75) 50%, transparent 50%);
  opacity: 0.35;
  animation-delay: 3s;
}
@keyframes twinkle {
  0%   { opacity: 0.15; }
  50%  { opacity: 0.6; }
  100% { opacity: 0.25; }
}

/* Top bar (close button + status pill) */
.sleep-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 18px 14px;
  z-index: 5;
}
.sleep-close {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  color: #e8ecf3;
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
  cursor: pointer;
}
.sleep-timer-pill {
  background: rgba(212,160,23,0.18);
  border: 1px solid rgba(212,160,23,0.35);
  color: #f0c050;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  display: none;
}
.sleep-timer-pill.active { display: inline-block; }

/* Breathing moon center — must be able to shrink below its content size so
   the bottom controls stay reachable on phones with limited vertical space. */
.sleep-moon-stage {
  flex: 1 1 auto;
  min-height: 0;             /* allow flex shrinking under controls */
  overflow-y: auto;          /* fall back to scroll if everything doesn't fit */
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px 24px;
  position: relative;
  z-index: 2;
}
.sleep-moon {
  width: 160px;
  height: 160px;
  border-radius: 50%;
  background: radial-gradient(ellipse at 35% 35%,
              #f5e9d4 0%,
              #d4b97a 40%,
              #8a6a32 80%,
              #4a3a18 100%);
  box-shadow:
    0 0 60px rgba(245,233,212,0.25),
    0 0 120px rgba(245,233,212,0.12),
    inset -8px -8px 24px rgba(50,30,10,0.4);
  animation: moonBreath 8s ease-in-out infinite;
  margin-bottom: 32px;
  position: relative;
}
.sleep-moon::before {
  /* subtle crater dimples */
  content: "";
  position: absolute;
  top: 30%;
  left: 25%;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(0,0,0,0.08);
  box-shadow:
    24px 8px 0 -4px rgba(0,0,0,0.06),
    -8px 28px 0 -6px rgba(0,0,0,0.06);
}
@keyframes moonBreath {
  0%, 100% { transform: scale(1); box-shadow: 0 0 60px rgba(245,233,212,0.25), 0 0 120px rgba(245,233,212,0.12), inset -8px -8px 24px rgba(50,30,10,0.4); }
  50%      { transform: scale(1.06); box-shadow: 0 0 90px rgba(245,233,212,0.4), 0 0 180px rgba(245,233,212,0.2), inset -8px -8px 24px rgba(50,30,10,0.4); }
}

/* Sleeping lamb mascot nestled below the moon — its own cloud, gentle bob. */
.sleep-lamb {
  display: block;
  width: 168px;
  height: auto;
  margin: -14px 0 24px;
  filter: drop-shadow(0 8px 22px rgba(0,0,0,0.35));
  animation: sleepLambFloat 7s ease-in-out infinite;
  pointer-events: none;
}
@keyframes sleepLambFloat {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-7px); }
}
@media (prefers-reduced-motion: reduce) {
  .sleep-lamb { animation: none; }
}

.sleep-title {
  font-size: 1.3rem;
  font-weight: 600;
  text-align: center;
  margin: 0 0 8px;
  color: #f5e9d4;
}
.sleep-subtitle {
  font-size: 0.9rem;
  text-align: center;
  color: rgba(232,236,243,0.88);   /* bumped from 0.6 */
  margin: 0 0 24px;
}

/* Timer selector */
.sleep-timer-options {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-bottom: 24px;
  padding: 0 8px;
}
.sleep-timer-options button {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  color: #e8ecf3;
  padding: 8px 16px;
  border-radius: 18px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
}
.sleep-timer-options button:hover { background: rgba(255,255,255,0.12); }
.sleep-timer-options button.active {
  background: rgba(212,160,23,0.2);
  border-color: rgba(212,160,23,0.5);
  color: #f0c050;
}

/* Bottom controls — pinned at the bottom of the modal regardless of the
   moon-stage height. flex:0 0 auto so it never gets squeezed off-screen. */
.sleep-controls {
  flex: 0 0 auto;
  padding: 14px 24px calc(env(safe-area-inset-bottom, 0px) + 22px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  background: linear-gradient(180deg, transparent 0%, rgba(5,10,19,0.45) 30%, rgba(5,10,19,0.7) 100%);
  position: relative;
  z-index: 3;
}

/* Short phones: shrink the moon + collapse vertical breathing room so the
   controls stay above the system bars without scrolling. */
@media (max-height: 720px) {
  .sleep-moon { width: 110px; height: 110px; margin-bottom: 18px; }
  .sleep-title { font-size: 1.15rem; }
  .sleep-subtitle { margin-bottom: 14px; }
  .sleep-timer-options { gap: 8px; margin-bottom: 14px; }
  .sleep-timer-options button { padding: 6px 12px; font-size: 0.8rem; }
}
@media (max-height: 620px) {
  .sleep-moon { width: 88px; height: 88px; margin-bottom: 12px; }
}
.sleep-play-pause {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  background: rgba(245,233,212,0.92);
  color: #1a2845;
  border: none;
  font-size: 1.8rem;
  cursor: pointer;
  box-shadow: 0 6px 30px rgba(245,233,212,0.3);
  transition: transform 0.15s ease;
}
.sleep-play-pause:active { transform: scale(0.95); }

.sleep-progress {
  width: 100%;
  max-width: 320px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.78rem;
  color: rgba(232,236,243,0.85);   /* bumped from 0.5 — was unreadable */
  font-variant-numeric: tabular-nums;
}
.sleep-progress .bar {
  flex: 1;
  height: 14px;             /* taller hit target for scrub */
  background: transparent;
  border-radius: 8px;
  position: relative;
  cursor: pointer;
  touch-action: none;        /* let JS handle drag */
  display: flex;
  align-items: center;
}
.sleep-progress .bar::before {
  content: '';
  position: absolute;
  left: 0; right: 0;
  top: 50%;
  height: 4px;
  margin-top: -2px;
  background: rgba(255,255,255,0.16);
  border-radius: 2px;
  pointer-events: none;
}
.sleep-progress .bar .fill {
  position: absolute;
  left: 0;
  top: 50%;
  height: 4px;
  margin-top: -2px;
  background: linear-gradient(90deg, #d4b97a, #f5e9d4);
  width: 0%;
  border-radius: 2px;
  transition: width 0.18s linear;
  pointer-events: none;
}
.sleep-progress .bar:focus { outline: none; }
.sleep-progress .bar:focus-visible::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 10px;
  border: 2px solid rgba(245,233,212,0.55);
}

.sleep-buttons {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 22px;
}
.sleep-btn-aux {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  color: rgba(232,236,243,0.92);
  padding: 12px 18px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.2s ease;
}
.sleep-btn-aux:active { transform: scale(0.96); background: rgba(255,255,255,0.14); }
.sleep-btn-skip {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.14);
  color: rgba(232,236,243,0.95);
  width: 46px; height: 46px; border-radius: 50%;
  font-size: 1.05rem; cursor: pointer; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.15s ease, background 0.2s ease;
}
.sleep-btn-skip:active { transform: scale(0.9); background: rgba(255,255,255,0.16); }

.sleep-btn-stop {
  background: rgba(168,58,42,0.18);
  border: 1px solid rgba(197,74,58,0.45);
  color: #f5e9d4;
  padding: 12px 26px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 800;
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: background 0.2s ease, transform 0.15s ease;
}
.sleep-btn-stop:active { transform: scale(0.97); background: rgba(168,58,42,0.32); }

.sleep-btn-music {
  display: inline-flex; align-items: center; gap: 6px;
  margin: 4px auto 0;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.14);
  color: rgba(232,236,243,0.88);
  padding: 9px 18px;
  border-radius: 999px;
  font-family: inherit; font-size: 0.82rem; font-weight: 700; letter-spacing: 0.02em;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.2s ease;
}
.sleep-btn-music:active { transform: scale(0.97); background: rgba(255,255,255,0.12); }

.sleep-verse {
  text-align: center;
  font-style: italic;
  color: rgba(232,236,243,0.82);   /* bumped from 0.45 — quote needs readability */
  font-size: 0.86rem;
  line-height: 1.55;
  max-width: 320px;
  margin: 0 auto;
}

@media (max-height: 640px) {
  .sleep-moon { width: 120px; height: 120px; margin-bottom: 20px; }
  .sleep-title { font-size: 1.15rem; }
}

/* When a sleep routine has its own cover art, show it instead of the
   generic gold orb — rounded card, keep the glow + breathing pulse. */
.sleep-moon.has-image {
  border-radius: 26px;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}
.sleep-moon.has-image::before { display: none; }
