* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

:root {
    --warrior: #ff0000;
    --valkyrie: #00ffff;
    --wizard: #ffff00;
    --elf: #00ff00;
    --gold: #ffcc00;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #000;
    font-family: 'Press Start 2P', cursive;
}

#game-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: #000;
}

/* Title Screen */
#title-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #000;
    z-index: 100;
}

#title-screen.hidden {
    display: none;
}

.title-text {
    font-size: clamp(1.5rem, 8vw, 4rem);
    color: var(--gold);
    text-shadow: 4px 4px 0 #884400, 0 0 20px #ff6600;
    letter-spacing: 0.15em;
    margin-bottom: 0.5rem;
    animation: flicker 0.1s infinite alternate;
}

@keyframes flicker {
    0% { opacity: 1; }
    100% { opacity: 0.95; }
}

.subtitle {
    font-size: clamp(0.4rem, 1.5vw, 0.8rem);
    color: #888;
    margin-bottom: 2rem;
    letter-spacing: 0.2em;
}

.character-select {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: clamp(0.5rem, 2vw, 1rem);
    padding: 1rem;
    max-width: 500px;
}

.character-btn {
    padding: clamp(0.6rem, 2vw, 1rem);
    font-family: 'Press Start 2P', cursive;
    font-size: clamp(0.4rem, 1.5vw, 0.7rem);
    border: 3px solid;
    background: #000;
    cursor: pointer;
    text-align: center;
}

.character-btn.warrior {
    color: var(--warrior);
    border-color: var(--warrior);
}

.character-btn.warrior:hover {
    background: #330000;
    box-shadow: 0 0 20px #ff000066;
}

.character-btn.valkyrie {
    color: var(--valkyrie);
    border-color: var(--valkyrie);
}

.character-btn.valkyrie:hover {
    background: #003333;
    box-shadow: 0 0 20px #00ffff66;
}

.character-btn.wizard {
    color: var(--wizard);
    border-color: var(--wizard);
}

.character-btn.wizard:hover {
    background: #333300;
    box-shadow: 0 0 20px #ffff0066;
}

.character-btn.elf {
    color: var(--elf);
    border-color: var(--elf);
}

.character-btn.elf:hover {
    background: #003300;
    box-shadow: 0 0 20px #00ff0066;
}

.char-stats {
    font-size: clamp(0.3rem, 1vw, 0.5rem);
    margin-top: 0.4rem;
    opacity: 0.6;
}

.char-preview {
    width: 48px;
    height: 48px;
    margin: 0.5rem auto;
    image-rendering: pixelated;
}

/* HUD */
#hud {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: clamp(0.2rem, 1vw, 0.5rem) clamp(0.3rem, 1.5vw, 0.8rem);
    background: #000;
    border-bottom: 2px solid #333;
    flex-shrink: 0;
}

.hud-section {
    display: flex;
    align-items: center;
    gap: clamp(0.2rem, 0.8vw, 0.4rem);
}

.health-bar {
    width: clamp(50px, 12vw, 100px);
    height: clamp(10px, 2.5vw, 16px);
    border: 2px solid #666;
    background: #111;
}

.health-fill {
    height: 100%;
    background: linear-gradient(180deg, #ff4444 0%, #aa0000 50%, #660000 100%);
    transition: width 0.2s;
}

.hud-label {
    font-size: clamp(0.35rem, 1vw, 0.5rem);
    color: #888;
}

.hud-value {
    font-size: clamp(0.4rem, 1.2vw, 0.7rem);
    color: var(--gold);
}

.player-indicator {
    font-size: clamp(0.4rem, 1.2vw, 0.6rem);
    padding: 0.2rem 0.4rem;
    border: 2px solid;
}

.player-indicator.warrior {
    color: var(--warrior);
    border-color: var(--warrior);
}

.player-indicator.valkyrie {
    color: var(--valkyrie);
    border-color: var(--valkyrie);
}

.player-indicator.wizard {
    color: var(--wizard);
    border-color: var(--wizard);
}

.player-indicator.elf {
    color: var(--elf);
    border-color: var(--elf);
}

/* Canvas Container */
#canvas-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: #000;
}

#game-canvas {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* CRT Scanline Effect */
#canvas-container::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: repeating-linear-gradient(
        0deg,
        rgba(0, 0, 0, 0.15) 0px,
        rgba(0, 0, 0, 0.15) 1px,
        transparent 1px,
        transparent 2px
    );
    pointer-events: none;
    z-index: 10;
}

/* Mobile Controls */
#mobile-controls {
    display: none;
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: clamp(0.5rem, 2vw, 1rem);
    pointer-events: none;
    z-index: 20;
}

@media (pointer: coarse) {
    #mobile-controls {
        display: flex;
        justify-content: space-between;
        align-items: flex-end;
    }
}

.dpad-container {
    position: relative;
    width: clamp(90px, 22vw, 130px);
    height: clamp(90px, 22vw, 130px);
    pointer-events: auto;
}

.dpad-btn {
    position: absolute;
    width: clamp(32px, 7vw, 44px);
    height: clamp(32px, 7vw, 44px);
    background: rgba(100, 100, 100, 0.4);
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(0.8rem, 2.5vw, 1.2rem);
    color: rgba(255, 255, 255, 0.7);
}

.dpad-btn:active,
.dpad-btn.active {
    background: rgba(255, 255, 255, 0.5);
}

.dpad-up {
    top: 0;
    left: 50%;
    transform: translateX(-50%);
}

.dpad-down {
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
}

.dpad-left {
    left: 0;
    top: 50%;
    transform: translateY(-50%);
}

.dpad-right {
    right: 0;
    top: 50%;
    transform: translateY(-50%);
}

.action-buttons {
    display: flex;
    gap: clamp(0.4rem, 1.5vw, 0.8rem);
    pointer-events: auto;
}

.action-btn {
    width: clamp(44px, 10vw, 60px);
    height: clamp(44px, 10vw, 60px);
    border-radius: 50%;
    border: 3px solid;
    background: rgba(0, 0, 0, 0.6);
    font-family: 'Press Start 2P', cursive;
    font-size: clamp(0.3rem, 1vw, 0.5rem);
}

.action-btn.attack {
    color: #ff4444;
    border-color: #ff4444;
}

.action-btn.attack:active {
    background: rgba(255, 68, 68, 0.5);
}

.action-btn.magic {
    color: #4488ff;
    border-color: #4488ff;
}

.action-btn.magic:active {
    background: rgba(68, 136, 255, 0.5);
}

.controls-hint {
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    font-size: clamp(0.3rem, 0.8vw, 0.45rem);
    color: #444;
    z-index: 5;
}

@media (pointer: coarse) {
    .controls-hint {
        display: none;
    }
}

/* Announcer */
#announcer {
    position: absolute;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    font-size: clamp(0.5rem, 1.5vw, 0.8rem);
    color: #ffcc00;
    text-shadow: 2px 2px 0 #000;
    text-align: center;
    opacity: 0;
    transition: opacity 0.3s;
    z-index: 50;
    pointer-events: none;
}

#announcer.show {
    opacity: 1;
}

@media (pointer: coarse) {
    #announcer {
        bottom: 140px;
    }
}

/* Game Over */
#game-over {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

#game-over.show {
    display: flex;
}

.game-over-text {
    font-size: clamp(1.2rem, 5vw, 2.5rem);
    color: #ff0000;
    text-shadow: 0 0 10px #ff0000;
    margin-bottom: 1rem;
    animation: flash 0.5s infinite alternate;
}

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

.final-score {
    font-size: clamp(0.6rem, 2.5vw, 1.2rem);
    color: var(--gold);
    margin-bottom: 2rem;
}

.restart-btn {
    padding: 0.8rem 1.5rem;
    font-family: 'Press Start 2P', cursive;
    font-size: clamp(0.5rem, 1.5vw, 0.8rem);
    color: var(--gold);
    background: transparent;
    border: 3px solid var(--gold);
    cursor: pointer;
}

.restart-btn:hover {
    background: #332200;
}
