/* Español Reader — friendly but polished theme */
:root {
  --bg: #f7f5f1;
  --card: #ffffff;
  --ink: #22303c;
  --ink-soft: #67727e;
  --line: #e7e2da;
  --accent: #e0722a;       /* warm terracotta */
  --accent-soft: #fdeede;
  --accent-dark: #b85a1d;
  --teal: #1d8a72;
  --teal-dark: #14614f;
  --teal-soft: #e3f2ed;
  --green: #2f9e5f;
  --green-soft: #e6f4ec;
  --red: #d0523c;
  --red-soft: #fbe9e5;
  --blue: #3f6fb5;
  --radius: 14px;
  --shadow-sm: 0 1px 2px rgba(34, 48, 60, 0.06);
  --shadow-md: 0 6px 20px rgba(34, 48, 60, 0.08);
  --shadow-lg: 0 12px 32px rgba(34, 48, 60, 0.12);
}

* { box-sizing: border-box; }

/* iPad/iOS: instant tap response, no double-tap zoom delay or grey flash */
button { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  font-family: "Avenir Next", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

.app-header {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 20px 16px;
}

.header-inner {
  max-width: 1080px;
  margin: 0 auto;
  display: flex;
  align-items: baseline;
  gap: 14px;
  flex-wrap: wrap;
}

.app-header h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.app-header h1 .logo-dot { color: var(--accent); }

.tagline {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

main { max-width: 1080px; margin: 0 auto; padding: 32px 24px 72px; }

.hidden { display: none !important; }

.view-title { font-size: 1.25rem; margin: 0 0 6px; letter-spacing: -0.01em; }
.view-subtitle { color: var(--ink-soft); margin: 0 0 26px; font-size: 0.95rem; }

/* CEFR groups */
.cefr-group { margin-bottom: 34px; }

.cefr-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.cefr-badge {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 3px 10px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink-soft);
}

.cefr-group[data-cefr="A1"] .cefr-badge { color: var(--teal-dark); border-color: #bfe0d6; background: var(--teal-soft); }
.cefr-group[data-cefr="A2"] .cefr-badge { color: #2d5496; border-color: #c6d6ef; background: #e9f0fb; }
.cefr-group[data-cefr="B1"] .cefr-badge { color: var(--accent-dark); border-color: #f2cfb2; background: var(--accent-soft); }

.cefr-desc { font-size: 0.85rem; color: var(--ink-soft); }

/* Book grid & cards */
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 18px;
}

.book-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  text-align: left;
  font-family: inherit;
  color: var(--ink);
  display: flex;
  gap: 16px;
  align-items: stretch;
}
.book-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: #d8cfc2;
}

/* Mockup book cover */
.book-cover {
  position: relative;
  flex-shrink: 0;
  width: 112px;
  aspect-ratio: 5 / 7;
  border-radius: 6px 10px 10px 6px;
  background: linear-gradient(155deg, var(--cover, #888) 0%, rgba(0, 0, 0, 0.32) 130%);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm), inset 0 0 0 1px rgba(255, 255, 255, 0.18);
  overflow: hidden;
}
.cover-emoji { font-size: 2.4rem; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.25)); }
.cover-spine {
  position: absolute;
  left: 6px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: rgba(0, 0, 0, 0.22);
}
.book-cover.has-img { padding: 0; }
.book-cover.has-img .cover-spine { display: none; }
.book-cover.has-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.book-info { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.book-title { font-size: 1.05rem; font-weight: 700; letter-spacing: -0.01em; }
.book-intro {
  font-size: 0.87rem;
  font-weight: 400;
  color: var(--ink-soft);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.book-meta { font-size: 0.8rem; color: var(--ink-soft); margin-top: auto; }

/* ---------- Book view ---------- */
.book-hero {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 28px;
  display: flex;
  gap: 26px;
  align-items: center;
  margin-bottom: 26px;
}

.book-cover.large {
  width: 210px;
  height: 294px;
  border-radius: 10px 18px 18px 10px;
}
.book-cover.large .cover-emoji { font-size: 4rem; }
.cover-title {
  position: absolute;
  bottom: 12px;
  left: 10px;
  right: 10px;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  text-align: center;
  line-height: 1.25;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

.book-cover.large .cover-title { font-size: 0.95rem; bottom: 16px; }

.book-hero-info h2 { margin: 8px 0 10px; font-size: 1.45rem; letter-spacing: -0.01em; }
.book-hero-info .book-intro { font-size: 0.95rem; display: block; -webkit-line-clamp: unset; }

.chapters-title {
  font-size: 1.05rem;
  margin: 0 0 12px;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
}

.chapter-row {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 18px;
  margin-bottom: 10px;
  cursor: pointer;
  font-family: inherit;
  font-size: 1rem;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s ease, background 0.15s ease;
  text-align: left;
}
.chapter-row:hover { border-color: var(--accent); background: var(--accent-soft); }

.chapter-num {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chapter-row-title { font-weight: 600; }
.chapter-row-meta { margin-left: auto; font-size: 0.83rem; color: var(--ink-soft); }
.chapter-row .arrow { color: var(--accent); font-weight: 700; }

/* ---------- Chapter view ---------- */
.chapter-content {
  margin-top: 24px;
}

/* Hero illustration: full width on top, dominant — the pattern used by
   children's reading apps (Epic!, Skybrary): the art is on full display
   and the reading text follows below in large, comfortable type. */
.chapter-illustration {
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: 430px;
  margin: 0 0 26px;
  border: 2px dashed #cfc8bd;
  border-radius: 12px;
  background: #fbf9f5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--ink-soft);
  text-align: center;
}
.chapter-illustration .illus-icon { font-size: 2rem; opacity: 0.7; }
.chapter-illustration .illus-text { font-size: 0.88rem; font-weight: 600; }
.chapter-illustration .illus-text small {
  display: block;
  font-weight: 400;
  color: #a29a8d;
  margin-top: 2px;
}
.chapter-illustration.has-image { border: none; padding: 0; overflow: hidden; }
.chapter-illustration.has-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Reading text: slightly larger type for young readers */
.chapter-content .text-block {
  margin: 0 0 10px;
  font-size: 1.18rem;
  line-height: 1.9;
}

@media (max-width: 680px) {
  .book-hero { flex-direction: column; text-align: center; }
}

/* Study view */
.btn-back {
  background: none;
  border: none;
  color: var(--ink-soft);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 0;
  font-family: inherit;
  margin-bottom: 14px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn-back:hover { color: var(--accent-dark); }

.study-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 38px 42px;
}

.study-header { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.study-header h2 { margin: 0; font-size: 1.45rem; letter-spacing: -0.01em; }

.text-block {
  background: #fbf9f5;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  padding: 26px 30px;
  margin: 22px 0;
  font-size: 1.15rem;
  line-height: 1.9;
}
.text-block p { margin: 0; }
.text-block p + p { margin-top: 14px; }

.btn-play {
  background: var(--teal);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 10px 24px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: background 0.15s ease, transform 0.1s ease;
}
.btn-play:hover { background: #187a64; }
.btn-play:active { transform: scale(0.97); }
.btn-play.playing { background: var(--red); }

.audio-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.voice-switch {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.voice-switch-label {
  padding: 0 6px 0 8px;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.voice-option {
  border: none;
  background: transparent;
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.82rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.voice-option:hover { background: var(--teal-soft); }
.voice-option.active { background: var(--teal); color: #fff; }
.voice-option.active:hover { background: var(--teal-dark); }

.questions-title {
  font-size: 1.05rem;
  margin: 28px 0 6px;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
}

.question { margin-bottom: 26px; }
.question .prompt { font-weight: 600; font-size: 1.08rem; margin-bottom: 12px; }

.choices { display: flex; flex-direction: column; gap: 10px; max-width: 620px; }

.choice {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 1rem;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 10px;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.choice::before {
  content: "";
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid #c9c2b8;
  flex-shrink: 0;
  transition: border-color 0.15s ease;
}
.choice:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.choice:hover:not(:disabled)::before { border-color: var(--accent); }
.choice:disabled { cursor: default; }

.choice.correct { background: var(--green-soft); border-color: var(--green); }
.choice.correct::before {
  border-color: var(--green);
  background: var(--green);
  box-shadow: inset 0 0 0 3px #fff;
}
.choice.correct::after { content: "✓"; margin-left: auto; color: var(--green); font-weight: 700; }

.choice.wrong { background: var(--red-soft); border-color: var(--red); }
.choice.wrong::before { border-color: var(--red); }
.choice.wrong::after { content: "✗"; margin-left: auto; color: var(--red); font-weight: 700; }

.score-banner {
  margin-top: 30px;
  border-radius: 10px;
  padding: 18px 22px;
  font-size: 1.08rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
}
.score-banner.great { background: var(--green-soft); color: #1e6b40; border: 1px solid #bfe3cf; }
.score-banner.try { background: var(--red-soft); color: #93341f; border: 1px solid #f0cdc5; }

@media (max-width: 560px) {
  .study-card { padding: 22px 18px; }
  .header-inner { flex-direction: column; gap: 2px; }
  .book-card { flex-direction: row; }
}
