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

:root {
    --bg: #0a0a0a;
    --bg-panel: #111114;
    --bg-card: #18181c;
    --cyan: #00f0ff;
    --magenta: #ff00aa;
    --green: #39ff14;
    --yellow: #ffe600;
    --text: #e0e0e0;
    --text-dim: #666;
    --border: #2a2a2e;
    --font-mono: 'JetBrains Mono', 'Share Tech Mono', monospace;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-mono);
    min-height: 100vh;
    overflow-x: hidden;
}

/* Scanline overlay on body */
body::after {
    content: '';
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(0,0,0,0.03) 2px,
        rgba(0,0,0,0.03) 4px
    );
    pointer-events: none;
    z-index: 9999;
}

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

/* HEADER */
header {
    text-align: center;
    padding: 20px 0 10px;
}

.glitch-title {
    font-size: clamp(1.8rem, 6vw, 3.2rem);
    font-weight: 800;
    color: #fff;
    position: relative;
    display: inline-block;
    animation: glitch-skew 4s infinite linear alternate-reverse;
}

.glitch-title::before,
.glitch-title::after {
    content: attr(data-text);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.glitch-title::before {
    color: var(--cyan);
    animation: glitch-1 2s infinite linear alternate-reverse;
    clip-path: polygon(0 0, 100% 0, 100% 35%, 0 35%);
    z-index: -1;
}

.glitch-title::after {
    color: var(--magenta);
    animation: glitch-2 3s infinite linear alternate-reverse;
    clip-path: polygon(0 65%, 100% 65%, 100% 100%, 0 100%);
    z-index: -1;
}

@keyframes glitch-1 {
    0%, 80% { transform: translate(0); }
    82% { transform: translate(-3px, 1px); }
    84% { transform: translate(3px, -1px); }
    86% { transform: translate(-1px, 2px); }
    88%, 100% { transform: translate(0); }
}

@keyframes glitch-2 {
    0%, 70% { transform: translate(0); }
    72% { transform: translate(2px, -1px); }
    74% { transform: translate(-4px, 1px); }
    76% { transform: translate(1px, -2px); }
    78%, 100% { transform: translate(0); }
}

@keyframes glitch-skew {
    0%, 90% { transform: skewX(0deg); }
    92% { transform: skewX(0.5deg); }
    94% { transform: skewX(-0.3deg); }
    96% { transform: skewX(0.2deg); }
    98%, 100% { transform: skewX(0deg); }
}

.subtitle {
    font-size: 0.8rem;
    font-weight: 300;
    color: var(--text-dim);
    letter-spacing: 2px;
    text-transform: uppercase;
    margin-top: 4px;
}

/* CANVAS */
#canvas-wrapper {
    position: relative;
    margin: 16px auto;
    border-radius: 12px;
    overflow: hidden;
    border: 2px solid var(--border);
    box-shadow: 
        0 0 20px rgba(0, 240, 255, 0.1),
        0 0 60px rgba(255, 0, 170, 0.05),
        inset 0 0 80px rgba(0,0,0,0.5);
    animation: border-glow 3s ease-in-out infinite alternate;
    background: #000;
}

@keyframes border-glow {
    0% { border-color: rgba(0, 240, 255, 0.4); box-shadow: 0 0 15px rgba(0, 240, 255, 0.15), inset 0 0 80px rgba(0,0,0,0.5); }
    33% { border-color: rgba(255, 0, 170, 0.4); box-shadow: 0 0 15px rgba(255, 0, 170, 0.15), inset 0 0 80px rgba(0,0,0,0.5); }
    66% { border-color: rgba(57, 255, 20, 0.4); box-shadow: 0 0 15px rgba(57, 255, 20, 0.15), inset 0 0 80px rgba(0,0,0,0.5); }
    100% { border-color: rgba(0, 240, 255, 0.4); box-shadow: 0 0 15px rgba(0, 240, 255, 0.15), inset 0 0 80px rgba(0,0,0,0.5); }
}

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

#rec-indicator {
    position: absolute;
    top: 12px;
    left: 12px;
    font-size: 0.7rem;
    font-weight: 700;
    color: #ff2222;
    display: none;
    align-items: center;
    gap: 6px;
    z-index: 10;
    text-shadow: 0 0 8px rgba(255,0,0,0.6);
    letter-spacing: 2px;
}

#rec-indicator.active {
    display: flex;
}

.rec-dot {
    width: 8px;
    height: 8px;
    background: #ff2222;
    border-radius: 50%;
    animation: rec-blink 1s infinite;
    box-shadow: 0 0 6px #ff2222;
}

@keyframes rec-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.2; }
}

#flash-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: white;
    opacity: 0;
    pointer-events: none;
    z-index: 20;
    transition: opacity 0.1s;
}

#flash-overlay.flash {
    opacity: 0.8;
    transition: opacity 0s;
}

/* ACTION BAR */
#action-bar {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin: 12px 0;
    flex-wrap: wrap;
}

.action-btn {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    font-weight: 700;
    padding: 10px 24px;
    border: 2px solid var(--cyan);
    background: transparent;
    color: var(--cyan);
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.action-btn:hover {
    background: rgba(0, 240, 255, 0.1);
    box-shadow: 0 0 20px rgba(0, 240, 255, 0.3);
    transform: translateY(-1px);
}

.action-btn.active {
    background: rgba(0, 240, 255, 0.15);
    box-shadow: 0 0 25px rgba(0, 240, 255, 0.3);
}

.capture-btn {
    border-color: var(--magenta);
    color: var(--magenta);
}

.capture-btn:hover {
    background: rgba(255, 0, 170, 0.1);
    box-shadow: 0 0 20px rgba(255, 0, 170, 0.3);
}

.btn-icon {
    margin-right: 4px;
}

/* SECTION LABELS */
.section-label {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-dim);
    letter-spacing: 3px;
    text-transform: uppercase;
    margin-bottom: 10px;
    padding-left: 4px;
}

/* PRESETS */
#presets-bar {
    margin: 20px 0 16px;
}

#presets-container {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.preset-btn {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 700;
    padding: 8px 14px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text);
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
    white-space: nowrap;
}

.preset-btn:hover {
    border-color: var(--green);
    color: var(--green);
    box-shadow: 0 0 12px rgba(57, 255, 20, 0.2);
}

.preset-btn.active {
    border-color: var(--green);
    color: var(--green);
    background: rgba(57, 255, 20, 0.08);
}

/* EFFECTS PANEL */
#effects-panel {
    margin: 16px 0;
}

#effects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 10px;
}

.effect-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 14px;
    transition: all 0.2s;
}

.effect-card.active {
    border-color: var(--cyan);
    box-shadow: 0 0 12px rgba(0, 240, 255, 0.1);
}

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

.effect-name {
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.effect-toggle {
    width: 42px;
    height: 22px;
    border-radius: 11px;
    border: 2px solid var(--border);
    background: var(--bg);
    cursor: pointer;
    position: relative;
    transition: all 0.2s;
    flex-shrink: 0;
}

.effect-toggle::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--text-dim);
    transition: all 0.2s;
}

.effect-toggle.on {
    border-color: var(--cyan);
    background: rgba(0, 240, 255, 0.15);
}

.effect-toggle.on::after {
    left: 22px;
    background: var(--cyan);
    box-shadow: 0 0 8px var(--cyan);
}

.effect-sliders {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.slider-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.slider-label {
    font-size: 0.6rem;
    color: var(--text-dim);
    min-width: 50px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.slider-val {
    font-size: 0.6rem;
    color: var(--cyan);
    min-width: 28px;
    text-align: right;
}

/* Custom range slider */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    flex: 1;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    background: var(--cyan);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 6px rgba(0, 240, 255, 0.5);
    transition: box-shadow 0.2s;
}

input[type="range"]::-webkit-slider-thumb:hover {
    box-shadow: 0 0 12px rgba(0, 240, 255, 0.8);
}

input[type="range"]::-moz-range-thumb {
    width: 14px;
    height: 14px;
    background: var(--cyan);
    border-radius: 50%;
    border: none;
    cursor: pointer;
    box-shadow: 0 0 6px rgba(0, 240, 255, 0.5);
}

/* FOOTER */
footer {
    text-align: center;
    padding: 30px 0 16px;
    font-size: 0.65rem;
    color: var(--text-dim);
    letter-spacing: 1px;
}

footer a {
    color: var(--cyan);
    text-decoration: none;
    transition: color 0.2s;
}

footer a:hover {
    color: var(--magenta);
    text-shadow: 0 0 8px rgba(255, 0, 170, 0.4);
}

/* Test pattern fallback */
#test-pattern-msg {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.65rem;
    color: var(--yellow);
    background: rgba(0,0,0,0.7);
    padding: 4px 12px;
    border-radius: 4px;
    z-index: 10;
    white-space: nowrap;
}

/* Mobile adjustments */
@media (max-width: 600px) {
    #app {
        padding: 8px;
    }
    
    #effects-grid {
        grid-template-columns: 1fr;
    }
    
    .action-btn {
        font-size: 0.75rem;
        padding: 8px 16px;
    }
    
    .preset-btn {
        font-size: 0.6rem;
        padding: 6px 10px;
    }
}