/* ============================================
   YouTube Looper 2 — Web Edition (Premium Dark Theme)
   ============================================ */

:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-tertiary: #1a1a28;
    --bg-card: #14141f;
    --bg-card-hover: #1c1c2e;
    --bg-input: #1a1a28;
    --border: rgba(255, 255, 255, 0.06);
    --border-hover: rgba(255, 255, 255, 0.12);
    --text-primary: #eeeef0;
    --text-secondary: #9898a8;
    --text-muted: #5a5a6e;
    --accent-purple: #a855f7;
    --accent-pink: #ec4899;
    --accent-blue: #6366f1;
    --gradient-primary: linear-gradient(135deg, #a855f7, #ec4899);
    --gradient-subtle: linear-gradient(135deg, rgba(168, 85, 247, 0.15), rgba(236, 72, 153, 0.15));
    --gradient-glow: linear-gradient(135deg, rgba(168, 85, 247, 0.3), rgba(236, 72, 153, 0.3));
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 30px rgba(168, 85, 247, 0.15);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
    --transition-smooth: 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
}

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

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Background ambient glow */
body::before {
    content: '';
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(ellipse at 30% 20%, rgba(168, 85, 247, 0.06) 0%, transparent 50%),
        radial-gradient(ellipse at 70% 80%, rgba(236, 72, 153, 0.04) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

/* ============================================
   Layout
   ============================================ */

.app-container {
    position: relative;
    z-index: 1;
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px 32px;
    min-height: 100vh;
}

/* ============================================
   Header
   ============================================ */

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 28px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    gap: 12px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: var(--gradient-subtle);
    border-radius: var(--radius-md);
    border: 1px solid rgba(168, 85, 247, 0.2);
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.02em;
}

.web-badge {
    font-size: 0.65rem;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 999px;
    background: rgba(168, 85, 247, 0.15);
    border: 1px solid rgba(168, 85, 247, 0.35);
    color: #d8b4fe;
    letter-spacing: 0.06em;
}

.header-right-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.tagline {
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 400;
    margin-right: 6px;
}

.btn-header-action {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-secondary);
    padding: 7px 13px;
    font-size: 0.8rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-header-action:hover {
    color: var(--text-primary);
    border-color: var(--accent-purple);
    background: rgba(168, 85, 247, 0.1);
}

/* ============================================
   Main Content — Two Column Layout
   ============================================ */

.main-content {
    display: grid;
    grid-template-columns: 1fr 420px;
    gap: 24px;
    align-items: start;
}

/* ============================================
   Add Video Card
   ============================================ */

.add-video-card {
    margin-bottom: 20px;
}

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

.input-wrapper {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
}

.input-icon {
    position: absolute;
    left: 14px;
    color: var(--text-muted);
    pointer-events: none;
    transition: color var(--transition-normal);
}

.input-wrapper input {
    width: 100%;
    padding: 13px 16px 13px 44px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: inherit;
    outline: none;
    transition: all var(--transition-normal);
}

.input-wrapper input::placeholder {
    color: var(--text-muted);
}

.input-wrapper input:focus {
    border-color: var(--accent-purple);
    box-shadow: 0 0 0 3px rgba(168, 85, 247, 0.1);
}

.input-wrapper input:focus~.input-icon,
.input-wrapper:has(input:focus) .input-icon {
    color: var(--accent-purple);
}

/* ============================================
   Buttons
   ============================================ */

.btn-primary {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 12px 20px;
    background: var(--gradient-primary);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition-normal);
    white-space: nowrap;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 20px rgba(168, 85, 247, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-ghost {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 7px 10px;
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition-normal);
}

.btn-ghost:hover {
    color: var(--text-primary);
    border-color: var(--border-hover);
    background: var(--bg-tertiary);
}

/* ============================================
   Player Card
   ============================================ */

.player-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-md);
}

.player-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    background: #000;
    overflow: hidden;
}

.player-wrapper iframe {
    width: 100%;
    height: 100%;
    border: none;
}

.player-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--text-muted);
    background: linear-gradient(180deg, #0d0d15 0%, #111120 100%);
}

.player-placeholder p {
    font-size: 0.95rem;
    font-weight: 500;
}

/* Now Playing */
.now-playing {
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
}

.now-playing-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.now-playing-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--accent-purple);
    white-space: nowrap;
}

.pulse-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-purple);
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.4;
        transform: scale(0.8);
    }
}

.now-playing-title {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

/* Progress Bar */
.progress-section {
    padding: 12px 20px 6px;
    background: var(--bg-secondary);
}

.progress-bar-container {
    position: relative;
    cursor: pointer;
    padding: 6px 0;
}

.progress-bar-bg {
    position: relative;
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 2px;
    overflow: visible;
}

.progress-bar-fill {
    height: 100%;
    background: var(--gradient-primary);
    border-radius: 2px;
    width: 0%;
    transition: width 0.1s linear;
    position: relative;
}

.progress-bar-handle {
    position: absolute;
    top: 50%;
    left: 0%;
    transform: translate(-50%, -50%) scale(0);
    width: 14px;
    height: 14px;
    background: white;
    border-radius: 50%;
    box-shadow: 0 0 8px rgba(168, 85, 247, 0.5);
    transition: transform var(--transition-fast);
    z-index: 2;
}

.progress-bar-container:hover .progress-bar-handle {
    transform: translate(-50%, -50%) scale(1);
}

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

.time-display {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    padding-top: 4px;
}

/* Playback Controls */
.playback-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 20px 16px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
}

.ctrl-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-normal);
    position: relative;
}

.ctrl-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.06);
}

.ctrl-btn.active {
    color: var(--accent-purple);
}

.ctrl-btn.active:hover {
    background: rgba(168, 85, 247, 0.1);
}

.ctrl-btn.play-btn {
    width: 52px;
    height: 52px;
    background: var(--gradient-primary);
    color: white;
    border-radius: 50%;
    margin: 0 8px;
    box-shadow: 0 4px 16px rgba(168, 85, 247, 0.3);
}

.ctrl-btn.play-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 24px rgba(168, 85, 247, 0.4);
    color: white;
    background: var(--gradient-primary);
}

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

.loop-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    font-size: 0.55rem;
    font-weight: 700;
    color: var(--accent-purple);
    pointer-events: none;
}

.ctrl-separator {
    width: 1px;
    height: 24px;
    background: var(--border);
    margin: 0 4px;
}

/* Volume Control */
.volume-control {
    display: flex;
    align-items: center;
    gap: 4px;
}

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

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    background: white;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 4px rgba(0, 0, 0, 0.3);
}

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

/* ============================================
   Playlist Section
   ============================================ */

.playlist-section {
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 120px);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-md);
}

.playlist-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
    flex-shrink: 0;
    gap: 12px;
}

.playlist-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.playlist-select {
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px 12px;
    font-size: 0.95rem;
    font-weight: 600;
    font-family: inherit;
    outline: none;
    cursor: pointer;
    transition: all var(--transition-fast);
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.playlist-select:hover {
    border-color: var(--accent-purple);
    background: var(--bg-tertiary);
}

.playlist-select:focus {
    border-color: var(--accent-purple);
    box-shadow: 0 0 0 2px rgba(168, 85, 247, 0.15);
}

.btn-playlist-action {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.btn-playlist-action:hover {
    color: var(--text-primary);
    border-color: var(--border-hover);
    background: var(--bg-tertiary);
}

.btn-playlist-action#deletePlaylistBtn:hover {
    color: #f87171;
    border-color: rgba(248, 113, 113, 0.2);
    background: rgba(248, 113, 113, 0.08);
}

.playlist-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.track-count {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
    padding-right: 4px;
}

.playlist-container {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.playlist-container::-webkit-scrollbar {
    width: 6px;
}

.playlist-container::-webkit-scrollbar-track {
    background: transparent;
}

.playlist-container::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 3px;
}

.playlist-container::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.15);
}

.playlist-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
    gap: 8px;
}

.playlist-empty p {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.playlist-empty span {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Playlist Items */
.playlist-list {
    list-style: none;
}

.playlist-item {
    display: flex;
    flex-direction: column;
    padding: 12px 14px;
    border-radius: var(--radius-md);
    margin-bottom: 4px;
    cursor: pointer;
    transition: all var(--transition-normal);
    border: 1px solid transparent;
    position: relative;
}

.playlist-item:hover {
    background: var(--bg-card-hover);
    border-color: var(--border);
}

.playlist-item.active {
    background: var(--gradient-subtle);
    border-color: rgba(168, 85, 247, 0.2);
    box-shadow: var(--shadow-glow);
}

.playlist-item.dragging {
    opacity: 0.5;
    border-color: var(--accent-purple);
}

.playlist-item-main {
    display: flex;
    align-items: center;
    gap: 12px;
}

.playlist-item-index {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    width: 22px;
    text-align: center;
    flex-shrink: 0;
}

.playlist-item.active .playlist-item-index {
    color: var(--accent-purple);
}

.playlist-item-thumb {
    width: 52px;
    height: 38px;
    border-radius: 6px;
    overflow: hidden;
    flex-shrink: 0;
    position: relative;
}

.playlist-item-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.playlist-item-thumb::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.06);
}

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

.playlist-item-title {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.4;
}

.playlist-item.active .playlist-item-title {
    color: var(--accent-purple);
}

.playlist-item-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.playlist-item-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.playlist-item:hover .playlist-item-actions {
    opacity: 1;
}

.playlist-item-actions button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.playlist-item-actions button:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.08);
}

.playlist-item-actions button.delete-btn:hover {
    color: #f87171;
    background: rgba(248, 113, 113, 0.1);
}

/* Time Editor (inline) */
.playlist-item-time-editor {
    display: none;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
    animation: slideDown 0.2s ease;
}

.playlist-item-time-editor.show {
    display: block;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-6px);
    }

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

/* Segments Editor */
.segments-container {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 8px;
}

.segment-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border);
    border-radius: 6px;
    transition: all var(--transition-fast);
}

.segment-row:hover {
    border-color: var(--border-hover);
    background: rgba(255, 255, 255, 0.04);
}

.segment-row.segment-active {
    border-color: rgba(168, 85, 247, 0.3);
    background: rgba(168, 85, 247, 0.06);
}

.segment-label-display {
    display: none;
}

.seg-label-input {
    width: 70px;
    padding: 4px 6px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--accent-purple);
    font-size: 0.75rem;
    font-weight: 600;
    font-family: inherit;
    outline: none;
    transition: all var(--transition-fast);
}

.seg-label-input:focus {
    border-color: var(--accent-purple);
}

.seg-start-input,
.seg-end-input {
    width: 55px;
    padding: 4px 6px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 0.8rem;
    font-family: 'Inter', monospace;
    text-align: center;
    outline: none;
    transition: all var(--transition-fast);
}

.seg-start-input:focus,
.seg-end-input:focus {
    border-color: var(--accent-purple);
    box-shadow: 0 0 0 2px rgba(168, 85, 247, 0.1);
}

.seg-arrow {
    color: var(--text-muted);
    font-size: 0.75rem;
    flex-shrink: 0;
}

.seg-play-btn,
.seg-delete-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: transparent;
    border: none;
    border-radius: 4px;
    font-size: 0.7rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.seg-play-btn {
    color: var(--accent-purple);
}

.seg-play-btn:hover {
    background: rgba(168, 85, 247, 0.15);
    color: white;
}

.seg-delete-btn {
    color: var(--text-muted);
}

.seg-delete-btn:hover {
    background: rgba(248, 113, 113, 0.15);
    color: #f87171;
}

.segments-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-top: 6px;
}

.add-segment-btn {
    padding: 5px 12px;
    background: transparent;
    border: 1px dashed var(--border-hover);
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition-fast);
    flex: 1;
}

.add-segment-btn:hover {
    border-color: var(--accent-purple);
    color: var(--accent-purple);
    background: rgba(168, 85, 247, 0.05);
}

.save-segments-btn {
    padding: 5px 14px;
    background: var(--accent-purple);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.78rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition-normal);
}

.save-segments-btn:hover {
    background: #9333ea;
    box-shadow: 0 2px 10px rgba(168, 85, 247, 0.3);
}

/* Drag Handle */
.drag-handle {
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    color: var(--text-muted);
    opacity: 0;
    transition: opacity var(--transition-fast);
    flex-shrink: 0;
}

.playlist-item:hover .drag-handle {
    opacity: 0.5;
}

.drag-handle:hover {
    opacity: 1 !important;
}

.drag-handle:active {
    cursor: grabbing;
}

/* ============================================
   Toast
   ============================================ */

.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 1000;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 18px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.85rem;
    box-shadow: var(--shadow-lg);
    animation: toastIn 0.3s ease;
    backdrop-filter: blur(12px);
}

.toast.success {
    border-color: rgba(34, 197, 94, 0.3);
}

.toast.error {
    border-color: rgba(248, 113, 113, 0.3);
}

.toast.info {
    border-color: rgba(168, 85, 247, 0.3);
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(40px);
    }

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

@keyframes toastOut {
    from {
        opacity: 1;
        transform: translateX(0);
    }

    to {
        opacity: 0;
        transform: translateX(40px);
    }
}

/* ============================================
   Modal & File Upload / Export
   ============================================ */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.modal-card {
    width: 90%;
    max-width: 540px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px 28px;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.3s ease;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(10px);
    }

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

.modal-card h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.modal-card p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 14px;
}

.file-dropzone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 18px 16px;
    margin-bottom: 14px;
    background: rgba(168, 85, 247, 0.04);
    border: 1.5px dashed rgba(168, 85, 247, 0.35);
    border-radius: var(--radius-md);
    text-align: center;
    cursor: pointer;
    transition: all var(--transition-normal);
    font-size: 0.85rem;
    color: var(--text-primary);
}

.file-dropzone:hover,
.file-dropzone.dragover {
    background: rgba(168, 85, 247, 0.1);
    border-color: var(--accent-purple);
}

.modal-card textarea {
    width: 100%;
    padding: 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.82rem;
    font-family: 'Inter', monospace;
    resize: vertical;
    outline: none;
    transition: border-color var(--transition-normal);
}

.modal-card textarea:focus {
    border-color: var(--accent-purple);
}

.modal-text-input {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: inherit;
    outline: none;
}

.modal-text-input:focus {
    border-color: var(--accent-purple);
}

.import-mode-options,
.export-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.radio-option {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.84rem;
    color: var(--text-primary);
    cursor: pointer;
}

.radio-option input[type="radio"] {
    accent-color: var(--accent-purple);
    cursor: pointer;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 18px;
}

/* ============================================
   Responsive
   ============================================ */

@media (max-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr;
    }

    .playlist-section {
        max-height: 500px;
    }
}

@media (max-width: 640px) {
    .app-container {
        padding: 16px;
    }

    .app-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .input-group {
        flex-direction: column;
    }

    .playback-controls {
        flex-wrap: wrap;
    }

    .volume-control {
        display: none;
    }
}

/* =========================================
   FIRST-TIME GAME TUTORIAL
   ========================================= */

.tutorial-overlay {
    position: fixed;
    inset: 0;
    z-index: 99999;
    display: none;
    pointer-events: none;
}

.tutorial-overlay.show {
    display: block;
}

.tutorial-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(5, 5, 12, 0.78);
    backdrop-filter: blur(3px);
    pointer-events: auto;
}

.tutorial-highlight {
    position: absolute;
    z-index: 2;
    border: 2px solid #c084fc;
    border-radius: 16px;
    box-shadow:
        0 0 0 4px rgba(168, 85, 247, 0.18),
        0 0 35px rgba(168, 85, 247, 0.65);
    pointer-events: none;
    transition:
        left 0.35s ease,
        top 0.35s ease,
        width 0.35s ease,
        height 0.35s ease;
    animation: tutorialPulse 1.8s infinite;
}

@keyframes tutorialPulse {

    0%,
    100% {
        box-shadow:
            0 0 0 4px rgba(168, 85, 247, 0.18),
            0 0 25px rgba(168, 85, 247, 0.45);
    }

    50% {
        box-shadow:
            0 0 0 7px rgba(168, 85, 247, 0.12),
            0 0 45px rgba(236, 72, 153, 0.7);
    }
}

.tutorial-card {
    position: absolute;
    z-index: 3;
    width: min(420px, calc(100vw - 32px));
    padding: 24px;
    background:
        linear-gradient(145deg,
            rgba(31, 20, 49, 0.98),
            rgba(16, 12, 27, 0.98));
    border: 1px solid rgba(192, 132, 252, 0.35);
    border-radius: 20px;
    box-shadow:
        0 25px 80px rgba(0, 0, 0, 0.6),
        0 0 40px rgba(168, 85, 247, 0.15);
    color: #fff;
    pointer-events: auto;
    animation: tutorialCardIn 0.35s ease;
}

@keyframes tutorialCardIn {
    from {
        opacity: 0;
        transform: translateY(15px) scale(0.97);
    }

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

.tutorial-level {
    display: flex;
    align-items: center;
    gap: 9px;
    margin-bottom: 12px;
    color: #c084fc;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 1.5px;
}

.tutorial-level-icon {
    font-size: 20px;
}

.tutorial-progress {
    height: 4px;
    width: 100%;
    margin-bottom: 20px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    overflow: hidden;
}

.tutorial-progress-fill {
    display: block;
    height: 100%;
    width: 20%;
    background: linear-gradient(90deg, #a855f7, #ec4899);
    border-radius: inherit;
    transition: width 0.35s ease;
}

.tutorial-card h2 {
    margin: 0 0 10px;
    font-size: 25px;
    line-height: 1.25;
    background: linear-gradient(90deg, #d8b4fe, #f9a8d4);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.tutorial-card p {
    margin: 0;
    color: rgba(255, 255, 255, 0.72);
    font-size: 14px;
    line-height: 1.6;
}

.tutorial-tip {
    margin-top: 16px;
    padding: 12px 14px;
    background: rgba(168, 85, 247, 0.09);
    border: 1px solid rgba(168, 85, 247, 0.16);
    border-radius: 12px;
    color: rgba(255, 255, 255, 0.8);
    font-size: 13px;
    line-height: 1.5;
}

.tutorial-tip strong {
    color: #d8b4fe;
}

.tutorial-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 22px;
}

.tutorial-skip {
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.42);
    font-size: 13px;
    cursor: pointer;
}

.tutorial-skip:hover {
    color: rgba(255, 255, 255, 0.75);
}

.tutorial-next {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 11px 18px;
    border: none;
    border-radius: 10px;
    background: linear-gradient(135deg, #a855f7, #ec4899);
    color: white;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 8px 25px rgba(168, 85, 247, 0.3);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.tutorial-next:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 30px rgba(168, 85, 247, 0.45);
}

.tutorial-next span {
    font-size: 18px;
}

body.tutorial-active .playlist-item-actions,
body.tutorial-active .drag-handle {
    opacity: 1 !important;
}

/* ============================================
   YouTube Search Trigger Button & Modal UI
   ============================================ */

.btn-search-trigger {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 16px;
    background: rgba(168, 85, 247, 0.08);
    border: 1px solid rgba(168, 85, 247, 0.2);
    border-radius: var(--radius-md);
    color: var(--accent-purple);
    font-size: 0.9rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition-normal);
    white-space: nowrap;
}

.btn-search-trigger:hover {
    background: rgba(168, 85, 247, 0.18);
    border-color: var(--accent-purple);
    color: white;
    box-shadow: 0 4px 12px rgba(168, 85, 247, 0.2);
}

.search-modal-card {
    max-width: 680px;
    width: 90%;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 24px;
}

.search-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
    flex-shrink: 0;
}

.search-modal-header h3 {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.close-modal-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all var(--transition-fast);
}

.close-modal-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.search-modal-body {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.search-results-wrapper {
    flex: 1;
    overflow-y: auto;
    padding-right: 4px;
}

.search-results-wrapper::-webkit-scrollbar {
    width: 6px;
}

.search-results-wrapper::-webkit-scrollbar-track {
    background: transparent;
}

.search-results-wrapper::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 3px;
}

.search-results-list {
    list-style: none;
}

.search-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    margin-bottom: 4px;
    cursor: pointer;
    transition: all var(--transition-normal);
    border: 1px solid transparent;
    position: relative;
}

.search-item:hover {
    background: var(--bg-card-hover);
    border-color: var(--border);
}

.search-item-thumb {
    width: 64px;
    height: 48px;
    border-radius: 6px;
    overflow: hidden;
    flex-shrink: 0;
    position: relative;
}

.search-item-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

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

.search-item-title {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-height: 1.35;
}

.search-item-channel {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 3px;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
}

.search-item-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.search-item:hover .search-item-actions {
    opacity: 1;
}

.search-btn-action {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.search-btn-action:hover {
    color: var(--text-primary);
    border-color: var(--border-hover);
}

.search-btn-action.play:hover {
    color: var(--accent-purple);
    border-color: rgba(168, 85, 247, 0.2);
    background: rgba(168, 85, 247, 0.08);
}

.search-empty,
.search-loading,
.search-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
    gap: 8px;
}

.spinner {
    width: 28px;
    height: 28px;
    border: 3px solid rgba(255, 255, 255, 0.08);
    border-top-color: var(--accent-purple);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.search-error .error-icon {
    font-size: 2rem;
    margin-bottom: 4px;
}

.search-error p {
    font-size: 0.95rem;
    font-weight: 600;
    color: #f87171;
}

/* ============================================
   Visual Segment Timeline (Thước chọn đoạn)
   ============================================ */

.visual-timeline-section {
    margin-top: 24px;
    padding: 16px 20px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.visual-timeline-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.timeline-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.timeline-title svg {
    color: var(--accent-purple);
}

.btn-primary-small {
    padding: 6px 12px;
    background: var(--gradient-primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-normal);
}

.btn-primary-small:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(168, 85, 247, 0.25);
}

.timeline-ruler-container {
    padding: 16px 8px 24px 8px;
    position: relative;
    user-select: none;
}

.timeline-ruler {
    position: relative;
    height: 12px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 6px;
    border: 1px solid var(--border);
}

.ruler-ticks {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.ruler-tick {
    position: absolute;
    top: 100%;
    width: 1px;
    height: 6px;
    background: var(--border);
}

.ruler-tick-label {
    position: absolute;
    top: 10px;
    transform: translateX(-50%);
    font-size: 0.7rem;
    color: var(--text-muted);
}

.timeline-track {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.timeline-segment-bar {
    position: absolute;
    height: 100%;
    top: 0;
    border-radius: 4px;
    opacity: 0.85;
    transition: opacity 0.2s, box-shadow 0.2s;
    cursor: pointer;
}

.timeline-segment-bar:hover {
    opacity: 1;
    box-shadow: 0 0 8px currentColor;
}

.timeline-handle {
    position: absolute;
    top: 50%;
    width: 14px;
    height: 14px;
    background: white;
    border: 3px solid currentColor;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    cursor: ew-resize;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
    z-index: 10;
    transition: transform 0.1s, background-color 0.1s;
}

.timeline-handle:hover,
.timeline-handle.dragging {
    transform: translate(-50%, -50%) scale(1.3);
    background-color: var(--bg-primary);
}

.timeline-handle-label {
    position: absolute;
    bottom: 18px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-secondary);
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.65rem;
    font-weight: 500;
    border: 1px solid var(--border);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
}

.timeline-handle:hover .timeline-handle-label,
.timeline-handle.dragging .timeline-handle-label {
    opacity: 1;
}

.timeline-segments-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    max-height: 150px;
    overflow-y: auto;
    padding-right: 4px;
}

.timeline-meta-card {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.timeline-meta-card:hover {
    border-color: var(--border-hover);
    background: var(--bg-tertiary);
}

.timeline-meta-card.active {
    border-color: currentColor;
    background: rgba(255, 255, 255, 0.03);
}

.meta-card-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
}

.meta-card-label {
    font-weight: 600;
    color: var(--text-primary);
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.meta-card-time {
    color: var(--text-secondary);
}

.meta-card-delete {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 0.75rem;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.meta-card-delete:hover {
    color: #f87171;
    background: rgba(248, 113, 113, 0.08);
}

.toggle-video-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border: 1px solid #444;
    border-radius: 8px;
    background: #252525;
    color: #fff;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.2s ease;
}

.toggle-video-btn:hover {
    background: #383838;
}

