/* Little Stories - stories.dallaswx.com
   A picture book, not an edtech dashboard. Cream paper, brown ink, one leaf.
   Built iPad-first: the story text is never below the fold. */

/* ------------------------------------------------------------------ fonts */
/* Andika (SIL, OFL) is drawn for literacy learners: single-storey a and g,
   the letterforms she is being taught to write. That matters more than taste. */
@font-face {
  font-family: 'Andika';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/static/fonts/andika-400.woff2') format('woff2');
}
@font-face {
  font-family: 'Andika';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('/static/fonts/andika-700.woff2') format('woff2');
}
@font-face {
  font-family: 'Andika';
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url('/static/fonts/andika-400-italic.woff2') format('woff2');
}
@font-face {
  font-family: 'Fraunces';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('/static/fonts/fraunces-400.woff2') format('woff2');
}

/* ------------------------------------------------------------------ tokens */
:root {
  --paper: #f6efe2;
  --paper-2: #efe4d2;
  --paper-3: #e6d6c0;
  --ink: #3d2f36;
  --muted: #6f5a53;        /* 5.4:1 on paper, was 3.4:1 */
  --leaf: #3e6b4a;
  --leaf-deep: #2f5238;
  --leaf-soft: #e3ece2;
  --stretch: #2e6b6f;
  --name: #6b4a32;
  --rule: rgba(61, 47, 54, 0.14);
  --rule-strong: rgba(61, 47, 54, 0.42);

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 24px;
  --r-2xl: 28px;

  --font-read: 'Andika', 'Lexend', 'Segoe UI', system-ui, sans-serif;
  --font-ui: 'Andika', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-display: 'Fraunces', 'Iowan Old Style', 'Palatino Linotype', Georgia, serif;

  --ease: cubic-bezier(0.23, 1, 0.32, 1);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

/* ------------------------------------------------------------------ base */
* { box-sizing: border-box; }

/* A display rule in a component beats the UA's [hidden] rule. Put it back. */
[hidden] { display: none !important; }

html {
  -webkit-text-size-adjust: 100%;     /* iPad landscape must not inflate type */
  height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  background-color: var(--paper);
  background-image:
    radial-gradient(1200px 500px at 12% -10%, #fff8ee 0%, transparent 55%),
    radial-gradient(900px 600px at 100% 0%, #eadcc4 0%, transparent 50%);
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 17px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;        /* no rubber-band under a small thumb */
}

h1, h2, h3 { font-family: var(--font-display); font-weight: 600; margin: 0; letter-spacing: -0.01em; }
p { margin: 0; }
a { color: var(--leaf-deep); }

button, input, select, textarea {
  font: inherit;
  color: inherit;
}
button { cursor: pointer; }

:focus-visible {
  outline: 3px solid var(--leaf);
  outline-offset: 2px;
  border-radius: 6px;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.muted { color: var(--muted); }
.center { text-align: center; }
.hidden { display: none !important; }

/* ------------------------------------------------------------------ chrome */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + var(--safe-t)) max(16px, var(--safe-r)) 10px max(16px, var(--safe-l));
  max-width: 1100px;
  margin: 0 auto;
}

.topbar .brand {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.chip-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 12px;
  border-radius: var(--r-md);
  color: var(--muted);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 600;
}
.chip-link:hover { background: var(--paper-2); color: var(--ink); }

.wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 max(16px, var(--safe-r)) calc(40px + var(--safe-b)) max(16px, var(--safe-l));
}
.wrap-narrow { max-width: 720px; }

/* ------------------------------------------------------------------ buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
  padding: 0 22px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--paper-2);
  color: var(--ink);
  font-weight: 700;
  font-size: 1rem;
  transition: transform 120ms var(--ease), background 160ms var(--ease), box-shadow 160ms var(--ease);
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: default; }

.btn-leaf { background: var(--leaf); color: #fbf7ef; box-shadow: 0 10px 24px -14px rgba(47, 82, 56, 0.9); }
.btn-leaf:hover:not(:disabled) { background: var(--leaf-deep); }
.btn-outline { background: transparent; border-color: var(--rule-strong); }
.btn-outline:hover:not(:disabled) { background: var(--paper-2); }
.btn-ghost { background: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--paper-2); }
.btn-lg { min-height: 60px; font-size: 1.1rem; padding: 0 30px; }
.btn-block { width: 100%; }

.icon { width: 20px; height: 20px; flex: none; stroke-width: 2; }

/* ------------------------------------------------------------------ cards */
.card {
  background: rgba(255, 253, 248, 0.72);
  border: 1px solid var(--rule);
  border-radius: var(--r-2xl);
  padding: 20px;
}

.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-size: 0.9rem; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.field input[type='text'],
.field input[type='number'],
.field input[type='password'],
.field textarea,
.field select {
  width: 100%;
  min-height: 50px;
  padding: 12px 14px;
  border: 1px solid var(--rule-strong);
  border-radius: var(--r-md);
  background: #fffdf8;
  font-size: 1rem;
}
.field textarea { min-height: 96px; resize: vertical; line-height: 1.5; }

/* ------------------------------------------------------------------ chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--paper-2);
  font-size: 0.98rem;
  font-weight: 600;
  transition: background 140ms var(--ease), color 140ms var(--ease), border-color 140ms var(--ease);
}
.chip[aria-pressed='true'] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.chip.chip-on { background: var(--leaf); color: #fbf7ef; border-color: var(--leaf); }
.chip.chip-off { background: transparent; color: var(--muted); }
.chip-x {
  border: none; background: none; color: inherit; font-size: 1.2rem;
  min-width: 44px; min-height: 44px; margin: -8px -12px -8px 2px;
  border-radius: 50%;
}
.chip-x:hover { background: rgba(61, 47, 54, 0.1); }

/* ------------------------------------------------------------------ shelf */
.shelf-head { padding: 8px 0 20px; }
.shelf-head h1 { font-size: clamp(1.9rem, 4vw, 2.6rem); }
.shelf-head .sub { color: var(--muted); margin-top: 6px; }

.generate {
  border: 1px solid var(--rule);
  border-radius: var(--r-2xl);
  background: rgba(255, 253, 248, 0.72);
  padding: 20px;
  margin-bottom: 32px;
}
.generate h2 { font-size: 1.25rem; margin-bottom: 12px; }
.generate .note { color: var(--muted); font-size: 0.92rem; margin-top: 12px; max-width: 46ch; }

.library-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 0 0 14px;
}
.library-head h2 { font-size: 1.25rem; }

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

.book {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--rule);
  border-radius: var(--r-xl);
  background: #fffdf8;
  overflow: hidden;
  box-shadow: 0 14px 30px -26px rgba(61, 47, 54, 0.8);
  transition: transform 160ms var(--ease), box-shadow 160ms var(--ease);
}
.book:hover { transform: translateY(-2px); box-shadow: 0 20px 36px -26px rgba(61, 47, 54, 0.85); }
.book a.book-face { display: block; color: inherit; text-decoration: none; }
.book .cover { aspect-ratio: 4 / 3; background: var(--paper-2); display: block; width: 100%; object-fit: cover; }
.book .cover-fallback {
  aspect-ratio: 4 / 3;
  display: grid; place-items: center; padding: 14px;
  background: linear-gradient(150deg, var(--paper-2), var(--paper-3));
  font-family: var(--font-display); font-size: 1.05rem; text-align: center; line-height: 1.3;
}
.book .meta { padding: 12px 14px 4px; }
.book .meta h3 { font-size: 1.05rem; line-height: 1.25; }
.book .meta .line { font-size: 0.85rem; color: var(--muted); margin-top: 4px; }
.book .tools { display: flex; gap: 4px; padding: 4px 8px 8px; margin-top: auto; justify-content: flex-end; }
.book .tools a, .book .tools button {
  min-height: 44px; padding: 0 12px; border: none; background: none;
  color: var(--muted); font-size: 0.85rem; font-weight: 600; text-decoration: none;
  border-radius: var(--r-sm); display: inline-flex; align-items: center; gap: 5px;
}
.book .tools a:hover, .book .tools button:hover { background: var(--paper-2); color: var(--ink); }

.reread {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 0.8rem; font-weight: 700; color: var(--leaf-deep);
}
.reread .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--leaf); display: inline-block; }

.empty { padding: 40px 20px; text-align: center; color: var(--muted); }

/* ------------------------------------------------------------------ reader */
/* The whole point: on an iPad she sees the picture AND the words at once,
   with no scrolling, in both orientations. */
/* The reader owns whatever height is left after any banner above it, so a
   warning strip can never push the Next button off the bottom of the iPad. */
body.reading {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  height: 100dvh;
  overflow: hidden;
}
.reader {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.reader-top {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(6px + var(--safe-t)) max(12px, var(--safe-r)) 6px max(12px, var(--safe-l));
  flex: none;
}
.reader-top .pagecount { font-family: var(--font-display); font-size: 0.95rem; color: var(--muted); }

/* Text first, always. The words get the top of the page in portrait and the
   left of the page in landscape, and the picture is subordinate to them. */
.spread {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  gap: 12px;
  padding: 0 max(12px, var(--safe-r)) 0 max(12px, var(--safe-l));
  grid-template-rows: minmax(0, 58fr) minmax(0, 42fr);
  transition: grid-template-rows 320ms var(--ease), grid-template-columns 320ms var(--ease);
}

/* While the picture is still behind its tap, the words get the room. */
.spread.art-hidden { grid-template-rows: minmax(0, 74fr) minmax(0, 26fr); }

.scene {
  position: relative;
  min-height: 0;
  border-radius: var(--r-2xl);
  overflow: hidden;
  background: #fffdf8;
  border: 1px solid var(--rule);
  display: grid;
  place-items: center;
}
/* contain, not cover: a picture book page is the whole picture. The scene box
   is cream, so the letterboxing reads as the page, not as a gap. */
.scene img {
  width: 100%; height: 100%; object-fit: contain; display: block;
  animation: fadein 420ms var(--ease);
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
  user-select: none;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.scene .scene-placeholder { padding: 20px; text-align: center; color: var(--muted); }
.scene .scene-placeholder .title { font-family: var(--font-display); font-size: 1.4rem; color: var(--ink); }

.page-text {
  min-height: 0;
  display: flex;
  flex-direction: column;
  /* "safe center" so a long page scrolls from the top instead of clipping its
     own first line above the scroll origin. */
  justify-content: safe center;
  gap: 14px;
  padding: 18px 22px;
  border-radius: var(--r-2xl);
  background: #fffdf8;
  border: 1px solid var(--rule);
  overflow-y: auto;
}

.story-line {
  font-family: var(--font-read);
  font-size: clamp(1.6rem, 3.6vh + 1rem, 2.9rem);
  line-height: 1.55;
  letter-spacing: 0.012em;
  word-spacing: 0.08em;
  text-wrap: pretty;
}

/* Every word is a tap target. Padding gives a fat finger room without
   pushing the words apart on the line. */
.w {
  display: inline-block;
  min-width: 1.1em;
  padding: 0.06em 0.12em;
  margin: 0 -0.04em;
  border-radius: 0.22em;
  border: 0;
  background: none;
  font: inherit;
  color: inherit;
  text-align: left;
  transition: background-color 140ms ease, color 140ms ease;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}
.w:hover { background: rgba(62, 107, 74, 0.13); }
.w.is-speaking { background: rgba(62, 107, 74, 0.26); }
.w.w-stretch { color: var(--stretch); box-shadow: inset 0 -0.11em 0 rgba(46, 107, 111, 0.45); }
.w.w-name { color: var(--name); font-weight: 700; }
.w.w-unknown { box-shadow: inset 0 -0.11em 0 rgba(61, 47, 54, 0.3); }
.w.w-hard::after {
  content: '';
  display: block;
  height: 0.1em;
  margin-top: -0.02em;
  border-radius: 2px;
  background: repeating-linear-gradient(90deg, var(--muted) 0 3px, transparent 3px 6px);
}

.new-words {
  font-size: 0.95rem;
  color: var(--stretch);
  padding-top: 2px;
}
.new-words b { font-weight: 700; }

.sound-out {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  font-family: var(--font-read);
  font-size: 1.3rem;
  color: var(--muted);
  min-height: 1.9em;
}
.sound-out .ph {
  padding: 2px 10px; border-radius: var(--r-sm);
  background: var(--paper-2); color: var(--ink); font-weight: 700;
}
.sound-out .ph.on { background: var(--leaf); color: #fbf7ef; }
.sound-out .whole { font-weight: 700; color: var(--ink); }

.reader-bottom {
  flex: none;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px max(12px, var(--safe-r)) calc(14px + var(--safe-b)) max(12px, var(--safe-l));
  border-top: 1px solid var(--rule);
  background: rgba(246, 239, 226, 0.9);
  backdrop-filter: blur(8px);
}
.reader-bottom .btn { min-width: 108px; }

/* Landscape iPad: picture beside the words. Nothing below the fold. */
@media (min-aspect-ratio: 1/1) and (min-width: 700px) {
  .spread {
    grid-template-rows: none;
    grid-template-columns: minmax(0, 56fr) minmax(0, 44fr);
  }
  .spread.art-hidden { grid-template-rows: none; grid-template-columns: minmax(0, 68fr) minmax(0, 32fr); }
  .story-line { font-size: clamp(1.7rem, 4.4vh + 0.6rem, 3.1rem); }
  .page-text { padding: 22px 30px; }
}

/* Phone portrait: shrink the picture, never the words. */
@media (max-width: 520px) {
  .spread { grid-template-rows: minmax(0, 62fr) minmax(0, 38fr); gap: 10px; }
  .spread.art-hidden { grid-template-rows: minmax(0, 74fr) minmax(0, 26fr); }
  .reveal { min-height: 72px; padding: 12px 18px; font-size: 0.92rem; }
  .reveal svg { width: 24px; height: 24px; }
  .story-line { font-size: clamp(1.45rem, 3.4vh + 0.9rem, 2.1rem); }
  .reader-bottom .btn { min-width: 0; flex: 1; padding: 0 12px; }
}

/* ------------------------------------------------------------------ finish card */
.finish {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: max(16px, var(--safe-l));
  background: rgba(61, 47, 54, 0.35);
  backdrop-filter: blur(4px);
  animation: fadein 220ms var(--ease);
}
.finish-card {
  width: min(560px, 100%);
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--paper);
  border-radius: var(--r-2xl);
  padding: 26px;
  box-shadow: 0 40px 80px -40px rgba(61, 47, 54, 0.9);
}
.finish-card h2 { font-size: 1.6rem; }
.finish-card .row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; }
.finish-card .row3 .btn { min-width: 0; padding: 0 8px; font-size: 0.95rem; }

/* find-the-word game */
.hunt { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--rule); }
.hunt .prompt { font-family: var(--font-read); font-size: 1.35rem; margin-bottom: 12px; }
.hunt .prompt b { color: var(--leaf-deep); }
.hunt .options { display: flex; flex-wrap: wrap; gap: 10px; }
.hunt .options button {
  font-family: var(--font-read);
  font-size: 1.5rem;
  min-height: 60px;
  padding: 0 22px;
  border-radius: var(--r-lg);
  border: 2px solid var(--rule-strong);
  background: #fffdf8;
}
.hunt .options button.right { border-color: var(--leaf); background: var(--leaf-soft); }
.hunt .options button.wrong { opacity: 0.35; }
.hunt .done { color: var(--leaf-deep); font-weight: 700; }

/* ------------------------------------------------------------------ parent desk */
.section { margin-bottom: 34px; }
.section > h2 { font-size: 1.3rem; margin-bottom: 4px; }
.section > .hint { color: var(--muted); font-size: 0.92rem; margin-bottom: 14px; max-width: 62ch; }

.setlist { display: flex; flex-direction: column; gap: 8px; }
.setrow {
  display: flex; align-items: center; gap: 14px;
  width: 100%; text-align: left;
  min-height: 60px; padding: 10px 16px;
  border: 1px solid var(--rule);
  border-radius: var(--r-lg);
  background: #fffdf8;
}
.setrow[data-on='1'] { background: var(--leaf-soft); border-color: rgba(62, 107, 74, 0.4); }
.setrow .num {
  flex: none; width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--paper-2); font-size: 0.8rem; font-weight: 700; color: var(--muted);
}
.setrow[data-on='1'] .num { background: var(--leaf); color: #fbf7ef; }
.setrow .body { min-width: 0; }
.setrow .name { font-weight: 700; font-family: var(--font-read); letter-spacing: 0.03em; }
.setrow .blurb { font-size: 0.86rem; color: var(--muted); }

.wordstats { display: flex; flex-wrap: wrap; gap: 8px; }
.wordstat {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: 999px;
  background: #fffdf8; border: 1px solid var(--rule);
  font-family: var(--font-read);
}
.wordstat .n { font-size: 0.78rem; color: var(--muted); font-family: var(--font-ui); }
.wordstat.tricky { border-color: rgba(46, 107, 111, 0.5); color: var(--stretch); }

/* Checking the sounds. Tap targets stay finger-sized because this gets used
   one-handed, standing up, while someone waits to be read to. */
.soundgrid { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.soundchip {
  min-height: 44px; padding: 8px 16px; border-radius: 999px;
  background: #fffdf8; border: 1px solid var(--rule); color: inherit;
  font-family: var(--font-read); font-size: 1.05rem; cursor: pointer;
}
.soundchip:hover { border-color: var(--ink); }
.soundchip.held { border-color: var(--stretch); color: var(--stretch); }

.toggle {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  min-height: 60px; padding: 8px 4px;
  border-bottom: 1px solid var(--rule);
}
.toggle:last-child { border-bottom: none; }
.toggle .label { font-weight: 700; }
.toggle .desc { font-size: 0.88rem; color: var(--muted); }
.switch {
  flex: none; width: 64px; height: 44px; border-radius: 999px;
  border: 1px solid var(--rule-strong); background: var(--paper-3); position: relative;
  transition: background 160ms var(--ease);
}
.switch::after {
  content: ''; position: absolute; top: 7px; left: 7px;
  width: 28px; height: 28px; border-radius: 50%; background: #fffdf8;
  box-shadow: 0 2px 6px rgba(61, 47, 54, 0.3);
  transition: transform 180ms var(--ease);
}
.switch[aria-checked='true'] { background: var(--leaf); }
.switch[aria-checked='true']::after { transform: translateX(24px); }

.stepper { display: inline-flex; align-items: center; gap: 4px; }
.stepper button {
  width: 46px; height: 46px; border-radius: var(--r-md);
  border: 1px solid var(--rule-strong); background: #fffdf8; font-size: 1.3rem; font-weight: 700;
}
.stepper .val { min-width: 44px; text-align: center; font-weight: 700; font-size: 1.1rem; }

/* ------------------------------------------------------------------ toast */
.toast-host {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(96px + var(--safe-b)); z-index: 90;
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none;
}
.toast {
  background: var(--ink); color: var(--paper);
  padding: 12px 20px; border-radius: 999px;
  font-size: 0.95rem; font-weight: 600;
  box-shadow: 0 16px 34px -18px rgba(0, 0, 0, 0.7);
  animation: rise 240ms var(--ease);
  max-width: min(90vw, 460px); text-align: center;
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ------------------------------------------------------------------ onboarding + auth */
.onboard { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.onboard-card { width: min(560px, 100%); }
.onboard-card h1 { font-size: 2rem; margin-bottom: 6px; }
.level-list { display: flex; flex-direction: column; gap: 10px; margin: 18px 0 24px; }
.level {
  text-align: left; width: 100%;
  min-height: 68px; padding: 12px 18px;
  border: 1px solid var(--rule); border-radius: var(--r-lg);
  background: #fffdf8;
}
.level[aria-pressed='true'] { background: var(--leaf-soft); border-color: rgba(62, 107, 74, 0.45); }
.level .name { font-weight: 700; }
.level .blurb { font-size: 0.88rem; color: var(--muted); }

/* ------------------------------------------------------------------ spinner */
.spinner {
  width: 18px; height: 18px; flex: none;
  border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------------ print */
/* One scene + its words per sheet. Fold, staple, read. */
.print-screen-only { display: block; }

/* On screen the booklet is a preview, not a page: never let a 1152px
   illustration push the whole document sideways on an iPad. */
.booklet { max-width: 820px; margin: 0 auto; padding: 0 16px 40px; }
.booklet img { max-width: 100%; height: auto; display: block; margin: 0 auto; }
.booklet .sheet { margin-bottom: 28px; }
.booklet .text-print {
  font-family: var(--font-read);
  font-size: clamp(1.2rem, 3vw, 1.6rem);
  line-height: 1.5;
  margin-bottom: 10px;
}
.booklet .cover-sheet h1 { font-size: clamp(1.6rem, 5vw, 2.4rem); }
.booklet .pnum { text-align: center; color: var(--muted); font-size: 0.85rem; }

@media print {
  @page { size: letter portrait; margin: 12mm; }

  html, body {
    background: #fff !important;
    color: #000;
    font-size: 12pt;
  }
  body { background-image: none !important; }

  .no-print, .print-screen-only, .topbar, .reader-bottom, .toast-host { display: none !important; }

  .sheet {
    page-break-after: always;
    break-after: page;
    height: 245mm;
    display: flex;
    flex-direction: column;
    gap: 8mm;
  }
  .sheet:last-child { page-break-after: auto; break-after: auto; }

  .sheet .scene-print {
    flex: 1 1 auto;
    min-height: 0;
    border: 1pt solid #bbb;
    border-radius: 4mm;
    overflow: hidden;
    display: grid;
    place-items: center;
  }
  .sheet .scene-print img {
    width: 100%; height: 100%; object-fit: contain;
  }
  .sheet .text-print {
    flex: none;
    font-family: var(--font-read);
    font-size: 22pt;
    line-height: 1.5;
    letter-spacing: 0.012em;
  }
  .sheet .pnum { flex: none; text-align: center; font-size: 10pt; color: #666; }

  .cover-sheet { text-align: center; justify-content: center; }
  .cover-sheet h1 { font-size: 30pt; line-height: 1.15; }
  .cover-sheet .for { font-size: 14pt; margin-top: 4mm; color: #444; }
  .cover-sheet .cover-img { max-height: 150mm; max-width: 100%; margin: 8mm auto 0; }

  .notes-sheet { font-size: 11pt; line-height: 1.5; }
  .notes-sheet h2 { font-size: 16pt; margin-bottom: 3mm; }
  .notes-sheet .stretch-list { margin: 4mm 0; }
  .notes-sheet .stretch-list li { margin-bottom: 2mm; font-size: 13pt; }
  .notes-sheet .fold { margin-top: 10mm; font-style: italic; color: #555; }

  a { text-decoration: none; color: #000; }
  .w { display: inline; padding: 0; margin: 0; box-shadow: none !important; color: #000 !important; }
}

/* ------------------------------------------------------------------ motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ------------------------------------------------------------------ added components */

.eyebrow {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}
.small { font-size: 0.88rem; }
.err { color: #8c3b3b; font-size: 0.92rem; margin: -6px 0 14px; }
.grow { flex: 1; }
.field-label { font-size: 0.9rem; font-weight: 700; color: var(--muted); margin-bottom: 8px; }
.generate-go { margin-top: 16px; }
.mini-select {
  min-height: 46px; padding: 0 12px; border-radius: var(--r-md);
  border: 1px solid var(--rule-strong); background: #fffdf8; font-size: 0.95rem;
}
.add-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.add-row input {
  flex: 1 1 160px; min-width: 0; min-height: 50px; padding: 12px 14px; font-size: 1rem;
  border: 1px solid var(--rule-strong); border-radius: var(--r-md); background: #fffdf8;
}
.saved { padding: 8px 0 40px; }

/* ------------------------------------------------------------------ tonight */
/* Last night's book, first and largest. Four reads of one book beats one read
   of four; changing the default does that without a single nag. */
.tonight {
  display: grid;
  grid-template-columns: minmax(0, 200px) minmax(0, 1fr);
  gap: 20px;
  align-items: center;
  padding: 18px;
  margin-bottom: 28px;
  border: 1px solid var(--rule);
  border-radius: var(--r-2xl);
  background: linear-gradient(180deg, rgba(255, 253, 248, 0.95), rgba(255, 253, 248, 0.62));
  box-shadow: 0 18px 40px -34px rgba(61, 47, 54, 0.9);
}
.tonight-face { display: block; border-radius: var(--r-xl); overflow: hidden; }
.tonight-cover { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; }
.tonight-fallback {
  aspect-ratio: 4 / 3;
  display: grid; place-items: center; padding: 14px; text-align: center;
  background: linear-gradient(150deg, var(--paper-2), var(--paper-3));
  font-family: var(--font-display); font-size: 1.1rem; line-height: 1.25;
}
.tonight-body h2 { font-size: clamp(1.3rem, 2.6vw, 1.8rem); margin-bottom: 4px; }
.tonight-body .btn { margin-top: 14px; text-decoration: none; }
@media (max-width: 560px) {
  .tonight { grid-template-columns: 1fr; }
}

/* Read marks: an analog leaf per read, capped at four, then it stops changing.
   The signal is "this book looks loved", not "3 of 4 complete". */
.leaves { display: inline-flex; gap: 4px; align-items: center; min-height: 14px; }
.leaf {
  width: 11px; height: 11px; flex: none;
  background: var(--leaf);
  border-radius: 0 60% 0 60%;
  transform: rotate(-18deg);
  opacity: 0.85;
}

/* ------------------------------------------------------------------ sounds card */
.sounds { margin-bottom: 30px; }
.sound-row {
  font-family: var(--font-read);
  font-size: clamp(1.1rem, 2.4vw, 1.5rem);
  letter-spacing: 0.06em;
  color: var(--name);
  word-spacing: 0.1em;
  line-height: 1.7;
}

/* ------------------------------------------------------------------ reveal */
.scene { position: relative; }
.scene.is-empty { border-style: dashed; background: transparent; }
.scene .scene-note { position: absolute; color: var(--muted); font-size: 0.95rem; }

.reveal {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 18px 24px;
  border: 2px dashed rgba(62, 107, 74, 0.55);
  border-radius: var(--r-xl);
  background: rgba(62, 107, 74, 0.05);
  color: var(--leaf-deep);
  font-weight: 700;
  font-size: 0.98rem;
  min-height: 88px;
  transition: background 160ms var(--ease), color 160ms var(--ease);
}
.reveal:hover { background: var(--paper-2); color: var(--ink); }
.reveal svg { width: 30px; height: 30px; color: var(--leaf); }

/* ------------------------------------------------------------------ coach */
/* The highest-risk cueing vector is not the app, it is a loving grown-up saying
   "what do you think it is, look at the picture". Supply the replacement line. */
.coach {
  flex: none;
  max-width: 62ch;
  margin: 8px auto 0;
  padding: 0 20px;
  font-size: 0.9rem;
  line-height: 1.45;
  color: var(--muted);
  text-align: center;
}
@media (max-height: 560px) { .coach { display: none; } }

/* ------------------------------------------------------------------ page turn */
.reader.turn .story-line { animation: pagein 260ms var(--ease); }
@keyframes pagein {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ------------------------------------------------------------------ word chain */
.finish-card .ask { margin-top: 18px; }
.finish-card .keep-row { margin-top: 20px; }
.finish-actions { display: flex; gap: 8px; margin-top: 22px; }
.finish-actions .btn { text-decoration: none; }

.chain {
  margin-top: 18px; padding: 18px;
  border: 1px solid var(--rule); border-radius: var(--r-xl);
  background: var(--paper-2);
}
.chain-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.chain .prompt { font-family: var(--font-read); font-size: 1.15rem; }
.chain .prompt.done { color: var(--leaf-deep); font-weight: 700; }
.chain .say-again { min-height: 46px; padding: 0 16px; font-size: .92rem; }

.chain .tiles { display: flex; gap: 8px; align-items: center; margin: 16px 0 4px; }
.chain .tile {
  display: grid; place-items: center;
  width: 60px; height: 70px;
  font-family: var(--font-read); font-size: 2.1rem; font-weight: 700;
  background: #fffdf8; border: 1px solid var(--rule-strong); border-radius: var(--r-md);
}
.chain .tile.slot { border: 2px dashed var(--stretch); background: transparent; }
.chain .tile.filled {
  border: 2px solid var(--leaf); color: var(--leaf-deep); background: var(--leaf-soft);
  animation: settle 320ms var(--ease);
}
@keyframes settle { from { transform: scale(0.86); } to { transform: none; } }

.chain .chain-label { margin-top: 14px; font-size: .86rem; font-weight: 700; color: var(--muted); }
.chain .tile-choices { display: flex; gap: 10px; margin-top: 8px; }
.chain .tile-choice {
  width: 64px; height: 68px;
  font-family: var(--font-read); font-size: 2rem; font-weight: 700;
  background: var(--paper); border: 2px solid var(--rule-strong); border-radius: var(--r-lg);
  transition: transform 120ms var(--ease), border-color 160ms var(--ease);
}
.chain .tile-choice:active:not(:disabled) { transform: scale(0.94); }
.chain .tile-choice.right { border-color: var(--leaf); background: var(--leaf-soft); color: var(--leaf-deep); }
.chain .tile-choice.wrong { opacity: 0.3; }
.chain .chain-hint {
  margin-top: 12px; min-height: 1.6em;
  font-family: var(--font-read); font-size: 1.5rem; font-weight: 700; color: var(--leaf-deep);
}

/* ------------------------------------------------------------------ holding */
.w.is-holding { background: rgba(46, 107, 111, 0.2); }

/* ------------------------------------------------------------------ first-run hint */
/* Nothing else on the reading page says the words can be touched, and the whole
   teaching mechanic depends on her finding out. Once, then never again. */
.first-hint {
  font-size: 0.98rem;
  color: var(--leaf-deep);
  font-weight: 700;
  animation: rise 400ms var(--ease);
}

.w.beckon {
  animation: beckon 2.4s var(--ease) 3;
  border-radius: 0.22em;
}
@keyframes beckon {
  0%, 70%, 100% { background: transparent; }
  35% { background: rgba(62, 107, 74, 0.22); }
}

/* ------------------------------------------------------------------ grown-up row */
/* Visually separate from her two buttons, so the calibration question reads as
   the parent's and not as part of her book. */
.grown-up {
  margin-top: 26px;
  padding-top: 18px;
  border-top: 1px solid var(--rule);
}
.grown-up .row3 { margin-top: 8px; }
.grown-up .row3 .btn { min-height: 46px; font-size: 0.9rem; }
.grown-up .keep-row { margin-top: 16px; }
.grown-up .print-link { margin-top: 10px; padding-left: 0; }

.chain-go { min-height: 52px; }

/* The read-aloud chip lives in the top bar now, not dead centre of the bottom:
   the fastest path through a book must not be "have it read to me, next". */
.chip-link.is-on { background: var(--leaf); color: #fbf7ef; }

.sound-out .ph {
  transition: background 140ms var(--ease), color 140ms var(--ease), transform 140ms var(--ease);
}
.sound-out .ph.on { transform: translateY(-2px); }

.reader-bottom .grow { flex: 1; }

/* ------------------------------------------------------------------ theme chips */
/* She cannot read the labels yet, so every chip carries a mark she can. */
.chip .thumb {
  font-size: 1.15rem;
  line-height: 1;
  margin-right: 7px;
  filter: saturate(0.75);
}

/* ------------------------------------------------------------------ warnings */
.open-warning {
  background: #8c3b3b;
  color: #fdf6ec;
  font-size: 0.85rem;
  font-weight: 700;
  text-align: center;
  padding: calc(8px + var(--safe-t)) 16px 8px;
}
@media print { .open-warning { display: none; } }
