:root {
    --bg-primary: #0a0a0a;
    --bg-secondary: #111111;
    --bg-tertiary: #1a1a1a;
    --bg-panel: #0d0d0d;
    --border: #2a2a2a;
    --border-glow: #00ff4120;
    --text-primary: #00ff41;
    --text-secondary: #00cc33;
    --text-dim: #006622;
    --text-muted: #444;
    --accent: #00ff41;
    --accent-dim: #00aa2a;
    --highlight: #ffff00;
    --error: #ff4444;
    --warning: #ffaa00;
    --read-color: #4488ff;
    --write-color: #ff4444;
    --breakpoint: #ff0044;
    --font-mono: 'Fira Code', 'IBM Plex Mono', 'Courier New', monospace;
    --scanline-opacity: 0.03;
}

[data-theme="amber"] {
    --text-primary: #ffb000;
    --text-secondary: #cc8800;
    --text-dim: #664400;
    --accent: #ffb000;
    --accent-dim: #aa7700;
    --border-glow: #ffb00020;
}

[data-theme="blue"] {
    --text-primary: #00aaff;
    --text-secondary: #0088cc;
    --text-dim: #004466;
    --accent: #00aaff;
    --accent-dim: #0077aa;
    --border-glow: #00aaff20;
}

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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 12px;
}

#app {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* Scanline overlay */
.scanlines::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(0, 0, 0, var(--scanline-opacity)) 2px,
        rgba(0, 0, 0, var(--scanline-opacity)) 4px
    );
    z-index: 10000;
}

/* Header */
.header {
    display: flex;
    align-items: center;
    padding: 4px 8px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    gap: 6px;
    flex-shrink: 0;
    min-height: 36px;
    flex-wrap: wrap;
}

.header-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--accent);
    text-shadow: 0 0 10px var(--accent);
    white-space: nowrap;
    margin-right: 8px;
}

.toolbar-btn {
    padding: 3px 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 11px;
    cursor: pointer;
    border-radius: 2px;
    transition: all 0.15s;
    white-space: nowrap;
}

.toolbar-btn:hover {
    background: var(--accent-dim);
    color: var(--bg-primary);
    border-color: var(--accent);
    box-shadow: 0 0 6px var(--accent);
}

.toolbar-btn:active {
    transform: scale(0.97);
}

.toolbar-btn.active {
    background: var(--accent);
    color: var(--bg-primary);
}

.toolbar-btn.danger {
    border-color: var(--error);
    color: var(--error);
}

.toolbar-btn.danger:hover {
    background: var(--error);
    color: white;
}

.header-info {
    font-size: 10px;
    color: var(--text-dim);
    white-space: nowrap;
}

.header-info span {
    color: var(--text-secondary);
}

.speed-control {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 10px;
    color: var(--text-dim);
}

.speed-control input[type="range"] {
    width: 60px;
    accent-color: var(--accent);
    height: 12px;
}

.theme-select {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 10px;
    padding: 2px 4px;
    cursor: pointer;
}

.example-select {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 10px;
    padding: 2px 4px;
    cursor: pointer;
    max-width: 140px;
}

/* Main layout */
.main-container {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.panel {
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    overflow: hidden;
}

.panel:last-child {
    border-right: none;
}

.panel-header {
    padding: 3px 8px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    font-size: 10px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.panel-body {
    flex: 1;
    overflow: auto;
    background: var(--bg-panel);
}

/* Code editor */
.code-editor-wrap {
    position: relative;
    flex: 1;
    overflow: hidden;
    display: flex;
}

.line-numbers {
    padding: 4px 4px 4px 2px;
    text-align: right;
    color: var(--text-dim);
    font-size: 11px;
    line-height: 1.5;
    user-select: none;
    min-width: 30px;
    border-right: 1px solid var(--border);
    overflow: hidden;
    background: var(--bg-secondary);
}

.code-textarea {
    flex: 1;
    background: transparent;
    color: var(--text-primary);
    border: none;
    outline: none;
    resize: none;
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 1.5;
    padding: 4px 8px;
    tab-size: 8;
    white-space: pre;
    overflow: auto;
}

.code-textarea::placeholder {
    color: var(--text-dim);
}

/* Error display */
.error-bar {
    padding: 4px 8px;
    background: #1a0000;
    border-top: 1px solid var(--error);
    color: var(--error);
    font-size: 10px;
    flex-shrink: 0;
    max-height: 60px;
    overflow-y: auto;
}

/* Disassembly view */
.disasm-line {
    display: flex;
    padding: 1px 8px;
    font-size: 11px;
    line-height: 1.5;
    cursor: pointer;
    border-left: 3px solid transparent;
}

.disasm-line:hover {
    background: var(--bg-tertiary);
}

.disasm-line.current {
    background: #002200;
    border-left-color: var(--accent);
}

.disasm-line.breakpoint {
    border-left-color: var(--breakpoint);
}

.disasm-line.breakpoint .disasm-addr::before {
    content: '●';
    color: var(--breakpoint);
    margin-right: 4px;
}

.disasm-addr {
    color: var(--text-dim);
    min-width: 70px;
    flex-shrink: 0;
}

.disasm-bytes {
    color: var(--text-muted);
    min-width: 80px;
    flex-shrink: 0;
}

.disasm-mnemonic {
    color: var(--accent);
    font-weight: 500;
}

/* Register display */
.reg-section {
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
}

.reg-section-title {
    font-size: 9px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 3px;
}

.reg-row {
    display: flex;
    align-items: center;
    padding: 1px 0;
    font-size: 11px;
    gap: 4px;
}

.reg-name {
    color: var(--text-secondary);
    min-width: 24px;
    font-weight: 600;
}

.reg-value {
    color: var(--text-primary);
    font-weight: 500;
    transition: color 0.3s, text-shadow 0.3s;
    min-width: 40px;
}

.reg-value.changed {
    color: var(--highlight);
    text-shadow: 0 0 8px var(--highlight);
}

.reg-sub {
    color: var(--text-dim);
    font-size: 10px;
}

/* Flags */
.flags-row {
    display: flex;
    gap: 2px;
    flex-wrap: wrap;
    padding: 4px 0;
}

.flag-indicator {
    width: 22px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    font-weight: 700;
    border: 1px solid var(--border);
    border-radius: 2px;
    transition: all 0.3s;
}

.flag-indicator.active {
    background: var(--accent);
    color: var(--bg-primary);
    border-color: var(--accent);
    box-shadow: 0 0 6px var(--accent);
}

.flag-indicator.inactive {
    background: var(--bg-tertiary);
    color: var(--text-muted);
}

.flag-indicator.changed {
    animation: flagFlash 0.5s ease;
}

@keyframes flagFlash {
    0%, 100% { }
    50% { box-shadow: 0 0 12px var(--highlight); border-color: var(--highlight); }
}

/* Stack view */
.stack-entry {
    display: flex;
    padding: 1px 8px;
    font-size: 11px;
    gap: 8px;
}

.stack-entry.top {
    background: #001a00;
    font-weight: 600;
}

.stack-addr {
    color: var(--text-dim);
    min-width: 50px;
}

.stack-val {
    color: var(--text-primary);
}

/* Bottom panels */
.bottom-container {
    display: flex;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    height: 180px;
    min-height: 100px;
}

.bottom-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.bottom-panel + .bottom-panel {
    border-left: 1px solid var(--border);
}

/* Memory viewer */
.mem-controls {
    display: flex;
    gap: 4px;
    padding: 3px 8px;
    align-items: center;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.mem-addr-input {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 11px;
    padding: 2px 6px;
    width: 80px;
    outline: none;
}

.mem-addr-input:focus {
    border-color: var(--accent);
}

.mem-jump-btn {
    font-size: 9px;
    padding: 2px 5px;
}

.hex-view {
    flex: 1;
    overflow: auto;
    padding: 2px 8px;
    font-size: 11px;
    line-height: 1.4;
}

.hex-line {
    display: flex;
    white-space: nowrap;
}

.hex-addr {
    color: var(--text-dim);
    min-width: 55px;
    margin-right: 8px;
}

.hex-bytes {
    margin-right: 8px;
    flex-shrink: 0;
}

.hex-byte {
    display: inline-block;
    width: 22px;
    text-align: center;
    color: var(--text-primary);
}

.hex-byte.read {
    color: var(--read-color);
    text-shadow: 0 0 4px var(--read-color);
}

.hex-byte.written {
    color: var(--write-color);
    text-shadow: 0 0 4px var(--write-color);
}

.hex-ascii {
    color: var(--text-dim);
}

.hex-ascii .printable {
    color: var(--text-secondary);
}

/* Console */
.console-output {
    flex: 1;
    overflow: auto;
    padding: 4px 8px;
    font-size: 12px;
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-all;
    color: var(--text-primary);
    background: var(--bg-primary);
    text-shadow: 0 0 4px var(--accent);
}

.console-cursor {
    display: inline-block;
    width: 7px;
    height: 14px;
    background: var(--accent);
    animation: blink 1s step-end infinite;
}

@keyframes blink {
    50% { opacity: 0; }
}

/* Execution log */
.exec-log {
    flex: 1;
    overflow: auto;
    padding: 2px 8px;
    font-size: 10px;
}

.exec-log-entry {
    color: var(--text-dim);
    border-bottom: 1px solid #111;
    padding: 1px 0;
}

.exec-log-entry .log-addr {
    color: var(--text-secondary);
}

/* Footer */
.footer {
    padding: 2px 8px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    font-size: 9px;
    color: var(--text-dim);
    display: flex;
    justify-content: space-between;
    flex-shrink: 0;
}

.footer a {
    color: var(--text-secondary);
    text-decoration: none;
}

.footer a:hover {
    color: var(--accent);
    text-decoration: underline;
}

/* Tabs for bottom panel */
.tab-bar {
    display: flex;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.tab-btn {
    padding: 2px 10px;
    font-size: 10px;
    font-family: var(--font-mono);
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    border-bottom: 2px solid transparent;
}

.tab-btn.active {
    color: var(--text-primary);
    border-bottom-color: var(--accent);
}

.tab-btn:hover {
    color: var(--text-secondary);
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-dim);
}

/* Mobile responsive */
@media (max-width: 900px) {
    .main-container {
        flex-direction: column;
    }
    .panel {
        border-right: none;
        border-bottom: 1px solid var(--border);
        min-height: 150px;
        max-height: 300px;
    }
    .bottom-container {
        flex-direction: column;
        height: auto;
    }
    .bottom-panel {
        min-height: 120px;
    }
    .bottom-panel + .bottom-panel {
        border-left: none;
        border-top: 1px solid var(--border);
    }
}

/* HLT indicator */
.hlt-indicator {
    color: var(--warning);
    font-size: 10px;
    font-weight: 700;
    margin-left: 8px;
    animation: hltBlink 1s step-end infinite;
}

@keyframes hltBlink {
    50% { opacity: 0.3; }
}