/* ===================== Times Table Trainer — kid theme ===================== */
:root {
    --pink: #ff5e9a;
    --purple: #8b5cf6;
    --blue: #38bdf8;
    --green: #34d399;
    --yellow: #fbbf24;
    --orange: #fb7185;
    --ink: #2b2350;
    --card: #ffffff;
    --shadow: 0 10px 0 rgba(43, 35, 80, 0.18);
    --radius: 26px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; margin: 0; }

body {
    font-family: 'Fredoka', 'Baloo 2', system-ui, sans-serif;
    color: var(--ink);
    background: linear-gradient(160deg, #a78bfa 0%, #60a5fa 45%, #34d399 100%);
    background-attachment: fixed;
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
}

/* Floating background emojis */
.bg-shapes { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.bg-shapes span {
    position: absolute;
    font-size: 2.6rem;
    opacity: 0.25;
    animation: float 9s ease-in-out infinite;
}
.bg-shapes span:nth-child(1){ left: 6%;  top: 12%; animation-delay: 0s; }
.bg-shapes span:nth-child(2){ left: 82%; top: 8%;  animation-delay: 1.2s; }
.bg-shapes span:nth-child(3){ left: 15%; top: 72%; animation-delay: 2.1s; }
.bg-shapes span:nth-child(4){ left: 70%; top: 66%; animation-delay: .6s; }
.bg-shapes span:nth-child(5){ left: 45%; top: 18%; animation-delay: 3s; }
.bg-shapes span:nth-child(6){ left: 88%; top: 44%; animation-delay: 1.8s; }
.bg-shapes span:nth-child(7){ left: 30%; top: 40%; animation-delay: 2.6s; }
.bg-shapes span:nth-child(8){ left: 58%; top: 82%; animation-delay: .3s; }
@keyframes float {
    0%,100% { transform: translateY(0) rotate(-6deg); }
    50%     { transform: translateY(-26px) rotate(8deg); }
}

/* Screens */
.screen { display: none; position: relative; z-index: 1; padding: 22px 16px 60px; max-width: 980px; margin: 0 auto; }
.screen.active { display: block; animation: screenIn .4s ease; }
@keyframes screenIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

/* Header */
.app-header { text-align: center; margin: 8px 0 26px; }
.app-title {
    font-family: 'Baloo 2', sans-serif;
    font-size: clamp(2rem, 7vw, 3.4rem);
    margin: 0;
    color: #fff;
    text-shadow: 0 4px 0 rgba(43,35,80,.28), 0 0 22px rgba(255,255,255,.4);
    animation: pop .6s ease;
}
.app-subtitle { color: #fff; font-size: 1.1rem; margin: 8px 0 0; text-shadow: 0 2px 0 rgba(43,35,80,.2); }
@keyframes pop { 0%{ transform: scale(.6); opacity: 0;} 70%{ transform: scale(1.08);} 100%{ transform: scale(1); opacity:1;} }

/* Profiles grid */
.profiles-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 18px;
}
.profile-tile {
    background: var(--card);
    border-radius: var(--radius);
    padding: 20px 14px 16px;
    text-align: center;
    box-shadow: var(--shadow);
    cursor: pointer;
    position: relative;
    border: 4px solid #fff;
    transition: transform .15s ease, box-shadow .15s ease;
    animation: tileIn .45s ease backwards;
}
.profile-tile:hover { transform: translateY(-6px) rotate(-1deg); }
.profile-tile:active { transform: translateY(-2px) scale(.98); }
@keyframes tileIn { from { opacity: 0; transform: scale(.7);} to { opacity: 1; transform: scale(1);} }

.tile-avatar {
    width: 78px; height: 78px; margin: 0 auto 10px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 2.6rem;
    box-shadow: inset 0 -6px 0 rgba(0,0,0,.12);
}
.tile-name { font-weight: 700; font-size: 1.2rem; margin: 0; word-break: break-word; }
.tile-level {
    margin: 8px auto 4px;
    display: inline-block;
    background: var(--yellow);
    color: var(--ink);
    font-weight: 700;
    padding: 4px 12px;
    border-radius: 999px;
    font-size: .92rem;
    box-shadow: 0 3px 0 rgba(43,35,80,.18);
}
.tile-stars { font-size: .9rem; color: #6b6390; margin-top: 6px; }
.tile-delete {
    position: absolute; top: -10px; right: -10px;
    width: 32px; height: 32px; border-radius: 50%;
    border: 3px solid #fff; background: var(--orange); color: #fff;
    font-size: 1rem; cursor: pointer; line-height: 1;
    box-shadow: 0 3px 0 rgba(43,35,80,.25);
}
.tile-delete:hover { transform: scale(1.12) rotate(8deg); }

/* Add tile */
.add-tile {
    background: rgba(255,255,255,.35);
    border: 4px dashed #fff;
    color: #fff;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    min-height: 180px; border-radius: var(--radius); cursor: pointer;
    transition: transform .15s ease, background .15s ease;
}
.add-tile:hover { background: rgba(255,255,255,.5); transform: translateY(-6px); }
.add-tile .plus { font-size: 3rem; line-height: 1; }
.add-tile .add-label { font-weight: 700; margin-top: 6px; }

/* ============================ PLAY SCREEN ============================ */
.play-topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.btn-back {
    background: #fff; border: none; border-radius: 999px; padding: 10px 16px;
    font-family: inherit; font-weight: 700; font-size: 1rem; color: var(--ink);
    cursor: pointer; box-shadow: 0 4px 0 rgba(43,35,80,.2);
}
.btn-back:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(43,35,80,.2); }
.player-chip {
    display: flex; align-items: center; gap: 8px; background: #fff;
    padding: 6px 16px 6px 6px; border-radius: 999px; box-shadow: 0 4px 0 rgba(43,35,80,.2);
    margin-right: auto;
}
.chip-avatar {
    width: 40px; height: 40px; border-radius: 50%; display: flex;
    align-items: center; justify-content: center; font-size: 1.4rem;
    box-shadow: inset 0 -4px 0 rgba(0,0,0,.12);
}
.chip-name { font-weight: 700; font-size: 1.1rem; }
.star-counter {
    background: var(--yellow); color: var(--ink); font-weight: 700;
    padding: 8px 16px; border-radius: 999px; box-shadow: 0 4px 0 rgba(43,35,80,.2);
}

.play-view { display: none; }
.play-view.active { display: block; animation: screenIn .35s ease; }

/* Lobby */
.level-banner {
    display: flex; align-items: center; gap: 18px;
    background: #fff; border-radius: var(--radius); padding: 18px 22px;
    box-shadow: var(--shadow); margin-bottom: 22px;
}
.level-badge {
    width: 66px; height: 66px; border-radius: 20px; flex: none;
    background: linear-gradient(135deg, var(--purple), var(--pink));
    color: #fff; font-family: 'Baloo 2'; font-size: 2.1rem; font-weight: 800;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 5px 0 rgba(43,35,80,.25);
}
.level-banner-text h2 { margin: 0; font-size: 1.6rem; }
.level-banner-text p { margin: 2px 0 0; color: #6b6390; font-size: 1.1rem; }

.mode-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 24px; }
.mode-card {
    border: none; border-radius: var(--radius); padding: 22px 18px; cursor: pointer;
    color: #fff; text-align: center; font-family: inherit;
    display: flex; flex-direction: column; align-items: center; gap: 6px;
    box-shadow: 0 8px 0 rgba(43,35,80,.22); transition: transform .15s ease;
}
.mode-card:hover { transform: translateY(-5px); }
.mode-card:active { transform: translateY(2px); box-shadow: 0 3px 0 rgba(43,35,80,.22); }
.mode-card.practice { background: linear-gradient(135deg, var(--blue), var(--green)); }
.mode-card.quiz { background: linear-gradient(135deg, var(--pink), var(--orange)); }
.mode-emoji { font-size: 2.8rem; }
.mode-name { font-size: 1.5rem; font-weight: 800; font-family: 'Baloo 2'; }
.mode-desc { font-size: .95rem; opacity: .95; }

.level-track {
    display: flex; flex-wrap: wrap; gap: 10px; justify-content: center;
    background: rgba(255,255,255,.28); padding: 14px; border-radius: var(--radius);
}
.level-dot {
    width: 46px; height: 46px; border-radius: 14px; display: flex;
    align-items: center; justify-content: center; font-weight: 800; font-size: 1.1rem;
    background: rgba(255,255,255,.55); color: var(--ink); border: 3px solid #fff;
}
.level-dot.done { background: var(--green); color: #fff; }
.level-dot.current { background: var(--yellow); color: var(--ink); transform: scale(1.12); box-shadow: 0 0 0 4px rgba(255,255,255,.6); }
.level-dot.locked { opacity: .55; }

/* Game HUD */
.game-hud { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.hud-mode { background: #fff; padding: 6px 14px; border-radius: 999px; font-weight: 700; box-shadow: 0 4px 0 rgba(43,35,80,.2); }
.progress-wrap { flex: 1; height: 16px; background: rgba(255,255,255,.5); border-radius: 999px; overflow: hidden; box-shadow: inset 0 2px 4px rgba(0,0,0,.15); }
.progress-bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--yellow), var(--green)); border-radius: 999px; transition: width .4s ease; }
.hud-score { background: #fff; padding: 6px 14px; border-radius: 999px; font-weight: 700; box-shadow: 0 4px 0 rgba(43,35,80,.2); white-space: nowrap; }

/* Flash card */
.card-stage { position: relative; margin-bottom: 20px; }
.flash-card {
    background: #fff; border-radius: 30px; padding: 34px 20px;
    box-shadow: var(--shadow); text-align: center;
    display: flex; align-items: center; justify-content: center; gap: 16px; flex-wrap: wrap;
    min-height: 150px;
}
.flash-card.shake { animation: shake .5s; }
.flash-card.correct-glow { animation: glow .6s; }
@keyframes shake { 0%,100%{transform:translateX(0);} 20%{transform:translateX(-12px);} 40%{transform:translateX(12px);} 60%{transform:translateX(-8px);} 80%{transform:translateX(8px);} }
@keyframes glow { 0%{ box-shadow: var(--shadow);} 50%{ box-shadow: 0 0 0 8px rgba(52,211,153,.55), var(--shadow);} 100%{ box-shadow: var(--shadow);} }
.question { font-family: 'Baloo 2'; font-size: clamp(2.6rem, 11vw, 4.6rem); font-weight: 800; color: var(--purple); }
.equals { font-family: 'Baloo 2'; font-size: clamp(2.2rem, 9vw, 4rem); color: #b9b2d6; }
.answer-slot {
    font-family: 'Baloo 2'; font-size: clamp(2.6rem, 11vw, 4.6rem); font-weight: 800;
    color: var(--pink); min-width: 90px;
    border-bottom: 6px dashed #e3def3; border-radius: 6px;
}
.answer-slot.filled { border-bottom-color: transparent; }

/* Feedback bubble */
.feedback {
    margin-top: 14px; text-align: center; font-weight: 700; font-size: 1.25rem;
    min-height: 30px; opacity: 0; transform: translateY(8px); transition: all .25s ease;
}
.feedback.show { opacity: 1; transform: none; }
.feedback.good { color: #067a4e; }
.feedback.bad { color: #fff; }
.feedback .fb-pill {
    display: inline-block; padding: 10px 18px; border-radius: 16px; line-height: 1.35;
}
.feedback.good .fb-pill { background: rgba(52,211,153,.28); }
.feedback.bad .fb-pill { background: var(--orange); box-shadow: 0 4px 0 rgba(43,35,80,.2); }
.feedback .fb-correct { font-family: 'Baloo 2'; font-size: 1.5rem; }

/* Choices */
.choices { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; margin-bottom: 18px; }
.choice-btn {
    background: #fff; border: 4px solid #fff; border-radius: 22px; padding: 20px;
    font-family: 'Baloo 2'; font-size: 2rem; font-weight: 800; color: var(--ink);
    cursor: pointer; box-shadow: 0 6px 0 rgba(43,35,80,.2); transition: transform .1s ease;
}
.choice-btn:hover:not(:disabled) { transform: translateY(-4px); }
.choice-btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 2px 0 rgba(43,35,80,.2); }
.choice-btn:disabled { cursor: default; }
.choice-btn.right { background: var(--green); color: #fff; border-color: var(--green); animation: pop .4s ease; }
.choice-btn.wrong { background: var(--orange); color: #fff; border-color: var(--orange); }
.choice-btn.dim { opacity: .5; }

.game-controls { display: flex; justify-content: space-between; gap: 12px; }

/* Buttons */
.btn-primary, .btn-secondary, .btn-danger {
    font-family: inherit; font-weight: 700; font-size: 1.1rem; border: none;
    border-radius: 999px; padding: 14px 26px; cursor: pointer;
}
.btn-primary { background: linear-gradient(135deg, var(--purple), var(--pink)); color: #fff; box-shadow: 0 6px 0 rgba(43,35,80,.28); }
.btn-secondary { background: #fff; color: var(--ink); box-shadow: 0 6px 0 rgba(43,35,80,.2); }
.btn-danger { background: var(--orange); color: #fff; box-shadow: 0 6px 0 rgba(43,35,80,.25); }
.btn-primary:active, .btn-secondary:active, .btn-danger:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(43,35,80,.2); }
.hidden { display: none !important; }

/* Results */
.results-card {
    background: #fff; border-radius: 32px; padding: 34px 24px; text-align: center;
    box-shadow: var(--shadow); max-width: 460px; margin: 10px auto; animation: pop .5s ease;
}
.results-emoji { font-size: 4.5rem; animation: float 2.5s ease-in-out infinite; }
.results-card h2 { font-family: 'Baloo 2'; font-size: 2.2rem; margin: 6px 0; }
.results-score { font-size: 1.5rem; font-weight: 700; color: var(--purple); margin: 4px 0; }
.results-stars { font-size: 2.4rem; margin: 10px 0; letter-spacing: 4px; min-height: 44px; }
.results-msg { color: #6b6390; font-size: 1.15rem; margin: 6px 0 20px; }
.results-buttons { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* Modals */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(43,35,80,.55); backdrop-filter: blur(3px);
    display: none; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.modal-overlay.show { display: flex; animation: screenIn .25s ease; }
.modal { background: #fff; border-radius: 28px; padding: 28px 24px; max-width: 380px; width: 100%; text-align: center; box-shadow: 0 16px 40px rgba(0,0,0,.35); }
.modal h2 { font-family: 'Baloo 2'; margin: 0 0 6px; font-size: 1.8rem; }
.modal p { color: #6b6390; margin: 0 0 16px; }
.modal input {
    width: 100%; padding: 14px 16px; font-family: inherit; font-size: 1.3rem; font-weight: 600;
    border: 3px solid #e3def3; border-radius: 16px; text-align: center; outline: none;
}
.modal input:focus { border-color: var(--purple); }
.modal-error { color: var(--orange); font-weight: 700; min-height: 22px; margin: 8px 0 0; }
.modal-buttons { display: flex; gap: 12px; justify-content: center; margin-top: 18px; }

/* Confetti */
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 60; }

/* Sound toggle */
.sound-toggle {
    position: fixed; bottom: 16px; right: 16px; z-index: 40;
    width: 52px; height: 52px; border-radius: 50%; background: #fff;
    display: flex; align-items: center; justify-content: center; font-size: 1.5rem;
    cursor: pointer; box-shadow: 0 5px 0 rgba(43,35,80,.25); user-select: none;
}
.sound-toggle.muted { opacity: .55; }

@media (max-width: 520px) {
    .mode-cards { grid-template-columns: 1fr; }
    .choices { grid-template-columns: repeat(2, 1fr); }
}
