* {
    box-sizing: border-box;
}

/* Accessibility: Visible Focus */
*:focus-visible {
    outline: 3px solid #ffd700;
    outline-offset: 2px;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #121212;
    color: #e0e0e0;
    margin: 0;
    padding: 10px;
    display: flex;
    justify-content: center;
    overflow-x: hidden;
    /* Prevent horizontal scroll */
}

.container {
    max-width: 800px;
    width: 100%;
    margin-bottom: 60px;
}

.header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

h1 {
    font-size: 1.5rem;
    color: #ffd700;
    margin: 0;
    /* Let header-row handle spacing */
}

/* Inputs & Buttons */
.input-group {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

input[type="text"] {
    flex: 1;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid #444;
    background: #1e1e1e;
    color: #fff;
    min-width: 200px;
}

.clear-btn {
    position: absolute;
    right: 5px;
    top: 50%;
    transform: translateY(-50%);
    margin: 0;

    /* Strict Geometry - No Circle, Just Icon */
    width: 30px !important;
    height: 30px !important;
    min-width: 0 !important;
    min-height: 0 !important;
    padding: 0 !important;
    border-radius: 50%;
    /* Restore circle for focus rings */

    background: transparent !important;
    -webkit-tap-highlight-color: transparent;
    /* Remove mobile tap box */
    border: none;
    color: #888;
    cursor: pointer;
    font-size: 1.2em;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    line-height: 1;
}

.clear-btn:hover,
.clear-btn:focus,
.clear-btn:active {
    background: transparent !important;
    color: #fff;
    filter: none;
    outline: none;
}

.clear-btn:disabled {
    background: transparent !important;
    color: #666 !important;
    /* Dimmed color */
    filter: none;
    transform: translateY(-50%) !important;
    /* Prevent jumping */
    cursor: default;
}

.clear-btn:active {
    transform: translateY(-50%) scale(0.9);
    /* Keeps centering while scaling */
}

button {
    padding: 12px 20px;
    border-radius: 8px;
    border: none;
    background: #2196f3;
    color: white;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.2s;
    /* Touch target size */
    min-height: 44px;
}

button:hover {
    filter: brightness(1.1);
}

button:active {
    transform: scale(0.98);
}

button:disabled {
    background: #555 !important;
    color: #aaa;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-secondary {
    background: #009688;
}

.btn-info {
    background: #00bcd4;
}

.btn-warn {
    background: #ff9800;
}

.btn-danger {
    background: #f44336;
}

/* Bars (Sync, TTS) */
.sync-bar,
.tts-controls {
    background: #1e1e1e;
    padding: 15px;
    margin: 10px 0;
    border-radius: 12px;
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

.control-group {
    display: flex;
    align-items: center;
    gap: 5px;
    background: #333;
    padding: 5px 10px;
    border-radius: 20px;
}

.code-display {
    font-family: monospace;
    color: #ffeb3b;
    font-weight: bold;
    margin-left: auto;
}

.status-text {
    font-size: 0.85em;
    color: #888;
    margin-left: auto;
}

/* File List */
#fileList {
    background: #1e1e1e;
    padding: 15px;
    border-radius: 12px;
    margin-top: 20px;
}

.file-item {
    padding: 12px;
    background: #2c2c2c;
    margin: 5px 0;
    border-radius: 6px;
    cursor: pointer;
    border-left: 3px solid transparent;

    /* Responsive Text Wrapping */
    white-space: normal;
    word-break: break-word;
    /* Handle long filenames */
    overflow-wrap: break-word;
    font-size: 0.9em;
    line-height: 1.4;
}

#videoSelect {
    margin-bottom: 20px;
    border-bottom: 1px solid #333;
    padding-bottom: 10px;
}

.file-item.selected {
    background: #3d3d3d;
    border-left-color: #2196f3;
}

/* Play Button - Distinguished */
#playBtn {
    background: linear-gradient(135deg, #4caf50, #2e7d32);
    font-size: 1.2rem;
    padding: 15px;
    text-transform: uppercase;
    letter-spacing: 1px;
    box-shadow: 0 4px 15px rgba(76, 175, 80, 0.4);

    /* Standard Layout */
    display: block;
    width: 100%;
    margin-top: 30px;
    border-radius: 12px;
}

#playBtn:disabled {
    background: #555;
    cursor: not-allowed;
    box-shadow: none;
}

/* Video & Subtitles */
.player-container {
    position: relative;
    margin-top: 20px;
}

video {
    width: 100%;
    border-radius: 12px;
    background: #000;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

#subtitleDisplay {
    position: absolute;
    bottom: 5%;
    left: 0;
    right: 0;
    margin: 0 auto;
    width: 90%;
    text-align: center;
    pointer-events: none;

    /* Netflix Style Typography */
    font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
    font-size: clamp(1rem, 2vw, 1.5rem);
    /* Reduced significantly */
    font-weight: 400;
    color: #ffffff;
    line-height: 1.2;

    /* Heavy Shadow/Outline */
    text-shadow:
        0 0 2px rgba(0, 0, 0, 1),
        0 0 4px rgba(0, 0, 0, 0.8),
        0 0 8px rgba(0, 0, 0, 0.8);

    background: transparent;
    padding: 10px;
    z-index: 2147483647;
    /* Max z-index to stay on top */
}

/* Fullscreen Overrides */
.player-container:fullscreen {
    background: black;
    display: flex;
    justify-content: center;
    align-items: center;
}

.player-container:fullscreen video {
    height: 100vh;
    width: 100vw;
    object-fit: contain;
}

.player-container:fullscreen #subtitleDisplay {
    bottom: 8%;
    font-size: clamp(1.5rem, 3vw, 2.5rem);
    /* Slightly larger in fullscreen */
}

/* Fake Fullscreen (iOS / Fallback) */
.fake-fullscreen {
    position: fixed !important;
    top: 0;
    left: 0;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 999999;
    background: black;
    margin: 0 !important;
    display: flex;
    justify-content: center;
    align-items: center;
}

.fake-fullscreen video {
    height: 100% !important;
    width: 100% !important;
    object-fit: contain;
}

.fake-fullscreen #subtitleDisplay {
    bottom: 10% !important;
    font-size: 1.5rem !important;
}



@media (max-width: 600px) {
    body {
        padding: 10px;
    }

    .sync-bar,
    .tts-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .control-group {
        justify-content: space-between;
    }

    .code-display,
    .status-text {
        margin-left: 0;
        text-align: center;
        margin-top: 5px;
        width: 100%;
    }

    input[type="range"] {
        flex: 1;
    }

    /* Full width buttons and inputs */
    button:not(.clear-btn),
    input[type="text"],
    .input-group,
    .magnet-wrapper,
    /* Added this */
    .control-group {
        width: 100%;
        justify-content: center;
        margin-bottom: 5px;
    }

    .input-group {
        flex-direction: column;
        gap: 10px;
    }

    /* Search Buttons Stack */
    .search-row button {
        width: 100%;
        margin-left: 0 !important;
        /* Override inline margin */
        margin-top: 5px;
    }

    .search-row {
        display: flex;
        flex-direction: column;
    }
}

.hidden {
    display: none !important;
}

/* Upload Section */
.upload-section {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #333;
    text-align: left;
}

.section-label {
    margin: 0 0 10px 0;
    color: #aaa;
    font-size: 0.9em;
}

.upload-controls {
    display: flex;
    gap: 15px;
    align-items: center;
    flex-wrap: wrap;
}

.file-input {
    flex: 1;
    background: #1e1e1e;
    padding: 10px;
    border-radius: 8px;
    color: #bbb;
    border: 1px solid #333;
    min-width: 200px;
    max-width: 100%;
}

/* File input custom styling */
.file-input::file-selector-button {
    background: #444;
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 6px;
    margin-right: 15px;
    cursor: pointer;
    transition: background 0.2s;
}

.file-input::file-selector-button:hover {
    background: #555;
}

.btn-sm {
    padding: 10px 20px;
    font-size: 0.9em;
    min-height: auto;
    white-space: nowrap;
}

/* Sync Buttons Mobile Tweaks */
@media (max-width: 600px) {
    .upload-controls {
        flex-direction: column;
        align-items: stretch;
    }

    /* Make clear button full width and spaced out on mobile */
    .btn-sm {
        width: 100%;
        margin-top: 10px;
    }

    /* Wrap file input content if needed */
    .file-input {
        width: 100%;
    }

    .upload-grid {
        grid-template-columns: 1fr !important;
    }
}

/* New Upload Grid Layout */
.upload-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.upload-card {
    background: #252525;
    padding: 15px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    gap: 15px;
    border: 1px solid #333;
    transition: transform 0.2s, background 0.2s;
}

.upload-card:hover {
    background: #2a2a2a;
    transform: translateY(-2px);
    border-color: #444;
}

.card-icon {
    font-size: 1.5rem;
    color: #2196f3;
    background: rgba(33, 150, 243, 0.1);
    width: 40px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 8px;
}

.upload-card:nth-child(2) .card-icon {
    color: #ff9800;
    /* Orange for subtitles */
    background: rgba(255, 152, 0, 0.1);
}

.card-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 5px;
    overflow: hidden;
    min-width: 0;
    /* Enable flex truncation */
}

.card-content label {
    font-size: 0.9em;
    font-weight: 600;
    color: #ddd;

    /* Responsive Text Wrapping */
    white-space: normal;
    word-break: break-word;
    overflow-wrap: break-word;
    /* Standard property */
    line-height: 1.3;
}

/* Override file input to be cleaner inside card */
.file-input {
    background: transparent;
    border: none;
    padding: 0;
    min-width: 0;
}

.file-input::file-selector-button {
    padding: 6px 12px;
    font-size: 0.8em;
    margin-right: 10px;
    background: #444;
    color: #eee;
}