:root {
  --bg: #f4f7f5;
  --panel: #ffffff;
  --card: #ffffff;
  --field: #f3f6f4;
  --subtle: #eef3f0;
  --line: #e1e7e3;
  --line-strong: #c9d3cd;
  --text: #12201a;
  --muted: #5d6b64;
  --accent: #20d976;
  --accent-2: #1cc56b;
  --accent-ink: #0a7d43;
  --accent-soft: #e5fbef;
  --on-accent: #052e18;
  --danger: #e5484d;
  --danger-soft: #fdecec;
  --pause: #f59e0b;
  --sel: #2f80ed;
  --radius: 12px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 Inter, system-ui, -apple-system, Segoe UI, sans-serif;
  display: flex; flex-direction: column; overflow: hidden;
}
button, select, input, textarea { font: inherit; color: inherit; }
kbd { font: 11px ui-monospace, monospace; padding: 1px 5px; border-radius: 4px; background: var(--subtle); border: 1px solid var(--line); margin-left: 4px; opacity: .8; }
[hidden] { display: none !important; }

.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 18px; border-bottom: 1px solid var(--line); background: var(--panel); flex: none; }
.brand { font-weight: 700; font-size: 17px; letter-spacing: .2px; display: flex; align-items: center; gap: 8px; }
.logo { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--on-accent); font-size: 15px; }
.brand em { font-style: normal; font-weight: 600; color: var(--accent-ink); }
.file-info { color: var(--muted); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; gap: 8px; }

.btn { border: 1px solid var(--line); background: var(--card); padding: 8px 14px; border-radius: 9px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; transition: background .15s, border-color .15s; }
.btn:hover:not(:disabled) { background: var(--subtle); border-color: var(--line-strong); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 700; }
.btn.primary:hover:not(:disabled) { background: var(--accent-2); border-color: var(--accent-2); }
.btn.danger { background: var(--danger-soft); border-color: #f5c2c4; color: #b4232a; }
.btn.danger:hover:not(:disabled) { background: #fadadb; }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.wide { width: 100%; margin-top: 10px; padding: 11px; }

/* Landing */
.landing { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 28px; padding: 24px 16px; overflow: auto; }
.dropzone { width: min(640px, 100%); border: 2px dashed var(--line-strong); border-radius: 20px; padding: 56px 24px; text-align: center; cursor: pointer; background: radial-gradient(ellipse at top, var(--accent-soft) 0%, var(--panel) 75%); transition: border-color .2s, transform .2s; }
.dropzone:hover, .dropzone.over { border-color: var(--accent); transform: scale(1.01); }
.dz-icon { width: 64px; height: 64px; margin: 0 auto 16px; border-radius: 50%; display: grid; place-items: center; font-size: 26px; background: var(--accent); color: var(--on-accent); }
.dz-title { font-size: 22px; font-weight: 700; }
.dz-sub { color: var(--muted); margin-top: 6px; }
.steps { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; width: min(900px, 100%); }
.steps li { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; color: var(--muted); font-size: 13px; }
.steps b { display: block; color: var(--text); font-size: 14px; margin-bottom: 4px; }
.loading { display: flex; align-items: center; gap: 12px; color: var(--muted); }
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Editor layout */
.editor { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 380px; grid-template-rows: minmax(0, 1fr) auto; }
.stage { grid-column: 1; grid-row: 1; display: flex; flex-direction: column; min-height: 0; padding: 14px; gap: 10px; }
.preview-wrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; background: #e9eeeb; border-radius: var(--radius); overflow: hidden; position: relative; }
#preview { max-width: 100%; max-height: 100%; display: block; background: #000; cursor: pointer; }
.transport { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.icon-btn { width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); cursor: pointer; display: grid; place-items: center; font-size: 14px; }
.icon-btn.play { width: 46px; height: 46px; background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-size: 16px; }
.time { font-variant-numeric: tabular-nums; color: var(--muted); margin-right: auto; }
.time span:first-child { color: var(--text); }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; color: var(--muted); user-select: none; }
.switch input { display: none; }
.switch span { width: 34px; height: 20px; border-radius: 10px; background: var(--line-strong); position: relative; transition: background .2s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(14px); }

.panel { grid-column: 2; grid-row: 1 / span 2; background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; border-bottom: 1px solid var(--line); flex: none; }
.tab { flex: 1; background: none; border: 0; padding: 13px 4px; cursor: pointer; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; }
.tab.active { color: var(--accent-ink); border-bottom-color: var(--accent); }
.tab-body { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: 0 1px 2px #12201a0d; }
.card h3 { margin: 0 0 6px; font-size: 14px; }
.hint { color: var(--muted); font-size: 12.5px; margin: 6px 0 0; }
.row { display: flex; gap: 8px; align-items: center; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; gap: 14px; margin-top: 12px; }
.card > .row { margin-top: 10px; flex-wrap: wrap; }
.card > .row.between { margin-top: 0; }
.fields { display: grid; gap: 12px; margin-top: 12px; }
.fields.two { grid-template-columns: 1fr 1fr; }
.fields label { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--muted); }
.fields label output { float: right; color: var(--text); font-variant-numeric: tabular-nums; }
.fields label:has(output) { display: block; }
.fields label:has(output) input { width: 100%; margin-top: 6px; }
.fields.disabled { opacity: .45; pointer-events: none; }
select { background: var(--field); border: 1px solid var(--line); border-radius: 8px; padding: 7px 8px; width: 100%; }
input[type=range] { accent-color: var(--accent); }
.color { flex-direction: row !important; align-items: center; justify-content: space-between; }
input[type=color] { width: 44px; height: 28px; border: 1px solid var(--line); border-radius: 6px; background: none; padding: 2px; cursor: pointer; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.check.big { font-weight: 600; font-size: 15px; }
.check.big input { width: 19px; height: 19px; }
.sel-info { margin-top: 8px; font-size: 12.5px; color: var(--sel); min-height: 18px; font-variant-numeric: tabular-nums; }

.cut-list, .cap-list { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.cut-list li { display: flex; align-items: center; gap: 8px; padding: 7px 10px; background: var(--field); border-radius: 8px; font-variant-numeric: tabular-nums; font-size: 13px; }
.cut-list li .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }
.cut-list li span { flex: 1; cursor: pointer; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; gap: 6px; }
.stats b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.stats small { color: var(--muted); }

.cap-list li { background: var(--field); border: 1px solid transparent; border-radius: 9px; padding: 8px 10px; }
.cap-list li.active { border-color: var(--accent); background: var(--accent-soft); }
.cap-head { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.cap-head input { width: 62px; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 2px 5px; font-size: 12px; }
.cap-head .sp { flex: 1; }
.cap-head button { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 2px 5px; border-radius: 5px; }
.cap-head button:hover { background: var(--subtle); color: var(--text); }
.cap-text { width: 100%; margin-top: 6px; background: transparent; border: 1px solid transparent; border-radius: 6px; padding: 4px 6px; resize: none; font-size: 14px; line-height: 1.35; field-sizing: content; min-height: 30px; }
.cap-text:focus { outline: none; border-color: var(--line-strong); background: var(--panel); }

.presets { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.preset { border: 2px solid var(--line); border-radius: 10px; background: #2b3242 linear-gradient(160deg, #3c4a5f, #1d222b); height: 74px; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 6px; overflow: hidden; }
.preset.active { border-color: var(--accent); box-shadow: 0 0 0 3px #20d97640; }
.preset canvas { width: 100%; height: 46px; }
.preset small { color: #cfd3df; font-size: 11px; }

.formats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 4px; }
.fmt { border: 2px solid var(--line); background: var(--field); border-radius: 10px; padding: 10px 4px 8px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; font-weight: 600; font-size: 13px; }
.fmt i { display: block; height: 30px; border: 2px solid currentColor; border-radius: 3px; margin-bottom: 4px; opacity: .8; }
.fmt small { font-weight: 400; color: var(--muted); font-size: 10.5px; text-align: center; line-height: 1.2; }
.fmt.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); }

.progress { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--muted); }
.progress .bar { height: 8px; border-radius: 4px; background: var(--subtle); overflow: hidden; }
.progress .bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.result { margin-top: 14px; }
.result video { width: 100%; max-height: 360px; border-radius: 10px; background: #000; }

/* Timeline */
.timeline-wrap { grid-column: 1; grid-row: 2; border-top: 1px solid var(--line); background: var(--panel); padding: 6px 0 0; }
.tl-bar { display: flex; justify-content: space-between; align-items: center; padding: 0 14px 6px; font-size: 12px; color: var(--muted); gap: 12px; }
.tl-legend { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.lg { width: 12px; height: 10px; border-radius: 2px; display: inline-block; margin-left: 8px; }
.lg.pause { background: var(--pause); } .lg.cut { background: var(--danger); } .lg.sel { background: var(--sel); }
.zoom { display: flex; align-items: center; gap: 8px; }
.timeline { position: relative; height: 150px; overflow-x: auto; overflow-y: hidden; touch-action: pan-x; }
.tl-spacer { height: 1px; }
#tlCanvas { position: sticky; left: 0; top: 0; display: block; height: 138px; cursor: crosshair; touch-action: none; }

.offscreen { position: fixed; left: -10px; top: -10px; width: 4px; height: 4px; opacity: 0.01; pointer-events: none; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: #fff; border: 1px solid var(--text); padding: 10px 16px; border-radius: 10px; box-shadow: 0 8px 24px #0003; z-index: 50; max-width: calc(100% - 32px); }
.toast.error { background: #b4232a; border-color: #b4232a; }

@media (max-width: 900px) {
  body { overflow-x: hidden; overflow-y: auto; }
  .editor > * { min-width: 0; }
  .editor { display: flex; flex-direction: column; }
  .stage { min-height: 56vh; }
  .panel { border-left: 0; border-top: 1px solid var(--line); }
  .tab-body { overflow: visible; }
  .steps { grid-template-columns: 1fr 1fr; }
  .timeline-wrap { order: 0; }
  .panel { order: 1; }
  .stage { order: -1; }
}
