/* =====================================================================
   KHANZA E-Learning - tampilan ramah anak
   Target sentuh besar, teks besar, warna cerah, mode gelap tetap nyaman.
   ===================================================================== */

:root {
    --kid-font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
    --emoji-font: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
    --c: #2563eb;
    --good: #16a34a;
    --bad: #dc2626;
    --hl: #fde047;
    --hl-text: #1c1917;
}

/* Warna per mata pelajaran (aman di mode terang & gelap lewat color-mix) */
.c-merah  { --c: #e5484d; }
.c-oranye { --c: #f97316; }
.c-kuning { --c: #d4a106; }
.c-hijau  { --c: #16a34a; }
.c-toska  { --c: #0d9488; }
.c-biru   { --c: #2563eb; }
.c-ungu   { --c: #7c3aed; }
.c-pink   { --c: #db2777; }
.c-coklat { --c: #9a5b2e; }

[class*="c-"] {
    --c-soft: color-mix(in srgb, var(--c) 14%, var(--surface));
    --c-line: color-mix(in srgb, var(--c) 35%, var(--border));
}

[hidden] { display: none !important; }

.emoji { font-family: var(--emoji-font); font-style: normal; line-height: 1; }

/* ---------- Pemberitahuan suara ---------- */
.voice-notice {
    background: #fff7d6; color: #6b4e00; border-bottom: 1px solid #f1dc8c;
    padding: 10px 16px; text-align: center; font-weight: 600;
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .voice-notice { background: #3a300c; color: #f8df8a; border-color: #5c4b12; }
}
:root[data-theme="dark"] .voice-notice { background: #3a300c; color: #f8df8a; border-color: #5c4b12; }

/* ---------- Tombol speaker ---------- */
.speak-btn, .speak-main {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    flex-shrink: 0; cursor: pointer;
    border: 2px solid var(--c-line, var(--border)); border-radius: 999px;
    background: var(--surface); color: var(--c, var(--primary));
    font: inherit; font-weight: 700;
    transition: transform .1s, background .15s;
}
.speak-btn { width: 52px; height: 52px; }
.speak-btn svg, .speak-main svg { width: 28px; height: 28px; }
.speak-btn:hover, .speak-main:hover { background: var(--c-soft, var(--surface-alt)); }
.speak-btn:active, .speak-main:active { transform: scale(.94); }
.speak-btn-sm { width: 46px; height: 46px; }
.speak-btn-sm svg { width: 24px; height: 24px; }
.speak-btn-lg { width: auto; height: 60px; padding: 0 22px 0 18px; font-size: 1.15rem; }
.speak-btn-lg:not(:has(span)) { width: 60px; padding: 0; }
.speak-btn-lg svg { width: 32px; height: 32px; }

.is-speaking { background: var(--c, var(--primary)) !important; color: #fff !important; border-color: transparent !important; }
.is-speaking .wave { animation: wave 1s ease-in-out infinite; }
.is-speaking .wave-2 { animation-delay: .25s; }
@keyframes wave { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }

/* ---------- Tombol anak ---------- */
.btn-kid {
    display: inline-flex; align-items: center; justify-content: center; gap: 10px;
    min-height: 60px; padding: 0 28px; border-radius: 999px;
    font: inherit; font-size: 1.2rem; font-weight: 800; text-decoration: none; cursor: pointer;
    border: 3px solid transparent; transition: transform .1s, filter .15s, background .15s;
}
.btn-kid:active { transform: scale(.96); }
.btn-kid-primary { background: var(--c, var(--primary)); color: #fff; box-shadow: 0 5px 0 color-mix(in srgb, var(--c, var(--primary)) 60%, #000); }
.btn-kid-primary:hover { filter: brightness(1.07); }
.btn-kid-primary:disabled { filter: grayscale(.7) opacity(.5); cursor: not-allowed; box-shadow: none; }
.btn-kid-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-kid-ghost:hover { background: var(--surface-alt); }
.btn-kid-xl { min-height: 76px; padding: 0 44px; font-size: 1.6rem; }

.kid-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; margin-top: 24px; }
.kid-actions.center { justify-content: center; }

/* ---------- Beranda ---------- */
.kid-hero {
    --c: #f97316;
    padding: 64px 0 56px;
    background:
        radial-gradient(circle at 12% 20%, color-mix(in srgb, #fde047 35%, transparent) 0 120px, transparent 121px),
        radial-gradient(circle at 92% 80%, color-mix(in srgb, #60a5fa 30%, transparent) 0 160px, transparent 161px),
        linear-gradient(180deg, color-mix(in srgb, #f97316 12%, var(--bg)), var(--bg));
}
.kid-hero-inner { display: flex; align-items: center; gap: 36px; }
.mascot { font-size: clamp(6rem, 18vw, 10rem); animation: bob 3s ease-in-out infinite; }
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-10px) rotate(3deg); } }

.kid-title { font-family: var(--kid-font); font-size: clamp(2rem, 6vw, 3.2rem); font-weight: 900; letter-spacing: -.01em; margin: 0; }
.kid-lead { font-size: 1.25rem; color: var(--muted); margin: 12px 0 0; }

.section-head { display: flex; align-items: center; gap: 14px; margin-bottom: 1.2em; }
.section-head .section-title { margin: 0; }
.section-tight { padding-top: 24px; }

.steps-row { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.step-card {
    position: relative; display: flex; flex-direction: column; align-items: center; gap: 10px;
    background: var(--surface); border: 2px solid var(--border); border-radius: 20px; padding: 28px 16px 22px;
}
.step-num {
    position: absolute; top: -14px; left: 50%; transform: translateX(-50%);
    width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center;
    background: var(--primary); color: var(--on-primary); font-weight: 800;
}
.step-icon { font-size: 3rem; }
.step-title { font-weight: 800; font-size: 1.15rem; }

.parent-note h2 { font-size: 1.3rem; }
.parent-note p:last-child { margin-bottom: 0; }

/* ---------- Kepala halaman belajar ---------- */
.kid-head { padding: 40px 0 8px; background: linear-gradient(180deg, var(--c-soft, var(--surface-alt)), var(--bg)); }
.kid-head-row { display: flex; align-items: center; flex-wrap: wrap; gap: 16px; }
.kid-head-icon { font-size: 3.4rem; }
.back-link {
    display: inline-flex; align-items: center; gap: 8px; margin-bottom: 14px;
    padding: 8px 16px; border-radius: 999px; background: var(--surface); border: 2px solid var(--border);
    color: var(--text); text-decoration: none; font-weight: 700;
}
.back-link:hover { background: var(--surface-alt); }

/* ---------- Kartu (tile) pelajaran & materi ---------- */
.tile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 20px; }
.tile {
    position: relative; border-radius: 24px; background: var(--c-soft);
    border: 3px solid var(--c-line); transition: transform .15s, box-shadow .15s;
}
.tile:hover { transform: translateY(-4px); box-shadow: 0 10px 24px color-mix(in srgb, var(--c) 22%, transparent); }
.tile-link {
    display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px;
    padding: 30px 18px 24px; color: var(--text); text-decoration: none; border-radius: 21px; min-height: 100%;
}
.tile-icon { font-size: 4rem; transition: transform .2s; }
.tile:hover .tile-icon { transform: scale(1.12) rotate(-4deg); }
.tile-title { font-size: 1.3rem; font-weight: 800; line-height: 1.25; }
.tile-meta {
    font-size: .92rem; font-weight: 700; color: var(--c);
    background: var(--surface); padding: 2px 12px; border-radius: 999px;
}
.tile-stars { font-size: 1.2rem; letter-spacing: 2px; min-height: 1.4em; color: #eab308; }
.tile .speak-btn { position: absolute; top: 10px; right: 10px; }
.tile.done { border-style: solid; border-color: color-mix(in srgb, #eab308 60%, var(--c-line)); }

.bab-head { display: flex; align-items: center; gap: 12px; margin: 34px 0 14px; }
.bab-head:first-child { margin-top: 0; }
.bab-title {
    margin: 0; font-size: 1.35rem; font-weight: 900; color: var(--c, var(--text));
    padding: 6px 18px; border-radius: 999px; background: var(--c-soft, var(--surface-alt));
}
.lesson-acuan { margin: 22px 4px 0; font-size: .88rem; }

.empty-state { text-align: center; padding: 48px 16px; display: grid; justify-items: center; gap: 10px; }
.empty-state .emoji { font-size: 4rem; }
.empty-state p { font-size: 1.2rem; margin: 0; }

/* ---------- Kata yang bisa diketuk ---------- */
.word {
    font: inherit; color: inherit; background: none; border: 0; padding: 0 .06em; margin: 0;
    border-radius: 6px; cursor: pointer; line-height: inherit; letter-spacing: inherit;
    transition: background .12s;
}
.word:hover { background: var(--c-soft, var(--surface-alt)); }
.word.hl, .word.tap { background: var(--hl); color: var(--hl-text); }
.word.tap { animation: tap .35s ease; }
@keyframes tap { 50% { transform: scale(1.15); } }

/* ---------- Halaman materi ---------- */
.lesson { padding: 24px 0 120px; background: linear-gradient(180deg, var(--c-soft), var(--bg) 320px); min-height: 70vh; }
.lesson-container { max-width: 860px; }
.lesson-top { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; }
.lesson-top .back-link { margin: 0; }
.lesson-settings { display: flex; gap: 8px; }
.toggle-btn {
    display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 14px;
    border-radius: 999px; border: 2px solid var(--border); background: var(--surface); color: var(--muted);
    font: inherit; font-weight: 700; cursor: pointer;
}
.toggle-btn[aria-pressed="true"] { border-color: var(--c); color: var(--c); background: var(--c-soft); }
.toggle-btn .emoji { font-size: 1.2rem; }

.lesson-title { display: flex; align-items: center; gap: 12px; font-size: clamp(1.5rem, 4vw, 2.1rem); font-weight: 900; margin: 22px 0 14px; }
.lesson-title .emoji { font-size: 1.4em; }

.lesson-progress { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.lesson-progress-track { flex: 1; height: 14px; border-radius: 999px; background: var(--surface-alt); border: 1px solid var(--border); overflow: hidden; }
.lesson-progress-bar { height: 100%; width: 0; background: var(--c); border-radius: 999px; transition: width .35s ease; }
.lesson-progress-text { font-weight: 800; min-width: 64px; text-align: right; color: var(--c); }

.lesson-start {
    display: grid; justify-items: center; gap: 18px; text-align: center;
    padding: 48px 16px; background: var(--surface); border: 3px dashed var(--c-line); border-radius: 28px;
}
.lesson-start-icon { font-size: 6rem; animation: bob 3s ease-in-out infinite; }
.lesson-start p { margin: 0; font-size: 1.1rem; }

/* Langkah: tanpa JS semua tampil berurutan; dengan JS satu per satu */
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 22px; }
.lesson.is-js .step { display: none; }
.lesson.is-js.is-started .step.active { display: block; animation: slideIn .35s ease; }
@keyframes slideIn { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }

.step {
    background: var(--surface); border: 3px solid var(--c-line); border-radius: 28px;
    padding: 28px 22px 32px; text-align: center; box-shadow: var(--shadow);
}

/* Slide */
.slide-pic { display: flex; justify-content: center; margin-bottom: 8px; }
.slide-pic .pic.emoji {
    font-size: clamp(4.5rem, 18vw, 8rem); line-height: 1.15;
    max-width: 100%; overflow-wrap: anywhere; word-break: break-all;
}
.slide-pic img.pic, .q-pic img.pic { max-width: min(100%, 360px); max-height: 280px; object-fit: contain; border-radius: 18px; }
.slide-body { border-radius: 18px; padding: 6px 4px; transition: background .2s; }
.slide-body.is-reading, .q-text.is-reading { background: color-mix(in srgb, var(--hl) 22%, transparent); }
.slide-title { font-size: clamp(2.4rem, 9vw, 4rem); font-weight: 900; margin: 0 0 6px; color: var(--c); letter-spacing: .02em; }
.slide-text { font-size: clamp(1.5rem, 5vw, 2.1rem); font-weight: 700; line-height: 1.45; margin: 0; }

.syllables { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 10px; margin-top: 20px; }
.syl {
    min-width: 72px; min-height: 64px; padding: 0 18px; border-radius: 18px;
    border: 3px solid var(--c-line); background: var(--c-soft); color: var(--text);
    font: inherit; font-size: 1.8rem; font-weight: 800; cursor: pointer;
    box-shadow: 0 4px 0 var(--c-line);
}
.syl:hover { border-color: var(--c); }
.syl:active, .syl.tap { transform: translateY(3px); box-shadow: 0 1px 0 var(--c-line); background: var(--hl); color: var(--hl-text); }
.syl-sep { font-size: 1.6rem; font-weight: 800; color: var(--muted); }

/* Kuis */
.q-badge {
    display: inline-flex; align-items: center; gap: 6px; margin: 0 0 12px;
    padding: 4px 14px; border-radius: 999px; background: var(--c-soft); color: var(--c); font-weight: 800;
}
.q-pic { display: flex; justify-content: center; margin-bottom: 8px; }
.q-pic .pic.emoji { font-size: clamp(3.5rem, 14vw, 6rem); line-height: 1.15; overflow-wrap: anywhere; word-break: break-all; }
.q-text { font-size: clamp(1.4rem, 4.5vw, 1.9rem); font-weight: 800; margin: 0 0 22px; border-radius: 14px; }

.options { display: grid; gap: 14px; grid-template-columns: repeat(2, 1fr); }
.options-3 { grid-template-columns: repeat(3, 1fr); }
.opt {
    position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
    min-height: 120px; padding: 16px 10px; border-radius: 22px;
    border: 3px solid var(--border); background: var(--bg); color: var(--text);
    font: inherit; cursor: pointer; transition: transform .12s, border-color .12s, background .12s;
    box-shadow: 0 5px 0 var(--border);
}
.opt:hover:not(:disabled) { border-color: var(--c); }
.opt:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 2px 0 var(--border); }
.opt-pic.emoji { font-size: 3.4rem; line-height: 1.1; }
.opt img.opt-pic { max-width: 100%; max-height: 110px; object-fit: contain; }
.opt-label { font-size: 1.6rem; font-weight: 800; }
.opt.selected { border-color: var(--c); background: var(--c-soft); box-shadow: 0 5px 0 var(--c); }
.opt.correct { border-color: var(--good); background: color-mix(in srgb, var(--good) 16%, var(--surface)); box-shadow: 0 5px 0 var(--good); opacity: 1; }
.opt.wrong { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 10%, var(--surface)); box-shadow: none; opacity: .55; }
.opt:disabled { cursor: default; }
.opt.correct .opt-mark::after, .opt.wrong .opt-mark::after {
    position: absolute; top: 8px; right: 10px; font-size: 1.4rem; font-family: var(--emoji-font);
}
.opt.correct .opt-mark::after { content: "✅"; }
.opt.wrong .opt-mark::after { content: "❌"; }

.q-hint {
    display: inline-block; margin: -10px 0 20px; padding: 6px 16px; border-radius: 999px;
    background: color-mix(in srgb, var(--hl) 30%, var(--surface)); font-weight: 700; font-size: 1.1rem;
}
.options-4 { grid-template-columns: repeat(2, 1fr); }
.options-5, .options-6 { grid-template-columns: repeat(3, 1fr); }
.q-urutkan .opt-label { font-size: 1.15rem; line-height: 1.3; }
.opt.ordered { border-color: var(--good); background: color-mix(in srgb, var(--good) 12%, var(--surface)); box-shadow: 0 5px 0 var(--good); }
.opt.ordered .opt-mark {
    position: absolute; top: 8px; left: 10px; width: 34px; height: 34px; border-radius: 50%;
    display: grid; place-items: center; background: var(--good); color: #fff; font-weight: 900; font-size: 1.1rem;
}

/* Pilihan + tombol speaker kecil di pojok */
.opt-wrap { position: relative; display: flex; }
.opt-wrap .opt { flex: 1; width: 100%; }
.opt-wrap > .speak-btn {
    position: absolute; right: 8px; bottom: 12px; z-index: 1;
    width: 40px; height: 40px; background: var(--surface);
}
.opt-wrap > .speak-btn svg { width: 22px; height: 22px; }
.opt-wrap:has(> .speak-btn) .opt { padding-bottom: 30px; }

.q-feedback-row { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.q-feedback-row .q-feedback { margin: 0; }

/* Menu pilihan suara */
.voice-select {
    display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 6px 0 12px;
    border-radius: 999px; border: 2px solid var(--border); background: var(--surface);
}
.voice-select select {
    font: inherit; font-weight: 700; color: var(--text); background: transparent;
    border: 0; padding: 6px 4px; max-width: 190px; cursor: pointer;
}
.voice-select select:focus { outline: none; }
.voice-select:focus-within { border-color: var(--c); }
.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;
}

.q-actions { margin-top: 26px; }
.q-actions .btn-kid { min-width: 220px; }
.q-feedback { min-height: 1.6em; margin: 16px 0 0; font-size: 1.35rem; font-weight: 800; }
.q-feedback.good { color: var(--good); }
.q-feedback.bad { color: var(--bad); }

.shake { animation: shake .45s ease; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.celebrate { animation: celebrate .6s ease; }
@keyframes celebrate { 30% { transform: scale(1.03) rotate(-1deg); } 60% { transform: scale(1.02) rotate(1deg); } }
.nudge { animation: nudge .35s ease; }
@keyframes nudge { 50% { transform: scale(1.06); } }

/* Hasil */
.result-stars { display: flex; justify-content: center; gap: 10px; font-size: clamp(3.5rem, 14vw, 5.5rem); font-family: var(--emoji-font); }
.result-stars .star { filter: grayscale(1) opacity(.25); transform: scale(.8); transition: filter .3s, transform .3s; }
.result-stars .star.on.pop { filter: none; transform: scale(1); animation: starPop .5s ease; }
@keyframes starPop { 0% { transform: scale(.3) rotate(-30deg); } 70% { transform: scale(1.25) rotate(8deg); } 100% { transform: scale(1); } }
.result-title { font-size: clamp(2rem, 7vw, 3rem); font-weight: 900; color: var(--c); margin: 10px 0 6px; }
.result-text { font-size: 1.3rem; font-weight: 600; }

/* Navigasi bawah (melayang) */
.lesson-nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    display: flex; align-items: center; justify-content: center; gap: 18px;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(10px); border-top: 1px solid var(--border);
}
.lesson:not(.is-started) .lesson-nav { display: none; }
.nav-btn {
    width: 68px; height: 68px; border-radius: 50%; border: 3px solid var(--c-line);
    background: var(--surface); color: var(--c); font-size: 1.7rem; cursor: pointer;
    display: grid; place-items: center; transition: transform .1s, opacity .2s;
}
.nav-btn:active:not(:disabled) { transform: scale(.92); }
.nav-btn:disabled { opacity: .3; cursor: not-allowed; }
.nav-next:not(:disabled) { background: var(--c); color: #fff; border-color: transparent; }
.nav-next.attention { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--c) 50%, transparent); } 50% { box-shadow: 0 0 0 12px transparent; } }
.speak-main { height: 68px; padding: 0 28px; font-size: 1.25rem; border-width: 3px; }
.speak-main svg { width: 34px; height: 34px; }

/* ---------- Responsif ---------- */
@media (max-width: 820px) {
    .steps-row { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
    .kid-hero { padding: 40px 0; }
    .kid-hero-inner { flex-direction: column; text-align: center; gap: 12px; }
    .kid-hero .kid-actions { justify-content: center; }
    .tile-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
    .tile-link { padding: 26px 8px 18px; }
    .tile-icon { font-size: 3rem; }
    .tile-title { font-size: 1.05rem; }
    .tile .speak-btn { top: 6px; right: 6px; width: 40px; height: 40px; }
    .options-3, .options-5, .options-6 { grid-template-columns: repeat(2, 1fr); }
    .options-3 .opt-wrap:last-child, .options-5 .opt-wrap:last-child { grid-column: 1 / -1; }
    .voice-select select { max-width: 120px; }
    .step { padding: 22px 14px 26px; border-radius: 22px; }
    .opt { min-height: 100px; }
    .lesson-nav { gap: 10px; }
    .nav-btn { width: 60px; height: 60px; }
    .speak-main { height: 60px; padding: 0 20px; }
    .lesson-settings .toggle-btn span:last-child { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    .mascot, .lesson-start-icon, .nav-next.attention, .is-speaking .wave { animation: none; }
    .lesson.is-js.is-started .step.active { animation: none; }
}
