:root {
    --bg-color: #202020;
    --dialog-bg: #ffffff;
    --border-color: #404040;
    --hp-green: #4caf50;
    --hp-yellow: #ffeb3b;
    --hp-red: #f44336;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--bg-color);
    font-family: 'Press Start 2P', cursive;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    color: #333;
}

.game-container {
    width: 100vw;
    height: 100vh;
    background-color: #f8f8f8;
    border: none;
    position: relative;
    overflow: hidden;
    box-shadow: none;
}

.game-container::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url('assets/battle_bg.png');
    background-size: cover;
    background-position: center;
    z-index: 0;
    /* Background layer */
    transition: filter 0.5s;
}

.game-container>* {
    position: relative;
    z-index: 1;
    /* Ensure content is above background */
}

.game-container.infinite-mode {
    background: none;
    /* Remove gradient */
}

.game-container.infinite-mode::before {
    filter: grayscale(100%) sepia(100%) hue-rotate(-50deg) saturate(300%) contrast(1.2);
}

/* Utility - Moved to end for specificity */
.hidden {
    display: none !important;
}

#ending-overlay.hidden {
    display: none !important;
}

/* Language Button */
.lang-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 2000;
    /* Highest priority */
    font-family: 'DungGeunMo', cursive;
    background: #fff;
    color: #000;
    /* Black text */
    border: 2px solid #333;
    padding: 5px 10px;
    cursor: pointer;
    font-size: 12px;
    font-weight: bold;
    box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.2);
}

.lang-btn:hover {
    background: #eee;
}

/* Mute Button */
.mute-btn {
    position: absolute;
    bottom: 20px;
    right: 20px;
    z-index: 2000;
    font-family: 'DungGeunMo', cursive;
    background: #fff;
    color: #000;
    border: 2px solid #333;
    padding: 0;
    cursor: pointer;
    font-size: 20px;
    box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.2);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.mute-btn:hover {
    background: #eee;
}

/* ... existing styles ... */

/* Ending Statistics */
.ending-stats {
    background: rgba(0, 0, 0, 0.6);
    border: 2px solid #fff;
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 20px;
    text-align: left;
    width: 80%;
    max-width: 400px;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 14px;
    color: #fff;
    border-bottom: 1px dashed rgba(255, 255, 255, 0.3);
    padding-bottom: 4px;
}

.stat-item:last-child {
    border-bottom: none;
}

.stat-label {
    color: #ffeb3b;
}

.stat-value {
    font-weight: bold;
}

#ending-restart-btn {
    background-color: #4caf50;
    font-size: 14px;
    padding: 15px 30px;
}

/* Battle Scene */
.battle-scene {
    position: relative;
    height: calc(100vh - 200px);
    min-height: 350px;
    background-color: #87ceeb;
    /* Fallback */
}

.background-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 0;
}

/* HUDs */
.hud {
    position: absolute;
    background: rgba(255, 255, 255, 0.9);
    border: 3px solid #333;
    border-radius: 8px;
    padding: 10px;
    width: 220px;
    z-index: 10;
    box-shadow: 4px 4px 0px rgba(0, 0, 0, 0.2);
}

.enemy-hud {
    top: 20px;
    left: 20px;
}

.player-hud {
    bottom: 80px;
    right: 20px;
}

.name {
    font-size: 12px;
    margin-bottom: 5px;
    text-transform: uppercase;
}

@font-face {
    font-family: 'DungGeunMo';
    src: url('https://cdn.jsdelivr.net/gh/projectnoonnu/noonfonts_2001@1.1/DungGeunMo.woff') format('woff');
    font-weight: normal;
    font-style: normal;
}

.hp-bar-container {
    width: 100%;
    height: 10px;
    background-color: #ddd;
    border: 2px solid #333;
    border-radius: 5px;
    overflow: hidden;
}

.hp-bar-fill {
    height: 100%;
    background-color: var(--hp-green);
    width: 100%;
    transition: width 0.5s ease-out, background-color 0.3s;
}

.hp-text {
    font-size: 10px;
    text-align: right;
    margin-top: 3px;
}

/* Sprites */
.sprite-container {
    position: absolute;
    z-index: 5;
}

.enemy-sprite {
    top: 10%;
    right: 10%;
    width: 50vmin;
    max-width: 600px;
}

.enemy-sprite img {
    /* transform: scale(2); Removed for desktop */
}

.player-sprite {
    bottom: 5%;
    left: 10%;
    width: 30vmin;
    max-width: 350px;
}

img {
    width: 100%;
    image-rendering: pixelated;
}

/* Dialog Box */
.dialog-box {
    height: 200px;
    min-height: 150px;
    background-color: var(--dialog-bg);
    border-top: 4px solid #333;
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: relative;
}

.message {
    font-size: 14px;
    line-height: 1.6;
}

.controls {
    margin-top: 10px;
}

.hidden {
    display: none;
}

.problem-display {
    font-size: 14px;
    margin-bottom: 10px;
    color: #d32f2f;
}

/* Battle Controls */
.battle-controls {
    margin-top: 10px;
    width: 100%;
}

.control-layout {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.input-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.numpad-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.numpad-row {
    display: flex;
    gap: 5px;
}

.num-btn {
    flex: 1;
    padding: 8px 0;
    font-family: 'DungGeunMo', cursive;
    font-size: 16px;
    background: #f0f0f0;
    border: 2px solid #ccc;
    border-radius: 5px;
    cursor: pointer;
    transition: background 0.1s;
    color: #333;
}

.num-btn:active {
    background: #ddd;
    transform: translateY(2px);
}

.special-key {
    background-color: #2196f3;
    color: white;
    border-color: #1976d2;
    font-weight: bold;
}

.special-key:active {
    background-color: #1976d2;
}

#answer-input {
    width: 100%;
    padding: 10px;
    font-family: 'DungGeunMo', cursive;
    font-size: 16px;
    border: 2px solid #333;
    border-radius: 5px;
    text-transform: lowercase;
}

#attack-btn {
    width: 100%;
    padding: 10px;
    font-family: 'DungGeunMo', cursive;
    font-size: 16px;
    background-color: #f44336;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    box-shadow: 0 4px #d32f2f;
}

#attack-btn:active {
    box-shadow: 0 2px #d32f2f;
    transform: translateY(2px);
}

/* Mobile Responsive for Controls */
@media (max-width: 600px) {
    .control-layout {
        flex-direction: column;
    }

    .numpad-section {
        width: 100%;
    }
}

button {
    padding: 10px 20px;
    font-family: 'DungGeunMo', cursive;
    font-size: 12px;
    background-color: #333;
    color: white;
    border: none;
    cursor: pointer;
    transition: background-color 0.2s;
}

button:hover {
    background-color: #555;
}

/* Animations */
@keyframes shake {
    0% {
        transform: translate(0, 0);
    }

    25% {
        transform: translate(-5px, 0);
    }

    50% {
        transform: translate(5px, 0);
    }

    75% {
        transform: translate(-5px, 0);
    }

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

.shake {
    animation: shake 0.4s;
}

@keyframes attack-player {
    0% {
        transform: translate(0, 0);
    }

    50% {
        transform: translate(20px, -20px);
    }

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

@keyframes attack-enemy {
    0% {
        transform: translate(0, 0);
    }

    50% {
        transform: translate(-20px, 20px);
    }

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

.attack-anim-player {
    animation: attack-player 0.3s;
}

.attack-anim-enemy {
    animation: attack-enemy 0.3s;
}

.damage-flash {
    animation: flash 0.2s;
}

@keyframes flash {
    0% {
        opacity: 1;
    }

    50% {
        opacity: 0;
    }

    100% {
        opacity: 1;
    }

    100% {
        opacity: 1;
    }
}

@keyframes heal-effect {
    0% {
        filter: brightness(100%);
        transform: scale(1);
    }

    50% {
        filter: brightness(300%) drop-shadow(0 0 10px gold);
        transform: scale(1.2);
    }

    100% {
        filter: brightness(100%);
        transform: scale(1);
    }
}

.heal-anim {
    animation: heal-effect 1s ease-in-out;
}

.attack-particle {
    position: absolute;
    width: 40px;
    height: 40px;
    pointer-events: none;
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 30px;
    font-weight: bold;
    font-family: 'Courier New', monospace;
    /* Distinct math font */
    text-shadow: 1px 1px 0px rgba(0, 0, 0, 0.5);
}

/* Stage Progress */
.stage-progress {
    display: flex;
    gap: 5px;
    margin-bottom: 5px;
}

.pokeball-icon {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 1px solid #333;
    background: linear-gradient(to bottom, #f00 50%, #fff 50%);
    /* Active by default */
    position: relative;
}

.pokeball-icon::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 4px;
    height: 4px;
    background: #fff;
    border: 1px solid #333;
    border-radius: 50%;
}

.pokeball-icon.defeated {
    background: #888;
    /* Gray for defeated */
    filter: grayscale(100%);
}

.pokeball-icon.defeated::after {
    background: #555;
}

/* Items */
.items-area {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}

.item-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    background-color: #f0f0f0;
    color: #333;
    border: 2px solid #333;
    padding: 5px 10px;
    font-size: 10px;
}

.item-btn img {
    width: 16px;
    height: 16px;
}

.item-btn:hover {
    background-color: #e0e0e0;
}

.item-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Ending Overlay */
#ending-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 100;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: white;
    text-align: center;
}

.ending-img {
    width: 200px;
    margin-bottom: 20px;
    border: 4px solid #fff;
    border-radius: 10px;
}

.ending-text h1 {
    font-size: 24px;
    margin-bottom: 10px;
    color: #ffeb3b;
    text-shadow: 2px 2px #333;
}

.ending-text p {
    font-size: 14px;
    margin-bottom: 20px;
}

#ending-restart-btn {
    background-color: #4caf50;
    font-size: 14px;
    padding: 15px 30px;
}

/* Overlay Styles (Start & Ending) */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 100;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: white;
    text-align: center;
}

.main-title {
    font-size: 40px;
    color: #ffeb3b;
    text-shadow: 4px 4px #333;
    margin-bottom: 20px;
    line-height: 1.2;
}

.credits {
    font-size: 16px;
    margin-bottom: 40px;
    color: #ccc;
}

.start-btn {
    font-family: 'DungGeunMo', cursive;
    font-size: 24px;
    padding: 15px 40px;
    background: #f44336;
    color: white;
    border: 4px solid #fff;
    cursor: pointer;
    animation: blink 1s infinite;
}

@keyframes blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

/* Starter Selection Screen */
.selection-title {
    font-size: 28px;
    color: #ffeb3b;
    text-shadow: 3px 3px #333;
    margin-bottom: 10px;
}

.selection-hint {
    font-size: 14px;
    color: #4caf50;
    margin-bottom: 30px;
    background: rgba(255, 255, 255, 0.1);
    padding: 10px 20px;
    border-radius: 5px;
}

.starter-selection {
    display: flex;
    gap: 30px;
    justify-content: center;
    align-items: center;
}

.starter-option {
    cursor: pointer;
    text-align: center;
    padding: 20px;
    background: rgba(255, 255, 255, 0.1);
    border: 3px solid #fff;
    border-radius: 10px;
    transition: all 0.3s;
}

.starter-option:hover {
    transform: scale(1.1);
    background: rgba(255, 255, 255, 0.2);
    box-shadow: 0 0 20px rgba(255, 235, 59, 0.5);
}

.starter-option img {
    width: 120px;
    height: 120px;
    object-fit: contain;
    margin-bottom: 10px;
}

.starter-option p {
    font-size: 14px;
    color: white;
    margin: 0;
}

/* Grade Selection Screen */
.grade-selection {
    display: flex;
    gap: 50px;
    justify-content: center;
    align-items: center;
}

.grade-option {
    cursor: pointer;
    text-align: center;
    padding: 30px 40px;
    background: rgba(255, 255, 255, 0.1);
    border: 3px solid #fff;
    border-radius: 10px;
    transition: all 0.3s;
    min-width: 150px;
}

.grade-option:hover {
    transform: translateY(-5px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    border-color: #3f51b5;
}

.grade-option.selected {
    border-color: #ff5722;
    background-color: #fff3e0;
    transform: translateY(-5px);
    box-shadow: 0 5px 15px rgba(255, 87, 34, 0.3);
}

.grade-option p {
    font-size: 18px;
    color: white;
    margin: 0;
}

.grade-icon {
    font-size: 60px;
    margin-bottom: 15px;
}

.grade-option p {
    font-size: 18px;
    color: white;
    margin: 0;
}

/* Hint Display */
.hint-display {
    background: rgba(76, 175, 80, 0.2);
    border: 2px solid #4caf50;
    border-radius: 5px;
    padding: 10px;
    margin-bottom: 10px;
    font-size: 12px;
    color: #2e7d32;
    animation: fadeIn 0.3s;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

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

#hint-text {
    font-weight: bold;
    color: #1b5e20;
}

/* Name Input Area */
.name-input-area {
    margin-bottom: 30px;
}

.name-input-area input {
    font-family: 'DungGeunMo', cursive;
    font-size: 16px;
    padding: 15px 20px;
    border: 3px solid #fff;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.9);
    color: #333;
    text-align: center;
    min-width: 250px;
}

.name-input-area input::placeholder {
    color: #999;
}

.name-input-area input:focus {
    outline: none;
    border-color: #3f51b5;
}

/* Difficulty Selection */
.difficulty-selection {
    margin-top: 20px;
    width: 100%;
    text-align: center;
}

.difficulty-selection h3 {
    font-size: 16px;
    margin-bottom: 10px;
    color: #333;
}

.difficulty-options {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.diff-btn {
    padding: 8px 16px;
    border: 2px solid #ccc;
    background: #fff;
    border-radius: 20px;
    cursor: pointer;
    font-family: 'DungGeunMo', cursive;
    font-size: 14px;
    transition: all 0.2s;
    color: black;
}

.diff-btn:hover {
    background: #f0f0f0;
}

.diff-btn.selected {
    background: #ff5722;
    color: black;
    border-color: #e64a19;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* Timer Display */
.timer-display {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 255, 255, 0.95);
    border: 3px solid #333;
    border-radius: 8px;
    padding: 10px 20px;
    font-size: 18px;
    font-weight: bold;
    color: #d32f2f;
    z-index: 50;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    animation: pulse 1s infinite;
}

@keyframes pulse {

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

    50% {
        transform: translateX(-50%) scale(1.05);
    }
}




/* Responsive Design */
@media (max-width: 600px) {
    .game-container {
        width: 100%;
        height: 100vh;
        max-width: none;
        border: none;
        border-radius: 0;
    }

    .battle-scene {
        height: 60%;
    }

    .dialog-box {
        height: 40%;
    }

    .sprite-container img {
        width: 120px;
        height: 120px;
    }

    .enemy-sprite {
        top: 40px;
        right: 20px;
        width: 240px;
    }

    .player-sprite {
        bottom: 20px;
        left: 20px;
        width: 150px;
    }

    .hud {
        padding: 5px 10px;
    }

    .enemy-hud {
        top: 10px;
        left: 10px;
    }

    .player-hud {
        bottom: 10px;
        right: 10px;
    }

    .main-title {
        font-size: 32px;
    }
}

/* Mobile Responsive Layout */
@media (max-width: 768px) {
    .game-container {
        width: 100%;
        max-width: 480px;
        height: 100vh;
        background-color: #fff;
        border: none;
        position: relative;
        overflow: hidden;
        box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
        margin: 0 auto;
        display: flex;
        flex-direction: column;
    }

    .battle-scene {
        position: relative;
        flex: 1;
        width: 100%;
        height: auto;
        background-color: #87ceeb;
        overflow: hidden;
    }

    .dialog-box {
        height: auto;
        min-height: auto;
        flex-shrink: 0;
    }

    .enemy-hud {
        top: 70px;
        left: 10px;
        transform: scale(0.9);
        transform-origin: top left;
    }

    .player-hud {
        bottom: 20px;
        right: 10px;
        transform: scale(0.9);
        transform-origin: bottom right;
    }

    .enemy-sprite {
        top: 42%;
        right: 10%;
        width: 50%;
        max-width: 250px;
        z-index: 5;
    }

    .enemy-sprite img {
        transform: scale(2);
        transform-origin: center bottom;
    }

    .player-sprite {
        bottom: 5%;
        left: 5%;
        width: 35%;
        max-width: 180px;
    }

    .starter-selection {
        gap: 15px;
        flex-wrap: wrap;
        padding: 0 10px;
    }

    .starter-option img {
        width: 80px;
        height: 80px;
    }
}