/* Yara Reads: a storybook at dusk. Warm paper, plum ink, dragon ember and gold. */

:root {
  --paper: #fbf5ea;
  --paper-2: #f2e7d3;
  --card: #fffdf8;
  --ink: #2a2440;
  --ink-soft: #6e6585;
  --line: #e6dac4;
  --ember: #e0533a;
  --ember-deep: #b53b27;
  --ember-soft: #fbe2da;
  --gold: #f2b33d;
  --gold-soft: #fde9b8;
  --moss: #4f8a6b;
  --dusk: #3c3570;
  --plum-soft: #ebe5f6;
  --press: 0 5px 0 rgba(42, 36, 64, 0.16);
  --lift: 0 14px 34px rgba(42, 36, 64, 0.14);
  --ui: 'Fredoka', system-ui, sans-serif;
  --read: 'Andika', system-ui, sans-serif;
  --cover-egg: #e0533a;
  --cover-tear: #4f6fb0;
  --cover-bog: #4f8a6b;
  --cover-sun: #e9a23b;
  --cover-moon: #3c3570;
  --cover-sparkle: #7fb3d5;
  --cover-wheel: #e58c8a;
  --cover-crash: #8a64b8;
  --cover-whoa: #e0533a;
  --cover-feelings: #4f8a6b;
  --cover-float: #3c3570;
}

/* touch-action: manipulation turns off double-tap zoom (iOS ignores user-scalable=no) but keeps pinch and scroll. */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

html, body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  font-family: var(--ui);
  font-weight: 500;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}
body {
  background:
    radial-gradient(1200px 600px at 10% -10%, #fff 0%, transparent 60%),
    radial-gradient(900px 500px at 110% 110%, var(--paper-2) 0%, transparent 60%),
    var(--paper);
  min-height: 100dvh;
}

button, input { font: inherit; color: inherit; }
button { border: none; background: none; cursor: pointer; padding: 0; }
.icon { width: 1em; height: 1em; display: block; }
.round .icon { width: 1.2em; height: 1.2em; }

/* A chunky button that presses down like a real one. */
.press {
  background: var(--card);
  box-shadow: var(--press), 0 0 0 2px var(--line) inset;
  transition: transform 0.08s, box-shadow 0.08s;
}
.press:active { transform: translateY(4px); box-shadow: 0 1px 0 rgba(42, 36, 64, 0.16), 0 0 0 2px var(--line) inset; }
.press[disabled] { opacity: 0.3; pointer-events: none; }
.press.ember { background: var(--ember); color: #fff; box-shadow: 0 5px 0 var(--ember-deep); }
.press.ember:active { box-shadow: 0 1px 0 var(--ember-deep); }

.round {
  width: 60px; height: 60px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 28px; flex-shrink: 0;
}

/* ---------- Wordmark ---------- */

.brand { display: flex; align-items: center; gap: 12px; }
.brand .logo { width: 52px; height: 52px; }
.brand .name { font-size: 34px; font-weight: 700; letter-spacing: -0.01em; }
.brand .name em { font-style: normal; color: var(--ember); }

/* ---------- Keypad screens (PIN, grown-ups gate) ---------- */

.keyscreen {
  min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 22px; padding: 24px 16px;
  text-align: center;
}
.keyscreen h2 { margin: 0; font-size: 26px; font-weight: 600; }
.keyscreen p { margin: -10px 0 0; color: var(--ink-soft); font-size: 18px; }
.slots { display: flex; gap: 12px; }
.slots span {
  width: 22px; height: 22px; border-radius: 50%;
  border: 3px solid var(--ink-soft); transition: background 0.1s, border-color 0.1s;
}
.slots.digits span {
  width: 46px; height: 58px; border-radius: 14px; border-width: 2.5px;
  display: grid; place-items: center; font-size: 30px; font-weight: 600;
}
.slots span.on { background: var(--ink); border-color: var(--ink); }
.slots.digits span.on { background: var(--card); }
.slots.shake { animation: shake 0.4s; }
@keyframes shake { 25% { transform: translateX(-10px); } 75% { transform: translateX(10px); } }
.keys { display: grid; grid-template-columns: repeat(3, 76px); gap: 16px; }
.keys button { height: 76px; border-radius: 50%; font-size: 30px; font-weight: 600; display: grid; place-items: center; }
.keys .erase { font-size: 30px; }
.link { color: var(--ink-soft); font-size: 18px; padding: 8px 16px; }

/* ---------- Library ---------- */

.library { max-width: 980px; margin: 0 auto; padding: 28px 16px 48px; }
.library header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 30px; }
.series-title {
  display: flex; align-items: center; gap: 12px;
  font-size: 22px; font-weight: 600; color: var(--ink-soft);
  margin: 0 0 16px;
}
.series-title::after { content: ''; flex: 1; height: 2px; background: var(--line); border-radius: 2px; }
.shelf + .series-title { margin-top: 36px; }
.shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 22px 18px; }

.book {
  border-radius: 22px; overflow: hidden; text-align: left;
  display: flex; flex-direction: column;
  position: relative;
}
.book .art { aspect-ratio: 1 / 0.9; display: grid; place-items: center; }
.book .motif { width: 78%; height: 78%; }
.book .art.photo { overflow: hidden; background: var(--paper-2); }
.book .art.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.book .meta { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 4px; }
.book .num { font-size: 14px; font-weight: 600; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.08em; }
.book .title { font-size: 21px; font-weight: 600; line-height: 1.15; min-height: 2.3em; }
.book .times { margin-top: 2px; min-height: 22px; font-size: 15px; color: var(--ink-soft); }
.book.next { box-shadow: var(--press), 0 0 0 3px var(--gold) inset; }
.book .tag {
  position: absolute; top: 10px; right: 10px;
  background: var(--gold); color: var(--ink);
  font-size: 14px; font-weight: 600; padding: 3px 10px; border-radius: 99px;
}

.star { width: 22px; height: 22px; fill: var(--paper-2); stroke: var(--line); stroke-width: 1.5; }
.star.on { fill: var(--gold); stroke: #d99a22; }

.grownups-btn {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 16px; color: var(--ink-soft);
  padding: 10px 16px; border-radius: 99px;
}
.grownups-btn .icon { font-size: 18px; }
.library-foot { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 8px 20px; margin-top: 40px; }
.library-foot .link { flex-basis: 100%; text-align: center; }
.fine-links { flex-basis: 100%; text-align: center; font-size: 14px; }
.fine-links a { color: var(--ink-soft); margin: 0 8px; }

/* ---------- Reader ---------- */

.reader {
  /* Exactly one screen: the picture shrinks, then the text (fitPage in app.js), never the buttons. */
  height: 100vh; height: 100dvh; max-width: 1040px; margin: 0 auto;
  display: flex; flex-direction: column; gap: 14px;
  padding: 14px 16px 18px;
}
.topbar { display: flex; align-items: center; gap: 12px; }
.topbar .title { flex: 1; text-align: center; font-size: 19px; font-weight: 600; color: var(--ink-soft); }
.topbar .spacer { width: 60px; }

.sheet {
  flex: 1; min-height: 0; overflow: hidden;
  background: var(--card);
  border-radius: 28px;
  box-shadow: var(--lift), 0 0 0 2px var(--line) inset;
  display: flex; align-items: center; justify-content: center;
  padding: 32px 28px;
  position: relative;
}
.text {
  font-family: var(--read);
  font-size: clamp(32px, 6.4vw, 56px);
  line-height: 1.85;
  max-width: 21ch;
  word-spacing: 0.14em;
}
.text .w {
  border-radius: 10px; padding: 0 3px; margin: 0 -3px;
  cursor: pointer; transition: background 0.15s, box-shadow 0.15s;
}
.text .w.active { background: var(--gold-soft); box-shadow: 0 3px 0 var(--gold); }
/* A word she can't read yet (books from home): quiet, so the page still reads as a page. */
.text .w.new { text-decoration: underline dotted var(--ink-soft); text-decoration-thickness: 2px; text-underline-offset: 0.22em; }

/* Pages with a picture: the picture runs edge to edge in the card and fills the space the text leaves
   (object-fit: cover), stacked on tall screens, side by side when there's room. The box is kept within
   about 20% of the picture's own shape either way (--ia, its aspect ratio, set in app.js when it loads),
   so cover never crops more than ~20% off any picture: on the iPad in landscape a plain half-card box
   was taller than wide and cut a third off every picture (half of Julia's face on the bee page). */
.sheet.with-picture {
  flex-direction: column; align-items: stretch; padding: 0; gap: 0;
  container-type: size; --ia: 1.3333;
}
.sheet.with-picture .picture {
  flex: 1 1 auto; position: relative;
  min-height: calc(100cqw / (var(--ia) * 1.25));
  max-height: calc(100cqw / (var(--ia) * 0.8));
}
.sheet.with-picture .picture img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; object-position: center 40%; display: block;
}
.sheet.with-picture .text { flex: 0 0 auto; align-self: center; margin-block: auto; padding: 18px 24px 22px; }
.sheet.with-picture .text { font-size: clamp(28px, 5vw, 44px); line-height: 1.7; }
/* Long text on a tall screen: the picture may lose up to about a third rather than the text getting tiny. */
.sheet.with-picture.tight .picture { min-height: calc(100cqw / (var(--ia) * 1.6)); }
@media (min-width: 760px) and (min-aspect-ratio: 5/4) {
  .sheet.with-picture { flex-direction: row; }
  /* Full height; as wide as the picture's shape asks, but leaving the text at least ~40% of the card. */
  .sheet.with-picture .picture {
    flex: 0 0 auto; min-height: 0; max-height: none;
    width: min(calc(100cqh * var(--ia)), 60cqw);
    min-width: min(calc(100cqh * var(--ia) * 0.8), 66cqw);
  }
  .sheet.with-picture .text { flex: 1 1 0; min-width: 0; max-width: none; padding: 24px 28px; }
}

.nav { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.nav .round { width: 76px; height: 76px; font-size: 34px; }
.nav .round.ember { font-size: 36px; }
.progress { flex: 1; max-width: 360px; display: flex; gap: 6px; }
.progress span { flex: 1; height: 8px; border-radius: 8px; background: var(--line); }
.progress span.on { background: var(--ember); }

/* ---------- Word card: the hint lives on the word ---------- */

.pop {
  position: fixed; z-index: 10;
  background: var(--card);
  border-radius: 24px;
  box-shadow: 0 18px 50px rgba(42, 36, 64, 0.28), 0 0 0 2px var(--line) inset;
  padding: 14px;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  animation: pop 0.16s ease-out;
}
@keyframes pop { from { transform: scale(0.88) translateY(6px); opacity: 0; } }

.chips { display: flex; gap: 6px; }
.chip {
  /* --chip shrinks for long words so the card never leaves the screen (fitPop in app.js). */
  font-family: var(--read); font-size: var(--chip, 46px); line-height: 1;
  padding: 0.22em 0.26em 0.26em; min-width: 1.17em; border-radius: 16px;
  background: var(--paper);
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  transition: background 0.12s, transform 0.12s;
}
/* Sound buttons, as in class: a dot under one letter, a bar under letters that make one sound. */
.chip .mark { height: 9px; width: 100%; display: flex; justify-content: center; }
.chip .mark::after { content: ''; background: var(--ember); border-radius: 9px; }
.chip.one .mark::after { width: 11px; height: 11px; }
.chip.many .mark::after { width: 78%; height: 8px; }
.chip.lit { background: var(--gold-soft); transform: translateY(-3px); }
/* Silent e: the vowel and its e share a tint and an arc, the way it's drawn in class. */
.chip.split { background: var(--ember-soft); }
.chip.split .mark::after { display: none; }
.chip.split.lit { background: var(--gold-soft); }
/* A sound she hasn't learned yet: plum instead of ember, so known sounds still stand out. */
.chip.new { background: var(--plum-soft); color: var(--dusk); }
.chip.new .mark::after { background: var(--dusk); }
.chip.new.lit { background: var(--gold-soft); }
.badge.new { background: var(--paper-2); color: var(--ink-soft); }
.chips.linked { position: relative; padding-bottom: 18px; }
.chips .links { position: absolute; left: 0; top: 0; pointer-events: none; overflow: visible; }
.chips .links path { fill: none; stroke: var(--ember); stroke-width: 7; stroke-linecap: round; }
.chips .links path.new { stroke: var(--dusk); }

.whole { font-family: var(--read); font-size: var(--chip, 46px); padding: 2px 14px; }
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 16px; font-weight: 600; border-radius: 99px; padding: 4px 12px 4px 8px;
  background: var(--plum-soft); color: var(--dusk);
}
.badge .star { width: 18px; height: 18px; }
.pop .actions { display: flex; gap: 10px; }
.pop .actions button {
  height: 52px; border-radius: 16px; padding: 0 18px;
  display: inline-flex; align-items: center; gap: 10px;
  font-size: 19px; font-weight: 600;
}
.pop .actions .icon { font-size: 24px; }
.pop .actions .speak { width: 60px; height: 56px; padding: 0; justify-content: center; border-radius: 18px; }
.pop .actions .speak .icon { font-size: 28px; }

/* ---------- The End ---------- */

.end {
  min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; padding: 24px 16px; text-align: center;
}
.end .big { font-size: 64px; font-weight: 700; margin: 0; }
@keyframes starpop { from { transform: scale(0) rotate(-30deg); } }
.end .said { font-size: 26px; margin: 0; }
.end .next { font-size: 24px; font-weight: 600; border-radius: 20px; padding: 16px 28px; display: inline-flex; align-items: center; gap: 12px; }

/* ---------- Grown-ups ---------- */

.admin { max-width: 860px; margin: 0 auto; padding: 24px 16px 64px; -webkit-user-select: text; user-select: text; }
.admin header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.admin h1 { margin: 0; font-size: 30px; font-weight: 700; }
.admin .done { height: 48px; border-radius: 16px; padding: 0 20px; font-size: 18px; font-weight: 600; display: inline-flex; align-items: center; gap: 8px; }
.panel {
  background: var(--card); border-radius: 24px;
  box-shadow: 0 0 0 2px var(--line) inset;
  padding: 22px; margin-bottom: 18px;
}
.panel h2 { margin: 0 0 4px; font-size: 22px; font-weight: 600; display: flex; justify-content: space-between; align-items: baseline; }
.panel h2 small { font-size: 15px; color: var(--ink-soft); font-weight: 500; }
.panel > p { margin: 0 0 16px; color: var(--ink-soft); font-size: 16px; line-height: 1.45; }
.panel h3 { font-size: 15px; font-weight: 600; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.08em; margin: 18px 0 10px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(62px, 1fr)); gap: 10px; }
.tile {
  height: 62px; border-radius: 50%;
  font-family: var(--read); font-size: 24px;
  display: grid; place-items: center;
  background: var(--paper); color: var(--ink-soft);
  box-shadow: 0 0 0 2px var(--line) inset;
  transition: background 0.12s, color 0.12s;
}
.tile { flex-direction: column; gap: 0; line-height: 1; }
.tile small { font-family: var(--ui); font-size: 11px; font-weight: 500; opacity: 0.8; margin-top: 3px; }
.tile.on { background: var(--dusk); color: #fff; box-shadow: 0 4px 0 #29234f; }

.wordlist { display: flex; flex-wrap: wrap; gap: 8px; }
.wordchip {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--plum-soft); color: var(--dusk);
  font-family: var(--read); font-size: 19px;
  border-radius: 99px; padding: 4px 6px 4px 14px;
}
.wordchip button { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-size: 15px; opacity: 0.6; }
.wordchip button:hover { opacity: 1; background: rgba(60, 53, 112, 0.1); }
.wordchip.plain { padding-right: 14px; }
.wordchip .count { font-family: var(--ui); font-size: 14px; opacity: 0.7; margin-left: 4px; }
.adder { display: flex; gap: 8px; margin-top: 14px; }
.adder input {
  flex: 1; min-width: 0; height: 48px; border-radius: 14px; padding: 0 14px;
  border: 2px solid var(--line); background: var(--paper); font-size: 18px; outline: none;
}
.adder input:focus { border-color: var(--dusk); }
.adder button { height: 48px; padding: 0 18px; border-radius: 14px; display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }

.bookrow { display: flex; gap: 14px; align-items: flex-start; padding: 12px 0; border-top: 2px solid var(--paper-2); }
.bookrow:first-of-type { border-top: none; }
.bookrow .dot { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: 16px; flex-shrink: 0; margin-top: 2px; }
.bookrow .dot.ok { background: var(--moss); }
.bookrow .dot.bad { background: var(--ember); }
.bookrow .dot.home { background: var(--dusk); font-size: 12px; font-weight: 600; width: 34px; height: 34px; }
.muted { color: var(--ink-soft); font-size: 15px; }
.bookrow b { font-weight: 600; font-size: 18px; }
.bookrow div div { color: var(--ink-soft); font-size: 15px; margin-top: 2px; }
.panel .check { height: 48px; padding: 0 20px; border-radius: 14px; font-weight: 600; font-size: 17px; }
.days { font-size: 16px; color: var(--ink-soft); line-height: 1.7; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: #fff; border-radius: 99px; padding: 10px 18px;
  font-size: 16px; display: flex; align-items: center; gap: 8px;
  animation: pop 0.16s ease-out;
}

@media (max-width: 520px) {
  .brand .name { font-size: 28px; }
  .brand .logo { width: 44px; height: 44px; }
  .shelf { grid-template-columns: repeat(2, 1fr); gap: 16px 12px; }
  .book .title { font-size: 18px; }
  .sheet { padding: 28px 20px; border-radius: 22px; }
  .nav .round { width: 66px; height: 66px; font-size: 30px; }
  .keys { grid-template-columns: repeat(3, 70px); }
  .keys button { height: 70px; }
}

/* ---------- Grown-ups tabs ---------- */

.tabs {
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
  margin: -8px -16px 18px; padding: 4px 16px 6px;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  flex-shrink: 0; text-decoration: none; color: var(--ink-soft);
  font-size: 17px; font-weight: 600; padding: 10px 16px; border-radius: 99px;
  box-shadow: 0 0 0 2px var(--line) inset; background: var(--card);
}
.tabs a.on { background: var(--dusk); color: #fff; box-shadow: 0 4px 0 #29234f; }

/* ---------- Voice ---------- */

.voices { display: flex; flex-direction: column; }
.voicerow { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-top: 2px solid var(--paper-2); }
.voicerow:first-child { border-top: none; }
.voicerow .try { width: 52px; height: 48px; border-radius: 14px; display: grid; place-items: center; font-size: 22px; flex-shrink: 0; }
.voicerow .pick { flex: 1; text-align: left; padding: 8px 0; font-size: 18px; }
.voicerow .pick b { font-weight: 600; }
.voicerow.chosen .pick b { color: var(--dusk); }
.voicerow .inuse { display: inline-flex; align-items: center; gap: 6px; color: var(--moss); font-weight: 600; font-size: 15px; }
.warm-status { margin-left: 12px; }

/* A speaker button waiting for its audio: the icon dims and a ring spins. */
.speak { position: relative; }
.speak.waiting .icon { opacity: 0.25; }
.speak.waiting::after {
  content: ''; position: absolute; inset: 0; margin: auto; width: 26px; height: 26px;
  border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--dusk);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Grown-ups > App: the sound log, one line per word said. */
.soundlog { display: flex; flex-direction: column; gap: 4px; font-size: 15px; font-variant-numeric: tabular-nums; }
.soundlog div { display: flex; gap: 10px; flex-wrap: wrap; padding: 4px 0; border-top: 1px solid var(--paper-2); }
.soundlog div.bad { color: var(--ember-deep); }
.soundlog b { font-family: var(--read); font-weight: 400; min-width: 70px; }

/* Sound buttons you can tap to hear (grown-ups > Voice > "Tap a sound to hear it"). */
.chips.tappable .chip { cursor: pointer; }
.chips.tappable .chip:active { transform: translateY(2px); }

/* On/off rows in grown-ups. */
.switchrow { display: flex; align-items: center; gap: 16px; width: 100%; text-align: left; padding: 12px 0; border-top: 2px solid var(--paper-2); }
.switchrow:first-of-type { border-top: none; }
.switchrow > span:first-child { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.switchrow b { font-weight: 600; font-size: 18px; }
.switch { width: 52px; height: 30px; border-radius: 99px; background: var(--line); position: relative; flex-shrink: 0; transition: background 0.15s; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: var(--card); box-shadow: 0 1px 3px rgba(42, 36, 64, 0.25); transition: transform 0.15s; }
.switch.on { background: var(--moss); }
.switch.on::after { transform: translateX(22px); }

/* ---------- Agents ---------- */
.newkey { background: var(--gold-soft); border-radius: 16px; padding: 14px 16px; margin: 12px 0; display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.newkey p { margin: 0; }
.newkey input { width: 100%; font: 15px/1.3 ui-monospace, monospace; padding: 10px 12px; border-radius: 12px; border: 2px solid var(--line); background: #fff; }
.newkey code { font-size: 14px; overflow-wrap: anywhere; }
