/* ============================================
   vidcut.ru - Video & Audio Editor
   ============================================ */

:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f3460;
    --bg-card: #1e2a4a;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0b0;
    --text-muted: #6c6c80;
    --accent: #e94560;
    --accent-hover: #ff6b81;
    --accent-secondary: #0f3460;
    --success: #4caf50;
    --warning: #ff9800;
    --error: #f44336;
    --border: #2a2a4a;
    --shadow: rgba(0, 0, 0, 0.3);
    --radius: 8px;
    --radius-lg: 12px;
    --transition: 0.2s ease;
    --wave-blue: #4a9eff;
    --wave-bg: #0d1b2a;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

/* Header */
.header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
}

.header h1 { font-size: 1.4rem; font-weight: 600; }
.header h1 span { color: var(--accent); }
.header-actions { display: flex; gap: 12px; }

.container { max-width: 1400px; margin: 0 auto; padding: 20px; }

/* Sections */
.section {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 20px;
}

.section-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.section-title .badge {
    background: var(--accent);
    color: white;
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 10px;
}

.section-hint {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 16px;
}

/* Library */
.library-upload-row {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.upload-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border: 1px dashed var(--border);
    border-radius: 20px;
    background: var(--bg-card);
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-secondary);
    transition: all var(--transition);
}

.upload-chip:hover,
.upload-chip.drag-over {
    border-color: var(--accent);
    color: var(--text-primary);
    background: rgba(233, 69, 96, 0.08);
}

.library-group { margin-bottom: 12px; }
.library-group:last-child { margin-bottom: 0; }

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

.resource-pool {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    min-height: 44px;
    padding: 10px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.pool-empty {
    font-size: 0.8rem;
    color: var(--text-muted);
    padding: 4px 0;
}

.resource-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 0.8rem;
    cursor: grab;
    transition: all var(--transition);
    max-width: 260px;
}

.resource-chip:hover {
    border-color: var(--accent);
    transform: translateY(-1px);
}

.resource-chip.dragging { opacity: 0.5; }

.chip-icon { font-size: 1rem; flex-shrink: 0; }

.chip-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 120px;
}

.chip-dur {
    color: var(--text-muted);
    font-size: 0.75rem;
    font-family: 'Courier New', monospace;
    flex-shrink: 0;
}

.chip-remove {
    background: none;
    border: none;
    color: var(--error);
    cursor: pointer;
    font-size: 0.85rem;
    padding: 0 2px;
    opacity: 0.6;
    flex-shrink: 0;
}

.chip-remove:hover { opacity: 1; }

/* Timelines */
.timeline-block-wrap { margin-bottom: 20px; }
.timeline-block-wrap:last-child { margin-bottom: 0; }

.timeline-label {
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.timeline-scroll {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
}

.timeline-track {
    position: relative;
    min-height: 90px;
    padding: 8px 0 12px;
    overflow: visible;
}

.timeline-track.drag-over {
    outline: 2px dashed var(--accent);
    outline-offset: -2px;
}

.timeline-ruler {
    position: relative;
    height: 22px;
    margin: 0 8px 6px;
    border-bottom: 1px solid var(--border);
}

.timeline-ruler .tick {
    position: absolute;
    top: 0;
    width: 1px;
    height: 8px;
    background: var(--text-muted);
}

.timeline-ruler .tick-label {
    position: absolute;
    top: 10px;
    font-size: 0.65rem;
    color: var(--text-muted);
    transform: translateX(-50%);
    font-family: 'Courier New', monospace;
}

/* Marker toolbar */
.video-audio-toggle {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 12px;
    padding: 10px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    cursor: pointer;
    user-select: none;
}

.toggle-label input {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
    cursor: pointer;
}

.toggle-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    padding-left: 24px;
}

.marker-toolbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px 14px;
    margin-bottom: 12px;
    padding: 10px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.marker-toolbar .btn.active {
    border-color: var(--accent);
    background: rgba(233, 69, 96, 0.15);
    color: var(--accent);
}

.marker-toolbar-label {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.marker-color-palette {
    display: flex;
    align-items: center;
    gap: 6px;
}

.marker-color-swatch {
    width: 22px;
    height: 22px;
    border: 2px solid transparent;
    border-radius: 50%;
    cursor: pointer;
    padding: 0;
    flex-shrink: 0;
}

.marker-color-swatch.active {
    border-color: white;
    box-shadow: 0 0 0 2px var(--accent);
}

.marker-color-input {
    width: 28px;
    height: 28px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: none;
    cursor: pointer;
}

.marker-mode-hint {
    font-size: 0.75rem;
    color: var(--accent);
    flex: 1 1 100%;
}

.user-markers-layer {
    position: absolute;
    inset: 0;
    bottom: 20px;
    pointer-events: none;
    z-index: 4;
}

.user-marker {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--marker-color, #ffeb3b);
    box-shadow: 0 0 6px color-mix(in srgb, var(--marker-color) 60%, transparent);
    transform: translateX(-50%);
    pointer-events: auto;
    cursor: default;
}

.user-marker-del {
    position: absolute;
    top: 2px;
    left: 50%;
    transform: translateX(-50%);
    width: 16px;
    height: 16px;
    border: none;
    border-radius: 50%;
    background: var(--marker-color);
    color: #111;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    pointer-events: auto;
}

.waveform-editor.marker-mode {
    cursor: cell;
    outline: 2px dashed var(--accent);
    outline-offset: -2px;
}

.marker-frames-row {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    margin-bottom: 12px;
    padding-bottom: 4px;
}

.marker-frame-card {
    flex: 0 0 auto;
    width: 120px;
    text-align: center;
    border: 2px solid;
    border-radius: var(--radius);
    overflow: hidden;
    background: #000;
}

.marker-frame-time {
    font-size: 0.7rem;
    padding: 4px;
    background: var(--bg-card);
    color: var(--text-secondary);
    font-family: 'Courier New', monospace;
}

.marker-frame-card img {
    width: 100%;
    height: 68px;
    object-fit: contain;
    display: block;
}

.markers-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
    min-height: 24px;
}

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

.marker-list-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 14px;
    font-size: 0.75rem;
}

.marker-list-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--marker-color);
}

.marker-list-time {
    font-family: 'Courier New', monospace;
    color: var(--text-secondary);
}

.marker-list-del {
    background: none;
    border: none;
    color: var(--error);
    cursor: pointer;
    font-size: 0.7rem;
    padding: 0 2px;
    opacity: 0.7;
}

.marker-list-del:hover { opacity: 1; }

.timeline-lane {
    position: relative;
    height: 52px;
    margin: 0 8px;
    background: var(--bg-primary);
    border-radius: 4px;
}

.timeline-user-marker {
    position: absolute;
    top: -8px;
    bottom: -8px;
    width: 3px;
    background: var(--marker-color, #ffeb3b);
    box-shadow: 0 0 4px color-mix(in srgb, var(--marker-color) 50%, transparent);
    transform: translateX(-50%);
    z-index: 5;
    pointer-events: none;
}

.timeline-clip {
    position: absolute;
    top: 4px;
    height: 44px;
    border: 2px solid;
    border-radius: 4px;
    cursor: grab;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 8px;
    overflow: hidden;
    transition: box-shadow var(--transition);
    user-select: none;
}

.timeline-clip:hover {
    box-shadow: 0 2px 8px var(--shadow);
    z-index: 2;
}

.timeline-clip.is-dragging {
    cursor: grabbing;
    opacity: 0.85;
    z-index: 10;
    box-shadow: 0 4px 16px var(--shadow);
}

.clip-grip {
    font-size: 0.75rem;
    color: var(--text-muted);
    flex-shrink: 0;
    line-height: 1;
}

.clip-label {
    font-size: 0.7rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    pointer-events: none;
}

.clip-remove {
    background: rgba(0,0,0,0.4);
    border: none;
    color: white;
    cursor: pointer;
    font-size: 0.7rem;
    padding: 2px 5px;
    border-radius: 3px;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity var(--transition);
}

.timeline-clip:hover .clip-remove { opacity: 1; }

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
}

.modal-panel {
    position: relative;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    width: 100%;
    max-width: 720px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
    animation: fadeIn 0.25s ease;
}

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

.modal-header h2 { font-size: 1.1rem; }

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px 8px;
}

.modal-close:hover { color: var(--text-primary); }

.modal-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 12px 20px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.modal-meta-item { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

/* Video frames */
.video-frames-row {
    display: flex;
    gap: 16px;
    margin-bottom: 16px;
}

.frame-preview {
    flex: 1;
    text-align: center;
}

.frame-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.frame-preview img {
    width: 100%;
    max-height: 120px;
    object-fit: contain;
    background: #000;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

/* Waveform editor */
.waveform-editor {
    position: relative;
    height: 140px;
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 8px;
    cursor: crosshair;
}

.playhead {
    position: absolute;
    top: 0;
    bottom: 20px;
    width: 2px;
    background: #fff;
    box-shadow: 0 0 4px rgba(255,255,255,0.6);
    pointer-events: none;
    z-index: 5;
    transform: translateX(-50%);
}

.audio-player-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 16px;
    padding: 10px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.play-time {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-family: 'Courier New', monospace;
}

.chip-play {
    background: none;
    border: none;
    color: var(--success);
    cursor: pointer;
    font-size: 0.75rem;
    padding: 2px 4px;
    flex-shrink: 0;
    line-height: 1;
}

.chip-play:hover { color: #6ddf72; }

.resource-chip.is-playing {
    border-color: var(--success);
    box-shadow: 0 0 0 1px rgba(76, 175, 80, 0.3);
}

#waveformCanvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.waveform-overlay {
    position: absolute;
    inset: 0;
}

.wave-dim {
    position: absolute;
    top: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.55);
}

#waveDimLeft { left: 0; }
#waveDimRight { right: 0; }

.wave-selection {
    position: absolute;
    top: 0;
    bottom: 0;
    background: rgba(233, 69, 96, 0.25);
    border-left: 3px solid var(--accent);
    border-right: 3px solid var(--accent);
    pointer-events: auto;
}

.wave-handle {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 14px;
    cursor: ew-resize;
    z-index: 3;
}

.wave-handle::after {
    content: '';
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid white;
    box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}

.wave-handle-start { left: -7px; }
.wave-handle-end { right: -7px; }

.waveform-markers {
    position: relative;
    height: 20px;
    margin-bottom: 12px;
}

.wave-marker {
    position: absolute;
    transform: translateX(-50%);
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-family: 'Courier New', monospace;
}

/* Time inputs */
.time-inputs {
    display: flex;
    gap: 24px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.time-input-group {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.time-box {
    width: 48px;
    padding: 6px 8px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-primary);
    text-align: center;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
}

.time-box:focus {
    outline: none;
    border-color: var(--accent);
}

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

/* PWA install modal */
.pwa-install-panel {
    max-width: 480px;
}

.pwa-install-lead {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.pwa-install-steps {
    margin: 0 0 20px;
    padding-left: 1.25rem;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.pwa-install-steps li {
    margin-bottom: 10px;
    line-height: 1.45;
}

.pwa-install-steps li:last-child {
    margin-bottom: 0;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
}

.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn-secondary { background: var(--bg-tertiary); color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--accent-secondary); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #45a049; }
.btn-success:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }

/* Progress & Status */
.progress-container { display: none; margin-top: 16px; padding: 16px; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); }
.progress-container.active { display: block; }
.progress-bar { width: 100%; height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; margin-bottom: 8px; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-hover)); width: 0%; transition: width 0.3s; }
.progress-text { font-size: 0.85rem; color: var(--text-secondary); text-align: center; }

.status { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 12px; font-size: 0.9rem; display: none; }
.status.active { display: block; }
.status.success { background: rgba(76,175,80,0.1); border: 1px solid var(--success); color: var(--success); }
.status.error { background: rgba(244,67,54,0.1); border: 1px solid var(--error); color: var(--error); }
.status.info { background: rgba(33,150,243,0.1); border: 1px solid #2196f3; color: #2196f3; }

/* Export */
.output-section { text-align: center; }
.download-section { display: flex; gap: 10px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }

.format-selector { display: flex; gap: 8px; margin: 12px 0; justify-content: center; flex-wrap: wrap; }
.format-btn {
    padding: 8px 16px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-secondary);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all var(--transition);
}
.format-btn:hover { border-color: var(--accent-secondary); color: var(--text-primary); }
.format-btn.active { border-color: var(--accent); color: var(--accent); background: rgba(233,69,96,0.1); }

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

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

@media (max-width: 768px) {
    .container { padding: 12px; }
    .header h1 { font-size: 1.1rem; }
    .modal-panel { padding: 16px; }
    .video-frames-row { flex-direction: column; }
    .resource-chip { max-width: 100%; }
    .header-actions { flex-wrap: wrap; justify-content: flex-end; }
    .footer-inner { flex-direction: column; align-items: flex-start; }
    .help-feature-grid { grid-template-columns: 1fr; }
}

/* Links as buttons */
a.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

/* SEO intro on home */
.seo-intro-text {
    color: var(--text-secondary);
    margin-bottom: 12px;
    max-width: 70ch;
}
.seo-feature-list {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}
.seo-feature-list li {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 12px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}
.seo-intro a { color: var(--accent); }
.seo-intro a:hover { color: var(--accent-hover); }

/* Footer */
.site-footer {
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
    margin-top: 24px;
    padding: 20px 0 28px;
    color: var(--text-muted);
    font-size: 0.85rem;
}
.footer-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}
.site-footer a {
    color: var(--text-secondary);
    text-decoration: none;
    margin-left: 12px;
}
.site-footer a:first-child { margin-left: 0; }
.site-footer a:hover,
.site-footer a[aria-current="page"] { color: var(--accent); }
.footer-inner > p a { margin-left: 0; color: var(--accent); }

/* Help page */
.help-container { max-width: 860px; }
.breadcrumbs {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 16px;
}
.breadcrumbs a { color: var(--text-secondary); text-decoration: none; }
.breadcrumbs a:hover { color: var(--accent); }
.breadcrumbs-sep { opacity: 0.5; }
.help-title {
    font-size: 1.45rem;
    font-weight: 650;
    margin-bottom: 10px;
    line-height: 1.35;
}
.help-lead {
    color: var(--text-secondary);
    font-size: 1.02rem;
    max-width: 65ch;
}
.help-list {
    margin: 10px 0 12px 1.2rem;
    color: var(--text-secondary);
}
.help-list li { margin-bottom: 6px; }
.help-list.numbered { list-style: decimal; }
.help-feature-grid {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}
.help-feature {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.help-feature strong { color: var(--text-primary); }
.help-feature span { color: var(--text-muted); font-size: 0.85rem; }
.faq-item {
    border-top: 1px solid var(--border);
    padding: 14px 0;
}
.faq-item:first-of-type { border-top: none; padding-top: 4px; }
.faq-q {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text-primary);
}
.faq-item p {
    color: var(--text-secondary);
    max-width: 65ch;
}
.help-cta { text-align: center; }
.help-cta .btn { margin-top: 8px; }
.help-page .section p { color: var(--text-secondary); }
