/* =========================================
   VISUALIZER.CSS — rebased from style.css
   Color vars updated to match cyber theme.
   Layout & structure are unchanged.
   ========================================= */

:root {
    /* Updated to cyber theme — background */
    --bg-gradient-start: #05080f;
    --bg-gradient-end:   #0d1117;
    --card-gradient-start: #0a1020;
    --card-gradient-end:   #0d1628;

    /* Glass surfaces */
    --glass-bg:     rgba(10, 16, 30, 0.75);
    --glass-border: rgba(0, 200, 255, 0.12);

    /* Text */
    --text-primary:   #e2e8f0;
    --text-secondary: #cbd5e1;
    --text-muted:     #64748b;

    /* Button colors — semantic meaning preserved */
    --btn-green-start: #22c55e;  --btn-green-end: #15803d;
    --btn-red-start:   #f87171;  --btn-red-end:   #dc2626;
    --btn-purple-start:#a78bfa;  --btn-purple-end:#7c3aed;
    --btn-grey-start:  #d1d5db;  --btn-grey-end:  #4b5563;

    /* Status */
    --status-connected:    #00ff88;
    --status-disconnected: #ff3366;
    --status-pending:      #f59e0b;
}


* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}


body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    padding-top: var(--nav-h);
}


/* =========================================
   LAYOUT & CONTAINERS
   ========================================= */
.page-frame {
    height: calc(100vh - var(--nav-h));
    padding: 18px 24px;
    display: flex;
    justify-content: center;
    align-items: stretch;
}


.container {
    height: 100%;
    width: 100%;
    max-width: 1480px;
    background: linear-gradient(135deg, var(--card-gradient-start) 0%, var(--card-gradient-end) 100%);
    border-radius: 22px;
    border: 1px solid var(--glass-border);
    padding: 16px 18px 18px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.7);
    display: flex;
    flex-direction: column;
}


.main-layout {
    display: flex;
    gap: 24px;
    align-items: stretch;
    flex: 0 0 auto;
    margin-bottom: 24px;
    max-height: calc(100vh - var(--nav-h) - 250px);
}


.column {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
    position: relative;
    min-width: 0;
}


.stick-section,
.buttons-section,
.triggers-section,
.dpad-section {
    background: var(--glass-bg);
    padding: 15px;
    border-radius: 12px;
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    flex-shrink: 0;
}


.dpad-section {
    margin-top: auto;
}


/* =========================================
   SCROLLING PANELS
   ========================================= */
.panel-wrapper {
    flex: 1;
    position: relative;
    min-height: 100px;
}


.scroll-panel {
    position: absolute;
    inset: 0;
    overflow-y: auto;

    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    padding: 20px;
    border-radius: 12px;
    backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
}


.shortcut-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}


/* =========================================
   FOOTER: CALIBRATION INSTRUCTIONS
   ========================================= */
.calibration-instructions {
    flex: 1;
    display: flex;
    flex-direction: column;
    width: 100%;

    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    backdrop-filter: blur(10px);
    padding: 20px;
    overflow: hidden;
}


.instructions-content {
    flex: 1;
    overflow-y: auto;
}


.instructions-content p {
    color: var(--text-secondary);
    line-height: 1.6;
    font-size: 1rem;
}


/* =========================================
   STATUS & HEADER
   ========================================= */
.connection-status {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    background: rgba(10, 16, 30, 0.85);
    border: 1px solid var(--glass-border);
    padding: 8px 16px;
    border-radius: 20px;
    backdrop-filter: blur(10px);
    align-self: center;
    margin-bottom: 8px;
    font-size: 0.9rem;
    flex-shrink: 0;
}


.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--status-disconnected);
    animation: pulse 2s infinite;
}


.status-dot.connected { background: var(--status-connected); }
.status-dot.pending   { background: var(--status-pending); }


@keyframes pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.5; }
}


a.download-link {
    align-self: center;
    margin-bottom: 14px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 18px;
    border-radius: 999px;
    background: radial-gradient(circle at 30% 20%, #0ea5e9, #0369a1);
    color: #f9fafb;
    font-size: 0.86rem;
    font-weight: 600;
    text-decoration: none;
    border: 1px solid rgba(0, 200, 255, 0.4);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.6);
    position: relative;
    overflow: hidden;
    transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.15s ease;
}


a.download-link::after {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 0% 0%, rgba(255,255,255,0.35), transparent 55%);
    opacity: 0.2;
    mix-blend-mode: screen;
    pointer-events: none;
    transition: opacity 0.15s ease, transform 0.2s ease;
}


a.download-link:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 22px rgba(0, 200, 255, 0.4);
    background: radial-gradient(circle at 30% 20%, #38bdf8, #0369a1);
}


a.download-link:hover::after {
    opacity: 0.4;
    transform: translateX(6px) translateY(4px);
}


/* =========================================
   COMPONENTS
   ========================================= */
h2 {
    font-size: 1.2rem;
    margin-bottom: 10px;
    text-align: center;
    text-shadow: 0 0 6px rgba(0,0,0,0.6);
}


canvas {
    display: block;
    background: radial-gradient(circle at 30% 20%, rgba(5,8,15,0.97), rgba(13,17,23,0.92));
    border-radius: 18px;
    border: 1px solid rgba(0, 200, 255, 0.2);
    box-shadow: 0 0 0 1px rgba(5,8,15,0.9) inset, 0 14px 28px rgba(0,0,0,0.8);
    margin: 0 auto;
}


.stick-values { width: 100%; margin-top: 12px; }


.value-row {
    display: flex;
    justify-content: space-between;
    margin: 5px 0;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
}


.label { font-weight: 600; color: var(--text-secondary); opacity: 0.9; }
.strong-label { letter-spacing: 0.12em; font-size: 0.75rem; }


/* =========================================
   BUTTONS — dark glass idle, color burst on press
   ========================================= */
.buttons-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    max-width: 400px;
    margin: 0 auto;
}


/* Base: near-black glass panel */
.button {
    padding: 15px 10px;
    border-radius: 10px;
    text-align: center;
    font-weight: 700;
    font-size: 0.82rem;
    transition:
        background  0.06s ease,
        border-color 0.06s ease,
        box-shadow  0.06s ease,
        transform   0.06s ease;
    border: 1px solid rgba(255, 255, 255, 0.07);
    position: relative;
    overflow: hidden;
    cursor: default;
    background: linear-gradient(160deg, rgba(11, 15, 25, 0.97) 0%, rgba(6, 9, 16, 0.99) 100%);
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.03), 0 2px 8px rgba(0,0,0,0.5);
}


/* Thin colored bottom-edge accent — always present, dim at idle */
.button::before {
    content: '';
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 2px;
    border-radius: 0 0 10px 10px;
    transition: height 0.06s ease, opacity 0.06s ease;
    pointer-events: none;
}


.button-label {
    position: relative;
    z-index: 2;
    letter-spacing: 0.07em;
    transition: color 0.06s ease, text-shadow 0.06s ease;
}


/* ---- Idle colors (dim, color-tinted labels) ---- */
.button.green::before              { background: #22c55e; opacity: 0.45; }
.button.green .button-label        { color: rgba(74, 222, 128, 0.55); }

.button.red::before                { background: #ef4444; opacity: 0.45; }
.button.red .button-label          { color: rgba(248, 113, 113, 0.55); }

.button.purple::before             { background: #a78bfa; opacity: 0.45; }
.button.purple .button-label       { color: rgba(167, 139, 250, 0.55); }

.button.grey::before               { background: #94a3b8; opacity: 0.25; }
.button.grey .button-label         { color: rgba(148, 163, 184, 0.4); }


/* ---- Pressed: color burst ---- */
.button.pressed {
    transform: scale(0.92) translateY(1px);
}
.button.pressed::before { height: 3px; opacity: 1; }

/* Green (A) */
.button.green.pressed {
    background: linear-gradient(160deg, rgba(22,163,74,0.3) 0%, rgba(22,163,74,0.12) 100%);
    border-color: rgba(34, 197, 94, 0.6);
    box-shadow:
        0 0 22px rgba(34, 197, 94, 0.38),
        0 0 8px  rgba(34, 197, 94, 0.2),
        inset 0 0 10px rgba(34, 197, 94, 0.08);
}
.button.green.pressed .button-label {
    color: #4ade80;
    text-shadow: 0 0 12px rgba(74, 222, 128, 0.8);
}

/* Red (B) */
.button.red.pressed {
    background: linear-gradient(160deg, rgba(220,38,38,0.3) 0%, rgba(220,38,38,0.12) 100%);
    border-color: rgba(239, 68, 68, 0.6);
    box-shadow:
        0 0 22px rgba(239, 68, 68, 0.38),
        0 0 8px  rgba(239, 68, 68, 0.2),
        inset 0 0 10px rgba(239, 68, 68, 0.08);
}
.button.red.pressed .button-label {
    color: #f87171;
    text-shadow: 0 0 12px rgba(248, 113, 113, 0.8);
}

/* Purple (Z) */
.button.purple.pressed {
    background: linear-gradient(160deg, rgba(124,58,237,0.3) 0%, rgba(124,58,237,0.12) 100%);
    border-color: rgba(167, 139, 250, 0.6);
    box-shadow:
        0 0 22px rgba(167, 139, 250, 0.38),
        0 0 8px  rgba(167, 139, 250, 0.2),
        inset 0 0 10px rgba(167, 139, 250, 0.08);
}
.button.purple.pressed .button-label {
    color: #c4b5fd;
    text-shadow: 0 0 12px rgba(196, 181, 253, 0.8);
}

/* Grey (X, Y, L, R, Start) */
.button.grey.pressed {
    background: linear-gradient(160deg, rgba(100,116,139,0.24) 0%, rgba(100,116,139,0.1) 100%);
    border-color: rgba(148, 163, 184, 0.5);
    box-shadow:
        0 0 18px rgba(148, 163, 184, 0.24),
        inset 0 0 8px rgba(148, 163, 184, 0.06);
}
.button.grey.pressed .button-label {
    color: #e2e8f0;
    text-shadow: 0 0 10px rgba(226, 232, 240, 0.6);
}


/* =========================================
   TRIGGERS
   ========================================= */
.triggers-display {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
}

.trigger-header-row {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    margin-bottom: 8px;
}

.trigger-origin-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
}

.trigger-item {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
}

.trigger-label {
    font-weight: bold;
    text-align: center;
    font-size: 0.9rem;
}

.trigger-bar {
    width: 90%;
    max-width: 260px;
    height: 25px;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 12px;
    overflow: hidden;
    border: 2px solid rgba(255, 255, 255, 0.15);
    position: relative;
}

.trigger-fill {
    height: 100%;
    background: linear-gradient(90deg, #00ff88, #00cc66);
    width: 0%;
    transition: width 0.05s, background 0.1s;
}

.trigger-fill.analog  { background: linear-gradient(90deg, #f59e0b, #d97706); }
.trigger-fill.digital { background: linear-gradient(90deg, #00c8ff, #0284c7); }

.trigger-value {
    text-align: center;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    font-size: 0.9rem;
}


/* =========================================
   D-PAD
   ========================================= */
.dpad-container {
    display: flex;
    justify-content: center;
    padding: 10px;
}

.dpad-shell {
    width: 120px;
    height: 120px;
    position: relative;
    border-radius: 32px;
    background: radial-gradient(circle at 30% 15%, #020617, #020617);
    box-shadow: 0 14px 30px rgba(0,0,0,0.9);
    display: flex;
    align-items: center;
    justify-content: center;
}

.dpad-plus {
    position: relative;
    width: 70px;
    height: 70px;
    border-radius: 20px;
    background: #020617;
    box-shadow: 0 0 12px rgba(0,0,0,0.95) inset, 0 6px 10px rgba(0,0,0,1);
}

.dpad-plus::before,
.dpad-plus::after {
    content: "";
    position: absolute;
    border-radius: 20px;
    background: #0b1120;
    z-index: 1;
}

.dpad-plus::before {
    width: 28px;
    height: 70px;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
}

.dpad-plus::after {
    width: 70px;
    height: 28px;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
}

.dpad-center {
    position: absolute;
    width: 18px;
    height: 18px;
    border-radius: 7px;
    background: radial-gradient(circle at 30% 20%, #1f2937, #020617);
    box-shadow: 0 0 6px rgba(0,0,0,0.9) inset;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 10;
}

.dpad-glow {
    position: absolute;
    background: transparent;
    opacity: 0;
    z-index: 5;
    transition: opacity 0.1s ease, box-shadow 0.1s ease;
    pointer-events: none;
}

.dpad-glow-up, .dpad-glow-down {
    width: 28px;
    height: 50%;
    left: calc(50% - 14px);
}

.dpad-glow-up   { top: 0; border-radius: 20px 20px 0 0; }
.dpad-glow-down { bottom: 0; border-radius: 0 0 20px 20px; }

.dpad-glow-left, .dpad-glow-right {
    height: 28px;
    width: 50%;
    top: calc(50% - 14px);
}

.dpad-glow-left  { left: 0; border-radius: 20px 0 0 20px; }
.dpad-glow-right { right: 0; border-radius: 0 20px 20px 0; }

.dpad-glow.active {
    opacity: 1;
    background: #00c8ff;
    box-shadow: 0 0 15px rgba(0, 200, 255, 0.8);
}


/* =========================================
   SCOPE
   ========================================= */
#scopeCanvas {
    width: 100%;
    height: 180px;
}

.scope-legend {
    margin-top: 8px;
    display: flex;
    justify-content: center;
    gap: 10px;
    font-family: 'Courier New', monospace;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.scope-legend-x { color: #00ff88; }
.scope-legend-y { color: #00c8ff; }


/* =========================================
   RESPONSIVE
   ========================================= */
@media (max-height: 800px) {
    canvas { width: 220px; height: 220px; }
    h2 { font-size: 1.1rem; margin-bottom: 8px; }
    .button { padding: 12px 8px; font-size: 0.8rem; }
    .dpad-shell { width: 108px; height: 108px; }
    .dpad-plus  { width: 63px; height: 63px; }
    #scopeCanvas { height: 130px; }
}

@media (max-width: 900px) {
    .main-layout {
        flex-direction: column;
        align-items: center;
        overflow-y: auto;
    }
    .column { width: 100%; max-width: 500px; }
    .panel-wrapper { min-height: 200px; }
    .dpad-section { margin-top: 0; }
}
