:root {
  --bg: #FFF6E9;
  --paper: #FFFFFF;
  --ink: #2A2233;
  --muted: #857B8E;
  --faint: #EFE5D6;
  --accent: #E8742A;
  --accent-deep: #C85A14;
  --spoken: #D2601A;
  --mark: #FFD84A;
  --mark-ink: #2A2233;
  --turn: #DDF3E4;
  --turn-ink: #1C6E3F;
  --gold: #F5B800;
  --shadow: 0 2px 0 rgba(42, 34, 51, .06), 0 10px 28px rgba(42, 34, 51, .08);
  --font-poem: 'Andika', 'Avenir Next', 'Segoe UI', system-ui, sans-serif;
  --font-ui: 'Nunito', 'Avenir Next', 'Segoe UI', system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1D1922; --paper: #28222F; --ink: #F5EFE6; --muted: #A89DB2; --faint: #3A3244;
    --accent: #F08A3E; --accent-deep: #FFA360; --spoken: #FFA360; --turn: #1E3A2B; --turn-ink: #8FE3B2;
    --shadow: 0 2px 0 rgba(0, 0, 0, .2), 0 10px 28px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1D1922; --paper: #28222F; --ink: #F5EFE6; --muted: #A89DB2; --faint: #3A3244;
  --accent: #F08A3E; --accent-deep: #FFA360; --spoken: #FFA360; --turn: #1E3A2B; --turn-ink: #8FE3B2;
  --shadow: 0 2px 0 rgba(0, 0, 0, .2), 0 10px 28px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-weight: 600;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
svg { fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.emoji { font-family: 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', sans-serif; font-weight: 400; }
[hidden] { display: none !important; }

.view { max-width: 880px; margin: 0 auto; padding: max(16px, env(safe-area-inset-top)) 16px 150px; }

/* ---------- Home ---------- */
.home-head { display: flex; align-items: center; gap: 14px; margin: 12px 0 24px; }
.home-head h1 { font-size: clamp(30px, 6vw, 44px); font-weight: 900; margin: 0; letter-spacing: -.01em; }
.logo { font-size: 52px; display: inline-block; animation: bob 2.4s ease-in-out infinite; }
/* Every card is the size of the biggest one: equal rows, and each card fills its cell. */
.cards { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); grid-auto-rows: 1fr; gap: 16px; }
.cards li { display: flex; }
.card {
  flex: 1;
  display: flex; flex-direction: column; gap: 6px; padding: 22px; min-height: 180px;
  background: var(--paper); border-radius: 26px; box-shadow: var(--shadow);
  color: inherit; text-decoration: none; transition: transform .15s;
}
.card:active { transform: scale(.98); }
.card { position: relative; }
.kind-badge {
  position: absolute; top: 18px; right: 18px; padding: 4px 12px; border-radius: 999px;
  font-size: 13px; font-weight: 800; letter-spacing: .02em;
}
.kind-badge.kind-poem { color: var(--turn-ink); background: color-mix(in srgb, var(--turn-ink) 14%, transparent); }
.kind-badge.kind-song { color: var(--accent-deep); background: color-mix(in srgb, var(--accent) 18%, transparent); }
.card .cover { font-size: 56px; line-height: 1; margin-bottom: 6px; }
.card .t { font-family: var(--font-poem); font-size: 28px; font-weight: 700; }
/* Author and stars sit at the bottom, so authors line up across a row whatever the title length. */
.card .a { color: var(--muted); margin-top: auto; }

/* ---------- Reader: top ---------- */
.topbar { display: flex; align-items: center; gap: 10px; }
.title-wrap { flex: 1; min-width: 0; }
.title-wrap h1 { margin: 0; font-size: clamp(20px, 4vw, 28px); font-weight: 900; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  flex: none; width: 52px; height: 52px; border-radius: 50%; border: 0;
  display: grid; place-items: center; background: var(--paper); box-shadow: var(--shadow);
  color: var(--ink); font-size: 26px; text-decoration: none; transition: transform .12s, background .2s;
}
.icon-btn svg { width: 26px; height: 26px; }
.icon-btn:active { transform: scale(.94); }
.icon-btn[aria-pressed="true"] { background: var(--mark); box-shadow: 0 0 0 3px var(--accent) inset; }

.stars { display: flex; gap: 3px; margin-top: 2px; }
.star { width: 20px; height: 20px; }
.star path { fill: var(--faint); stroke: none; }
.star.on path { fill: var(--gold); }

.modes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 16px; }
.modes button, .levels button {
  border: 0; border-radius: 20px; padding: 10px 4px 12px; background: var(--paper); box-shadow: var(--shadow);
  font-weight: 800; font-size: 15px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  transition: transform .15s, background .2s, color .2s;
}
.modes .emoji { font-size: 32px; line-height: 1.15; }
.modes button[aria-pressed="true"] { background: var(--accent); color: #fff; transform: translateY(-2px); }
.levels { display: flex; gap: 8px; margin-top: 10px; }
.levels button { flex: 1; flex-direction: row; justify-content: center; gap: 8px; padding: 10px; font-size: 15px; }
.levels .emoji { font-size: 22px; }
.levels button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }

/* ---------- Poem ---------- */
.poem {
  margin-top: 16px; padding: clamp(18px, 4vw, 40px) clamp(12px, 3vw, 32px);
  background: var(--paper); border-radius: 30px; box-shadow: var(--shadow);
  font-size: clamp(25px, 4.6vw, 42px);
}
.line {
  display: flex; align-items: baseline; gap: .35em; padding: .12em .3em; margin: 0 -.1em;
  border-radius: .45em; transition: background-color .25s, opacity .35s;
}
.line.stanza-start { margin-top: .75em; }
.line.kind-title { margin-bottom: .45em; }
.line.kind-label { margin-bottom: -.15em; }
.label-text { margin: 0; font-family: var(--font-ui); font-size: .5em; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
/* Songs follow the school sheet: verses in regular weight, the refrain in bold. */
.poem.song .w { font-weight: 400; }
.poem.song .line.refrain .w { font-weight: 700; }
.line.kind-title .words { font-size: 1.2em; }
.line.kind-title .w { font-weight: 700; }
.line.kind-author { justify-content: flex-end; font-size: .72em; margin-top: 1.1em; font-style: italic; }
.pic {
  flex: none; width: 2.1em; padding: 0; border: 0; background: none; text-align: center;
  font-size: .8em; line-height: 1; align-self: center; transition: transform .2s;
}
.pic:active { transform: scale(1.25); }
.no-pics .pic { display: none; }
.words { margin: 0; font-family: var(--font-poem); line-height: 1.45; flex: 1; min-width: 0; }
.kind-author .words { flex: none; }
.w {
  display: inline-block; color: var(--muted); border-radius: .22em; padding: 0 .07em; margin: 0 -.07em;
  transition: color .12s, background-color .12s, transform .12s;
  cursor: pointer; user-select: none; -webkit-user-select: none;
}
.w.spoken { color: var(--spoken); }
.w.current { color: var(--mark-ink); background: var(--mark); transform: scale(1.08); }
.line.active { background: color-mix(in srgb, var(--mark) 16%, transparent); }
.line.turn { background: var(--turn); }
.line.turn .w, .line.turn .w.spoken { color: var(--turn-ink); }
.line.out { opacity: .32; }
[data-mode="build"] .line.out { opacity: .1; }
.line.unspoken { opacity: .45; }
.tr { display: none; font-family: var(--font-ui); font-size: .5em; color: var(--muted); font-weight: 600; margin-top: -.1em; }
.poem[data-tr="bg"] .tr[lang="bg"], .poem[data-tr="en"] .tr[lang="en"] { display: block; }

/* Pictures-only practice: each word shows as a blank bar until it is spoken. */
.hide-text .w:not(.spoken):not(.current) { color: transparent; background: var(--faint); }
.hide-text .line.turn .w { color: transparent; background: color-mix(in srgb, var(--turn-ink) 22%, transparent); }
.hide-text .tr { visibility: hidden; }

/* ---------- Dock ---------- */
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  padding: 26px 16px max(16px, env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, transparent, var(--bg) 34%);
  pointer-events: none;
}
.dock-inner {
  max-width: 880px; margin: 0 auto; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px;
}
.dock-inner > * { pointer-events: auto; }
.dock-left { min-width: 0; }
.dock-center { display: flex; align-items: center; gap: 12px; position: relative; }
.dock-right { display: flex; justify-content: flex-end; align-items: center; gap: 10px; }
.status { margin: 0; font-weight: 800; font-size: 17px; color: var(--muted); line-height: 1.25; }
.play {
  width: 88px; height: 88px; border-radius: 50%; border: 0; display: grid; place-items: center;
  background: var(--accent); color: #fff; box-shadow: 0 6px 0 var(--accent-deep), 0 14px 30px rgba(232, 116, 42, .35);
  transition: transform .1s, box-shadow .1s;
}
.play:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--accent-deep), 0 8px 18px rgba(232, 116, 42, .3); }
.play svg { width: 40px; height: 40px; fill: currentColor; stroke-width: 1.5; }
.play .i-stop, .play.on .i-play { display: none; }
.play.on .i-stop { display: block; }
.small-round {
  position: absolute; right: calc(100% + 10px); width: 46px; height: 46px; border-radius: 50%; border: 0;
  display: grid; place-items: center; background: var(--paper); box-shadow: var(--shadow); color: var(--ink);
}
.small-round svg { width: 22px; height: 22px; }

.turn { display: flex; align-items: center; gap: 10px; }
.parrot { font-size: 48px; line-height: 1; display: inline-block; animation: bob .9s ease-in-out infinite; }
.turn-text { flex: 1; min-width: 0; }
.turn-text strong { display: block; font-size: 22px; font-weight: 900; color: var(--turn-ink); }
.drain { height: 10px; border-radius: 5px; background: var(--faint); overflow: hidden; margin-top: 6px; }
.drain i { display: block; height: 100%; width: 100%; background: var(--turn-ink); border-radius: 5px; transform-origin: left; }
@keyframes drain { from { transform: scaleX(1); } to { transform: scaleX(0); } }
.next {
  border: 0; border-radius: 26px; padding: 14px 22px; font-weight: 900; font-size: 20px;
  background: var(--turn-ink); color: var(--paper); box-shadow: var(--shadow);
}
.next.big { padding: 18px 28px; font-size: 24px; animation: pulse 1.2s ease-in-out infinite; }
.skip-btn {
  width: 64px; height: 64px; border-radius: 50%; border: 0; display: grid; place-items: center;
  background: var(--turn-ink); color: var(--paper); box-shadow: var(--shadow);
  animation: pulse 1.2s ease-in-out infinite;
}
.skip-btn svg { width: 32px; height: 32px; fill: currentColor; stroke: none; }

/* ---------- Settings ---------- */
dialog {
  border: 0; border-radius: 26px; padding: 24px; width: min(460px, calc(100vw - 32px));
  background: var(--paper); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
dialog::backdrop { background: rgba(29, 25, 34, .45); }
dialog h2 { margin: 0 0 14px; font-weight: 900; }
dialog h2 small { font-size: 14px; color: var(--muted); font-weight: 700; margin-left: 6px; }
fieldset { border: 0; padding: 0; margin: 0 0 14px; }
legend { font-weight: 800; margin-bottom: 6px; }
.seg { display: flex; background: var(--faint); border-radius: 14px; padding: 4px; gap: 4px; }
.seg label { flex: 1; text-align: center; padding: 9px 6px; border-radius: 10px; cursor: pointer; font-size: 15px; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { background: var(--paper); box-shadow: var(--shadow); font-weight: 800; }
.seg label:has(input:focus-visible) { outline: 2px solid var(--accent); }
fieldset:disabled { opacity: .45; }
.note { font-size: 14px; color: var(--muted); margin: 0 0 12px; }
.done { width: 100%; border: 0; border-radius: 16px; padding: 14px; font-weight: 900; font-size: 18px; background: var(--accent); color: #fff; }

/* ---------- Celebration ---------- */
.party {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; overflow: hidden;
  background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
.bit { position: absolute; top: -60px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(calc(100vh + 120px)) rotate(540deg); } }
.bravo { position: relative; text-align: center; padding: 30px 40px; background: var(--paper); border-radius: 30px; box-shadow: var(--shadow); animation: pop .5s cubic-bezier(.2, 1.6, .4, 1) both; }
.bravo-word { font-size: clamp(48px, 12vw, 84px); font-weight: 900; color: var(--accent); line-height: 1.1; }
.bravo .stars { justify-content: center; gap: 8px; margin-top: 10px; }
.bravo .star { width: 44px; height: 44px; }

@keyframes bob { 0%, 100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-6px) rotate(4deg); } }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.06); } }
@keyframes pop { from { transform: scale(.4); opacity: 0; } }

@media (max-width: 560px) {
  .modes { gap: 6px; }
  .modes button { font-size: 13px; border-radius: 16px; }
  .modes .emoji { font-size: 26px; }
  .play { width: 76px; height: 76px; }
  .play svg { width: 34px; height: 34px; }
  .status { font-size: 14px; }
  .parrot { font-size: 36px; }
  .turn-text strong { font-size: 17px; }
  .next { padding: 12px 14px; font-size: 17px; }
  .next.big { padding: 14px 16px; font-size: 19px; }
  .skip-btn { width: 52px; height: 52px; }
  .skip-btn svg { width: 26px; height: 26px; }
  .dock-right .icon-btn { width: 46px; height: 46px; font-size: 22px; }
  .small-round { right: calc(100% + 6px); width: 40px; height: 40px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .w.current { transform: none; }
}
