@font-face {
  font-family: 'Baloo 2';
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url('assets/fonts/baloo2-latin-var.woff2') format('woff2');
}

:root {
  --bg: #FFF6E9;
  --bg2: #FFE9CC;
  --ink: #2B1D16;
  --ink-soft: #5C4A3F;
  --coral: #FF8A65;
  --sun: #FFC93C;
  --mint: #6FD6B8;
  --sky: #7CC8F2;
  --lilac: #C3B1F0;
  --pink: #FFB3C1;
  --card: #FFFFFF;
  --shadow: 0 8px 0 rgba(43, 29, 22, .14);
  --radius: 32px;
  --font: 'Baloo 2', 'Nunito', ui-rounded, 'SF Pro Rounded', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --emoji: 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', 'Twemoji Mozilla', sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
body { overscroll-behavior: none; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 4px solid #1E6FD9; outline-offset: 3px; }

/* Toddler mode: no selection, no long-press menus, no scroll, no zoom gestures */
body.toddler {
  overflow: hidden;
  position: fixed; inset: 0;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}
body.toddler * { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
body.toddler img, body.toddler svg { -webkit-user-drag: none; pointer-events: none; }

#app { height: 100%; }
.screen {
  display: none;
  height: 100%;
  min-height: 100dvh;
  padding: calc(12px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
  flex-direction: column;
  background:
    radial-gradient(circle at 15% 10%, #FFE3B3 0 90px, transparent 91px),
    radial-gradient(circle at 92% 85%, #D9F3EA 0 120px, transparent 121px),
    var(--bg);
}
.screen.active { display: flex; }

/* top bar */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 64px; }
.star-pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--card); border-radius: 999px; padding: 6px 18px;
  font-size: 1.6rem; font-weight: 800; box-shadow: var(--shadow);
  font-variant-numeric: tabular-nums;
}
.star-pill span:first-child { font-family: var(--emoji); }
.star-pill.bump { animation: bump .5s ease; }
@keyframes bump { 40% { transform: scale(1.3); } }

.hold-btn {
  position: relative; width: 60px; height: 60px; border-radius: 50%;
  background: var(--card); box-shadow: var(--shadow);
  display: grid; place-items: center; font-size: 1.7rem; font-family: var(--emoji);
}
.hold-btn > span { position: relative; z-index: 1; }
.hold-ring { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.hold-ring circle { fill: none; stroke: #1E6FD9; stroke-width: 5; stroke-linecap: round; stroke-dasharray: 132; stroke-dashoffset: 132; }
.hold-btn.holding .hold-ring circle { transition: stroke-dashoffset var(--hold-ms, 3000ms) linear; stroke-dashoffset: 0; }
.parent-btn { opacity: .75; }
.hold-hint { text-align: center; font-size: 1rem; color: var(--ink-soft); min-height: 1.5em; margin: 4px 0 0; }

/* Buddy */
.buddy-slot { display: grid; place-items: center; }
.buddy-slot[data-size="big"] .buddy { width: min(44vw, 30vh, 230px); }
.buddy-slot[data-size="mid"] .buddy { width: min(36vw, 22vh, 180px); }
.buddy-slot[data-size="small"] .buddy { width: min(24vw, 13vh, 120px); }
.buddy { display: block; overflow: visible; }
.buddy .b-all { transform-origin: 100px 200px; animation: sway 4s ease-in-out infinite; }
.buddy .b-lid { transform-box: fill-box; transform-origin: center top; transform: scaleY(0); animation: blink 4.5s infinite; }
.buddy .b-happy { opacity: 0; }
.buddy .b-mouth { opacity: 0; transform-box: fill-box; transform-origin: center; }
.buddy .b-beak { transform-box: fill-box; transform-origin: center top; }
.buddy .b-wing-l { transform-origin: 40px 100px; }
.buddy .b-wing-r { transform-origin: 160px 100px; }
@keyframes sway { 0%,100% { transform: rotate(-2deg); } 50% { transform: rotate(2deg); } }
@keyframes blink { 0%, 92%, 100% { transform: scaleY(0); } 95% { transform: scaleY(1); } }

.talking .buddy .b-mouth { opacity: 1; animation: talk .32s ease-in-out infinite alternate; }
.talking .buddy .b-beak { animation: beak .32s ease-in-out infinite alternate; }
@keyframes talk { from { transform: scaleY(.4); } to { transform: scaleY(1.3); } }
@keyframes beak { from { transform: translateY(0); } to { transform: translateY(-6px) scaleY(.85); } }

.cheer .buddy .b-all { animation: hop .6s ease-in-out infinite; }
.cheer .buddy .b-eyes, .cheer .buddy .b-lids { opacity: 0; }
.cheer .buddy .b-happy { opacity: 1; }
.cheer .buddy .b-mouth { opacity: 1; }
.cheer .buddy .b-wing-l { animation: flapL .3s ease-in-out infinite alternate; }
.cheer .buddy .b-wing-r { animation: flapR .3s ease-in-out infinite alternate; }
@keyframes hop { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-14px); } }
@keyframes flapL { from { transform: rotate(10deg); } to { transform: rotate(45deg); } }
@keyframes flapR { from { transform: rotate(-10deg); } to { transform: rotate(-45deg); } }

.bubble {
  position: relative; background: var(--card); border-radius: 26px; padding: 10px 22px;
  font-size: clamp(1.4rem, 5.5vw, 2rem); font-weight: 700; box-shadow: var(--shadow);
  text-align: center; max-width: 90%;
}
.bubble:empty { visibility: hidden; }
.bubble::before {
  content: ''; position: absolute; top: -14px; left: 50%; margin-left: -14px;
  border: 14px solid transparent; border-top: 0; border-bottom-color: var(--card);
}

/* Home */
.home-hero { display: flex; flex-direction: column; align-items: center; gap: 10px; margin: 4px 0 18px; }
.buddy-wrap { border-radius: 50%; padding: 4px; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: minmax(150px, 1.1fr) minmax(140px, 1fr); gap: 16px; flex: 1; max-height: 560px; max-width: 720px; width: 100%; margin: 0 auto; }
.tile {
  border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 150px; padding: 12px; transition: transform .12s ease;
  border: 4px solid rgba(43,29,22,.08);
}
.tile:active { transform: translateY(4px) scale(.98); box-shadow: 0 3px 0 rgba(43,29,22,.14); }
.tile-emoji { font-family: var(--emoji); font-size: clamp(3.6rem, 16vw, 6rem); line-height: 1.1; }
.tile-label { font-size: clamp(1.5rem, 6vw, 2.2rem); font-weight: 800; line-height: 1.05; }
.tile-words { background: var(--sun); grid-column: 1 / -1; flex-direction: row; gap: 18px; }
.tiles.only-words { grid-template-rows: minmax(150px, 1fr); max-height: 380px; }
.tile-animals { background: var(--mint); }
.tile-phrases { background: var(--sky); }
.tile[hidden] { display: none; }

/* Card */
.dots { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; flex: 1; }
.dot { width: 18px; height: 18px; border-radius: 50%; background: #EAD9C3; transition: background .3s, transform .3s; }
.dot.done { background: var(--sun); }
.dot.now { background: var(--coral); transform: scale(1.25); }

.card-area { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; min-height: 0; }
.picture-card {
  position: relative; width: min(100%, 560px); flex: 1; max-height: 52vh; min-height: 240px;
  background: var(--card); border-radius: 40px; box-shadow: 0 10px 0 rgba(43,29,22,.14);
  border: 6px solid var(--bg2);
  display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 10px;
  transition: transform .15s ease;
}
.picture-card:active { transform: scale(.97); }
.picture-card.pop { animation: cardIn .45s cubic-bezier(.2,1.4,.4,1); }
@keyframes cardIn { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.picture { font-family: var(--emoji); font-size: clamp(7rem, 34vw, 15rem); line-height: 1.05; }
.picture.two { font-size: clamp(5.5rem, 26vw, 11rem); letter-spacing: -.05em; }
.picture.big { font-size: clamp(8.5rem, 42vw, 18rem); }
.picture.letter {
  font-family: var(--font); font-weight: 800; width: 1.3em; height: 1.3em; border-radius: 50%;
  display: grid; place-items: center; background: var(--lilac); font-size: clamp(5rem, 24vw, 10rem);
}
.picture-card.speaking .picture { animation: wiggle .5s ease-in-out infinite alternate; }
@keyframes wiggle { from { transform: rotate(-4deg) scale(1); } to { transform: rotate(4deg) scale(1.05); } }
.word { font-size: clamp(2.6rem, 12vw, 4.6rem); font-weight: 800; line-height: 1; letter-spacing: .02em; }
.parts { font-size: clamp(1.4rem, 6vw, 2.2rem); font-weight: 700; color: var(--ink-soft); min-height: 1.2em; }
.tap-hint { position: absolute; right: 18px; top: 12px; font-size: 1.8rem; font-family: var(--emoji); opacity: .55; }

.card-buddy { display: flex; align-items: center; gap: 6px; width: min(100%, 560px); min-height: 70px; }
.bubble-small { font-size: clamp(1.2rem, 5vw, 1.7rem); padding: 8px 18px; flex: 1; text-align: left; }
.bubble-small::before { top: 50%; left: -12px; margin: -12px 0 0; border: 12px solid transparent; border-left: 0; border-right-color: var(--card); }

.actions { display: flex; align-items: center; justify-content: center; gap: 14px; padding-top: 10px; min-height: 140px; }
.mic-btn {
  position: relative; width: 132px; height: 132px; border-radius: 50%;
  background: var(--coral); box-shadow: 0 10px 0 #D9603D;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  transition: transform .12s;
}
.mic-btn:active { transform: translateY(5px); box-shadow: 0 5px 0 #D9603D; }
.mic-icon { font-family: var(--emoji); font-size: 3.4rem; line-height: 1; position: relative; z-index: 1; }
.mic-label { font-size: 1.15rem; font-weight: 800; position: relative; z-index: 1; }
.mic-ring { position: absolute; inset: -10px; border-radius: 50%; border: 6px solid var(--coral); opacity: 0; }
.mic-btn.ready .mic-ring { animation: ripple 1.4s ease-out infinite; }
.mic-btn.listening { background: #FF6F61; }
.mic-btn.listening .mic-ring { animation: ripple .8s ease-out infinite; border-color: #E63946; }
@keyframes ripple { from { transform: scale(.9); opacity: .9; } to { transform: scale(1.35); opacity: 0; } }
.mic-btn[hidden], .said-btn[hidden] { display: none; }

.said-btn {
  min-width: 132px; height: 132px; border-radius: 36px; padding: 0 18px;
  background: var(--mint); box-shadow: 0 10px 0 #3FAE90;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-family: var(--font);
}
.said-btn > span:first-child { font-family: var(--emoji); font-size: 3.2rem; line-height: 1; }
.said-label { font-size: 1.25rem; font-weight: 800; }
.said-btn:active { transform: translateY(5px); box-shadow: 0 5px 0 #3FAE90; }
.actions.said-only .said-btn { min-width: 220px; height: 150px; }
.actions.said-only .said-btn > span:first-child { font-size: 4rem; }
.actions.said-only .said-label { font-size: 1.7rem; }
.actions.secondary-said .said-btn { min-width: 96px; height: 96px; border-radius: 28px; }
.actions.secondary-said .said-btn > span:first-child { font-size: 2.2rem; }
.actions.secondary-said .said-label { font-size: .95rem; }
.next-btn {
  width: 76px; height: 76px; border-radius: 50%; background: var(--card); box-shadow: var(--shadow);
  font-family: var(--emoji); font-size: 2.2rem;
}
.actions.waiting .mic-btn, .actions.waiting .said-btn { opacity: .45; }
.mic-note { text-align: center; color: var(--ink-soft); font-size: 1rem; margin: 6px 0 0; min-height: 1.3em; }

/* Done */
#screen-done { justify-content: center; }
.done-wrap { display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
.high-five {
  width: 190px; height: 190px; border-radius: 50%; background: var(--sun); box-shadow: 0 12px 0 #E0A800;
  font-family: var(--emoji); font-size: 6.5rem; animation: hi5 1.2s ease-in-out infinite;
}
.high-five:active { transform: scale(.92); }
@keyframes hi5 { 0%,100% { transform: rotate(-8deg); } 50% { transform: rotate(8deg) scale(1.05); } }
.done-title { font-size: clamp(2.4rem, 11vw, 4rem); line-height: 1.05; margin: 6px 0; font-weight: 800; }
.done-stars { font-family: var(--emoji); font-size: 2.4rem; letter-spacing: 4px; max-width: 90vw; }
.done-stars span { display: inline-block; animation: starIn .5s cubic-bezier(.2,1.6,.4,1) both; }
@keyframes starIn { from { transform: scale(0) rotate(-90deg); } to { transform: scale(1) rotate(0); } }
.done-actions { display: flex; gap: 16px; margin-top: 6px; }
.big-btn {
  min-width: 150px; min-height: 84px; border-radius: 28px; font-size: 1.8rem; font-weight: 800;
  box-shadow: var(--shadow); padding: 0 22px;
}
.big-btn span { font-family: var(--emoji); }
.big-btn.again { background: var(--sky); }
.big-btn.home { background: var(--card); }

/* Celebration */
.celebrate {
  position: fixed; inset: 0; z-index: 50; display: none;
  background: rgba(255, 246, 233, .94);
  align-items: center; justify-content: center;
}
.celebrate.show { display: flex; animation: fadeIn .2s ease; }
@keyframes fadeIn { from { opacity: 0; } }
.fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 55; }
.cel-inner { position: relative; display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; padding: 20px; }
.cel-star { font-family: var(--emoji); font-size: clamp(7rem, 35vw, 12rem); line-height: 1; animation: starBig .7s cubic-bezier(.2,1.6,.4,1) both; }
@keyframes starBig { from { transform: scale(0) rotate(-120deg); } to { transform: scale(1) rotate(0); } }
.cel-text { font-size: clamp(2.2rem, 10vw, 3.6rem); font-weight: 800; line-height: 1.05; max-width: 92vw; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translateX(-50%) translateY(150%);
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 16px; font-size: 1.05rem; z-index: 60;
  transition: transform .25s ease, opacity .25s ease; max-width: 92vw; text-align: center;
  opacity: 0; pointer-events: none;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* Parent corner: normal, scrollable, selectable */
.screen.parent { padding: 0; background: #FBF4EA; }
.parent-scroll {
  height: 100%; width: 100%; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding: calc(14px + var(--safe-top)) 16px calc(28px + var(--safe-bottom));
  font-size: 1.08rem; line-height: 1.45;
}
.parent-scroll > * { max-width: 720px; margin-left: auto; margin-right: auto; }
.parent-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; position: sticky; top: calc(-14px - var(--safe-top)); background: #FBF4EA; padding: 8px 0; z-index: 2; }
.parent-head h1 { margin: 0; font-size: 1.9rem; }
.pcard { background: #fff; border-radius: 20px; padding: 16px 18px; margin-bottom: 14px; box-shadow: 0 2px 0 rgba(43,29,22,.08); border: 1px solid #EFE3D3; }
.pcard h2 { margin: 0 0 6px; font-size: 1.35rem; }
.pcard p { margin: 6px 0; }
.pcard.note { border: 3px solid var(--sun); }
.muted { color: var(--ink-soft); }
.small { font-size: .95rem; color: var(--ink-soft); }
.tips { margin: 6px 0; padding-left: 1.2em; }
.field { display: block; margin: 12px 0; }
.field > span { display: block; font-weight: 700; margin-bottom: 4px; }
.field input:not([type]), .field input[type="text"], .field select {
  width: 100%; font: inherit; font-size: 1.1rem; padding: 12px 14px; border-radius: 14px; border: 2px solid #D9C7B2; background: #FFFDF9; color: var(--ink);
}
input[type="range"] { width: 100%; height: 36px; accent-color: #E2683F; }
.switch { display: flex; align-items: flex-start; gap: 12px; margin: 12px 0; font-weight: 600; }
.switch input { width: 28px; height: 28px; flex: none; accent-color: #2E9C7E; margin-top: 2px; }
.pbtn {
  font-weight: 700; font-size: 1.05rem; padding: 12px 18px; border-radius: 14px; min-height: 48px;
  background: #F1E6D8; color: var(--ink); border: 2px solid #E2D2BF;
}
.pbtn.primary { background: var(--sun); border-color: #E7B21F; }
.pbtn.danger { background: #FFE4E1; border-color: #F3B6AE; color: #8A1C12; }
.pbtn.mini { padding: 6px 12px; min-height: 40px; font-size: .95rem; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.emoji-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)); gap: 6px; max-height: 220px; overflow-y: auto; padding: 4px; border: 2px solid #EFE3D3; border-radius: 14px; }
.emoji-picker button { font-family: var(--emoji); font-size: 1.8rem; height: 50px; border-radius: 12px; background: #FFF9F1; }
.emoji-picker button[aria-checked="true"] { background: var(--sun); outline: 3px solid #E2683F; }
.custom-list, .rec-list { list-style: none; padding: 0; margin: 10px 0 0; }
.custom-list li, .rec-list li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid #F0E6D9; }
.custom-list .ce { font-family: var(--emoji); font-size: 1.8rem; width: 44px; text-align: center; }
.custom-list .cw, .rec-list .rw { flex: 1; min-width: 0; }
.custom-list .cw small, .rec-list .rw small { display: block; color: var(--ink-soft); }
.set-toggles .switch { margin: 8px 0; }
.set-toggles small { display: block; font-weight: 500; color: var(--ink-soft); }
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 6px 0 10px; }
.stat { background: #FFF6E9; border-radius: 14px; padding: 8px; text-align: center; }
.stat b { display: block; font-size: 1.6rem; line-height: 1.1; }
.table-wrap { overflow-x: auto; max-height: 320px; overflow-y: auto; border: 1px solid #F0E6D9; border-radius: 12px; }
table.log { width: 100%; border-collapse: collapse; font-size: .95rem; }
table.log th, table.log td { text-align: left; padding: 6px 8px; border-bottom: 1px solid #F3EADF; vertical-align: top; }
table.log th { position: sticky; top: 0; background: #FFF6E9; }
table.log td.words { min-width: 110px; }
table.log th:last-child, table.log td:last-child { white-space: nowrap; }
.foot { text-align: center; color: var(--ink-soft); font-size: .9rem; }

@media (orientation: landscape) and (min-width: 700px) {
  #screen-card .card-area { flex-direction: row; }
  .card-buddy { flex-direction: column; width: auto; max-width: 260px; }
  .bubble-small { text-align: center; }
  .bubble-small::before { display: none; }
  .tiles { grid-template-columns: repeat(3, 1fr); grid-template-rows: 1fr; }
  .tile-words { grid-column: auto; flex-direction: column; }
  .home-hero { flex-direction: row; justify-content: center; }
}
@media (max-height: 640px) {
  .tile { min-height: 100px; }
  .tiles { grid-template-rows: minmax(100px, 1fr) minmax(100px, 1fr); }
  .actions { min-height: 110px; }
  .mic-btn { width: 110px; height: 110px; }
  .said-btn { height: 110px; min-width: 110px; }
}
@media (prefers-contrast: more) {
  .tile, .picture-card, .mic-btn, .said-btn, .big-btn, .hold-btn, .star-pill { border: 4px solid var(--ink); }
  .muted, .small { color: var(--ink); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
  .buddy .b-lid { transform: scaleY(0) !important; }
  .hold-btn.holding .hold-ring circle { transition-duration: var(--hold-ms, 3000ms) !important; }
}
