:root {
  --cream: #FFF8EE;
  --warm: #FFF0D6;
  --warm-hover: #FFE4B5;
  --amber: #F5A623;
  --amber-dark: #D4861A;
  --brown: #5C3D1E;
  --brown-light: #8B6343;
  --green: #4CAF7D;
  --green-dark: #3A9063;
  --red: #E05C5C;
  --blue: #5B9BD5;
  --purple: #9B7FD4;
  --shadow: rgba(92, 61, 30, 0.15);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-user-select: none; user-select: none; }

html, body {
  touch-action: pan-y;
  overscroll-behavior-y: none;
}

body {
  font-family: 'Nunito', sans-serif;
  background-color: var(--cream);
  background-image:
    radial-gradient(circle at 10% 20%, rgba(245,166,35,0.08) 0%, transparent 50%),
    radial-gradient(circle at 90% 80%, rgba(76,175,125,0.08) 0%, transparent 50%),
    url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%235C3D1E' fill-opacity='0.03'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  min-height: 100vh;
  color: var(--brown);
}

/* ── PIN screen ──────────────────────────────────────────────── */
#pin-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
  animation: fadeIn 0.5s ease;
}

.pin-dots {
  display: flex;
  gap: 1rem;
  margin: 2rem 0 2.5rem;
}

.pin-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--warm);
  border: 2px solid var(--amber);
  transition: background 0.15s, transform 0.1s;
}

.pin-dot.filled {
  background: var(--amber);
  transform: scale(1.15);
}

.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  width: min(300px, 90vw);
}

.pin-btn {
  background: white;
  border: 2px solid var(--warm);
  border-radius: 16px;
  font-family: 'Nunito', sans-serif;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--brown);
  padding: 1rem;
  cursor: pointer;
  box-shadow: 0 3px 10px var(--shadow);
  transition: background 0.1s, transform 0.1s, box-shadow 0.1s;
  min-height: 72px;
}

.pin-btn:hover  { background: var(--warm); }
.pin-btn:active { transform: scale(0.93); box-shadow: none; }

.pin-btn-ghost { background: transparent; border-color: transparent; box-shadow: none; cursor: default; }
.pin-btn-ghost:hover { background: transparent; }
.pin-btn-del { color: var(--brown-light); font-size: 1.3rem; }

.pin-error {
  margin-top: 1.5rem;
  color: var(--red);
  font-weight: 700;
  font-size: 0.95rem;
  min-height: 1.4rem;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60%  { transform: translateX(-8px); }
  40%, 80%  { transform: translateX(8px); }
}

.pin-dots.shake { animation: shake 0.4s ease; }

/* ── Scan button (library header) ────────────────────────────── */
.scan-btn {
  background: var(--warm);
  border: none;
  border-radius: 12px;
  padding: 0.5rem 0.75rem;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--brown);
  transition: background 0.15s, transform 0.2s;
}

#stats-btn { font-size: 1.02rem; }

.scan-btn:hover    { background: var(--warm-hover); }
.scan-btn.spinning { animation: spin 1s linear infinite; }

/* ── iOS install banner ──────────────────────────────────────── */
#new-books-banner {
  display: flex;
  position: fixed;
  top: 1rem;
  left: 1rem;
  right: 1rem;
  background: white;
  border-radius: 16px;
  padding: 1rem 1.25rem;
  box-shadow: 0 8px 32px var(--shadow);
  z-index: 200;
  align-items: center;
  gap: 0.75rem;
  border: 2px solid var(--green);
  transform: translateY(calc(-100% - 2rem));
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
}
#new-books-banner.visible {
  transform: translateY(0);
  pointer-events: auto;
}
#new-books-banner { cursor: pointer; padding: 0.75rem 1rem; }
#new-books-banner-cover-wrap {
  width: 48px; height: 48px; border-radius: 10px; flex-shrink: 0;
  background: var(--warm); overflow: hidden;
  display: flex; align-items: center; justify-content: center; font-size: 1.5rem;
}
#new-books-banner-img {
  width: 100%; height: 100%; object-fit: cover; display: none;
}
#new-books-banner-img.loaded { display: block; }
#new-books-banner-img.loaded ~ #new-books-banner-fallback { display: none; }
#new-books-banner-info { flex: 1; min-width: 0; }
#new-books-banner-label {
  font-size: 0.68rem; font-weight: 800; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--green); margin-bottom: 0.1rem;
}
#new-books-banner-title {
  font-size: 0.88rem; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--brown);
}
#new-books-banner-sub { font-size: 0.75rem; color: var(--brown-light); margin-top: 0.05rem; }
#new-books-banner button {
  background: none; border: none; font-size: 1.3rem;
  cursor: pointer; color: var(--brown-light); padding: 0.25rem; flex-shrink: 0;
}

#ios-banner {
  display: none;
  position: fixed;
  bottom: 1rem;
  left: 1rem;
  right: 1rem;
  background: white;
  border-radius: 16px;
  padding: 1rem 1.25rem;
  box-shadow: 0 8px 32px var(--shadow);
  z-index: 100;
  align-items: center;
  gap: 0.75rem;
  border: 2px solid var(--warm);
}
#ios-banner p { flex: 1; font-size: 0.9rem; color: var(--brown); line-height: 1.4; }
#ios-banner button {
  background: none; border: none; font-size: 1.4rem;
  cursor: pointer; color: var(--brown-light); padding: 0.25rem;
}

/* ── Setup screen ────────────────────────────────────────────── */
#setup-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
  animation: fadeIn 0.6s ease;
}

#setup-screen .profile-cards {
  flex-wrap: wrap;
  gap: 1.25rem;
}

.setup-card-both .profile-avatar {
  letter-spacing: -0.5rem;
}

/* ── Profile screen ──────────────────────────────────────────── */
#profile-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
  animation: fadeIn 0.6s ease;
}

.profile-title {
  font-family: 'Playfair Display', serif;
  font-size: clamp(2.5rem, 6vw, 4rem);
  color: var(--brown);
  text-align: center;
  margin-bottom: 0.4rem;
  line-height: 1.1;
}

.profile-subtitle {
  font-size: 1.1rem;
  color: var(--brown-light);
  margin-bottom: 3rem;
  text-align: center;
}

.profile-cards {
  display: flex;
  gap: 2rem;
  flex-wrap: wrap;
  justify-content: center;
}

.profile-card {
  background: white;
  border-radius: 24px;
  padding: 2.5rem 2rem;
  width: 200px;
  text-align: center;
  cursor: pointer;
  box-shadow: 0 6px 24px var(--shadow), 0 2px 8px var(--shadow);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  border: 3px solid transparent;
  position: relative;
  overflow: hidden;
}

.profile-card::before {
  content: '';
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 0.2s;
  border-radius: 21px;
}

.profile-card[data-color="amber"]::before { background: rgba(245,166,35,0.06); }
.profile-card[data-color="purple"]::before { background: rgba(155,127,212,0.06); }

.profile-card:hover {
  transform: translateY(-6px) scale(1.02);
  box-shadow: 0 16px 40px var(--shadow);
}

.profile-card:hover::before { opacity: 1; }

.profile-avatar {
  font-size: 4rem;
  margin-bottom: 1rem;
  display: block;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.1));
}

.profile-name { font-size: 1.4rem; font-weight: 900; color: var(--brown); }
.profile-age { font-size: 0.9rem; color: var(--brown-light); margin-top: 0.2rem; }

.profile-badge {
  display: inline-block;
  margin-top: 0.8rem;
  padding: 0.25rem 0.8rem;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 700;
}

[data-color="amber"] .profile-badge { background: rgba(245,166,35,0.15); color: var(--amber-dark); }
[data-color="purple"] .profile-badge { background: rgba(155,127,212,0.15); color: #7B5FB4; }


/* ── Collection cards (library view) ─────────────────────────── */
.collection-card {
  cursor: pointer;
  transition: transform 0.2s ease;
  animation: popIn 0.4s ease backwards;
  min-width: 0;
}

.collection-card:hover { transform: translateY(-4px); }

.collection-card.archived, .book-card.archived { opacity: 0.55; }
.collection-card.archived:hover, .book-card.archived:hover { opacity: 1; }

/* ── Collection screen archive button ────────────────────────── */
.coll-archive-btn {
  background: none;
  border: none;
  padding: 0.15rem 0;
  font-family: 'Nunito', sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--brown-light);
  cursor: pointer;
  transition: color 0.15s;
  display: block;
}
.coll-archive-btn:hover { color: var(--red); }

.archived-section-toggle {
  grid-column: 1 / -1;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--brown-light);
  padding: 0.75rem 0 0.25rem;
  text-align: left;
  margin-top: 0.5rem;
}
.archived-section-toggle:hover { color: var(--brown); }

.collection-cover {
  width: 100%;
  aspect-ratio: 1/1;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Stacked-books shadow effect */
  box-shadow:
    8px 8px 0 rgba(92,61,30,0.07),
    5px 5px 0 rgba(92,61,30,0.09),
    0 8px 24px var(--shadow);
  margin-bottom: 0.75rem;
  position: relative;
  overflow: hidden;
  background: var(--warm);
}

.collection-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 12px;
}

.collection-count-badge {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: var(--amber);
  color: white;
  font-size: 0.75rem;
  font-weight: 800;
  padding: 0.2rem 0.55rem;
  border-radius: 8px;
  min-width: 1.6rem;
  text-align: center;
}

/* ── Collection screen ───────────────────────────────────────── */
#collection-screen {
  display: none;
  min-height: 100vh;
  padding: 0 0 6rem;
  animation: fadeIn 0.3s ease;
}

/* ── Library screen ──────────────────────────────────────────── */
#library-screen {
  display: none;
  min-height: 100vh;
  padding: 0 0 6rem;
  animation: fadeIn 0.4s ease;
}

.library-header {
  background: white;
  padding: 1.2rem 2rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: 0 2px 12px var(--shadow);
  position: sticky;
  top: 0;
  z-index: 10;
}

.back-btn {
  background: var(--warm);
  border: none;
  border-radius: 12px;
  padding: 0.5rem 1rem;
  cursor: pointer;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 1rem;
  color: var(--brown);
  transition: background 0.15s;
}

.back-btn:hover { background: var(--warm-hover); }

.library-user {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-left: auto;
}

.library-user-avatar { font-size: 1.8rem; }
.library-user-name { font-weight: 900; font-size: 1.1rem; color: var(--brown); }

.library-title-wrap { padding: 2.5rem 2rem 1rem; }

#stats-panel {
  position: fixed;
  left: 0;
  right: 0;
  z-index: 200;
  background: white;
  border-bottom: 2px solid var(--warm);
  box-shadow: 0 6px 24px rgba(0,0,0,0.13);
  padding: 1rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  max-height: 70vh;
  overflow-y: auto;
}

#stats-backdrop {
  position: fixed;
  inset: 0;
  z-index: 199;
}

.stats-top-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.stats-cover {
  width: 28px;
  height: 28px;
  border-radius: 5px;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--warm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.stats-cover img { width: 100%; height: 100%; object-fit: cover; }
.stats-cover .book-cover-fallback { font-size: 0.9rem; }

.stats-top-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--brown);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.stats-empty {
  font-size: 0.8rem;
  color: var(--brown-light);
  font-style: italic;
}

.library-heading {
  font-family: 'Playfair Display', serif;
  font-size: clamp(1.8rem, 4vw, 2.5rem);
  color: var(--brown);
  margin-bottom: 0.3rem;
}

.library-count { color: var(--brown-light); font-size: 0.95rem; }

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1.5rem;
  padding: 1.5rem 2rem 2rem;
}

.book-card {
  cursor: pointer;
  transition: transform 0.2s ease;
  animation: popIn 0.4s ease backwards;
  min-width: 0;
}

.book-card:hover { transform: translateY(-4px); }

.book-cover {
  width: 100%;
  aspect-ratio: 1/1;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 20px var(--shadow), 3px 3px 0 rgba(0,0,0,0.06);
  margin-bottom: 0.75rem;
  position: relative;
  overflow: hidden;
  background: var(--warm);
}

.book-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 12px;
}

.book-cover-fallback {
  font-size: 3rem;
  opacity: 0.5;
}

.book-badge {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  font-size: 0.72rem;
  font-weight: 800;
  padding: 0.2rem 0.5rem;
  border-radius: 8px;
  line-height: 1;
}
.book-badge.completed   { background: var(--green);  color: white; }
.book-badge.in-progress { background: var(--amber);  color: white; }
.book-badge.not-started { background: rgba(92,61,30,0.1); color: var(--brown-light); letter-spacing: 0.02em; }

/* ── Collection filter bar ────────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 0.5rem;
  padding: 0 2rem 1.25rem;
  flex-wrap: wrap;
}

.filter-pill {
  background: var(--warm);
  border: 2px solid transparent;
  border-radius: 20px;
  padding: 0.35rem 0.9rem;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--brown-light);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.filter-pill:hover { background: var(--warm-hover); color: var(--brown); }
.filter-pill.active { background: white; color: var(--brown); }
.filter-pill[data-filter="all"].active        { border-color: var(--brown-light); }
.filter-pill[data-filter="not-started"].active { border-color: var(--brown-light); }
.filter-pill[data-filter="in-progress"].active { border-color: var(--amber); }
.filter-pill[data-filter="completed"].active   { border-color: var(--green); }

.coll-empty {
  grid-column: 1 / -1;
  padding: 2rem;
  text-align: center;
  color: var(--brown-light);
  font-size: 0.95rem;
}

.book-progress-wrap {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: rgba(255,255,255,0.4);
}

.book-progress-fill {
  height: 4px;
  background: var(--green);
}

.book-title { font-weight: 800; font-size: 0.9rem; color: var(--brown); line-height: 1.3; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.book-author { font-size: 0.78rem; color: var(--brown-light); margin-top: 0.15rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

.book-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.3rem;
}

.book-duration { font-size: 0.75rem; color: var(--brown-light); }

.book-status-chip {
  font-size: 0.68rem;
  font-weight: 800;
  padding: 0.15rem 0.45rem;
  border-radius: 6px;
  white-space: nowrap;
}
.book-status-chip.completed   { background: rgba(76,175,125,0.15);  color: var(--green-dark); }
.book-status-chip.in-progress { background: rgba(245,166,35,0.15);  color: var(--amber-dark); }
.book-status-chip.not-started { background: rgba(92,61,30,0.07);    color: var(--brown-light); }
.book-status-chip.not-started.is-new { background: var(--amber); color: white; animation: pulse-new 1.8s ease-in-out infinite; }
@keyframes pulse-new { 0%,100% { opacity:1; } 50% { opacity:0.7; } }

.download-btn {
  background: var(--warm);
  border: none;
  border-radius: 8px;
  padding: 0.23rem 0.575rem;
  font-size: 0.98rem;
  cursor: pointer;
  color: var(--brown);
  transition: background 0.15s;
  display: flex;
  align-items: center;
  gap: 0.2rem;
}

.download-btn:hover { background: var(--warm-hover); }
.download-btn.downloaded { color: var(--green); }
.download-btn.downloading {
  background: conic-gradient(var(--amber) var(--dl-pct, 0deg), var(--warm) var(--dl-pct, 0deg));
  color: transparent;
  font-size: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  padding: 0;
}

/* ── Continue listening ──────────────────────────────────────── */
#continue-section {
  padding: 1.5rem 2rem 0.5rem;
}

.continue-box {
  background: white;
  border-radius: 16px;
  border: 1.5px solid var(--warm);
  box-shadow: 0 2px 12px var(--shadow);
  overflow: hidden;
}

.continue-heading {
  font-family: 'Nunito', sans-serif;
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--brown-light);
  padding: 0.9rem 1.25rem 0.5rem;
}

.continue-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0 0 0.5rem;
}

.continue-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  cursor: pointer;
  transition: background 0.15s;
}

.continue-card:hover { background: var(--warm); }

.continue-cover {
  width: 56px;
  height: 56px;
  border-radius: 10px;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--warm);
  box-shadow: 0 3px 10px var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
}

.continue-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.continue-cover .book-cover-fallback { font-size: 1.6rem; }

.continue-info { flex: 1; min-width: 0; }

.continue-title {
  font-weight: 800;
  font-size: 0.9rem;
  color: var(--brown);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.continue-time-left {
  font-size: 0.78rem;
  color: var(--brown-light);
  margin-top: 0.15rem;
}

.continue-progress {
  height: 3px;
  background: var(--warm);
  border-radius: 3px;
  margin-top: 0.4rem;
  overflow: hidden;
}

.continue-progress-fill {
  height: 3px;
  background: var(--green);
  border-radius: 3px;
}

/* ── Player screen ───────────────────────────────────────────── */
#player-screen {
  display: none;
  min-height: 100vh;
  animation: fadeIn 0.4s ease;
}

.player-header {
  background: white;
  padding: 1.2rem 2rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: 0 2px 12px var(--shadow);
  position: sticky;
  top: 0;
  z-index: 10;
}

.player-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2.5rem 2rem;
  max-width: 480px;
  margin: 0 auto;
}

.player-cover {
  width: min(280px, 70vw);
  aspect-ratio: 1/1;
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 6rem;
  box-shadow: 0 20px 60px var(--shadow), 6px 6px 0 rgba(0,0,0,0.08);
  margin-bottom: 2rem;
  position: relative;
  overflow: hidden;
  background: var(--warm);
  animation: floatBook 1.5s ease-out 1;
}

.player-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 20px;
}

@keyframes floatBook {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

.player-book-title {
  font-family: 'Playfair Display', serif;
  font-size: clamp(1.4rem, 4vw, 1.9rem);
  font-weight: 900;
  color: var(--brown);
  text-align: center;
  margin-bottom: 0.3rem;
}

.player-book-author { color: var(--brown-light); font-size: 1rem; text-align: center; margin-bottom: 0.5rem; }

.player-chapter {
  background: var(--warm);
  border-radius: 20px;
  padding: 0.35rem 1rem;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--brown-light);
  margin-bottom: 2rem;
  max-width: 100%;
  text-align: center;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

.progress-wrap { width: 100%; margin-bottom: 1.5rem; }

.progress-track {
  width: 100%;
  height: 10px;
  background: var(--warm);
  border-radius: 10px;
  cursor: pointer;
  position: relative;
  overflow: visible;
  touch-action: none;
}

.progress-fill {
  height: 10px;
  border-radius: 10px;
  background: linear-gradient(90deg, var(--green), #6DD5A0);
  transition: width 0.1s linear;
  position: relative;
}

.progress-fill::after {
  content: '';
  position: absolute;
  right: -9px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  background: white;
  border: 3px solid var(--green);
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

.time-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 0.5rem;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--brown-light);
}

.controls {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.ctrl-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  font-family: 'Nunito', sans-serif;
  font-weight: 800;
  color: var(--brown-light);
  transition: color 0.15s, transform 0.15s;
  padding: 0.75rem;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
}

.ctrl-btn svg { width: 28px; height: 28px; fill: currentColor; }
.ctrl-btn:hover { color: var(--brown); transform: scale(1.1); }

.play-btn {
  width: 72px;
  height: 72px;
  background: var(--amber);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 2rem;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 20px rgba(245,166,35,0.4), 0 3px 0 var(--amber-dark);
  transition: transform 0.15s, box-shadow 0.15s;
  position: relative;
  top: 0;
}

.play-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 28px rgba(245,166,35,0.4), 0 5px 0 var(--amber-dark);
}

.play-btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 8px rgba(245,166,35,0.4), 0 1px 0 var(--amber-dark);
}

.archive-book-btn {
  background: none;
  border: none;
  padding: 0.2rem 0;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 0.78rem;
  color: var(--brown-light);
  cursor: pointer;
  transition: color 0.15s;
  margin-bottom: 0.5rem;
}
.archive-book-btn:hover { color: var(--red); }

.chapter-section { width: 100%; margin-top: 2rem; padding-bottom: 4rem; }

.chapter-heading {
  font-family: 'Playfair Display', serif;
  font-size: 1.1rem;
  color: var(--brown);
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--warm);
}

.chapter-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 0.75rem;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 0.25rem;
}

.chapter-item:hover { background: var(--warm); }
.chapter-item.active { background: rgba(245,166,35,0.12); }

.chapter-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--warm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--brown-light);
  flex-shrink: 0;
}

.chapter-item.active .chapter-num { background: var(--amber); color: white; }
.chapter-name { font-weight: 700; font-size: 0.9rem; color: var(--brown); flex: 1; }
.chapter-time { font-size: 0.8rem; color: var(--brown-light); }

/* ── Offline notice ──────────────────────────────────────────── */
.offline-notice {
  background: rgba(224,92,92,0.1);
  border: 2px solid var(--red);
  border-radius: 12px;
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  color: var(--red);
  width: 100%;
  margin-bottom: 1rem;
  display: none;
  text-align: center;
}

/* ── Animations ──────────────────────────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.85); }
  to { opacity: 1; transform: scale(1); }
}

/* ── Chapter nav buttons (prev/next) ─────────────────────────── */
.ctrl-btn.chapter-nav svg { width: 22px; height: 22px; }


/* ── Loading spinner (player cover) ─────────────────────────── */
.cover-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--warm);
  border-top-color: var(--amber);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ── Mini player bar ─────────────────────────────────────────── */
#mini-player {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 76px;
  background: #5C3D1E;
  border-top: 3px solid #3d2810;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0 2rem;
  cursor: pointer;
  z-index: 90;
  box-shadow: 0 -4px 20px var(--shadow);
}

#mini-cover {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--warm);
  border: 2px solid var(--warm);
}

.mini-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

#mini-title {
  font-weight: 800;
  font-size: 0.88rem;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#mini-chapter {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.65);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#mini-play-btn {
  width: 40px;
  height: 40px;
  background: var(--amber);
  border: none;
  border-radius: 50%;
  color: white;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 3px 10px rgba(245, 166, 35, 0.35);
  transition: transform 0.15s;
}

#mini-play-btn svg { width: 20px; height: 20px; fill: white; }
.play-btn svg { width: 32px; height: 32px; fill: white; }
#mini-play-btn:active { transform: scale(0.9); }

@media (max-width: 480px) {
  .book-grid { grid-template-columns: repeat(2, 1fr); gap: 1rem; padding: 1rem; }
  .controls { gap: 0.6rem; }
  .profile-cards { gap: 1rem; }
  .profile-card { width: 160px; padding: 2rem 1.5rem; }
}

/* ── Listening limit warning (player) ────────────────────────── */
#listen-limit-warning {
  width: 100%;
  background: rgba(245,166,35,0.12);
  border: 2px solid var(--amber);
  border-radius: 12px;
  padding: 0.65rem 1rem;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--amber-dark);
  text-align: center;
  margin-bottom: 1rem;
  animation: pulse-limit 2.5s ease-in-out infinite;
}
@keyframes pulse-limit {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.65; }
}

/* ── Stats panel (7-day chart view) ─────────────────────────── */
.stats-today-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--brown-light);
  margin-bottom: 0.35rem;
}
.stats-today-used { color: var(--brown); }

.stats-today-bar {
  height: 6px;
  background: var(--warm);
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 1rem;
}
.stats-today-bar-fill {
  height: 6px;
  background: var(--green);
  border-radius: 6px;
  transition: width 0.3s ease;
}
.stats-today-bar-fill.over-limit { background: var(--red); }

/* ── 7-day bar chart ─────────────────────────────────────────── */
.listen-chart-label {
  font-size: 0.68rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--brown-light);
  margin-bottom: 0.6rem;
}

.listen-chart-bars {
  display: flex;
  gap: 5px;
  align-items: flex-end;
  height: 80px;
}

.listen-bar-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.listen-bar-inner {
  width: 100%;
  height: 56px;
  position: relative;
  display: flex;
  align-items: flex-end;
}

.listen-bar {
  width: 100%;
  background: rgba(92,61,30,0.18);
  border-radius: 4px 4px 0 0;
  min-height: 0;
  transition: height 0.35s ease;
}
.listen-bar-wrap.today .listen-bar { background: var(--amber); }
.listen-bar.over-limit             { background: var(--red);   }

.listen-limit-line {
  position: absolute;
  left: -1px;
  right: -1px;
  height: 0;
  border-top: 2px dashed rgba(92,61,30,0.3);
}

.listen-bar-day {
  font-size: 0.6rem;
  font-weight: 900;
  color: var(--brown-light);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.listen-bar-wrap.today .listen-bar-day { color: var(--amber-dark); font-weight: 900; }

.listen-bar-time {
  font-size: 0.58rem;
  font-weight: 700;
  color: var(--brown-light);
}

/* ── Parent screen ───────────────────────────────────────────── */
#parent-screen {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 0 0 4rem;
  animation: fadeIn 0.4s ease;
}

.parent-header {
  background: white;
  padding: 1.2rem 2rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: 0 2px 12px var(--shadow);
  position: sticky;
  top: 0;
  z-index: 10;
}

.parent-title {
  font-family: 'Playfair Display', serif;
  font-size: 1.3rem;
  color: var(--brown);
  margin-left: auto;
}

.parent-content {
  padding: 1.25rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* Tracking toggle card */
.parent-tracking-card {
  background: white;
  border-radius: 16px;
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 12px var(--shadow);
  border: 1.5px solid var(--warm);
}
.parent-tracking-title {
  font-weight: 900;
  font-size: 0.95rem;
  color: var(--brown);
  margin-bottom: 0.15rem;
}
.parent-tracking-sub {
  font-size: 0.78rem;
  color: var(--brown-light);
}

/* Toggle switch */
.toggle-switch {
  position: relative;
  width: 48px;
  height: 28px;
  flex-shrink: 0;
}
.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}
.toggle-switch-track {
  position: absolute;
  inset: 0;
  background: var(--warm-hover);
  border-radius: 14px;
  cursor: pointer;
  transition: background 0.2s;
}
.toggle-switch input:checked + .toggle-switch-track { background: var(--green); }
.toggle-switch-track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}
.toggle-switch input:checked + .toggle-switch-track::after { transform: translateX(20px); }

/* Kid cards */
.parent-kid-card {
  background: white;
  border-radius: 20px;
  padding: 1.25rem 1.25rem 1.5rem;
  box-shadow: 0 2px 12px var(--shadow);
  border: 1.5px solid var(--warm);
}
.parent-kid-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.9rem;
}
.parent-kid-avatar { font-size: 2rem; }
.parent-kid-name   { font-size: 1.1rem; font-weight: 900; color: var(--brown); }

.parent-today-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--brown-light);
  margin-bottom: 0.35rem;
}
.parent-today-used { color: var(--brown); }

.parent-progress-bar {
  height: 7px;
  background: var(--warm);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 1.1rem;
}
.parent-progress-fill {
  height: 7px;
  background: var(--green);
  border-radius: 8px;
  transition: width 0.3s ease;
}
.parent-progress-fill.over-limit { background: var(--red); }

.parent-limit-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.6rem;
}
.parent-limit-label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--brown-light);
  flex: 1;
}
.parent-limit-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.parent-limit-btn {
  width: 30px;
  height: 30px;
  background: var(--warm);
  border: none;
  border-radius: 8px;
  font-size: 1.1rem;
  font-weight: 900;
  color: var(--brown);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.parent-limit-btn:hover { background: var(--warm-hover); }
.parent-limit-value {
  font-size: 0.88rem;
  font-weight: 800;
  color: var(--brown);
  min-width: 52px;
  text-align: center;
}

.parent-override-set-btn {
  background: var(--warm);
  border: none;
  border-radius: 10px;
  padding: 0.3rem 0.75rem;
  font-family: 'Nunito', sans-serif;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--brown);
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}
.parent-override-set-btn:hover { background: var(--warm-hover); }

.parent-chart-heading {
  font-size: 0.68rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--brown-light);
  margin: 1rem 0 0.5rem;
}
.parent-chart-wrap .listen-chart-bars { height: 70px; }
