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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #1a1a1a;
    color: #ffffff;
    height: 100vh;
    overflow: hidden;
    /* Ensure bottom UI (iOS/Android bars) doesn't overlap */
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;    /* fallback */
    height: 100svh;   /* small viewport on mobile */
    height: 100dvh;   /* dynamic viewport for modern browsers */
}

.app-header {
    background: #2a2a2a;
    padding: 1rem;
    border-bottom: 1px solid #3a3a3a;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.app-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

.metadata-panel {
    display: flex;
    gap: 1.5rem;
    font-size: 0.9rem;
    color: #cccccc;
}

.metadata-panel span {
    background: #3a3a3a;
    padding: 0.3rem 0.8rem;
    border-radius: 4px;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
}

.drop-zone {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px dashed #555;
    margin: 2rem;
    border-radius: 8px;
    transition: all 0.3s ease;
    cursor: pointer;
}

.drop-zone:hover,
.drop-zone.drag-over {
    border-color: #4a9eff;
    background: rgba(74, 158, 255, 0.1);
}

.drop-zone-content {
    text-align: center;
    color: #cccccc;
}

.drop-zone-content p {
    margin-bottom: 1rem;
    font-size: 1.1rem;
}

.open-button {
    background: #4a9eff;
    color: white;
    border: none;
    padding: 0.8rem 1.5rem;
    border-radius: 6px;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.2s;
}

.open-button:hover {
    background: #3a8eef;
}

.video-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
    position: relative;
    margin: 1rem;
    border-radius: 8px;
    overflow: hidden;
}

.video-canvas {
    max-width: 100%;
    max-height: 100%;
    display: block;
    border-radius: 4px;
}

/* Crop overlay styles */
.crop-overlay-root { position: absolute; inset: 0; pointer-events: none; }
.crop-box {
    position: absolute;
    border: 2px dashed rgba(0, 200, 255, 0.9);
    box-shadow: 0 0 0 9999px rgba(0,0,0,0.35);
}
.crop-size-label {
    position: absolute;
    top: -22px;
    left: 0;
    background: rgba(0,0,0,0.7);
    color: #fff;
    font-size: 12px;
    padding: 2px 6px;
    border-radius: 3px;
}
.crop-handle { position: absolute; width: 10px; height: 10px; background: #00c8ff; border: 2px solid #000; border-radius: 50%; pointer-events: auto; }
.handle-nw { top: -6px; left: -6px; cursor: nwse-resize; }
.handle-n  { top: -6px; left: 50%; transform: translateX(-50%); cursor: ns-resize; }
.handle-ne { top: -6px; right: -6px; cursor: nesw-resize; }
.handle-e  { top: 50%; right: -6px; transform: translateY(-50%); cursor: ew-resize; }
.handle-se { bottom: -6px; right: -6px; cursor: nwse-resize; }
.handle-s  { bottom: -6px; left: 50%; transform: translateX(-50%); cursor: ns-resize; }
.handle-sw { bottom: -6px; left: -6px; cursor: nesw-resize; }
.handle-w  { top: 50%; left: -6px; transform: translateY(-50%); cursor: ew-resize; }

.timeline-section {
    background: #1e1e1e;
    border-top: 1px solid #3a3a3a;
    border-bottom: 1px solid #3a3a3a;
    padding: 0.75rem;
    overflow-x: auto;
    overflow-y: hidden;
    margin-bottom: 0;
}

.timeline-frames {
    width: 100%;
    overflow: hidden;
}

.frame-strip {
    position: relative;
    height: 96px;
    cursor: pointer;
    user-select: none;
    touch-action: pan-x;
    margin-bottom: 4px;
    border-radius: 4px;
    outline: none;
}

.frame-strip:focus {
    box-shadow: 0 0 0 2px rgba(74, 158, 255, 0.6);
}

/* Cursor states for timeline interaction */
.frame-strip[data-cursor="col-resize"] {
    cursor: col-resize !important;
}

.frame-strip[data-cursor="grab"] {
    cursor: grab !important;
}

.frame-strip[data-cursor="grabbing"] {
    cursor: grabbing !important;
}

.thumbnails-container {
    display: flex;
    height: 100%;
    position: relative;
    width: 100%;
    justify-content: space-between;
    align-items: center;
}

.thumbnail-placeholder,
.thumbnail {
    position: relative;
    flex-shrink: 0;
    background: #2a2a2a;
    border: 1px solid #3a3a3a;
    border-radius: 4px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.thumbnail-placeholder:hover,
.thumbnail:hover {
    border-color: #4a9eff;
}

.thumbnail-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    object-position: center;
}

.thumbnail-time {
    position: absolute;
    bottom: 2px;
    left: 2px;
    background: rgba(0, 0, 0, 0.9);
    color: white;
    font-size: 10px;
    padding: 2px 4px;
    border-radius: 2px;
    font-family: 'Courier New', monospace;
    pointer-events: none;
    z-index: 10;
    max-width: calc(100% - 8px);
    white-space: nowrap;
    overflow: hidden;
}

.timeline-progress-track {
    height: 4px;
    background: #2a2a2a;
    position: relative;
    width: 100%;
    margin: 4px 0;
    border-radius: 2px;
    border: 1px solid #4a4a4a;
}

.timeline-progress-line {
    height: 100%;
    background: #4a9eff;
    position: absolute;
    top: 0;
    left: 0;
    width: 0%;
    border-radius: 2px;
    min-width: 1px;
}

/* Collapsed timeline track (shows only non-deleted time) */
.timeline-collapsed-track {
    height: 8px;
    background: #2a2a2a;
    position: relative;
    width: 100%;
    margin: 6px 0 2px 0;
    border-radius: 3px;
    border: 1px solid #4a4a4a;
}

.timeline-collapsed-line {
    height: 100%;
    background: #4a9eff;
    position: absolute;
    top: 0;
    left: 0;
    width: 0%;
    border-radius: 3px;
    min-width: 1px;
}

.timeline-collapsed-playhead {
    position: absolute;
    top: -4px;
    width: 2px;
    bottom: -4px;
    background: #ffffff;
    box-shadow: 0 0 4px rgba(74, 158, 255, 0.8);
}

.timeline-deleted-markers {
    position: absolute;
    inset: 0;
    pointer-events: none; /* re-enable on child */
    z-index: 100; /* ensure above playhead/overlays */
}

/* High-visibility marker: circular badge + pointer stem */
/* Triangle marker for collapsed deleted region */
.timeline-deleted-marker {
    position: absolute;
    top: 6px; /* inside ribbon */
    left: 0;
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 10px solid #ff3b30; /* triangle pointing down */
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.6));
    cursor: pointer;
    pointer-events: auto;
    transform: translateX(-50%);
}

.timeline-deleted-marker:hover {
    border-top-color: #ff5a52;
}

/* Collapse marker (for expanded deleted region) */
.timeline-collapse-marker {
    position: absolute;
    top: 4px; /* vertically center-ish within ribbon */
    left: 0;
    width: 0;
    height: 0;
    border-top: 8px solid transparent;
    border-bottom: 8px solid transparent;
    border-left: 10px solid #ff3b30; /* triangle pointing right */
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.6));
    cursor: pointer;
    pointer-events: auto;
    /* align tip exactly at left edge (no centering) */
}

.timeline-collapse-marker:hover {
    border-left-color: #ff5a52;
}

.timeline-playhead-frames {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 3px;
    background: #ffffff;
    box-shadow: 0 0 4px rgba(74, 158, 255, 0.8);
    pointer-events: none;
    z-index: 10;
}

.timeline-playhead-frames::before {
    content: '';
    position: absolute;
    top: -6px;
    left: -4px;
    width: 11px;
    height: 12px;
    background: #ffffff;
    border: 2px solid #4a9eff;
    clip-path: polygon(50% 100%, 0 0, 100% 0);
}

.timeline-selection-overlay {
    position: absolute;
    top: 0;
    bottom: 0;
    background: rgba(255, 193, 7, 0.3);
    border: 1px solid rgba(255, 193, 7, 0.6);
    border-radius: 1px;
    pointer-events: none;
    z-index: 5;
}

/* Deleted segments overlay (visual indication only) */
.timeline-deleted-overlay {
    position: absolute;
    top: 0;
    bottom: 0;
    background: repeating-linear-gradient(
        45deg,
        rgba(220, 53, 69, 0.22),
        rgba(220, 53, 69, 0.22) 8px,
        rgba(220, 53, 69, 0.35) 8px,
        rgba(220, 53, 69, 0.35) 16px
    );
    border-top: 1px solid rgba(220, 53, 69, 0.5);
    border-bottom: 1px solid rgba(220, 53, 69, 0.5);
    pointer-events: none;
    z-index: 4; /* below selection overlay, above thumbnails */
}

.timeline-selection-overlay::before,
.timeline-selection-overlay::after {
    content: '';
    position: absolute;
    top: -1px;
    bottom: -1px;
    width: 4px;
    background: rgba(255, 193, 7, 1);
    z-index: 6;
    cursor: col-resize;
    border-radius: 1px;
}

.timeline-selection-overlay::before {
    left: -2px;
    box-shadow: -1px 0 1px rgba(0, 0, 0, 0.2);
}

.timeline-selection-overlay::after {
    right: -2px;
    box-shadow: 1px 0 1px rgba(0, 0, 0, 0.2);
}

.timeline-selection-overlay:hover::before,
.timeline-selection-overlay:hover::after {
    background: rgba(255, 193, 7, 1);
    width: 6px;
}

.timeline-selection-overlay:hover::before {
    left: -3px;
}

.timeline-selection-overlay:hover::after {
    right: -3px;
}

.controls-panel {
    background: #2a2a2a;
    padding: 1rem;
    /* Add breathing room at bottom (supports iOS safe area) */
    padding-bottom: calc(2.25rem + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid #3a3a3a;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-top: 0;
}



/* Control buttons base styles - uniform appearance */
.controls-panel button {
    background: #3a3a3a;
    color: #ccc;
    border: 1px solid #4a4a4a;
    padding: 0;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0; /* icon-only buttons; suppress stray text */
    width: 40px;
    height: 40px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
    position: relative;
}

/* Unified icon sizing for control buttons */
.controls-panel button svg {
    width: 18px;
    height: 18px;
    display: block;
}

.controls-panel button:hover {
    background: #4a4a4a;
    color: #fff;
    border-color: #5a5a5a;
}

.controls-panel button:active {
    background: #2a2a2a;
    border-color: #3a3a3a;
    transform: translateY(1px);
}

/* Primary button (play/pause) - same size as others */
#play-pause-button {
    background: #4a9eff;
    color: white;
    border: 1px solid #4a9eff;
}

#play-pause-button:hover {
    background: #3a8eef;
    border-color: #3a8eef;
}

#play-pause-button:active {
    background: #2a7edf;
    border-color: #2a7edf;
}

/* Play/pause icons: default to play, swap when playing */
#play-pause-button .play-icon { display: block; }
#play-pause-button .pause-icon { display: none; }
#play-pause-button.playing .play-icon { display: none; }
#play-pause-button.playing .pause-icon { display: block; }

/* Loop button active state */
.loop-button.active {
    background: #4a9eff;
    color: white;
    border-color: #4a9eff;
}

.loop-button.active:hover {
    background: #3a8eef;
    border-color: #3a8eef;
}

.loop-button.active:active {
    background: #2a7edf;
    border-color: #2a7edf;
}

/* Volume control */
.volume-control {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: #ccc;
}

.volume-control label {
    font-size: 0.85rem;
}

#volume-slider {
    width: 160px;
    appearance: none;
    height: 4px;
    background: #3a3a3a;
    border-radius: 2px;
    outline: none;
}

#volume-slider::-webkit-slider-thumb {
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #4a9eff;
    cursor: pointer;
    border: none;
}

#volume-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #4a9eff;
    cursor: pointer;
    border: none;
}

#volume-percentage {
    font-variant-numeric: tabular-nums;
    color: #aaa;
    min-width: 40px;
    text-align: right;
}

/* Selection info display */
.selection-info {
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    color: #ffc107;
    font-size: 0.85rem;
    margin-left: auto;
    padding: 0.4rem 0.8rem;
    background: rgba(255, 193, 7, 0.1);
    border: 1px solid rgba(255, 193, 7, 0.3);
    border-radius: 4px;
}

.selection-label {
    font-weight: 600;
}

.selection-time {
    font-variant-numeric: tabular-nums;
    color: #fff;
}

.selection-time span {
    color: #ffc107;
}

/* Time input fields for precise editing */
.selection-info .time-input {
    width: 118px; /* fits 00:00:00.000 */
    padding: 4px 6px;
    margin-left: 6px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
    font-size: 0.85rem;
    color: #fff;
    background: #1f2937;
    border: 1px solid #3a3a3a;
    border-radius: 4px;
}
.selection-info .time-input::placeholder { color: #8891a1; }
.selection-info .time-input:focus { outline: none; border-color: #4a9eff; box-shadow: 0 0 0 2px rgba(74,158,255,0.25); }

@media (max-width: 600px), (pointer: coarse) {
    .selection-info .time-input { width: 106px; padding: 6px 8px; font-size: 0.9rem; }
    :root { --controls-mobile-h: 112px; }
    body { overflow-y: auto; -webkit-overflow-scrolling: touch; }
    .main-content { overflow-y: auto; padding-bottom: calc(var(--controls-mobile-h) + env(safe-area-inset-bottom, 0px)); }
    .video-container { max-height: 50dvh; }
    .controls-panel {
        position: fixed;
        left: 0; right: 0; bottom: 0;
        z-index: 1000;
        width: 100%;
        box-sizing: border-box;
        overflow-x: auto;
        backdrop-filter: blur(6px);
        padding: 0.75rem 0.75rem calc(0.75rem + env(safe-area-inset-bottom, 0px));
        gap: 0.6rem;
        flex-wrap: wrap;
    }
}


@media (max-width: 768px) {
    .app-header {
        flex-direction: column;
        gap: 1rem;
    }
    
    .metadata-panel {
        flex-direction: column;
        gap: 0.5rem;
        text-align: center;
    }
    
    .timeline-section {
        padding: 0.25rem;
    }
    
    .frame-strip {
        height: 72px;
    }
    
    .timeline-frames {
        min-height: 72px;
    }
    
    .controls-panel {
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.5rem;
        padding-bottom: calc(2.75rem + env(safe-area-inset-bottom, 0px));
    }
    
    .selection-info {
        flex-wrap: wrap;
        font-size: 0.75rem;
        margin-left: 0;
        gap: 0.5rem;
        padding: 0.3rem 0.6rem;
    }
}

/* Export Button */
.export-button {
    display: none; /* replaced by icon-button in selection block */
}

.export-button:hover {
    background: inherit;
}

.export-button:disabled {
    opacity: 0.5;
}

/* Small icon button for export inside selection block */
.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: 1px solid #3a3a3a;
    border-radius: 6px;
    background: #2a2a2a;
    color: #e6f0ff;
    cursor: pointer;
}
.icon-button:hover {
    background: #334b6d;
    border-color: #4a9eff;
}
.icon-button svg { display: block; }
.icon-button[disabled] {
    opacity: 0.5;
    cursor: default;
    pointer-events: none;
}

/* Export Modal */
.export-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.export-modal-content {
    background: #2a2a2a;
    border-radius: 8px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.export-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid #3a3a3a;
}

.export-modal-header h3 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 600;
}

.export-modal-close {
    background: none;
    border: none;
    color: #ccc;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
}

.export-modal-close:hover {
    background: #3a3a3a;
    color: #fff;
}

.export-modal-body {
    padding: 1.5rem;
}

.export-section {
    margin-bottom: 1.5rem;
}

.export-section:last-child {
    margin-bottom: 0;
}

.export-section h4 {
    margin: 0 0 0.8rem 0;
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
}

.export-range-info {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    font-size: 0.9rem;
    color: #ccc;
}

.preset-options,
.method-options {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.preset-option,
.method-option {
    display: flex;
    align-items: flex-start;
    gap: 0.8rem;
    cursor: pointer;
    padding: 0.8rem;
    border-radius: 6px;
    border: 1px solid #3a3a3a;
    transition: all 0.2s;
}

.preset-option:hover,
.method-option:hover {
    background: #333;
    border-color: #4a4a4a;
}

.preset-option input,
.method-option input {
    margin: 0;
    margin-top: 0.2rem;
}

.method-option input:disabled ~ .method-label {
    opacity: 0.5;
}

.preset-label,
.method-label {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    flex: 1;
}

.preset-label strong,
.method-label strong {
    font-weight: 600;
    color: #fff;
}

.preset-label small,
.method-label small {
    color: #999;
    font-size: 0.8rem;
    line-height: 1.3;
}

.export-estimate {
    padding: 0.8rem;
    background: #333;
    border-radius: 6px;
    font-size: 0.9rem;
    color: #ccc;
}

.export-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.8rem;
    padding: 1.5rem;
    border-top: 1px solid #3a3a3a;
}

.export-cancel-button,
.export-start-button {
    border: none;
    padding: 0.6rem 1.2rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.export-cancel-button {
    background: #6c757d;
    color: white;
}

.export-cancel-button:hover {
    background: #5a6268;
}

.export-start-button {
    background: #28a745;
    color: white;
}

.export-start-button:hover {
    background: #218838;
}

/* Progress Modal */
.export-progress-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1001;
}

.export-progress-content {
    background: #2a2a2a;
    border-radius: 8px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.export-progress-header {
    padding: 1.5rem 1.5rem 0;
}

.export-progress-header h3 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 600;
    text-align: center;
}

.export-progress-body {
    padding: 1.5rem;
}

.progress-status {
    text-align: center;
    margin-bottom: 1rem;
    font-size: 0.9rem;
    color: #ccc;
}

.progress-bar-container {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    margin-bottom: 1rem;
}

.progress-bar {
    flex: 1;
    height: 8px;
    background: #3a3a3a;
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: #28a745;
    width: 0%;
    transition: width 0.3s ease;
}

.progress-text {
    min-width: 40px;
    text-align: center;
    font-size: 0.9rem;
    color: #fff;
    font-weight: 600;
}

.progress-details {
    font-size: 0.8rem;
    color: #999;
}

.progress-time {
    display: flex;
    justify-content: space-between;
}

.export-progress-footer {
    padding: 0 1.5rem 1.5rem;
    text-align: center;
}

#export-cancel-progress {
    background: #dc3545;
    color: white;
    border: none;
    padding: 0.6rem 1.2rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

#export-cancel-progress:hover {
    background: #c82333;
}
