:root {
  --bg: #0e0f1d; --card: #171930; --panel: #171930; --ink: #f1f2fa; --mute: #a3a7c4; 
  --line: #2a2e3d; --acc: #3b82f6; --acc2: #10b981; --timeline-bg: #0a0c12; --danger: #dc2626;
}
* { box-sizing: border-box; }
body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 system-ui, sans-serif; display: flex; flex-direction: column; min-height: 100vh; }

.editor-container { display: flex; flex-direction: column; flex: 1; padding: 10px; gap: 10px; max-width: 1024px; margin: 0 auto; width: 100%; }
.editor-header { display: flex; justify-content: space-between; align-items: center; background: var(--panel); padding: 10px 15px; border-radius: 8px; border: 1px solid var(--line); flex-wrap: wrap; gap: 8px; }
.editor-header h1 { margin: 0; font-size: 1.1rem; color: var(--acc); }
.export-controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.export-controls select { width: auto; }

.btn-primary { background: var(--acc); color: #fff; border: none; padding: 8px 16px; border-radius: 6px; font-weight: 600; cursor: pointer; transition: 0.2s; }
.btn-primary:hover { background: #2563eb; }
.btn-danger { background: transparent; color: #fca5a5; border: 1px solid var(--danger); padding: 6px 10px; border-radius: 6px; cursor: pointer; width: 100%; margin-top: 6px; }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-mini { background: var(--acc2); color: #fff; border: none; padding: 4px 8px; border-radius: 4px; cursor: pointer; font-size: 12px; white-space: nowrap; }
select, input[type="text"], input[type="number"], input[type="color"] { width: 100%; padding: 6px; background: #101216; border: 1px solid var(--line); color: var(--ink); border-radius: 4px; outline: none; font-size: 13px; }
select:disabled, input:disabled { opacity: 0.5; }
:is(button, input, select, summary):focus-visible { outline: 2px solid var(--acc); outline-offset: 2px; }

.editor-main { display: grid; grid-template-columns: 320px 1fr; gap: 10px; flex: 1; min-height: 0; }
.sidebar { display: flex; flex-direction: column; gap: 10px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px; }
.panel h3 { margin: 0 0 8px; font-size: 0.95rem; border-bottom: 1px solid var(--line); padding-bottom: 6px; }
.panel label { display: block; font-size: 12px; color: var(--mute); margin-top: 6px; }
.note { font-size: 0.75rem; color: var(--mute); margin: 0 0 8px; }
.row { display: flex; gap: 8px; margin-top: 4px; margin-bottom: 8px; }
.row > div { flex: 1; }
.chk-wrap { display: flex !important; align-items: center; gap: 6px; margin-top: 10px; cursor: pointer; font-weight: 600; font-size: 13px !important; color: var(--ink) !important; }
.chk-wrap input { width: auto; }

.preview-area { display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; min-height: 0; }
.canvas-wrapper { width: 100%; height: 40vh; min-height: 240px; background: #000; display: flex; align-items: center; justify-content: center; position: relative; overflow: hidden; padding: 10px; }
canvas { background: #111; max-width: 100%; max-height: 100%; box-shadow: 0 4px 15px rgba(0,0,0,0.5); }

.timeline-section { background: var(--timeline-bg); border-top: 1px solid var(--line); padding: 10px; }
.playback-controls { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.playback-controls button { background: var(--line); border: none; color: var(--ink); padding: 4px 12px; border-radius: 4px; cursor: pointer; font-size: 16px; }
.playback-controls button:disabled { opacity: 0.5; cursor: not-allowed; }
#scrub { flex: 1; min-width: 60px; accent-color: var(--acc); }
#timeDisplay { font-family: monospace; font-size: 12px; color: var(--mute); white-space: nowrap; }

.tracks-container { display: flex; flex-direction: column; gap: 8px; }
.track-row { display: flex; align-items: stretch; gap: 8px; }
.track-label { font-size: 11px; font-weight: bold; color: var(--mute); width: 45px; text-transform: uppercase; display: flex; align-items: center; }
.timeline-track { flex: 1; display: flex; gap: 6px; background: #000; border: 1px solid var(--line); border-radius: 6px; padding: 6px; min-height: 66px; overflow-x: auto; align-items: center; position: relative; }
.empty-msg { font-size: 12px; color: #777; font-style: italic; margin-left: 10px; white-space: nowrap; }

.tl-clip { flex: none; height: 54px; min-width: 110px; background: #2a2e3d; border-radius: 4px; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 11px; border: 1px solid #444; position: relative; overflow: hidden; cursor: pointer; }
.tl-clip.audio { background: #0f5132; }
.tl-clip.active { border-color: var(--acc); box-shadow: 0 0 0 1px var(--acc); }
.tl-clip .tl-thumb { width: 100%; height: 100%; object-fit: cover; opacity: 0.4; position: absolute; }
.tl-clip .tl-label { z-index: 2; font-weight: bold; text-shadow: 1px 1px 2px #000; text-align: center; padding: 0 20px 0 4px; white-space: nowrap; }
.tl-controls { display: flex; gap: 4px; z-index: 3; margin-top: 2px; }
.tl-btn { background: #111; border: 1px solid #444; color: #fff; border-radius: 3px; cursor: pointer; padding: 1px 5px; font-size: 10px; }
.tl-btn:hover { background: #333; }
.tl-x { position: absolute; top: 2px; right: 2px; z-index: 4; width: 18px; height: 18px; padding: 0; border: none; border-radius: 50%; background: var(--danger); color: #fff; font-size: 13px; line-height: 18px; text-align: center; cursor: pointer; }
.tl-x:hover { background: #ef4444; transform: scale(1.1); }

.render-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.8); z-index: 9999; display: none; align-items: center; justify-content: center; }
.render-overlay.show { display: flex; }
.render-box { background: var(--panel); border: 1px solid var(--acc); padding: 30px; border-radius: 12px; text-align: center; width: min(340px, 92vw); }
.render-box h3 { margin: 0 0 15px; color: var(--acc); }
.progress-bar { width: 100%; height: 10px; background: #000; border-radius: 5px; overflow: hidden; margin-bottom: 10px; }
#progressFill { height: 100%; width: 0%; background: var(--acc2); transition: width 0.1s; }
#renderStatus { font-size: 12px; color: var(--mute); margin: 0 0 12px; }

/* Tutorial / SEO text under the tool */
.seo { max-width: 1024px; width: 100%; margin: 10px auto 40px; padding: 0 15px; color: #c7cbd9; font-size: 15px; line-height: 1.75; }
.seo h2 { color: var(--ink); font-size: 1.3rem; margin: 28px 0 8px; }
.seo h3 { color: var(--acc); font-size: 1.05rem; margin: 18px 0 6px; }
.seo li { margin-bottom: 6px; }
.seo details { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; margin-bottom: 8px; }
.seo summary { cursor: pointer; font-weight: 600; color: var(--ink); }
.seo details p { margin: 8px 0 0; }

@media (max-width: 800px) {
  .editor-main { grid-template-columns: 1fr; }
  .editor-header { flex-direction: column; align-items: stretch; }
  .canvas-wrapper { min-height: 280px; }
  .track-label { width: 38px; font-size: 10px; }
}

/* ===== v2: multi-row timeline ===== */
.tl-toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.tl-toolbar label { font-size: 12px; color: var(--mute); display: flex; align-items: center; gap: 6px; margin-left: auto; }
.tl-toolbar input[type="range"] { width: 110px; accent-color: var(--acc); }
.btn-mini:disabled { opacity: 0.45; cursor: not-allowed; }
.tl-scroll { overflow-x: auto; overflow-y: hidden; border: 1px solid var(--line); border-radius: 6px; background: #000; }
.tl-inner { position: relative; display: flex; flex-direction: column; gap: 4px; padding: 4px 0; }
.track-row { display: flex; align-items: stretch; gap: 0; }
.track-label { position: sticky; left: 0; z-index: 6; flex: none; width: 96px; background: #0e1016; border-right: 1px solid var(--line); padding: 0 6px; display: flex; align-items: center; justify-content: space-between; gap: 4px; font-size: 11px; font-weight: bold; color: var(--mute); text-transform: none; }
.tl-title { white-space: nowrap; }
.tl-plus { width: 22px; height: 22px; padding: 0; border: none; border-radius: 4px; background: var(--acc2); color: #fff; font-size: 16px; line-height: 20px; cursor: pointer; }
.tl-plus:hover { filter: brightness(1.15); }
.tl-fx { width: 58px; padding: 2px; font-size: 11px; }
.track-lane { position: relative; flex: none; height: 42px; border-bottom: 1px dashed #1c2030; background: repeating-linear-gradient(90deg, transparent 0 27px, #12151d 27px 28px); }
.video-row .track-lane { height: 56px; }
.ruler-row .track-lane { height: 22px; background: #0e1016; cursor: ew-resize; }
.tick { position: absolute; top: 4px; font-size: 10px; color: var(--mute); padding-left: 3px; border-left: 1px solid #333; height: 14px; line-height: 14px; pointer-events: none; }
.tl-clip { position: absolute; top: 3px; bottom: 3px; height: auto; min-width: 0; padding: 0 4px; }
.tl-clip .tl-label { padding: 0 20px 0 4px; font-size: 11px; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.tl-clip.video, .tl-clip.image { background: #2a2e3d; }
.tl-clip.gap { border-style: dashed; color: #aaa; }
.tl-clip.audio { background: #0f5132; }
.tl-clip.ov-image { background: #5b21b6; }
.tl-clip.ov-text { background: #b45309; touch-action: none; cursor: grab; }
.tl-clip.ov-fx { background: #0e7490; touch-action: none; cursor: grab; }
.tl-clip.ov-image { touch-action: none; cursor: grab; }
.tl-rz { position: absolute; top: 0; right: 0; bottom: 0; width: 8px; cursor: ew-resize; background: rgba(255,255,255,0.25); z-index: 3; }
.playhead { position: absolute; top: 0; bottom: 0; width: 2px; background: #f43f5e; z-index: 7; pointer-events: none; }
.playhead::before { content: ''; position: absolute; top: 0; left: -4px; border: 5px solid transparent; border-top-color: #f43f5e; }

/* ===== v2: settings panel ===== */
.f-row { margin-bottom: 6px; }
.f-row input[type="range"] { width: 100%; accent-color: var(--acc); }
.pos-grid { display: grid; grid-template-columns: repeat(3, 34px); gap: 4px; margin-top: 4px; justify-content: center; }
.pos-btn { height: 28px; background: #101216; color: var(--ink); border: 1px solid var(--line); border-radius: 4px; cursor: pointer; }
.pos-btn:hover { border-color: var(--acc); background: #1b2030; }
.move-row { display: flex; gap: 6px; margin: 8px 0 0; }
.move-row .btn-mini { flex: 1; background: #334155; }

/* ===== v4: more rows, layout buttons ===== */
.track-label { width: 112px; padding: 0 5px; }
.tl-btns { display: flex; align-items: center; gap: 3px; }
.tl-minus { width: 20px; height: 22px; padding: 0; border: none; border-radius: 4px; background: #475569; color: #fff; font-size: 15px; line-height: 20px; cursor: pointer; }
.tl-minus:hover { background: var(--danger); }
.tl-fx { width: 56px; }
.tl-clip.ov-video { background: #1d4ed8; touch-action: none; cursor: grab; }
.tl-clip.ov-audio { background: #166534; touch-action: none; cursor: grab; }
.layout-row { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0 6px; justify-content: center; }
.layout-btn { flex: 1 1 30%; padding: 5px 4px; font-size: 11px; background: #101216; color: var(--ink); border: 1px solid var(--line); border-radius: 4px; cursor: pointer; }
.layout-btn:hover { border-color: var(--acc); background: #1b2030; }
.tl-toolbar .btn-mini { background: #334155; }
.tl-toolbar #addGapBtn { background: var(--acc2); }

/* ===== v4.2: Clean Accordion Settings Panel ===== */
.field-row { display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.field-row input, .field-row select { flex: 1; min-width: 0; }
.kf-btn { flex: none; width: 32px; height: 32px; padding: 0; border: 1px solid var(--line); border-radius: 4px; background: #101216; color: #9aa0b4; font-size: 14px; line-height: 1; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.kf-btn:hover { border-color: var(--acc); background: #1b2030; }
.kf-btn:active { transform: scale(0.95); }

/* The sidebar becomes a flexible column, the clip panel gets scrollable */
.sidebar.compact { display: flex; flex-direction: column; }
.sidebar.compact #clipPanel { display: flex; flex-direction: column; max-height: calc(100vh - 120px); overflow-y: auto; padding-right: 4px; }
.sidebar.compact #clipPanel::-webkit-scrollbar { width: 6px; }
.sidebar.compact #clipPanel::-webkit-scrollbar-thumb { background: #2a2e3d; border-radius: 3px; }

/* Accordion groups */
.f-group { border-bottom: 1px solid var(--line); padding-bottom: 4px; margin-bottom: 4px; }
.f-group:last-child { border-bottom: none; }
.f-group summary { display: flex; align-items: center; justify-content: space-between; font-size: 13px; font-weight: bold; color: var(--ink); cursor: pointer; padding: 8px 4px; user-select: none; list-style: none; }
.f-group summary::-webkit-details-marker { display: none; }
.f-group summary::after { content: '▼'; font-size: 10px; color: var(--mute); transition: transform 0.2s; }
.f-group[open] summary::after { transform: rotate(180deg); }
.f-group summary:hover { color: var(--acc); }

/* Grid layout for the fields inside a group */
.f-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; padding: 4px 4px 8px; }
.f-row { margin-bottom: 0; }
.f-row.full-width { grid-column: 1 / -1; }

@media (max-width: 800px) {
  .sidebar.compact #clipPanel { max-height: none; overflow-y: visible; }
  .f-grid { grid-template-columns: 1fr; }
  .f-row.full-width { grid-column: auto; }
}
