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

body {
    background-color: #1a1a2e;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    font-family: 'Courier New', monospace;
    overflow: hidden;
}

#game-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}

#game-area {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
}

/* Controls Panel */
#controls-panel {
    width: 120px;
    height: 520px; /* Match canvas height including border */
    padding: 12px;
    margin-right: 12px;
    background-color: #2a2a4e;
    border: 4px solid #4a4a6a;
    border-radius: 4px;
    color: #aaa;
    font-size: 11px;
    box-sizing: border-box;
}

#controls-panel h3 {
    color: #ffd700;
    font-size: 12px;
    margin-bottom: 12px;
    text-align: center;
    letter-spacing: 2px;
}

.control-group {
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid #4a4a6a;
}

.control-group:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.control-row {
    margin-bottom: 4px;
    line-height: 1.4;
}

.control-row .key {
    color: #fff;
    font-weight: bold;
    display: block;
    font-size: 10px;
}

#game-canvas {
    border: 4px solid #4a4a6a;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    background-color: #000;
}

#ui-overlay {
    display: flex;
    justify-content: space-between;
    width: 896px; /* Match canvas width */
    margin-left: 132px; /* Align with canvas (controls panel width + margin) */
    padding: 10px 20px;
    background-color: #2a2a4e;
    color: #ffd700;
    font-size: 18px;
    font-weight: bold;
    text-shadow: 2px 2px 0 #000;
    border: 4px solid #4a4a6a;
    border-top: none;
}

#message-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 10;
}

#message-overlay.hidden {
    display: none;
}

#message-text {
    color: #ffd700;
    font-size: 32px;
    text-align: center;
    text-shadow: 3px 3px 0 #8B4513;
    animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

#score-display,
#gold-display,
#lives-display {
    display: flex;
    gap: 5px;
}

/* Editor UI Styles */
#editor-ui {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    background-color: #1a1a2e;
    z-index: 50;
}

#editor-ui.hidden {
    display: none;
}

/* Editor Toolbar */
#editor-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    background-color: #2a2a4e;
    border-bottom: 2px solid #4a4a6a;
    gap: 16px;
    flex-shrink: 0;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.toolbar-center {
    flex: 1;
    justify-content: center;
}

.toolbar-separator {
    width: 1px;
    height: 24px;
    background-color: #4a4a6a;
    margin: 0 4px;
}

#editor-title {
    color: #ffd700;
    font-size: 16px;
    font-weight: bold;
}

/* Editor Main Area */
#editor-main {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Editor Sidebar */
#editor-sidebar {
    width: 140px;
    height: 100%;
    background-color: #2a2a4e;
    border-right: 2px solid #4a4a6a;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
    flex-shrink: 0;
}

/* Editor Canvas Area - contains the canvas */
#editor-canvas-area {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #1a1a2e;
}

.sidebar-section h3 {
    color: #aaa;
    font-size: 12px;
    text-transform: uppercase;
    margin-bottom: 8px;
    letter-spacing: 1px;
}

/* Tool Buttons */
.tool-buttons,
.spawn-buttons,
.view-buttons {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.tool-buttons button,
.spawn-buttons button,
.view-buttons button {
    padding: 6px 8px;
    font-size: 12px;
    text-align: left;
}

/* Tile Palette */
#tile-palette {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 4px;
}

.palette-tile {
    width: 100%;
    aspect-ratio: 1;
    padding: 2px;
    background-color: #1a1a2e;
    border: 2px solid #4a4a6a;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.1s;
}

.palette-tile:hover {
    border-color: #7a7aaa;
    transform: scale(1.05);
}

.palette-tile.active {
    border-color: #ffd700;
    box-shadow: 0 0 8px rgba(255, 215, 0, 0.5);
}

.palette-tile canvas {
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* Editor Status Bar */
#editor-status {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    background-color: #2a2a4e;
    border-top: 2px solid #4a4a6a;
    gap: 24px;
    font-size: 14px;
    color: #aaa;
    flex-shrink: 0;
}

.status-warning {
    margin-left: auto;
}

.status-warning.error {
    color: #ff4444;
}

.status-warning.warning {
    color: #ffaa00;
}

.status-warning.ok {
    color: #44ff44;
}

/* Buttons */
#editor-ui button {
    background-color: #3a3a5e;
    color: #fff;
    border: 2px solid #4a4a6a;
    border-radius: 4px;
    padding: 6px 12px;
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.1s;
}

#editor-ui button:hover {
    background-color: #4a4a6e;
    border-color: #6a6a8a;
}

#editor-ui button:active {
    background-color: #2a2a4e;
}

#editor-ui button.active {
    background-color: #5a5a7e;
    border-color: #ffd700;
    color: #ffd700;
}

#btn-test {
    background-color: #2a5a2a;
    border-color: #3a7a3a;
}

#btn-test:hover {
    background-color: #3a7a3a;
}

#btn-exit {
    background-color: #5a2a2a;
    border-color: #7a3a3a;
}

#btn-exit:hover {
    background-color: #7a3a3a;
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background-color: #2a2a4e;
    border: 4px solid #4a4a6a;
    border-radius: 8px;
    padding: 20px;
    min-width: 300px;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.modal-header h2 {
    color: #ffd700;
    font-size: 20px;
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    color: #aaa;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.modal-close:hover {
    color: #fff;
}

.modal form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.modal label {
    color: #aaa;
    font-size: 14px;
}

.modal input[type="text"] {
    background-color: #1a1a2e;
    border: 2px solid #4a4a6a;
    border-radius: 4px;
    color: #fff;
    padding: 8px 12px;
    font-family: inherit;
    font-size: 14px;
}

.modal input[type="text"]:focus {
    outline: none;
    border-color: #ffd700;
}

.modal-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 8px;
}

.modal button {
    background-color: #3a3a5e;
    color: #fff;
    border: 2px solid #4a4a6a;
    border-radius: 4px;
    padding: 8px 16px;
    font-family: inherit;
    font-size: 14px;
    cursor: pointer;
}

.modal button:hover {
    background-color: #4a4a6e;
}

.modal .btn-primary {
    background-color: #2a5a2a;
    border-color: #3a7a3a;
}

.modal .btn-primary:hover {
    background-color: #3a7a3a;
}

/* Level List */
.level-list {
    max-height: 300px;
    overflow-y: auto;
}

.level-list-item {
    display: flex;
    align-items: center;
    padding: 8px;
    border-bottom: 1px solid #4a4a6a;
    gap: 12px;
}

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

.level-name {
    flex: 1;
    color: #fff;
    font-size: 14px;
}

.level-date {
    color: #888;
    font-size: 12px;
}

.level-list-item button {
    padding: 4px 8px;
    font-size: 12px;
}

.btn-delete-level {
    background-color: #5a2a2a !important;
    border-color: #7a3a3a !important;
}

.btn-delete-level:hover {
    background-color: #7a3a3a !important;
}

.no-levels {
    color: #888;
    text-align: center;
    padding: 20px;
    font-style: italic;
}

/* Main Menu Styles */
#menu-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: rgba(0, 0, 0, 0.9);
    z-index: 20;
}

#menu-overlay.hidden {
    display: none;
}

#menu-content {
    text-align: center;
    padding: 40px;
}

#menu-title {
    color: #ffd700;
    font-size: 48px;
    margin-bottom: 40px;
    text-shadow: 4px 4px 0 #8B4513, 2px 2px 0 #000;
    letter-spacing: 4px;
    animation: menuPulse 2s ease-in-out infinite;
}

@keyframes menuPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.02); }
}

#menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: center;
}

#menu-buttons button {
    background-color: #3a3a5e;
    color: #fff;
    border: 3px solid #4a4a6a;
    border-radius: 8px;
    padding: 16px 48px;
    font-family: inherit;
    font-size: 20px;
    cursor: pointer;
    transition: all 0.2s;
    min-width: 220px;
}

#menu-buttons button:hover {
    background-color: #4a4a6e;
    border-color: #ffd700;
    transform: scale(1.05);
}

#menu-buttons button:active {
    background-color: #2a2a4e;
    transform: scale(0.98);
}

/* Level Selection in Menu */
#level-select {
    margin-bottom: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

#level-select-label {
    color: #aaa;
    font-size: 24px;
    font-weight: bold;
    text-shadow: 2px 2px 0 #000;
}

#level-select-number {
    color: #ffd700;
    font-size: 32px;
    font-weight: bold;
    text-shadow: 3px 3px 0 #8B4513, 2px 2px 0 #000;
    min-width: 60px;
    display: inline-block;
    text-align: center;
}

#level-select-hint {
    color: #666;
    font-size: 14px;
}

#btn-play {
    background-color: #2a5a2a !important;
    border-color: #3a7a3a !important;
}

#btn-play:hover {
    background-color: #3a7a3a !important;
    border-color: #ffd700 !important;
}

/* Modal wide variant for ASCII export */
.modal-wide {
    min-width: 600px;
    max-width: 800px;
}

.modal-hint {
    color: #aaa;
    font-size: 14px;
    margin-bottom: 12px;
}

#ascii-output {
    width: 100%;
    height: 300px;
    background-color: #1a1a2e;
    border: 2px solid #4a4a6a;
    border-radius: 4px;
    color: #fff;
    font-family: monospace;
    font-size: 12px;
    padding: 12px;
    resize: vertical;
    margin-bottom: 16px;
}

#ascii-output:focus {
    outline: none;
    border-color: #ffd700;
}

/* Built-in level button style */
#btn-builtin {
    background-color: #2a4a5a !important;
    border-color: #3a6a7a !important;
}

#btn-builtin:hover {
    background-color: #3a6a7a !important;
}
