* { box-sizing: border-box; }
[hidden] { display: none !important; }
:root { color-scheme: dark; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #0f0f0f;
    color: #e7e9ea;
    min-height: 100vh;
    margin: 0;
    padding: 20px;
    line-height: 1.6;
}
a { color: #1d9bf0; text-decoration: none; }
a:hover { text-decoration: underline; }
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}
input[type="text"], select {
    width: 100%;
    padding: 14px 16px;
    font-size: 16px;
    font-family: inherit;
    border: 1px solid #333;
    border-radius: 8px;
    background: #1a1a1a;
    color: #e7e9ea;
    outline: none;
}
input[type="text"]:focus, select:focus { border-color: #1d9bf0; }
input[type="text"]::placeholder { color: #6e7681; }
button {
    padding: 14px;
    font-size: 16px;
    font-weight: 600;
    font-family: inherit;
    border: none;
    border-radius: 8px;
    background: #1d9bf0;
    color: white;
    cursor: pointer;
    transition: background 0.2s;
}
button:hover { background: #1a8cd8; }
button:disabled { background: #1d9bf066; cursor: not-allowed; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, .clip:focus-visible {
    outline: 2px solid #6dbdff;
    outline-offset: 2px;
}
.quiet-button {
    border: 1px solid #555;
    background: transparent;
    color: #c3ccd5;
    font-weight: 500;
}
.quiet-button:hover { background: #242424; color: #e7e9ea; }
.small-button {
    padding: 5px 10px;
    font-size: 12px;
    font-weight: 500;
    border: 1px solid #3d434a;
    background: #191b1e;
    color: #c3ccd5;
}
.small-button:hover { background: #242424; color: #e7e9ea; }
.progress-bar-bg {
    width: 100%;
    height: 6px;
    background: #333;
    border-radius: 3px;
    overflow: hidden;
}
.progress-bar {
    height: 100%;
    background: #1d9bf0;
    border-radius: 3px;
    width: 0%;
    transition: width 0.2s ease;
}
.progress-bar.indeterminate {
    width: 35%;
    transition: none;
    animation: progress-indeterminate 1.4s ease-in-out infinite;
}
@keyframes progress-indeterminate {
    from { transform: translateX(-120%); }
    to { transform: translateX(300%); }
}
.form-error { margin: 10px 0 0; color: #f4877f; font-size: 14px; }
.format-hint { margin: 12px 0 0; color: #9ca3af; font-size: 12px; }
.download-again {
    display: block;
    padding: 12px 14px;
    margin-bottom: 12px;
    border-radius: 8px;
    background: #168659;
    color: #fff;
    text-align: center;
    font-size: 15px;
    font-weight: 600;
}
.download-again:hover { background: #11734b; color: #fff; text-decoration: none; }

/* Landing */
.page-wrapper { max-width: 1100px; margin: 0 auto; }
.hero { text-align: center; padding: 56px 0 28px; }
.hero h1 { font-size: 32px; font-weight: 700; line-height: 1.25; margin: 0 0 10px; }
.tagline { color: #9ca3af; font-size: 16px; max-width: 560px; margin: 0 auto 28px; }
.url-form { display: flex; flex-direction: column; gap: 12px; max-width: 560px; margin: 0 auto; }
.url-form button { width: 100%; }
.steps {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    max-width: 900px;
    margin: 28px auto 0;
}
.step { padding: 18px 20px; background: #1a1a1a; border: 1px solid #262626; border-radius: 12px; }
.step h2 { margin: 0 0 6px; font-size: 16px; color: #1d9bf0; }
.step p { margin: 0; color: #9ca3af; font-size: 14px; }
.footer-links {
    text-align: center;
    color: #6e7681;
    font-size: 12px;
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid #333;
}
.footer-links a { color: #6e7681; }
.footer-links a:hover { color: #1d9bf0; }

/* Legal pages */
.legal { max-width: 700px; margin: 0 auto; }
.legal h1 { font-size: 28px; font-weight: 600; margin: 0 0 8px; }
.legal h2 { color: #1d9bf0; font-size: 20px; margin: 32px 0 12px; }
.legal p, .legal li { color: #9ca3af; }
.legal .meta { color: #6e7681; font-size: 14px; }
.back-link { display: inline-block; margin-bottom: 20px; }

/* Editor */
body.editing { padding: 0; height: 100dvh; overflow: hidden; }
.editor { display: flex; flex-direction: column; height: 100%; }
.editor-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    background: #141414;
    border-bottom: 1px solid #262626;
}
.brand { color: #e7e9ea; font-weight: 700; font-size: 16px; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.url-form.inline { flex-direction: row; flex: 1; max-width: 560px; margin: 0; gap: 8px; }
.url-form.inline input { padding: 8px 12px; font-size: 14px; }
.url-form.inline button { width: auto; padding: 8px 14px; font-size: 14px; }
.bar-files { padding: 8px 14px; font-size: 14px; white-space: nowrap; }
.bar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.bar-actions select { width: auto; padding: 8px 10px; font-size: 13px; }
.bar-actions button { padding: 8px 14px; font-size: 14px; white-space: nowrap; }
.bar-error { margin: 0; padding: 6px 12px; background: #2a1414; }
.editor-main {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr) 240px;
}
.panel { min-height: 0; overflow-y: auto; padding: 12px; background: #141414; }
.media-panel { border-right: 1px solid #262626; display: flex; flex-direction: column; }
.inspector { border-left: 1px solid #262626; }
.panel h2 { margin: 0 0 10px; font-size: 13px; font-weight: 600; color: #9ca3af; text-transform: uppercase; letter-spacing: 0.04em; }
.panel-hint { margin: 0 0 10px; color: #6e7681; font-size: 12px; }
.storage { margin: auto 0 0; padding-top: 8px; }
.media-list { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.media-item {
    display: grid;
    grid-template-columns: 72px minmax(0, 1fr);
    gap: 6px 10px;
    padding: 8px;
    background: #1a1a1a;
    border: 1px solid #262626;
    border-radius: 8px;
    cursor: grab;
}
.media-item.importing { display: block; cursor: default; }
.media-item.importing .progress-bar-bg { margin: 6px 0 8px; }
.media-item.failed { border-color: #5c2b2b; }
.media-item.failed .media-meta { color: #f4877f; }
.media-thumb { width: 72px; height: 41px; border-radius: 4px; background: #000; }
.media-text { min-width: 0; }
.media-title { margin: 0; font-size: 13px; font-weight: 500; line-height: 1.3; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.media-meta { margin: 2px 0 0; color: #9ca3af; font-size: 11px; line-height: 1.4; }
.media-actions { grid-column: 1 / -1; display: flex; gap: 6px; }

.preview-panel { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: #0b0b0b; }
.stage-box { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 12px; }
.stage { position: relative; background: #000; box-shadow: 0 0 0 1px #262626; overflow: hidden; }
.stage canvas { display: block; width: 100%; height: 100%; }
.stage-loading {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    pointer-events: none;
}
.stage-loading p { margin: 0; color: #c3ccd5; font-size: 15px; }
.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #333;
    border-top-color: #1d9bf0;
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}
.transform-box {
    position: absolute;
    border: 1.5px solid #1d9bf0;
    cursor: move;
    touch-action: none;
}
.transform-handle {
    position: absolute;
    right: -7px;
    bottom: -7px;
    width: 14px;
    height: 14px;
    background: #1d9bf0;
    border: 2px solid #fff;
    border-radius: 50%;
    cursor: nwse-resize;
}
.transport {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 6px 12px 10px;
}
.play-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
}
.time { color: #c3ccd5; font-size: 13px; font-variant-numeric: tabular-nums; }
.clip-title { margin: 0 0 4px; font-size: 13px; font-weight: 500; overflow-wrap: anywhere; }
.control-group { margin: 12px 0; }
.control-group label { display: flex; justify-content: space-between; font-size: 13px; color: #c3ccd5; margin-bottom: 4px; }
.control-group output { color: #9ca3af; font-variant-numeric: tabular-nums; }
.control-group select { padding: 8px 10px; font-size: 14px; }
input[type="range"] { width: 100%; accent-color: #1d9bf0; }
.button-row { display: flex; gap: 8px; margin-top: 8px; }

.timeline-panel { height: 300px; display: flex; flex-direction: column; background: #141414; border-top: 1px solid #262626; }
.tl-toolbar {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    border-bottom: 1px solid #262626;
    overflow-x: auto;
}
.tool {
    padding: 5px 10px;
    font-size: 13px;
    font-weight: 500;
    background: transparent;
    color: #c3ccd5;
    white-space: nowrap;
}
.tool:hover { background: #242424; color: #e7e9ea; }
.tool:disabled { background: transparent; color: #4b5158; }
.tool-gap { width: 12px; flex: none; }
.tool-spacer { flex: 1; min-width: 12px; }
.tl-toolbar .zoom { width: 130px; flex: none; }

.timeline { flex: 1; min-height: 0; position: relative; }
.tl-scroll {
    --tl-head: 72px;
    position: absolute;
    inset: 0;
    overflow: auto;
    outline: none;
    user-select: none;
    -webkit-user-select: none;
}
.tl-content { position: relative; min-height: 100%; }
.tl-ruler-row {
    position: sticky;
    top: 0;
    z-index: 4;
    display: flex;
    height: 24px;
    background: #141414;
    border-bottom: 1px solid #262626;
    cursor: col-resize;
}
.tl-corner { position: sticky; left: 0; z-index: 5; flex: none; width: var(--tl-head); background: #141414; }
.tl-ruler { position: sticky; left: var(--tl-head); display: block; height: 24px; }
.tl-lanes { position: relative; padding-bottom: 8px; }
.tl-lane { display: flex; align-items: stretch; margin-bottom: 3px; }
.tl-lane.video { height: 54px; }
.tl-lane.audio { height: 40px; }
.tl-lane-head {
    position: sticky;
    left: 0;
    z-index: 3;
    flex: none;
    width: var(--tl-head);
    display: flex;
    align-items: center;
    padding: 0 6px;
    background: #141414;
}
.tl-toggle {
    width: 100%;
    padding: 4px 2px;
    font-size: 11px;
    font-weight: 500;
    background: #1f2226;
    color: #c3ccd5;
}
.tl-toggle:hover { background: #2a2e33; }
.tl-toggle.off { background: #3a2020; color: #f4877f; }
.tl-lane-body { position: relative; flex: 1; background: #191919; border-radius: 4px; }
.tl-lane.drop-target .tl-lane-body { background: #14212d; }
.tl-divider { height: 3px; }
.tl-new-lane {
    height: 14px;
    margin-left: var(--tl-head);
    color: transparent;
    font-size: 10px;
    line-height: 14px;
    text-align: center;
    border-radius: 4px;
}
.dragging .tl-new-lane { color: #6e7681; }
.tl-new-lane.drop-target { background: #14212d; color: #9ad1f5; }
.clip {
    position: absolute;
    top: 0;
    bottom: 0;
    overflow: hidden;
    border-radius: 4px;
    cursor: grab;
    touch-action: none;
    border: 1px solid transparent;
    outline: none;
}
.clip.video { background: #16466b; }
.clip.audio { background: #0d3b2c; }
.clip.selected { border-color: #fff; box-shadow: 0 0 0 1px #fff; z-index: 2; }
.clip.dragged { opacity: 0.8; z-index: 6; cursor: grabbing; }
.clip-visual { position: absolute; top: 0; height: 100%; pointer-events: none; }
.clip-label {
    position: absolute;
    left: 6px;
    top: 2px;
    max-width: calc(100% - 12px);
    padding: 0 4px;
    font-size: 11px;
    line-height: 16px;
    color: #fff;
    background: #0009;
    border-radius: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
}
.clip-label.linked {
    padding-left: 18px;
    background: #0009 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2.5'%3E%3Cpath d='M10 14a5 5 0 0 0 7 0l3-3a5 5 0 0 0-7-7l-1 1M14 10a5 5 0 0 0-7 0l-3 3a5 5 0 0 0 7 7l1-1'/%3E%3C/svg%3E") 3px center / 12px no-repeat;
}
.clip-trim { position: absolute; top: 0; bottom: 0; width: 8px; cursor: ew-resize; touch-action: none; }
.clip-trim.start { left: 0; }
.clip-trim.end { right: 0; }
.clip.selected .clip-trim { background: #ffffffb3; }
.tl-playhead {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 2px;
    margin-left: -1px;
    background: #f4212e;
    z-index: 4;
    pointer-events: none;
    will-change: transform;
}
.tl-playhead-cap {
    position: sticky;
    top: 0;
    width: 14px;
    height: 14px;
    margin-left: -6px;
    background: #f4212e;
    clip-path: polygon(0 0, 100% 0, 100% 50%, 50% 100%, 0 50%);
    pointer-events: auto;
    cursor: col-resize;
    touch-action: none;
}
body.dropping::after {
    content: 'Drop files to add them';
    position: fixed;
    inset: 12px;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #e7e9ea;
    font-size: 20px;
    font-weight: 600;
    background: #0f0f0fcc;
    border: 2px dashed #1d9bf0;
    border-radius: 12px;
    pointer-events: none;
}
.toast {
    position: fixed;
    left: 50%;
    bottom: 16px;
    transform: translateX(-50%);
    max-width: min(560px, calc(100vw - 32px));
    margin: 0;
    padding: 10px 16px;
    background: #242424;
    border: 1px solid #3d434a;
    border-radius: 8px;
    font-size: 14px;
    z-index: 20;
}
.export-dialog {
    width: min(400px, calc(100vw - 32px));
    padding: 20px;
    color: #e7e9ea;
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 12px;
}
.export-dialog::backdrop { background: #000a; }
.export-dialog h2 { margin: 0 0 12px; font-size: 18px; }
.export-dialog #exportProgress { margin-bottom: 12px; }
.export-dialog #exportStatus { margin: 8px 0 0; color: #c3ccd5; }
.export-dialog .button-row button { flex: 1; padding: 10px; font-size: 14px; }

@media (max-width: 960px) {
    body.editing { height: auto; min-height: 100dvh; overflow: auto; }
    .editor { height: auto; }
    .editor-bar { flex-wrap: wrap; }
    .url-form.inline { order: 3; flex-basis: 100%; max-width: none; }
    .bar-files { order: 2; }
    /* Flatten the panels so the timeline can sit directly under the preview. */
    .editor-main { display: contents; }
    .preview-panel { order: 1; }
    .stage-box { height: 42vh; flex: none; padding: 8px; }
    .timeline-panel { order: 2; height: 270px; flex: none; }
    .inspector { order: 3; border: 0; border-top: 1px solid #262626; }
    .media-panel { order: 4; border: 0; border-top: 1px solid #262626; }
    .panel { overflow: visible; flex: none; }
    .tl-scroll { --tl-head: 52px; }
    .tl-toggle { font-size: 10px; }
}
@media (max-width: 720px) {
    .steps { grid-template-columns: minmax(0, 1fr); }
    .hero { padding-top: 32px; }
    .hero h1 { font-size: 26px; }
}
@media (prefers-reduced-motion: reduce) {
    .progress-bar, button { transition: none !important; }
    .progress-bar.indeterminate { animation: none !important; width: 100% !important; opacity: 0.6; }
    .spinner { animation: none; border-top-color: #333; }
}
