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

:root {
    --bg: #0a0a0a;
    --panel: #161616;
    --panel-border: #2a2a2a;
    --cyan: #00FFFF;
    --magenta: #FF00FF;
    --yellow: #FFFF00;
    --green: #00FF00;
    --red: #FF0000;
    --white: #FFFFFF;
    --dim: #888888;
    --text: #cccccc;
}

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

body::before {
    content: '';
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(255,255,255,0.008) 2px,
        rgba(255,255,255,0.008) 4px
    );
    pointer-events: none;
    z-index: 9999;
}

#app {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 16px;
}

/* Header */
header {
    padding-top: 8px;
}

.rainbow-bar {
    height: 4px;
    background: linear-gradient(90deg, 
        var(--red) 0%, var(--yellow) 16%, var(--green) 33%, 
        var(--cyan) 50%, #0000FF 66%, var(--magenta) 83%, var(--red) 100%
    );
    background-size: 200% 100%;
    animation: rainbowSlide 4s linear infinite;
}

@keyframes rainbowSlide {
    0% { background-position: 0% 0; }
    100% { background-position: 200% 0; }
}

.header-content {
    text-align: center;
    padding: 24px 16px 16px;
    position: relative;
}

.header-content h1 {
    font-family: 'Press Start 2P', monospace;
    font-size: clamp(10px, 2.2vw, 18px);
    color: var(--white);
    text-shadow: 0 0 20px rgba(0, 255, 255, 0.4);
    margin-bottom: 12px;
    line-height: 1.6;
}

.subtitle {
    font-size: 13px;
    color: var(--dim);
    font-style: italic;
}

.loading-stripes {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 40px;
    background: repeating-linear-gradient(
        0deg,
        var(--red) 0px, var(--red) 3px,
        var(--yellow) 3px, var(--yellow) 6px,
        var(--green) 6px, var(--green) 9px,
        var(--cyan) 9px, var(--cyan) 12px,
        #0000FF 12px, #0000FF 15px
    );
    background-size: 100% 30px;
    animation: stripeScroll 0.8s linear infinite;
    border: 1px solid var(--dim);
}

@keyframes stripeScroll {
    0% { background-position: 0 0; }
    100% { background-position: 0 30px; }
}

/* Drop Zone */
.drop-zone {
    border: 3px dashed var(--magenta);
    border-radius: 4px;
    padding: 60px 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
    margin: 24px auto;
    max-width: 600px;
    background: rgba(255, 0, 255, 0.03);
    animation: dropPulse 3s ease-in-out infinite;
}

@keyframes dropPulse {
    0%, 100% { border-color: var(--magenta); box-shadow: 0 0 0 rgba(255,0,255,0); }
    50% { border-color: var(--cyan); box-shadow: 0 0 30px rgba(0,255,255,0.1); }
}

.drop-zone:hover, .drop-zone.drag-over {
    border-color: var(--cyan);
    background: rgba(0, 255, 255, 0.05);
    animation: none;
}

.drop-icon {
    margin-bottom: 16px;
}

.drop-text {
    font-family: 'Press Start 2P', monospace;
    font-size: 11px;
    color: var(--white);
    margin-bottom: 8px;
}

.drop-formats {
    font-size: 12px;
    color: var(--dim);
}

/* Sample section */
.sample-section {
    text-align: center;
    margin-bottom: 32px;
}

.sample-label {
    font-size: 12px;
    color: var(--dim);
    margin-bottom: 8px;
}

.sample-buttons {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
}

.sample-btn {
    font-family: 'Press Start 2P', monospace;
    font-size: 9px;
    padding: 8px 14px;
    background: transparent;
    border: 2px solid var(--yellow);
    color: var(--yellow);
    cursor: pointer;
    transition: all 0.15s;
}

.sample-btn:hover {
    background: var(--yellow);
    color: var(--bg);
}

/* Processing View */
.processing-view {
    margin-top: 16px;
}

.processing-view.hidden, .hidden {
    display: none !important;
}

.canvas-area {
    display: flex;
    gap: 16px;
    margin-bottom: 16px;
}

.canvas-panel {
    flex: 1;
    min-width: 0;
}

.canvas-panel h3 {
    font-family: 'Press Start 2P', monospace;
    font-size: 9px;
    color: var(--cyan);
    margin-bottom: 8px;
    text-align: center;
}

.canvas-wrapper {
    background: #000;
    border: 2px solid var(--panel-border);
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    min-height: 200px;
}

.canvas-wrapper canvas {
    max-width: 100%;
    height: auto;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

.crt-glow {
    box-shadow: 0 0 30px rgba(0, 255, 255, 0.08), inset 0 0 60px rgba(0,0,0,0.3);
}

.scanline-overlay {
    position: absolute;
    top: 4px; left: 4px; right: 4px; bottom: 4px;
    background: repeating-linear-gradient(
        0deg,
        transparent 0px,
        transparent 2px,
        rgba(0,0,0,0.25) 2px,
        rgba(0,0,0,0.25) 4px
    );
    pointer-events: none;
}

/* View toggles */
.view-toggles {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-bottom: 16px;
}

.toggle-btn {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 11px;
    font-weight: 500;
    padding: 6px 16px;
    background: transparent;
    border: 1px solid var(--panel-border);
    color: var(--dim);
    cursor: pointer;
    transition: all 0.15s;
}

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

.toggle-btn.active {
    background: var(--cyan);
    color: var(--bg);
    border-color: var(--cyan);
}

/* Processing indicator */
.processing-indicator {
    text-align: center;
    padding: 12px;
    color: var(--yellow);
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.zx-loading {
    width: 24px;
    height: 24px;
    background: repeating-linear-gradient(
        0deg,
        var(--red) 0px, var(--red) 3px,
        var(--cyan) 3px, var(--cyan) 6px,
        var(--yellow) 6px, var(--yellow) 9px,
        var(--green) 9px, var(--green) 12px
    );
    background-size: 100% 24px;
    animation: stripeScroll 0.4s linear infinite;
}

/* Presets bar */
.presets-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 0;
    overflow-x: auto;
    flex-wrap: wrap;
}

.presets-label {
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
    color: var(--dim);
    white-space: nowrap;
}

.preset-btn {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 10px;
    font-weight: 500;
    padding: 5px 10px;
    background: var(--panel);
    border: 1px solid var(--green);
    color: var(--green);
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.preset-btn:hover {
    background: var(--green);
    color: var(--bg);
}

/* Controls Panel */
.controls-panel {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    padding: 16px;
    margin-bottom: 16px;
}

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

.controls-header h3 {
    font-family: 'Press Start 2P', monospace;
    font-size: 10px;
    color: var(--magenta);
}

.controls-header-buttons {
    display: flex;
    align-items: center;
    gap: 16px;
}

.live-toggle {
    font-size: 11px;
    color: var(--dim);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
}

.live-toggle input {
    accent-color: var(--green);
}

.controls-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.control-group label {
    font-size: 10px;
    font-weight: 500;
    color: var(--cyan);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.control-group input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: var(--panel-border);
    outline: none;
    border-radius: 0;
}

.control-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: var(--magenta);
    cursor: pointer;
    border: 2px solid var(--white);
}

.control-group input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: var(--magenta);
    cursor: pointer;
    border: 2px solid var(--white);
    border-radius: 0;
}

.val {
    font-size: 11px;
    color: var(--yellow);
    font-weight: 700;
}

.control-group select {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--panel-border);
    padding: 6px 8px;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 12px;
}

.toggle-group {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
}

.switch-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

.switch-label {
    font-size: 10px;
    color: var(--dim);
}

.switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 20px;
}

.switch input { opacity: 0; width: 0; height: 0; }

.switch .slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background: #333;
    transition: 0.2s;
    border: 1px solid var(--dim);
}

.switch .slider::before {
    content: '';
    position: absolute;
    width: 14px;
    height: 14px;
    left: 2px;
    bottom: 2px;
    background: var(--dim);
    transition: 0.2s;
}

.switch input:checked + .slider {
    background: rgba(0, 255, 0, 0.2);
    border-color: var(--green);
}

.switch input:checked + .slider::before {
    transform: translateX(20px);
    background: var(--green);
}

/* Action Buttons */
.action-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.action-btn {
    font-family: 'Press Start 2P', monospace;
    font-size: 9px;
    padding: 10px 16px;
    background: transparent;
    border: 2px solid var(--cyan);
    color: var(--cyan);
    cursor: pointer;
    transition: all 0.15s;
    text-transform: uppercase;
}

.action-btn:hover {
    background: var(--cyan);
    color: var(--bg);
}

.action-btn.primary {
    background: var(--magenta);
    border-color: var(--magenta);
    color: var(--white);
}

.action-btn.primary:hover {
    background: var(--white);
    color: var(--magenta);
}

.action-btn.danger {
    border-color: var(--red);
    color: var(--red);
}

.action-btn.danger:hover {
    background: var(--red);
    color: var(--white);
}

/* Info Panel */
.info-panel {
    margin-bottom: 16px;
}

.info-toggle {
    width: 100%;
    background: var(--panel);
    border: 1px solid var(--panel-border);
    color: var(--yellow);
    padding: 12px 16px;
    font-family: 'Press Start 2P', monospace;
    font-size: 9px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.15s;
}

.info-toggle:hover {
    border-color: var(--yellow);
}

.info-toggle .arrow {
    transition: transform 0.3s;
}

.info-toggle.open .arrow {
    transform: rotate(180deg);
}

.info-content {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-top: none;
    padding: 20px;
}

.info-section {
    margin-bottom: 16px;
}

.info-section h4 {
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
    color: var(--cyan);
    margin-bottom: 8px;
    line-height: 1.6;
}

.info-section p {
    font-size: 12px;
    line-height: 1.7;
    color: var(--dim);
}

.info-table table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
    margin-top: 12px;
}

.info-table th {
    background: rgba(0, 255, 255, 0.1);
    color: var(--cyan);
    padding: 8px;
    text-align: left;
    border: 1px solid var(--panel-border);
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
}

.info-table td {
    padding: 8px;
    border: 1px solid var(--panel-border);
    color: var(--dim);
}

/* Pixel Inspector */
.pixel-inspector {
    position: fixed;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.92);
    border: 1px solid var(--cyan);
    padding: 8px 14px;
    font-size: 10px;
    z-index: 100;
    white-space: nowrap;
    pointer-events: none;
}

.inspector-label {
    color: var(--cyan);
    margin-right: 8px;
}

#inspectorData {
    color: var(--yellow);
}

/* Footer */
footer {
    text-align: center;
    padding: 24px 0;
    margin-top: 32px;
}

.rainbow-stripe {
    height: 4px;
    background: linear-gradient(90deg, 
        var(--red), var(--yellow), var(--green), 
        var(--cyan), #0000FF, var(--magenta), var(--red)
    );
    margin-bottom: 16px;
}

.footer-text {
    font-size: 12px;
    color: var(--dim);
    margin-bottom: 8px;
}

.footer-link a {
    font-family: 'Press Start 2P', monospace;
    font-size: 10px;
    color: var(--magenta);
    text-decoration: none;
}

.footer-link a:hover {
    color: var(--cyan);
}

.footer-disclaimer {
    font-size: 10px;
    color: #444;
    margin-top: 8px;
    font-style: italic;
}

.footer-keys {
    font-size: 10px;
    color: #333;
    margin-top: 4px;
}

/* Signal tuning animation */
@keyframes signalTune {
    0% { transform: skewX(0deg) translateX(0); filter: brightness(1); }
    10% { transform: skewX(2deg) translateX(-3px); filter: brightness(1.3); }
    20% { transform: skewX(-1deg) translateX(2px); filter: brightness(0.8); }
    30% { transform: skewX(1.5deg) translateX(-1px); filter: brightness(1.1); }
    50% { transform: skewX(-0.5deg) translateX(1px); filter: brightness(0.9); }
    100% { transform: skewX(0deg) translateX(0); filter: brightness(1); }
}

.signal-tuning {
    animation: signalTune 0.5s ease-out;
}

/* Responsive */
@media (max-width: 768px) {
    .canvas-area {
        flex-direction: column;
    }

    .controls-grid {
        grid-template-columns: 1fr;
    }

    .action-buttons {
        flex-direction: column;
    }

    .action-btn {
        width: 100%;
        text-align: center;
    }

    .controls-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .presets-bar {
        justify-content: flex-start;
    }

    .header-content h1 {
        font-size: 10px;
    }
}