:root {
    --bg-dark: #0d0d0d;
    --header-bg: #0d0d0d;
    --pad-bg: #2b2b2b;
    --pad-border: #444;
    --pad-active: #FC1B73;
    --text-primary: #ffffff;
    --text-secondary: #888;
    --accent-blue: #FC1B73;
    --accent-orange: #FC1B73;
    --accent-green: #FC1B73;
}

* {
    box-sizing: border-box;
    user-select: none;
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--bg-dark);
    font-family: 'Roboto Mono', monospace;
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
}

/* ==========================================
   COMPACT HEADER
   ========================================== */
.compact-header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 0 20px;
    height: 60px;
    background-color: var(--header-bg);
    border-bottom: 1px solid #1a1a1a;
}

.header-left {
    justify-self: start;
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-center {
    justify-self: center;
}

.header-right {
    justify-self: end;
    display: flex;
    align-items: center;
    gap: 12px;
}

#btn-midi-toggle {
    background: none;
    border: none;
    color: #666;
    font-family: 'Roboto Mono', monospace;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    padding: 4px 8px;
    transition: all 0.2s;
    letter-spacing: 0.5px;
}

#btn-midi-toggle:hover {
    color: var(--accent-blue);
}

#btn-midi-toggle.active {
    color: var(--text-primary);
    text-shadow: 0 0 5px rgba(255, 255, 255, 0.3);
}

.header-knob {
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.knob-indicator {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: conic-gradient(var(--knob-color) 0%, transparent 0%);
    border: 2px solid #333;
}

/* Knob colors */
#knob-volume .knob-indicator {
    --knob-color: var(--accent-orange);
}

#knob-pitch .knob-indicator {
    --knob-color: var(--accent-blue);
}

.mode-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent-green);
}

.mode-icon svg {
    width: 14px;
    height: 14px;
    fill: currentColor;
}

/* Timeline */
.timeline-container {
    width: 100%;
    height: 16px;
    position: relative;
    background-color: #1a1a1a;
    border-radius: 2px;
}

.timeline-track {
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(90deg,
            #222,
            #222 1px,
            transparent 1px,
            transparent 8px);
}

.playhead {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2px;
    background-color: var(--text-primary);
    left: 0%;
    z-index: 10;
    pointer-events: none;
}

.trim-handle {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    gap: 2px;
    cursor: ew-resize;
    z-index: 5;
    font-size: 11px;
    font-variant-numeric: tabular-nums;
    color: var(--accent-orange);
    font-weight: 500;
    white-space: nowrap;
    user-select: none;
}

.trim-handle.start {
    left: 0%;
    flex-direction: row-reverse;
    transform: translate(0, -50%);
}

.trim-handle.end {
    flex-direction: row-reverse;
    transform: translate(-100%, -50%);
}

.trim-time {
    font-size: 11px;
    color: var(--accent-orange);
    padding: 0 2px;
}

.trim-arrow {
    width: 12px;
    height: 12px;
    color: var(--accent-orange);
    flex-shrink: 0;
}

.trim-overlay {
    position: absolute;
    top: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.7);
    pointer-events: none;
}

/* ==========================================
   MAIN GRID SECTION
   ========================================== */
.grid-section {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 15px;
    overflow: hidden;
    min-height: 0;
}

.pad-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    width: 100%;
    max-width: 100%;
    max-height: 100%;
}

.pad {
    background-color: var(--pad-bg);
    border-radius: 4px;
    border: 2px solid transparent;
    position: relative;
    cursor: pointer;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    aspect-ratio: 16 / 9;
    width: 100%;
}

.pad:active,
.pad.active {
    transform: scale(0.98);
    border-color: #555;
}

.pad.has-video {
    border-color: var(--pad-border);
}

.pad.playing {
    border-color: var(--accent-green);
    box-shadow: 0 0 12px rgba(78, 183, 72, 0.4);
}

/* Video iframes */
.pad iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0.3;
    pointer-events: none;
    filter: grayscale(100%);
}

.pad.playing iframe {
    opacity: 0.8;
    filter: grayscale(0%);
}

/* Pad key overlay */
.pad-key-overlay {
    position: absolute;
    bottom: 6px;
    right: 8px;
    font-family: 'Roboto Mono', monospace;
    font-size: 11px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.5);
    pointer-events: none;
    mix-blend-mode: difference;
    z-index: 10;
}

/* ==========================================
   COMPACT FOOTER
   ========================================== */
.compact-footer {
    display: flex;
    flex-direction: column;
    background-color: var(--header-bg);
    border-top: 1px solid #1a1a1a;
}

/* Footer Row 1: Controls, Title, Trash */
.footer-row-1 {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 20px;
    padding: 8px 20px;
    height: 40px;
}

.footer-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.footer-title {
    justify-self: center;
    max-width: 400px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    text-align: center;
    color: var(--text-primary);
    font-size: 12px;
}

.footer-trash {
    justify-self: end;
}

/* Footer Row 2: Timeline */
.footer-row-2 {
    display: flex;
    align-items: center;
    padding: 0 20px 8px 20px;
    height: 30px;
}

.footer-timeline {
    flex: 1;
    min-width: 0;
    padding: 0;
}

.branding-logo {
    height: 72px;
    width: auto;
    display: block;
    pointer-events: none;
    margin-top: -4px;
}

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    color: #666;
    transition: color 0.2s;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    color: var(--accent-blue);
}

.trash-zone {
    width: 24px;
    height: 24px;
    border: 2px dashed #555;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #666;
    transition: all 0.2s;
    cursor: pointer;
}

.trash-zone.drag-over {
    border-color: var(--accent-orange);
    color: var(--accent-orange);
    background-color: rgba(255, 87, 34, 0.1);
    transform: scale(1.1);
}

/* ==========================================
   MODAL
   ========================================== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 5000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.modal-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background-color: #1a1a1a;
    padding: 25px;
    border-radius: 8px;
    width: 90%;
    max-width: 640px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
    border: 1px solid #333;
    position: relative;
}

#btn-close-modal {
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    border: none;
    color: #666;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
}

#btn-close-modal:hover {
    color: var(--text-primary);
    background-color: rgba(255, 255, 255, 0.1);
}

.modal-content h3 {
    margin-top: 0;
    color: var(--text-primary);
    font-size: 16px;
    font-weight: 600;
}

#video-url-input {
    width: 100%;
    padding: 10px;
    margin: 12px 0;
    border: 1px solid #333;
    border-radius: 4px;
    font-family: inherit;
    font-size: 12px;
    background-color: #0d0d0d;
    color: var(--text-primary);
}

#video-url-input:focus {
    outline: none;
    border-color: var(--accent-blue);
}

.modal-actions {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    margin-top: 12px;
}

.modal-actions button {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-family: inherit;
    font-weight: 600;
    font-size: 12px;
    transition: opacity 0.2s;
}

.modal-actions button:hover {
    opacity: 0.8;
}

#btn-cancel-load {
    background-color: #333;
    color: var(--text-primary);
}

#btn-confirm-load {
    background-color: var(--accent-blue);
    color: white;
}

.modal-divider {
    margin: 16px 0;
    font-size: 10px;
    color: var(--text-secondary);
    position: relative;
}

.modal-divider::before,
.modal-divider::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 40%;
    height: 1px;
    background-color: #333;
}

.modal-divider::before {
    left: 0;
}

.modal-divider::after {
    right: 0;
}

.btn-link {
    display: block;
    width: 100%;
    padding: 10px;
    background-color: var(--accent-orange);
    color: white;
    text-decoration: none;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    transition: opacity 0.2s;
}

.btn-link:hover {
    opacity: 0.8;
}

/* Suggested Videos Grid */
.suggested-videos-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    margin-top: 16px;
    width: 100%;
    max-height: 60vh;
    overflow-y: auto;
}

.suggested-video-pad {
    width: 100%;
    height: 0;
    padding-bottom: 56.25%;
    /* 16:9 Aspect Ratio */
    background-color: var(--pad-bg);
    border-radius: 4px;
    border: 2px solid var(--pad-border);
    position: relative;
    cursor: pointer;
    transition: transform 0.05s, border-color 0.1s, box-shadow 0.2s;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.suggested-video-pad:hover {
    border-color: var(--accent-blue);
    box-shadow: 0 0 8px rgba(0, 160, 233, 0.3);
    transform: scale(1.02);
}

.suggested-video-pad:active {
    transform: scale(0.98);
}

.suggested-video-thumbnail {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0.5;
    pointer-events: none;
    filter: grayscale(100%);
    transition: opacity 0.2s, filter 0.2s;
}

.suggested-video-pad:hover .suggested-video-thumbnail {
    opacity: 0.8;
    filter: grayscale(30%);
}


/* ==========================================
   RESPONSIVE
   ========================================== */
@media (max-width: 900px) {
    .compact-header {
        height: 50px;
        padding: 0 12px;
    }

    .branding-logo {
        height: 40px;
    }

    .knob-indicator {
        width: 18px;
        height: 18px;
    }

    .grid-section {
        padding: 10px;
    }

    .footer-row-1 {
        padding: 6px 12px;
        height: 35px;
    }

    .footer-title {
        max-width: 300px;
        font-size: 11px;
    }
}

@media (max-width: 640px) {
    .compact-header {
        height: 45px;
        padding: 0 10px;
    }

    .branding-logo {
        height: 36px;
    }

    .grid-section {
        padding: 8px;
    }

    .footer-row-1 {
        padding: 6px 10px;
        height: 32px;
        gap: 12px;
    }

    .footer-row-2 {
        padding: 0 10px 6px 10px;
        height: 26px;
        gap: 8px;
    }

    .footer-title {
        max-width: 200px;
        font-size: 10px;
    }

    .footer-controls {
        gap: 6px;
    }

    /* Suggested videos: 2 columns on mobile */
    .suggested-videos-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-height: 600px) {
    .compact-header {
        height: 45px;
    }

    .branding-logo {
        height: 36px;
    }

    .footer-row-1 {
        height: 32px;
    }

    .footer-row-2 {
        height: 24px;
    }

    .grid-section {
        padding: 8px;
    }
}

/* ==========================================
   FULL SCREEN MODE
   ========================================== */

#btn-exit-fullscreen {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2100;
    background-color: rgba(0, 0, 0, 0.6);
    color: white;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, transform 0.2s;
}

#btn-exit-fullscreen:hover {
    background-color: rgba(255, 255, 255, 0.1);
    transform: scale(1.1);
}

/* Body state for full screen */
body.full-screen-mode .compact-header,
body.full-screen-mode .compact-footer {
    display: none !important;
}

body.full-screen-mode .grid-section {
    padding: 0;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 1000;
}

body.full-screen-mode .pad-grid {
    display: block;
    /* Disable grid layout to allow absolute positioning */
    width: 100%;
    height: 100%;
}

body.full-screen-mode .pad {
    display: none;
    /* Hide all pads by default */
    transition: none;
    /* Remove transitions to prevent animation glitches */
}

body.full-screen-mode .pad.active,
body.full-screen-mode .pad.playing {
    display: block;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    max-width: calc((100vh - 120px) * 16 / 9);
    aspect-ratio: 16 / 9;
    z-index: 2000;
    /* Base for selected pad */
    border: none;
    border-radius: 8px;
    margin: 0;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.8);
}

body.full-screen-mode #btn-exit-fullscreen {
    display: flex;
    top: 10px;
    right: 20px;
}

/* Hide overlays in full screen */
body.full-screen-mode .pad.active .pad-key-overlay {
    display: none;
}

/* Ensure video is fully visible and clear in full screen */
body.full-screen-mode .pad.active iframe {
    opacity: 1;
    filter: none;
}

/* Ensure exit button is definitely on top */
#btn-exit-fullscreen {
    z-index: 2147483647;
}

/* ==========================================
   UTILITY CLASSES
   ========================================== */
.hidden-control {
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
}