/* Draw Along: styles. Phones first; no external fonts or assets. */

:root {
  --bg: #FFF5EA;
  --paper: #fbf7ef;
  --graphite: #2f2b33;
  --ink: #3E3B47;
  --text: #3A3542;
  --muted: #7B7183;
  --line: #F0E1D1;
  --card-shadow: #EBDCCB;
  --primary: #F2672E;
  --primary-deep: #C24A18;
  --sun: #FFC233;
  --sun-deep: #DE9800;
  --danger: #DE4560;
  --danger-deep: #A92E46;
  --focus: #2B7BE4;
  --gold: #FFB91F;
  --gold-deep: #D99000;

  /* category colours (overridden by [data-cat]) */
  --accent: #F2672E;
  --accent-deep: #D2551F;
  --accent-shadow: #A9400F;
  --accent-tint: #FFEBDD;

  --radius: 22px;
  --font: ui-rounded, "Nunito", "Segoe UI Rounded", "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --sat: var(--studio-sat, env(safe-area-inset-top, 0px));
  --sab: var(--studio-sab, env(safe-area-inset-bottom, 0px));
  --sal: var(--studio-sal, env(safe-area-inset-left, 0px));
  --sar: var(--studio-sar, env(safe-area-inset-right, 0px));
  color-scheme: light;
}

[data-cat="techniques"]     { --accent: #16A39B; --accent-deep: #0E7F78; --accent-shadow: #085A55; --accent-tint: #DDF3F1; }
[data-cat="shaded"]         { --accent: #6E6880; --accent-deep: #4B4658; --accent-shadow: #322E3C; --accent-tint: #ECEAF1; }
[data-cat="all"]            { --accent: #8A7C93; --accent-deep: #5A4F63; --accent-shadow: #3D3445; --accent-tint: #F1ECF3; }
[data-cat="starter"]        { --accent: #FF8A3D; --accent-deep: #E0601C; --accent-shadow: #A84410; --accent-tint: #FFEBDA; }
[data-cat="animals"]        { --accent: #F25C7A; --accent-deep: #D63F62; --accent-shadow: #9E2B47; --accent-tint: #FFE6EC; }
[data-cat="things-that-go"] { --accent: #3A8DEB; --accent-deep: #2470D0; --accent-shadow: #18509A; --accent-tint: #E3EFFD; }
[data-cat="nature"]         { --accent: #34B26A; --accent-deep: #1E8F50; --accent-shadow: #146638; --accent-tint: #E0F5E8; }
[data-cat="fantasy"]        { --accent: #9466F2; --accent-deep: #7A4ADF; --accent-shadow: #5530A8; --accent-tint: #EEE6FE; }

*, *::before, *::after { box-sizing: border-box; }

html {
  overscroll-behavior: contain;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(70vmax 45vmax at -10% -10%, #FFE4CC 0, rgba(255, 228, 204, 0) 60%),
    radial-gradient(60vmax 40vmax at 110% 0%, #FDE2EC 0, rgba(253, 226, 236, 0) 60%),
    var(--bg);
  overflow-x: hidden;
  overflow-x: clip;
  -webkit-tap-highlight-color: transparent;
  line-height: 1.35;
}

/* During a lesson the page never scrolls. */
html[data-screen="lesson"],
html[data-screen="lesson"] body {
  height: 100%;
  overflow: hidden;
}

button { font: inherit; color: inherit; }
img, svg { max-width: 100%; }
.screen[hidden], [hidden] { display: none !important; }

:focus { outline: none; }
:focus-visible { outline: 4px solid var(--focus); outline-offset: 3px; }

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

/* ---------- buttons ---------- */

.btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5em;
  min-height: 52px;
  padding: 0 1.25em;
  border-radius: 999px;
  font-weight: 800;
  font-size: 1.05rem;
  line-height: 1.1;
  letter-spacing: .01em;
  background: var(--b, #fff);
  color: var(--bt, var(--text));
  box-shadow: 0 4px 0 var(--bs, var(--card-shadow));
  transition: transform .12s ease, box-shadow .12s ease, filter .12s ease;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  white-space: nowrap;
}
.btn svg { width: 1.4em; height: 1.4em; flex: none; }
.btn:hover { filter: brightness(1.04); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--bs, var(--card-shadow)); }
.btn:disabled { opacity: .55; cursor: default; transform: none; }
.btn-primary { --b: var(--primary); --bt: #fff; --bs: var(--primary-deep); }
.btn-sun     { --b: var(--sun); --bt: #4A3300; --bs: var(--sun-deep); }
.btn-soft    { --b: #fff; --bt: var(--text); --bs: var(--card-shadow); outline: 2px solid var(--line); outline-offset: -2px; }
.btn-soft:focus-visible { outline: 4px solid var(--focus); outline-offset: 3px; }
.btn-danger  { --b: var(--danger); --bt: #fff; --bs: var(--danger-deep); }

.icon-btn {
  appearance: none;
  flex: none;
  width: 52px;
  height: 52px;
  padding: 0;
  border: 2px solid var(--line);
  border-radius: 16px;
  background: #fff;
  color: var(--text);
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--card-shadow);
  transition: transform .12s ease, box-shadow .12s ease, background-color .2s;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.icon-btn svg { width: 26px; height: 26px; }
.icon-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--card-shadow); }
.icon-btn .mini { font-size: 10.5px; font-weight: 800; line-height: 1; margin-top: 2px; letter-spacing: .02em; }
.icon-btn.toggle svg { width: 24px; height: 24px; }

/* ---------- HOME ---------- */

.home {
  max-width: 1120px;
  margin: 0 auto;
  padding: calc(16px + var(--sat)) calc(16px + var(--sar)) calc(28px + var(--sab)) calc(16px + var(--sal));
}

.home-head {
  display: grid;
  grid-template-areas: "brand" "tag" "actions";
  gap: 10px;
  margin-bottom: 14px;
}
.brand { grid-area: brand; display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { width: clamp(46px, 12vw, 64px); height: auto; flex: none; }
.brand-squiggle {
  fill: none; stroke: #F2672E; stroke-width: 5; stroke-linecap: round;
  stroke-dasharray: 64; stroke-dashoffset: 0;
  animation: squiggle 1.3s .15s ease-out both;
}
@keyframes squiggle { from { stroke-dashoffset: 64; } to { stroke-dashoffset: 0; } }
.brand-name {
  margin: 0;
  font-size: clamp(32px, 9vw, 54px);
  line-height: 1;
  font-weight: 900;
  letter-spacing: -.01em;
  white-space: nowrap;
}
.brand-name .w1 { color: #E85A22; }
.brand-name .w2 { color: #7A4ADF; }

.sticker-pill {
  margin-left: auto;
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 14px 0 10px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 3px 0 var(--card-shadow);
  font-weight: 900;
  font-size: 18px;
  color: #6B4A00;
}
.sticker-pill svg { width: 26px; height: 26px; color: var(--gold); filter: drop-shadow(0 1px 0 var(--gold-deep)); }
.sticker-pill.bump { animation: bump .6s ease; }
@keyframes bump { 30% { transform: scale(1.18) rotate(-4deg); } 60% { transform: scale(.96); } }

.tagline {
  grid-area: tag;
  margin: 0;
  font-size: clamp(16px, 4.3vw, 21px);
  color: var(--muted);
  font-weight: 700;
}

.home-actions { grid-area: actions; display: flex; flex-wrap: wrap; gap: 10px; }
.home-actions .btn { flex: 1 1 auto; }

@media (min-width: 720px) {
  .home-head {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "brand brand" "tag actions";
    align-items: center;
    row-gap: 6px;
    margin-bottom: 18px;
  }
  .home-actions .btn { flex: 0 0 auto; }
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 18px; }
.chip {
  appearance: none;
  min-height: 48px;
  padding: 0 16px 0 11px;
  border-radius: 999px;
  border: 2px solid var(--line);
  background: #fff;
  color: var(--text);
  font-weight: 800;
  font-size: 15.5px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--card-shadow);
  transition: background-color .15s, color .15s, transform .12s;
  touch-action: manipulation;
  white-space: nowrap;
}
.chip svg { width: 22px; height: 22px; color: var(--accent); flex: none; }
.chip:active { transform: translateY(2px); }
.chip[aria-pressed="true"] {
  background: var(--accent-deep);
  border-color: var(--accent-deep);
  color: #fff;
  box-shadow: 0 3px 0 var(--accent-shadow);
}
.chip[aria-pressed="true"] svg { color: #fff; }

/* Phones: a compact grid of chips, labels may wrap onto two lines. */
@media (max-width: 559px) {
  .chips {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    gap: 8px;
  }
  .chip {
    min-width: 0;
    padding: 5px 8px 5px 8px;
    gap: 6px;
    font-size: 14px;
    line-height: 1.1;
    white-space: normal;
    text-align: left;
    border-radius: 16px;
  }
  .chip svg { width: 20px; height: 20px; }
}

.lesson-list { min-height: 200px; }
.loading-note, .list-note {
  text-align: center;
  color: var(--muted);
  font-weight: 800;
  font-size: 18px;
  padding: 40px 0;
}
.list-note .btn { margin-top: 14px; }

.cat-section { margin: 0 0 26px; }
.cat-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  font-size: clamp(20px, 5.4vw, 26px);
  font-weight: 900;
  color: var(--accent-deep);
}
.cat-head svg { width: 28px; height: 28px; color: var(--accent); }
.cat-head .count {
  font-size: 14px;
  font-weight: 800;
  color: var(--accent-deep);
  background: var(--accent-tint);
  border-radius: 999px;
  padding: 2px 10px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(156px, 44%), 1fr));
  gap: clamp(10px, 2.6vw, 18px);
}

.card {
  appearance: none;
  border: 0;
  padding: 0;
  margin: 0;
  text-align: left;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: 0 3px 0 var(--card-shadow), 0 10px 22px rgba(150, 100, 60, .10);
  overflow: hidden;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  transition: transform .16s ease, box-shadow .16s ease;
  touch-action: manipulation;
  min-width: 0;
}
.card:hover { transform: translateY(-3px) rotate(-.5deg); box-shadow: 0 5px 0 var(--card-shadow), 0 16px 28px rgba(150, 100, 60, .14); }
.card:active { transform: scale(.97); }
.card-art {
  position: relative;
  display: block;
  aspect-ratio: 1;
  background-color: var(--accent-tint);
  background-image: radial-gradient(circle, rgba(120, 90, 60, .14) 1.1px, transparent 1.6px);
  background-size: 10% 10%;
  background-position: center;
}
.card-sheet {
  position: absolute;
  inset: 7%;
  border-radius: 9%;
  background: var(--paper);
  box-shadow: 0 1px 0 rgba(140, 100, 60, .14), 0 4px 10px rgba(140, 90, 40, .10);
  overflow: hidden;
}
.card-sheet svg { position: absolute; inset: 2%; width: 96%; height: 96%; display: block; }
.card { content-visibility: auto; contain-intrinsic-size: auto 250px; }
.ribbon {
  position: absolute;
  left: 6px;
  top: 8px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px 3px 5px;
  border-radius: 999px;
  background: var(--graphite);
  color: #fff;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .02em;
  box-shadow: 0 2px 0 rgba(0, 0, 0, .18);
  transform: rotate(-4deg);
}
.ribbon svg { width: 15px; height: 15px; flex: none; }
.done-badge {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--gold);
  color: #fff;
  box-shadow: 0 2px 0 var(--gold-deep), 0 0 0 3px #fff;
  display: none;
  place-items: center;
  transform: rotate(-8deg);
}
.done-badge svg { width: 24px; height: 24px; }
.card.is-done .done-badge { display: grid; }
.card-info { display: grid; gap: 3px; padding: 10px 12px 12px; }
.card-title {
  font-weight: 900;
  font-size: clamp(15.5px, 4.1vw, 18px);
  line-height: 1.18;
  overflow-wrap: anywhere;
}
.card-level {
  display: flex;
  align-items: center;
  gap: 1px;
  font-size: 13px;
  font-weight: 800;
  color: var(--accent-deep);
}
.card-level svg { width: 17px; height: 17px; flex: none; }
.card-level svg.off { opacity: .22; }
.card-level span { margin-left: 5px; }

.home-foot {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
  color: var(--muted);
  font-weight: 700;
  font-size: 15px;
  text-align: center;
}
.home-foot svg { width: 22px; height: 22px; flex: none; }

/* ---------- PAPER ---------- */

.paper {
  background-color: var(--paper);
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .45 0 0 0 0 .34 0 0 0 0 .22 .05 0 0 0 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 160px 160px;
  border-radius: clamp(14px, 4%, 28px);
  box-shadow:
    0 2px 0 #EADBC9,
    0 14px 32px rgba(140, 90, 40, .15),
    inset 0 0 0 1.5px rgba(160, 120, 80, .10);
  overflow: hidden;
}

/* ---------- LESSON ---------- */

/* One column at every size, top to bottom: the step's words, the paper, the buttons.
   The paper is square and gets whatever the width or the height leaves over; the
   words strip and the buttons have fixed heights so the paper never jumps between
   steps. Free height (phones) is split above and below the group, so the three
   always touch. */
.lesson {
  --vh: 100vh;
  --pad-t: 8px;
  --pad-b: 10px;
  --pad-x: 12px;
  --gap: clamp(6px, calc(var(--vh) * .014), 14px);
  --bar-h: 52px;
  --ctrl-h: 60px;
  --strip-h: clamp(88px, calc(var(--vh) * .15), 132px);
  --thumb: clamp(48px, min(15vw, calc(var(--vh) * .08)), 84px);
  --avail-w: calc(100vw - 2 * var(--pad-x) - var(--sal) - var(--sar));
  --avail-h: calc(var(--vh) - var(--pad-t) - var(--pad-b) - var(--sat) - var(--sab) - var(--bar-h) - var(--strip-h) - var(--ctrl-h) - 3 * var(--gap));
  --stage-size: max(0px, min(var(--avail-w), var(--avail-h)));
  --col-w: max(var(--stage-size), min(420px, var(--avail-w)));
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--gap);
  padding: calc(var(--pad-t) + var(--sat)) calc(var(--pad-x) + var(--sar)) calc(var(--pad-b) + var(--sab)) calc(var(--pad-x) + var(--sal));
  overflow: hidden;
}
@supports (height: 100dvh) {
  .lesson { --vh: 100dvh; }
}
.lesson.rich { --strip-h: clamp(104px, calc(var(--vh) * .19), 168px); }

.lesson-bar { flex: none; align-self: stretch; display: flex; align-items: center; gap: 8px; min-width: 0; }
.bar-start { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; container: bar / inline-size; }
.bar-end { flex: none; display: flex; align-items: center; gap: 8px; }
.lesson-name { flex: 1; min-width: 0; display: grid; padding: 0 2px; }
.lesson-title {
  font-weight: 900;
  font-size: clamp(17px, 4.8vw, 24px);
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lesson-cat {
  font-size: 13px;
  font-weight: 800;
  color: var(--accent-deep);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#btn-speed[aria-pressed="true"] { background: var(--accent-tint); border-color: var(--accent); color: var(--accent-deep); }
#btn-voice[aria-pressed="true"] { color: var(--accent-deep); }
#btn-voice[aria-pressed="false"] { color: var(--muted); }
#btn-voice.speaking .wave1 { animation: wave 1s ease-in-out infinite; }
#btn-voice.speaking .wave2 { animation: wave 1s .2s ease-in-out infinite; }
@keyframes wave { 50% { opacity: .25; } }

.stage-wrap {
  grid-area: stage;
  flex: 0 1 var(--stage-size);
  width: var(--col-w);
  max-width: 100%;
  min-height: 0;
  min-width: 0;
  container-type: size;
  display: grid;
  place-items: center;
}
.stage {
  position: relative;
  width: min(100%, 52vh);
  aspect-ratio: 1;
  width: min(100cqw, 100cqh);
  height: min(100cqw, 100cqh);
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.stage-svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* Drawing strokes (same look as draw-kit/preview.mjs) */
.st-line { fill: none; stroke-linecap: round; stroke-linejoin: round; transition: stroke .55s ease; }
.st-line.ink { stroke: var(--graphite); }
.st-line.live { stroke: var(--accent); }
.st-guide { fill: none; stroke: #8f9bb3; stroke-width: 2.5; stroke-dasharray: 8 7; stroke-linecap: round; stroke-linejoin: round; }
.st-hatch { fill: none; stroke-linecap: round; transition: stroke .55s ease; }
.st-hatch.ink { stroke: var(--graphite); }
.st-hatch.live { stroke: var(--accent); }
.tone-ink > stop { stop-color: #3a3540; }
.tone-live > stop { stop-color: var(--accent); }
.fade { animation: stroke-fade .35s ease-out both; }
html[data-preview] .st-line, html[data-preview] .st-hatch { transition: none; }
@keyframes stroke-fade { from { opacity: 0; } to { opacity: 1; } }

.stage-tools {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  will-change: transform;
  transition: opacity .3s ease;
}
.pencil, .pencil-shadow, .eraser, .eraser-shadow { transition: opacity .2s ease; }
.eraser, .eraser-shadow { opacity: 0; }
.stage-tools.erasing .eraser,
.stage-tools.erasing .eraser-shadow { opacity: 1; }
.stage-tools.erasing .pencil,
.stage-tools.erasing .pencil-shadow { opacity: 0; }
.eraser-shadow rect { fill: rgba(90, 60, 30, .17); }
.eraser-body { fill: #FF9EB4; }
.eraser-sleeve { fill: #6FA8F5; }
.eraser-stripe { fill: none; stroke: rgba(255, 255, 255, .75); stroke-width: 2; }
.eraser-outline { fill: none; stroke: #3E3B47; stroke-width: 2.4; }
.pencil-shadow path { fill: rgba(90, 60, 30, .17); }
.pencil-wood { fill: #F6D3A1; }
.pencil-lead { fill: var(--accent-deep); }
.pencil-body { fill: var(--accent); }
.pencil-shine { fill: rgba(255, 255, 255, .34); }
.pencil-shade { fill: rgba(0, 0, 0, .13); }
.pencil-band { fill: #CDD2DB; }
.pencil-band-line { fill: none; stroke: #9AA2B1; stroke-width: 1.6; }
.pencil-eraser { fill: #FF9EB4; }
.pencil-outline { fill: none; stroke: #3E3B47; stroke-width: 2.4; stroke-linejoin: round; }
.lesson.no-pencil .stage-tools { opacity: 0; }


/* The words strip: step number and progress on top, the instruction under it,
   and a small finished-picture thumbnail at the right end. */
.say-box {
  grid-area: say;
  flex: none;
  width: var(--col-w);
  max-width: 100%;
  height: var(--strip-h);
  min-height: 0;
  margin-top: auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: "meta thumb" "words thumb";
  column-gap: 10px;
  background: #fff;
  border-radius: 20px;
  padding: 8px 12px 8px 14px;
  box-shadow: 0 3px 0 var(--card-shadow);
  container: saybox / inline-size;
}
.step-meta {
  grid-area: meta;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 3px 8px;
  font-size: 13.5px;
  font-weight: 900;
  color: var(--accent-deep);
  min-height: 22px;
}
.your-turn {
  background: var(--accent-tint);
  color: var(--accent-deep);
  border-radius: 999px;
  padding: 1px 9px;
  opacity: 0;
  transform: scale(.6);
  transition: opacity .25s ease, transform .35s cubic-bezier(.2, 1.6, .4, 1);
  white-space: nowrap;
}
.lesson.is-your-turn .your-turn { opacity: 1; transform: none; }
.tech-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 9px 1px 5px;
  border-radius: 999px;
  background: var(--accent-tint);
  color: var(--accent-deep);
  font-size: 12.5px;
  white-space: nowrap;
}
.tech-chip svg { width: 15px; height: 15px; flex: none; }
.dots { margin-left: auto; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; max-width: 46%; }
.dots i { display: block; width: 7px; height: 7px; border-radius: 50%; background: #EEE2D6; transition: background-color .3s, transform .3s; }
.dots i.done { background: var(--accent); }
.dots i.now { background: var(--accent-deep); transform: scale(1.35); }

.say-wrap {
  grid-area: words;
  min-width: 0;
  min-height: 0;
  margin-top: 2px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
  overflow: hidden;
  cursor: pointer;
}
.tip {
  flex: none;
  margin: 0;
  font-size: clamp(13.5px, min(3.9vw, 2.4dvh), 19px);
  line-height: 1.25;
  font-weight: 700;
  color: var(--muted);
}
.say {
  flex: none;
  margin: 0;
  display: flex;
  align-items: center;
  font-size: clamp(18px, min(5.6vw, 3.6dvh), 30px);
  line-height: 1.2;
  font-weight: 800;
  color: var(--text);
  cursor: pointer;
  overflow-wrap: break-word;
  gap: .45em;
}
.say-icon { display: none; flex: none; width: 1.6em; height: 1.6em; }
.lesson.text-step .say-icon { display: block; animation: bob 2.4s ease-in-out .4s infinite; }
@keyframes bob { 50% { transform: translateY(-8%) rotate(-8deg); } }

/* The finished picture as a small thumbnail; tap it to see it big. */
.peek-thumb {
  grid-area: thumb;
  align-self: center;
  appearance: none;
  flex: none;
  width: var(--thumb);
  height: var(--thumb);
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  border-radius: 12px;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .12s ease;
}
.peek-thumb:active { transform: scale(.94); }
.peek-paper {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 12px;
  transform: rotate(2deg);
  box-shadow:
    0 2px 0 #EADBC9,
    0 4px 10px rgba(140, 90, 40, .16),
    inset 0 0 0 1.5px rgba(160, 120, 80, .16);
}
.peek-paper svg { position: absolute; inset: 6%; width: 88%; height: 88%; }

.controls {
  grid-area: controls;
  flex: none;
  width: var(--col-w);
  max-width: 100%;
  margin-bottom: auto;
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr);
  gap: 10px;
}
.ctrl {
  appearance: none;
  min-width: 64px;
  min-height: var(--ctrl-h, 60px);
  padding: 4px 12px;
  border: 2px solid var(--line);
  border-radius: 20px;
  background: #fff;
  color: var(--text);
  font-weight: 800;
  font-size: 13px;
  line-height: 1.05;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--card-shadow);
  transition: transform .12s ease, box-shadow .12s ease, opacity .2s;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  white-space: nowrap;
}
.ctrl svg { width: 26px; height: 26px; flex: none; }
.ctrl:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--card-shadow); }
.ctrl:disabled { opacity: .38; cursor: default; transform: none; box-shadow: 0 4px 0 var(--card-shadow); }
.ctrl-next {
  flex-direction: row;
  gap: 6px;
  font-size: clamp(21px, 5.8vw, 27px);
  font-weight: 900;
  background: var(--accent-deep);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 5px 0 var(--accent-shadow);
}
.ctrl-next svg { width: 1.15em; height: 1.15em; }
.ctrl-next:active { box-shadow: 0 2px 0 var(--accent-shadow); }
.lesson.is-your-turn .ctrl-next { animation: nudge 1.8s ease-in-out .3s infinite; }
@keyframes nudge {
  0%, 100% { transform: none; }
  45% { transform: translateY(-2px) scale(1.035); }
  60% { transform: translateY(0) scale(1); }
}

/* Narrow name and words boxes (small phones, and the corners in landscape). */
@container bar (max-width: 200px) {
  .lesson-cat { display: none; }
  .lesson-title {
    white-space: normal;
    font-size: 16px;
    line-height: 1.1;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }
}
@container saybox (max-width: 320px) {
  .dots { display: none; }
}
@container saybox (max-width: 560px) {
  .lesson.rich .dots { display: none; }
}

/* Landscape / desktop: still one column (words, paper, buttons). The exit, speed
   and voice buttons move into the corners beside the words strip, so the paper
   gets that height too. */
@media (min-aspect-ratio: 11/10) {
  .lesson {
    --pad-t: clamp(8px, calc(var(--vh) * .02), 20px);
    --pad-b: var(--pad-t);
    --pad-x: clamp(12px, 2.5vw, 32px);
    --col-gap: clamp(10px, 2vw, 28px);
    --side-min: 124px; /* room for the speed and voice buttons */
    --strip-h: clamp(76px, calc(var(--vh) * .13), 120px);
    --thumb: clamp(44px, calc(var(--vh) * .08), 80px);
    --avail-w: calc(100vw - 2 * var(--pad-x) - var(--sal) - var(--sar) - 2 * (var(--side-min) + var(--col-gap)));
    --avail-h: calc(var(--vh) - var(--pad-t) - var(--pad-b) - var(--sat) - var(--sab) - var(--strip-h) - var(--ctrl-h) - 2 * var(--gap));
    display: grid;
    grid-template-columns: minmax(0, 1fr) var(--col-w) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, var(--stage-size)) auto;
    grid-template-areas:
      "name  say      opts"
      ".     stage    ."
      ".     controls .";
    align-content: center;
    align-items: stretch;
    column-gap: var(--col-gap);
    row-gap: var(--gap);
  }
  .lesson.rich { --strip-h: clamp(92px, calc(var(--vh) * .17), 150px); }
  .lesson-bar { display: contents; }
  .bar-start { grid-area: name; align-self: start; }
  .bar-end { grid-area: opts; align-self: start; justify-self: end; }
  .say-box, .stage-wrap, .controls { width: auto; margin: 0; }
  .say-box { padding: 10px 14px 10px 16px; }
  .say { font-size: clamp(16px, min(2.2vw, 3.1dvh), 28px); }
  .tip { font-size: clamp(13px, min(1.7vw, 2.2dvh), 18px); }
  .ctrl { font-size: 14px; }
}

/* Short landscape (phones on their side): a slimmer words strip and buttons. */
@media (min-aspect-ratio: 11/10) and (max-height: 500px) {
  .lesson { --strip-h: 74px; --ctrl-h: 52px; --thumb: 44px; }
  .lesson.rich { --strip-h: 90px; }
  .say-box { padding: 6px 12px 6px 14px; }
  .say { font-size: clamp(14px, 4.2vh, 18px); }
  .tip { font-size: 12.5px; }
  .ctrl svg { width: 22px; height: 22px; }
}


/* ---------- FINISH ---------- */

.finish {
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 1040px;
  margin: 0 auto;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: clamp(14px, 3dvh, 28px);
  padding: calc(16px + var(--sat)) calc(16px + var(--sar)) calc(16px + var(--sab)) calc(16px + var(--sal));
  text-align: center;
}
.finish-art {
  position: relative;
  width: min(62vw, 33dvh, 340px);
  aspect-ratio: 1;
}
.finish-paper {
  position: absolute;
  inset: 0;
  overflow: visible;
  transform: rotate(-2.5deg);
  animation: pop-in .6s cubic-bezier(.2, 1.4, .4, 1) both;
}
.finish-svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.tape {
  position: absolute;
  top: -4%;
  width: 30%;
  height: 10%;
  background: rgba(255, 210, 110, .62);
  box-shadow: 0 1px 2px rgba(120, 80, 20, .12);
}
.tape-l { left: -6%; transform: rotate(-28deg); }
.tape-r { right: -6%; transform: rotate(26deg); }
@keyframes pop-in {
  from { opacity: 0; transform: scale(.7) rotate(-8deg); }
  to { opacity: 1; transform: scale(1) rotate(-2.5deg); }
}
.snap-polaroid {
  position: absolute;
  right: -10%;
  bottom: -9%;
  width: 44%;
  margin: 0;
  padding: 5% 5% 2%;
  background: #fff;
  border-radius: 6px;
  box-shadow: 0 6px 18px rgba(80, 50, 20, .25);
  transform: rotate(7deg);
  animation: polaroid-in .5s cubic-bezier(.2, 1.4, .4, 1) both;
}
.snap-polaroid img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 3px; background: #F2EAE0; }
.snap-polaroid figcaption { font-weight: 900; font-size: 14px; color: var(--nature, #1E8F50); padding-top: 3px; }
@keyframes polaroid-in { from { opacity: 0; transform: translateY(20%) rotate(20deg) scale(.7); } }

.finish-body { display: grid; gap: clamp(8px, 1.6dvh, 14px); justify-items: center; width: min(100%, 420px); }
.finish-title {
  margin: 0;
  font-size: clamp(32px, min(10vw, 7.4dvh), 58px);
  line-height: 1;
  font-weight: 900;
  color: var(--accent-deep);
}
.finish-sub { margin: 0; font-size: clamp(19px, min(5.4vw, 4dvh), 28px); font-weight: 800; }
.sticker-earned {
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 5px 16px 5px 5px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 3px 0 var(--card-shadow);
  font-weight: 700;
  font-size: 15px;
  text-align: left;
}
.sticker-star {
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 50%;
  background: var(--gold);
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: 0 2px 0 var(--gold-deep);
  animation: sticker-pop .8s .45s cubic-bezier(.2, 1.6, .4, 1) both;
}
.sticker-star svg { width: 26px; height: 26px; }
@keyframes sticker-pop { from { transform: scale(0) rotate(-90deg); } to { transform: scale(1) rotate(0); } }
.btn-big { width: 100%; min-height: 60px; font-size: 1.2rem; }
.finish-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; }
.finish-row .btn { padding: 0 .7em; font-size: 1rem; min-width: 0; }
.privacy { margin: 0; color: var(--muted); font-size: 13px; font-weight: 700; }

@media (min-aspect-ratio: 11/10) and (min-width: 600px) {
  .finish {
    grid-template-columns: auto minmax(0, 420px);
    justify-content: center;
    align-items: center;
    column-gap: clamp(24px, 5vw, 64px);
    text-align: left;
  }
  .finish-art { width: min(40vw, 64dvh, 470px); }
  .finish-body { justify-items: start; }
}

/* ---------- MY DRAWINGS ---------- */

.gallery {
  max-width: 1120px;
  margin: 0 auto;
  padding: calc(14px + var(--sat)) calc(16px + var(--sar)) calc(28px + var(--sab)) calc(16px + var(--sal));
}
.sub-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.sub-head h1 { margin: 0; font-size: clamp(26px, 7.4vw, 42px); font-weight: 900; line-height: 1.05; }
.count-pill {
  font-weight: 900;
  font-size: 15px;
  background: #fff;
  border-radius: 999px;
  padding: 3px 12px;
  box-shadow: 0 2px 0 var(--card-shadow);
}
.count-pill:empty { display: none; }
.privacy-top { display: flex; align-items: center; gap: 6px; margin: 0 0 18px; }
.privacy-top svg { width: 17px; height: 17px; flex: none; }

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(170px, 44%), 1fr));
  gap: clamp(12px, 3vw, 22px);
}
.photo {
  appearance: none;
  border: 0;
  margin: 0;
  padding: 8px 8px 10px;
  background: #fff;
  border-radius: 10px;
  text-align: left;
  cursor: pointer;
  box-shadow: 0 2px 0 var(--card-shadow), 0 8px 20px rgba(120, 80, 40, .14);
  transform: rotate(var(--tilt, 0deg));
  transition: transform .16s ease;
  min-width: 0;
  touch-action: manipulation;
}
.photo:hover { transform: rotate(0deg) translateY(-3px); }
.photo:active { transform: scale(.97); }
.photo img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 5px; background: #F2EAE0; }
.photo b { display: block; margin-top: 8px; font-size: 15.5px; line-height: 1.2; overflow-wrap: anywhere; }
.photo small { display: block; color: var(--muted); font-weight: 700; font-size: 13px; }

.empty { display: grid; justify-items: center; gap: 10px; text-align: center; padding: 36px 12px; }
.empty svg { width: 76px; height: 76px; color: #E3CDB6; }
.empty p { margin: 0; font-size: 17px; font-weight: 600; color: var(--muted); max-width: 30ch; }
.empty p b { color: var(--text); font-size: 20px; }

/* ---------- OVERLAYS ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: calc(14px + var(--sat)) calc(14px + var(--sar)) calc(14px + var(--sab)) calc(14px + var(--sal));
  background: rgba(50, 38, 58, .58);
  animation: fade-in .2s ease both;
}
@keyframes fade-in { from { opacity: 0; } }
.viewer-card {
  width: min(100%, 760px);
  max-height: 100%;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
  gap: 10px;
  padding: 12px;
  background: #fff;
  border-radius: 24px;
  box-shadow: 0 20px 50px rgba(30, 20, 40, .35);
  animation: pop-up .25s cubic-bezier(.2, 1.3, .4, 1) both;
}
@keyframes pop-up { from { transform: scale(.92); opacity: 0; } }
.viewer-card img {
  display: block;
  width: 100%;
  height: auto;
  max-height: calc(100dvh - 200px);
  min-height: 0;
  object-fit: contain;
  border-radius: 14px;
  background: #F6EFE7;
}
.viewer-meta { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 10px; padding: 0 6px; }
.viewer-meta b { font-size: 18px; }
.viewer-meta span { color: var(--muted); font-weight: 700; }
.viewer-actions { display: flex; gap: 10px; }
.viewer-actions .btn { flex: 1 1 0; min-width: 0; }
.confirm-card {
  width: min(100%, 380px);
  display: grid;
  justify-items: center;
  gap: 14px;
  padding: 24px 18px 18px;
  background: #fff;
  border-radius: 24px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(30, 20, 40, .35);
  animation: pop-up .25s cubic-bezier(.2, 1.3, .4, 1) both;
}
.confirm-card p { margin: 0; font-size: 16px; font-weight: 600; color: var(--muted); }
.confirm-card p b { font-size: 21px; color: var(--text); }
.confirm-card .viewer-actions { width: 100%; }
.confirm-icon { width: 52px; height: 52px; color: var(--danger); }

/* The finished picture, big (from the thumbnail in the words strip). Tap anywhere to close. */
.peek-card {
  --art: min(480px, calc(100vw - 56px - var(--sal) - var(--sar)), calc(100vh - 172px - var(--sat) - var(--sab)));
  width: calc(max(160px, var(--art)) + 28px);
  max-width: 100%;
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 14px 14px 16px;
  background: #fff;
  border-radius: 24px;
  box-shadow: 0 20px 50px rgba(30, 20, 40, .35);
  animation: pop-up .25s cubic-bezier(.2, 1.3, .4, 1) both;
  cursor: pointer;
}
@supports (height: 100dvh) {
  .peek-card { --art: min(480px, calc(100vw - 56px - var(--sal) - var(--sar)), calc(100dvh - 172px - var(--sat) - var(--sab))); }
}
.peek-big { position: relative; width: max(160px, var(--art)); max-width: 100%; aspect-ratio: 1; transform: rotate(-1.5deg); }
.peek-big svg { position: absolute; inset: 4%; width: 92%; height: 92%; }
.peek-label { font-size: 18px; font-weight: 900; color: var(--text); }
.peek-card .btn { width: 100%; }

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  top: calc(14px + var(--sat));
  z-index: 60;
  width: fit-content;
  max-width: calc(100% - 32px);
  margin: 0 auto;
  padding: 12px 20px;
  border-radius: 999px;
  background: #3E3B47;
  color: #fff;
  font-weight: 800;
  text-align: center;
  box-shadow: 0 8px 24px rgba(30, 20, 40, .3);
  animation: toast-in .3s cubic-bezier(.2, 1.4, .4, 1) both;
}
@keyframes toast-in { from { transform: translateY(-20px); opacity: 0; } }

.confetti { position: fixed; inset: 0; z-index: 40; pointer-events: none; overflow: hidden; }
.confetti i {
  position: absolute;
  top: -24px;
  display: block;
  width: 10px;
  height: 14px;
  border-radius: 3px;
  opacity: 0;
  animation: fall var(--dur, 3s) var(--delay, 0s) cubic-bezier(.3, .55, .55, 1) forwards;
}
.confetti i.star {
  width: 20px;
  height: 20px;
  border-radius: 0;
  clip-path: polygon(50% 0, 62% 35%, 98% 36%, 69% 58%, 79% 93%, 50% 72%, 21% 93%, 31% 58%, 2% 36%, 38% 35%);
}
.confetti i.dot { width: 11px; height: 11px; border-radius: 50%; }
@keyframes fall {
  0% { opacity: 1; transform: translate3d(0, 0, 0) rotate(0deg); }
  85% { opacity: 1; }
  100% { opacity: 0; transform: translate3d(var(--dx, 0px), 104vh, 0) rotate(var(--rot, 360deg)); }
}

.boot-error {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  background: var(--bg);
  font-size: 18px;
}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    animation-delay: 0s !important;
    transition-duration: .01ms !important;
  }
  .fade { animation-duration: .3s !important; }
  .card:hover, .photo:hover { transform: none; }
}
