@import url("https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500&family=JetBrains+Mono:wght@600&display=swap");

:root {
    --bg-color: #12101b;
    --card-bg: #1c192b;
    --primary: #8764f2;
    --primary-hover: #9b7cf9;
    --text-primary: #a78bfa;
    --text-secondary: #9ca3af;
    --border: #2f2b43;
    --control-bg: rgba(0, 0, 0, 0.8);
}

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

html {
    overflow-x: hidden;
    max-width: 100vw;
}

body {
    font-family: "JetBrains Mono", monospace;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' version='1.1' xmlns:xlink='http://www.w3.org/1999/xlink' xmlns:svgjs='http://svgjs.dev/svgjs' width='1920' height='1080' preserveAspectRatio='none' viewBox='0 0 1920 1080'%3e%3cg mask='url(%26quot%3b%23SvgjsMask1007%26quot%3b)' fill='none'%3e%3crect width='1920' height='1080' x='0' y='0' fill='rgba(18%2c 16%2c 27%2c 1)'%3e%3c/rect%3e%3cpath d='M771.06 1266.87C980.44 1249.73 1076.9 853.92 1486.91 826.73 1896.92 799.54 2001.9 470.03 2202.76 459.53' stroke='rgba(161%2c 161%2c 170%2c 1)' stroke-width='2'%3e%3c/path%3e%3cpath d='M778.04 1166.26C927.05 1132.44 836.3 764.9 1213.76 737.62 1591.21 710.34 1851.88 408.51 2085.19 402.82' stroke='rgba(161%2c 161%2c 170%2c 1)' stroke-width='2'%3e%3c/path%3e%3cpath d='M919.23 1134.28C1101.74 1019.59 1012.23 379.07 1330.72 376.6 1649.21 374.13 1920.47 805.64 2153.7 819.4' stroke='rgba(161%2c 161%2c 170%2c 1)' stroke-width='2'%3e%3c/path%3e%3cpath d='M772.76 1265.07C985.41 1068.81 829.95 218.54 1204.43 191.09 1578.91 163.64 1838.21 499.5 2067.76 504.29' stroke='rgba(161%2c 161%2c 170%2c 1)' stroke-width='2'%3e%3c/path%3e%3cpath d='M366.79 1197.8C635.54 1177.95 787.42 669.03 1295.49 650.56 1803.56 632.09 1981.65 372.81 2224.19 369.76' stroke='rgba(161%2c 161%2c 170%2c 1)' stroke-width='2'%3e%3c/path%3e%3c/g%3e%3cdefs%3e%3cmask id='SvgjsMask1007'%3e%3crect width='1920' height='1080' fill='white'%3e%3c/rect%3e%3c/mask%3e%3c/defs%3e%3c/svg%3e");
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    padding: 2rem;
    overflow-x: hidden;
    max-width: 100vw;
}

.app-container {
    width: 100%;
    max-width: min(900px, calc(100vw - 4rem)); /* Account for body padding */
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

header {
    text-align: center;
    margin-bottom: 1rem;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
}

header p {
    color: var(--text-secondary);
    margin-top: 0.5rem;
}

.input-section {
    display: flex;
    gap: 1rem;
    background: var(--card-bg);
    padding: 1rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    max-width: 100%; /* Prevent overflow */
    box-sizing: border-box;
}

input[type="text"] {
    flex: 1;
    background: #111318;
    border: 1px solid var(--border);
    padding: 0.75rem 1rem;
    border-radius: 8px;
    color: white;
    font-family: inherit;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
    min-width: 0; /* Allow flexbox to shrink below content size */
    max-width: 100%;
}

input[type="text"]:focus {
    border-color: var(--primary);
}

button {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0 1.5rem;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

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

.player-container {
    position: relative;
    width: 100%;
    max-width: 100%;
    aspect-ratio: 16/9;
    background: #000;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    border: 1px solid var(--border);
    box-sizing: border-box;
}

video {
    width: 100%;
    height: 100%;
    display: block;
}

.status-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.8);
    padding: 1rem 2rem;
    border-radius: 8px;
    font-size: 1.1rem;
    pointer-events: none;
    transition: opacity 0.3s;
}

/* Custom Controls */
.controls {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to top, var(--control-bg) 0%, transparent 100%);
    padding: 2rem 1rem 1rem;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

/* Mobile: shift controls slightly left for better reach */
@media (max-width: 768px) {
    .controls {
        padding: 2rem 0.5rem 1rem 1rem;
    }
}

/* Show on hover (desktop) */
.player-container:hover .controls {
    opacity: 1;
}

/* Always show on touch devices */
@media (hover: none) and (pointer: coarse) {
    .controls {
        opacity: 1;
    }
}

/* Fullscreen mode - ensure controls auto-hide on desktop */
.player-container:fullscreen .controls,
.player-container:-webkit-full-screen .controls,
.player-container:-moz-full-screen .controls,
.player-container:-ms-fullscreen .controls {
    opacity: 0;
}

/* Show controls on hover in fullscreen (desktop) */
.player-container:fullscreen:hover .controls,
.player-container:-webkit-full-screen:hover .controls,
.player-container:-moz-full-screen:hover .controls,
.player-container:-ms-fullscreen:hover .controls {
    opacity: 1;
}

/* Keep controls visible in fullscreen on touch devices */
@media (hover: none) and (pointer: coarse) {
    .player-container:fullscreen .controls,
    .player-container:-webkit-full-screen .controls,
    .player-container:-moz-full-screen .controls,
    .player-container:-ms-fullscreen .controls {
        opacity: 1;
    }
}

.progress-container {
    margin-bottom: 0.5rem;
    cursor: pointer;
}

.progress-bar {
    height: 5px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 10px;
    overflow: hidden;
    transition: height 0.2s;
}

.progress-container:hover .progress-bar {
    height: 8px;
}

.progress-filled {
    height: 100%;
    background: var(--primary);
    width: 0%;
    transition: width 0.1s;
}

.controls-bottom {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.control-btn {
    background: transparent;
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
    padding: 0;
    position: relative;
}

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

.icon {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

.skip-label {
    position: absolute;
    font-size: 10px;
    font-weight: 700;
    bottom: 2px;
    right: 6px;
}

.time-display {
    font-size: 14px;
    color: white;
    margin-left: 0.5rem;
}

.spacer {
    flex: 1;
}

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

.volume-slider {
    width: 80px;
    height: 4px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.3);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

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

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

.control-select {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 14px;
    cursor: pointer;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.control-select:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* Fix dropdown options visibility */
.control-select option {
    background: #1c1f26;
    color: white;
    padding: 0.5rem;
}

.stats-panel {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    max-width: 100%; /* Prevent overflow */
    box-sizing: border-box;
}

.stat-item {
    background: var(--card-bg);
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    box-sizing: border-box;
    min-width: 0; /* Allow grid items to shrink */
}

.stat-item .label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.stat-item .value {
    font-weight: 600;
    font-family: monospace;
}

/* Compact subtitle button in stats panel */
.subtitle-upload-stat {
    flex-direction: column;
    gap: 0.5rem;
}

.subtitle-label-compact {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.5rem 1rem;
    background: var(--primary);
    color: white;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    font-size: 13px;
    transition: background 0.2s;
}

.subtitle-label-compact:hover {
    background: var(--primary-hover);
}

.subtitle-list-compact {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    width: 100%;
    justify-content: center;
}

.subtitle-item {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.6rem;
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: 4px;
    font-size: 12px;
}

.subtitle-item.active {
    background: rgba(59, 130, 246, 0.3);
    border-color: var(--primary);
}

.subtitle-remove {
    background: transparent;
    border: none;
    color: #ef4444;
    cursor: pointer;
    padding: 0;
    font-size: 18px;
    line-height: 1;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.subtitle-remove:hover {
    color: #dc2626;
}

/* ===== MOBILE RESPONSIVE STYLES ===== */

/* Tablet and below */
@media (max-width: 768px) {
    body {
        padding: 1rem; /* Reduced from 2rem */
        overflow-x: hidden;
    }

    .app-container {
        max-width: calc(100vw - 2rem); /* Account for reduced padding */
        gap: 1.5rem;
    }

    header h1 {
        font-size: 2rem;
    }

    header p {
        font-size: 0.9rem;
    }

    .app-container {
        gap: 1.5rem;
        max-width: 100%;
    }

    /* Fix player width */
    .player-container {
        width: 100%;
    }

    /* Stack input section on mobile */
    .input-section {
        flex-direction: column;
        gap: 0.75rem;
    }

    button {
        width: 100%;
        padding: 0.75rem;
    }

    /* Stats panel - 2 columns on tablet */
    .stats-panel {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }

    /* Make subtitle stat full width */
    .subtitle-upload-stat {
        grid-column: span 2;
    }

    /* Adjust control button sizes */
    .control-btn {
        width: 40px;
        height: 40px;
    }

    .icon {
        width: 22px;
        height: 22px;
    }
}

/* Mobile phones */
@media (max-width: 480px) {
    body {
        padding: 0.5rem; /* Further reduced for mobile */
        overflow-x: hidden !important; /* Prevent horizontal scroll */
    }

    .app-container {
        max-width: calc(100vw - 1rem) !important; /* Account for mobile padding */
        gap: 1rem;
        overflow-x: hidden;
    }

    /* Universal overflow prevention */
    .app-container > * {
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    .input-section,
    .player-container,
    .stats-panel {
        width: 100%;
        max-width: 100%;
        overflow-x: hidden;
    }

    header {
        margin-bottom: 0.5rem;
    }

    header h1 {
        font-size: 1.75rem;
    }

    header p {
        font-size: 0.85rem;
        margin-top: 0.25rem;
    }

    .app-container {
        gap: 1rem;
        max-width: 100%; /* Ensure it doesn't exceed viewport */
    }

    /* Fix player overflow */
    .player-container {
        width: 100%;
        max-width: 100%;
        margin: 0;
    }

    /* Stack stats panel vertically */
    .stats-panel {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }

    .subtitle-upload-stat {
        grid-column: span 1;
    }

    .stat-item {
        padding: 0.75rem;
    }

    /* Make player controls more touch-friendly */
    .controls {
        padding: 1.5rem 0.5rem 0.5rem;
        opacity: 1; /* Always visible on mobile */
    }

    .controls-bottom {
        gap: 0.35rem;
        max-width: 100%; /* Prevent overflow */
    }

    .control-btn {
        width: 44px; /* Larger touch targets */
        height: 44px;
        flex-shrink: 0; /* Don't shrink buttons */
    }

    .icon {
        width: 24px;
        height: 24px;
    }

    /* Adjust time display */
    .time-display {
        font-size: 12px;
        margin-left: 0.15rem;
        margin-right: 0.15rem;
        flex-shrink: 0; /* Prevent shrinking */
        white-space: nowrap; /* Keep on one line */
    }

    /* Make volume slider easier to use */
    .volume-slider {
        width: 60px;
        flex-shrink: 0;
    }

    /* Compact playback speed select */
    .control-select {
        padding: 0.35rem 0.5rem;
        font-size: 12px;
        flex-shrink: 0;
    }

    /* Reduce input padding */
    input[type="text"] {
        padding: 0.65rem 0.85rem;
        font-size: 0.9rem;
    }

    button {
        padding: 0.65rem;
        font-size: 0.9rem;
    }

    /* Compact stat items */
    .stat-item .label {
        font-size: 0.75rem;
    }

    .stat-item .value {
        font-size: 0.85rem;
    }

    /* Smaller subtitle button */
    .subtitle-label-compact {
        padding: 0.4rem 0.75rem;
        font-size: 11px;
        gap: 0.25rem;
    }

    .subtitle-label-compact .icon {
        width: 16px;
        height: 16px;
    }

    .subtitle-item {
        font-size: 11px;
        padding: 0.3rem 0.5rem;
    }

    /* Skip label adjustment */
    .skip-label {
        font-size: 9px;
        bottom: 1px;
        right: 5px;
    }
}

/* iPhone SE and similar (375px) */
@media (max-width: 375px) {
    /* Tighter control spacing */
    .controls-bottom {
        gap: 0.2rem;
        flex-wrap: wrap;
        justify-content: center;
    }

    /* Smaller buttons */
    .control-btn {
        width: 40px;
        height: 40px;
    }

    .icon {
        width: 20px;
        height: 20px;
    }

    /* More compact time display */
    .time-display {
        font-size: 11px;
        margin: 0 0.1rem;
    }

    /* Reduce volume slider width */
    .volume-slider {
        width: 50px;
    }

    /* More compact playback speed */
    .control-select {
        padding: 0.3rem 0.4rem;
        font-size: 11px;
        min-width: 48px;
    }
}

/* Very small phones */
@media (max-width: 360px) {
    header h1 {
        font-size: 1.5rem;
    }

    header p {
        font-size: 0.8rem;
    }

    /* More compact controls on very small screens */
    .controls {
        padding: 1rem 0.25rem 0.5rem;
    }

    /* Allow controls to wrap and ensure they fit within viewport */
    .controls-bottom {
        gap: 0.25rem;
        flex-wrap: wrap;
        justify-content: center;
        max-width: 100%;
    }

    /* Hide volume slider on very small phones (use physical buttons) */
    .volume-container .volume-slider {
        display: none;
    }

    /* Reduce button sizes to fit more controls */
    .control-btn {
        width: 36px;
        height: 36px;
        flex-shrink: 0;
    }

    .icon {
        width: 18px;
        height: 18px;
    }

    /* Compact time display */
    .time-display {
        font-size: 10px;
        margin: 0 0.1rem;
        white-space: nowrap;
        flex-shrink: 0;
    }

    /* Make playback speed selector more compact */
    .control-select {
        padding: 0.2rem 0.3rem;
        font-size: 10px;
        min-width: 45px;
    }

    /* Ensure spacer doesn't take up too much space */
    .spacer {
        flex: 0;
        width: 0;
    }
}

/* Landscape mode on mobile */
@media (max-width: 768px) and (orientation: landscape) {
    body {
        padding: 0.5rem;
    }

    .app-container {
        gap: 0.75rem;
    }

    header {
        margin-bottom: 0.25rem;
    }

    header h1 {
        font-size: 1.5rem;
    }

    header p {
        font-size: 0.8rem;
        margin-top: 0.25rem;
    }

    /* Keep stats in 3 columns for landscape */
    .stats-panel {
        grid-template-columns: repeat(3, 1fr);
    }

    .subtitle-upload-stat {
        grid-column: span 1;
    }
}

/* Settings Panel */
.settings-panel {
    position: absolute;
    bottom: 60px;
    right: 10px;
    background: rgba(28, 25, 43, 0.98);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    min-width: 220px;
    z-index: 100;
    backdrop-filter: blur(10px);
    animation: slideUp 0.2s ease-out;
}

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

.settings-section {
    margin-bottom: 1rem;
}

.settings-section:last-of-type {
    margin-bottom: 0.5rem;
}

.settings-label {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.settings-select {
    width: 100%;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 0.5rem;
   border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    outline: none;
    font-family: inherit;
}

.settings-select:hover {
    background: rgba(255, 255, 255, 0.15);
}

.settings-select option {
    background: #1c192b;
    color: white;
    padding: 0.5rem;
}

.settings-button {
    width: 100%;
    background: rgba(135, 100, 242, 0.2);
    color: var(--text-primary);
    border: 1px solid var(--primary);
    padding: 0.5rem;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    font-family: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.2s;
}

.settings-button:hover {
    background: rgba(135, 100, 242, 0.3);
}

.icon-small {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.settings-hint {
    font-size: 11px;
    color: var(--text-secondary);
    text-align: center;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
    font-style: italic;
}
