:root {
  --bg: #0b0d12;
  --panel: #12151c;
  --panel-2: #181c25;
  --line: #262b37;
  --text: #e6e9f0;
  --muted: #8b93a7;
  --accent: #38bdf8;
  --accent-2: #0ea5e9;
  --red: #ef4444;
  --green: #22c55e;
  --amber: #f59e0b;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); font: 14px/1.4 var(--font);
  display: grid; grid-template-rows: 52px 1fr 190px; height: 100vh; overflow: hidden;
}
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.spacer { flex: 1; }
.hint { color: var(--muted); font-size: 12px; }
.hint b { color: var(--text); font-weight: 600; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 10px; padding: 0 14px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 500; letter-spacing: .02em; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand b { font-weight: 700; }
.brand .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--red); box-shadow: 0 0 0 3px rgba(239,68,68,.25); }
.name-input {
  background: transparent; border: 1px solid transparent; border-radius: 6px; padding: 5px 8px; min-width: 200px;
}
.name-input:hover, .name-input:focus { border-color: var(--line); background: var(--panel-2); outline: none; }

.btn {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px;
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; line-height: 1.2;
}
.btn:hover { border-color: #3a4152; background: #1f2431; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: #b91c1c; border-color: #dc2626; }
.btn.primary:hover { background: #dc2626; }
.btn.accent { background: var(--accent-2); border-color: var(--accent); color: #04121a; font-weight: 600; }
.btn.accent:hover { background: var(--accent); }
.btn.ghost { background: transparent; }
.btn.danger { color: #fca5a5; border-color: #7f1d1d; }
.btn.danger:hover { background: #3b0a0a; }
.btn.sm { padding: 4px 9px; font-size: 12px; border-radius: 6px; }
.btn.icon { width: 36px; justify-content: center; padding: 6px 0; }
.btn.icon.sm { width: 28px; padding: 3px 0; }
.rec-dot { width: 9px; height: 9px; border-radius: 50%; background: #fff; display: inline-block; }

/* ---------- workspace ---------- */
.workspace { display: grid; grid-template-columns: 1fr 360px; min-height: 0; }
.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; padding: 14px; gap: 10px; }
.preview-wrap {
  flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; position: relative;
  background: #07080c; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
#preview { max-width: 100%; max-height: 100%; object-fit: contain; background: #000; }
.empty-hint { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 24px; }
.empty-card { max-width: 520px; background: rgba(18,21,28,.92); border: 1px solid var(--line); border-radius: 14px; padding: 22px 26px; }
.empty-card h2 { margin: 0 0 8px; font-size: 20px; }
.empty-card p { margin: 6px 0; color: #c7cdd9; }
.empty-card .fine { color: var(--muted); font-size: 12px; margin-top: 12px; }

.transport { display: flex; align-items: center; gap: 10px; }
.transport .time { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 120px; }
.transport input[type=range] { flex: 1; }

/* ---------- inspector ---------- */
.inspector {
  border-left: 1px solid var(--line); background: var(--panel); overflow-y: auto; padding: 14px; min-height: 0;
}
.insp-empty p { margin: 4px 0 12px; color: var(--muted); }
.insp-empty ul { padding-left: 18px; margin: 0; }
.insp-empty li { margin: 4px 0; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px 12px; margin: 12px 0 0; }
legend { padding: 0 6px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); margin: 6px 0; flex: 1; }
.field input, .field select, #fCaption {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; color: var(--text); width: 100%;
}
.field input:focus, .field select:focus, #fCaption:focus, .name-input:focus { outline: 1px solid var(--accent); }
.field.range { position: relative; }
.field.range .val { position: absolute; right: 0; top: 0; color: var(--text); font-variant-numeric: tabular-nums; }
.field.range input[type=range] { padding: 0; }
.check { display: flex; align-items: center; gap: 6px; font-size: 12px; margin: 6px 0; }
.row { display: flex; align-items: flex-end; gap: 8px; }
.row.four .field { flex: 1; }
.row.meta { align-items: center; margin-top: 4px; }
.row.actions { margin-top: 14px; flex-wrap: wrap; }
.row.actions.right { justify-content: flex-end; }
.tag { background: #1e293b; color: #93c5fd; font-size: 11px; padding: 2px 7px; border-radius: 999px; text-transform: uppercase; letter-spacing: .05em; }
.crop-wrap { display: flex; justify-content: center; background: #07080c; border-radius: 6px; border: 1px solid var(--line); overflow: hidden; }
#cropCanvas { display: block; touch-action: none; cursor: crosshair; }
#fCaption { margin-top: 4px; }

/* ---------- timeline ---------- */
.timeline { border-top: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; position: relative; min-height: 0; }
.timeline-head { display: flex; align-items: center; gap: 12px; padding: 8px 14px 4px; }
.timeline-head .title { font-weight: 600; }
.clips {
  flex: 1; display: flex; align-items: stretch; gap: 8px; padding: 6px 14px 12px; overflow-x: auto; overflow-y: hidden; min-height: 0;
}
.clips:empty::before {
  content: "Nothing here yet. Capture the screen, import files, or drop them here."; color: var(--muted); align-self: center; margin: auto; font-size: 13px;
}
.card {
  position: relative; flex: 0 0 auto; width: var(--w, 140px); border: 2px solid var(--line); border-radius: 8px; overflow: hidden;
  background: var(--panel-2); cursor: pointer; user-select: none; display: flex; flex-direction: column;
}
.card:hover { border-color: #3a4152; }
.card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(56,189,248,.25); }
.card.dragging { opacity: .4; }
.card.drop-before { box-shadow: -4px 0 0 0 var(--accent); }
.card.drop-after { box-shadow: 4px 0 0 0 var(--accent); }
.card .thumb { flex: 1; min-height: 0; background: #000 center/cover no-repeat; }
.card .label { display: flex; align-items: center; gap: 6px; padding: 4px 6px; font-size: 11px; white-space: nowrap; overflow: hidden; }
.card .label .nm { overflow: hidden; text-overflow: ellipsis; flex: 1; }
.card .label .dur { color: var(--muted); font-variant-numeric: tabular-nums; }
.card .kind { position: absolute; top: 4px; left: 4px; font-size: 10px; padding: 1px 5px; border-radius: 4px; background: rgba(0,0,0,.6); color: #cbd5e1; text-transform: uppercase; }
.card .prog { position: absolute; left: 0; bottom: 0; height: 3px; width: calc(var(--p, 0) * 100%); background: var(--accent); pointer-events: none; }
.drop-overlay {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center; font-size: 16px; font-weight: 600;
  background: rgba(14,165,233,.15); border: 2px dashed var(--accent); border-radius: 0; pointer-events: none;
}
.timeline.dragover .drop-overlay { display: flex; }

/* ---------- share panel ---------- */
.share-panel {
  position: fixed; left: 16px; bottom: 206px; width: 360px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: 0 20px 50px rgba(0,0,0,.5); padding: 10px; z-index: 30;
}
.share-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 13px; }
.share-head .live { background: var(--red); color: #fff; font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 4px; letter-spacing: .08em; }
.rec-timer { color: #fca5a5; font-variant-numeric: tabular-nums; font-weight: 600; animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .45; } }
#shareVideo { width: 100%; aspect-ratio: 16/9; background: #000; border-radius: 6px; object-fit: contain; }
.share-actions { display: flex; gap: 6px; margin: 8px 0 6px; flex-wrap: wrap; }

/* ---------- modals ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 40; }
.dialog { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px; width: 400px; max-width: calc(100vw - 32px); max-height: calc(100vh - 32px); overflow-y: auto; }
.dialog.wide { width: 560px; }
.dialog h3 { margin: 0 0 10px; }
.formats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.format { display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 8px; align-items: start; padding: 10px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.format:has(input:checked) { border-color: var(--accent); background: rgba(56,189,248,.08); }
.format input { grid-row: 1 / span 2; margin-top: 2px; }
.format span { color: var(--muted); font-size: 12px; }
.format.disabled { opacity: .45; }
.progress { position: relative; height: 22px; background: var(--panel-2); border-radius: 6px; overflow: hidden; margin: 10px 0; border: 1px solid var(--line); }
.progress .bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent-2), var(--accent)); transition: width .15s; }
.progress span { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; }
.result { margin: 10px 0; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); }
.result img, .result video { max-width: 100%; max-height: 240px; display: block; margin: 8px auto 0; border-radius: 4px; }
.result a { color: var(--accent); }

/* ---------- toasts ---------- */
.toasts { position: fixed; right: 16px; top: 62px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: #1e293b; border: 1px solid #334155; color: #e2e8f0; padding: 8px 12px; border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.4); max-width: 360px; font-size: 13px; animation: pop .15s ease-out; }
.toast.error { border-color: #7f1d1d; background: #3b0a0a; }
@keyframes pop { from { transform: translateY(-6px); opacity: 0; } }

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .inspector { border-left: 0; border-top: 1px solid var(--line); max-height: 45vh; }
  .share-panel { width: calc(100vw - 32px); }
}

/* ---------- live region picker ---------- */
.region-mode { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; background: #07080c; z-index: 5; }
.region-bar { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 12px; font-size: 12px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.region-bar .check { margin: 0; }
#regionCanvas { display: block; margin: auto; touch-action: none; cursor: crosshair; box-shadow: 0 0 0 1px var(--line); }
.share-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.btn.active { border-color: var(--accent); color: var(--accent); }
.countdown {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 60; pointer-events: none;
  font-size: 180px; font-weight: 800; color: #fff; text-shadow: 0 0 40px rgba(0,0,0,.8); background: rgba(0,0,0,.35);
}
body.region-open .share-panel { left: auto; right: 16px; bottom: auto; top: 62px; width: 330px; }
body.region-open #shareVideo { display: none; }
