@import url('https://fonts.googleapis.com/css2?family=Comic+Neue:wght@400;700&family=Fredoka:wght@400;600;700&family=Nunito:wght@400;600;700;800;900&display=swap');

:root {
    --desk-bg: radial-gradient(circle at center, #2c1b4d 0%, #110926 100%);
    --book-page-bg: #fffdf5;
    --book-cover-bg: linear-gradient(145deg, #4a154b, #6b117b, #2b0838);
    --primary-color: #ff6b6b;
    --secondary-color: #4ecdc4;
    --accent-yellow: #ffe66d;
    --accent-orange: #ff9f43;
    --text-dark: #2d3436;
    --gold: #ffd700;
    --font-heading: 'Fredoka', 'Nunito', sans-serif;
    --font-body: 'Nunito', 'Comic Neue', sans-serif;
    --shadow-book: -10px 15px 40px rgba(0,0,0,0.4), 0 0 20px rgba(255,230,109,0.2);
}

* { box-sizing: border-box; margin: 0; padding: 0; user-select: none; -webkit-user-select: none; }

body {
    font-family: var(--font-body);
    background: var(--desk-bg);
    color: var(--text-dark);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow-x: hidden;
    position: relative;
}

.stars-bg {
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    pointer-events: none; z-index: 0; overflow: hidden;
}

.star-particle {
    position: absolute; background: white; border-radius: 50%;
    animation: twinkle var(--duration, 3s) infinite ease-in-out; opacity: 0.7;
}

@keyframes twinkle {
    0%, 100% { transform: scale(0.8); opacity: 0.3; }
    50% { transform: scale(1.4); opacity: 1; filter: drop-shadow(0 0 6px var(--gold)); }
}

/* HEADER */
.app-header {
    position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 100;
    display: flex; align-items: center; gap: 15px;
    background: rgba(255,255,255,0.15); backdrop-filter: blur(12px);
    padding: 8px 25px; border-radius: 50px;
    border: 2px solid rgba(255,255,255,0.3); box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}
.header-title {
    color: #fff; font-family: var(--font-heading); font-size: 1.2rem; font-weight: 700;
    display: flex; align-items: center; gap: 8px; text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}
.header-controls { display: flex; align-items: center; gap: 10px; }
.btn-icon {
    background: #fff; border: none; border-radius: 50%; width: 40px; height: 40px;
    font-size: 1.2rem; cursor: pointer; display: flex; align-items: center; justify-content: center;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2); transition: all 0.2s;
}
.btn-icon:hover { transform: scale(1.15) rotate(5deg); background: var(--accent-yellow); }
.star-counter {
    background: var(--accent-orange); color: white; font-family: var(--font-heading);
    font-weight: 700; padding: 6px 14px; border-radius: 20px;
    display: flex; align-items: center; gap: 6px;
    box-shadow: 0 4px 12px rgba(255,159,67,0.4); font-size: 1rem;
}
.star-counter span.star-icon { font-size: 1.3rem; animation: pulse-star 1.5s infinite alternate; }
@keyframes pulse-star { from { transform: scale(1); } to { transform: scale(1.25) rotate(15deg); } }

/* ============ FLYING 3D MASCOT OVERLAY ============ */
.mascot-overlay {
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    z-index: 500; pointer-events: none; overflow: hidden;
}
#threeCanvas {
    width: 100%; height: 100%; display: block;
}

/* ============ FLOATING SPEECH BUBBLE (DOCKED AT TOP-RIGHT OUTSIDE BOOK) ============ */
.floating-bubble {
    position: fixed;
    top: 68px;
    right: 20px;
    z-index: 501;
    pointer-events: auto;
    background: #ffffff;
    border: 3px solid var(--accent-orange);
    border-radius: 20px;
    padding: 12px 16px;
    width: 320px;
    max-width: calc(100vw - 40px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.3);
    transition: opacity 0.3s ease, transform 0.3s ease;
    opacity: 1;
}
.floating-bubble.hidden { opacity: 0; pointer-events: none; transform: translateY(-10px); }
.floating-bubble::after, .floating-bubble::before { display: none; }
.speech-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 6px; padding-bottom: 6px; border-bottom: 1.5px dashed #eee;
}
.mascot-name {
    font-family: var(--font-heading); font-weight: 700; color: var(--primary-color); font-size: 1rem;
}
.btn-tts-speak {
    background: var(--secondary-color); color: white; border: none; border-radius: 15px;
    padding: 4px 12px; font-size: 0.85rem; font-family: var(--font-heading); font-weight: 700;
    cursor: pointer; display: flex; align-items: center; gap: 5px; transition: all 0.2s;
}
.btn-tts-speak:hover { background: #36b9b0; transform: scale(1.05); }
.btn-tts-speak.speaking { background: var(--primary-color); animation: pulse-speaking 0.8s infinite alternate; }
@keyframes pulse-speaking { from { opacity: 0.8; } to { opacity: 1; transform: scale(1.08); } }
.speech-text {
    font-size: 0.92rem; line-height: 1.4; color: var(--text-dark); font-weight: 600;
    max-height: 90px; overflow-y: auto;
}
.bubble-close {
    position: absolute; top: 6px; right: 10px; cursor: pointer;
    font-size: 0.85rem; color: #aaa; font-weight: bold; line-height: 1;
}
.bubble-close:hover { color: var(--primary-color); }

/* ============ BOOK ============ */
.book-wrapper {
    position: relative; z-index: 10; width: 92vw; max-width: 1150px;
    height: 82vh; max-height: 720px; margin-top: 55px; perspective: 2000px;
}
.book-container {
    width: 100%; height: 100%; position: relative; background: var(--book-page-bg);
    border-radius: 20px; box-shadow: var(--shadow-book); display: flex; overflow: hidden;
    border: 8px solid #3d2314;
}
.book-spine {
    position: absolute; top: 0; left: 50%; transform: translateX(-50%);
    width: 30px; height: 100%; z-index: 20; pointer-events: none;
    background: linear-gradient(to right, rgba(0,0,0,0.25) 0%, rgba(0,0,0,0.05) 40%, rgba(0,0,0,0.3) 50%, rgba(0,0,0,0.05) 60%, rgba(0,0,0,0.25) 100%);
}
.book-page {
    flex: 1; height: 100%; padding: 28px 36px 60px; overflow-y: auto; position: relative;
    background-color: var(--book-page-bg);
    background-image: radial-gradient(#e5dec9 0.75px, transparent 0.75px); background-size: 20px 20px;
}
.book-page.left-page { border-right: 1px solid rgba(0,0,0,0.1); }
.book-page::-webkit-scrollbar { width: 6px; }
.book-page::-webkit-scrollbar-track { background: rgba(0,0,0,0.05); border-radius: 10px; }
.book-page::-webkit-scrollbar-thumb { background: var(--secondary-color); border-radius: 10px; }

/* COVER */
.cover-view {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: var(--book-cover-bg); z-index: 50;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    text-align: center; padding: 40px; border-radius: 12px; color: white;
    box-shadow: inset 0 0 100px rgba(0,0,0,0.6);
    transition: transform 0.8s cubic-bezier(0.645,0.045,0.355,1), opacity 0.6s ease;
}
.cover-view.opened { transform: rotateY(-120deg) scale(0.9); opacity: 0; pointer-events: none; }
.cover-border {
    border: 4px dashed var(--gold); border-radius: 20px; padding: 35px 25px;
    width: 90%; max-width: 650px;
    background: rgba(0,0,0,0.3); backdrop-filter: blur(5px);
    display: flex; flex-direction: column; align-items: center; gap: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}
.cover-badge {
    background: var(--accent-orange); color: white; font-family: var(--font-heading);
    font-weight: 700; font-size: 0.95rem; padding: 6px 18px; border-radius: 20px;
    letter-spacing: 1px; text-transform: uppercase;
}
.cover-title {
    font-family: var(--font-heading); font-size: 2.6rem; font-weight: 700;
    color: var(--accent-yellow);
    text-shadow: 0 4px 10px rgba(0,0,0,0.6), 0 0 20px rgba(255,230,109,0.4); line-height: 1.15;
}
.cover-subtitle { font-size: 1.2rem; color: #e0e0e0; max-width: 520px; line-height: 1.4; }
.btn-start-book {
    background: linear-gradient(135deg, #ff9f43, #ff5252); color: white;
    font-family: var(--font-heading); font-size: 1.4rem; font-weight: 700;
    padding: 16px 45px; border: none; border-radius: 50px; cursor: pointer;
    box-shadow: 0 8px 25px rgba(255,82,82,0.5), inset 0 2px 4px rgba(255,255,255,0.4);
    transition: all 0.25s; display: flex; align-items: center; gap: 12px;
}
.btn-start-book:hover { transform: scale(1.08) translateY(-3px); box-shadow: 0 12px 35px rgba(255,82,82,0.7); }

/* PAGE CONTENT */
.page-chapter-tag {
    display: inline-block; background: rgba(78,205,196,0.15); color: #16a085;
    font-family: var(--font-heading); font-weight: 700; font-size: 0.9rem;
    padding: 4px 14px; border-radius: 20px; margin-bottom: 10px;
    border: 1px solid rgba(78,205,196,0.3);
}
.page-title {
    font-family: var(--font-heading); font-size: 1.7rem; font-weight: 700;
    color: #2c3e50; line-height: 1.25; margin-bottom: 15px;
}
.renaming-flow-kids {
    display: flex; align-items: center; justify-content: center; gap: 12px;
    background: linear-gradient(135deg, #fff9e6, #fff0f5);
    border: 2px dashed var(--accent-orange); border-radius: 16px;
    padding: 10px 16px; margin: 12px 0;
}
.old-name-badge {
    background: #e74c3c; color: white; font-family: var(--font-heading);
    font-size: 1rem; font-weight: 700; padding: 5px 14px; border-radius: 10px;
}
.arrow-icon-kids { font-size: 1.3rem; color: var(--accent-orange); animation: arrow-bounce 1s infinite alternate; }
@keyframes arrow-bounce { from { transform: translateX(0); } to { transform: translateX(6px); } }
.new-name-badge {
    background: #2ecc71; color: white; font-family: var(--font-heading);
    font-size: 1.1rem; font-weight: 700; padding: 6px 16px; border-radius: 10px;
}
.kids-text-box {
    font-size: 1rem; line-height: 1.55; color: #34495e; background: #fff;
    border-radius: 14px; padding: 14px 16px; border-left: 5px solid var(--secondary-color);
    box-shadow: 0 3px 10px rgba(0,0,0,0.04); margin-bottom: 12px;
}

/* COMPARISON SLIDER */
.comparison-container {
    position: relative; width: 100%; height: 220px; border-radius: 16px;
    overflow: hidden; border: 3px solid #fff;
    box-shadow: 0 8px 20px rgba(0,0,0,0.15); margin: 12px 0; cursor: ew-resize;
}
.comparison-img { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; }
.comparison-img.after { clip-path: polygon(50% 0, 100% 0, 100% 100%, 50% 100%); }
.comparison-slider-handle {
    position: absolute; top: 0; bottom: 0; left: 50%; width: 4px;
    background: var(--gold); z-index: 10; box-shadow: 0 0 10px rgba(0,0,0,0.5);
}
.comparison-slider-handle::after {
    content: '↔'; position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
    width: 34px; height: 34px; background: var(--gold); color: #3d2314; font-weight: bold;
    border-radius: 50%; display: flex; align-items: center; justify-content: center;
}
.comparison-label {
    position: absolute; bottom: 10px; padding: 4px 12px; background: rgba(0,0,0,0.7);
    color: white; font-family: var(--font-heading); font-size: 0.8rem; border-radius: 10px; z-index: 5;
}
.comparison-label.before-label { left: 10px; }
.comparison-label.after-label { right: 10px; }

/* GALLERY */
.kids-gallery { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin: 12px 0; }
.kids-photo-card {
    background: white; border-radius: 12px; padding: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08); transition: transform 0.25s;
}
.kids-photo-card:hover { transform: translateY(-4px); }
.kids-photo-card img { width: 100%; height: 120px; object-fit: cover; border-radius: 8px; }
.kids-photo-caption {
    font-size: 0.8rem; font-weight: 700; color: var(--text-dark); margin-top: 5px; text-align: center;
}

/* QUIZ */
.quiz-box {
    background: linear-gradient(135deg, #e3f2fd, #bbdefb); border: 2px dashed #2196f3;
    border-radius: 14px; padding: 12px 15px; margin-top: 12px;
}
.quiz-title {
    font-family: var(--font-heading); font-size: 1.05rem; font-weight: 700; color: #0d47a1;
    display: flex; align-items: center; gap: 6px; margin-bottom: 6px;
}
.quiz-options { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.btn-quiz-opt {
    background: white; border: 2px solid #90caf9; border-radius: 18px;
    padding: 6px 14px; font-family: var(--font-body); font-size: 0.9rem; font-weight: 700;
    color: #1565c0; cursor: pointer; transition: all 0.2s;
}
.btn-quiz-opt:hover { background: #e3f2fd; border-color: #2196f3; }
.btn-quiz-opt.correct { background: #4caf50 !important; color: white !important; border-color: #4caf50 !important; }
.btn-quiz-opt.wrong { background: #f44336 !important; color: white !important; border-color: #f44336 !important; }

/* NAV */
.book-nav-bar {
    position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); z-index: 30;
    display: flex; align-items: center; gap: 15px;
    background: rgba(255,255,255,0.95); padding: 5px 18px; border-radius: 30px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.15);
}
.btn-page-nav {
    background: var(--primary-color); color: white; border: none; border-radius: 20px;
    padding: 6px 18px; font-family: var(--font-heading); font-weight: 700; font-size: 0.95rem;
    cursor: pointer; display: flex; align-items: center; gap: 6px;
    box-shadow: 0 4px 10px rgba(255,107,107,0.4); transition: all 0.2s;
}
.btn-page-nav:hover:not(:disabled) { transform: scale(1.08); background: #ff5252; }
.btn-page-nav:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; }
.page-indicator { font-family: var(--font-heading); font-weight: 700; font-size: 1rem; color: var(--text-dark); }

/* DIPLOMA MODAL */
.diploma-modal {
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0,0,0,0.7); backdrop-filter: blur(8px); z-index: 600;
    display: flex; align-items: center; justify-content: center;
    opacity: 0; pointer-events: none; transition: opacity 0.4s;
}
.diploma-modal.active { opacity: 1; pointer-events: auto; }
.diploma-card {
    background: #fffdf5; border: 8px solid var(--gold); border-radius: 24px;
    padding: 35px; max-width: 580px; width: 90%; text-align: center;
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
    background-image: radial-gradient(#e5dec9 0.75px, transparent 0.75px); background-size: 15px 15px;
}
.diploma-title { font-family: var(--font-heading); font-size: 2.1rem; color: #d35400; margin-bottom: 10px; }
.diploma-input {
    width: 80%; padding: 12px 18px; font-size: 1.2rem; font-family: var(--font-body);
    font-weight: 700; border: 3px solid var(--secondary-color); border-radius: 15px;
    text-align: center; margin: 15px 0; outline: none;
}

@media (max-width: 900px) {
    .book-wrapper { width: 96vw; height: 88vh; }
    .book-container { flex-direction: column; }
    .book-spine { display: none; }
    .book-page.left-page { border-right: none; border-bottom: 2px dashed #ddd; }
    .cover-title { font-size: 2rem; }
    .floating-bubble { max-width: 220px; }
}
