/* ===========================================
   HAUNTED HOUSE: GHOST FIGHTER
   Pixel Art Retro Style CSS
   =========================================== */

/* CSS Reset and Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* 8-bit color palette: purples, greens, blacks */
    --bg-dark: #0a0a0f;
    --bg-medium: #1a1a2e;
    --bg-light: #252540;
    --purple-dark: #4a1a6b;
    --purple-main: #7b2cbf;
    --purple-light: #9d4edd;
    --green-dark: #1a472a;
    --green-main: #2d6a4f;
    --green-glow: #40916c;
    --green-bright: #52b788;
    --text-main: #e0e0e0;
    --text-dim: #808080;
    --red-danger: #c1121f;
    --red-bright: #e63946;
    --gold: #ffd700;
    --white: #ffffff;
}

body {
    font-family: 'Press Start 2P', monospace;
    background-color: var(--bg-dark);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    image-rendering: pixelated;
}

#game-container {
    width: 100%;
    max-width: 800px;
    height: 600px;
    background-color: var(--bg-medium);
    border: 4px solid var(--purple-main);
    position: relative;
    overflow: hidden;
    box-shadow:
        0 0 20px var(--purple-dark),
        inset 0 0 50px rgba(0, 0, 0, 0.5);
}

/* ===========================================
   SCREEN MANAGEMENT
   =========================================== */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.screen.active {
    display: flex;
    opacity: 1;
}

/* ===========================================
   PIXEL BUTTONS
   =========================================== */
.pixel-btn {
    font-family: 'Press Start 2P', monospace;
    font-size: 12px;
    padding: 15px 30px;
    background: linear-gradient(180deg, var(--purple-light) 0%, var(--purple-main) 100%);
    color: var(--white);
    border: none;
    border-bottom: 4px solid var(--purple-dark);
    cursor: pointer;
    text-transform: uppercase;
    transition: all 0.1s ease;
    position: relative;
}

.pixel-btn:hover {
    background: linear-gradient(180deg, var(--purple-main) 0%, var(--purple-light) 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(123, 44, 191, 0.5);
}

.pixel-btn:active {
    transform: translateY(2px);
    border-bottom-width: 2px;
}

.pixel-btn.small {
    font-size: 8px;
    padding: 8px 15px;
}

.pixel-btn.action-btn {
    font-size: 10px;
    padding: 12px 20px;
    min-width: 120px;
}

.pixel-btn:disabled {
    background: var(--text-dim);
    border-color: #555;
    cursor: not-allowed;
    opacity: 0.6;
}

/* ===========================================
   TITLE SCREEN
   =========================================== */
#title-screen {
    justify-content: center;
    background:
        radial-gradient(ellipse at center, var(--bg-light) 0%, var(--bg-dark) 70%),
        url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect fill="%230a0a0f" width="100" height="100"/><rect fill="%231a1a2e" x="10" y="10" width="2" height="2" opacity="0.3"/></svg>');
}

.haunted-house-logo {
    text-align: center;
    margin-bottom: 40px;
}

.haunted-house-logo h1 {
    font-size: 28px;
    color: var(--purple-light);
    text-shadow:
        0 0 10px var(--purple-main),
        0 0 20px var(--purple-dark),
        4px 4px 0 var(--bg-dark);
    margin-bottom: 10px;
    letter-spacing: 2px;
}

.haunted-house-logo h2 {
    font-size: 16px;
    color: var(--green-bright);
    text-shadow: 0 0 10px var(--green-main);
}

/* Flickering animation for title */
.flicker {
    animation: flicker 3s infinite;
}

@keyframes flicker {

    0%,
    100% {
        opacity: 1;
    }

    92% {
        opacity: 1;
    }

    93% {
        opacity: 0.8;
    }

    94% {
        opacity: 1;
    }

    95% {
        opacity: 0.9;
    }

    96% {
        opacity: 1;
    }
}

/* Pixel art haunted house sprite */
.house-sprite {
    width: 120px;
    height: 100px;
    margin: 0 auto 20px;
    background:
        /* Roof */
        linear-gradient(135deg, transparent 40%, var(--purple-dark) 40%, var(--purple-dark) 60%, transparent 60%),
        /* Main building */
        linear-gradient(to bottom, var(--bg-light) 30%, var(--purple-dark) 30%);
    position: relative;
    image-rendering: pixelated;
}

.house-sprite::before {
    content: '';
    position: absolute;
    width: 20px;
    height: 30px;
    background: var(--green-glow);
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    box-shadow:
        -30px -20px 0 0 var(--green-glow),
        30px -20px 0 0 var(--green-glow),
        0 0 20px var(--green-main);
    animation: windowGlow 2s ease-in-out infinite alternate;
}

@keyframes windowGlow {
    0% {
        box-shadow: -30px -20px 0 0 var(--green-glow), 30px -20px 0 0 var(--green-glow), 0 0 10px var(--green-main);
    }

    100% {
        box-shadow: -30px -20px 0 0 var(--green-bright), 30px -20px 0 0 var(--green-bright), 0 0 30px var(--green-bright);
    }
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.credits {
    position: absolute;
    bottom: 20px;
    font-size: 8px;
    color: var(--text-dim);
}

/* ===========================================
   HOW TO PLAY SCREEN
   =========================================== */
#howto-screen {
    justify-content: flex-start;
    padding-top: 40px;
}

#howto-screen h2 {
    font-size: 20px;
    color: var(--purple-light);
    margin-bottom: 30px;
}

.howto-content {
    text-align: left;
    max-width: 600px;
    margin-bottom: 30px;
}

.howto-section {
    margin-bottom: 25px;
}

.howto-section h3 {
    font-size: 12px;
    color: var(--green-bright);
    margin-bottom: 10px;
}

.howto-section p {
    font-size: 8px;
    line-height: 2;
    color: var(--text-main);
}

/* ===========================================
   MAP SCREEN
   =========================================== */
#map-screen {
    justify-content: flex-start;
    padding-top: 15px;
}

.game-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding: 0 10px;
}

.player-stats {
    display: flex;
    gap: 20px;
    font-size: 10px;
}

.player-stats span {
    color: var(--green-bright);
}

#map-screen h2 {
    font-size: 16px;
    color: var(--purple-light);
    margin-bottom: 20px;
    text-shadow: 0 0 10px var(--purple-main);
}

.house-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 8px;
    width: 520px;
    height: 360px;
    padding: 12px;
    background: var(--bg-dark);
    border: 3px solid var(--purple-dark);
    margin-bottom: 15px;
}

.room {
    background: var(--bg-light);
    border: 2px solid var(--purple-main);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

.room:hover:not(.fog):not(.cleared):not(.current) {
    border-color: var(--green-bright);
    box-shadow: 0 0 15px var(--green-main);
}

.room.fog {
    background: var(--bg-dark);
    cursor: not-allowed;
}

.room.fog::after {
    content: '?';
    font-size: 24px;
    color: var(--text-dim);
}

.room.cleared {
    background: var(--green-dark);
    border-color: var(--green-main);
}

.room.current {
    border-color: var(--gold);
    box-shadow: 0 0 20px var(--gold);
    animation: currentPulse 1.5s ease-in-out infinite;
}

@keyframes currentPulse {

    0%,
    100% {
        box-shadow: 0 0 10px var(--gold);
    }

    50% {
        box-shadow: 0 0 25px var(--gold);
    }
}

.room-icon {
    font-size: 24px;
    margin-bottom: 5px;
}

.room-label {
    font-size: 6px;
    color: var(--text-dim);
    text-align: center;
}

/* Room type indicators */
.room[data-type="empty"] .room-icon::before {
    content: '[ ]';
    color: var(--text-dim);
}

.room[data-type="ghost"] .room-icon::before {
    content: '[G]';
    color: var(--purple-light);
}
.room[data-type="ghost"] {
    background: linear-gradient(180deg, var(--bg-light) 0%, rgba(123, 44, 191, 0.2) 100%);
}

.room[data-type="treasure"] .room-icon::before {
    content: '[$]';
    color: var(--gold);
}
.room[data-type="treasure"] {
    background: linear-gradient(180deg, var(--bg-light) 0%, rgba(255, 215, 0, 0.15) 100%);
}

.room[data-type="trap"] .room-icon::before {
    content: '[!]';
    color: var(--red-bright);
}
.room[data-type="trap"] {
    background: linear-gradient(180deg, var(--bg-light) 0%, rgba(230, 57, 70, 0.15) 100%);
}

.room[data-type="item"] .room-icon::before {
    content: '[+]';
    color: var(--green-bright);
}
.room[data-type="item"] {
    background: linear-gradient(180deg, var(--bg-light) 0%, rgba(82, 183, 136, 0.15) 100%);
}

.room[data-type="shrine"] .room-icon::before {
    content: '[*]';
    color: #00ffff;
}
.room[data-type="shrine"] {
    background: linear-gradient(180deg, var(--bg-light) 0%, rgba(0, 255, 255, 0.1) 100%);
}

.room[data-type="armory"] .room-icon::before {
    content: '[A]';
    color: #ff8c00;
}
.room[data-type="armory"] {
    background: linear-gradient(180deg, var(--bg-light) 0%, rgba(255, 140, 0, 0.15) 100%);
}

.room[data-type="mystery"] .room-icon::before {
    content: '[?]';
    color: #ff69b4;
    animation: mysteryPulse 1.5s ease-in-out infinite;
}
.room[data-type="mystery"] {
    background: linear-gradient(180deg, var(--bg-light) 0%, rgba(255, 105, 180, 0.1) 100%);
}

@keyframes mysteryPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.room[data-type="boss"] .room-icon::before {
    content: '[B]';
    color: var(--red-danger);
    text-shadow: 0 0 10px var(--red-danger);
}
.room[data-type="boss"] {
    background: linear-gradient(180deg, var(--bg-light) 0%, rgba(193, 18, 31, 0.2) 100%);
    border-color: var(--red-danger);
}

.room[data-type="start"] .room-icon::before {
    content: '[S]';
    color: var(--green-bright);
}
.room[data-type="start"] {
    background: linear-gradient(180deg, var(--bg-light) 0%, rgba(82, 183, 136, 0.2) 100%);
}

.room-info {
    font-size: 10px;
    color: var(--text-main);
    text-align: center;
    min-height: 40px;
    padding: 10px;
    background: var(--bg-dark);
    border: 2px solid var(--purple-dark);
    width: 520px;
}

/* ===========================================
   COMBAT SCREEN
   =========================================== */
#combat-screen {
    justify-content: flex-start;
    padding-top: 20px;
    background:
        radial-gradient(ellipse at center bottom, var(--purple-dark) 0%, transparent 50%),
        var(--bg-medium);
}

.combat-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    padding: 0 40px;
    margin-bottom: 20px;
}

.player-combat-stats,
.ghost-combat-stats {
    font-size: 12px;
}

.player-combat-stats {
    color: var(--green-bright);
}

.ghost-combat-stats {
    color: var(--red-bright);
}

.combat-arena {
    display: flex;
    justify-content: space-around;
    align-items: center;
    width: 100%;
    height: 200px;
    margin-bottom: 20px;
}

.combatant {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.pixel-character {
    width: 80px;
    height: 100px;
    image-rendering: pixelated;
    position: relative;
}

/* Player pixel art */
.pixel-character.player {
    background: var(--green-main);
    clip-path: polygon(40% 0%, 60% 0%,
            60% 20%, 70% 20%,
            70% 40%, 80% 40%,
            80% 70%, 70% 70%,
            70% 100%, 30% 100%,
            30% 70%, 20% 70%,
            20% 40%, 30% 40%,
            30% 20%, 40% 20%);
    box-shadow: 0 0 20px var(--green-glow);
}

.pixel-character.player::before {
    content: '';
    position: absolute;
    width: 8px;
    height: 8px;
    background: var(--white);
    top: 25%;
    left: 35%;
    box-shadow: 15px 0 0 var(--white);
}

/* Ghost pixel art - varies by type */
.pixel-character.ghost {
    background: var(--purple-light);
    border-radius: 40% 40% 0 0;
    clip-path: polygon(20% 30%, 30% 10%, 50% 0%, 70% 10%, 80% 30%,
            85% 60%, 80% 100%, 70% 80%, 60% 100%,
            50% 80%, 40% 100%, 30% 80%, 20% 100%, 15% 60%);
    box-shadow: 0 0 30px var(--purple-main);
    animation: ghostFloat 2s ease-in-out infinite;
}

.pixel-character.ghost::before {
    content: '';
    position: absolute;
    width: 12px;
    height: 12px;
    background: var(--red-bright);
    border-radius: 50%;
    top: 30%;
    left: 25%;
    box-shadow: 25px 0 0 var(--red-bright);
}

.pixel-character.ghost.wisp {
    background: #88ccff;
    box-shadow: 0 0 30px #88ccff;
    transform: scale(0.7);
}

.pixel-character.ghost.phantom {
    background: var(--purple-light);
    box-shadow: 0 0 30px var(--purple-main);
}

.pixel-character.ghost.poltergeist {
    background: #ff6b6b;
    box-shadow: 0 0 30px #ff6b6b;
    transform: scale(1.1);
}

.pixel-character.ghost.boss {
    background: linear-gradient(180deg, #2d0a3e 0%, #5c1a8c 50%, #8b2fc9 100%);
    box-shadow: 0 0 50px var(--purple-main), 0 0 100px var(--red-danger);
    transform: scale(1.4);
}

@keyframes ghostFloat {

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

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

.vs-indicator {
    font-size: 24px;
    color: var(--red-bright);
    text-shadow: 0 0 10px var(--red-danger);
    animation: vsPulse 1s ease-in-out infinite;
}

@keyframes vsPulse {

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

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

.hp-bar {
    width: 100px;
    height: 12px;
    background: var(--bg-dark);
    border: 2px solid var(--text-dim);
    overflow: hidden;
}

.hp-fill {
    height: 100%;
    background: linear-gradient(180deg, var(--green-bright) 0%, var(--green-main) 100%);
    transition: width 0.3s ease;
    width: 100%;
}

.hp-fill.ghost-hp {
    background: linear-gradient(180deg, var(--red-bright) 0%, var(--red-danger) 100%);
}

.hp-fill.low {
    background: linear-gradient(180deg, var(--red-bright) 0%, var(--red-danger) 100%);
    animation: lowHpFlash 0.5s ease-in-out infinite;
}

@keyframes lowHpFlash {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

.combat-log {
    width: 90%;
    max-width: 500px;
    height: 80px;
    background: var(--bg-dark);
    border: 2px solid var(--purple-dark);
    padding: 10px;
    margin-bottom: 20px;
    overflow-y: auto;
    font-size: 8px;
    line-height: 1.8;
}

.combat-log p {
    margin-bottom: 5px;
}

.combat-log .damage {
    color: var(--red-bright);
}

.combat-log .heal {
    color: var(--green-bright);
}

.combat-log .info {
    color: var(--purple-light);
}

.combat-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

/* Attack animation */
.pixel-character.attacking {
    animation: attackAnim 0.3s ease-out;
}

@keyframes attackAnim {
    0% {
        transform: translateX(0);
    }

    50% {
        transform: translateX(30px);
    }

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

.pixel-character.ghost.attacking {
    animation: ghostAttackAnim 0.3s ease-out;
}

@keyframes ghostAttackAnim {
    0% {
        transform: translateX(0) translateY(0);
    }

    50% {
        transform: translateX(-30px) translateY(-5px);
    }

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

/* Hit flash effect */
.pixel-character.hit {
    animation: hitFlash 0.2s ease-out;
}

@keyframes hitFlash {

    0%,
    100% {
        filter: brightness(1);
    }

    50% {
        filter: brightness(3) saturate(0);
    }
}

/* Screen shake */
.screen.shake {
    animation: screenShake 0.3s ease-out;
}

@keyframes screenShake {

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

    20% {
        transform: translateX(-5px);
    }

    40% {
        transform: translateX(5px);
    }

    60% {
        transform: translateX(-3px);
    }

    80% {
        transform: translateX(3px);
    }
}

/* ===========================================
   INVENTORY SCREEN
   =========================================== */
#inventory-screen {
    justify-content: flex-start;
    padding-top: 40px;
}

#inventory-screen h2 {
    font-size: 20px;
    color: var(--purple-light);
    margin-bottom: 30px;
}

.stats-panel,
.items-panel {
    width: 100%;
    max-width: 400px;
    background: var(--bg-dark);
    border: 2px solid var(--purple-dark);
    padding: 15px;
    margin-bottom: 20px;
}

.stats-panel h3,
.items-panel h3 {
    font-size: 12px;
    color: var(--green-bright);
    margin-bottom: 15px;
}

#full-stats p {
    font-size: 10px;
    margin-bottom: 8px;
}

#full-stats span {
    color: var(--purple-light);
}

.item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px;
    margin-bottom: 5px;
    background: var(--bg-light);
    border: 1px solid var(--purple-dark);
}

.item-name {
    font-size: 8px;
    color: var(--gold);
}

.item-count {
    font-size: 8px;
    color: var(--text-dim);
}

.no-items {
    font-size: 8px;
    color: var(--text-dim);
    font-style: italic;
}

/* ===========================================
   ITEM MODAL
   =========================================== */
.modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-medium);
    border: 3px solid var(--purple-main);
    padding: 20px;
    min-width: 250px;
    text-align: center;
}

.modal-content h3 {
    font-size: 12px;
    color: var(--purple-light);
    margin-bottom: 20px;
}

#combat-items-list {
    margin-bottom: 20px;
}

.combat-item-btn {
    width: 100%;
    margin-bottom: 8px;
    font-size: 8px;
    padding: 10px;
    background: var(--bg-light);
    border: 2px solid var(--green-main);
    color: var(--text-main);
    cursor: pointer;
    font-family: 'Press Start 2P', monospace;
}

.combat-item-btn:hover {
    background: var(--green-dark);
    border-color: var(--green-bright);
}

/* ===========================================
   GAME OVER & VICTORY SCREENS
   =========================================== */
#gameover-screen,
#victory-screen {
    justify-content: center;
    background: radial-gradient(ellipse at center, var(--bg-light) 0%, var(--bg-dark) 100%);
}

#gameover-screen h2 {
    font-size: 32px;
    color: var(--red-bright);
    text-shadow: 0 0 20px var(--red-danger);
    margin-bottom: 30px;
    animation: gameoverPulse 1s ease-in-out infinite;
}

@keyframes gameoverPulse {

    0%,
    100% {
        opacity: 1;
        text-shadow: 0 0 20px var(--red-danger);
    }

    50% {
        opacity: 0.8;
        text-shadow: 0 0 40px var(--red-danger);
    }
}

.gameover-message,
.victory-message {
    font-size: 10px;
    margin-bottom: 30px;
    text-align: center;
    line-height: 2;
}

.final-stats {
    background: var(--bg-dark);
    border: 2px solid var(--purple-dark);
    padding: 20px;
    margin-bottom: 30px;
    font-size: 10px;
}

.final-stats p {
    margin-bottom: 10px;
}

.final-stats span {
    color: var(--gold);
}

.victory-title {
    font-size: 32px;
    color: var(--gold);
    text-shadow:
        0 0 20px var(--gold),
        0 0 40px var(--green-bright);
    margin-bottom: 30px;
    animation: victoryGlow 1s ease-in-out infinite alternate;
}

@keyframes victoryGlow {
    0% {
        text-shadow: 0 0 20px var(--gold), 0 0 40px var(--green-bright);
    }

    100% {
        text-shadow: 0 0 40px var(--gold), 0 0 80px var(--green-bright);
    }
}

/* ===========================================
   SCROLLBAR STYLING
   =========================================== */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-dark);
}

::-webkit-scrollbar-thumb {
    background: var(--purple-dark);
    border: 1px solid var(--purple-main);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--purple-main);
}

/* ===========================================
   LEVEL UP ANIMATION
   =========================================== */
.level-up-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 50;
    animation: fadeInOut 2s ease-in-out forwards;
}

.level-up-text {
    font-size: 24px;
    color: var(--gold);
    text-shadow: 0 0 30px var(--gold);
    animation: levelUpPop 0.5s ease-out;
}

@keyframes fadeInOut {
    0% {
        opacity: 0;
    }

    20% {
        opacity: 1;
    }

    80% {
        opacity: 1;
    }

    100% {
        opacity: 0;
    }
}

@keyframes levelUpPop {
    0% {
        transform: scale(0.5);
    }

    50% {
        transform: scale(1.2);
    }

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

/* ===========================================
   RESPONSIVE ADJUSTMENTS
   =========================================== */
@media (max-width: 850px) {
    #game-container {
        max-width: 100%;
        height: 100vh;
        border: none;
    }

    .house-grid {
        width: 100%;
        max-width: 480px;
        height: auto;
        aspect-ratio: 4/3;
        gap: 5px;
        padding: 8px;
    }

    .room-info {
        width: 100%;
        max-width: 480px;
    }

    .room-label {
        font-size: 5px;
    }

    .room-icon {
        font-size: 18px;
    }

    .haunted-house-logo h1 {
        font-size: 20px;
    }

    .combat-actions {
        gap: 5px;
    }

    .pixel-btn.action-btn {
        font-size: 8px;
        padding: 10px 15px;
        min-width: 100px;
    }
}