/* Reading practice, laid out for an iPad Air (834 x 1112 points) held either
   way: big type, 56px+ touch targets, no hover states, no scrolling while reading. */

@font-face { font-family: 'VIC Hand'; src: url('../fonts/vic-hand.woff2') format('woff2'); font-weight: 400 700; font-display: block; }

:root {
  color-scheme: light;
  --bg: #f6f3ec;
  --ink: #1d2433;
  --muted: #5b6577;
  --line: #e4dfd4;
  --accent: #2f5fb3;
  --accent-soft: #e9effa;
  --heart: #e0457b;
  --right: #1f9d55;
  --wrong: #d64545;
  --helped: #fff1c9;
  --shadow: 0 1px 2px rgb(29 36 51 / 0.08), 0 8px 24px rgb(29 36 51 / 0.1);
  --ui: system-ui, -apple-system, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --hand: 'VIC Hand', var(--ui);
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body.reader {
  background: var(--bg);
  color: var(--ink);
  font: 18px/1.4 var(--ui);
  overscroll-behavior: none;
  /* A book, not a document: no text selection or long-press menus. */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }

/* VIC Hand's space is narrow; beginners need clear gaps between words. */
.bar-title, .book-title, .text, .question, .answer, .how-step, .how h2, .done h2 { word-spacing: 0.3em; }
button:disabled { cursor: default; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px; }

.app {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.message { grid-row: 1 / -1; display: grid; place-content: center; justify-items: center; gap: 16px; padding: 24px; text-align: center; font-size: 22px; }

/* ---- Bars and buttons ---- */

.bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.bar-title {
  flex: 1;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  font: 400 32px/1.2 var(--hand);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.round {
  flex: none;
  width: 56px;
  height: 56px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 2px solid var(--line);
  border-radius: 50%;
  background: #fff;
  font-size: 26px;
  line-height: 1;
  text-decoration: none;
}

.round.spacer { visibility: hidden; }
.round:disabled { opacity: 0.3; }
.round.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.big-round { width: 76px; height: 76px; font-size: 44px; }

.big {
  min-height: 64px;
  padding: 0 28px;
  border: 2px solid var(--line);
  border-radius: 32px;
  background: #fff;
  font-size: 22px;
  font-weight: 700;
  white-space: nowrap;
}

.big.primary { background: var(--accent); border-color: var(--accent); color: #fff; }

.round:active:not(:disabled), .big:active, .book-card:active, .answer:active:not(:disabled), .how-step:active {
  transform: scale(0.96);
}

.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: #fff;
  border-top: 1px solid var(--line);
}

.controls.empty { padding: 0; border: 0; }
.middle { display: flex; align-items: center; gap: 24px; }
.dots { display: flex; gap: 8px; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--line); }
.dot.on { background: var(--accent); }

.coach { display: flex; align-items: center; gap: 12px; margin: 0; color: var(--muted); font-size: 20px; font-weight: 600; }
.coach-say {
  flex: none;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--accent-soft);
  font-size: 22px;
}

/* ---- Shelf ---- */

.shelf { overflow-y: auto; padding: 20px 24px 32px; }

.books { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 18px; }

.book-card {
  position: relative;
  display: grid;
  gap: 6px;
  align-content: start;
  padding: 10px 10px 14px;
  border: 0;
  border-radius: 20px;
  background: #fff;
  box-shadow: var(--shadow);
  text-align: left;
}

.book-card img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 14px; background: var(--accent-soft); }
.badge {
  position: absolute;
  top: 18px;
  left: 18px;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 800;
}
.book-title { padding: 2px 4px 0; font: 400 28px/1.15 var(--hand); }
.book-stars { padding: 0 4px; color: var(--muted); font-size: 16px; font-weight: 600; }

/* ---- Reading a page: picture above the text, or beside it when the iPad is landscape ---- */

.page {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  padding: 16px 24px;
  touch-action: pan-y; /* horizontal swipes turn the page */
}

.page figure { flex: 1 1 auto; min-height: 140px; margin: 0; display: grid; place-items: center; }
.page figure img { width: 100%; height: 100%; object-fit: contain; }
.reading { flex: none; display: grid; gap: 4px; max-height: 100%; overflow-y: auto; }

.text { margin: 0; font: 400 var(--size, 44px)/2.2 var(--hand); text-align: center; }
.level-a { --size: 58px; }
.level-b { --size: 52px; }
.level-c { --size: 44px; }
.level-d { --size: 40px; }
.level-e { --size: 36px; }

@media (orientation: landscape) {
  .page { flex-direction: row; align-items: center; gap: 28px; padding: 16px 28px; }
  .page figure { flex: 1 1 54%; height: 100%; }
  .reading { flex: 0 1 46%; }
  .text { text-align: left; }
}

/* A word is a button. First tap shows its sound buttons, second tap says it. */
.word {
  position: relative;
  display: inline-block;
  margin: 0;
  padding: 0 0.08em;
  border: 0;
  border-radius: 0.18em;
  background: transparent;
  font: inherit;
  line-height: 1.3;
}
.word.helped { background: var(--helped); }

/* Sound marks hang below the tails of g, j, p, q and y. .g and .split stay
   inline (not inline-block) so their marks are placed against the font's full
   height, ascent to descent, whatever the line height: top: 100% is just
   under the descender at every text size. */
.g, .split { position: relative; }

.sounds .g::after { position: absolute; left: 50%; transform: translateX(-50%); }
.sounds .g[data-mark="dot"]::after {
  content: '';
  top: calc(100% + 0.03em);
  width: 0.17em;
  height: 0.17em;
  border-radius: 50%;
  background: var(--accent);
}
.sounds .g[data-mark="bar"]::after {
  content: '';
  top: calc(100% + 0.06em);
  width: 82%;
  height: 0.1em;
  border-radius: 0.05em;
  background: var(--accent);
}
.sounds .g[data-mark="heart"]::after {
  content: '♥';
  top: calc(100% + 0.1em); /* em here = the heart's own (smaller) size */
  color: var(--heart);
  font: 700 0.42em/1 var(--ui);
}
.sounds .split::after {
  content: '';
  position: absolute;
  left: 0.12em;
  right: 0.12em;
  top: calc(100% + 0.2em);
  height: 0.2em;
  border: 0.06em solid var(--accent);
  border-top: 0;
  border-radius: 0 0 50% 50% / 0 0 100% 100%;
}

/* ---- Warm-up, questions, well done ---- */

.warmup, .done, .quiz {
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 20px;
  padding: 24px;
  overflow-y: auto;
  text-align: center;
}

.warm-card {
  min-width: min(80vw, 520px);
  padding: 28px 48px 88px;
  border-radius: 28px;
  background: #fff;
  box-shadow: var(--shadow);
  font: 400 104px/1.3 var(--hand);
}
.warm-count, .quiz-count { margin: 0; color: var(--muted); font-weight: 700; }

.quiz { justify-items: stretch; width: min(100%, 860px); margin: 0 auto; text-align: left; }
.question { display: flex; align-items: center; gap: 16px; margin: 0; font: 400 42px/1.25 var(--hand); }
.options { display: grid; gap: 14px; }
.option { display: flex; align-items: center; gap: 12px; }
.answer {
  flex: 1;
  min-height: 80px;
  padding: 8px 24px;
  border: 3px solid var(--line);
  border-radius: 24px;
  background: #fff;
  font: 400 38px/1.2 var(--hand);
  text-align: left;
}
.answer.right { border-color: var(--right); background: #e6f6ec; }
.answer.right::after { content: '  ✓'; color: var(--right); font-family: var(--ui); font-weight: 800; }
.answer.wrong { border-color: var(--wrong); opacity: 0.45; animation: shake 0.35s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }

.star { font-size: 120px; line-height: 1; animation: pop 0.6s ease-out; }
@keyframes pop { from { transform: scale(0.3); opacity: 0; } }
.done h2 { margin: 0; font: 400 56px/1.1 var(--hand); }
.done-note { margin: 0; font-size: 22px; color: var(--muted); }
.practise { display: grid; justify-items: center; gap: 12px; }
.practise h3 { margin: 8px 0 0; font-size: 15px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.practise-words { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 16px; font: 400 54px/2 var(--hand); }
.practise-word { padding: 0 0.3em 0.15em; border-radius: 18px; background: #fff; box-shadow: var(--shadow); }

@media (prefers-reduced-motion: reduce) {
  .star, .answer.wrong { animation: none; }
}

.debug-log {
  position: fixed;
  left: 8px;
  right: 8px;
  bottom: 96px;
  z-index: 10;
  max-height: 34vh;
  margin: 0;
  padding: 8px 10px;
  overflow: auto;
  border-radius: 10px;
  background: rgb(0 0 0 / 0.8);
  color: #9ef0a8;
  font: 12px/1.4 ui-monospace, Menlo, Consolas, monospace;
  white-space: pre-wrap;
  pointer-events: none;
}

/* ---- How I read ---- */

.how {
  width: min(92vw, 580px);
  padding: 28px;
  border: 0;
  border-radius: 28px;
  box-shadow: 0 20px 60px rgb(29 36 51 / 0.3);
}
.how::backdrop { background: rgb(29 36 51 / 0.45); }
.how h2 { margin: 0 0 14px; font: 400 44px/1.1 var(--hand); text-align: center; }
.how ul { display: grid; gap: 10px; margin: 0 0 20px; padding: 0; list-style: none; }
.how-step {
  width: 100%;
  min-height: 76px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 18px;
  border: 0;
  border-radius: 20px;
  background: var(--accent-soft);
  font: 400 30px/1.2 var(--hand);
  text-align: left;
}
.how-icon { flex: none; width: 48px; font: 34px/1 var(--ui); text-align: center; }
.how-icon.heart { color: var(--heart); font-weight: 800; }
.how .big { width: 100%; }
