/* ===================== Little Hands – styles ===================== */
:root {
  --bg: #fff7ec;
  --ink: #3b2f5c;
  --muted: #7a6f96;
  --card: #ffffff;
  --sky: #7cc6fe; --mango: #ffb547; --berry: #ff7aa8;
  --mint: #6fdcb4; --lilac: #b9a3ff; --sun: #ffd84d; --pink: #ff9fc4; --orange: #ff9b5e;
  --guide: #b8cdf0;
  --start: #2ec27e; --end: #ff5d73;
  --child-ink: #7b3fe4;
  --radius: 28px;
  --shadow: 0 10px 0 rgba(59,47,92,.08), 0 18px 40px rgba(59,47,92,.10);
  --font: 'Baloo 2', 'Fredoka', 'Comic Sans MS', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { overflow-x: hidden; }
button { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
body { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; font-family: var(--font); color: var(--ink);
  background: radial-gradient(circle at 10% 10%, #ffe9f2 0, transparent 35%),
              radial-gradient(circle at 90% 20%, #e3f4ff 0, transparent 35%),
              radial-gradient(circle at 50% 100%, #e8fff4 0, transparent 40%), var(--bg);
}
:focus-visible { outline: 4px solid #5b3fd1; outline-offset: 3px; border-radius: 16px; }

.bg-blobs span { position: fixed; border-radius: 50%; opacity: .35; z-index: -1; animation: drift 14s ease-in-out infinite; }
.bg-blobs span:nth-child(1){ width:120px;height:120px;background:var(--sun);top:8%;left:4%; }
.bg-blobs span:nth-child(2){ width:80px;height:80px;background:var(--mint);top:60%;left:90%;animation-delay:-4s; }
.bg-blobs span:nth-child(3){ width:60px;height:60px;background:var(--pink);top:85%;left:10%;animation-delay:-8s; }
.bg-blobs span:nth-child(4){ width:100px;height:100px;background:var(--lilac);top:15%;left:85%;animation-delay:-2s; }
@keyframes drift { 50% { transform: translate(20px,-25px) scale(1.1); } }

.screen { display: none; }
.screen.active { display: block; animation: pop-in .45s ease; }
@keyframes pop-in { from { opacity: 0; transform: translateY(16px) scale(.98); } }

/* ---------- Home ---------- */
.logo-hand { font-size: 4rem; display: inline-block; animation: wave 2.4s ease-in-out infinite; transform-origin: 70% 80%; }
@keyframes wave { 0%,60%,100% { transform: rotate(0); } 15%,45% { transform: rotate(14deg); } 30% { transform: rotate(-8deg); } }
.app-title { font-weight: 800; font-size: clamp(2.8rem, 9vw, 5rem); line-height: 1; margin: 0; letter-spacing: -1px; }
.app-title span { color: #ff6f91; }
.app-subtitle { font-size: clamp(1.2rem, 4vw, 1.8rem); color: var(--muted); font-weight: 600; }

.lang-card {
  width: 100%; border: 0; border-radius: var(--radius); padding: 2rem 1.5rem; text-align: center;
  color: var(--ink); box-shadow: var(--shadow); transition: transform .2s, box-shadow .2s; position: relative; overflow: hidden;
}
@media (hover: hover) { .lang-card:hover { transform: translateY(-6px) rotate(-1deg); } }
.lang-card:active { transform: scale(.96); }
.lang-card .glyph { font-size: 5rem; font-weight: 800; line-height: 1.2; display: block; }
.lang-card .native { font-size: 1.9rem; font-weight: 800; display: block; }
.lang-card .name { font-size: 1.1rem; opacity: .8; }
.lang-card .stars-mini { margin-top: .5rem; font-weight: 700; }
.lang-card::after { content: ""; position: absolute; width: 160px; height: 160px; border-radius: 50%; background: rgba(255,255,255,.35); right: -50px; top: -50px; }
.theme-sky { background: linear-gradient(160deg, #d8efff, #a9dbff); }
.theme-mango { background: linear-gradient(160deg, #fff0cc, #ffd18a); }
.theme-berry { background: linear-gradient(160deg, #ffe0ec, #ffb3cf); }

/* ---------- Learning header ---------- */
.learn-header { display: grid; grid-template-columns: auto minmax(0,1fr) auto auto; gap: .75rem; align-items: center;
  background: var(--card); border-radius: 999px; padding: .5rem .75rem; box-shadow: var(--shadow); }
.header-info { min-width: 0; display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.lang-badge { background: #efe8ff; padding: .2rem .8rem; border-radius: 999px; font-weight: 700; }
.lesson-label { font-weight: 700; color: var(--muted); }
.progress-wrap { grid-column: 1 / -1; order: 5; }
.kid-progress { height: 14px; border-radius: 999px; background: #f1ecfb; }
.kid-progress .progress-bar { background: linear-gradient(90deg, var(--mint), var(--sky)); border-radius: 999px; transition: width .5s; }
.star-counter { font-weight: 800; font-size: 1.3rem; background: #fff6cf; padding: .2rem .9rem; border-radius: 999px; }
.star-counter.bump { animation: bump .6s; }
@keyframes bump { 40% { transform: scale(1.35); } }
@media (min-width: 768px) {
  .learn-header { grid-template-columns: auto auto minmax(0,1fr) auto auto; }
  .progress-wrap { grid-column: auto; order: 0; }
}

.btn-round { width: 56px; height: 56px; border-radius: 50%; border: 0; background: #ffe2ec; font-size: 1.6rem; transition: transform .15s; }
.btn-round:active { transform: scale(.9); }

/* ---------- Cards ---------- */
.card-kid { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; }
.info-card { display: flex; flex-direction: column; align-items: center; text-align: center; justify-content: center; gap: .25rem; }
.big-letter { font-size: clamp(4rem, 14vw, 7.5rem); font-weight: 800; line-height: 1.1; color: #ff6f91; text-shadow: 0 6px 0 #ffe0ea; }
.word-image { font-size: clamp(3rem, 10vw, 5rem); }
.float { animation: float 3s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-10px) rotate(3deg); } }
.word-text { font-size: clamp(1.6rem, 5vw, 2.2rem); font-weight: 800; }
.word-text .first { color: #ff6f91; }
.word-meaning { color: var(--muted); font-weight: 600; min-height: 1.5em; }
.mascot-row { display: flex; align-items: center; gap: .5rem; margin-top: .75rem; }
.mascot { font-size: 2.6rem; animation: bob 2.5s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-5px) rotate(-5deg); } }
.bubble { background: #f1ecff; border-radius: 20px 20px 20px 4px; padding: .5rem .9rem; font-weight: 700; min-height: 2.6rem; display: flex; align-items: center; transition: transform .3s; }
.bubble.say { animation: bump .5s; }

.trace-card { display: flex; flex-direction: column; align-items: center; }
.instructions { font-weight: 700; font-size: 1.15rem; margin-bottom: .6rem; text-align: center; }
.trace-wrap { position: relative; width: 100%; max-width: min(600px, 66vh); max-width: min(600px, 64dvh); aspect-ratio: 1 / 1; }
#trace-svg {
  width: 100%; height: 100%; display: block; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  background: #fbfdff; border-radius: 24px; border: 4px dashed #d9e6fa; cursor: crosshair;
}
.grid-line { stroke: #e7eefb; stroke-width: .4; }
.grid-mid { stroke: #f6c9d6; stroke-width: .4; stroke-dasharray: 2 2; }
.guide-path { fill: none; stroke: var(--guide); stroke-width: 6.5; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: .1 4; }
.guide-path.done { stroke: #c6f0dc; }
.guide-bg { fill: none; stroke: #eef4fd; stroke-width: 9; stroke-linecap: round; stroke-linejoin: round; }
.ref-glyph { fill: #e3ebf8; font-weight: 700; }
.start-dot { fill: var(--start); stroke: #fff; stroke-width: .8; transform-box: fill-box; transform-origin: center; animation: pulse 1.6s ease-in-out infinite; }
.end-dot { fill: var(--end); stroke: #fff; stroke-width: .6; }
.stroke-num { font-size: 3.6px; font-weight: 800; fill: #fff; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
@keyframes pulse { 50% { transform: scale(1.35); } }
.dir-arrow { fill: none; stroke: #8fa8d8; stroke-width: 1.2; stroke-linecap: round; stroke-dasharray: 3 3; animation: march 1s linear infinite; }
.arrow-head { fill: #8fa8d8; }
@keyframes march { to { stroke-dashoffset: -6; } }
.replay-path { fill: none; stroke: #ffb547; stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; opacity: .85; }
.ink { fill: none; stroke: var(--child-ink); stroke-width: 4.5; stroke-linecap: round; stroke-linejoin: round; }
.hand { font-size: 12px; pointer-events: none; transition: opacity .3s; }
.hide-directions #layer-directions, .hide-directions .stroke-num, .hide-directions .end-dot { display: none; }

.placeholder-note { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); background: #fff3d6; color: #7a5200;
  border-radius: 999px; padding: .25rem .9rem; font-size: .85rem; font-weight: 700; white-space: nowrap; max-width: 95%; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Controls ---------- */
.controls { display: grid; grid-template-columns: repeat(3, 1fr); gap: .75rem; margin: 1rem 0 2rem; }
@media (min-width: 768px) { .controls { grid-template-columns: repeat(6, 1fr); } }
.btn-kid { border: 0; border-radius: 22px; min-height: 76px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-family: var(--font); font-weight: 800; color: var(--ink); box-shadow: 0 6px 0 rgba(0,0,0,.12); transition: transform .12s, box-shadow .12s; }
.btn-kid span { font-size: 1.8rem; line-height: 1; }
.btn-kid small { font-size: 1rem; }
@media (hover: hover) { .btn-kid:hover { transform: translateY(-2px); } }
.btn-kid:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0,0,0,.12); }
.btn-kid:disabled { opacity: .45; }
.btn-kid[aria-pressed="false"] { filter: grayscale(.8); opacity: .7; }
.btn-kid.wide { min-width: 130px; padding: 0 1rem; }
.c-lilac { background: var(--lilac); } .c-pink { background: var(--pink); } .c-sky { background: var(--sky); }
.c-mint { background: var(--mint); } .c-sun { background: var(--sun); } .c-orange { background: var(--orange); }

/* ---------- Hints ---------- */
.start-dot.nudge { animation: nudge .7s ease-in-out 4; }
@keyframes nudge { 50% { transform: scale(1.9); } }
.bubble.hint { background: #fff3c4; }

/* ---------- Phones & tablets ---------- */
@media (max-width: 767.98px) {
  #learn-screen { padding-left: .6rem; padding-right: .6rem; padding-bottom: calc(88px + env(safe-area-inset-bottom)); }
  .learn-header { border-radius: 24px; padding: .4rem .6rem; gap: .5rem; }
  .btn-round { width: 48px; height: 48px; font-size: 1.4rem; }
  .star-counter { font-size: 1.1rem; }
  .lesson-label { font-size: .9rem; }
  .info-card { display: grid; grid-template-columns: auto auto minmax(0,1fr); align-items: center; text-align: left; gap: .1rem .75rem; padding: .6rem .9rem; }
  .big-letter { font-size: 3.4rem; grid-row: span 2; }
  .word-image { font-size: 2.6rem; grid-row: span 2; }
  .word-text { font-size: 1.4rem; line-height: 1.1; }
  .word-meaning { font-size: .9rem; min-height: 0; }
  .mascot-row { grid-column: 1 / -1; margin-top: .25rem; }
  .mascot { font-size: 2rem; }
  .bubble { min-height: 2.2rem; font-size: .95rem; }
  .trace-card { padding: .6rem; }
  .instructions { font-size: 1rem; margin-bottom: .4rem; }
  .trace-wrap { max-width: min(100%, 58dvh); }
  .controls { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; margin: 0; gap: .35rem;
    grid-template-columns: repeat(7, minmax(0,1fr)); padding: .5rem .5rem calc(.5rem + env(safe-area-inset-bottom));
    background: rgba(255,247,236,.94); box-shadow: 0 -6px 20px rgba(59,47,92,.10); }
  .btn-kid { min-height: 62px; border-radius: 16px; box-shadow: 0 4px 0 rgba(0,0,0,.12); padding: 0; }
  .btn-kid span { font-size: 1.4rem; }
  .btn-kid small { font-size: .72rem; }
  .celebrate-card { padding: 1.4rem; }
}
@media (min-width: 768px) { .controls { grid-template-columns: repeat(7, 1fr); } }
/* Landscape phones: letter card beside the board, small header */
@media (max-height: 500px) and (orientation: landscape) {
  .trace-wrap { max-width: min(100%, 72dvh); }
  .big-letter { font-size: 3rem; } .word-image { font-size: 2.4rem; }
}

/* ---------- Celebration ---------- */
.celebrate { position: fixed; inset: 0; background: rgba(59,47,92,.35); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 1rem; }
.celebrate[hidden] { display: none; }
.celebrate-card { background: #fff; border-radius: 32px; padding: 2rem; text-align: center; max-width: 420px; width: 100%; box-shadow: var(--shadow); animation: pop .5s cubic-bezier(.2,1.6,.4,1); position: relative; z-index: 2; }
.celebrate-card h2 { font-weight: 800; font-size: 2.2rem; }
.celebrate-card p { color: var(--muted); font-weight: 600; font-size: 1.2rem; }
.celebrate-stars { font-size: 3.5rem; animation: spin-in 1s ease; }
@keyframes pop { from { transform: scale(.5); opacity: 0; } }
@keyframes spin-in { from { transform: rotate(-180deg) scale(0); } }
.confetti { position: fixed; top: -40px; font-size: 1.6rem; animation: fall linear forwards; z-index: 1; pointer-events: none; }
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); } }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

.category-title { text-align: center; font-weight: 800; font-size: 1.8rem; color: #4a3b6b; margin: 1rem 0 0; }
.word-image { overflow-wrap: anywhere; }
.word-image.many { font-size: clamp(1.4rem, 3.5vw, 2rem) !important; letter-spacing: .1em; line-height: 1.4; }

/* ---------------- Sound settings ---------------- */
.home-settings { position: absolute; top: 1rem; right: 1rem; }
#home-screen { position: relative; }
.settings-card { width: min(440px, 92vw); max-width: none; text-align: left; }
.settings-card h2 { text-align: center; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .55rem 0; font-weight: 700; font-size: 1.15rem; border-bottom: 2px dashed #f1e6ff; cursor: pointer; }
.set-row input[type=checkbox] { appearance: none; width: 58px; height: 32px; border-radius: 99px; background: #ddd; position: relative; transition: background .2s; flex: none; cursor: pointer; }
.set-row input[type=checkbox]::after { content: ""; position: absolute; top: 4px; left: 4px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgba(0,0,0,.2); transition: left .2s; }
.set-row input[type=checkbox]:checked { background: #4cc38a; }
.set-row input[type=checkbox]:checked::after { left: 30px; }
.set-row input[type=range] { width: 50%; accent-color: #ff8a3d; height: 32px; }
.set-row input:disabled { opacity: .4; }
.settings-card .btn-kid { width: 100%; }
