/* ============================================================
   Sam & Friends — Decodable Mini-Book Series
   Editorial / warm-paper aesthetic
   ============================================================ */

:root {
  --paper: #f7f1e3;
  --paper-dark: #ede4cc;
  --paper-light: #fdf9ed;
  --ink: #2b2520;
  --ink-light: #5a5048;
  --ink-soft: #8a7e6e;
  --accent: #e76f51;
  --accent-dark: #c4543a;
  --sage: #7a9b7e;
  --border: #d4c4a8;
  --border-light: #e8dfd0;
  --shadow: 0 30px 60px rgba(43, 37, 32, 0.10), 0 8px 20px rgba(43, 37, 32, 0.05);
  --shadow-sm: 0 8px 24px rgba(43, 37, 32, 0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  font-family: 'Spectral', Georgia, serif;
  color: var(--ink);
  background: var(--paper);
  background-image:
    radial-gradient(circle at 20% 30%, rgba(231, 111, 81, 0.04) 0%, transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(122, 155, 126, 0.04) 0%, transparent 50%);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

button { cursor: pointer; font-family: inherit; border: none; background: none; }
button:disabled { cursor: not-allowed; opacity: 0.4; }
img { display: block; max-width: 100%; }

.view { display: none; min-height: 100vh; }
.view.active { display: block; animation: fadeIn 0.4s ease; }
.hidden { display: none !important; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   LIBRARY VIEW
   ============================================================ */

.library-header {
  padding: 36px 48px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-weight: 700;
  font-size: 22px;
  color: var(--ink);
}

.tagline {
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  color: var(--ink-soft);
  letter-spacing: 0.02em;
}

.intro {
  text-align: center;
  padding: 80px 24px 60px;
  max-width: 720px;
  margin: 0 auto;
}

.intro h1 {
  font-family: 'Fraunces', serif;
  font-size: clamp(40px, 6vw, 64px);
  font-weight: 500;
  line-height: 1.05;
  color: var(--ink);
  margin-bottom: 24px;
  letter-spacing: -0.02em;
}

.intro h1 em {
  font-style: italic;
  font-weight: 400;
  color: var(--accent);
}

.intro-text {
  font-size: 18px;
  line-height: 1.6;
  color: var(--ink-light);
  max-width: 560px;
  margin: 0 auto;
}

.intro-text strong {
  font-weight: 700;
  color: var(--ink);
}

.book-grid {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 48px 80px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 28px;
}

.book-card {
  background: #fff;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  opacity: 0;
  animation: bookIn 0.5s ease forwards;
}

@keyframes bookIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.book-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 20px 40px rgba(43, 37, 32, 0.12);
}

.book-cover {
  aspect-ratio: 3 / 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #fff;
  position: relative;
  overflow: hidden;
}

.book-cover::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, transparent 0%, transparent 50%, rgba(0,0,0,0.18) 100%);
  pointer-events: none;
  z-index: 2;
}

.book-cover::after {
  content: '';
  position: absolute;
  left: 14px;
  top: 0; bottom: 0;
  width: 2px;
  background: rgba(0,0,0,0.18);
  z-index: 3;
}

.cover-portrait {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 25%;
  z-index: 1;
}

.book-vowel {
  position: absolute;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  font-family: 'Fraunces', serif;
  font-size: 90px;
  font-style: italic;
  font-weight: 700;
  line-height: 1;
  color: #fff;
  text-shadow: 0 4px 16px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
  z-index: 4;
  letter-spacing: -0.02em;
}

.book-number {
  position: absolute;
  bottom: 12px;
  right: 14px;
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.85;
  z-index: 4;
  text-shadow: 0 1px 4px rgba(0,0,0,0.4);
}

.book-info {
  padding: 18px 20px 22px;
}

.book-stage {
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  font-weight: 500;
  display: block;
  margin-bottom: 6px;
}

.book-title {
  font-family: 'Fraunces', serif;
  font-size: 22px;
  font-weight: 500;
  line-height: 1.2;
  margin-bottom: 6px;
  color: var(--ink);
}

.book-blurb {
  font-size: 14px;
  color: var(--ink-light);
  line-height: 1.4;
  font-style: italic;
}

.book-pages {
  display: block;
  margin-top: 12px;
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  color: var(--ink-soft);
}

.library-footer {
  text-align: center;
  padding: 40px 24px 60px;
  border-top: 1px solid var(--border-light);
  max-width: 720px;
  margin: 0 auto;
}

.library-footer p {
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  color: var(--ink-soft);
  letter-spacing: 0.02em;
  line-height: 1.8;
}

/* ============================================================
   READER VIEW
   ============================================================ */

.reader-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 16px 32px;
  background: var(--paper);
  border-bottom: 1px solid var(--border);
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(8px);
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--ink-light);
  font-size: 12px;
  font-family: 'DM Mono', monospace;
  transition: all 0.15s;
  width: fit-content;
}

.back-btn:hover {
  background: var(--paper-dark);
  color: var(--ink);
}

.reader-title {
  font-family: 'Fraunces', serif;
  font-size: 18px;
  font-style: italic;
  font-weight: 500;
  color: var(--ink);
  text-align: center;
}

.reader-stage {
  min-height: calc(100vh - 60px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  background: linear-gradient(135deg, var(--paper) 0%, var(--paper-dark) 100%);
}

.reader-book {
  background: #fff;
  border-radius: 20px;
  padding: 36px 48px 32px;
  box-shadow: var(--shadow);
  max-width: 560px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.progress-dots {
  display: flex;
  gap: 6px;
  margin-bottom: 24px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--paper-dark);
  transition: background 0.3s;
}

.dot.filled {
  background: var(--accent);
}

.page-illust {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 32px;
  min-height: 280px;
}

.page-illust img {
  max-height: 360px;
  width: auto;
  border-radius: 12px;
}

.img-fallback {
  font-size: 140px;
  line-height: 1;
}

.page-text {
  font-family: 'Fraunces', serif;
  font-size: 36px;
  font-weight: 500;
  text-align: center;
  color: var(--ink);
  line-height: 1.3;
  margin-bottom: 36px;
  min-height: 50px;
  letter-spacing: -0.01em;
}

.reader-controls {
  display: flex;
  gap: 10px;
  width: 100%;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}

.btn-audio, .btn-next, .btn-prev {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 14px 22px;
  border-radius: 10px;
  font-family: 'Fraunces', serif;
  font-size: 15px;
  font-weight: 500;
  transition: transform 0.1s, box-shadow 0.15s, opacity 0.15s;
}

.btn-audio {
  background: var(--sage);
  color: #fff;
}

.btn-next {
  background: var(--accent);
  color: #fff;
}

.btn-prev {
  background: transparent;
  color: var(--ink-light);
  border: 1px solid var(--border);
}

.btn-audio:hover, .btn-next:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(43, 37, 32, 0.12);
}

.btn-prev:hover:not(:disabled) {
  background: var(--paper-dark);
  color: var(--ink);
}

/* ============================================================
   QUESTION PHASE
   ============================================================ */

.question-stage {
  background: #fff;
  border-radius: 20px;
  padding: 48px;
  box-shadow: var(--shadow);
  max-width: 560px;
  width: 100%;
  text-align: center;
  position: relative;
}

.q-label {
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  display: block;
  margin-bottom: 18px;
}

.q-prompt {
  font-family: 'Fraunces', serif;
  font-size: 28px;
  font-weight: 500;
  color: var(--ink);
  margin-bottom: 20px;
  line-height: 1.3;
}

.q-audio {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--sage);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 28px;
  transition: transform 0.1s;
}

.q-audio:hover {
  transform: scale(1.08);
}

.q-choices {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.q-choice {
  padding: 16px 24px;
  font-family: 'Fraunces', serif;
  font-size: 20px;
  font-weight: 500;
  background: #fff;
  border: 2px solid var(--border);
  border-radius: 12px;
  color: var(--ink);
  transition: all 0.15s;
}

.q-choice:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--paper-light);
  transform: translateY(-1px);
}

.q-choice.correct {
  background: #d4ead8;
  border-color: var(--sage);
  color: #2d4a3e;
}

.q-choice.incorrect {
  background: #f0d4d0;
  border-color: #c44;
  color: #7a2a1f;
}

/* ============================================================
   DONE CARD
   ============================================================ */

.done-card {
  background: #fff;
  border-radius: 20px;
  padding: 56px 40px;
  box-shadow: var(--shadow);
  text-align: center;
  max-width: 460px;
  width: 100%;
}

.done-card h2 {
  font-family: 'Fraunces', serif;
  font-size: 40px;
  font-style: italic;
  font-weight: 500;
  color: var(--ink);
  margin: 18px 0 8px;
}

.done-card p {
  font-family: 'Spectral', serif;
  font-size: 17px;
  color: var(--ink-light);
  margin-bottom: 32px;
}

.done-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

.btn-restart, .btn-next-book {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 14px 28px;
  border-radius: 10px;
  font-family: 'Fraunces', serif;
  font-size: 15px;
  font-weight: 500;
  color: #fff;
  background: var(--accent);
  transition: transform 0.1s, box-shadow 0.15s;
  min-width: 220px;
  justify-content: center;
}

.btn-next-book {
  background: var(--sage);
}

.btn-restart:hover, .btn-next-book:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(43, 37, 32, 0.12);
}

.btn-back-library {
  padding: 10px 20px;
  background: transparent;
  color: var(--ink-soft);
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  margin-top: 4px;
}

.btn-back-library:hover {
  color: var(--ink);
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 640px) {
  .library-header { padding: 24px 24px 0; }
  .intro { padding: 50px 20px 40px; }
  .book-grid { padding: 0 20px 60px; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 18px; }
  .book-cover { padding: 20px; }
  .book-vowel { font-size: 64px; bottom: 20px; }
  .book-info { padding: 14px 16px 18px; }
  .book-title { font-size: 18px; }
  .reader-header { padding: 12px 16px; }
  .reader-title { font-size: 14px; }
  .reader-stage { padding: 20px 14px; }
  .reader-book, .question-stage { padding: 28px 22px 24px; border-radius: 16px; }
  .page-illust img { max-height: 260px; }
  .page-text { font-size: 26px; margin-bottom: 24px; }
  .q-prompt { font-size: 22px; }
  .q-choice { font-size: 17px; padding: 13px 18px; }
  .btn-audio, .btn-next, .btn-prev { padding: 11px 16px; font-size: 14px; }
}
