:root {
    --bg-color: #09090b;
    --text-primary: #ffffff;
    --text-secondary: #a1a1aa;
    --accent-color: #8b5cf6;
    --accent-hover: #7c3aed;
    --accent-glow: rgba(139, 92, 246, 0.5);
    --glass-bg: rgba(24, 24, 27, 0.6);
    --glass-border: rgba(255, 255, 255, 0.08);
    --danger: #ef4444;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
}

/* Dynamic Background Blobs */
.background-blobs {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
}

.blob {
    position: absolute;
    filter: blur(100px);
    border-radius: 50%;
    animation: float 20s infinite ease-in-out alternate;
    opacity: 0.6;
}

.blob-1 {
    top: -10%;
    left: -10%;
    width: 50vw;
    height: 50vw;
    background: radial-gradient(circle, rgba(139,92,246,0.3) 0%, rgba(0,0,0,0) 70%);
}

.blob-2 {
    bottom: -20%;
    right: -10%;
    width: 60vw;
    height: 60vw;
    background: radial-gradient(circle, rgba(56,189,248,0.2) 0%, rgba(0,0,0,0) 70%);
    animation-delay: -5s;
}

.blob-3 {
    top: 40%;
    left: 40%;
    width: 40vw;
    height: 40vw;
    background: radial-gradient(circle, rgba(236,72,153,0.15) 0%, rgba(0,0,0,0) 70%);
    animation-delay: -10s;
}

@keyframes float {
    0% { transform: translate(0, 0) scale(1); }
    100% { transform: translate(5%, 10%) scale(1.1); }
}

/* Layout */
.app-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 3rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 1rem;
}

.logo {
    font-size: 3.5rem;
    font-weight: 800;
    letter-spacing: -2px;
    margin-bottom: 0.5rem;
}

.logo span {
    background: linear-gradient(135deg, #a78bfa, #38bdf8);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
    font-weight: 300;
}

/* Glass Panels */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 2rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    transition: all 0.3s ease;
}

.hidden {
    display: none !important;
}

/* Upload UI */
.drop-zone {
    border: 2px dashed rgba(255, 255, 255, 0.2);
    border-radius: 16px;
    padding: 3rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
}

.drop-zone:hover, .drop-zone.dragover {
    border-color: var(--accent-color);
    background: rgba(139, 92, 246, 0.05);
}

.drop-icon {
    color: var(--accent-color);
    background: rgba(139, 92, 246, 0.1);
    padding: 1rem;
    border-radius: 50%;
    margin-bottom: 0.5rem;
}

.drop-zone h2 {
    font-size: 1.5rem;
    font-weight: 600;
}

.drop-zone p {
    color: var(--text-secondary);
}

#file-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.05);
    padding: 1rem 1.5rem;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
}

.icon-btn:hover {
    color: var(--danger);
}

/* Editor Section */
#editor-section {
    display: flex;
    flex-direction: column;
    gap: 2rem;
    animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Player Controls */
.player-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    justify-content: center;
}

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    outline: none;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--accent-color);
    color: white;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    box-shadow: 0 0 20px var(--accent-glow);
}

.btn-primary:hover {
    background: var(--accent-hover);
    transform: scale(1.05);
}

.btn-primary:active {
    transform: scale(0.95);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    width: 50px;
    height: 50px;
    border-radius: 50%;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
}

.time-display {
    font-variant-numeric: tabular-nums;
    font-weight: 300;
    font-size: 1.2rem;
    margin-left: 1rem;
    color: var(--text-secondary);
}

/* Visualizer */
.visualizer-container {
    width: 100%;
    height: 80px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    overflow: hidden;
    position: relative;
    border: 1px solid var(--glass-border);
}

canvas#visualizer {
    width: 100%;
    height: 100%;
    display: block;
}

/* Effects Controls */
.effects-controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.control-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.control-header label {
    font-weight: 600;
    font-size: 1rem;
}

.value-display {
    background: rgba(255, 255, 255, 0.1);
    padding: 0.2rem 0.6rem;
    border-radius: 6px;
    font-size: 0.85rem;
    font-variant-numeric: tabular-nums;
}

/* Custom Range Slider */
input[type=range] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    background: transparent;
}

input[type=range]:focus {
    outline: none;
}

input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 6px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

input[type=range]::-webkit-slider-thumb {
    height: 20px;
    width: 20px;
    border-radius: 50%;
    background: #ffffff;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    margin-top: -7px;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
    border: 2px solid var(--accent-color);
    transition: transform 0.1s;
}

input[type=range]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

/* Export Button */
.export-container {
    margin-top: 1rem;
    border-top: 1px solid var(--glass-border);
    padding-top: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.btn-action {
    background: linear-gradient(135deg, #a78bfa, #38bdf8);
    color: white;
    padding: 1rem 2rem;
    font-size: 1.1rem;
    font-weight: 600;
    gap: 0.5rem;
    width: 100%;
    box-shadow: 0 4px 15px rgba(139, 92, 246, 0.3);
    position: relative;
    overflow: hidden;
}

.btn-action::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    transition: left 0.5s;
}

.btn-action:hover::after {
    left: 100%;
}

.progress-bar {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #a78bfa, #38bdf8);
    transition: width 0.3s linear;
}

.export-status {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* Loading/Processing State */
.btn-action:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

/* Timeline Area */
.timeline-area {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1.5rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 16px;
    border: 1px solid var(--glass-border);
    margin-bottom: 1rem;
}
.timeline-container {
    width: 100%;
    height: 40px;
    position: relative;
    cursor: pointer;
    display: flex;
    align-items: center;
}
.timeline-track {
    width: 100%;
    height: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    position: relative;
    pointer-events: none;
}
.timeline-progress {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-color), #38bdf8);
    width: 0%;
    border-radius: 4px;
}
.playhead {
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 10px rgba(255,255,255,0.5);
    left: 0%;
    z-index: 10;
}
.kf-marker {
    width: 15px;
    height: 15px;
    background: #38bdf8;
    border-radius: 50%;
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 5;
    box-shadow: 0 0 5px rgba(56,189,248, 0.8);
    cursor: ew-resize;
    pointer-events: auto;
}

.kf-label {
    position: absolute;
    top: 22px;
    left: 50%;
    transform: translateX(-50%);
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Helvetica Neue", sans-serif;
    font-style: italic;
    font-weight: 300;
    font-size: 0.65rem;
    color: rgba(255, 255, 255, 0.8);
    white-space: pre;
    text-align: center;
    pointer-events: none;
    line-height: 1.2;
    background: rgba(0, 0, 0, 0.5);
    padding: 2px 6px;
    border-radius: 4px;
    backdrop-filter: blur(4px);
    opacity: 0.9;
    border: 1px solid var(--glass-border);
    transition: all 0.2s ease;
}

.kf-marker:hover .kf-label {
    color: #fff;
    opacity: 1;
    background: rgba(0, 0, 0, 0.8);
    border-color: rgba(56, 189, 248, 0.5);
}

/* Keyframe buttons */
.kf-wrap {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.btn-keyframe {
    background: none;
    color: rgba(255,255,255,0.2);
    border: none;
    font-size: 1.2rem;
    padding: 0;
    width: auto;
    height: auto;
    transition: 0.2s;
    line-height: 1;
}
.btn-keyframe:hover {
    color: var(--accent-color);
}
.btn-keyframe.active-kf {
    color: #38bdf8;
    text-shadow: 0 0 8px rgba(56,189,248,0.8);
}

/* Loading Screen */
#loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: var(--bg-color);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: opacity 0.8s ease, visibility 0.8s ease;
}

#loading-screen.fade-out {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.loading-logo {
    font-size: 4.5rem;
    font-weight: 800;
    letter-spacing: -2px;
    margin-bottom: 1rem;
    animation: pulseGlow 2s infinite alternate;
}

.loading-logo span.loading-accent {
    background: linear-gradient(135deg, #a78bfa, #38bdf8);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.loading-text {
    color: var(--text-secondary);
    font-size: 1.2rem;
    font-weight: 300;
    letter-spacing: 2px;
    animation: fadeInOut 2s infinite ease-in-out;
}

@keyframes pulseGlow {
    0% { transform: scale(1); text-shadow: 0 0 10px rgba(139, 92, 246, 0.2); }
    100% { transform: scale(1.05); text-shadow: 0 0 30px rgba(56, 189, 248, 0.6); }
}

@keyframes fadeInOut {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
}

/* iPhone / Mobile Optimizations */
@media (max-width: 768px) {
    body {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
    .app-container {
        padding: 1.5rem 1rem;
        gap: 1.5rem;
    }
    .logo {
        font-size: 2.8rem;
    }
    .subtitle {
        font-size: 1rem;
    }
    .glass-panel {
        padding: 1.5rem;
        border-radius: 16px;
    }
    .effects-controls {
        grid-template-columns: 1fr; /* Stack vertically */
    }
    .player-controls {
        flex-wrap: wrap;
    }
    .time-display {
        width: 100%;
        text-align: center;
        margin-left: 0;
        margin-top: 0.5rem;
    }
    .drop-zone {
        padding: 2rem 1rem;
    }
    .kf-marker {
        width: 25px; /* Larger hit area for touch */
        height: 25px;
    }
    .kf-label {
        top: 30px; /* Adjust below larger marker */
    }
}

.header-container { display:flex; flex-direction:column; align-items:center; position:relative; }
.logo-wrapper { display:flex; align-items:center; gap: 1rem; margin-bottom: 0.5rem; justify-content:center; flex-wrap:wrap;}
.logo-wrapper .logo { margin-bottom: 0; }
.view-counter {
    display:flex; align-items:center; gap:0.5rem;
    background: rgba(255,255,255,0.05); padding: 0.4rem 0.8rem;
    border-radius: 20px; font-size: 0.95rem; font-weight: 600;
    color: var(--text-primary); border: 1px solid var(--glass-border);
    box-shadow: 0 4px 6px rgba(0,0,0,0.1); backdrop-filter: blur(5px);
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: default;
}
.view-counter:hover {
    transform: scale(1.05);
    box-shadow: 0 0 15px rgba(56,189,248, 0.4);
}
.view-counter svg { color: #38bdf8; opacity: 0.9; animation: float 6s infinite ease-in-out alternate;}
.animated-number { font-variant-numeric: tabular-nums; }
