:root {
  --reader-ink: #173e5c;
  --reader-blue: #254e70;
  --reader-coral: #ff6b6b;
  --reader-yellow: #ffdd59;
  --reader-mint: #14b8a6;
  --reader-bg: #fff8ed;
  --reader-card: #ffffff;
  --reader-soft: #f3fafd;
  --reader-border: rgba(37, 78, 112, 0.12);
  --reader-shadow: 0 18px 42px rgba(37, 78, 112, 0.12);
  font-family: "DM Sans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--reader-bg);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--reader-ink);
  background:
    radial-gradient(circle at top left, rgba(255, 221, 89, 0.28), transparent 32rem),
    radial-gradient(circle at bottom right, rgba(20, 184, 166, 0.18), transparent 28rem),
    var(--reader-bg);
}

[hidden] {
  display: none !important;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
}

.skip-link {
  position: fixed;
  left: 1rem;
  top: 1rem;
  z-index: 20;
  transform: translateY(-150%);
  padding: 0.7rem 1rem;
  border-radius: 999px;
  background: var(--reader-blue);
  color: #fff;
  font-weight: 800;
  text-decoration: none;
}

.skip-link:focus {
  transform: translateY(0);
}

.reader-shell {
  width: min(1180px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 1rem;
}

.reader-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.reader-brand,
.reader-library-link {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 44px;
  color: var(--reader-blue);
  font-weight: 900;
  text-decoration: none;
}

.reader-brand span {
  font-family: "Nunito", sans-serif;
  font-size: 1.05rem;
}

.reader-brand img {
  border-radius: 12px;
}

.reader-header__actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.reader-library-link,
.reader-icon-btn {
  padding: 0.55rem 0.8rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 8px 20px rgba(37, 78, 112, 0.08);
}

.reader-icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  color: var(--reader-blue);
  cursor: pointer;
}

.reader-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.18fr) minmax(320px, 0.82fr);
  gap: 1rem;
  align-items: stretch;
}

.reader-art-panel,
.reader-story-panel {
  border: 1px solid var(--reader-border);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: var(--reader-shadow);
}

.reader-art-panel {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  min-height: 520px;
  padding: 0.8rem;
}

.reader-progress-row {
  display: grid;
  grid-template-columns: auto minmax(120px, 1fr);
  align-items: center;
  gap: 0.75rem;
  padding: 0.15rem 0.2rem;
  font-weight: 900;
  color: var(--reader-blue);
}

.reader-progress-bar {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8f0f5;
}

.reader-progress-bar span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--reader-yellow), var(--reader-coral));
  transition: width 0.28s ease;
}

.reader-figure {
  position: relative;
  display: grid;
  flex: 1;
  place-items: center;
  min-height: 420px;
  margin: 0;
  overflow: hidden;
  border-radius: 20px;
  background: #fff;
}

.reader-figure.is-changing img,
.reader-story-text.is-changing {
  opacity: 0;
  transform: translateY(8px) scale(0.99);
}

.reader-figure img {
  display: block;
  width: 100%;
  height: 100%;
  max-height: calc(100vh - 190px);
  object-fit: contain;
  padding: 0;
  transition:
    opacity 0.24s ease,
    transform 0.24s ease;
}

.reader-figure figcaption {
  position: absolute;
  left: 1rem;
  bottom: 1rem;
  max-width: calc(100% - 2rem);
  padding: 0.4rem 0.65rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--reader-blue);
  font-size: 0.82rem;
  font-weight: 800;
}

.reader-image-state {
  position: absolute;
  inset: 1rem;
  display: grid;
  place-items: center;
  padding: 1rem;
  border: 2px dashed rgba(37, 78, 112, 0.2);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--reader-blue);
  text-align: center;
  font-weight: 800;
}

.reader-story-panel {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 1rem;
}

.reader-eyebrow,
.reader-text-label {
  margin: 0 0 0.3rem;
  color: var(--reader-coral);
  font-size: 0.8rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.reader-book-meta h1 {
  margin: 0;
  color: var(--reader-blue);
  font-family: "Nunito", sans-serif;
  font-size: clamp(1.55rem, 4vw, 2.3rem);
  line-height: 1.04;
}

.reader-book-meta p:last-child {
  margin: 0.45rem 0 0;
  color: #526978;
  font-weight: 600;
}

.reader-text-card,
.reader-audio-card {
  border: 1px solid var(--reader-border);
  border-radius: 18px;
  background: #fff;
}

.reader-text-card {
  flex: 1;
  padding: 1rem;
}

.reader-story-text {
  min-height: 150px;
  color: #263f50;
  font-size: clamp(1.08rem, 2.5vw, 1.32rem);
  font-weight: 700;
  line-height: 1.65;
  transition:
    opacity 0.24s ease,
    transform 0.24s ease;
}

.reader-story-text .read-segment {
  display: inline;
  padding: 0.05rem 0.08rem;
  border-radius: 0.35rem;
  transition:
    background-color 0.16s ease,
    box-shadow 0.16s ease,
    color 0.16s ease;
}

.reader-story-text .read-segment.is-read {
  background: rgba(20, 184, 166, 0.14);
  color: #163f4f;
}

.reader-story-text .read-segment.is-active {
  background: rgba(255, 221, 89, 0.62);
  box-shadow: 0 0 0 2px rgba(255, 221, 89, 0.36);
  color: #173e5c;
}

.reader-audio-card {
  padding: 0.8rem;
}

.reader-time-row {
  display: grid;
  grid-template-columns: auto minmax(120px, 1fr) auto;
  align-items: center;
  gap: 0.65rem;
  color: var(--reader-blue);
  font-size: 0.9rem;
  font-weight: 900;
}

#seekBar {
  width: 100%;
  accent-color: var(--reader-coral);
}

.reader-audio-error {
  margin: 0.7rem 0 0;
  padding: 0.65rem;
  border-radius: 12px;
  background: #fff7dc;
  color: #7b5b00;
  font-weight: 800;
}

.reader-controls {
  display: grid;
  grid-template-columns: 1fr 1.15fr 1fr;
  gap: 0.65rem;
}

.reader-control-btn,
.reader-play-btn,
.reader-primary-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 54px;
  padding: 0.75rem 0.9rem;
  border-radius: 18px;
  font-weight: 900;
  text-decoration: none;
  cursor: pointer;
  transition:
    transform 0.16s ease,
    box-shadow 0.2s ease,
    opacity 0.2s ease;
}

.reader-control-btn--secondary {
  background: #e9fbf7;
  color: #08776a;
}

.reader-play-btn,
.reader-primary-link {
  background: var(--reader-coral);
  color: #fff;
  box-shadow: 0 12px 24px rgba(255, 107, 107, 0.2);
}

.reader-play-btn span:first-child {
  font-size: 1.2rem;
}

.reader-control-btn:disabled,
.reader-play-btn:disabled {
  opacity: 0.48;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.reader-control-btn:not(:disabled):hover,
.reader-play-btn:not(:disabled):hover,
.reader-primary-link:hover,
.reader-icon-btn:hover,
.reader-library-link:hover {
  transform: translateY(-2px);
}

.reader-control-btn:not(:disabled):active,
.reader-play-btn:not(:disabled):active {
  transform: scale(0.98);
}

.reader-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.reader-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 44px;
  padding: 0.45rem 0.7rem;
  border-radius: 999px;
  background: var(--reader-soft);
  color: var(--reader-blue);
  font-weight: 800;
}

.reader-toggle input {
  width: 1.1rem;
  height: 1.1rem;
  accent-color: var(--reader-mint);
}

.reader-loading,
.reader-error {
  width: min(620px, 100%);
  margin: 14vh auto 0;
  padding: 1.4rem;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--reader-shadow);
  text-align: center;
}

.reader-error h1 {
  margin: 0 0 0.5rem;
  color: var(--reader-blue);
  font-family: "Nunito", sans-serif;
}

.reader-spinner {
  width: 48px;
  height: 48px;
  margin: 0 auto 0.8rem;
  border: 5px solid #e8f0f5;
  border-top-color: var(--reader-coral);
  border-radius: 50%;
  animation: reader-spin 0.8s linear infinite;
}

@keyframes reader-spin {
  to {
    transform: rotate(360deg);
  }
}

:focus-visible {
  outline: 3px solid rgba(37, 78, 112, 0.26);
  outline-offset: 3px;
}

@media (max-width: 900px) {
  .reader-layout {
    grid-template-columns: 1fr;
  }

  .reader-art-panel {
    min-height: 0;
  }

  .reader-figure {
    min-height: min(68vh, 520px);
  }
}

@media (max-width: 560px) {
  .reader-shell {
    padding: 0.75rem;
  }

  .reader-header {
    align-items: flex-start;
  }

  .reader-brand span {
    max-width: 9rem;
    line-height: 1.05;
  }

  .reader-library-link {
    display: none;
  }

  .reader-progress-row,
  .reader-time-row,
  .reader-controls {
    grid-template-columns: 1fr;
  }

  .reader-progress-row {
    gap: 0.45rem;
  }

  .reader-controls {
    grid-template-areas:
      "play"
      "next"
      "prev";
  }

  #playPauseBtn {
    grid-area: play;
  }

  #nextBtn {
    grid-area: next;
  }

  #prevBtn {
    grid-area: prev;
  }

  .reader-figure {
    min-height: 360px;
  }

  .reader-figure figcaption {
    font-size: 0.76rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
