/* CSS Reset and Base Styles */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --secondary-color: #22d3ee;
    --background-dark: #0f172a;
    --background-card: #1e293b;
    --background-hover: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border-color: #334155;
    --success-color: #22c55e;
    --warning-color: #f59e0b;
    --error-color: #ef4444;
    --gradient-start: #6366f1;
    --gradient-end: #22d3ee;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.4);
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--background-dark);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    max-width: 1400px;
    margin: 0 auto;
    padding: 1rem;
}

/* Header */
.header {
    text-align: center;
    padding: 2rem 1rem;
    margin-bottom: 1rem;
}

.logo-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.logo {
    width: 48px;
    height: 48px;
    object-fit: contain;
}

.header h1 {
    font-size: clamp(1.5rem, 5vw, 2.5rem);
    font-weight: 700;
    background: linear-gradient(135deg, var(--gradient-start), var(--gradient-end));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.tagline {
    color: var(--text-secondary);
    font-size: 1rem;
    margin-top: 0.5rem;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Upload Section */
.upload-section {
    background: var(--background-card);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
}

.upload-area {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-md);
    padding: 3rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition-normal);
}

.upload-area:hover,
.upload-area.dragover {
    border-color: var(--primary-color);
    background: rgba(99, 102, 241, 0.1);
}

.upload-icon {
    color: var(--text-muted);
    margin-bottom: 1rem;
    transition: color var(--transition-fast);
}

.upload-area:hover .upload-icon {
    color: var(--primary-color);
}

.upload-text {
    font-size: 1.125rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.upload-subtext {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.supported-formats {
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-top: 1rem;
}

.file-info {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-top: 1rem;
    padding: 0.75rem 1rem;
    background: rgba(99, 102, 241, 0.1);
    border-radius: var(--radius-sm);
}

.file-name {
    color: var(--primary-color);
    font-weight: 500;
}

.btn-clear {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
    padding: 0 0.25rem;
    transition: color var(--transition-fast);
}

.btn-clear:hover {
    color: var(--error-color);
}

/* Controls Section */
.controls-section {
    background: var(--background-card);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
}

.player-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.btn-play {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--gradient-start), var(--gradient-end));
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
    flex-shrink: 0;
}

.btn-play:hover {
    transform: scale(1.05);
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.5);
}

.btn-play:active {
    transform: scale(0.95);
}

.time-display {
    font-family: 'SF Mono', Monaco, 'Courier New', monospace;
    font-size: 0.875rem;
    color: var(--text-secondary);
    white-space: nowrap;
    min-width: 90px;
}

.time-separator {
    margin: 0 0.25rem;
    color: var(--text-muted);
}

.progress-container {
    flex: 1;
    height: 8px;
    background: var(--background-hover);
    border-radius: 4px;
    cursor: pointer;
    position: relative;
    min-width: 100px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--gradient-start), var(--gradient-end));
    border-radius: 4px;
    width: 0%;
    transition: width 0.1s linear;
    position: relative;
    z-index: 2;
}

.progress-events {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1;
}

.progress-event-marker {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 3px;
    opacity: 0.8;
    border-radius: 1px;
}

.volume-control {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-volume {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color var(--transition-fast);
}

.btn-volume:hover {
    color: var(--text-primary);
}

.volume-slider {
    width: 80px;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--background-hover);
    border-radius: 2px;
    outline: none;
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    transition: transform var(--transition-fast);
}

.volume-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.volume-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

/* Visualization Section */
.visualization-section {
    background: var(--background-card);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
}

.viz-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    overflow-x: auto;
    padding-bottom: 0.5rem;
}

.viz-tab {
    padding: 0.5rem 1rem;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.875rem;
    white-space: nowrap;
    transition: all var(--transition-fast);
}

.viz-tab:hover {
    background: var(--background-hover);
    color: var(--text-primary);
}

.viz-tab.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

.viz-container {
    position: relative;
    width: 100%;
    height: 250px;
    background: var(--background-dark);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.viz-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
}

.viz-canvas.active {
    display: block;
}

/* Events Section */
.events-section {
    background: var(--background-card);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
}

.events-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1rem;
}

.events-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.events-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.sensitivity-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.sensitivity-slider {
    width: 100px;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--background-hover);
    border-radius: 2px;
    outline: none;
}

.sensitivity-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    background: var(--secondary-color);
    border-radius: 50%;
    cursor: pointer;
}

.sensitivity-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    background: var(--secondary-color);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.btn-analyze {
    padding: 0.5rem 1rem;
    background: var(--primary-color);
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    font-size: 0.875rem;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.btn-analyze:hover {
    background: var(--primary-hover);
}

.events-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
    padding: 1rem;
    background: var(--background-dark);
    border-radius: var(--radius-md);
}

.stat-item {
    text-align: center;
}

.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--secondary-color);
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.events-list {
    max-height: 300px;
    overflow-y: auto;
    padding-right: 0.5rem;
}

.events-list::-webkit-scrollbar {
    width: 6px;
}

.events-list::-webkit-scrollbar-track {
    background: var(--background-dark);
    border-radius: 3px;
}

.events-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.events-list::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.no-events {
    color: var(--text-muted);
    text-align: center;
    padding: 2rem;
    font-style: italic;
}

.event-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem;
    background: var(--background-dark);
    border-radius: var(--radius-sm);
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    border-left: 3px solid transparent;
}

.event-item:hover {
    background: var(--background-hover);
    transform: translateX(4px);
}

.event-item.active {
    border-left-color: var(--primary-color);
    background: rgba(99, 102, 241, 0.1);
}

.event-color {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.event-info {
    flex: 1;
    min-width: 0;
}

.event-type {
    font-weight: 500;
    font-size: 0.875rem;
    margin-bottom: 0.125rem;
}

.event-details {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.event-time {
    font-family: 'SF Mono', Monaco, 'Courier New', monospace;
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

/* Legend Section */
.legend-section {
    background: var(--background-card);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
}

.legend-section h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

.legend-items {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.legend-color {
    width: 16px;
    height: 16px;
    border-radius: 4px;
}

/* Footer */
.footer {
    text-align: center;
    padding: 2rem 1rem;
    margin-top: 2rem;
    border-top: 1px solid var(--border-color);
}

.footer p {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    transition: color var(--transition-fast);
}

.footer a:hover {
    color: var(--secondary-color);
    text-decoration: underline;
}

/* Responsive Design */
@media (max-width: 768px) {
    .app-container {
        padding: 0.75rem;
    }

    .header {
        padding: 1.5rem 0.5rem;
    }

    .logo-container {
        flex-direction: column;
        gap: 0.5rem;
    }

    .upload-area {
        padding: 2rem 1rem;
    }

    .player-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .player-controls > :first-child {
        align-self: center;
    }

    .time-display {
        text-align: center;
    }

    .progress-container {
        width: 100%;
        height: 12px;
    }

    .volume-control {
        justify-content: center;
    }

    .volume-slider {
        width: 120px;
    }

    .viz-container {
        height: 200px;
    }

    .events-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .events-controls {
        width: 100%;
        justify-content: space-between;
    }

    .events-stats {
        grid-template-columns: repeat(3, 1fr);
    }

    .legend-items {
        flex-direction: column;
        gap: 0.75rem;
    }
}

@media (max-width: 480px) {
    .viz-tabs {
        justify-content: center;
    }

    .viz-tab {
        padding: 0.4rem 0.75rem;
        font-size: 0.8rem;
    }

    .events-stats {
        grid-template-columns: 1fr;
    }

    .stat-item {
        display: flex;
        justify-content: space-between;
        align-items: center;
        text-align: left;
    }

    .stat-value {
        font-size: 1.25rem;
    }
}

/* Animations */
@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.analyzing {
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.event-item {
    animation: fadeIn 0.3s ease-out;
}

/* Print styles */
@media print {
    .upload-section,
    .controls-section,
    .footer {
        display: none;
    }
}
