/* ==========================================
   GAME LAYOUT — Shared Layout cho TẤT CẢ Game
   Centered, responsive, professional design
   NO HTML changes needed — tự apply qua CSS
   ========================================== */

/* === Body: Full Page Layout === */
body {
    margin: 0;
    padding: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    background-color: #f0f2f8;
    position: relative;
    overflow-x: hidden;
    font-family: 'Nunito', sans-serif;
}

/* --- Dot Grid Pattern Overlay --- */
body::before {
    content: '';
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background-image: radial-gradient(circle, rgba(0,0,0,0.04) 1px, transparent 1px);
    background-size: 24px 24px;
    pointer-events: none;
    z-index: 0;
}

/* --- Gentle Gradient Glow (center of screen) --- */
body::after {
    content: '';
    position: fixed;
    top: 50%; left: 50%;
    width: 800px; height: 800px;
    transform: translate(-50%, -50%);
    background: radial-gradient(circle, rgba(123,97,255,0.06) 0%, rgba(255,107,139,0.04) 40%, transparent 70%);
    pointer-events: none;
    z-index: 0;
    animation: glowPulse 8s ease-in-out infinite alternate;
}

@keyframes glowPulse {
    0% { opacity: 0.6; transform: translate(-50%, -50%) scale(0.9); }
    100% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
}

/* --- Floating Blobs (via game-wrapper pseudo) --- */
.game-wrapper::before,
.game-wrapper::after {
    content: '';
    position: fixed;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.35;
    pointer-events: none;
    z-index: 0;
}

.game-wrapper::before {
    width: 350px; height: 350px;
    top: -80px; left: -120px;
    background: var(--blob-color-1, #ff9ebd);
    animation: blobFloat1 18s ease-in-out infinite alternate;
}
.game-wrapper::after {
    width: 400px; height: 400px;
    bottom: -100px; right: -150px;
    top: auto;
    background: var(--blob-color-2, #8fe3ff);
    animation: blobFloat2 22s ease-in-out infinite alternate;
}

@keyframes blobFloat1 {
    0%   { transform: translate(0, 0) rotate(0deg); }
    33%  { transform: translate(40px, 60px) rotate(20deg); }
    66%  { transform: translate(-30px, 100px) rotate(-15deg); }
    100% { transform: translate(60px, 40px) rotate(30deg); }
}
@keyframes blobFloat2 {
    0%   { transform: translate(0, 0) rotate(0deg); }
    33%  { transform: translate(-50px, -40px) rotate(-20deg); }
    66%  { transform: translate(30px, -80px) rotate(15deg); }
    100% { transform: translate(-40px, -60px) rotate(-25deg); }
}

/* --- Theme-specific blob colors + background gradients --- */
.theme-mam-non   { --blob-color-1: #ff9ebd; --blob-color-2: #ffd18c; }
.theme-tieu-hoc  { --blob-color-1: #ffcc80; --blob-color-2: #a5d6a7; }
.theme-thcs,
.theme-thcs-su,
.theme-space,
.theme-geo,
.theme-vocab,
.theme-lab,
.theme-circuit,
.theme-flags     { --blob-color-1: #90caf9; --blob-color-2: #80deea; }
.theme-bio,
.theme-thpt,
.theme-lit,
.theme-physics   { --blob-color-1: #a5d6a7; --blob-color-2: #b39ddb; }
.theme-music     { --blob-color-1: #f48fb1; --blob-color-2: #ce93d8; }
.theme-art       { --blob-color-1: #ffe082; --blob-color-2: #ffab91; }
.theme-clock     { --blob-color-1: #90caf9; --blob-color-2: #81d4fa; }
.theme-viet      { --blob-color-1: #a5d6a7; --blob-color-2: #c5e1a5; }
.theme-frac      { --blob-color-1: #ffcc80; --blob-color-2: #ffe0b2; }
.theme-thpt-eng  { --blob-color-1: #ffcc80; --blob-color-2: #ffab91; }
.theme-chem      { --blob-color-1: #9fa8da; --blob-color-2: #b39ddb; }
.theme-eng       { --blob-color-1: #b39ddb; --blob-color-2: #ce93d8; }

/* === Page Shell: wraps banner + main + footer === */
.page-shell {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    z-index: 1;
    position: relative;
}

/* === Top Banner === */
.page-banner {
    width: 100%;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    color: #fff;
    text-align: center;
    padding: 14px 20px;
    font-family: 'Baloo 2', cursive;
    font-size: 1.1rem;
    font-weight: 800;
    letter-spacing: 2px;
    text-transform: uppercase;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    position: relative;
    overflow: hidden;
    z-index: 10;
}
.page-banner::before {
    content: '';
    position: absolute;
    top: 0; left: -100%;
    width: 200%; height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.06), transparent);
    animation: bannerShine 4s ease-in-out infinite;
}
@keyframes bannerShine {
    0% { transform: translateX(-50%); }
    100% { transform: translateX(50%); }
}
.page-banner .banner-icon {
    margin: 0 8px;
    font-size: 1.2rem;
}

/* === Main Layout: 3 columns === */
.page-main {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    gap: 16px;
    width: 100%;
    max-width: 1280px;
    padding: 20px 16px;
    box-sizing: border-box;
    flex: 1;
}

/* === Sidebars === */
.sidebar {
    width: 220px;
    flex-shrink: 0;
    position: sticky;
    top: 20px;
}
.sidebar-card {
    background: rgba(255,255,255,0.85);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid rgba(255,255,255,0.7);
    border-radius: 18px;
    padding: 18px 16px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.06);
}
.sidebar-card h3 {
    font-family: 'Baloo 2', cursive;
    font-size: 0.95rem;
    color: #333;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 2px dashed rgba(0,0,0,0.06);
    text-align: center;
}
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 12px;
    margin-bottom: 6px;
    border-radius: 12px;
    font-size: 0.82rem;
    font-weight: 700;
    color: #444;
    text-decoration: none;
    transition: all 0.2s;
    background: rgba(255,255,255,0.5);
    border: 1px solid rgba(0,0,0,0.04);
}
.sidebar-link:hover {
    background: #fff;
    color: #1a73e8;
    transform: translateX(4px);
    box-shadow: 0 2px 10px rgba(26,115,232,0.12);
}
.sidebar-link .link-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
}

/* Right sidebar CTA buttons */
.sidebar-cta {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.cta-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 11px 14px;
    border-radius: 14px;
    font-size: 0.82rem;
    font-weight: 800;
    color: #fff;
    text-decoration: none;
    transition: all 0.25s;
    border: none;
    cursor: pointer;
    box-shadow: 0 3px 0 rgba(0,0,0,0.15);
}
.cta-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0,0,0,0.15);
}
.cta-btn:active {
    transform: translateY(3px);
    box-shadow: 0 0 0;
}
.cta-btn .cta-icon {
    font-size: 1.2rem;
}
.cta-btn.cta-zalo {
    background: linear-gradient(135deg, #0068ff, #0099ff);
    box-shadow: 0 3px 0 #0050cc;
}
.cta-btn.cta-teacher {
    background: linear-gradient(135deg, #ff6b35, #ff8a50);
    box-shadow: 0 3px 0 #d45520;
}
.cta-btn.cta-software {
    background: linear-gradient(135deg, #00b894, #00cec9);
    box-shadow: 0 3px 0 #009680;
}

/* === Game Wrapper: centered container === */
.game-wrapper {
    width: 100% !important;
    max-width: 580px !important;
    margin: 0 auto !important;
    padding: 16px 16px 24px;
    display: flex !important;
    flex-direction: column !important;
    position: relative;
    box-sizing: border-box;
    height: auto !important;
    overflow: visible !important;
    z-index: 1;
    flex: 1;
}

/* === Game Container wrapper (some games have this) === */
.game-container {
    display: contents;
}

/* === Back Button: glassmorphism pill === */
.back-btn,
.back-btn.header-element {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    background: rgba(255,255,255,0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(0,0,0,0.06);
    border-radius: 12px;
    font-family: 'Nunito', sans-serif;
    font-weight: 700;
    font-size: 0.9rem;
    color: #666;
    text-decoration: none;
    transition: all 0.25s;
    box-shadow: 0 2px 10px rgba(0,0,0,0.06);
    align-self: flex-start;
    margin-bottom: 12px;
    position: relative;
    z-index: 10;
}
.back-btn:hover,
.back-btn.header-element:hover {
    background: #fff;
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.1);
    color: #333;
}
.back-btn .icon { font-size: 1rem; }

/* === Game Header Card: glassmorphism === */
.game-header,
.game-header.header-element {
    background: rgba(255,255,255,0.82) !important;
    backdrop-filter: blur(14px) !important;
    -webkit-backdrop-filter: blur(14px) !important;
    border: 1px solid rgba(255,255,255,0.7) !important;
    border-radius: 20px !important;
    padding: 20px 24px 18px !important;
    text-align: center !important;
    box-shadow: 0 4px 24px rgba(0,0,0,0.06) !important;
    margin-bottom: 16px !important;
}
.game-header h1 {
    font-family: 'Baloo 2', cursive;
    font-size: 1.65rem;
    margin-bottom: 4px;
    line-height: 1.25;
}
.game-header > p {
    font-family: 'Nunito', sans-serif;
    font-size: 0.88rem;
    color: #888;
    font-weight: 600;
    margin-bottom: 12px;
    line-height: 1.4;
}

/* === Score Board Row === */
.score-row {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}
.score-board {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 16px;
    background: #FFF3E0;
    color: #E65100;
    border-radius: 99px;
    font-family: 'Baloo 2', cursive;
    font-size: 0.9rem;
    font-weight: 700;
    box-shadow: 0 3px 0 rgba(255,179,71,0.4);
    border: 1px solid rgba(255,179,71,0.25);
    white-space: nowrap;
}
/* Stats container (batch 1 games dùng class này) */
.stats-container {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

.score-board .pop-text {
    font-size: 1.1rem;
    display: inline-block;
}
.score-board .pop-text.pop,
.pop-text.pop {
    animation: popScore 0.3s ease;
}
@keyframes popScore {
    0% { transform: scale(1); }
    50% { transform: scale(1.4); }
    100% { transform: scale(1); }
}

/* === Game Area Card === */
.game-area {
    background: rgba(255,255,255,0.78) !important;
    backdrop-filter: blur(12px) !important;
    -webkit-backdrop-filter: blur(12px) !important;
    border: 1px solid rgba(255,255,255,0.5) !important;
    border-radius: 20px !important;
    padding: 20px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.05) !important;
    flex: 1;
}

/* === Canvas Elements — auto-fit container === */
.game-area canvas {
    display: block;
    margin: 0 auto;
    max-width: 100%;
    height: auto;
    border-radius: 14px;
}

/* === Common Quiz Option Grids — override inline max-width === */
.quiz-options,
.flag-options,
.bio-options,
.elem-options,
.graph-options,
.circuit-options,
.sys-options,
.lit-options,
.match-options,
.lab-options,
.clock-options,
.punct-options,
.flag-grid {
    max-width: 100% !important;
    margin-left: auto !important;
    margin-right: auto !important;
    padding: 0 !important;
}

/* === Override game-specific styles that set max-width on inner cards === */
.quiz-card,
.word-card,
.equation-board,
.equation-display,
.cross-display,
.element-card,
.circuit-card,
.sys-display,
.lit-card,
.sentence-card,
.lab-mix {
    max-width: 100% !important;
    margin-left: auto !important;
    margin-right: auto !important;
}

/* === Coefficient / Asteroid Zones === */
.coefficient-zone,
.asteroids-zone,
.color-palette,
.piano-keys,
.frac-grid,
.sorted-bar {
    max-width: 100% !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
}

/* === Controls Panel (Physics game) === */
.controls-panel {
    max-width: 100% !important;
    padding: 0 !important;
}

/* === Footer === */
.page-footer {
    width: 100%;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    color: rgba(255,255,255,0.75);
    text-align: center;
    padding: 28px 20px;
    font-size: 0.85rem;
    line-height: 1.8;
    z-index: 10;
}
.page-footer .footer-title {
    font-family: 'Baloo 2', cursive;
    font-size: 1rem;
    font-weight: 700;
    color: #fff;
    margin-bottom: 4px;
}
.page-footer .footer-author {
    color: rgba(255,255,255,0.6);
    font-weight: 600;
    margin-bottom: 10px;
}
.page-footer .footer-links {
    display: flex;
    justify-content: center;
    gap: 16px;
    flex-wrap: wrap;
}
.page-footer .footer-links a {
    color: rgba(255,255,255,0.7);
    text-decoration: none;
    font-weight: 700;
    font-size: 0.82rem;
    transition: color 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.page-footer .footer-links a:hover {
    color: #fff;
}

/* ==========================================
   SHARED GAME COMPONENTS (Batch 3-4 Games)
   question-area, choices-grid, choice-btn
   ========================================== */

/* === Question Area Card === */
.question-area {
    text-align: center;
    padding: 18px 20px;
    margin-bottom: 14px;
    background: rgba(255,255,255,0.92);
    border-radius: 16px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.04);
    border: 1px solid rgba(0,0,0,0.04);
}
.q-text {
    font-family: 'Nunito', sans-serif;
    font-size: 1.05rem;
    font-weight: 700;
    color: #333;
    line-height: 1.6;
}
.q-emoji {
    font-size: 2.8rem;
    margin-bottom: 6px;
    line-height: 1.2;
}
.q-sub {
    font-size: 0.82rem;
    color: #999;
    margin-top: 6px;
    font-weight: 600;
}

/* === Choices Grid: auto-responsive === */
.choices-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

/* === Choice Button === */
.choice-btn {
    padding: 14px 12px;
    border: 2px solid rgba(0,0,0,0.08);
    border-radius: 14px;
    background: rgba(255,255,255,0.9);
    font-family: 'Nunito', sans-serif;
    font-size: 0.95rem;
    font-weight: 700;
    color: #333;
    cursor: pointer;
    transition: all 0.15s ease;
    box-shadow: 0 3px 0 rgba(0,0,0,0.06);
    text-align: center;
    word-break: break-word;
    line-height: 1.4;
}
.choice-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 14px rgba(0,0,0,0.08);
    border-color: rgba(0,0,0,0.12);
    background: #fff;
}
.choice-btn:active {
    transform: translateY(2px);
    box-shadow: 0 1px 0 rgba(0,0,0,0.06);
}
.choice-btn.correct {
    background: #e8f5e9 !important;
    border-color: #4caf50 !important;
    color: #2e7d32 !important;
    animation: bounceCorrect 0.4s ease;
    pointer-events: none;
    box-shadow: 0 3px 0 rgba(76,175,80,0.3);
}
.choice-btn.wrong {
    background: #ffebee !important;
    border-color: #f44336 !important;
    color: #c62828 !important;
    animation: shakeWrong 0.4s ease;
}
.choice-btn.reveal-correct {
    background: #e8f5e9 !important;
    border-color: #4caf50 !important;
    color: #2e7d32 !important;
    box-shadow: 0 0 0 3px rgba(76,175,80,0.2);
    pointer-events: none;
}

@keyframes bounceCorrect {
    0% { transform: scale(0.9); }
    50% { transform: scale(1.08); }
    100% { transform: scale(1); }
}
@keyframes shakeWrong {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}

/* === Answer Explanation Toast === */
.answer-explanation {
    margin-top: 10px;
    padding: 12px 16px;
    background: linear-gradient(135deg, #fff3e0, #fff8e1);
    border: 2px solid #ffb74d;
    border-radius: 12px;
    font-family: 'Nunito', sans-serif;
    font-size: 0.88rem;
    font-weight: 700;
    color: #e65100;
    text-align: center;
    animation: slideUpFade 0.35s ease;
    box-shadow: 0 2px 10px rgba(255,183,77,0.2);
    line-height: 1.5;
}
.answer-explanation .explain-icon {
    font-size: 1.1rem;
    margin-right: 4px;
}

@keyframes slideUpFade {
    0% { opacity: 0; transform: translateY(10px); }
    100% { opacity: 1; transform: translateY(0); }
}

/* ==========================================
   RESPONSIVE BREAKPOINTS
   ========================================== */

/* Desktop: 3-column layout */
@media (min-width: 1100px) {
    .page-banner { font-size: 1.25rem; padding: 16px 20px; }
    .page-main { gap: 20px; padding: 24px 24px; }
    .sidebar { width: 230px; }
    .game-wrapper {
        max-width: 600px !important;
        padding: 20px 20px 32px;
    }
    .game-header, .game-header.header-element {
        padding: 24px 32px 20px;
        border-radius: 24px;
    }
    .game-header h1 { font-size: 1.9rem; }
    .game-area { padding: 28px; border-radius: 24px; }
}

/* Tablet: sidebars below game as 2-col row */
@media (max-width: 1099px) {
    .page-main {
        flex-direction: column;
        align-items: center;
    }
    .sidebar {
        width: 100%;
        max-width: 580px;
        position: static;
    }
    .sidebar-card {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        align-items: center;
    }
    .sidebar-card h3 {
        width: 100%;
        margin-bottom: 6px;
        padding-bottom: 6px;
    }
    .sidebar-link {
        flex: 1;
        min-width: 140px;
        margin-bottom: 0;
        justify-content: center;
        text-align: center;
    }
    .sidebar-cta {
        flex-direction: row;
        flex-wrap: wrap;
    }
    .cta-btn {
        flex: 1;
        min-width: 140px;
        justify-content: center;
        text-align: center;
    }
    /* Reorder: left-sidebar goes below game */
    .page-main { display: flex; flex-direction: column; }
    .sidebar-left { order: 2; }
    .game-wrapper { order: 1; }
    .sidebar-right { order: 3; }
}

/* Tablet mid */
@media (min-width: 768px) and (max-width: 1099px) {
    .game-wrapper {
        max-width: 600px !important;
        padding: 20px 20px 32px;
    }
    .game-header, .game-header.header-element {
        padding: 22px 28px 18px;
        border-radius: 22px;
    }
    .game-header h1 { font-size: 1.8rem; }
    .game-area { padding: 24px; border-radius: 22px; }
    .score-board { font-size: 0.95rem; padding: 7px 18px; }
}

/* Small phones */
@media (max-width: 500px) {
    .page-banner { font-size: 0.8rem; padding: 10px 12px; letter-spacing: 1px; }
    .game-wrapper { padding: 12px 10px 20px; }
    .game-header, .game-header.header-element {
        padding: 14px 14px 12px;
        border-radius: 16px;
    }
    .game-header h1 { font-size: 1.35rem; }
    .game-header > p { font-size: 0.8rem; margin-bottom: 8px; }
    .score-board { padding: 4px 10px; font-size: 0.8rem; }
    .game-area { padding: 14px; border-radius: 16px; }
    .back-btn, .back-btn.header-element { padding: 6px 12px; font-size: 0.8rem; }
    .sidebar-link { font-size: 0.75rem; padding: 7px 10px; }
    .cta-btn { font-size: 0.75rem; padding: 9px 10px; }
    .page-footer { padding: 20px 14px; font-size: 0.78rem; }
    .page-footer .footer-links { gap: 10px; }

    /* Batch 3-4 game components */
    .question-area { padding: 14px 12px; }
    .q-text { font-size: 0.95rem; }
    .q-emoji { font-size: 2.2rem; }
    .choices-grid { grid-template-columns: 1fr !important; gap: 8px; }
    .choice-btn { padding: 12px 10px; font-size: 0.88rem; border-radius: 12px; }
    .answer-explanation { font-size: 0.82rem; padding: 10px 12px; }
}

/* Medium phones — auto 1-col when items are long */
@media (max-width: 767px) and (min-width: 501px) {
    .choices-grid { gap: 8px; }
    .choice-btn { padding: 12px; font-size: 0.9rem; }
}

