:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --secondary: #64748b;
    --bg-dark: #0f172a;
    --card-bg: rgba(30, 41, 59, 0.7);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --success: #22c55e;
    --error: #ef4444;
    --accent: #ffd700;
    --glass-border: rgba(255, 255, 255, 0.1);
    --font-outfit: 'Outfit', sans-serif;
    --font-inter: 'Inter', sans-serif;
}

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

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: var(--font-inter);
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-tap-highlight-color: transparent;
}

.background-glow {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60vw;
    height: 60vw;
    background: radial-gradient(circle, rgba(99, 102, 241, 0.15) 0%, rgba(15, 23, 42, 0) 70%);
    z-index: -1;
    pointer-events: none;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--glass-border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

.logo-icon {
    font-size: 1.5rem;
}

.logo h1 {
    font-family: var(--font-outfit);
    font-size: 1.5rem;
    font-weight: 700;
}

.gradient-text {
    background: linear-gradient(135deg, #818cf8 0%, #6366f1 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.search-bar {
    display: flex;
    gap: 0.5rem;
    flex: 0 1 500px;
}

.search-bar input {
    flex: 1;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 0.75rem 1rem;
    color: white;
    font-family: var(--font-inter);
    transition: 0.3s;
    font-size: 16px;
    /* Prevents auto-zoom on iOS */
}

.search-bar input:focus {
    outline: none;
    border-color: var(--primary);
    background: rgba(255, 255, 255, 0.1);
}

.search-bar button {
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 12px;
    padding: 0.75rem 1.5rem;
    font-weight: 600;
    cursor: pointer;
    transition: 0.3s;
    white-space: nowrap;
}

.search-bar button:hover {
    background: var(--primary-hover);
}

main {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 2rem;
    max-width: 1400px;
    margin: 1.5rem auto;
    padding: 0 1.5rem;
    transition: all 0.3s ease;
}

.left-panel {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    min-width: 0;
    /* Prevents flex items from overflowing */
}

.video-container {
    width: 100%;
    aspect-ratio: 16/9;
    max-height: 500px;
    background: #000;
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--glass-border);
}

#player {
    width: 100%;
    height: 100%;
}

.video-info h2 {
    font-family: var(--font-outfit);
    font-size: 1.25rem;
    margin-bottom: 1rem;
    font-weight: 600;
}

.auto-subs-warning {
    background: rgba(255, 107, 107, 0.1);
    border: 1px solid rgba(255, 107, 107, 0.2);
    color: #ff6b6b;
    padding: 10px 14px;
    border-radius: 10px;
    margin-bottom: 1.5rem;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 8px;
    animation: fadeIn 0.5s ease;
}

.hidden {
    display: none !important;
}

.sentence-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    background: rgba(255, 255, 255, 0.03);
    padding: 1rem;
    border-radius: 16px;
    border: 1px solid var(--glass-border);
}

.icon-btn {
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 1.1rem;
}

.icon-btn:hover {
    background: var(--primary);
    border-color: var(--primary);
    transform: translateY(-2px);
}

.replay-settings {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.05);
    padding: 0.4rem 0.8rem;
    border-radius: 10px;
}

.replay-settings select {
    background: transparent;
    border: none;
    color: var(--primary);
    font-weight: 600;
    cursor: pointer;
    outline: none;
    font-size: 0.85rem;
}

.time-nav {
    display: flex;
    gap: 0.5rem;
    margin-left: auto;
}

.time-nav button {
    background: transparent;
    border: 1px solid var(--glass-border);
    color: var(--text-muted);
    padding: 0.4rem 0.7rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: 0.2s;
}

.time-nav button:hover {
    border-color: var(--text-main);
    color: var(--text-main);
}

.right-panel {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.dictation-card {
    background: var(--card-bg);
    backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    position: sticky;
    top: 5.5rem;
}

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

#progress-text {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.progress-bar-bg {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
    overflow: hidden;
}

#progress-bar-fill {
    height: 100%;
    background: var(--primary);
    transition: width 0.3s ease;
}

.feedback-display {
    min-height: 4rem;
    font-size: 1.15rem;
    line-height: 1.6;
    padding: 1rem;
    background: rgba(0, 0, 0, 0.25);
    border-radius: 12px;
    color: var(--text-muted);
    border: 1px solid rgba(255, 255, 255, 0.03);
}

.feedback-display .correct {
    color: var(--success);
}

.feedback-display .incorrect {
    color: var(--error);
    text-decoration: underline dotted;
}

.feedback-display .masked {
    color: var(--text-muted);
    opacity: 0.3;
}

.feedback-display .hint {
    color: var(--accent);
    font-weight: 600;
}

.feedback-display .typing {
    border-bottom: 2px solid var(--primary);
    color: #fff;
}

textarea {
    width: 100%;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 1rem;
    color: white;
    font-family: inherit;
    font-size: 1.1rem;
    resize: none;
    transition: 0.2s;
}

textarea:focus {
    outline: none;
    border-color: var(--primary);
    background: rgba(255, 255, 255, 0.06);
}

.dictation-actions {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1rem;
}

.primary-btn {
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 12px;
    padding: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s;
}

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

.secondary-btn {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 1rem;
    cursor: pointer;
    transition: 0.2s;
}

.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.shortcut-hint {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.75rem;
    opacity: 0.8;
}

.correct-answer-card {
    background: rgba(34, 197, 94, 0.1);
    border-left: 4px solid var(--success);
    padding: 1.25rem;
    border-radius: 12px;
    margin-bottom: 1rem;
}

.correct-answer-card h3 {
    font-size: 0.8rem;
    color: var(--success);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

#correct-text {
    font-size: 1.1rem;
    line-height: 1.6;
}

.translation-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    padding: 1rem;
    border-radius: 12px;
}

.translation-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.welcome-screen {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-dark);
    z-index: 50;
    padding: 2rem;
}

.welcome-content {
    text-align: center;
    max-width: 600px;
}

.welcome-content h2 {
    font-size: 3rem;
    margin-bottom: 1rem;
    font-family: var(--font-outfit);
}

.features {
    display: flex;
    justify-content: center;
    gap: 2.5rem;
    margin-top: 3rem;
}

.feature-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

.feature-icon {
    font-size: 2rem;
}

.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(10px);
}

.loader {
    width: 48px;
    height: 48px;
    border: 3px solid rgba(99, 102, 241, 0.2);
    border-radius: 50%;
    border-top-color: var(--primary);
    animation: spin 1s linear infinite;
    margin-bottom: 1.5rem;
}

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

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- RESPONSIVE BREAKPOINTS --- */

/* TABLET (iPad) */
@media (max-width: 1024px) {
    main {
        grid-template-columns: 1fr;
        padding: 0 1rem;
        gap: 1.5rem;
    }

    .dictation-card {
        position: static;
        margin-bottom: 2rem;
    }

    .video-container {
        max-height: 400px;
    }
}

/* MOBILE LANDSCAPE */
@media (max-height: 500px) and (orientation: landscape) {
    header {
        padding: 0.5rem 1rem;
    }

    .logo h1 {
        font-size: 1.2rem;
    }

    .welcome-content h2 {
        font-size: 2rem;
    }

    .features {
        margin-top: 1rem;
        gap: 1rem;
    }

    main {
        margin-top: 0.5rem;
    }
}

/* MOBILE PORTRAIT */
@media (max-width: 640px) {
    header {
        flex-direction: column;
        padding: 1rem;
        gap: 1rem;
    }

    .search-bar {
        width: 100%;
        flex: 1;
    }

    .welcome-content h2 {
        font-size: 2rem;
    }

    .features {
        flex-direction: column;
        gap: 1.5rem;
        margin-top: 2rem;
    }

    .sentence-controls {
        justify-content: center;
        padding: 0.75rem;
    }

    .time-nav {
        width: 100%;
        justify-content: center;
        margin-left: 0;
        margin-top: 0.5rem;
    }

    .dictation-actions {
        grid-template-columns: 1fr;
    }

    .feedback-display {
        font-size: 1rem;
    }

    textarea {
        font-size: 1rem;
    }

    .logo h1 {
        font-size: 1.3rem;
    }

    .video-info h2 {
        font-size: 1.1rem;
    }

    .icon-btn {
        width: 40px;
        height: 40px;
    }
}

/* SMALL MOBILE */
@media (max-width: 380px) {
    .sentence-controls {
        gap: 0.5rem;
    }

    .replay-settings {
        width: 100%;
        justify-content: center;
    }
}