:root {
    --brand: #4af626;
    --brand-dim: rgba(74, 246, 38, 0.2);
    --brand-glow: rgba(74, 246, 38, 0.5);
    --ghost: #ff00ff;
    --ghost-glow: rgba(255, 0, 255, 0.6);
    --bg-dark: #050505;
    --bg-panel: #111111;
    --text-main: #f0f0f0;
    --font-ui: 'Inter', sans-serif;
    --font-data: 'Space Mono', monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body, html {
    margin: 0; padding: 0; width: 100vw; height: 100dvh;
    background-color: var(--bg-dark); color: var(--text-main);
    font-family: var(--font-ui); overflow: hidden; 
    overscroll-behavior: none; user-select: none; -webkit-user-select: none;
}

.view { position: absolute; inset: 0; display: flex; flex-direction: column; opacity: 0; pointer-events: none; transition: opacity 0.3s ease; }
.view.active { opacity: 1; pointer-events: auto; }

.scanlines { position: absolute; inset: 0; pointer-events: none; z-index: 100; background: linear-gradient(rgba(18,16,16,0) 50%, rgba(0,0,0,0.2) 50%); background-size: 100% 4px; mix-blend-mode: multiply;}
.vignette { position: absolute; inset: 0; pointer-events: none; z-index: 99; background: radial-gradient(circle, transparent 40%, #000 120%); }

/* --- VIEW 1: THE CRATE --- */
#view-crate { padding: 20px; padding-bottom: 100px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.crate-header { margin-bottom: 20px; border-bottom: 1px solid #333; padding-bottom: 15px; }
.crate-title { font-size: 28px; font-weight: 900; letter-spacing: -1px; margin: 0; color: #fff; }
.crate-sub { font-family: var(--font-data); font-size: 12px; color: var(--brand); letter-spacing: 2px; text-transform: uppercase; }

.grid-container { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 15px; padding-bottom: 20px; }

/* SETLIST UX STYLES */
.track-card { position: relative; background: var(--bg-panel); border-radius: 8px; overflow: hidden; border: 1px solid #222; transition: transform 0.2s, border-color 0.2s; display: flex; flex-direction: column; cursor: pointer; }
.track-card:active { transform: scale(0.98); }
.track-card.queued-card { border-color: var(--brand); }

.queue-badge {
    position: absolute; top: 10px; right: 10px; width: 28px; height: 28px;
    border-radius: 50%; border: 2px solid #333; background: rgba(0,0,0,0.8);
    color: var(--brand); font-family: var(--font-data); font-size: 12px; font-weight: 900;
    display: flex; align-items: center; justify-content: center;
    z-index: 10; transition: all 0.2s; cursor: pointer;
}
.queue-badge.queued { border-color: var(--brand); background: var(--brand); color: #000; box-shadow: 0 0 10px var(--brand-glow); }

.art-wrap { width: 100%; aspect-ratio: 1/1; background: #1a1a1a; position: relative; }
.art-wrap::before { content: 'NO ART'; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-family: var(--font-data); font-size: 10px; color: #444; z-index: 0; }
.art-wrap img { width: 100%; height: 100%; object-fit: cover; filter: grayscale(0.5) contrast(1.2); transition: filter 0.3s; position: relative; z-index: 1;}
.art-wrap:active img { filter: grayscale(0) contrast(1.2) sepia(1) hue-rotate(80deg); }

.track-info { padding: 12px; display: flex; flex-direction: column; flex: 1; justify-content: center; background: transparent; transition: background 0.2s;}
.track-info:active { background: rgba(255,255,255,0.05); }
.t-cat { font-family: var(--font-data); font-size: 10px; color: var(--brand); margin-bottom: 4px; pointer-events: none; }
.t-name { font-weight: 700; font-size: 14px; line-height: 1.2; margin: 0; pointer-events: none; }

/* V59 Crate Footer */
.crate-footer {
    text-align: center;
    font-family: var(--font-data);
    font-size: 10px;
    color: #555;
    margin-top: 20px;
    padding-bottom: 30px;
    letter-spacing: 0.5px;
    pointer-events: none;
}

/* FLOATING ACTION BAR */
#setlist-bar {
    position: fixed; bottom: 0; left: 0; width: 100%; padding: 15px 20px;
    background: rgba(5,5,5,0.95); backdrop-filter: blur(10px); border-top: 1px solid var(--brand-dim);
    display: flex; justify-content: space-between; align-items: center;
    transform: translateY(100%); transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); z-index: 200;
}
#setlist-bar.active { transform: translateY(0); }
#setlist-count { font-family: var(--font-data); font-size: 12px; color: #fff; font-weight: bold; letter-spacing: 1px;}
#btn-play-setlist {
    font-family: var(--font-data); font-size: 12px; font-weight: 900; 
    padding: 10px 20px; border: 2px solid var(--brand); background: rgba(74, 246, 38, 0.1); color: var(--brand); 
    border-radius: 6px; cursor: pointer; transition: all 0.2s; text-transform: uppercase;
}
#btn-play-setlist:active { background: var(--brand); color: #000; box-shadow: 0 0 15px var(--brand-glow); }

/* --- VIEW 2: THE DECK --- */
#view-deck { background: #000; }
.deck-nav { display: flex; align-items: center; justify-content: space-between; padding: 15px 20px; background: rgba(10,10,10,0.8); backdrop-filter: blur(10px); border-bottom: 1px solid #222; z-index: 50; gap: 15px;}
.back-btn { background: none; border: none; color: var(--text-main); font-size: 24px; padding: 0; cursor: pointer; font-weight: bold; }

.hud-cover-wrap { width: 44px; height: 44px; border-radius: 4px; overflow: hidden; border: 1px solid var(--brand-dim); flex-shrink: 0; background: #1a1a1a; position: relative;}
.hud-cover-wrap::before { content: 'NO ART'; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-family: var(--font-data); font-size: 10px; color: #444; z-index: 0; text-align: center; }
.hud-cover-wrap img { width: 100%; height: 100%; object-fit: cover; filter: grayscale(1) contrast(1.5) sepia(1) hue-rotate(85deg); position: relative; z-index: 1;}

.now-playing-hud { flex: 1; display: flex; flex-direction: column; overflow: hidden;}
.np-title { font-weight: 900; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin: 0; }
.np-sub { font-family: var(--font-data); font-size: 11px; color: var(--brand); }
.deck-bpm { font-family: var(--font-data); font-weight: bold; font-size: 14px; color: #fff; text-align: right; background: #222; padding: 4px 8px; border-radius: 4px; border: 1px solid #444;}
.deck-bpm.scanning { color: #ffeb3b; animation: pulse 1s infinite; }

.kaoss-container { flex: 1; position: relative; overflow: hidden; border-bottom: 1px solid var(--brand-dim); background: radial-gradient(circle at center, #112211 0%, #000 100%); touch-action: none; cursor: crosshair; }
#visualizer-canvas { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0.7; pointer-events: none; }
.pad-hint { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); font-family: var(--font-data); font-size: 14px; letter-spacing: 2px; color: var(--brand); opacity: 0.5; pointer-events: none; transition: opacity 0.5s ease; text-align: center; }

#reticle { position: absolute; width: 80px; height: 80px; border: 2px solid var(--brand); border-radius: 50%; pointer-events: none; transform: translate(-50%, -50%); display: none; z-index: 50; box-shadow: 0 0 20px var(--brand-glow); transition: width 0.1s, height 0.1s; }
#reticle::after { content: ''; position: absolute; top: 50%; left: 50%; width: 8px; height: 8px; background: #fff; transform: translate(-50%, -50%); border-radius: 50%; box-shadow: 0 0 10px #fff;}
#reticle.auto { border-color: var(--ghost); box-shadow: 0 0 20px var(--ghost-glow); opacity: 0.8;}
#reticle.parked { opacity: 0.2; transform: translate(-50%, -50%) scale(0.5); }

/* --- V53 VISUALIZER CONTROLS --- */
.vis-controls {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 60;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid #333;
}

.vis-btn {
    background: none;
    border: none;
    color: #666;
    cursor: pointer;
    font-size: 14px;
    padding: 2px 6px;
    transition: color 0.2s;
    touch-action: manipulation;
}

.vis-btn:hover, .vis-btn:active {
    color: var(--brand);
}

.vis-name {
    font-family: var(--font-data);
    font-size: 10px;
    color: var(--brand);
    min-width: 85px;
    text-align: center;
    pointer-events: none;
    letter-spacing: 1px;
}

.lcd-screen { background: #051005; border-bottom: 1px solid #222; padding: 12px 20px; font-family: var(--font-data); font-size: 12px; color: var(--brand); text-shadow: 0 0 8px var(--brand-glow); min-height: 55px; display: flex; align-items: center; box-shadow: inset 0 0 15px #000; line-height: 1.3; }
.lcd-cursor { display: inline-block; width: 8px; height: 1em; background: var(--brand); margin-left: 4px; animation: blink 1s step-end infinite; vertical-align: middle;}

.mpc-container { height: 20dvh; min-height: 120px; padding: 10px 15px; background: var(--bg-panel); display: flex; gap: 8px; }
.mpc-pad { flex: 1; border-radius: 8px; border: 2px solid #333; background: linear-gradient(180deg, #222 0%, #111 100%); box-shadow: 0 4px 6px rgba(0,0,0,0.5), inset 0 2px 2px rgba(255,255,255,0.1); display: flex; flex-direction: column; align-items: center; justify-content: center; cursor: pointer; transition: all 0.05s ease; touch-action: none; }
.mpc-pad:active, .mpc-pad.active { border-color: var(--brand); background: var(--brand); box-shadow: 0 0 15px var(--brand-glow), inset 0 4px 8px rgba(0,0,0,0.4); transform: translateY(4px); }
.mpc-pad.auto-active { border-color: var(--ghost); background: var(--ghost); box-shadow: 0 0 15px var(--ghost-glow), inset 0 4px 8px rgba(0,0,0,0.4); transform: translateY(4px); }
.pad-name { font-weight: 900; font-size: 12px; color: #fff; letter-spacing: 1px; pointer-events: none;}
.pad-desc { font-family: var(--font-data); font-size: 9px; color: #aaa; margin-top: 4px; pointer-events: none;}

.transport-bar { display: flex; justify-content: space-between; align-items: center; padding: 10px 20px 25px 20px; background: #000; border-top: 1px solid #222; }
.time-readout { font-family: var(--font-data); font-size: 18px; font-weight: bold; color: var(--brand); width: 60px;}
.play-btn { width: 54px; height: 54px; background: var(--brand); color: #000; border: none; border-radius: 50%; font-size: 20px; font-weight: 900; cursor: pointer;}

.auto-btn { 
    position: relative; font-family: var(--font-data); font-size: 11px; font-weight: 900; 
    padding: 10px 16px; border: 2px solid var(--ghost); background: #050005; color: var(--ghost); 
    border-radius: 6px; cursor: pointer; transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    text-transform: uppercase; letter-spacing: 1px; overflow: hidden;
    box-shadow: 0 0 5px var(--ghost-glow);
}
.auto-btn::before {
    content: ''; position: absolute; inset: 0; background: radial-gradient(circle at center, var(--ghost-glow) 0%, transparent 70%);
    opacity: 0.2; transition: opacity 0.4s; z-index: -1;
}
.auto-btn.on { 
    color: #fff; background: var(--ghost);
    box-shadow: 0 0 25px var(--ghost), inset 0 0 10px #000;
    text-shadow: 0 0 8px #fff; transform: scale(1.08);
    animation: ghost-pulse 1.5s ease-in-out infinite;
}

.fx-disabled { opacity: 0.25 !important; pointer-events: none !important; filter: grayscale(1) contrast(0.5) !important; }

@keyframes system-ready-flash {
    0% { filter: brightness(1); transform: scale(1); box-shadow: none; }
    30% { filter: brightness(2) contrast(1.2); transform: scale(1.05); box-shadow: 0 0 25px rgba(255, 255, 255, 0.6); }
    100% { filter: brightness(1); transform: scale(1); box-shadow: none; }
}
.sys-ready { animation: system-ready-flash 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards; }

@keyframes ghost-pulse {
    0%, 100% { box-shadow: 0 0 15px var(--ghost-glow); transform: scale(1.08); }
    50% { box-shadow: 0 0 35px var(--ghost); transform: scale(1.1); }
}

@media (min-width: 768px) {
    .grid-container { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
    .mpc-container { padding: 20px 30px; gap: 15px; height: 25dvh;}
}