/* ============================================================
   Lee Conmigo — El Teatro de Cuentos
   Warm night-stage: lantern amber, deep browns, storybook serifs
   ============================================================ */

:root {
  --bg: #1a110a;
  --bg-2: #241710;
  --bg-3: #2e1e14;
  --paper: #f4e8d2;
  --paper-dim: #cdb894;
  --ink-mute: #93795c;
  --ink-faint: #6b573f;
  --amber: #f5a83d;
  --amber-soft: #e9b46a;
  --amber-deep: #b96f1d;
  --amber-ink: #2b1806;
  --rose: #d9705f;
  --line-h: 1.5em;
  --radius: 18px;
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='0.55'/%3E%3C/svg%3E");
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { height: 100%; }

body {
  min-height: 100%;
  background:
    radial-gradient(120% 90% at 50% 0%, #2a1a10 0%, var(--bg) 55%, #120b06 100%);
  color: var(--paper);
  font-family: "Literata", Georgia, serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* grain + vignette atmosphere */
body::before {
  content: "";
  position: fixed; inset: 0;
  background: var(--grain);
  opacity: 0.05;
  mix-blend-mode: soft-light;
  pointer-events: none;
  z-index: 60;
}
body::after {
  content: "";
  position: fixed; inset: 0;
  background: radial-gradient(85% 70% at 50% 45%, transparent 60%, rgba(10,6,2,0.55) 100%);
  pointer-events: none;
  z-index: 59;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}
button:focus-visible, [role="slider"]:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 3px;
  border-radius: 8px;
}

.view { display: none; min-height: 100vh; }
.view.active { display: block; animation: viewIn 0.45s ease both; }
@keyframes viewIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

/* ============================================================
   HOME — Biblioteca
   ============================================================ */
.library {
  max-width: 1080px;
  margin: 0 auto;
  padding: clamp(24px, 5vw, 56px) clamp(18px, 4vw, 40px) 80px;
}

.library-head { text-align: center; margin-bottom: clamp(32px, 6vw, 60px); position: relative; }

.library-kicker {
  font-family: "Fraunces", serif;
  font-style: italic;
  font-size: clamp(0.95rem, 2vw, 1.15rem);
  color: var(--amber-soft);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  margin-bottom: 10px;
}

.library-title {
  font-family: "Fraunces", serif;
  font-weight: 560;
  font-size: clamp(2.6rem, 7vw, 4.6rem);
  line-height: 1.02;
  letter-spacing: -0.01em;
  text-wrap: balance;
}
.library-title em {
  font-style: italic;
  color: var(--amber);
  font-weight: 400;
}

.library-sub {
  margin-top: 14px;
  color: var(--ink-mute);
  font-size: clamp(0.95rem, 2vw, 1.1rem);
}

/* drifting fireflies (home only) */
.fireflies { position: absolute; inset: -40px 0 0; pointer-events: none; overflow: visible; }
.fireflies i {
  position: absolute;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--amber);
  filter: blur(1px);
  opacity: 0;
  animation: drift 14s ease-in-out infinite;
}
.fireflies i:nth-child(1) { left: 8%;  top: 30%; animation-delay: 0s; }
.fireflies i:nth-child(2) { left: 22%; top: 70%; animation-delay: -4s; width: 4px; height: 4px; }
.fireflies i:nth-child(3) { left: 45%; top: 15%; animation-delay: -8s; }
.fireflies i:nth-child(4) { left: 68%; top: 55%; animation-delay: -2s; width: 3px; height: 3px; }
.fireflies i:nth-child(5) { left: 84%; top: 25%; animation-delay: -6s; }
.fireflies i:nth-child(6) { left: 55%; top: 85%; animation-delay: -10s; width: 4px; height: 4px; }
.fireflies i:nth-child(7) { left: 92%; top: 75%; animation-delay: -12s; }
@keyframes drift {
  0%, 100% { transform: translate(0, 0); opacity: 0; }
  15%  { opacity: 0.55; }
  50%  { transform: translate(26px, -34px); opacity: 0.22; }
  85%  { opacity: 0.5; }
}

.shelf {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: clamp(20px, 4vw, 44px);
  justify-items: center;
}

/* the book card: leaning volumes on a night shelf */
.book-card {
  width: 100%;
  max-width: 300px;
  text-align: center;
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: riseIn 0.7s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}
.book-card:nth-child(1) { animation-delay: 0.05s; }
.book-card:nth-child(2) { animation-delay: 0.15s; }
.book-card:nth-child(3) { animation-delay: 0.25s; }
.book-card:nth-child(4) { animation-delay: 0.35s; }
@keyframes riseIn {
  from { opacity: 0; transform: translateY(34px) rotate(var(--tilt, 0deg)); }
  to   { opacity: 1; transform: translateY(0) rotate(var(--tilt, 0deg)); }
}

.book-card:nth-child(odd)  { --tilt: -1.6deg; }
.book-card:nth-child(even) { --tilt: 1.3deg; }
.book-card:hover { --tilt: 0deg; }

.book-cover {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  border-radius: 130px 130px 16px 16px;
  padding: 10px;
  background: linear-gradient(160deg, #3a2413, #241509 70%);
  border: 1px solid #4d321f;
  box-shadow:
    0 24px 50px -18px rgba(0, 0, 0, 0.75),
    0 4px 14px rgba(0, 0, 0, 0.4),
    inset 0 1px 0 rgba(245, 168, 61, 0.18);
  transition: transform 0.35s cubic-bezier(0.2, 0.7, 0.2, 1), box-shadow 0.35s ease;
  overflow: hidden;
}
.book-card:hover .book-cover {
  transform: translateY(-10px) scale(1.02);
  box-shadow:
    0 34px 64px -18px rgba(0, 0, 0, 0.8),
    0 6px 20px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(245, 168, 61, 0.35),
    inset 0 1px 0 rgba(245, 168, 61, 0.25);
}
.book-cover img {
  width: 100%; height: 100%;
  object-fit: cover;
  border-radius: 120px 120px 10px 10px;
  display: block;
  background: var(--bg-2);
}
.book-cover .cover-shine {
  position: absolute; inset: 10px;
  border-radius: 120px 120px 10px 10px;
  background: linear-gradient(115deg, transparent 55%, rgba(255, 235, 200, 0.13) 75%, transparent 82%);
  pointer-events: none;
}

.book-title {
  font-family: "Fraunces", serif;
  font-size: clamp(1.15rem, 2.4vw, 1.45rem);
  font-weight: 560;
  margin-top: 18px;
  line-height: 1.15;
}
.book-meta {
  margin-top: 6px;
  color: var(--ink-mute);
  font-size: 0.88rem;
  letter-spacing: 0.04em;
}
.book-meta b { color: var(--amber-soft); font-weight: 600; }

.library-foot {
  margin-top: clamp(40px, 8vw, 70px);
  text-align: center;
  color: var(--ink-faint);
  font-size: 0.85rem;
  font-style: italic;
}

/* ============================================================
   PLAYER — the stage
   ============================================================ */
.player {
  max-width: 880px;
  margin: 0 auto;
  padding: 18px clamp(14px, 3.5vw, 32px) 40px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.player-top {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 6px 0 18px;
}

.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95rem;
  color: var(--paper-dim);
  padding: 8px 14px 8px 10px;
  border-radius: 999px;
  transition: color 0.2s, background 0.2s;
}
.btn-back:hover { color: var(--amber); background: rgba(245, 168, 61, 0.08); }
.btn-back svg { width: 18px; height: 18px; }

.player-book {
  flex: 1;
  min-width: 0;
}
.player-book h1 {
  font-family: "Fraunces", serif;
  font-weight: 560;
  font-size: clamp(1.1rem, 2.6vw, 1.5rem);
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.player-page {
  color: var(--ink-mute);
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: 3px;
}

.chips { display: flex; gap: 8px; }
.chip {
  font-size: 0.82rem;
  letter-spacing: 0.05em;
  padding: 7px 13px;
  border-radius: 999px;
  color: var(--paper-dim);
  border: 1px solid #4a3117;
  background: rgba(0, 0, 0, 0.25);
  transition: all 0.2s ease;
  white-space: nowrap;
}
.chip:hover { border-color: var(--amber-deep); color: var(--amber-soft); }
.chip.on {
  background: rgba(245, 168, 61, 0.14);
  border-color: var(--amber-deep);
  color: var(--amber);
}

/* illustration: gilded stage frame */
.stage-frame {
  position: relative;
  border-radius: 22px;
  padding: 9px;
  background: linear-gradient(150deg, #46301a, #221408 75%);
  border: 1px solid #553a1e;
  box-shadow:
    0 26px 60px -20px rgba(0, 0, 0, 0.85),
    inset 0 1px 0 rgba(245, 168, 61, 0.2);
  max-height: 34vh;
  margin: 4px auto 22px;
  width: fit-content;
  max-width: 100%;
}
.stage-frame img {
  display: block;
  max-height: calc(34vh - 18px);
  max-width: 100%;
  border-radius: 14px;
  object-fit: contain;
}

/* ------------------------------------------------------------
   karaoke viewport
   ------------------------------------------------------------ */
.karaoke {
  position: relative;
  flex: 0 0 auto;
  margin: 6px auto 20px;
  width: 100%;
  overflow: hidden;
  padding: 2px 6px;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 7%, #000 88%, transparent 100%);
          mask-image: linear-gradient(to bottom, transparent 0, #000 7%, #000 88%, transparent 100%);
}

.karaoke-lines {
  transition: transform 0.45s cubic-bezier(0.25, 0.8, 0.25, 1);
  will-change: transform;
}

.ln {
  font-size: clamp(1.55rem, 4.4vw, 2.5rem);
  line-height: var(--line-h);
  font-weight: 420;
  letter-spacing: 0.005em;
  text-wrap: balance;
  padding: 0.06em 0.2em;
}

.w {
  cursor: pointer;
  border-radius: 0.3em;
  padding: 0 0.08em;
  transition: color 0.18s ease, background 0.18s ease;
  user-select: none;
  -webkit-user-select: none;
}
.w.todo { color: var(--ink-mute); }
.w.done { color: var(--amber-soft); }
.w.now {
  background: var(--amber);
  color: var(--amber-ink);
  box-shadow: 0 0 26px rgba(245, 168, 61, 0.4);
  font-weight: 560;
}
.w:hover.todo, .w:hover.done { background: rgba(245, 168, 61, 0.14); }

/* "Fin" card */
.fin-card {
  text-align: center;
  padding: 5vh 10px 3vh;
  animation: viewIn 0.8s ease both;
}
.fin-word {
  font-family: "Fraunces", serif;
  font-style: italic;
  font-weight: 500;
  font-size: clamp(4rem, 14vw, 7.5rem);
  color: var(--amber);
  line-height: 1;
  text-shadow: 0 0 60px rgba(245, 168, 61, 0.35);
}
.fin-dash {
  width: 120px; height: 2px;
  margin: 26px auto;
  background: linear-gradient(90deg, transparent, var(--amber-deep), transparent);
}
.fin-actions {
  display: flex;
  gap: 14px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 8px;
}
.btn-primary {
  font-family: "Fraunces", serif;
  font-size: 1.02rem;
  padding: 13px 26px;
  border-radius: 999px;
  background: var(--amber);
  color: var(--amber-ink);
  font-weight: 600;
  box-shadow: 0 10px 30px -8px rgba(245, 168, 61, 0.55);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 16px 36px -8px rgba(245, 168, 61, 0.65); }
.btn-ghost {
  font-size: 0.98rem;
  padding: 12px 22px;
  border-radius: 999px;
  border: 1px solid #4d321f;
  color: var(--paper-dim);
  transition: all 0.2s;
}
.btn-ghost:hover { border-color: var(--amber-deep); color: var(--amber); }

/* ------------------------------------------------------------
   progress + transport
   ------------------------------------------------------------ */
.progress-wrap { margin: 4px 2px 14px; }
.progress-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.time {
  font-variant-numeric: tabular-nums;
  font-size: 0.82rem;
  color: var(--ink-mute);
  min-width: 42px;
}
.time.right { text-align: right; }

.progress {
  flex: 1;
  height: 22px;
  display: flex;
  align-items: center;
  cursor: pointer;
  touch-action: none;
}
.progress-track {
  position: relative;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: #3a2712;
  overflow: visible;
}
.progress-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--amber-deep), var(--amber));
}
.progress-fill::after {
  content: "";
  position: absolute;
  right: -7px; top: 50%;
  transform: translateY(-50%) scale(0);
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 18px rgba(245, 168, 61, 0.7);
  transition: transform 0.15s ease;
}
.progress:hover .progress-fill::after { transform: translateY(-50%) scale(1); }
.tick {
  position: absolute;
  top: -2px;
  width: 2px; height: 10px;
  background: rgba(244, 232, 210, 0.22);
  border-radius: 1px;
}

.transport {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 3vw, 22px);
  padding: 6px 0 10px;
  flex-wrap: nowrap;
}

.tbtn {
  width: 52px; height: 52px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--paper-dim);
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid #442d16;
  transition: all 0.2s ease;
  flex: 0 0 auto;
}
.tbtn svg { width: 22px; height: 22px; }
.tbtn:hover {
  color: var(--amber);
  border-color: var(--amber-deep);
  background: rgba(245, 168, 61, 0.1);
  transform: translateY(-2px);
}
.tbtn:active { transform: translateY(0); }
.tbtn.small { width: 46px; height: 46px; }
.tbtn.stopbtn:hover { color: var(--rose); border-color: var(--rose); }
.tbtn[disabled] { opacity: 0.35; pointer-events: none; }

.playbtn {
  width: 74px; height: 74px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #ffc35f, var(--amber) 55%, var(--amber-deep));
  color: var(--amber-ink);
  border: none;
  display: grid;
  place-items: center;
  box-shadow:
    0 14px 34px -8px rgba(245, 168, 61, 0.6),
    inset 0 2px 3px rgba(255, 255, 255, 0.45),
    inset 0 -3px 6px rgba(80, 40, 0, 0.35);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  flex: 0 0 auto;
}
.playbtn svg { width: 30px; height: 30px; margin-left: 2px; }
.playbtn.playing svg { margin-left: 0; }
.playbtn:hover { transform: scale(1.06); }
.playbtn:active { transform: scale(0.97); }
.playbtn.loading { animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 14px 34px -8px rgba(245, 168, 61, 0.45); }
  50% { box-shadow: 0 14px 44px -4px rgba(245, 168, 61, 0.85); }
}

.kbd-hint {
  text-align: center;
  color: var(--ink-faint);
  font-size: 0.78rem;
  margin-top: 6px;
  letter-spacing: 0.03em;
}
.kbd-hint kbd {
  font-family: inherit;
  border: 1px solid #3d2915;
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1px 6px;
  color: var(--ink-mute);
  background: rgba(0,0,0,0.25);
}

/* loading / error */
.center-note {
  text-align: center;
  padding: 16vh 20px;
  color: var(--ink-mute);
  font-size: 1.05rem;
}
.center-note .spin {
  display: inline-block;
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 3px solid #4a3117;
  border-top-color: var(--amber);
  animation: spin 0.9s linear infinite;
  margin-bottom: 18px;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 560px) {
  .chips { order: 3; width: 100%; justify-content: center; margin-top: 8px; }
  .player-top { flex-wrap: wrap; }
  .stage-frame { max-height: 27vh; }
  .stage-frame img { max-height: calc(27vh - 18px); }
  .kbd-hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
  .fireflies { display: none; }
}
