:root {
    --phosphor: #33ff33;
    --phosphor-dim: #1a8c1a;
    --phosphor-glow: rgba(51, 255, 51, 0.3);
    --bg: #0a0a0a;
    --panel-bg: #1a1a1a;
    --panel-border: #333;
    --metal: linear-gradient(180deg, #3a3a3a 0%, #1a1a1a 50%, #2a2a2a 100%);
    --metal-border: #555;
}

[data-theme="amber"] {
    --phosphor: #ffb000;
    --phosphor-dim: #8c6000;
    --phosphor-glow: rgba(255, 176, 0, 0.3);
}

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

body {
    font-family: 'IBM Plex Mono', monospace;
    background: var(--bg);
    color: var(--phosphor);
    min-height: 100vh;
    overflow-x: hidden;
}

#crt-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    pointer-events: none;
    z-index: 9999;
    background: radial-gradient(ellipse at center, transparent 60%, rgba(0,0,0,0.4) 100%);
}

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

@keyframes flicker {
    0% { opacity: 1; }
    5% { opacity: 0.97; }
    10% { opacity: 1; }
    15% { opacity: 0.98; }
    20% { opacity: 1; }
    80% { opacity: 1; }
    85% { opacity: 0.96; }
    90% { opacity: 1; }
    95% { opacity: 0.99; }
    100% { opacity: 1; }
}

body.flicker-on {
    animation: flicker 4s infinite;
}

/* Header */
#header {
    background: var(--metal);
    border-bottom: 2px solid var(--metal-border);
    padding: 12px 20px;
    text-align: center;
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
}

.header-led {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--phosphor);
    box-shadow: 0 0 6px var(--phosphor-glow), 0 0 12px var(--phosphor-glow);
    animation: pulse-led 2s ease-in-out infinite;
}

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

#header h1 {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: 4px;
    text-shadow: 0 0 10px var(--phosphor-glow), 0 0 20px var(--phosphor-glow);
}

.header-subtitle {
    font-size: 0.65rem;
    color: var(--phosphor-dim);
    letter-spacing: 2px;
    width: 100%;
}

/* Main Layout */
#main-container {
    display: flex;
    gap: 0;
    min-height: calc(100vh - 200px);
}

/* Control Panel */
#control-panel {
    width: 280px;
    min-width: 280px;
    background: var(--metal);
    border-right: 2px solid var(--metal-border);
    padding: 12px;
    overflow-y: auto;
}

.panel-section {
    margin-bottom: 16px;
    padding: 10px;
    border: 1px solid var(--panel-border);
    border-radius: 4px;
    background: rgba(0,0,0,0.3);
}

.panel-title {
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 2px;
    color: var(--phosphor-dim);
    margin-bottom: 8px;
    border-bottom: 1px solid var(--panel-border);
    padding-bottom: 4px;
}

/* Drive Bay */
.drive-slot {
    background: #111;
    border: 2px solid #444;
    border-radius: 4px;
    padding: 16px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    overflow: hidden;
}

.drive-slot:hover {
    border-color: var(--phosphor-dim);
}

.drive-slot.drag-over {
    border-color: var(--phosphor);
    box-shadow: 0 0 10px var(--phosphor-glow);
}

.drive-slot.inserted {
    border-color: var(--phosphor);
}

.drive-slit {
    width: 80%;
    height: 4px;
    background: #000;
    border: 1px solid #333;
    margin: 0 auto 8px;
    border-radius: 2px;
}

.drive-label {
    font-size: 0.6rem;
    color: var(--phosphor-dim);
    letter-spacing: 1px;
}

@keyframes disk-insert {
    0% { transform: translateY(-20px); opacity: 0; }
    50% { transform: translateY(2px); }
    100% { transform: translateY(0); opacity: 1; }
}

.drive-slot.inserting .drive-slit {
    animation: disk-insert 0.5s ease-out;
    background: var(--phosphor-dim);
}

.drive-status {
    display: flex;
    gap: 16px;
    margin-top: 10px;
}

.led-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
}

.led {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #333;
    border: 1px solid #555;
    transition: all 0.3s;
}

.led.active {
    background: var(--phosphor);
    box-shadow: 0 0 6px var(--phosphor-glow), 0 0 12px var(--phosphor-glow);
}

.led.blink {
    animation: led-blink 0.15s ease-in-out infinite;
}

@keyframes led-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.led-label {
    font-size: 0.55rem;
    color: var(--phosphor-dim);
}

/* Buttons */
.button-row {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.hw-button {
    flex: 1;
    padding: 8px 12px;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 1px;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    transition: all 0.1s;
    text-transform: uppercase;
    position: relative;
    box-shadow: 0 3px 0 #000, inset 0 1px 0 rgba(255,255,255,0.1);
}

.hw-button:active {
    transform: translateY(2px);
    box-shadow: 0 1px 0 #000, inset 0 1px 0 rgba(255,255,255,0.1);
}

.hw-button.red { background: #8b0000; color: #ff4444; }
.hw-button.red:hover { background: #a00000; }
.hw-button.green { background: #006400; color: #44ff44; }
.hw-button.green:hover { background: #007800; }
.hw-button.yellow { background: #8b6900; color: #ffd700; }
.hw-button.yellow:hover { background: #a07800; }
.hw-button.toggle { background: #333; color: var(--phosphor); border: 1px solid var(--panel-border); }
.hw-button.toggle.active { background: #004400; border-color: var(--phosphor-dim); }
.hw-button.info { background: #222; color: var(--phosphor-dim); border: 1px solid var(--panel-border); }
.hw-button.info:hover { border-color: var(--phosphor-dim); }

/* DIP Switches */
.dip-switch-panel {
    display: flex;
    gap: 4px;
    justify-content: center;
    padding: 8px;
    background: #000;
    border: 1px solid #444;
    border-radius: 3px;
}

.dip-switch {
    width: 16px;
    height: 32px;
    background: #222;
    border: 1px solid #555;
    border-radius: 2px;
    cursor: pointer;
    position: relative;
    display: flex;
    flex-direction: column;
}

.dip-switch::after {
    content: '';
    position: absolute;
    width: 10px;
    height: 12px;
    background: #ccc;
    border-radius: 2px;
    left: 50%;
    transform: translateX(-50%);
    transition: all 0.15s;
    bottom: 3px;
}

.dip-switch.on::after {
    bottom: auto;
    top: 3px;
    background: var(--phosphor);
}

.dip-value {
    font-size: 0.6rem;
    text-align: center;
    margin-top: 6px;
    color: var(--phosphor-dim);
}

/* Options */
.option-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.option-label {
    font-size: 0.6rem;
    color: var(--phosphor-dim);
}

.toggle-btn {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.55rem;
    padding: 3px 8px;
    background: #222;
    color: var(--phosphor);
    border: 1px solid var(--panel-border);
    border-radius: 2px;
    cursor: pointer;
}

.toggle-btn:hover {
    border-color: var(--phosphor-dim);
}

/* Terminal */
#terminal-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.terminal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 12px;
    background: #111;
    border-bottom: 1px solid var(--panel-border);
}

.terminal-title {
    font-size: 0.6rem;
    letter-spacing: 2px;
    color: var(--phosphor-dim);
}

.terminal-clock {
    font-size: 0.6rem;
    color: var(--phosphor);
}

.terminal {
    flex: 1;
    background: #000;
    padding: 12px;
    overflow-y: auto;
    font-size: 0.75rem;
    line-height: 1.5;
    position: relative;
    min-height: 400px;
    white-space: pre-wrap;
    word-break: break-all;
}

.terminal .line {
    display: block;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

.cursor {
    animation: blink 1s step-end infinite;
    color: var(--phosphor);
}

/* Status Bar */
#status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 12px;
    background: var(--metal);
    border-top: 2px solid var(--metal-border);
    font-size: 0.6rem;
    flex-wrap: wrap;
    gap: 8px;
}

.status-section {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.cpu-regs-grid {
    gap: 6px;
}

.reg {
    color: var(--phosphor-dim);
}

.reg span {
    color: var(--phosphor);
    font-weight: 700;
}

.reg.seg span {
    color: var(--phosphor-dim);
    opacity: 0.8;
}

.reg.flags span {
    color: var(--phosphor);
    letter-spacing: 1px;
    font-size: 0.55rem;
}

#disk-activity {
    color: var(--phosphor-dim);
}

#disk-activity.active {
    color: var(--phosphor);
    text-shadow: 0 0 5px var(--phosphor-glow);
}

/* Hex Panel */
#hex-panel {
    background: #111;
    border-top: 1px solid var(--panel-border);
}

#hex-panel.collapsed .hex-body {
    display: none;
}

.hex-header {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 0.65rem;
    color: var(--phosphor-dim);
    border-bottom: 1px solid var(--panel-border);
}

.hex-header:hover {
    color: var(--phosphor);
}

#hex-panel:not(.collapsed) .hex-header span::before {
    content: '▼ ';
}

#hex-panel.collapsed .hex-header span::before {
    content: '▶ ';
}

.hex-header span::before {
    content: '';
}

.hex-body {
    padding: 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.hex-meta {
    font-size: 0.65rem;
    color: var(--phosphor-dim);
    width: 100%;
}

.hex-meta p {
    margin-bottom: 2px;
}

.hex-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
}

.hex-btn {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.6rem;
    padding: 4px 10px;
    background: #222;
    color: var(--phosphor);
    border: 1px solid var(--panel-border);
    cursor: pointer;
    border-radius: 2px;
}

.hex-btn:hover {
    border-color: var(--phosphor-dim);
}

#hex-sector-info {
    font-size: 0.6rem;
    color: var(--phosphor);
}

.hex-dump {
    font-size: 0.6rem;
    line-height: 1.6;
    flex: 1;
    min-width: 500px;
    white-space: pre;
    overflow-x: auto;
    color: var(--phosphor-dim);
}

.hex-dump .offset {
    color: var(--phosphor);
}

.hex-dump .ascii {
    color: var(--phosphor);
    opacity: 0.7;
}

#disk-geometry {
    border: 1px solid var(--panel-border);
    border-radius: 4px;
}

/* Footer */
#footer {
    text-align: center;
    padding: 8px 12px;
    font-size: 0.55rem;
    color: var(--phosphor-dim);
    border-top: 1px solid var(--panel-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#footer a {
    color: var(--phosphor-dim);
    text-decoration: none;
}

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

/* Modal */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: #1a1a1a;
    border: 2px solid var(--phosphor-dim);
    border-radius: 4px;
    padding: 24px;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 0 30px var(--phosphor-glow);
}

.modal-header {
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 2px;
    margin-bottom: 16px;
    color: var(--phosphor);
    text-shadow: 0 0 8px var(--phosphor-glow);
}

.modal-body {
    font-size: 0.7rem;
    line-height: 1.8;
    color: var(--phosphor-dim);
    margin-bottom: 16px;
}

.modal-body p {
    margin-bottom: 8px;
}

.modal-footer-text {
    font-size: 0.6rem;
    color: var(--phosphor);
    opacity: 0.5;
}

/* Responsive */
@media (max-width: 768px) {
    #main-container {
        flex-direction: column;
    }

    #control-panel {
        width: 100%;
        min-width: unset;
        border-right: none;
        border-bottom: 2px solid var(--metal-border);
        max-height: 300px;
        overflow-y: auto;
    }

    .terminal {
        min-height: 300px;
    }

    .hex-dump {
        min-width: unset;
        font-size: 0.5rem;
    }

    #status-bar {
        font-size: 0.5rem;
    }

    .status-section {
        gap: 6px;
    }
}