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

:root {
    --beige: #F5E6CA;
    --cream: #F0DDB8;
    --brown: #3E2723;
    --dark-brown: #2C1A0F;
    --wood-light: #C49A6C;
    --wood-dark: #7B4B2A;
    --green-glow: #00FF41;
    --terminal-bg: #0D0208;
    --red-btn: #D32F2F;
    --yellow-btn: #FBC02D;
    --led-red: #FF1744;
    --led-green: #00E676;
    --led-yellow: #FFEA00;
    --crt-border: #1A1A1A;
}

body {
    background: #2C1A0F;
    font-family: 'Share Tech Mono', monospace;
    color: var(--brown);
    overflow-x: hidden;
    min-height: 100vh;
}

h1, h2, h3, h4, .drop-text, .ctrl-btn, .action-btn, .chaos-label, .key-hint,
.reg-name, #led-label, #rom-info, #eject-btn {
    font-family: 'Press Start 2P', cursive;
}

#console-shell {
    display: flex;
    max-width: 1400px;
    margin: 20px auto;
    background: var(--beige);
    border-radius: 24px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.6), inset 0 2px 0 rgba(255,255,255,0.3);
    overflow: hidden;
    border: 3px solid var(--brown);
}

.wood-panel {
    width: 40px;
    min-height: 100%;
    background: 
        repeating-linear-gradient(
            0deg,
            var(--wood-light) 0px,
            var(--wood-dark) 2px,
            var(--wood-light) 4px,
            #A67B5B 8px,
            var(--wood-light) 12px,
            var(--wood-dark) 14px,
            var(--wood-light) 18px
        );
    flex-shrink: 0;
    border-right: 2px solid var(--dark-brown);
}

#wood-panel-right {
    border-right: none;
    border-left: 2px solid var(--dark-brown);
}

#console-body {
    flex: 1;
    padding: 16px;
    min-width: 0;
}

#header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    background: linear-gradient(180deg, var(--cream), var(--beige));
    border-radius: 12px;
    margin-bottom: 12px;
    border: 2px solid var(--brown);
}

#header h1 {
    font-size: 14px;
    color: var(--brown);
    letter-spacing: 2px;
    text-shadow: 1px 1px 0 rgba(255,255,255,0.5);
}

.subtitle {
    font-size: 9px;
    color: #8D6E63;
    margin-top: 4px;
    font-family: 'Share Tech Mono', monospace;
}

#status-led {
    display: flex;
    align-items: center;
    gap: 8px;
}

#led-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--led-red);
    box-shadow: 0 0 8px var(--led-red), 0 0 16px var(--led-red);
    border: 1px solid #333;
    animation: led-pulse 2s ease-in-out infinite;
}

#led-dot.running {
    background: var(--led-green);
    box-shadow: 0 0 8px var(--led-green), 0 0 16px var(--led-green);
}

#led-dot.paused {
    background: var(--led-yellow);
    box-shadow: 0 0 8px var(--led-yellow), 0 0 16px var(--led-yellow);
}

@keyframes led-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

#led-label {
    font-size: 7px;
    color: var(--brown);
}

/* Cartridge Slot */
#cartridge-slot {
    margin-bottom: 12px;
}

#drop-zone {
    background: linear-gradient(180deg, #1A1A1A, #333);
    border: 3px solid var(--brown);
    border-radius: 8px;
    padding: 16px;
    text-align: center;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: all 0.3s;
}

#drop-zone:hover {
    border-color: #FBC02D;
}

#drop-zone.drag-over {
    border-color: var(--led-green);
    background: linear-gradient(180deg, #1A2A1A, #2A3A2A);
}

#slot-glow {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    opacity: 0;
    background: radial-gradient(ellipse at center, rgba(0,230,118,0.15), transparent 70%);
    transition: opacity 0.5s;
    pointer-events: none;
}

#drop-zone.loaded #slot-glow {
    opacity: 1;
    animation: glow-pulse 3s ease-in-out infinite;
}

@keyframes glow-pulse {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 0.8; }
}

.slot-lines {
    height: 3px;
    background: repeating-linear-gradient(90deg, #555 0px, #555 8px, transparent 8px, transparent 12px);
    margin: 8px 0;
}

.drop-text {
    color: #CCC;
    font-size: 10px;
    margin: 4px 0;
}

.drop-sub {
    color: #888;
    font-size: 10px;
}

#rom-info {
    background: var(--terminal-bg);
    color: var(--green-glow);
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 10px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 6px;
    border: 1px solid #1A3A1A;
}

#eject-btn {
    background: var(--red-btn);
    color: white;
    border: 2px solid #B71C1C;
    border-radius: 4px;
    padding: 4px 10px;
    font-size: 7px;
    cursor: pointer;
    margin-left: auto;
}

#eject-btn:hover { background: #F44336; }
#eject-btn:active { transform: scale(0.95); }

/* Main Area */
#main-area {
    display: flex;
    gap: 12px;
}

#display-section {
    flex: 1;
    min-width: 0;
}

/* CRT Display */
#crt-bezel {
    background: linear-gradient(145deg, #2A2A2A, #111);
    border-radius: 20px;
    padding: 16px;
    border: 3px solid #444;
    box-shadow: inset 0 0 30px rgba(0,0,0,0.8);
}

#crt-screen {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    background: #000;
    border: 2px solid #333;
}

#canvas {
    display: block;
    width: 100%;
    height: auto;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

#scanlines {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent 0px,
        transparent 2px,
        rgba(0,0,0,0.15) 2px,
        rgba(0,0,0,0.15) 4px
    );
    pointer-events: none;
    z-index: 2;
}

#vignette {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: radial-gradient(ellipse at center, transparent 60%, rgba(0,0,0,0.5) 100%);
    pointer-events: none;
    z-index: 3;
}

/* Control Bar */
#control-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px;
    margin-top: 8px;
    background: var(--cream);
    border-radius: 8px;
    border: 2px solid var(--brown);
    flex-wrap: wrap;
}

.ctrl-btn {
    background: linear-gradient(180deg, #E0E0E0, #BDBDBD);
    border: 2px solid #888;
    border-bottom-width: 4px;
    border-radius: 4px;
    padding: 6px 10px;
    font-size: 7px;
    cursor: pointer;
    color: #333;
    text-transform: uppercase;
    white-space: nowrap;
}

.ctrl-btn:hover { background: linear-gradient(180deg, #EEE, #CCC); }
.ctrl-btn:active {
    border-bottom-width: 2px;
    transform: translateY(2px);
}

.ctrl-select {
    font-family: 'Press Start 2P', cursive;
    font-size: 7px;
    padding: 6px;
    border: 2px solid #888;
    border-radius: 4px;
    background: #E0E0E0;
    cursor: pointer;
}

/* Power Switch */
.power-switch {
    display: inline-block;
    cursor: pointer;
}

.power-switch input { display: none; }

.switch-body {
    display: inline-flex;
    align-items: center;
    background: linear-gradient(180deg, #999, #666);
    border: 2px solid #444;
    border-radius: 4px;
    padding: 4px 12px;
    transition: all 0.2s;
}

.switch-label {
    font-size: 7px;
    color: #DDD;
}

.power-switch input:checked + .switch-body {
    background: linear-gradient(180deg, #4CAF50, #2E7D32);
    border-color: #1B5E20;
    box-shadow: 0 0 8px rgba(76,175,80,0.5);
}

/* Audio Controls */
#audio-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    margin-top: 6px;
    background: var(--cream);
    border-radius: 8px;
    border: 2px solid var(--brown);
    flex-wrap: wrap;
}

#waveform-container {
    border: 1px solid #555;
    border-radius: 4px;
    background: var(--terminal-bg);
    overflow: hidden;
    flex-shrink: 0;
}

#waveform-canvas {
    display: block;
}

#volume-area {
    display: flex;
    align-items: center;
    gap: 6px;
}

.retro-slider {
    -webkit-appearance: none;
    width: 80px;
    height: 8px;
    background: #555;
    border-radius: 4px;
    outline: none;
}

.retro-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 20px;
    background: linear-gradient(180deg, #DDD, #999);
    border: 2px solid #666;
    border-radius: 3px;
    cursor: pointer;
}

#chaos-meter {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
}

.chaos-label {
    font-size: 7px;
    color: var(--red-btn);
}

.chaos-bar-bg {
    width: 60px;
    height: 10px;
    background: #333;
    border: 1px solid #555;
    border-radius: 3px;
    overflow: hidden;
}

.chaos-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #4CAF50, #FFEB3B, #FF5722, #D50000);
    transition: width 0.3s;
}

#chaos-value {
    font-size: 10px;
    color: var(--brown);
    font-family: 'Share Tech Mono', monospace;
    min-width: 20px;
}

/* Side Panel */
#side-panel {
    width: 300px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
}

.debug-panel {
    background: var(--terminal-bg);
    border: 2px solid #1A3A1A;
    border-radius: 6px;
    padding: 8px;
    color: var(--green-glow);
    font-size: 10px;
}

.debug-panel h3 {
    font-size: 7px;
    color: #00CC33;
    margin-bottom: 6px;
    border-bottom: 1px solid #1A3A1A;
    padding-bottom: 4px;
}

.debug-panel h4 {
    font-size: 6px;
    color: #009922;
    margin: 6px 0 4px;
}

.register-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 4px;
}

.reg {
    display: flex;
    justify-content: space-between;
    padding: 2px 4px;
    background: rgba(0,255,65,0.05);
    border: 1px solid #0A2A0A;
    border-radius: 2px;
}

.reg-name {
    font-size: 6px;
    color: #009922;
}

.reg-val {
    color: var(--green-glow);
    font-family: 'Share Tech Mono', monospace;
    font-size: 10px;
}

#disasm-lines {
    max-height: 100px;
    overflow-y: auto;
    font-family: 'Share Tech Mono', monospace;
    font-size: 9px;
    line-height: 1.5;
}

#disasm-lines::-webkit-scrollbar { width: 4px; }
#disasm-lines::-webkit-scrollbar-thumb { background: #1A4A1A; }

.disasm-line {
    padding: 1px 4px;
}

.disasm-current {
    background: rgba(0,255,65,0.15);
    color: #00FF88;
}

#hex-dump {
    max-height: 120px;
    overflow-y: auto;
    font-family: 'Share Tech Mono', monospace;
    font-size: 9px;
    line-height: 1.4;
    white-space: pre;
}

#hex-dump::-webkit-scrollbar { width: 4px; }
#hex-dump::-webkit-scrollbar-thumb { background: #1A4A1A; }

#sprite-info {
    font-family: 'Share Tech Mono', monospace;
    font-size: 9px;
    line-height: 1.5;
}

/* Controllers */
#controller-section {
    display: flex;
    justify-content: center;
    gap: 40px;
    padding: 12px;
    margin-top: 12px;
    background: var(--cream);
    border-radius: 12px;
    border: 2px solid var(--brown);
}

.controller {
    text-align: center;
}

.controller h4 {
    font-size: 7px;
    color: var(--brown);
    margin-bottom: 6px;
}

.paddle-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.paddle-canvas {
    cursor: grab;
    border-radius: 50%;
    border: 3px solid #666;
    background: #333;
    box-shadow: inset 0 2px 6px rgba(0,0,0,0.5);
}

.paddle-canvas:active { cursor: grabbing; }

.paddle-val {
    font-size: 10px;
    color: var(--brown);
    font-family: 'Share Tech Mono', monospace;
}

.action-buttons {
    display: flex;
    gap: 8px;
    margin-top: 6px;
    justify-content: center;
}

.action-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 3px solid;
    font-size: 8px;
    cursor: pointer;
    font-family: 'Press Start 2P', cursive;
    color: white;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

.btn-red {
    background: radial-gradient(circle at 35% 35%, #EF5350, #B71C1C);
    border-color: #7F0000;
    box-shadow: 0 4px 0 #7F0000, 0 6px 8px rgba(0,0,0,0.3);
}

.btn-red:active {
    box-shadow: 0 1px 0 #7F0000;
    transform: translateY(3px);
}

.btn-yellow {
    background: radial-gradient(circle at 35% 35%, #FFEE58, #F9A825);
    border-color: #F57F17;
    box-shadow: 0 4px 0 #E65100, 0 6px 8px rgba(0,0,0,0.3);
    color: #333;
}

.btn-yellow:active {
    box-shadow: 0 1px 0 #E65100;
    transform: translateY(3px);
}

.key-hint {
    font-size: 6px;
    color: #999;
    margin-top: 6px;
}

/* Footer */
#footer {
    text-align: center;
    padding: 12px;
    margin-top: 12px;
    font-size: 8px;
    color: #8D6E63;
    border-top: 1px solid #D7CCC8;
}

#footer a {
    color: var(--brown);
    text-decoration: none;
    font-family: 'Press Start 2P', cursive;
    font-size: 7px;
    display: inline-block;
    margin-top: 6px;
}

#footer a:hover { color: var(--red-btn); }

/* Modal */
.modal-overlay {
    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;
}

.modal-content {
    background: var(--beige);
    border: 3px solid var(--brown);
    border-radius: 12px;
    padding: 20px;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    color: var(--brown);
}

.modal-content h2 {
    font-family: 'Press Start 2P', cursive;
    font-size: 11px;
    margin-bottom: 12px;
}

.about-text {
    font-size: 11px;
    line-height: 1.7;
}

.about-text p { margin-bottom: 8px; }

.about-text ul {
    margin: 6px 0 6px 18px;
    font-size: 10px;
}

.about-note {
    font-style: italic;
    color: #8D6E63;
    margin-top: 12px;
}

.modal-content .ctrl-btn {
    margin-top: 12px;
}

/* Responsive */
@media (max-width: 900px) {
    #console-shell { flex-direction: column; margin: 8px; border-radius: 16px; }
    .wood-panel { width: 100%; min-height: 12px; border-right: none !important; border-left: none !important; border-bottom: 2px solid var(--dark-brown); }
    #wood-panel-right { border-bottom: none; border-top: 2px solid var(--dark-brown); }
    #main-area { flex-direction: column; }
    #side-panel { width: 100%; }
    #header h1 { font-size: 9px; }
    #controller-section { gap: 20px; }
    .register-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 500px) {
    #console-body { padding: 8px; }
    #header { flex-direction: column; gap: 6px; text-align: center; }
    #header h1 { font-size: 7px; letter-spacing: 1px; }
    #control-bar { justify-content: center; }
    #audio-controls { flex-direction: column; align-items: stretch; }
    #chaos-meter { margin-left: 0; justify-content: center; }
}