:root {
  --bg: #151313;
  --surface: #1c1816;
  --surface-raised: #26201d;
  --surface-soft: #221c19;
  --border: #3a2e29;
  --border-strong: #5a4639;
  --text: #eee8df;
  --text-soft: #d0c3b8;
  --text-dim: #a39487;
  --text-faint: #74675d;
  --accent: #d99758;
  --accent-strong: #edb477;
  --accent-dark: #4b2c1f;
  --gold: #d79a5a;
  --danger: #d17762;
  --radius: 12px;
  --serif: Georgia, "Iowan Old Style", "Palatino Linotype", ui-serif, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  background:
    radial-gradient(circle at 5% 0%, rgba(139, 79, 38, 0.2), transparent 30rem),
    radial-gradient(circle at 100% 20%, rgba(177, 102, 43, 0.13), transparent 25rem),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.5;
  min-height: 100vh;
}

body::before {
  background-image: radial-gradient(rgba(220, 166, 103, 0.08) 0.65px, transparent 0.65px);
  background-size: 17px 17px;
  content: "";
  inset: 0;
  opacity: 0.16;
  pointer-events: none;
  position: fixed;
  z-index: -1;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input {
  font-family: inherit;
}

button {
  cursor: pointer;
}

svg.icon {
  width: 1em;
  height: 1em;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -0.15em;
  flex-shrink: 0;
}

/* Navigation */

.topbar {
  padding: 20px 28px;
  position: relative;
  z-index: 2;
}

.topbar-inner {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin: 0 auto;
  max-width: 1100px;
}

.brand {
  align-items: center;
  color: var(--text);
  display: inline-flex;
  font-family: var(--serif);
  font-size: 1.18rem;
  gap: 10px;
  letter-spacing: -0.02em;
}

.brand-mark {
  align-items: center;
  background: var(--accent);
  border-radius: 8px 8px 8px 3px;
  color: var(--bg);
  display: inline-flex;
  font-family: var(--serif);
  font-size: 1.03rem;
  height: 28px;
  justify-content: center;
  line-height: 1;
  transform: rotate(-7deg);
  width: 28px;
}

.privacy-pill {
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-faint);
  display: inline-flex;
  font-size: 0.7rem;
  gap: 7px;
  padding: 6px 10px;
}

.privacy-dot,
.meta-dot {
  background: var(--accent);
  border-radius: 50%;
  display: inline-block;
  height: 6px;
  width: 6px;
}

/* General layout */

.app {
  margin: 0 auto;
  max-width: 1100px;
  padding: 35px 28px 80px;
}

/* Home */

.home-intro {
  animation: rise-in 0.6s both;
  margin: 12px 0 42px;
}

.home-intro p {
  color: var(--text-soft);
  font-family: var(--serif);
  font-size: 1.3rem;
  font-style: italic;
  margin: 0;
}

.library-toolbar {
  align-items: center;
  border-bottom: 1px solid var(--border);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  margin-bottom: 28px;
  padding: 14px 0;
}

.toolbar-label {
  color: var(--text);
  font-family: var(--serif);
  font-size: 1.1rem;
}

.search-row {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-faint);
  display: flex;
  gap: 9px;
  padding: 8px 13px;
  transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  width: min(100%, 270px);
}

.search-row:focus-within {
  background: var(--surface-raised);
  border-color: var(--border-strong);
  box-shadow: 0 0 0 3px rgba(217, 151, 88, 0.1);
}

.search-row input {
  background: transparent;
  border: 0;
  color: var(--text);
  font-size: 0.83rem;
  min-width: 0;
  outline: 0;
  width: 100%;
}

.search-row input::placeholder {
  color: var(--text-faint);
}

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

.book-card {
  animation: rise-in 0.5s calc(var(--card-index) * 55ms) both;
  display: block;
  min-width: 0;
}

.book-cover {
  aspect-ratio: 0.73;
  background:
    linear-gradient(145deg, rgba(217, 151, 88, 0.16), transparent 55%),
    var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  isolation: isolate;
  overflow: hidden;
  position: relative;
  transform: translateZ(0);
  transition: border-color 0.3s ease, box-shadow 0.3s ease, transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.book-cover::after {
  background: linear-gradient(150deg, transparent 25%, rgba(244, 222, 195, 0.1) 50%, transparent 70%);
  content: "";
  inset: 0;
  opacity: 0;
  position: absolute;
  transform: translateX(-100%);
  transition: opacity 0.2s ease, transform 0.7s ease;
  z-index: 1;
}

.book-card:hover .book-cover,
.book-card:focus-visible .book-cover {
  border-color: var(--border-strong);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.2);
  transform: translateY(-5px);
}

.book-card:hover .book-cover::after,
.book-card:focus-visible .book-cover::after {
  opacity: 1;
  transform: translateX(100%);
}

.book-cover img {
  display: block;
  height: 100%;
  object-fit: cover;
  width: 100%;
}

.book-cover .placeholder-icon {
  align-self: center;
  color: var(--text-faint);
  font-size: 2.3rem;
  margin: auto;
}

.cover-placeholder {
  align-items: center;
  display: flex;
  justify-content: center;
  margin: auto;
}

.cover-action {
  align-items: center;
  background: rgba(21, 19, 19, 0.92);
  border: 1px solid rgba(217, 151, 88, 0.4);
  border-radius: 999px;
  bottom: 12px;
  color: var(--accent-strong);
  display: inline-flex;
  font-size: 0.7rem;
  font-weight: 600;
  gap: 6px;
  left: 12px;
  opacity: 0;
  padding: 7px 10px;
  position: absolute;
  transform: translateY(6px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 2;
}

.cover-action .icon {
  font-size: 0.8rem;
}

.book-card:hover .cover-action,
.book-card:focus-visible .cover-action {
  opacity: 1;
  transform: translateY(0);
}

.book-card-footer {
  align-items: flex-start;
  display: flex;
  gap: 8px;
  justify-content: space-between;
  padding: 11px 1px 0;
}

.book-title {
  color: var(--text);
  font-family: var(--serif);
  font-size: 0.96rem;
  line-height: 1.3;
}

.book-card-arrow {
  color: var(--text-faint);
  font-size: 0.95rem;
  transition: color 0.2s ease, transform 0.2s ease;
}

.book-card:hover .book-card-arrow {
  color: var(--accent);
  transform: translate(2px, -2px);
}

/* Book page */

.back-link {
  align-items: center;
  color: var(--text-dim);
  display: inline-flex;
  font-size: 0.8rem;
  gap: 6px;
  margin-bottom: 34px;
  transition: color 0.2s ease, transform 0.2s ease;
}

.back-link:hover {
  color: var(--text);
  transform: translateX(-3px);
}

.book-header {
  align-items: center;
  animation: rise-in 0.6s both;
  display: flex;
  gap: clamp(26px, 6vw, 64px);
  margin-bottom: 68px;
}

.book-header .book-cover {
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.22);
  flex-shrink: 0;
  width: 210px;
}

.book-header-info {
  max-width: 570px;
}

.book-header-info .eyebrow,
.section-heading .eyebrow {
  color: var(--accent);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.book-header-info h1 {
  color: var(--text);
  font-family: var(--serif);
  font-size: clamp(2.4rem, 5vw, 4rem);
  font-weight: 400;
  letter-spacing: -0.06em;
  line-height: 0.97;
  margin: 15px 0 15px;
}

.book-subtitle {
  color: var(--text-dim);
  font-size: 0.9rem;
  margin: 0 0 20px;
}

.progress-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  max-width: 450px;
  padding: 13px 15px;
}

.progress-summary {
  align-items: center;
  color: var(--text-dim);
  display: flex;
  font-size: 0.76rem;
  gap: 8px;
  margin-bottom: 10px;
}

.progress-summary strong {
  color: var(--text);
  font-weight: 600;
}

.progress-icon {
  align-items: center;
  background: var(--accent-dark);
  border-radius: 50%;
  color: var(--accent);
  display: inline-flex;
  font-size: 0.67rem;
  height: 22px;
  justify-content: center;
  width: 22px;
}

.progress-percent {
  color: var(--accent);
  font-size: 0.7rem;
  font-weight: 600;
  margin-left: auto;
}

.progress-bar-track {
  background: var(--surface-raised);
  border-radius: 99px;
  display: block;
  height: 4px;
  overflow: hidden;
  width: 100%;
}

.progress-bar-fill {
  background: var(--accent);
  border-radius: inherit;
  display: block;
  height: 100%;
  transition: width 0.45s ease;
}

.autoplay-toggle {
  align-items: center;
  color: var(--text-dim);
  cursor: pointer;
  display: inline-flex;
  font-size: 0.76rem;
  gap: 8px;
  margin-top: 16px;
  user-select: none;
}

.autoplay-toggle input {
  height: 1px;
  opacity: 0;
  position: absolute;
  width: 1px;
}

.custom-checkbox {
  align-items: center;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  color: transparent;
  display: inline-flex;
  height: 17px;
  justify-content: center;
  transition: background 0.2s ease, border-color 0.2s ease;
  width: 17px;
}

.custom-checkbox .icon {
  font-size: 0.68rem;
  stroke-width: 3;
}

.autoplay-toggle input:checked + .custom-checkbox {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
}

.section-heading {
  align-items: flex-end;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 14px;
}

.section-heading h2 {
  color: var(--text);
  font-family: var(--serif);
  font-size: 1.85rem;
  font-weight: 400;
  letter-spacing: -0.04em;
  line-height: 1;
  margin: 8px 0 0;
}

.episode-count {
  color: var(--text-dim);
  font-size: 0.74rem;
  padding-bottom: 2px;
}

.episode-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.episode {
  animation: rise-in 0.45s calc(var(--episode-index) * 50ms) both;
  background: rgba(28, 24, 22, 0.78);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  transition: background 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}

.episode:hover {
  background: var(--surface);
  border-color: var(--border-strong);
}

.episode.is-active {
  background: var(--surface);
  border-color: #71513c;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
}

.episode-row {
  align-items: center;
  cursor: pointer;
  display: flex;
  gap: 13px;
}

.episode-mark-btn {
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: 50%;
  color: var(--text-faint);
  display: flex;
  font-size: 1.02rem;
  justify-content: center;
  padding: 0;
  transition: color 0.2s ease, transform 0.2s ease;
}

.episode-mark-btn:hover {
  color: var(--accent);
  transform: scale(1.1);
}

.episode-mark-btn.is-done {
  color: var(--accent);
}

.episode-copy {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
}

.episode-number {
  color: var(--text-faint);
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  margin-bottom: 2px;
  text-transform: uppercase;
}

.episode-title {
  color: var(--text-soft);
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.episode-play-btn {
  align-items: center;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--accent);
  display: flex;
  flex-shrink: 0;
  font-size: 0.9rem;
  height: 36px;
  justify-content: center;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease, transform 0.2s ease;
  width: 36px;
}

.episode-play-btn:hover,
.episode-play-btn.is-playing {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
  transform: scale(1.05);
}

/* Audio player */

.player {
  align-items: center;
  animation: player-in 0.35s both;
  display: flex;
  gap: 9px;
  margin-top: 14px;
  padding: 0 3px 1px 4px;
}

.player-live {
  align-items: center;
  display: flex;
  gap: 2px;
  height: 17px;
  justify-content: center;
  width: 13px;
}

.player-live span {
  background: var(--gold);
  border-radius: 99px;
  height: 5px;
  width: 2px;
}

.player.is-playing .player-live span {
  animation: sound-wave 0.9s ease-in-out infinite alternate;
}

.player.is-playing .player-live span:nth-child(2) {
  animation-delay: -0.35s;
}

.player.is-playing .player-live span:nth-child(3) {
  animation-delay: -0.65s;
}

.player-time {
  color: var(--text-faint);
  font-size: 0.69rem;
  font-variant-numeric: tabular-nums;
  min-width: 31px;
}

.player-time.end {
  text-align: right;
}

.player-seek,
.player-volume input {
  -webkit-appearance: none;
  appearance: none;
  background: var(--surface-raised);
  border-radius: 99px;
  height: 4px;
  outline: none;
}

.player-seek {
  flex: 1;
}

.player-seek::-webkit-slider-thumb,
.player-volume input::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  background: var(--accent);
  border: 2px solid var(--surface);
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  height: 12px;
  width: 12px;
}

.player-seek::-moz-range-thumb,
.player-volume input::-moz-range-thumb {
  background: var(--accent);
  border: 2px solid var(--surface);
  border-radius: 50%;
  cursor: pointer;
  height: 9px;
  width: 9px;
}

.player-volume {
  align-items: center;
  color: var(--text-faint);
  display: flex;
  gap: 6px;
  margin-left: 6px;
}

.player-volume input {
  width: 52px;
}

/* States and feedback */

.empty-state {
  color: var(--text-dim);
  padding: 60px 20px;
  text-align: center;
}

.empty-state svg.icon {
  color: var(--text-faint);
  display: block;
  font-size: 2rem;
  margin: 0 auto 12px;
}

.empty-state p {
  margin: 0 auto;
  max-width: 400px;
}

.loading-state {
  color: var(--text-dim);
  min-height: 220px;
  padding: 80px 0;
  text-align: center;
}

.loading-state::after {
  animation: loading-pulse 1.2s ease-in-out infinite;
  background: var(--accent);
  border-radius: 99px;
  content: "";
  display: block;
  height: 3px;
  margin: 13px auto 0;
  width: 34px;
}

.toast-root {
  bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  left: 50%;
  position: fixed;
  transform: translateX(-50%);
  z-index: 100;
}

.toast {
  align-items: center;
  background: #2b2420;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.3);
  color: var(--text);
  display: flex;
  font-size: 0.81rem;
  gap: 9px;
  max-width: 360px;
  padding: 11px 14px;
}

.toast .icon {
  color: var(--gold);
}

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

/* Motion */

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes player-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes sound-wave {
  from {
    height: 4px;
  }
  to {
    height: 15px;
  }
}

@keyframes loading-pulse {
  0%,
  100% {
    opacity: 0.25;
    transform: scaleX(0.7);
  }
  50% {
    opacity: 1;
    transform: scaleX(1);
  }
}

/* Responsive */

@media (max-width: 700px) {
  .topbar {
    padding: 18px 18px;
  }

  .privacy-pill {
    font-size: 0;
    padding: 7px;
  }

  .privacy-dot {
    height: 7px;
    width: 7px;
  }

  .app {
    padding: 28px 18px 64px;
  }

  .home-intro {
    margin-bottom: 34px;
  }

  .library-toolbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 14px;
  }

  .search-row {
    width: 100%;
  }

  .book-grid {
    gap: 23px 13px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .book-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 24px;
    margin-bottom: 55px;
  }

  .book-header .book-cover {
    width: min(48vw, 185px);
  }

  .book-header-info h1 {
    font-size: clamp(2.5rem, 12vw, 3.8rem);
  }

  .section-heading h2 {
    font-size: 1.65rem;
  }

  .player-volume {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}