* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Press Start 2P', monospace;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    overflow-x: hidden;
    touch-action: pan-y;
    user-select: none;
}

#app-container {
    max-width: 100vw;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Top Bar */
#top-bar {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background: rgba(44, 62, 80, 0.85);
    backdrop-filter: blur(10px);
    border-bottom: 2px solid rgba(255, 255, 255, 0.3);
}

.title {
    font-size: 0.9em;
    color: #FFD700;
    text-shadow: 2px 2px 0 #000;
}

.action-buttons {
    display: flex;
    gap: 8px;
}

.pill-btn {
    padding: 8px 12px;
    font-family: 'Press Start 2P', monospace;
    font-size: 0.7em;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.pill-btn:active {
    transform: scale(0.95);
}

.pill-btn.play {
    background: linear-gradient(135deg, #27AE60, #229954);
    border-color: #27AE60;
}

.pill-btn.play.stop {
    background: linear-gradient(135deg, #E74C3C, #C0392B);
    border-color: #E74C3C;
}

/* Canvas */
#canvas-wrapper {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    position: relative;
}

#game-canvas {
    border: 4px solid #2C3E50;
    background: #4A90C8;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.5);
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
    max-width: 100%;
    max-height: calc(100vh - 300px);
}

/* Play Overlay */
#play-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
}

#play-overlay > * {
    pointer-events: auto;
}

#hud {
    position: absolute;
    top: 30px;
    left: 20px;
    right: 20px;
    display: flex;
    justify-content: space-between;
    font-size: 0.8em;
    text-shadow: 2px 2px 0 #000;
    pointer-events: none;
}

/* Virtual Joystick */
#joystick-area {
    position: absolute;
    bottom: 30px;
    left: 30px;
    width: 120px;
    height: 120px;
}

#joystick-base {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100px;
    height: 100px;
    background: rgba(255, 255, 255, 0.15);
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    backdrop-filter: blur(5px);
}

#joystick-thumb {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.4);
    border: 3px solid rgba(255, 255, 255, 0.6);
    border-radius: 50%;
    transition: all 0.05s;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

/* Jump Button */
#jump-btn {
    position: absolute;
    bottom: 50px;
    right: 30px;
    width: 80px;
    height: 80px;
    font-family: 'Press Start 2P', monospace;
    font-size: 0.5em;
    background: linear-gradient(135deg, #3498DB, #2980B9);
    color: white;
    border: 3px solid #2C3E50;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 6px 0 #1F5F8B;
    transition: all 0.1s;
}

#jump-btn:active {
    transform: translateY(3px);
    box-shadow: 0 3px 0 #1F5F8B;
}

/* Bottom Toolbar */
#toolbar {
    position: sticky;
    bottom: 0;
    z-index: 100;
    padding: 10px;
    background: rgba(44, 62, 80, 0.85);
    backdrop-filter: blur(10px);
    border-top: 2px solid rgba(255, 255, 255, 0.3);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

#tool-palette {
    display: flex;
    gap: 8px;
    min-width: min-content;
    padding: 5px;
}

.tool-btn {
    min-width: 60px;
    min-height: 60px;
    font-size: 1.5em;
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.tool-btn:active {
    transform: scale(0.95);
}

.tool-btn.active {
    background: rgba(255, 215, 0, 0.4);
    border-color: #FFD700;
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.6);
}

.tool-btn.eraser {
    background: rgba(231, 76, 60, 0.3);
}

.tool-btn.brush {
    background: rgba(39, 174, 96, 0.3);
}

.tool-btn.bg-tool {
    background: linear-gradient(135deg, #9B59B6, #8E44AD);
}

/* Popups */
#block-skin-popup,
#theme-popup,
#import-export-modal,
#settings-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.popup-content {
    background: linear-gradient(135deg, #2C3E50, #34495E);
    border: 3px solid #FFD700;
    border-radius: 15px;
    padding: 20px;
    max-width: 500px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.popup-content h3 {
    font-size: 0.9em;
    margin-bottom: 15px;
    color: #FFD700;
    text-align: center;
    text-shadow: 2px 2px 0 #000;
}

#skin-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 10px;
    margin-bottom: 15px;
}

.skin-option {
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 10px;
    padding: 10px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

.skin-option:active {
    transform: scale(0.95);
    border-color: #FFD700;
}

.skin-preview {
    width: 64px;
    height: 64px;
    margin: 0 auto 8px;
    border-radius: 5px;
    image-rendering: pixelated;
}

.grass-block { background: linear-gradient(to bottom, #4CAF50 30%, #45a049 30%); }
.dirt-block { background: #8B4513; }
.stone-block { background: #808080; }
.deep-block { background: #2C1810; }
.wood-block { background: linear-gradient(90deg, #A0522D 45%, #8B4513 45%, #8B4513 55%, #A0522D 55%); }

.skin-option span {
    font-size: 0.5em;
    color: #ECF0F1;
}

/* Theme Popup */
#theme-input {
    width: 100%;
    padding: 10px;
    font-family: 'Press Start 2P', monospace;
    font-size: 0.6em;
    background: rgba(255, 255, 255, 0.9);
    border: 2px solid #2C3E50;
    border-radius: 5px;
    margin-bottom: 10px;
}

.theme-presets {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 15px;
}

.preset-btn {
    padding: 10px;
    font-family: 'Press Start 2P', monospace;
    font-size: 0.5em;
    background: rgba(156, 39, 176, 0.6);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.preset-btn:active {
    transform: scale(0.95);
}

#theme-loading {
    text-align: center;
    font-size: 0.7em;
    color: #FFD700;
    margin-top: 10px;
}

/* Buttons */
.game-btn {
    width: 100%;
    padding: 12px;
    margin-top: 10px;
    font-family: 'Press Start 2P', monospace;
    font-size: 0.6em;
    background: linear-gradient(to bottom, #27AE60, #229954);
    color: white;
    border: 3px solid #1E8449;
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 4px 0 #145A32;
    transition: all 0.1s;
}

.game-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #145A32;
}

.game-btn.secondary {
    background: linear-gradient(to bottom, #7F8C8D, #5D6D7E);
    border-color: #34495E;
    box-shadow: 0 4px 0 #2C3E50;
}

.game-btn.secondary:active {
    box-shadow: 0 2px 0 #2C3E50;
}

/* Settings */
#settings-btn {
    position: fixed;
    top: 70px;
    right: 15px;
    width: 50px;
    height: 50px;
    font-size: 1.5em;
    background: rgba(44, 62, 80, 0.85);
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    cursor: pointer;
    z-index: 99;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

#settings-panel label {
    display: block;
    font-size: 0.5em;
    margin: 15px 0 5px;
    color: #ECF0F1;
}

#settings-panel input[type="range"],
#settings-panel select {
    width: 100%;
    margin-top: 5px;
}

#settings-panel input[type="checkbox"] {
    margin-right: 8px;
}

/* Toast */
#toast {
    position: fixed;
    bottom: -100px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    color: #FFD700;
    padding: 15px 25px;
    border-radius: 10px;
    border: 2px solid #FFD700;
    font-size: 0.7em;
    text-shadow: 1px 1px 0 #000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    z-index: 2000;
    transition: bottom 0.3s ease;
}

#toast.show {
    bottom: 20px;
}

/* Footer */
footer {
    text-align: center;
    font-size: 0.5em;
    padding: 15px;
    background: rgba(0, 0, 0, 0.3);
    border-top: 2px solid rgba(255, 255, 255, 0.2);
}

footer a {
    color: #FFD700;
    text-decoration: none;
}

/* Responsive */
@media (max-width: 768px) {
    .title {
        font-size: 0.7em;
    }
    
    .pill-btn {
        font-size: 0.6em;
        padding: 6px 10px;
    }
    
    .tool-btn {
        min-width: 50px;
        min-height: 50px;
        font-size: 1.2em;
    }
    
    #joystick-area {
        width: 100px;
        height: 100px;
    }
    
    #joystick-base {
        width: 80px;
        height: 80px;
    }
    
    #jump-btn {
        width: 70px;
        height: 70px;
        font-size: 0.45em;
    }
}

@media (max-width: 480px) {
    .title {
        font-size: 0.6em;
    }
    
    #hud {
        font-size: 0.6em;
    }
}

/* Landscape mobile */
@media (max-height: 500px) and (orientation: landscape) {
    #canvas-wrapper {
        padding: 10px;
    }
    
    #game-canvas {
        max-height: calc(100vh - 200px);
    }
}