:root {
    --bg-color: #f8f9fa;
    --surface-color: #ffffff;
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-full: 9999px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.5;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* Prevent body scroll */
}

.app-container {
    max-width: 1400px;
    /* Increased max-width for sidebar */
    margin: 0 auto;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: row;
    /* Side-by-side layout */
    padding: 1rem;
    gap: 1.5rem;
}

/* Sidebar */
.sidebar {
    width: 250px;
    background-color: var(--surface-color);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow: hidden;
    transition: transform 0.3s ease;
}

.sidebar.hidden {
    display: none;
}

.sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    background-color: #f8fafc;
}

.sidebar-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

#section-list,
#saved-papers-list {
    list-style: none;
    overflow-y: auto;
    flex: 1;
    padding: 0.5rem;
}

.section-item {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-secondary);
    transition: all 0.2s;
    margin-bottom: 0.25rem;
}

.section-item:hover {
    background-color: #f1f5f9;
    color: var(--primary-color);
}

.section-item.active {
    background-color: #eff6ff;
    color: var(--primary-color);
    font-weight: 500;
}

/* Content Area */
.content-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-width: 0;
    /* Prevent flex overflow */
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 0 1rem 0;
    flex-shrink: 0;
}

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

.api-input {
    padding: 0.625rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    width: 250px;
    transition: border-color 0.2s;
}

.api-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--text-primary);
}

.logo svg {
    color: var(--primary-color);
}

.primary-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 0.625rem 1.25rem;
    border-radius: var(--radius-md);
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
    font-size: 0.875rem;
}

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

main {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    min-height: 0;
    /* Important for nested flex scrolling */
}

/* Upload Zone */
.upload-zone {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-lg);
    background-color: var(--surface-color);
    color: var(--text-secondary);
    transition: all 0.2s;
    cursor: pointer;
}

.upload-zone:hover {
    border-color: var(--primary-color);
    background-color: #eff6ff;
}

.icon-box {
    background-color: #f1f5f9;
    padding: 1.5rem;
    border-radius: var(--radius-full);
    margin-bottom: 1.5rem;
    color: var(--text-secondary);
}

.upload-zone h2 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

/* Player Interface */
#player-interface {
    display: flex;
    flex-direction: column;
    height: 100%;
    gap: 1rem;
}

.text-display {
    flex: 1;
    background-color: var(--surface-color);
    border-radius: var(--radius-lg);
    padding: 2rem;
    overflow-y: auto;
    box-shadow: var(--shadow-sm);
    font-size: 1.125rem;
    line-height: 1.8;
    color: #334155;
    border: 1px solid var(--border-color);
    scroll-behavior: smooth;
}

.text-display p {
    margin-bottom: 1.5rem;
}

.highlight {
    background-color: #fef08a;
    /* Yellow highlight */
    color: black;
    padding: 0.1rem 0;
    border-radius: 2px;
    transition: background-color 0.2s;
}

.controls-wrapper {
    background-color: var(--surface-color);
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    flex-shrink: 0;
}

.progress-area {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
    font-variant-numeric: tabular-nums;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

#progress-bar {
    flex: 1;
    height: 6px;
    -webkit-appearance: none;
    background: var(--border-color);
    border-radius: var(--radius-full);
    outline: none;
    cursor: pointer;
}

#progress-bar::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.1s;
}

#progress-bar::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.main-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.playback-buttons {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.control-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-primary);
    transition: transform 0.1s, color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

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

.primary-circle {
    width: 64px;
    height: 64px;
    background-color: var(--primary-color);
    color: white;
    border-radius: 50%;
    box-shadow: var(--shadow-md);
}

.primary-circle:hover {
    background-color: var(--primary-hover);
    color: white;
    transform: scale(1.05);
}

.speed-control {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.speed-control .label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
}

#speed-select {
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background-color: var(--bg-color);
    font-size: 0.875rem;
    color: var(--text-primary);
    cursor: pointer;
}

/* Utilities */
.hidden {
    display: none !important;
}

/* Loading Overlay */
#loading-overlay {
    position: absolute;
    inset: 0;
    background-color: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    z-index: 10;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
        padding: 0.5rem;
    }

    .sidebar {
        width: 100%;
        max-height: 200px;
        /* Collapsed on mobile */
    }

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

    .api-input {
        width: 100%;
    }
}