:root {
  --gap: 22px;
  --radius: 20px;
  --bg1: #3a1e6e;
  --bg2: #17092e;
  --card: #2a1a52;
  --card-hi: #362066;
  --accent: #ffcf4d;
  --text: #fff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Baloo 2", "Comic Sans MS", system-ui, sans-serif;
  background: radial-gradient(circle at 50% -20%, var(--bg1), var(--bg2) 70%);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
}

.app-header { padding: 28px 20px 8px; text-align: center; }
.app-header h1 {
  font-size: clamp(30px, 5vw, 54px);
  font-weight: 800;
  margin: 0 0 18px;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.25);
}
.moon { display: inline-block; }

.chips { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
#age-chips { margin-top: 10px; }
#age-chips .chip { font-size: 14px; padding: 6px 14px; opacity: 0.95; }
.chip {
  border: none;
  border-radius: 999px;
  padding: 11px 22px;
  font-size: 18px;
  font-family: inherit;
  font-weight: 700;
  background: #47317e;
  color: #fff;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s;
}
.chip:hover { transform: translateY(-2px); }
.chip.on { background: var(--accent); color: #3a1e6e; }

.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--gap);
  padding: var(--gap);
  max-width: 1400px;
  margin: 0 auto;
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  background: linear-gradient(180deg, var(--card-hi), var(--card));
  border: none;
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
  color: #fff;
  font-family: inherit;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.3);
  transition: transform 0.14s, box-shadow 0.14s;
}
/* Bright yellow "watched" tick */
.card-tick {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  background: #ffe000;
  color: #1c0f3a;
  border: 3px solid #fff;
  border-radius: 50%;
  font-size: 20px;
  font-weight: 900;
  line-height: 1;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.45);
  z-index: 2;
}
.card.watched .card-cover { opacity: 0.8; }
.card:hover,
.card:focus-visible {
  transform: translateY(-8px) scale(1.02);
  outline: 4px solid var(--accent);
  box-shadow: 0 16px 30px rgba(0, 0, 0, 0.4);
}

.card-cover {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 14px;
  background: #47317e;
}
.card-cover.missing {
  display: flex;
  background: #47317e;
  position: relative;
}
.card-cover.missing::after {
  content: "📖";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 48px;
}

.card-title {
  font-size: clamp(15px, 1.6vw, 21px);
  font-weight: 700;
  text-align: center;
  line-height: 1.2;
}
.card-badges { font-size: 20px; letter-spacing: 4px; }

.empty {
  grid-column: 1 / -1;
  text-align: center;
  font-size: 26px;
  padding: 80px 20px;
  opacity: 0.85;
}

/* ---- Player overlay ---- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 3, 24, 0.94);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.overlay.hidden { display: none; }
.overlay-body { width: min(94vw, 1100px); }
.overlay-close {
  position: absolute;
  top: 18px;
  right: 22px;
  font-size: 30px;
  font-weight: 800;
  background: var(--accent);
  color: #3a1e6e;
  border: none;
  border-radius: 999px;
  width: 58px;
  height: 58px;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

.stage { width: 100%; aspect-ratio: 16 / 9; border-radius: 16px; border: none; }

.audio-stage { display: flex; flex-direction: column; align-items: center; gap: 24px; }
.audio-art {
  width: min(60vw, 420px);
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: 18px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
}
.audio-stage audio { width: min(80vw, 520px); }

.reader {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.reader .pages { width: 100%; }
.page {
  display: none;
  width: 100%;
  max-height: 84vh;
  object-fit: contain;
  border-radius: 14px;
}
.page.on { display: block; }
.nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: 40px;
  font-weight: 800;
  background: rgba(255, 207, 77, 0.92);
  color: #3a1e6e;
  border: none;
  border-radius: 999px;
  width: 66px;
  height: 66px;
  cursor: pointer;
}
.nav.prev { left: 6px; }
.nav.next { right: 6px; }
.counter {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.55);
  padding: 6px 16px;
  border-radius: 999px;
  font-size: 16px;
}
.narrate {
  position: absolute;
  bottom: 12px;
  right: 14px;
  background: var(--accent);
  color: #3a1e6e;
  border: none;
  border-radius: 999px;
  padding: 8px 18px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
}
.narrate:hover { transform: translateY(-2px); }
.narrate[aria-pressed="true"] { background: #ffd76a; }

.linkout { text-align: center; padding: 40px 20px; }
.linkout p { font-size: 22px; }
.linkout-btn {
  display: inline-block;
  margin-top: 14px;
  background: var(--accent);
  color: #3a1e6e;
  padding: 14px 30px;
  border-radius: 999px;
  text-decoration: none;
  font-weight: 800;
  font-size: 20px;
}

@media (max-width: 900px) { .grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .grid { grid-template-columns: 1fr; } }
