:root {
    --pink: #ff62bb;
    --pink-dark: #e0439a;
    --pink-soft: rgba(255, 207, 232, 0.85);
    --purple: #a855f7;
    --gold: #f59e0b;
    --green: #22c55e;
    --red: #ef4444;
    --panel: rgba(255, 248, 252, 0.93);
    --panel-border: rgba(255, 173, 214, 0.7);
    --text: #4a2040;
    --text-soft: #7a5876;
    --shadow: 0 8px 32px rgba(200, 80, 150, 0.18);
    --radius: 20px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

.hidden {
    display: none !important;
}

html,
body {
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    font-family: 'Nunito', sans-serif;
    color: var(--text);
    background: #1a0a2e;
}

.ans-btn:focus {
    outline: 3px solid var(--purple);
    transform: scale(1.02);
}

#next-step-btn:focus,
#single-next-btn:focus {
    outline: none;
    box-shadow: 0 0 0 4px rgba(255, 98, 187, 0.4);
}

/* ── BACKGROUND ── */
#bg {
    position: fixed;
    inset: 0;
    z-index: 0;
    background: url('background2.png') center/cover no-repeat;
}

#bg::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255, 150, 200, 0.15), rgba(100, 50, 200, 0.1));
}

/* ── LOGIN SCREEN ── */
#login-screen {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(30, 10, 60, 0.72);
    backdrop-filter: blur(12px);
}

.login-card {
    background: var(--panel);
    border-radius: 28px;
    padding: 48px 40px;
    text-align: center;
    box-shadow: 0 24px 80px rgba(200, 80, 180, 0.35);
    border: 1px solid var(--panel-border);
    animation: popIn .4s cubic-bezier(.34, 1.56, .64, 1);
}

.login-card h1 {
    font-size: 2.2rem;
    font-weight: 900;
    margin-bottom: 8px;
}

.login-card p {
    color: var(--text-soft);
    margin-bottom: 32px;
    font-size: 1.1rem;
}

.login-egg {
    font-size: 5rem;
    margin-bottom: 16px;
    animation: bounce 2s ease-in-out infinite;
}

#google-login-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    justify-content: center;
    background: white;
    border: 2px solid #e0d0f0;
    border-radius: 999px;
    padding: 14px 32px;
    font-size: 1.15rem;
    font-weight: 700;
    cursor: pointer;
    color: #333;
    transition: all .2s;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

#google-login-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

#google-login-btn img {
    width: 24px;
    height: 24px;
}

/* ── MAIN APP ── */
#app {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-columns: 30% 1fr;
    width: 100vw;
    height: 100vh;
    padding: 14px;
    gap: 14px;
}

#app.hidden {
    display: none;
}

/* ── SIDEBAR ── */
#sidebar {
    /* background: rgba(255, 245, 252, 0.88); */
    backdrop-filter: blur(2px);
    border: 1px solid rgba(255, 180, 220, 0.5);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 16px 16px;
    gap: 10px;
    overflow: hidden;
    position: relative;
}

#logout-btn {
    position: absolute;
    z-index: 100;
    top: 12px;
    right: 12px;
    background: rgba(255, 100, 150, 0.15);
    border: 1px solid rgba(255, 100, 150, 0.3);
    border-radius: 999px;
    padding: 6px 14px;
    font-size: .85rem;
    color: var(--pink-dark);
    cursor: pointer;
    font-weight: 700;
    transition: all .2s;
    font-family: inherit;
}

#logout-btn:hover {
    background: var(--pink-dark);
    color: white;
}

/* ── CHARACTER STAGE ── */
#char-stage {
    width: 100%;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at 50% 30%, rgba(255, 240, 170, .6), rgba(219, 245, 255, .5));
    border-radius: 16px;
    border: 1px solid rgba(255, 214, 232, 0.8);
    position: relative;
    padding: 16px 8px 8px;
    gap: 6px;
}

#char-wrap {
    position: relative;
    width: 130px;
    height: 160px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: width .5s ease, height .5s ease;
}

#char-emoji {
    font-size: 5.5rem;
    line-height: 1;
    animation: bounce 2.5s ease-in-out infinite;
    filter: drop-shadow(0 6px 10px rgba(255, 150, 200, .35));
    transition: font-size .5s cubic-bezier(.34, 1.56, .64, 1), filter .5s ease;
    position: relative;
    z-index: 2;
    user-select: none;
}

/* Glow rings per level */
#char-wrap::before {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    opacity: 0;
    transition: all .5s;
    pointer-events: none;
    z-index: 1;
}

#char-wrap.lvl2::before {
    opacity: .5;
    box-shadow: 0 0 20px 8px rgba(255, 220, 100, .5);
}

#char-wrap.lvl3::before {
    opacity: .7;
    box-shadow: 0 0 28px 12px rgba(255, 200, 80, .6);
}

#char-wrap.lvl4::before {
    opacity: .8;
    box-shadow: 0 0 32px 14px rgba(255, 180, 60, .7);
}

#char-wrap.lvl5::before {
    opacity: 1;
    box-shadow: 0 0 36px 16px rgba(100, 200, 255, .75);
}

#char-wrap.lvl6::before {
    opacity: 1;
    box-shadow: 0 0 40px 18px rgba(180, 100, 255, .7), 0 0 60px 24px rgba(255, 150, 200, .4);
    animation: rainbowGlow 3s linear infinite;
}

#char-wrap.lvl7::before {
    opacity: 1;
    box-shadow: 0 0 44px 20px rgba(255, 200, 50, .8), 0 0 70px 30px rgba(255, 140, 0, .5);
    animation: rainbowGlow 2s linear infinite;
}

#char-wrap.lvl8::before {
    opacity: 1;
    box-shadow: 0 0 50px 24px rgba(200, 220, 255, .9), 0 0 80px 36px rgba(150, 200, 255, .6);
    animation: silverPulse 1.8s ease-in-out infinite;
}

#char-wrap.lvl9::before {
    opacity: 1;
    box-shadow: 0 0 56px 28px rgba(140, 80, 255, .9), 0 0 90px 40px rgba(80, 0, 200, .5);
    animation: cosmicGlow 1.5s ease-in-out infinite;
}

#char-wrap.lvl10::before {
    opacity: 1;
    box-shadow: 0 0 60px 30px rgba(255, 120, 30, 1), 0 0 100px 50px rgba(255, 60, 0, .6);
    animation: fireGlow 1s ease-in-out infinite;
}

/* Sparkle overlay */
#sparkles {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 3;
}

.sparkle {
    position: absolute;
    font-size: 1.1rem;
    animation: twinkle 1.8s ease-in-out infinite;
}

#char-name {
    font-size: 1.2rem;
    font-weight: 800;
    text-align: center;
    color: var(--text);
}

#char-level {
    font-size: 1rem;
    color: var(--pink-dark);
    font-weight: 700;
}

/* ── EXP BAR ── */
#exp-section {
    width: 100%;
}

#exp-label {
    display: flex;
    justify-content: space-between;
    font-size: .8rem;
    color: var(--text-soft);
    margin-bottom: 4px;
}

#exp-track {
    width: 100%;
    height: 14px;
    border-radius: 999px;
    background: rgba(255, 200, 230, .6);
    border: 1px solid rgba(255, 150, 200, .5);
    overflow: hidden;
}

#exp-fill {
    height: 100%;
    width: 0%;
    border-radius: inherit;
    background: linear-gradient(90deg, #ff92cf, #ff4db5);
    transition: width .6s cubic-bezier(.4, 0, .2, 1);
}

/* ── SIDEBAR BUTTONS ── */
#sidebar-btns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    width: 100%;
}

.side-btn {
    padding: 12px 8px;
    border-radius: 14px;
    font-size: 1rem;
    font-weight: 800;
    cursor: pointer;
    border: none;
    font-family: inherit;
    transition: all .2s;
}

#btn-study {
    background: linear-gradient(135deg, #ff7ec7, #e040a0);
    color: white;
    box-shadow: 0 6px 20px rgba(224, 64, 160, .3);
}

#btn-quiz {
    background: linear-gradient(135deg, #a855f7, #7c3aed);
    color: white;
    box-shadow: 0 6px 20px rgba(124, 58, 237, .3);
}

.side-btn:hover {
    transform: translateY(-2px);
    filter: brightness(1.08);
}

/* ── MAIN PANEL ── */
#main {
    /* background:rgba(255,245,252,0.88); */
    backdrop-filter: blur(2px);
    border: 1px solid rgba(255, 180, 220, 0.5);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ── TAB BAR ── */
#tab-bar {
    display: flex;
    gap: 0;
    padding: 12px 14px 0;
    border-bottom: 2px solid rgba(255, 200, 230, .5);
    background: rgba(255, 240, 250, .6);
    flex-shrink: 0;
}

.tab-btn {
    padding: 10px 20px;
    border-radius: 12px 12px 0 0;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    border: none;
    background: transparent;
    color: var(--text-soft);
    font-family: inherit;
    transition: all .2s;
}

.tab-btn.active {
    background: white;
    color: var(--pink-dark);
    box-shadow: 0 -2px 12px rgba(255, 100, 180, .15);
}

.tab-btn:hover:not(.active) {
    background: rgba(255, 220, 240, .5);
}

/* ── CONTENT AREA ── */
#content-area {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

/* ── STUDY PANEL ── */
#study-panel {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

#study-panel.hidden,
#quiz-panel.hidden {
    display: none;
}

#study-intro {
    padding: 14px 18px 6px;
    flex-shrink: 0;
}

#study-intro h2 {
    font-size: 1.5rem;
    font-weight: 900;
}

#study-intro p {
    /* color: var(--text-soft); */
    color: #f9f9f9;
    font-size: .95rem;
}

/* ── TOPIC FILTER TABS ── */
#topic-tabs-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    flex-shrink: 0;
    border-bottom: 1px solid rgba(255, 200, 230, .35);
}

#topic-tabs-wrapper.hidden {
    display: none;
}

/* Fade gradient ở hai đầu khi có nội dung bị khuất */
#topic-tabs-wrapper::before,
#topic-tabs-wrapper::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 40px;
    z-index: 2;
    pointer-events: none;
    opacity: 0;
    transition: opacity .2s;
}

#topic-tabs-wrapper::before {
    left: 36px;
    background: linear-gradient(to right, rgba(255, 245, 252, 0.95), transparent);
    border-radius: 20px 0px 0px 20px;
}

#topic-tabs-wrapper::after {
    right: 36px;
    background: linear-gradient(to left, rgba(255, 245, 252, 0.95), transparent);
    border-radius: 0px 20px 20px 0px;
}

#topic-tabs-wrapper.can-scroll-left::before {
    opacity: 1;
}

#topic-tabs-wrapper.can-scroll-right::after {
    opacity: 1;
}

/* Nút mũi tên */
.topic-arrow {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid rgba(255, 150, 200, .5);
    background: rgba(255, 245, 252, 0.9);
    color: var(--pink-dark);
    font-size: 1.3rem;
    line-height: 1;
    font-weight: 900;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 6px 4px;
    transition: all .18s cubic-bezier(.34, 1.5, .64, 1);
    opacity: 0.35;
    pointer-events: none;
    z-index: 3;
    font-family: inherit;
    box-shadow: 0 2px 8px rgba(224, 64, 160, .15);
    user-select: none;
}

.topic-arrow.visible {
    opacity: 1;
    pointer-events: auto;
}

.topic-arrow:hover {
    background: linear-gradient(135deg, #ff7ec7, #e040a0);
    color: white;
    border-color: transparent;
    transform: scale(1.12);
    box-shadow: 0 4px 16px rgba(224, 64, 160, .4);
}

.topic-arrow:active {
    transform: scale(0.95);
}

#topic-tabs {
    display: flex;
    flex-direction: row;
    gap: 8px;
    padding: 8px 4px 10px;
    overflow-x: auto;
    flex: 1;
    min-width: 0;
    scrollbar-width: none;
    -ms-overflow-style: none;
    scroll-behavior: smooth;
}

#topic-tabs::-webkit-scrollbar {
    display: none;
}

.topic-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 16px;
    border-radius: 999px;
    font-size: .85rem;
    font-weight: 700;
    cursor: pointer;
    border: 2px solid rgba(255, 150, 200, .45);
    background: rgba(255, 245, 252, 0.55);
    color: var(--text-soft);
    font-family: inherit;
    white-space: nowrap;
    transition: all .18s cubic-bezier(.34, 1.4, .64, 1);
    flex-shrink: 0;
    user-select: none;
}

.topic-chip:hover:not(.active) {
    background: rgba(255, 220, 242, .8);
    border-color: var(--pink);
    color: var(--pink-dark);
    transform: translateY(-1px);
}

.topic-chip.active {
    background: linear-gradient(135deg, #ff7ec7, #e040a0);
    color: white;
    border-color: transparent;
    box-shadow: 0 4px 14px rgba(224, 64, 160, .35);
    transform: translateY(-1px) scale(1.04);
}

#study-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 12px 16px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#study-scroll::-webkit-scrollbar {
    width: 8px;
}

#study-scroll::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #ff92cf, #a855f7);
    border-radius: 999px;
    border: 2px solid rgba(255, 245, 252, .8);
}

#study-scroll::-webkit-scrollbar-track {
    background: rgba(255, 240, 250, .6);
    border-radius: 999px;
}

/* Lesson Card */
.lesson-card {
    background: rgba(255, 245, 252, 0.5);
    border-radius: 16px;
    border: 1px solid rgba(255, 185, 220, .6);
    padding: 16px 18px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: transform .2s, box-shadow .2s;
}

.lesson-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(255, 100, 180, .15);
}

.lesson-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 999px;
    font-size: .8rem;
    font-weight: 700;
    width: fit-content;
}

.tag-present {
    background: rgba(34, 197, 94, .15);
    color: #15803d;
}

.tag-past {
    background: rgba(245, 158, 11, .15);
    color: #b45309;
}

.tag-future {
    background: rgba(168, 85, 247, .15);
    color: #7e22ce;
}

.tag-vocab {
    background: rgba(59, 130, 246, .15);
    color: #1e40af;
}

.lesson-card h3 {
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--text);
}

.lesson-card .desc {
    font-size: .9rem;
    color: var(--text-soft);
}

.formula-box {
    background: rgba(255, 245, 252, .8);
    border: 1px dashed rgba(255, 150, 200, .6);
    border-radius: 10px;
    padding: 10px 14px;
    font-size: .9rem;
    font-weight: 600;
    color: var(--text);
    line-height: 1.5;
}

.signal-box {
    font-size: .88rem;
    color: var(--text-soft);
}

.signal-box span {
    color: #d64f9f;
    font-weight: 700;
}

.example-box {
    font-size: .9rem;
    font-style: italic;
    color: var(--text-soft);
}

.card-footer {
    display: flex;
    justify-content: flex-end;
}

.learned-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 999px;
    font-size: .88rem;
    font-weight: 700;
    cursor: pointer;
    border: 2px solid rgba(255, 150, 200, .5);
    background: white;
    color: var(--text-soft);
    font-family: inherit;
    transition: all .2s;
}

.learned-btn.done {
    background: linear-gradient(90deg, #22c55e, #16a34a);
    color: white;
    border-color: transparent;
}

.learned-btn:hover:not(.done) {
    background: rgba(255, 230, 245, .8);
    border-color: var(--pink);
}

/* ── QUIZ PANEL ── */
#quiz-panel {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    padding: 14px 16px;
    gap: 12px;
    background: rgba(255, 245, 252, 0.3);
}

#quiz-panel::-webkit-scrollbar {
    width: 8px;
}

#quiz-panel::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #a855f7, #7c3aed);
    border-radius: 999px;
    border: 2px solid rgba(255, 245, 252, .8);
}

#quiz-panel::-webkit-scrollbar-track {
    background: rgba(255, 240, 250, .6);
    border-radius: 999px;
}

#quiz-no-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    color: var(--text-soft);
    text-align: center;
}

#quiz-no-content .big-emoji {
    font-size: 4rem;
}

#quiz-no-content p {
    font-size: 1.05rem;
    max-width: 320px;
}

#quiz-no-content button {
    padding: 12px 28px;
    border-radius: 999px;
    background: linear-gradient(90deg, #ff7ec7, #e040a0);
    color: white;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 700;
    font-family: inherit;
}

#quiz-meta-bar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
    flex-shrink: 0;
}

.meta-pill {
    padding: 5px 14px;
    border-radius: 999px;
    font-size: .85rem;
    font-weight: 700;
    background: white;
    border: 1px solid rgba(255, 180, 220, .6);
    color: var(--text-soft);
}

#quiz-question-text {
    font-size: 1.35rem;
    font-weight: 800;
    line-height: 1.4;
    color: var(--text);
    flex-shrink: 0;
}

#quiz-answers {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    flex-shrink: 0;
}

.ans-btn {
    padding: 14px 16px;
    border-radius: 14px;
    text-align: left;
    border: 2px solid rgba(255, 180, 220, .6);
    background: white;
    color: var(--text);
    font-size: .95rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: all .2s;
    min-height: 60px;
}

.ans-btn:hover:not(:disabled) {
    border-color: var(--pink);
    background: rgba(255, 230, 245, .8);
    transform: translateY(-1px);
}

.ans-btn.correct {
    background: #dcfce7;
    border-color: #22c55e;
    color: #15803d;
}

.ans-btn.wrong {
    background: #fee2e2;
    border-color: #ef4444;
    color: #991b1b;
}

.ans-btn:disabled {
    cursor: default;
}

#quiz-feedback {
    border-radius: 14px;
    padding: 14px 16px;
    background: rgba(255, 245, 252, .9);
    border: 1px solid rgba(255, 180, 220, .5);
    flex-shrink: 0;
    animation: quizFadeUp .3s cubic-bezier(.34, 1.3, .64, 1) both;
}

#quiz-feedback.hidden {
    display: none;
}

@keyframes quizFadeUp {
    from {
        opacity: 0;
        transform: translateY(10px) scale(.97);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

#feedback-title {
    font-size: 1.1rem;
    font-weight: 900;
    display: block;
    margin-bottom: 6px;
}

#feedback-title.ok {
    color: #15803d;
}

#feedback-title.fail {
    color: #991b1b;
}

#feedback-body {
    font-size: .9rem;
    color: var(--text-soft);
}

/* Container chứa cả 2 nút */
#quiz-control-group {
    display: flex;
    align-items: center;
    gap: 0;
    /* Dính liền nhau */
    margin-top: 10px;
    animation: nextBtnPop .35s cubic-bezier(.34, 1.5, .64, 1) both;
}

#quiz-control-group.hidden {
    display: none;
}

/* Nút bên trái: Đếm ngược & Dừng */
#stop-countdown-btn {
    padding: 10px 15px;
    border-radius: 999px 0 0 999px;
    background: var(--pink-soft);
    /* Chuyển sang màu hồng nhạt thay vì trắng */
    border: 2px solid var(--pink);
    border-right: 1px solid rgba(255, 98, 187, 0.3);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 60px;
    transition: all 0.2s;
}

#stop-countdown-btn .ring-bg {
    stroke: rgba(255, 98, 187, 0.2);
    /* Màu nền vòng mờ hơn */
}

#stop-countdown-btn .ring-fill {
    stroke: var(--pink-dark);
    /* Vòng chạy màu hồng đậm cho rõ nét */
}

#stop-countdown-btn .ring-num {
    color: var(--pink-dark);
    /* Số đếm màu hồng đậm */
}

/* Khi đã bấm dừng */
#stop-countdown-btn.paused {
    background: #ffd6eb;
    /* Hồng đậm hơn một chút khi dừng */
}

/* Nút bên phải: Đi tiếp */
#next-step-btn {
    padding: 10px 20px;
    border-radius: 0 999px 999px 0;
    /* Bo góc phải */
    background: linear-gradient(90deg, #ff7ec7, #e040a0);
    color: white;
    border: 2px solid #ff62bb;
    border-left: none;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 800;
    font-family: inherit;
    transition: all 0.2s;
}

#stop-countdown-btn:hover {
    background: #fff0f9;
}

#next-step-btn:hover {
    filter: brightness(1.1);
    transform: translateX(2px);
}

#stop-countdown-btn.paused .ring-fill {
    stroke: #7a5876;
}

#next-btn {
    align-self: flex-start;
    padding: 10px 22px 10px 14px;
    border-radius: 999px;
    background: linear-gradient(90deg, #ff7ec7, #e040a0);
    color: white;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 800;
    font-family: inherit;
    transition: all .2s;
    display: flex;
    align-items: center;
    gap: 10px;
}

#next-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(224, 64, 160, .3);
}

#next-btn.hidden {
    display: none;
}

/* Pop-in animation for next-btn when it appears */
#next-btn.pop-in {
    animation: nextBtnPop .35s cubic-bezier(.34, 1.5, .64, 1) both;
}

@keyframes nextBtnPop {
    from {
        opacity: 0;
        transform: scale(.7) translateY(6px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* Countdown ring inside next-btn */
.next-countdown-ring {
    position: relative;
    width: 28px;
    height: 28px;
    flex-shrink: 0;
}

.next-countdown-ring svg {
    transform: rotate(-90deg);
    width: 28px;
    height: 28px;
}

.next-countdown-ring .ring-bg {
    fill: none;
    stroke: rgba(255, 255, 255, 0.3);
    stroke-width: 3;
}

.next-countdown-ring .ring-fill {
    fill: none;
    stroke: white;
    stroke-width: 3;
    stroke-linecap: round;
    transition: stroke-dashoffset .95s linear;
}

/* Paused state: freeze ring + dim slightly */
/* Trạng thái khi đã tạm dừng */
#next-btn.countdown-paused .ring-fill {
    transition: none;
    stroke: #ff62bb;
}

#next-btn.countdown-paused {
    background: linear-gradient(90deg, #7a5876, #4a2040);
    opacity: 1;
}

#next-btn.countdown-paused .ring-num::after {
    content: '⏸';
    position: absolute;
    font-size: .55rem;
    bottom: 1px;
    right: 0px;
}

.next-countdown-ring .ring-num {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .8rem;
    font-weight: 900;
    color: white;
    line-height: 1;
}

/* ── OVERLAYS ── */
#levelup-overlay,
#leveldown-overlay {
    position: fixed;
    inset: 0;
    z-index: 500;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

#levelup-overlay.hidden,
#leveldown-overlay.hidden {
    display: none;
}

#levelup-overlay {
    background: rgba(255, 240, 200, .35);
    backdrop-filter: blur(4px);
}

#leveldown-overlay {
    background: rgba(60, 10, 100, .45);
    backdrop-filter: blur(4px);
}

.overlay-box {
    background: white;
    border-radius: 28px;
    padding: 40px 48px;
    text-align: center;
    box-shadow: 0 24px 80px rgba(0, 0, 0, .25);
    pointer-events: auto;
    animation: popIn .5s cubic-bezier(.34, 1.56, .64, 1);
}

.overlay-emoji {
    font-size: 5rem;
    margin-bottom: 12px;
    display: block;
}

.overlay-title {
    font-size: 2rem;
    font-weight: 900;
    margin-bottom: 8px;
}

.overlay-sub {
    font-size: 1.1rem;
    color: var(--text-soft);
}

#levelup-overlay .overlay-title {
    color: #d97706;
}

#leveldown-overlay .overlay-title {
    color: #7c3aed;
}

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

/* ── FLOATING EMOJIS ── */
#floating-emojis {
    position: fixed;
    left: 0;
    right: 0;
    bottom: -5px;
    /* Chìm nhẹ để không lộ chân emoji */
    height: 80px;
    /* Tăng nhẹ chiều cao để hoa có không gian đung đưa */
    z-index: 9999;
    /* Đưa lên trên cùng để bé thấy hoa lá luôn hiện diện */
    pointer-events: none;
    /* Quan trọng: để không ngăn cản việc bấm nút */
    display: flex;
    justify-content: space-around;
    align-items: flex-end;
    padding: 0 10px;
    overflow: visible;
    /* Cho phép hoa cao hơn 80px vẫn hiển thị được */
}

.garden-item {
    display: inline-block;
    transform-origin: bottom center;
    animation: sway var(--dur) ease-in-out infinite;
    /* Thêm dòng này để chuyển động mượt hơn trên một số trình duyệt */
    backface-visibility: hidden;
    will-change: transform;
}

@keyframes sway {

    0%,
    100% {
        transform: rotate(-3deg) translateY(0);
    }

    50% {
        transform: rotate(5deg) translateY(-2px);
    }
}

/* ── MUSIC TOGGLE BUTTON ── */
#music-toggle {
    position: fixed;
    bottom: 16px;
    right: 16px;
    z-index: 300;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.25);
    border: 2px solid rgba(255, 180, 220, 0.7);
    backdrop-filter: blur(8px);
    cursor: pointer;
    font-size: 1.3rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .2s;
    box-shadow: 0 4px 12px rgba(200, 80, 180, .2);
}

#music-toggle:hover {
    transform: scale(1.1);
    background: rgba(255, 255, 255, 0.4);
}

/* ── QUIZ LEVEL PROGRESS ── */
#quiz-level-bar {
    background: rgba(255, 245, 252, 0.9);
    border: 1px solid rgba(255, 180, 220, .5);
    border-radius: 12px;
    padding: 10px 14px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

#quiz-level-bar.hidden {
    display: none;
}

.qlb-label {
    display: flex;
    justify-content: space-between;
    font-size: .8rem;
    font-weight: 700;
    color: var(--text-soft);
}

.qlb-track {
    height: 10px;
    border-radius: 999px;
    background: rgba(200, 180, 220, .35);
    overflow: hidden;
}

.qlb-fill {
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #a855f7, #f59e0b);
    transition: width .5s cubic-bezier(.4, 0, .2, 1);
}

/* ── AUDIO PLAY BUTTON ── */
.audio-play-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #a855f7, #7c3aed);
    color: white;
    font-size: 1rem;
    cursor: pointer;
    flex-shrink: 0;
    transition: all .2s;
    box-shadow: 0 3px 10px rgba(124, 58, 237, .35);
    line-height: 1;
    padding: 0;
}

.audio-play-btn:hover {
    transform: scale(1.15);
    box-shadow: 0 5px 16px rgba(124, 58, 237, .5);
}

.audio-play-btn:active {
    transform: scale(0.95);
}

.audio-play-btn.playing {
    background: linear-gradient(135deg, #ff7ec7, #e040a0);
    animation: audioPulse .6s ease-in-out infinite;
}

@keyframes audioPulse {

    0%,
    100% {
        box-shadow: 0 3px 10px rgba(224, 64, 160, .35);
    }

    50% {
        box-shadow: 0 3px 20px rgba(224, 64, 160, .7);
    }
}


/* ── ORBITAL CHARACTER EFFECTS ── */
@keyframes orbitCW {
    to {
        transform: rotate(360deg);
    }
}

@keyframes orbitCCW {
    to {
        transform: rotate(-360deg);
    }
}

@keyframes orbitPulse {

    0%,
    100% {
        opacity: .65;
    }

    50% {
        opacity: 1;
    }
}

@keyframes streakSpin {
    from {
        transform: translate(-50%, -50%) rotate(0deg);
    }

    to {
        transform: translate(-50%, -50%) rotate(360deg);
    }
}

@keyframes streakSpinRev {
    from {
        transform: translate(-50%, -50%) rotate(0deg);
    }

    to {
        transform: translate(-50%, -50%) rotate(-360deg);
    }
}

.orbit-streak {
    position: absolute;
    top: 50%;
    left: 50%;
    border-radius: 999px;
    pointer-events: none;
    z-index: 3;
}

/* ── ANIMATIONS ── */
@keyframes bounce {

    0%,
    100% {
        transform: translateY(0) rotate(-2deg);
    }

    50% {
        transform: translateY(-10px) rotate(2deg);
    }
}

@keyframes twinkle {

    0%,
    100% {
        transform: scale(.8);
        opacity: .4;
    }

    50% {
        transform: scale(1.2);
        opacity: 1;
    }
}

@keyframes popIn {
    from {
        transform: scale(.5);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes rainbowGlow {
    0% {
        filter: hue-rotate(0deg);
    }

    100% {
        filter: hue-rotate(360deg);
    }
}

@keyframes silverPulse {

    0%,
    100% {
        box-shadow: 0 0 50px 24px rgba(200, 220, 255, .9), 0 0 80px 36px rgba(150, 200, 255, .6);
    }

    50% {
        box-shadow: 0 0 70px 34px rgba(220, 240, 255, 1), 0 0 110px 50px rgba(180, 220, 255, .8);
    }
}

@keyframes cosmicGlow {

    0%,
    100% {
        box-shadow: 0 0 56px 28px rgba(140, 80, 255, .9), 0 0 90px 40px rgba(80, 0, 200, .5);
    }

    50% {
        box-shadow: 0 0 80px 40px rgba(180, 100, 255, 1), 0 0 130px 60px rgba(120, 0, 255, .7);
    }
}

@keyframes fireGlow {

    0%,
    100% {
        box-shadow: 0 0 60px 30px rgba(255, 120, 30, 1), 0 0 100px 50px rgba(255, 60, 0, .6);
    }

    50% {
        box-shadow: 0 0 90px 45px rgba(255, 160, 50, 1), 0 0 140px 70px rgba(255, 100, 0, .8);
    }
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    20%,
    60% {
        transform: translateX(-10px);
    }

    40%,
    80% {
        transform: translateX(10px);
    }
}

@keyframes shimmer {
    0% {
        background-position: -200% center;
    }

    100% {
        background-position: 200% center;
    }
}

/* Hiệu ứng sóng âm nhấp nhô */
.listening-wave {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 4px;
    height: 30px;
    margin-top: 10px;
}

.listening-wave .bar {
    width: 4px;
    height: 8px;
    background: var(--pink);
    border-radius: 999px;
    animation: wave-grow 1s ease-in-out infinite;
}

.listening-wave .bar:nth-child(2) {
    animation-delay: 0.1s;
    background: var(--purple);
}

.listening-wave .bar:nth-child(3) {
    animation-delay: 0.2s;
    background: var(--pink-dark);
}

.listening-wave .bar:nth-child(4) {
    animation-delay: 0.3s;
    background: var(--purple);
}

.listening-wave .bar:nth-child(5) {
    animation-delay: 0.4s;
    background: var(--pink);
}

@keyframes wave-grow {

    0%,
    100% {
        height: 8px;
    }

    50% {
        height: 24px;
    }
}

/* ── Micro listening indicator trong quiz ── */
#quiz-voice-indicator {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 10px 14px;
    border-radius: 16px;
    background: linear-gradient(135deg, rgba(255, 100, 200, 0.07), rgba(140, 80, 255, 0.07));
    border: 1.5px solid rgba(255, 100, 200, 0.18);
    margin-top: 10px;
    box-sizing: border-box;
    overflow: hidden;
    min-height: 100px;
    height: 100px;
    /* Ẩn nhưng vẫn giữ chỗ trong layout */
    visibility: hidden;
}

/* Khi active: hiện lên sáng rõ */
#quiz-voice-indicator.active {
    visibility: visible;
    background: linear-gradient(135deg, rgba(255, 100, 200, 0.15), rgba(140, 80, 255, 0.15));
    border-color: rgba(255, 100, 200, 0.5);
    animation: micPulse 1.5s ease-in-out infinite;
}

/* Hàng trên: mic icon + wave + label */
.voice-indicator-top {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    flex-shrink: 0;
}

#quiz-voice-indicator .mic-icon {
    font-size: 1.4rem;
    animation: micBounce 0.8s ease-in-out infinite alternate;
    /* Dừng khi không active */
    animation-play-state: paused;
}

#quiz-voice-indicator.active .mic-icon {
    animation-play-state: running;
}

#quiz-voice-indicator .mic-label {
    font-size: 0.88rem;
    font-weight: 800;
    color: var(--pink-dark);
    letter-spacing: 0.5px;
}

#quiz-voice-indicator .mic-wave {
    display: flex;
    align-items: center;
    gap: 3px;
}

#quiz-voice-indicator .mic-wave span {
    display: inline-block;
    width: 3px;
    border-radius: 999px;
    background: var(--purple);
}

#quiz-voice-indicator .mic-wave span:nth-child(1) {
    height: 8px;
    animation: wave-grow 0.9s ease-in-out 0.0s infinite;
    animation-play-state: paused;
    background: var(--pink);
}

#quiz-voice-indicator .mic-wave span:nth-child(2) {
    height: 14px;
    animation: wave-grow 0.9s ease-in-out 0.1s infinite;
    animation-play-state: paused;
    background: var(--purple);
}

#quiz-voice-indicator .mic-wave span:nth-child(3) {
    height: 20px;
    animation: wave-grow 0.9s ease-in-out 0.2s infinite;
    animation-play-state: paused;
    background: var(--pink-dark);
}

#quiz-voice-indicator .mic-wave span:nth-child(4) {
    height: 14px;
    animation: wave-grow 0.9s ease-in-out 0.3s infinite;
    animation-play-state: paused;
    background: var(--purple);
}

#quiz-voice-indicator .mic-wave span:nth-child(5) {
    height: 8px;
    animation: wave-grow 0.9s ease-in-out 0.4s infinite;
    animation-play-state: paused;
    background: var(--pink);
}

/* Khi active: chạy animation sóng âm */
#quiz-voice-indicator.active .mic-wave span {
    animation-play-state: running;
}

@keyframes micPulse {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(255, 100, 200, 0.3);
    }

    50% {
        box-shadow: 0 0 0 8px rgba(255, 100, 200, 0);
    }
}

@keyframes micBounce {
    from {
        transform: scale(1);
    }

    to {
        transform: scale(1.2);
    }
}

/* Ô transcript thời gian thực khi đang lắng nghe */
#interim-transcript {
    display: block;
    padding: 6px 10px;
    border-radius: 10px;
    background: rgb(155 98 98 / 55%);
    border: 1px dashed rgba(255, 100, 200, 0.35);
    font-size: 0.88rem;
    color: rgba(255, 255, 255, 0.75);
    font-style: italic;
    min-height: 28px;
    line-height: 1.4;
    letter-spacing: 0.3px;
    transition: opacity 0.15s;
    text-align: left;
    word-break: break-word;
    width: 100%;
    box-sizing: border-box;
    flex-shrink: 0;
}

#interim-transcript.active {
    display: block;
}

#interim-transcript .interim-text {
    color: rgba(255, 200, 240, 0.85);
}

#interim-transcript .interim-cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background: var(--pink);
    vertical-align: middle;
    margin-left: 2px;
    animation: cursorBlink 0.7s step-end infinite;
}

@keyframes cursorBlink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0;
    }
}

/* Highlight answer labels A/B/C/D */
.ans-btn .ans-label {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.25);
    font-weight: 900;
    font-size: 0.85rem;
    margin-right: 8px;
    flex-shrink: 0;
    transition: background 0.2s;
}

.ans-btn {
    display: flex;
    align-items: center;
}

#speech-result {
    width: 100%;
    height: 80px;
    box-sizing: border-box;
    padding: 4px 10px;
    margin: 0;
    text-align: center;
    flex-shrink: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Xóa .voice-status-container – đã gộp vào quiz-voice-indicator */

/* ── RESPONSIVE (portrait / mobile) ── */
@media(max-width:700px), (orientation:portrait) {

    html,
    body {
        overflow-y: auto;
    }

    #app {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
        height: auto;
        min-height: 100vh;
    }

    #sidebar {
        min-height: auto;
        /* Cho phép chiều cao co dãn theo nội dung */
        flex-direction: column;
        /* Đổi thành cột để các phần tử xếp chồng lên nhau */
        align-items: center;
        /* Căn giữa tất cả các thành phần theo chiều ngang */
        justify-content: center;
        /* Căn giữa theo chiều dọc nếu cần */
        gap: 12px;
        padding: 20px 14px;
    }

    #char-stage {
        width: 100%;
        /* Chiếm hết chiều ngang để dễ căn giữa nhân vật */
        max-width: 280px;
        /* Giới hạn độ rộng tối đa để không quá to */
        flex: 0 0 auto;
        /* Không cho phép co dãn linh hoạt quá mức */
        height: auto;
        min-height: 200px;
        margin: 0 auto;
        /* Đảm bảo stage nằm giữa sidebar */
    }

    #sidebar-right {
        width: 100%;
        /* Để thanh EXP và nút bấm chiếm hết chiều ngang */
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 10px;
    }

    #exp-section {
        width: 100%;
        /* Thanh EXP rộng ra cho dễ nhìn */
        max-width: 400px;
    }

    #main {
        min-height: 60vh;
    }

    #quiz-answers {
        grid-template-columns: 1fr;
    }
}