/* The Songbook. The page is the night sky of the album covers; Dad's note is the
   one lit thing in it, a sheet of paper under a lantern. */
:root {
  color-scheme: dark;
  --night: #0b1430;
  --night-2: #142148;
  --night-3: #1d2d5e;
  --star: #f4ecd8;
  --dim: #a7b1d1;
  --rule: rgba(244, 236, 216, 0.16);
  --gold: #eab54d;
  --gold-deep: #c98d1f;
  --ember: #f29a3c;
  --paper: #f8eed5;
  --paper-edge: #e6d3a4;
  --paper-ink: #2b2440;
  --paper-dim: #6d6078;
  --f-display: "Bodoni 72", Didot, "Bodoni MT", "Iowan Old Style", Georgia, serif;
  --f-serif: "Iowan Old Style", Charter, Palatino, "Palatino Linotype", Georgia, serif;
  --f-hand: "Bradley Hand", Noteworthy, "Segoe Print", "Comic Sans MS", cursive;
  --f-ui: "Avenir Next", Avenir, -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html {
  background: var(--night);
  color: var(--star);
  -webkit-text-size-adjust: 100%;
  scroll-padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px));
}

body {
  margin: 0;
  padding: 0;
  background:
    radial-gradient(1.5px 1.5px at 12% 9%, rgba(255, 255, 255, 0.85) 50%, transparent 51%),
    radial-gradient(1px 1px at 27% 22%, rgba(255, 255, 255, 0.6) 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 44% 6%, rgba(255, 244, 214, 0.8) 50%, transparent 51%),
    radial-gradient(1px 1px at 58% 17%, rgba(255, 255, 255, 0.55) 50%, transparent 51%),
    radial-gradient(2px 2px at 71% 11%, rgba(255, 240, 200, 0.9) 50%, transparent 51%),
    radial-gradient(1px 1px at 83% 26%, rgba(255, 255, 255, 0.6) 50%, transparent 51%),
    radial-gradient(1px 1px at 93% 7%, rgba(255, 255, 255, 0.7) 50%, transparent 51%),
    radial-gradient(1px 1px at 6% 31%, rgba(255, 255, 255, 0.45) 50%, transparent 51%),
    radial-gradient(1px 1px at 36% 36%, rgba(255, 255, 255, 0.4) 50%, transparent 51%),
    radial-gradient(1px 1px at 66% 33%, rgba(255, 255, 255, 0.4) 50%, transparent 51%),
    linear-gradient(180deg, var(--night-2) 0, var(--night) 620px);
  background-repeat: no-repeat;
  background-size: 100% 620px, 100% 620px, 100% 620px, 100% 620px, 100% 620px, 100% 620px,
    100% 620px, 100% 620px, 100% 620px, 100% 620px, 100% 100%;
  color: var(--star);
  font-family: var(--f-serif);
  font-size: 17px;
  line-height: 1.6;
  overflow-x: clip;
  min-height: 100dvh;
}

/* The current cover, blurred, as the colour of the room. */
.ambient {
  position: fixed;
  z-index: -1;
  inset: -80px -80px auto -80px;
  height: 82vh;
  background-size: cover;
  background-position: center;
  filter: blur(70px) saturate(1.35);
  opacity: 0.5;
  -webkit-mask-image: linear-gradient(180deg, #000 30%, transparent 100%);
  mask-image: linear-gradient(180deg, #000 30%, transparent 100%);
  pointer-events: none;
}

img {
  display: block;
  max-width: 100%;
  height: auto;
}

a {
  color: inherit;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}

h1, h2, h3 {
  font-family: var(--f-display);
  font-weight: 500;
  margin: 0;
  line-height: 1.08;
  overflow-wrap: anywhere;
}

p {
  margin: 0;
}

.icon {
  width: 1em;
  height: 1em;
  fill: currentColor;
  flex: none;
}

/* Top bar */
.topbar {
  max-width: 1080px;
  margin: 0 auto;
  padding-top: max(14px, env(safe-area-inset-top, 0px));
  padding-bottom: 10px;
  padding-left: max(20px, env(safe-area-inset-left, 0px));
  padding-right: max(20px, env(safe-area-inset-right, 0px));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-family: var(--f-ui);
  font-size: 0.86rem;
}

.topbar-link {
  text-decoration: none;
  color: var(--dim);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 6px 0;
}

.topbar-link:hover,
.topbar-link.is-active {
  color: var(--gold);
}

/* Main page container */
.page {
  max-width: 1080px;
  margin: 0 auto;
  padding-top: 12px;
  padding-bottom: calc(112px + env(safe-area-inset-bottom, 0px));
  padding-left: max(20px, env(safe-area-inset-left, 0px));
  padding-right: max(20px, env(safe-area-inset-right, 0px));
}

.byline {
  font-family: var(--f-serif);
  font-style: italic;
  font-size: 1rem;
  color: var(--gold);
}

/* Buttons */
.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 20px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 48px;
  border-radius: 999px;
  padding: 10px 22px;
  font-family: var(--f-ui);
  font-size: 0.98rem;
  font-weight: 700;
  border: 1.5px solid transparent;
  text-decoration: none;
}

.btn-primary {
  background: linear-gradient(180deg, #f4c868, var(--gold));
  color: #2a1c05;
  box-shadow: 0 6px 22px rgba(234, 181, 77, 0.32);
}

.btn-dad {
  background: rgba(242, 154, 60, 0.12);
  border-color: var(--ember);
  color: #ffd9a8;
}

.btn:hover {
  filter: brightness(1.08);
}

.btn-hint {
  margin-top: 10px;
  font-size: 0.92rem;
  font-style: italic;
  color: var(--dim);
  max-width: 44ch;
}

/* Covers */
.cover-art {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 14px;
  background: var(--night-3);
  box-shadow:
    0 0 0 1px rgba(244, 236, 216, 0.14),
    0 24px 60px rgba(3, 6, 20, 0.7),
    0 0 90px rgba(234, 181, 77, 0.14);
}

/* Title page (one album) */
.volume {
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.volume-hero {
  max-width: 520px;
  width: 100%;
  margin: 0 auto;
}

.volume-body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 30px;
}

.title-head h1 {
  font-size: clamp(2.5rem, 10vw, 4rem);
  margin-top: 4px;
  letter-spacing: -0.01em;
}

.title-sub {
  margin-top: 10px;
  font-family: var(--f-ui);
  color: var(--dim);
  font-size: 0.92rem;
}

/* Dad's note: a lit sheet of paper */
.note-heading,
.voice-heading,
.section-heading {
  font-family: var(--f-display);
  font-style: italic;
  font-weight: 500;
  font-size: 1.5rem;
  color: var(--gold);
  margin-bottom: 14px;
}

.note-paper {
  position: relative;
  background:
    repeating-linear-gradient(180deg, transparent 0 31px, rgba(43, 36, 64, 0.07) 31px 32px),
    linear-gradient(180deg, #fbf3de, var(--paper));
  color: var(--paper-ink);
  border-radius: 4px 4px 4px 22px;
  padding: 24px 22px 22px;
  max-width: 60ch;
  transform: rotate(-0.6deg);
  box-shadow:
    0 0 0 1px var(--paper-edge),
    0 18px 44px rgba(3, 6, 20, 0.6),
    0 0 70px rgba(242, 154, 60, 0.22);
}

.note-paper::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  width: 22px;
  height: 22px;
  border-radius: 0 0 0 22px;
  background: linear-gradient(45deg, transparent 50%, var(--paper-edge) 50%);
}

.story-block {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.story-block p {
  font-size: 1.08rem;
  line-height: 32px;
}

.note-paper .story-block p {
  font-family: var(--f-hand);
  font-size: 1.3rem;
  color: #2f2e6b;
}

.note-sign {
  margin-top: 14px;
  font-family: var(--f-hand);
  font-size: 1.5rem;
  line-height: 32px;
  color: #3b3a78;
  text-align: right;
}

.story-pages {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 4px;
}

.story-page-img {
  border-radius: 2px;
  box-shadow: 0 2px 10px rgba(40, 30, 10, 0.25);
  background: #fff;
}

/* Dad's voice */
.recordings {
  display: flex;
  flex-direction: column;
  max-width: 60ch;
}

.recording-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.recording-item {
  background: linear-gradient(180deg, rgba(242, 154, 60, 0.14), rgba(242, 154, 60, 0.05));
  border: 1px solid rgba(242, 154, 60, 0.42);
  border-radius: 18px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.recording-head {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.voice-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 0;
  background: radial-gradient(circle at 35% 30%, #ffd08a, var(--ember));
  color: #3a1d02;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  font-size: 1.15rem;
  box-shadow: 0 0 0 5px rgba(242, 154, 60, 0.16), 0 0 30px rgba(242, 154, 60, 0.4);
}

.voice-btn:hover {
  filter: brightness(1.08);
}

.recording-meta {
  min-width: 0;
  flex: 1;
}

.recording-role {
  display: block;
  font-family: var(--f-serif);
  font-style: italic;
  font-size: 0.9rem;
  color: #ffd9a8;
}

.recording-title {
  display: block;
  font-family: var(--f-display);
  font-size: 1.22rem;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.recording-dur {
  font-family: var(--f-ui);
  font-size: 0.84rem;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
  flex: none;
}

/* The sound of a voice, drawn: bars that stand still until asked. */
.voice-wave {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 22px;
  flex: none;
}

.voice-wave i {
  width: 3px;
  border-radius: 2px;
  background: var(--ember);
  opacity: 0.75;
}

.transcript-toggle summary {
  cursor: pointer;
  font-family: var(--f-ui);
  font-size: 0.88rem;
  font-weight: 600;
  color: #ffd9a8;
  padding: 4px 0;
}

.transcript {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
  padding-left: 14px;
  border-left: 2px solid rgba(242, 154, 60, 0.5);
  font-size: 1rem;
  line-height: 1.6;
}

/* Contents */
.toc-section {
  max-width: 64ch;
}

.toc {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.toc li {
  border-top: 1px solid var(--rule);
}

.toc li:last-child {
  border-bottom: 1px solid var(--rule);
}

.toc-link {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
  padding: 9px 4px;
  text-decoration: none;
  border-radius: 10px;
}

.toc-link:hover {
  background: rgba(244, 236, 216, 0.06);
}

.toc-num {
  font-family: var(--f-display);
  font-style: italic;
  font-size: 1.1rem;
  color: var(--gold);
  width: 24px;
  text-align: right;
  flex: none;
  font-variant-numeric: tabular-nums;
}

.toc-thumb {
  width: 52px;
  height: 52px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--night-3);
  box-shadow: 0 0 0 1px rgba(244, 236, 216, 0.14);
  flex: none;
}

.toc-text {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.toc-title {
  font-family: var(--f-display);
  font-size: 1.24rem;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.toc-marks {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-style: italic;
  font-size: 0.86rem;
  color: #ffd9a8;
}

.toc-dur {
  font-family: var(--f-ui);
  font-size: 0.84rem;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
  flex: none;
}

.toc li.is-playing .toc-title {
  color: var(--gold);
}

.toc li.is-playing .toc-thumb {
  box-shadow: 0 0 0 2px var(--gold), 0 0 22px rgba(234, 181, 77, 0.5);
}

.site-credit {
  font-size: 0.92rem;
  font-style: italic;
  color: var(--dim);
  max-width: 64ch;
}

/* Shelf (several volumes) */
.shelf-head {
  margin-bottom: 24px;
}

.shelf-head h1 {
  font-size: clamp(2.2rem, 8vw, 3.4rem);
  margin-top: 4px;
}

.shelf-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 28px;
}

.volume-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-decoration: none;
}

.volume-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 12px;
  box-shadow: 0 0 0 1px rgba(244, 236, 216, 0.14), 0 16px 40px rgba(3, 6, 20, 0.6);
}

.volume-card h2 {
  font-size: 1.5rem;
  margin-top: 6px;
}

.volume-meta {
  font-family: var(--f-ui);
  font-size: 0.86rem;
  color: var(--dim);
}

/* Chapter */
.chapter-spread {
  display: flex;
  flex-direction: column;
  gap: 34px;
}

.chapter-left {
  display: flex;
  flex-direction: column;
  gap: 28px;
  min-width: 0;
}

.chapter-head h1 {
  font-size: clamp(2.2rem, 9vw, 3.4rem);
  margin-top: 4px;
  letter-spacing: -0.01em;
}

.chapter-collection-link {
  font-family: var(--f-serif);
  font-style: italic;
  font-size: 1rem;
  color: var(--gold);
  text-decoration: none;
}

.chapter-collection-link:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.chapter-media {
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 520px;
}

.chapter-media .btn {
  align-self: flex-start;
}

/* Lyrics */
.chapter-right {
  min-width: 0;
}

.lyrics-sections {
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.lyric-section-label {
  display: block;
  font-family: var(--f-serif);
  font-style: italic;
  font-size: 0.92rem;
  color: var(--gold);
  margin-bottom: 6px;
}

.lyric-stanza {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.lyric-stanza + .lyric-stanza {
  margin-top: 14px;
}

.lyric-line {
  font-size: 1.12rem;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.lyric-echo {
  font-size: 1rem;
  line-height: 1.6;
  font-style: italic;
  color: var(--dim);
  padding-left: 14px;
  overflow-wrap: anywhere;
}

.lyric-section.is-chorus {
  padding-left: 16px;
  border-left: 2px solid rgba(234, 181, 77, 0.55);
}

.lyric-section.is-chorus .lyric-line {
  font-style: italic;
  color: #fff6de;
}

/* Chapter prev / next */
.chapter-nav {
  padding-top: 20px;
  border-top: 1px solid var(--rule);
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.chapter-nav a {
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-decoration: none;
  max-width: 48%;
  overflow-wrap: anywhere;
  font-family: var(--f-display);
  font-size: 1.2rem;
  line-height: 1.2;
}

.chapter-nav small {
  font-family: var(--f-ui);
  font-size: 0.8rem;
  color: var(--dim);
}

.chapter-nav a:hover {
  color: var(--gold);
}

.chapter-nav-next {
  margin-left: auto;
  text-align: right;
}

/* Search and topics */
.index-head {
  margin-bottom: 20px;
}

.index-head h1 {
  font-size: clamp(2.2rem, 8vw, 3.2rem);
}

.search-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(244, 236, 216, 0.08);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 8px 18px;
  max-width: 58ch;
}

.search-wrap:focus-within {
  border-color: var(--gold);
}

.search-wrap svg {
  color: var(--dim);
  flex: none;
}

.search-input {
  width: 100%;
  border: 0;
  background: transparent;
  font-family: var(--f-serif);
  font-size: 1.08rem;
  color: var(--star);
  outline: none;
  padding: 6px 0;
}

.search-input::placeholder {
  color: var(--dim);
  font-style: italic;
}

.search-results {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  max-width: 64ch;
}

.search-empty {
  color: var(--dim);
  font-style: italic;
}

.search-hit {
  padding: 12px 0;
  border-top: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.search-hit-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 10px;
}

.search-source {
  font-style: italic;
  font-size: 0.88rem;
  color: #ffd9a8;
}

.search-hit-link {
  font-family: var(--f-display);
  font-size: 1.18rem;
  color: var(--gold);
  text-decoration: none;
}

.search-hit-link:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.search-hit-text {
  font-size: 1.04rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.topics-section {
  margin-top: 36px;
  max-width: 64ch;
}

.topic-letter {
  font-family: var(--f-display);
  font-style: italic;
  font-size: 2.2rem;
  color: var(--gold);
  line-height: 1;
  margin-top: 24px;
  margin-bottom: 10px;
}

.topic-group {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.topic-item h3 {
  font-size: 1.24rem;
  margin-bottom: 4px;
}

.topic-entries {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.topic-entries li {
  font-size: 0.98rem;
  color: var(--dim);
  line-height: 1.5;
}

.topic-entries a {
  color: var(--star);
  font-weight: 600;
  text-decoration: none;
}

.topic-entries a:hover {
  color: var(--gold);
  text-decoration: underline;
}

.topic-entries q {
  font-style: italic;
  quotes: none;
}

/* Player */
.player-bar {
  position: fixed;
  z-index: 40;
  left: max(12px, env(safe-area-inset-left, 0px));
  right: max(12px, env(safe-area-inset-right, 0px));
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  max-width: 720px;
  margin: 0 auto;
  min-height: 64px;
  border-radius: 20px;
  background: rgba(24, 36, 78, 0.86);
  -webkit-backdrop-filter: blur(18px) saturate(1.4);
  backdrop-filter: blur(18px) saturate(1.4);
  border: 1px solid rgba(244, 236, 216, 0.18);
  color: var(--star);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px 8px 8px;
  box-shadow: 0 16px 40px rgba(3, 6, 20, 0.7);
  font-family: var(--f-ui);
  overflow: hidden;
}

.player-bar[hidden] {
  display: none;
}

.player-progress {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  width: 100%;
  background: var(--gold);
  transform-origin: left center;
  transform: scaleX(var(--progress, 0));
}

.player-cover {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--night-3);
  flex: none;
}

.player-dot {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 0;
  background: var(--gold);
  color: #2a1c05;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  font-size: 1rem;
}

.player-meta {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.player-spoken {
  font-family: var(--f-serif);
  font-style: italic;
  font-size: 0.82rem;
  color: #ffd9a8;
  white-space: nowrap;
}

.player-spoken[hidden] {
  display: none;
}

.player-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-decoration: none;
  font-size: 0.96rem;
  font-weight: 700;
}

.player-time {
  font-size: 0.8rem;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  flex: none;
}

.player-nav {
  display: inline-flex;
  align-items: center;
  flex: none;
}

.player-step {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--star);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
}

.player-step:disabled {
  opacity: 0.3;
  cursor: default;
}

/* iPad and wider: two-page spread at >= 820px */
@media (min-width: 820px) {
  .page {
    padding-top: 28px;
  }

  .volume {
    display: grid;
    grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
    gap: 56px;
    align-items: start;
  }

  .volume-hero {
    position: sticky;
    top: 28px;
    max-width: none;
  }

  .chapter-spread {
    display: grid;
    grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
    gap: 40px 56px;
    align-items: start;
  }

  .chapter-media {
    max-width: none;
  }

  .chapter-right {
    padding-top: 8px;
  }

  .lyric-line {
    font-size: 1.2rem;
  }

  .chapter-nav {
    grid-column: 1 / -1;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .is-speaking .voice-wave i {
    animation: voice 0.9s ease-in-out infinite alternate;
  }

  .is-speaking .voice-wave i:nth-child(2n) {
    animation-delay: -0.3s;
  }

  .is-speaking .voice-wave i:nth-child(3n) {
    animation-delay: -0.6s;
  }
}

@keyframes voice {
  from { transform: scaleY(0.35); }
  to { transform: scaleY(1); }
}
