/* The letter font (Andika, SIL Open Font License, see /fonts/OFL.txt) is kept
   inside the Lab, so nothing about visitors is sent to Google for it. */
@font-face {
  font-family: "Andika";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/andika-400.woff2") format("woff2");
}

@font-face {
  font-family: "Andika";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("/fonts/andika-700.woff2") format("woff2");
}

:root {
  --bg: #f8f4ef;
  --panel: #ffffff;
  --text: #2f251f;
  --muted: #6f6258;
  --line: #ddcec0;
  --brand: #c30000;
  --brand-soft: #f9dddd;
  --success: #2f7d4f;
  --gold: #f5b700;
  --gold-dark: #c98f00;
  --letter-font: "Andika", "Avenir Next", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

/* Quick double taps (common with kids) shouldn't zoom the page on iPhone.
   Pinch-to-zoom still works. */
html,
body {
  touch-action: manipulation;
}

body {
  margin: 0;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at top right, #fff8f3, var(--bg) 50%);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

h1, h2, p {
  margin: 0;
}

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

.hidden {
  display: none !important;
}

/* ---------- Header ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #fff, #fcf8f3);
  box-shadow: 0 4px 20px rgba(90, 52, 38, 0.08);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 14px;
  color: inherit;
  text-decoration: none;
  min-width: 0;
}

.master-logo {
  width: 42px;
  height: 42px;
  object-fit: contain;
}

.topbar h1 {
  font-size: 1.3rem;
  color: var(--brand);
}

.topbar p {
  color: var(--muted);
  margin-top: 2px;
  font-size: 0.85rem;
}

.star-count {
  flex-shrink: 0;
  font-weight: 700;
  font-size: 1.1rem;
  padding: 6px 12px;
  border-radius: 999px;
  background: #fff7dc;
  border: 1px solid #f1d98a;
}

/* ---------- Screens ---------- */

.screen {
  flex: 1;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

/* ---------- Path map ---------- */

.path {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.unit-banner {
  width: 100%;
  margin: 28px 0 40px;
  padding: 16px 18px;
  border-radius: 18px;
  color: var(--unit-ink);
  background: var(--unit);
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.18);
}

.unit-banner:first-child {
  margin-top: 4px;
}

.unit-banner .unit-num {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.85;
}

.unit-banner h2 {
  font-size: 1.35rem;
  margin-top: 2px;
}

.unit-banner p {
  margin-top: 2px;
  font-size: 0.95rem;
  opacity: 0.92;
}

.bubble-row {
  position: relative;
  height: 96px;
  width: 100%;
  display: flex;
  justify-content: center;
}

.bubble {
  position: relative;
  width: 78px;
  height: 78px;
  border-radius: 50%;
  border: 3px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-family: var(--letter-font);
  font-size: 2.3rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 0 var(--line);
  transform: translateX(var(--shift, 0));
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.bubble:active {
  transform: translateX(var(--shift, 0)) translateY(4px);
  box-shadow: 0 2px 0 var(--line);
}

.bubble.small-text {
  font-size: 1.8rem;
}

.bubble.next {
  border-color: var(--unit-edge);
  background: var(--unit);
  color: var(--unit-ink);
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.25);
}

.bubble.next::after {
  content: "";
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  border: 4px solid var(--unit-edge);
  opacity: 0.35;
  animation: pulse 1.6s ease-in-out infinite;
}

.start-tag {
  position: absolute;
  bottom: calc(100% + 12px);
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 12px;
  border-radius: 10px;
  background: #fff;
  color: var(--unit-edge);
  border: 2px solid var(--unit-edge);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  white-space: nowrap;
  animation: bob 1.6s ease-in-out infinite;
}

.bubble.done {
  border-color: var(--gold-dark);
  background: var(--gold);
  color: #fff;
  box-shadow: 0 6px 0 var(--gold-dark);
}

.bubble .done-star {
  position: absolute;
  top: -6px;
  right: -6px;
  font-size: 1.1rem;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 0.35; }
  50% { transform: scale(1.08); opacity: 0.15; }
}

@keyframes bob {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(-4px); }
}

@media (prefers-reduced-motion: reduce) {
  .bubble.next::after,
  .start-tag {
    animation: none;
  }
}

/* ---------- Lesson screen ---------- */

.lesson-head {
  display: flex;
  align-items: center;
  gap: 14px;
}

.back-btn {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-size: 1.2rem;
}

.lesson-progress {
  flex: 1;
  height: 16px;
  border-radius: 999px;
  background: #ece3d9;
  overflow: hidden;
}

.lesson-progress-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--success);
  transition: width 0.3s ease;
}

.lesson-body {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
}

.step-title {
  font-size: 1.4rem;
}

.step-glyph {
  font-family: var(--letter-font);
  color: var(--unit-edge);
}

/* ---------- Writing board ---------- */

.board {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: 0 6px 18px rgba(90, 52, 38, 0.06);
  padding: 8px;
}

.board-svg {
  display: block;
  width: 100%;
  height: auto;
  max-height: min(40vh, 400px);
  overflow: visible;
}

.guide-lines line {
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}

.line-top,
.line-base {
  stroke: #8fb0e3;
}

.line-mid {
  stroke: #8fb0e3;
  stroke-dasharray: 8 7;
}

.road-path,
.ink-path {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.road-path {
  stroke: #ece3d9;
  stroke-width: 15;
}

.road-dot {
  fill: #ece3d9;
}

.ink-path {
  stroke: var(--unit-edge);
  stroke-width: 9;
}

.ink-dot {
  fill: var(--unit-edge);
}

.arrow {
  fill: none;
  stroke: #9a8b7d;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.start-dot circle {
  fill: var(--text);
}

.start-dot {
  transition: opacity 0.2s ease;
}

.start-dot.used {
  opacity: 0.2;
}

.start-dot text {
  fill: #fff;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  font-size: 13px;
  font-weight: 700;
  text-anchor: middle;
}

.start-dot.small text {
  font-size: 8px;
}

.pencil {
  fill: #fff;
  stroke: var(--text);
  stroke-width: 3;
}

.hidden-pencil {
  display: none;
}

.stroke-say {
  min-height: 1.6em;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text);
}

.step-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}

.secondary-btn {
  min-width: 180px;
  padding: 14px 22px;
  border: 2px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  color: var(--text);
  font-weight: 700;
  font-size: 1.1rem;
  box-shadow: 0 4px 0 var(--line);
}

.secondary-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--line);
}

.primary-btn {
  min-width: 220px;
  padding: 14px 24px;
  border: none;
  border-radius: 16px;
  background: var(--success);
  color: #fff;
  font-weight: 700;
  font-size: 1.1rem;
  box-shadow: 0 5px 0 #1f5a37;
}

.primary-btn:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #1f5a37;
}

/* ---------- Footer ---------- */

.site-footer {
  padding: 16px 20px calc(16px + env(safe-area-inset-bottom));
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--line);
}

.site-footer a {
  color: var(--brand);
}

@media (max-width: 480px) {
  .topbar {
    padding: 8px 12px;
  }

  .topbar p {
    display: none;
  }

  .master-logo {
    width: 36px;
    height: 36px;
  }

  /* Keep "ABC & Beyond" on one line next to the header buttons. */
  .brand-block {
    gap: 8px;
  }

  .topbar h1 {
    font-size: 1.12rem;
    white-space: nowrap;
  }

  .top-right {
    gap: 6px;
  }

  .mute-btn,
  .account-btn {
    width: 38px;
    height: 38px;
    font-size: 1.05rem;
  }

  .star-count {
    padding: 5px 9px;
    font-size: 1rem;
  }
}

/* ---------- Tracing ---------- */

/* While tracing, a finger on the board draws instead of scrolling the page. */
.board-svg.tracing {
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  cursor: crosshair;
}

.board.small {
  width: 78%;
}

.board.small .board-svg {
  max-height: min(28vh, 260px);
}

.hidden-layer {
  display: none;
}

.dot-body {
  transform-box: fill-box;
  transform-origin: center;
}

.start-dot.current .dot-body circle {
  stroke: var(--gold);
  stroke-width: 3;
}

.start-dot.pulse .dot-body {
  animation: dot-bounce 0.6s ease 2;
}

@keyframes dot-bounce {
  0%, 100% { transform: scale(1); }
  40% { transform: scale(1.5); }
}

.spark {
  fill: var(--gold);
  stroke: var(--gold-dark);
  stroke-width: 0.6;
  animation: spark-fly 0.7s ease-out forwards;
}

@keyframes spark-fly {
  0% { transform: translate(0, 0) scale(0.4); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(1); opacity: 0; }
}

.stroke-say.nudge {
  color: var(--brand);
}

.stroke-say.yay {
  color: var(--success);
  font-size: 1.5rem;
}

/* ---------- Lesson finished ---------- */

.lesson-done {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 24px 0 8px;
}


.lesson-done h2 {
  font-size: 2rem;
  color: var(--success);
}

.lesson-done p {
  color: var(--muted);
  font-size: 1.1rem;
}

/* ---------- Lessons fill the screen, no scrolling ---------- */

html.lesson-mode,
html.lesson-mode body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

html.lesson-mode body {
  position: fixed;
  inset: 0;
  height: 100vh;
  height: 100dvh;
}

html.lesson-mode .site-footer {
  display: none;
}

html.lesson-mode #lessonScreen {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding-top: 12px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
}

html.lesson-mode .lesson-body {
  flex: 1;
  min-height: 0;
  margin-top: 10px;
  gap: 10px;
}

html.lesson-mode .board {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

html.lesson-mode .board-svg {
  width: 100%;
  height: 100%;
  max-height: none;
}

html.lesson-mode .board.small .board-svg {
  height: 72%;
  max-height: none;
}

html.lesson-mode .board.small {
  width: 100%;
}

html.lesson-mode .step-title {
  font-size: clamp(1.1rem, 3.2vh, 1.5rem);
}

html.lesson-mode .stroke-say {
  font-size: clamp(1rem, 2.6vh, 1.3rem);
}

html.lesson-mode .step-buttons {
  width: 100%;
  min-height: 56px;
  flex-wrap: nowrap;
}

html.lesson-mode .primary-btn,
html.lesson-mode .secondary-btn {
  min-width: 0;
  flex: 0 1 230px;
  padding: 12px 16px;
}

html.lesson-mode .lesson-done {
  flex: 1;
  justify-content: center;
}

/* ---------- Find it ---------- */

.board.find {
  padding: 10px;
}

.find-grid {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 10px;
}

.find-tile {
  min-width: 0;
  min-height: 0;
  padding: 4px;
  border: 2px solid var(--line);
  border-radius: 16px;
  background: #fffdf9;
  box-shadow: 0 4px 0 var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
}

.find-tile:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 var(--line);
}

.tile-svg {
  width: 100%;
  height: 100%;
}

.tile-base {
  stroke: #c9d8f0;
  stroke-width: 2;
}

.tile-glyph path {
  fill: none;
  stroke: var(--text);
  stroke-width: 11;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tile-glyph circle {
  fill: var(--text);
}

.find-tile.right {
  border-color: var(--success);
  background: #e3f3e8;
  box-shadow: 0 4px 0 var(--success);
}

.find-tile.right .tile-glyph path {
  stroke: var(--success);
}

.find-tile.right .tile-glyph circle {
  fill: var(--success);
}

.find-tile.wrong {
  animation: wiggle 0.4s ease;
}

@keyframes wiggle {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

/* ---------- Write it ---------- */

.free-path {
  fill: none;
  stroke: var(--unit-edge);
  stroke-width: 9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.free-path.miss {
  stroke: #d9a3a3;
  transition: opacity 0.45s ease;
  opacity: 0;
}

/* When the faded letter comes back as help, make it lighter than in tracing. */
.writing .road-path {
  stroke: #f1ebe4;
}

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

.top-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.mute-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 1.2rem;
  line-height: 1;
}

/* ---------- Meet it ---------- */

.board.meet {
  padding: 12px;
}

.meet {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  justify-items: center;
}

.meet-glyph {
  width: 100%;
  height: 100%;
  min-height: 0;
}

.meet-glyph .tile-glyph path {
  stroke: var(--unit-edge);
}

.meet-glyph .tile-glyph circle {
  fill: var(--unit-edge);
}

.meet-picture {
  width: min(100%, 260px);
  height: 100%;
  max-height: 220px;
  border-radius: 20px;
  background: #fff7ef;
  border: 2px dashed var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
}

.picture-placeholder {
  font-size: clamp(1.4rem, 4vh, 2rem);
  font-weight: 700;
  color: var(--muted);
}

.meet-frames {
  width: 100%;
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.ten-frame {
  width: min(100%, 300px);
  max-height: 48%;
}

.meet-frames .ten-frame:only-child {
  max-height: 100%;
}

.tf-cell {
  fill: #fffdf9;
  stroke: var(--text);
  stroke-width: 2.5;
}

.tf-counter {
  fill: var(--unit-edge);
  transform-box: fill-box;
  transform-origin: center;
}

/* While the number is being counted, counters light up one by one. */
.tf-counter:not(.lit) {
  opacity: 0.25;
}

.tf-counter.lit {
  animation: pop 0.3s ease;
}

@keyframes pop {
  0% { transform: scale(0.4); }
  70% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

.meet-uses {
  width: 100%;
  height: 100%;
  min-height: 0;
  display: flex;
  justify-content: center;
  gap: 10px;
}

.meet-use {
  flex: 0 1 110px;
  border: 2px solid var(--line);
  border-radius: 16px;
  background: #fffdf9;
  padding: 4px;
}

/* ---------- Celebration ---------- */

.lesson-done {
  position: relative;
  overflow: hidden;
  width: 100%;
}

.done-glyph {
  width: min(60%, 220px);
  height: clamp(110px, 24vh, 220px);
}

.done-glyph .tile-glyph path {
  stroke: var(--unit-edge);
}

.done-glyph .tile-glyph circle {
  fill: var(--unit-edge);
}

.done-stars {
  display: flex;
  gap: 12px;
  font-size: clamp(2.2rem, 7vh, 3.4rem);
}

.done-stars span {
  opacity: 0;
  transform: scale(0.2);
  animation: star-in 0.45s ease forwards;
}

.done-stars span:nth-child(2) { animation-delay: 0.3s; }
.done-stars span:nth-child(3) { animation-delay: 0.6s; }

@keyframes star-in {
  0% { opacity: 0; transform: scale(0.2) rotate(-30deg); }
  70% { opacity: 1; transform: scale(1.25) rotate(8deg); }
  100% { opacity: 1; transform: scale(1) rotate(0); }
}

.confetti {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 20;
}

.confetti i {
  position: absolute;
  top: -12px;
  width: 9px;
  height: 14px;
  border-radius: 2px;
  opacity: 0;
  animation-name: confetti-fall;
  animation-timing-function: ease-in;
  animation-fill-mode: forwards;
}

@keyframes confetti-fall {
  0% { opacity: 1; transform: translate(0, 0) rotate(0); }
  85% { opacity: 1; }
  100% { opacity: 0; transform: translate(var(--drift), 105vh) rotate(var(--spin)); }
}

@media (prefers-reduced-motion: reduce) {
  .confetti {
    display: none;
  }
}

/* "ABC & Beyond" is the name kids see; "Lab" is a small gray word beside it. */
.lab-tag {
  margin-left: 2px;
  color: var(--muted);
  font-size: 0.65em;
  font-weight: 600;
}

.meet-picture.has-art {
  border-style: solid;
  border-color: #f0e4d6;
  padding: 8px;
}

.art-svg {
  width: 100%;
  height: 100%;
}

/* ---------- Recording page (grown-ups) ---------- */

.record-screen {
  max-width: 900px;
}

.rec-head {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.rec-head h2 {
  color: var(--brand);
}

.rec-head p {
  color: var(--muted);
}

.rec-count {
  color: var(--text) !important;
}

.rec-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.rec-actions .primary-btn:disabled {
  opacity: 0.5;
}

.rec-status {
  min-height: 1.4em;
  font-weight: 600;
  color: var(--success) !important;
}

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

.rec-card {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.rec-card.has-sound {
  border-color: var(--success);
}

.rec-card.recording {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.rec-letter {
  font-family: var(--letter-font);
  font-size: 2.4rem;
  line-height: 1;
  color: var(--brand);
}

.rec-word {
  font-weight: 700;
}

.rec-tip {
  flex: 1;
  font-size: 0.85rem;
  color: var(--muted);
}

.rec-buttons {
  display: flex;
  gap: 6px;
}

.rec-btn {
  flex: 1;
  padding: 8px 6px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  font-weight: 700;
}

.rec-btn.record {
  color: var(--brand);
}

.rec-btn.play {
  flex: 0 0 44px;
}

.rec-btn:disabled {
  opacity: 0.35;
}

/* ---------- Welcome and sign-in ---------- */

body.signed-out .star-count {
  display: none;
}

.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 14px;
  padding: 32px 8px;
}

.welcome-crest {
  width: 96px;
  height: 96px;
  object-fit: contain;
}

.welcome-title {
  font-size: clamp(2.2rem, 9vw, 3rem);
  color: var(--brand);
}

.welcome-tag {
  font-size: 1.15rem;
  color: var(--text);
  max-width: 340px;
}

.welcome-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(100%, 320px);
  margin-top: 8px;
}

.welcome-buttons .primary-btn,
.welcome-buttons .secondary-btn {
  width: 100%;
}

.welcome-note {
  color: var(--muted);
  font-size: 0.95rem;
  max-width: 320px;
}

.auth-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 400px;
  margin: 8px auto;
  padding: 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 6px 18px rgba(90, 52, 38, 0.06);
}

.auth-card h2 {
  color: var(--brand);
  font-size: 1.6rem;
}

.auth-back {
  align-self: flex-start;
  border: none;
  background: none;
  color: var(--muted);
  padding: 4px 0;
}

.auth-intro {
  color: var(--muted);
}

.auth-notice {
  padding: 10px 12px;
  border-radius: 12px;
  background: #e3f3e8;
  color: var(--success);
  font-weight: 600;
}

.auth-label {
  margin-top: 8px;
  font-weight: 700;
}

.auth-input {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid var(--line);
  border-radius: 12px;
  font: inherit;
  font-size: 16px; /* 16px stops iPhone from zooming in on the box */
  background: #fffdf9;
}

.auth-input:focus {
  outline: none;
  border-color: var(--brand);
}

.auth-password {
  position: relative;
}

.auth-password .auth-input {
  padding-right: 70px;
}

.auth-show {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: none;
  color: var(--brand);
  font-weight: 700;
}

.auth-hint {
  font-size: 0.9rem;
  color: var(--muted);
}

.auth-consent {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-top: 8px;
  font-size: 0.95rem;
}

.auth-consent input {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  margin-top: 1px;
  accent-color: var(--brand);
}

.auth-error {
  min-height: 1.2em;
  color: var(--brand);
  font-weight: 600;
}

.auth-submit {
  width: 100%;
}

.auth-submit:disabled {
  opacity: 0.6;
}

.auth-link {
  border: none;
  background: none;
  color: var(--brand);
  font-weight: 700;
  text-decoration: underline;
  padding: 4px 0;
}

.auth-switch {
  color: var(--muted);
  text-align: center;
}

.auth-mail {
  font-size: 3rem;
  text-align: center;
}

/* ---------- Account panel ---------- */

.account-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 1.2rem;
  line-height: 1;
}

.account-panel {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(47, 37, 31, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.account-sheet {
  width: min(100%, 380px);
  background: var(--panel);
  border-radius: 20px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.account-sheet h2 {
  color: var(--brand);
}

.account-sheet p {
  color: var(--muted);
  word-break: break-all;
}

/* ---------- Who's learning? ---------- */

.who {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 16px 0;
  text-align: center;
}

.who-title {
  font-size: clamp(1.8rem, 7vw, 2.4rem);
  color: var(--brand);
}

.who-intro,
.who-loading {
  color: var(--muted);
  max-width: 360px;
}

/* Cards stay centered, even when there's only one. */
.who-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 16px;
  width: min(100%, 560px);
}

.who-grid .who-card {
  flex: 0 1 calc(50% - 8px);
  max-width: 170px;
}

@media (min-width: 600px) {
  .who-grid .who-card {
    flex-basis: calc(33.33% - 11px);
  }
}

.who-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px 8px;
  border: 2px solid var(--line);
  border-radius: 22px;
  background: var(--panel);
  box-shadow: 0 5px 0 var(--line);
}

.who-card:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 var(--line);
}

.who-face {
  width: min(100%, 120px);
  aspect-ratio: 1;
}

.avatar-svg {
  display: block;
  width: 100%;
  height: 100%;
}

.add-face {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 3px dashed var(--line);
  color: var(--muted);
  font-size: 3rem;
  font-weight: 700;
}

.who-name {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  overflow-wrap: anywhere;
}

.who-manage {
  margin-top: 6px;
  font-size: 0.95rem;
}

.animal-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.animal-pick {
  padding: 3px;
  border: 3px solid transparent;
  border-radius: 50%;
  background: none;
  aspect-ratio: 1;
}

.animal-pick.picked {
  border-color: var(--brand);
  transform: scale(1.06);
}

.kid-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.kid-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.kid-row-face {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
}

.kid-row-name {
  flex: 1;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.kid-row-btn {
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  font-weight: 700;
}

.kid-row-btn.remove {
  color: var(--brand);
}

.primary-btn.danger {
  background: var(--brand);
  box-shadow: 0 5px 0 #8a0000;
}

/* The current child's face in the header (tap to switch). */
.kid-chip {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: none;
  overflow: hidden;
}

@media (max-width: 480px) {
  .kid-chip {
    width: 38px;
    height: 38px;
  }
}

/* ---------- Grown-up check ---------- */

.gate-answer {
  min-height: 52px;
  border: 2px solid var(--line);
  border-radius: 12px;
  font-size: 2rem;
  font-weight: 700;
  text-align: center;
  line-height: 48px;
}

.gate-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.gate-pad button {
  padding: 12px 0;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fffdf9;
  font-size: 1.4rem;
  font-weight: 700;
}

.gate-pad .gate-ok {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}

/* Small phones: everything in the header still fits on one line. */
@media (max-width: 400px) {
  .topbar {
    padding: 8px 10px;
  }

  .master-logo {
    width: 30px;
    height: 30px;
  }

  .brand-block {
    gap: 6px;
  }

  .topbar h1 {
    font-size: 1rem;
  }

  .top-right {
    gap: 4px;
  }

  .mute-btn,
  .account-btn,
  .kid-chip {
    width: 34px;
    height: 34px;
    font-size: 0.95rem;
  }

  .star-count {
    padding: 4px 7px;
    font-size: 0.9rem;
  }
}

/* ---------- Choose what to learn ---------- */

.areas {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 12px 0;
  text-align: center;
}

.areas-title {
  font-size: clamp(1.5rem, 6vw, 2.1rem);
  color: var(--brand);
  overflow-wrap: anywhere;
}

.area-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  width: min(100%, 420px);
}

@media (min-width: 700px) {
  .area-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: min(100%, 680px);
  }
}

.area-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 16px 12px 14px;
  border: 3px solid var(--area);
  border-radius: 24px;
  background: var(--panel);
  box-shadow: 0 6px 0 var(--area);
}

.area-card:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--area);
}

.area-pic {
  height: 78px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.area-art {
  height: 70px;
  width: auto;
}

.area-glyphs {
  display: flex;
  height: 78px;
}

.area-glyphs .tile-svg {
  width: 56px;
  height: 78px;
}

.area-glyphs .tile-base {
  display: none;
}

.area-glyphs .tile-glyph path {
  stroke: var(--area);
}

.area-name {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--area);
}

.area-stars {
  font-weight: 700;
  color: var(--muted);
}

.soon-tag {
  position: absolute;
  top: -12px;
  right: 14px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--gold);
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 800;
}

/* Top of each path: back to the three choices. */
.path-top {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.path-back {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-weight: 700;
  color: var(--text);
}

.path-area {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--area);
}

.path-top + .unit-banner {
  margin-top: 4px;
}

.coming-soon {
  margin-top: 30px;
  padding: 20px;
  width: 100%;
  border: 3px dashed var(--line);
  border-radius: 22px;
  text-align: center;
  color: var(--muted);
}

.coming-soon h2 {
  margin-top: 8px;
  font-size: 1.3rem;
}

/* Tablets: bigger cards so the three choices fill the screen nicely. */
@media (min-width: 700px) {
  .areas {
    padding-top: 40px;
    gap: 28px;
  }

  .area-grid {
    width: min(100%, 860px);
    gap: 22px;
  }

  .area-card {
    padding: 34px 16px 26px;
    gap: 12px;
  }

  .area-pic,
  .area-glyphs {
    height: 120px;
  }

  .area-art {
    height: 104px;
  }

  .area-glyphs .tile-svg {
    width: 76px;
    height: 120px;
  }

  .area-name {
    font-size: 2rem;
  }

  .area-stars {
    font-size: 1.15rem;
  }
}

/* The choice screen can be wider than the path, and the art always fits its card. */
#areaScreen {
  max-width: 900px;
}

.area-pic {
  width: 100%;
}

.area-art {
  max-width: 100%;
}

.area-glyphs {
  max-width: 100%;
  justify-content: center;
}

.area-glyphs .tile-svg {
  flex: 0 1 auto;
  min-width: 0;
}

/* ---------- Toy-block cards (Letters, Numbers, Shapes) ---------- */

.area-card {
  background: var(--area);
  border: 3px solid #3a2a20;
  box-shadow: 0 7px 0 #3a2a20;
  color: #fff;
  overflow: hidden;
}

.area-card:active {
  box-shadow: 0 3px 0 #3a2a20;
}

.area-card .area-pic {
  height: auto;
}

.area-card .area-art.blocks {
  width: min(100%, 260px);
  height: auto;
}

.area-card .area-name {
  color: #fff;
  font-size: clamp(1.5rem, 7vw, 2rem);
  line-height: 1.1;
  max-width: 100%;
  overflow-wrap: anywhere;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
}

.area-card .area-stars {
  color: #fff;
  opacity: 0.95;
}

.area-card .soon-tag {
  position: static;
  margin-top: 2px;
  border: 2px solid #3a2a20;
}

/* Shapes' "Coming soon" card on the path keeps its outline style. */
.coming-soon .area-art.blocks {
  width: min(100%, 220px);
}

@media (min-width: 700px) {
  .area-card .area-name {
    font-size: 2rem;
  }

  .area-card .area-stars {
    font-size: 1.15rem;
  }
}

/* Shape lessons show a small drawing of the shape in their path bubble. */
.bubble-shape {
  width: 62%;
  height: 62%;
}

.step-glyph:not(:only-child) {
  white-space: nowrap;
}

/* ---------- Privacy policy ---------- */

.policy {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 8px 4px 24px;
  line-height: 1.55;
}

.policy h2 {
  color: var(--brand);
  font-size: 1.8rem;
}

.policy h3 {
  margin: 12px 0 0;
  font-size: 1.15rem;
}

.policy p,
.policy li {
  color: var(--text);
}

.policy ul {
  margin: 0;
  padding-left: 22px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.policy-date {
  color: var(--muted) !important;
  font-size: 0.9rem;
}

.policy a,
.auth-inline-link {
  color: var(--brand);
  font-weight: 700;
}

.delete-link {
  align-self: center;
  color: var(--muted);
  font-size: 0.9rem;
}

/* ---------- "Let's play!" background (welcome and sign-in screens only) ---------- */

body.playful {
  background: linear-gradient(#bfe7ff 0%, #e3f5ff 45%, #fff7ec 100%);
}

/* The sky: sun, clouds and balloons. */
.play-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

/* The playground hill along the bottom (above the balloons, so they float
   up from behind it). */
.play-scene {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: clamp(190px, 30vh, 320px);
  z-index: 0;
  pointer-events: none;
}

.play-scene-svg {
  display: block;
  width: 100%;
  height: 100%;
}

.play-scene .kid {
  pointer-events: auto;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.play-scene .kid-body.hopping {
  animation: kid-hop 0.6s ease-out;
}

@keyframes kid-hop {
  0% { transform: translateY(0); }
  35% { transform: translateY(-34px); }
  60% { transform: translateY(0); }
  78% { transform: translateY(-10px); }
  100% { transform: translateY(0); }
}

/* Page content sits above the playground. Empty space lets taps through
   to the balloons and kids; buttons, text and cards still work as usual. */
body.playful .screen,
body.playful .site-footer {
  position: relative;
  z-index: 1;
}

body.playful .screen,
body.playful .welcome,
body.playful .site-footer {
  pointer-events: none;
}

body.playful .welcome > *,
body.playful .auth-card,
body.playful .site-footer p {
  pointer-events: auto;
}

/* A soft card behind the welcome words so they're easy to read over the sky. */
body.playful .welcome {
  background: rgba(255, 251, 246, 0.86);
  border-radius: 28px;
  box-shadow: 0 8px 24px rgba(40, 90, 130, 0.12);
  padding: 24px 18px;
  margin-top: 4px;
}

body.playful .site-footer {
  background: rgba(255, 255, 255, 0.82);
  border-top: none;
  margin: 0 auto 8px;
  border-radius: 16px;
  padding: 8px 14px calc(8px + env(safe-area-inset-bottom));
  width: fit-content;
  max-width: calc(100% - 24px);
}

.play-sun {
  position: absolute;
  top: 72px;
  right: 14px;
  width: 96px;
  height: 96px;
}

.play-sun svg {
  width: 100%;
  height: 100%;
}

.play-rays {
  transform-origin: 50px 50px;
  animation: play-spin 40s linear infinite;
}

@keyframes play-spin {
  to { transform: rotate(360deg); }
}

.play-cloud {
  position: absolute;
  width: 120px;
  height: 38px;
  background: #ffffff;
  border-radius: 40px;
  opacity: 0.9;
  animation: play-drift linear infinite;
}

.play-cloud::before,
.play-cloud::after {
  content: "";
  position: absolute;
  background: #ffffff;
  border-radius: 50%;
}

.play-cloud::before {
  width: 54px;
  height: 54px;
  left: 18px;
  top: -26px;
}

.play-cloud::after {
  width: 40px;
  height: 40px;
  left: 58px;
  top: -16px;
}

.play-cloud.c1 { top: 18%; animation-duration: 70s; animation-delay: -20s; }
.play-cloud.c2 { top: 34%; animation-duration: 95s; animation-delay: -60s; scale: 0.75; }
.play-cloud.c3 { top: 9%; animation-duration: 120s; animation-delay: -95s; scale: 0.6; }

@keyframes play-drift {
  from { left: -160px; }
  to { left: 100%; }
}

.play-balloon {
  position: absolute;
  top: 100%;
  width: var(--size);
  height: calc(var(--size) * 1.6);
  pointer-events: auto;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  animation-name: play-rise, play-sway;
  animation-timing-function: linear, ease-in-out;
  animation-iteration-count: infinite, infinite;
  animation-direction: normal, alternate;
}

.play-balloon svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

@keyframes play-rise {
  from { top: 100%; }
  to { top: calc(-1.6 * var(--size) - 20px); }
}

@keyframes play-sway {
  from { transform: translateX(0) rotate(0deg); }
  to { transform: translateX(var(--sway)) rotate(var(--tilt)); }
}

.play-balloon.popping {
  animation-play-state: paused;
  pointer-events: none;
  transition: opacity 0.3s ease, scale 0.3s ease;
  opacity: 0;
  scale: 1.6;
}

.play-spark {
  position: fixed;
  z-index: 5;
  width: 9px;
  height: 9px;
  margin: -4.5px 0 0 -4.5px;
  border-radius: 50%;
  pointer-events: none;
  animation: play-spark 0.6s ease-out forwards;
}

@keyframes play-spark {
  from { transform: translate(0, 0) scale(1); opacity: 1; }
  to { transform: translate(var(--dx), var(--dy)) scale(0.3); opacity: 0; }
}

/* For people who turn off motion on their device: everything stays still
   (balloons and kids can still be tapped). */
@media (prefers-reduced-motion: reduce) {
  .play-balloon,
  .play-cloud,
  .play-rays {
    animation: none;
  }
}

/* Welcome, sign in and sign up fit on a phone screen without scrolling,
   even with Safari's top and bottom bars showing. */
@media (max-height: 820px) {
  body.playful #authScreen,
  body.playful #welcomeScreen {
    padding: 8px 14px 6px;
  }

  body.playful #authScreen .auth-card {
    gap: 5px;
    padding: 14px 18px;
    margin: 0 auto;
  }

  body.playful #authScreen .auth-card h2 {
    font-size: 1.4rem;
  }

  body.playful #authScreen .auth-back,
  body.playful #authScreen .auth-link {
    padding: 2px 0;
  }

  body.playful #authScreen .auth-label,
  body.playful #authScreen .auth-consent {
    margin-top: 4px;
  }

  body.playful #authScreen .auth-input {
    padding: 10px 12px;
  }

  body.playful #authScreen .auth-consent {
    font-size: 0.9rem;
  }

  body.playful #authScreen .auth-submit {
    padding: 12px 20px;
  }

  body.playful .site-footer {
    margin-bottom: 4px;
    padding: 5px 12px calc(5px + env(safe-area-inset-bottom));
    font-size: 0.8rem;
  }
}
