:root {
    --primary: #6366f1;
    --primary-hover: #818cf8;
    --accent: #f43f5e;
    --success: #22c55e;
    --warning: #f59e0b;
    --bg-gradient: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
    --glass-bg: rgba(0, 0, 0, 0.7);
    --glass-border: rgba(255, 255, 255, 0.2);
    --text: #f8fafc;
}

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

body {
    font-family: 'Outfit', sans-serif;
    background: var(--bg-gradient);
    color: var(--text);
    overflow: hidden;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

#game-container {
    position: relative;
    width: 95vw;
    height: 90vh;
    max-width: 1400px;
    max-height: 900px;
    background: #87CEEB;
    border-radius: 20px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    border: 1px solid var(--glass-border);
}

#game-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

#confetti-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 25;
}

.glass {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
}

#hud {
    position: absolute;
    top: 20px;
    left: 20px;
    right: 20px;
    padding: 15px 30px;
    border-radius: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 10;
    pointer-events: none;
}

.hud-item {
    font-weight: 700;
    font-size: 1.5rem;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    position: relative;
}

#score-popup {
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    margin-left: 10px;
    font-size: 1.2rem;
    font-weight: 700;
    color: #22c55e;
    opacity: 0;
    pointer-events: none;
}

#score-popup.show {
    animation: score-float 1s ease-out forwards;
}

@keyframes score-float {
    0% {
        opacity: 1;
        transform: translateY(-50%) translateX(0);
    }

    100% {
        opacity: 0;
        transform: translateY(-50%) translateX(30px) translateY(-20px);
    }
}

#strikes-popup {
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    margin-left: 10px;
    font-size: 1.2rem;
    font-weight: 700;
    color: #ef4444;
    opacity: 0;
    pointer-events: none;
}

#strikes-popup.show {
    animation: score-float 1s ease-out forwards;
}

.hud-buttons {
    display: flex;
    gap: 8px;
    pointer-events: all;
}

.hud-button {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 1.4rem;
    cursor: pointer;
    transition: background 0.2s;
}

.hud-button:hover {
    background: rgba(255, 255, 255, 0.3);
}

.hint-text {
    color: #94a3b8;
    font-size: 0.95rem;
    margin-top: 15px;
}

.overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 20;
    transition: opacity 0.3s ease, transform 0.3s ease;
    padding: 40px;
    overflow-y: auto;
}

.hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.95);
}

.active {
    opacity: 1;
    pointer-events: all;
    transform: scale(1);
}

h1 {
    font-size: 3rem;
    font-weight: 800;
    margin-bottom: 1rem;
    background: linear-gradient(to right, #818cf8, #f472b6);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-align: center;
}

.subtitle {
    font-size: 1.3rem;
    color: #a5b4fc;
    margin-bottom: 1.5rem;
}

/* Menu Buttons */
.menu-button {
    padding: 16px 45px;
    border-radius: 30px;
    border: none;
    font-size: 1.2rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    margin: 8px 0;
    min-width: 220px;
}

.menu-button.primary {
    background: linear-gradient(135deg, var(--primary), #a855f7);
    color: white;
}

.menu-button.primary:hover {
    transform: scale(1.05);
    filter: brightness(1.1);
}

.menu-button.secondary {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid var(--glass-border);
}

.menu-button.secondary:hover {
    background: rgba(255, 255, 255, 0.2);
}

.menu-button.quit {
    background: rgba(239, 68, 68, 0.3);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.5);
    margin-top: 15px;
}

.menu-button.quit:hover {
    background: rgba(239, 68, 68, 0.5);
}

.settings-section {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 16px;
    padding: 20px;
    margin: 15px 0;
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
    max-width: 450px;
}

.settings-group {
    background: rgba(255, 255, 255, 0.03);
    border-radius: 12px;
    padding: 12px 15px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.pause-settings {
    max-width: 350px;
}

.pause-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    margin: 10px 0;
}

.pause-buttons .menu-button {
    min-width: 180px;
    padding: 12px 20px;
    font-size: 1rem;
}

.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    padding: 4px 0;
    font-size: 1.05rem;
    width: 100%;
}

.settings-row span {
    font-weight: 600;
}

.sub-row {
    margin-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    padding-top: 10px;
}

.volume-row {
    padding: 8px 0 4px 0;
    width: 100%;
}

/* Premium Sliders */
.volume-slider,
.speed-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.1);
    outline: none;
    cursor: pointer;
    transition: background 0.2s;
}

.volume-slider:hover,
.speed-slider:hover {
    background: rgba(255, 255, 255, 0.15);
}

.volume-slider::-webkit-slider-thumb,
.speed-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: 3px solid rgba(255, 255, 255, 0.8);
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.4);
    transition: transform 0.2s, background 0.2s;
}

.volume-slider::-webkit-slider-thumb:hover,
.speed-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    background: var(--primary-hover);
}

.volume-slider:disabled,
.speed-slider:disabled {
    cursor: default;
    background: rgba(255, 255, 255, 0.05);
    opacity: 0.5;
}

.volume-slider:disabled::-webkit-slider-thumb,
.speed-slider:disabled::-webkit-slider-thumb {
    background: #666;
    cursor: default;
    border-color: #444;
    box-shadow: none;
}

.toggle {
    position: relative;
    width: 50px;
    height: 26px;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background-color: #475569;
    border-radius: 26px;
    transition: 0.3s;
}

.slider:before {
    content: "";
    position: absolute;
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    border-radius: 50%;
    transition: 0.3s;
}

input:checked+.slider {
    background-color: var(--success);
}

input:checked+.slider:before {
    transform: translateX(24px);
}

.track-select:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.15);
    border-color: var(--primary);
}

.track-select:disabled {
    cursor: default;
    background: rgba(255, 255, 255, 0.02);
    color: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.05);
}

.voice-select {
    max-width: 220px;
}

.track-select option {
    background: #1e1b4b;
    color: white;
}

/* Character Selection */
.character-list {
    display: flex;
    gap: 30px;
    margin: 25px 0;
    flex-wrap: wrap;
    justify-content: center;
}

.char-card {
    padding: 25px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.08);
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
}

.char-card:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: var(--primary);
    transform: translateY(-5px);
}

.char-card img {
    width: 120px;
    height: 120px;
    object-fit: contain;
    margin-bottom: 12px;
}

.char-card h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

/* Difficulty Selector */
.difficulty-list {
    display: flex;
    gap: 25px;
    margin: 25px 0;
    flex-wrap: wrap;
    justify-content: center;
}

.difficulty-card {
    padding: 25px 35px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.08);
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    min-width: 150px;
    color: white;
}

.difficulty-card:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: var(--primary);
    transform: translateY(-5px);
}

.difficulty-card[data-difficulty="easy"]:hover {
    border-color: #22c55e;
    box-shadow: 0 0 20px rgba(34, 197, 94, 0.3);
}

.difficulty-card[data-difficulty="medium"]:hover {
    border-color: #f59e0b;
    box-shadow: 0 0 20px rgba(245, 158, 11, 0.3);
}

.difficulty-card[data-difficulty="hard"]:hover {
    border-color: #ef4444;
    box-shadow: 0 0 20px rgba(239, 68, 68, 0.3);
}

.difficulty-icon {
    font-size: 3rem;
    display: block;
    margin-bottom: 10px;
}

.difficulty-card h3 {
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 5px;
}

.difficulty-card p {
    font-size: 0.9rem;
    color: #94a3b8;
}

/* Trivia Header */
.trivia-header {
    position: absolute;
    top: 20px;
    left: 20px;
    right: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Trivia Pause Button */
.trivia-pause-btn {
    background: rgba(0, 0, 0, 0.6);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    font-size: 1.3rem;
    cursor: pointer;
    transition: all 0.2s;
    color: white;
    margin-left: auto;
    /* Always stay on the right */
}

.trivia-pause-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.4);
    transform: scale(1.1);
}

/* Trivia Timer */
.trivia-timer {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(0, 0, 0, 0.6);
    padding: 12px 20px;
    border-radius: 30px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    font-size: 1.5rem;
    font-weight: 700;
}

.trivia-timer.hidden {
    display: none;
}

.timer-icon {
    font-size: 1.3rem;
}

#timer-value {
    min-width: 30px;
    text-align: center;
}

.trivia-timer.urgent {
    border-color: #ef4444;
    animation: timer-pulse 0.5s ease-in-out infinite;
    color: #fca5a5;
}

@keyframes timer-pulse {

    0%,
    100% {
        box-shadow: 0 0 10px rgba(239, 68, 68, 0.5);
    }

    50% {
        box-shadow: 0 0 25px rgba(239, 68, 68, 0.8);
    }
}

/* Tutorial */
.tutorial-content {
    display: flex;
    flex-direction: column;
    gap: 18px;
    margin: 25px 0;
    text-align: center;
}

.tutorial-item {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 18px;
    font-size: 1.2rem;
}

.key {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 45px;
    height: 45px;
    padding: 0 14px;
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    font-weight: 700;
    font-size: 1.3rem;
}

.key.wide {
    min-width: 90px;
    padding: 0 18px;
}

#tutorial-coin {
    vertical-align: middle;
}

.icon {
    font-size: 1.6rem;
}

/* Trivia Overlay */
#trivia-overlay {
    background: rgba(0, 0, 0, 0.85);
}

#question-text {
    font-size: 2rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 30px;
    color: #ffffff;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
    max-width: 700px;
    line-height: 1.5;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 15px;
}

.question-content {
    font-size: 2rem;
    text-align: center;
}

/* Inline number blocks with frame images in questions */
.question-number-block {
    display: inline-block;
    text-align: center;
    margin: 0 4px;
    vertical-align: baseline;
}

.question-frame-img {
    display: block;
    width: 100px;
    height: auto;
    border-radius: 4px;
    margin: 0 auto 2px auto;
}

.question-number {
    font-size: 2rem;
    font-weight: 700;
}

.question-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
}

.tts-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.tts-btn:hover {
    background: rgba(255, 255, 255, 0.35);
    transform: scale(1.1);
}

.question-with-image {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    text-align: center;
}

.question-image {
    width: 150px;
    height: 150px;
    object-fit: contain;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.9);
    padding: 10px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.answer-image {
    width: 60px;
    height: 60px;
    object-fit: contain;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.9);
    padding: 8px;
    margin-bottom: 8px;
}

.option-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

#options-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 18px;
}

.option-btn {
    padding: 18px 30px;
    background: rgba(255, 255, 255, 0.15);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    color: white;
    font-size: 1.3rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 80px;
}

/* Larger buttons when containing frame images */
.option-btn.has-frame-image {
    min-height: 140px;
    padding: 12px 20px;
}

.option-btn.has-frame-image .answer-number {
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.option-btn.has-frame-image .answer-frame-img {
    width: 80px;
    height: auto;
    border-radius: 6px;
    object-fit: contain;
}

.option-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    border-color: var(--primary);
    transform: scale(1.02);
}

/* Glowing Star */
.glowing-star {
    font-size: 5rem;
    animation: glow-pulse 1s ease-in-out infinite, float 2s ease-in-out infinite;
    filter: drop-shadow(0 0 20px #fbbf24) drop-shadow(0 0 40px #f59e0b);
    margin-bottom: 10px;
}

/* Victory Celebration */
#victory-celebration {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 10px;
}

#victory-celebration.hidden {
    display: none;
}

#victory-celebration.show {
    display: flex;
}

.star-pyramid {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 15px;
}

.star-row-top {
    margin-bottom: -5px;
}

.star-row-bottom {
    display: flex;
    gap: 45px;
    margin-top: -15px;
}

.victory-star {
    font-size: 4rem;
    filter: drop-shadow(0 0 15px #fbbf24) drop-shadow(0 0 30px #f59e0b);
    display: inline-block;
}

.victory-star.middle {
    font-size: 6rem;
}

.victory-star.left {
    transform: rotate(-25deg) translateY(-10px);
}

.victory-star.right {
    transform: rotate(25deg) translateY(-10px);
}

.congratulations-text {
    font-size: 2.2rem;
    font-weight: 800;
    color: #fbbf24;
    text-shadow: 0 0 10px rgba(251, 191, 36, 0.5);
    margin: 15px 0;
}

@keyframes glow-pulse {

    0%,
    100% {
        filter: drop-shadow(0 0 20px #fbbf24) drop-shadow(0 0 40px #f59e0b);
    }

    50% {
        filter: drop-shadow(0 0 30px #fcd34d) drop-shadow(0 0 60px #fbbf24);
    }
}

@keyframes float {

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

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

/* Feedback Overlays */
.great-job {
    font-size: 3.5rem;
    animation: celebrate 0.5s ease;
}

.wrong-answer {
    font-size: 3.5rem;
    background: linear-gradient(to right, #ef4444, #f97316);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: shake 0.5s ease;
}

.feedback-text {
    font-size: 1.4rem;
    margin-top: 10px;
    color: #e2e8f0;
}

@keyframes celebrate {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }
}

@keyframes shake {

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

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

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

/* Final Heart Animation */
#breaking-hearts-container,
#game-over-hearts-container {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-bottom: 5px;
}

.breaking-heart {
    font-size: 5rem;
    display: inline-block;
    animation: heart-break 1.5s ease-out forwards;
    filter: drop-shadow(0 0 20px #ef4444) drop-shadow(0 0 40px #dc2626);
}

.breaking-heart:nth-child(2) {
    animation-delay: 0.15s;
}

.breaking-heart:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes heart-break {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }

    20% {
        transform: scale(1.3);
        opacity: 1;
    }

    40% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.15);
    }

    60% {
        transform: scale(1);
    }

    70% {
        transform: scale(1.1) rotate(-5deg);
    }

    80% {
        transform: scale(1.1) rotate(5deg);
    }

    90% {
        transform: scale(1.1) rotate(-3deg);
    }

    100% {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
}

#game-over-title {
    margin-bottom: 0.2rem;
}

/* Game Over */
#name-input-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    margin: 8px 0;
}

.game-over-buttons {
    display: flex;
    gap: 15px;
    margin-top: 0px;
}

.game-over-buttons .menu-button {
    min-width: 180px;
}

#player-name {
    padding: 14px 24px;
    border-radius: 10px;
    border: 2px solid var(--glass-border);
    background: rgba(255, 255, 255, 0.1);
    color: white;
    font-size: 1.2rem;
    font-family: 'Outfit', sans-serif;
    text-align: center;
    width: 280px;
}

#player-name::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

#player-name:focus {
    outline: none;
    border-color: var(--primary);
}

/* Leaderboard */
#leaderboard-list {
    width: 100%;
    max-width: 450px;
    max-height: 350px;
    overflow-y: auto;
    margin: 25px 0;
}

.leaderboard-entry {
    display: flex;
    justify-content: space-between;
    padding: 14px 24px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    margin-bottom: 10px;
    font-size: 1.2rem;
}

.leaderboard-entry:nth-child(1) {
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.3), rgba(255, 165, 0, 0.3));
}

.leaderboard-entry:nth-child(2) {
    background: linear-gradient(135deg, rgba(192, 192, 192, 0.3), rgba(169, 169, 169, 0.3));
}

.leaderboard-entry:nth-child(3) {
    background: linear-gradient(135deg, rgba(205, 127, 50, 0.3), rgba(184, 115, 51, 0.3));
}

.rank {
    font-weight: 700;
    min-width: 35px;
}

.name {
    flex: 1;
    margin-left: 18px;
}

.score {
    font-weight: 700;
    color: var(--primary-hover);
}

/* Scrollbar */
#leaderboard-list::-webkit-scrollbar {
    width: 6px;
}

#leaderboard-list::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

#leaderboard-list::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 3px;
}

/* Phoneme Audio Player */
.phoneme-player {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    margin-bottom: 25px;
    padding: 15px 25px;
    background: rgba(99, 102, 241, 0.2);
    border: 2px solid rgba(99, 102, 241, 0.4);
    border-radius: 16px;
    transition: all 0.3s ease;
}

.phoneme-player.hidden {
    display: none;
}

.phoneme-play-btn {
    background: linear-gradient(135deg, var(--primary), #a855f7);
    border: none;
    border-radius: 30px;
    padding: 12px 24px;
    font-size: 1.1rem;
    font-weight: 600;
    color: white;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.phoneme-play-btn:hover {
    transform: scale(1.05);
    filter: brightness(1.1);
}

.phoneme-play-btn:active {
    transform: scale(0.98);
}

.phoneme-volume-control {
    display: flex;
    align-items: center;
    gap: 10px;
}

.phoneme-volume-control .volume-icon {
    font-size: 1.2rem;
}

.phoneme-volume-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100px;
    height: 6px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.2);
    outline: none;
    cursor: pointer;
}

.phoneme-volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: 2px solid rgba(255, 255, 255, 0.8);
    box-shadow: 0 0 8px rgba(99, 102, 241, 0.4);
    transition: transform 0.2s;
}

.phoneme-volume-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}