:root {
  --bg: #0d1117;
  --panel: #151b23;
  --panel-2: #1c232d;
  --line: #262d38;
  --line-soft: #1f2630;
  --text: #e6edf3;
  --muted: #8b98a8;
  --accent: #4c8dff;
  --accent-soft: rgba(76, 141, 255, 0.14);
  --teal: #10a37f;
  --danger: #f0736a;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* An element's own display rule beats the UA stylesheet's [hidden] rule, so
   panels below that set display (.result, .progress) need this to stay hidden. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 ui-sans-serif, -apple-system, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── top bar ─────────────────────────────────────────── */
.topbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #131922, #0f151d);
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand .mark {
  width: 38px; height: 38px; border-radius: 11px;
  background: linear-gradient(140deg, var(--accent), #7b5cff);
  display: grid; place-items: center;
  font-size: 14px; color: #fff;
  box-shadow: 0 4px 14px rgba(76, 141, 255, 0.35);
}
.brand h1 { margin: 0; font-size: 16px; letter-spacing: -0.01em; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }
.status { font-size: 12px; color: var(--muted); }
.status.bad { color: var(--danger); }

/* ── layout ──────────────────────────────────────────── */
main {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(380px, 460px) 1fr;
  gap: 24px;
  padding: 24px;
  align-items: start;
  min-height: 0;
  overflow-y: auto;
}
@media (max-width: 980px) {
  main { grid-template-columns: 1fr; }
}

.controls { display: flex; flex-direction: column; gap: 16px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.card h2 {
  display: flex; align-items: center; gap: 9px;
  margin: 0 0 12px; font-size: 13.5px; font-weight: 600;
}
.card h2 small { color: var(--muted); font-weight: 400; margin-left: auto; font-size: 12px; }
.num {
  width: 20px; height: 20px; border-radius: 6px;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center;
  font-size: 11px; font-style: normal; font-weight: 700;
}

/* ── drop zones ──────────────────────────────────────── */
.drop {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 26px 16px;
  border: 1.5px dashed var(--line);
  border-radius: 12px;
  background: var(--panel-2);
  cursor: pointer;
  text-align: center;
  transition: border-color .15s, background .15s;
}
.drop.compact { padding: 18px 16px; }
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop-icon { font-size: 22px; }
.drop-title { font-weight: 600; font-size: 13px; }
.drop-sub { color: var(--muted); font-size: 11.5px; }

.meta { color: var(--muted); font-size: 12px; margin: 10px 2px 0; }

/* ── media list ──────────────────────────────────────── */
.media-list { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.media-list:empty { display: none; }
.media-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  padding: 8px 10px;
}
.media-item .idx {
  width: 18px; height: 18px; border-radius: 5px; flex: none;
  background: var(--line); color: var(--muted);
  display: grid; place-items: center; font-size: 10.5px; font-weight: 700;
}
.media-item .thumb {
  width: 44px; height: 44px; border-radius: 8px; flex: none;
  object-fit: cover; background: #000; border: 1px solid var(--line);
}
.media-item .thumb.ph {
  display: grid; place-items: center;
  color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .04em;
  background: var(--line-soft);
}
.media-item .info { min-width: 0; flex: 1; }
.media-item .info b {
  display: block; font-size: 12.5px; font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.media-item .info span { color: var(--muted); font-size: 11px; }
.media-item .tools { display: flex; gap: 4px; }
.icon-btn {
  width: 26px; height: 26px; border-radius: 7px;
  border: 1px solid var(--line); background: transparent;
  color: var(--muted); cursor: pointer; font-size: 12px; line-height: 1;
  display: grid; place-items: center;
}
.icon-btn:hover:not(:disabled) { color: var(--text); border-color: var(--accent); }
.icon-btn:disabled { opacity: .3; cursor: default; }
.icon-btn.del:hover { color: var(--danger); border-color: var(--danger); }

/* ── layout picker ───────────────────────────────────── */
.formats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.format-opt {
  border: 1px solid var(--line); background: var(--panel-2);
  border-radius: 10px; padding: 9px 6px 7px;
  cursor: pointer; color: var(--muted); display: grid; justify-items: center; gap: 5px;
}
.format-opt:hover { border-color: #3d4757; }
.format-opt.on { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.format-opt .ratio {
  width: 22px; border: 1.5px solid currentColor; border-radius: 3px;
}
.format-opt.on .ratio { border-color: var(--accent); }
.format-opt b { font-size: 11px; font-weight: 600; }
.format-opt span { font-size: 9.5px; opacity: .75; text-align: center; line-height: 1.25; }
.framing { gap: 2px; }
.framing-hint { text-align: left; margin-top: 2px; }

.layouts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.layout-opt {
  border: 1px solid var(--line); background: var(--panel-2);
  border-radius: 10px; padding: 8px 6px 6px;
  cursor: pointer; text-align: center; color: var(--muted);
}
.layout-opt:hover { border-color: #3d4757; }
.layout-opt.on { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.layout-opt .diagram {
  position: relative; width: 100%; aspect-ratio: 1 / 1;
  margin-bottom: 5px; border-radius: 4px;
}
.layout-opt .diagram i { position: absolute; background: currentColor; opacity: .55; border-radius: 2px; }
.layout-opt.on .diagram i { opacity: 1; color: var(--accent); }
.layout-opt span { font-size: 10.5px; display: block; }

.sliders { margin-top: 14px; display: flex; flex-direction: column; gap: 10px; }
.slider span { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.slider b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
input[type=range] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 4px; border-radius: 3px;
  background: var(--line); margin: 8px 0 0; outline: none;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 15px; height: 15px; border-radius: 50%;
  background: var(--accent); cursor: pointer; border: 2px solid var(--panel);
}

/* ── fields ──────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 0; }
.field + .field, .field-row { margin-top: 12px; }
.field-row { display: flex; gap: 12px; }
.field-row .field { margin-top: 0; }
.field label { font-size: 12px; color: var(--muted); }
input[type=text], input[type=number], select {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 9px;
  padding: 8px 10px; font: inherit; font-size: 13px; width: 100%;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
.duration { display: flex; align-items: center; gap: 12px; }
.duration input[type=range] { margin: 0; }
.numwrap { position: relative; flex: none; width: 92px; }
.numwrap span { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 12px; }
.numwrap input { padding-right: 24px; }

/* ── stage / preview ─────────────────────────────────── */
.stage {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  position: sticky; top: 24px;
}
.stage-bar { display: flex; align-items: center; justify-content: space-between; width: 100%; }
.stage-title { font-size: 13.5px; font-weight: 600; }
.stage-actions { display: flex; gap: 8px; }
button.ghost {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  border-radius: 8px; padding: 5px 11px; font: inherit; font-size: 12px; cursor: pointer;
}
button.ghost:hover { color: var(--text); border-color: var(--accent); }

.phone {
  /* Sized in JS (sizeStage) rather than by aspect-ratio: the screenshot lives
     in an absolutely positioned .canvas so it can be panned, which leaves this
     box with no in-flow content to derive a size from. */
  position: relative;
  width: 212px;
  height: 460px;
  border-radius: 10px;
  overflow: hidden;
  background: #000;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  user-select: none;
  touch-action: none;
}
.phone img { display: block; width: 100%; height: 100%; object-fit: fill; }

/* The frame (.phone) is the output; the screenshot rides inside it, so the
   preview shows exactly what gets encoded, side margins included. */
.canvas { position: absolute; left: 0; top: 0; width: 100%; height: 100%; }
.phone.pannable { cursor: grab; }
.phone.panning { cursor: grabbing; }
.phone-empty {
  position: absolute; inset: 0;
  display: grid; place-content: center; justify-items: center; gap: 8px;
  color: var(--muted); background: var(--panel-2);
}
.phone-empty span { font-size: 30px; }
.phone-empty p { margin: 0; font-size: 12.5px; }

.region {
  /* No dimming outside the box: the frame is a true preview of the encoded
     file, so tinting it would misrepresent the output. The outline and handles
     already mark the area. */
  position: absolute;
  outline: 1.5px solid var(--accent);
  outline-offset: 0;
  cursor: grab;
}
.region.dragging { cursor: grabbing; }
.tiles { position: absolute; inset: 0; }
.tile { position: absolute; overflow: hidden; background: #10151c; }
.tile video, .tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .empty {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: #64707f; font-size: 11px;
}

.handle {
  position: absolute; width: 12px; height: 12px;
  background: var(--accent); border: 2px solid #fff; border-radius: 3px;
}
.handle[data-handle=nw] { left: -6px; top: -6px; cursor: nwse-resize; }
.handle[data-handle=n]  { left: calc(50% - 6px); top: -6px; cursor: ns-resize; }
.handle[data-handle=ne] { right: -6px; top: -6px; cursor: nesw-resize; }
.handle[data-handle=e]  { right: -6px; top: calc(50% - 6px); cursor: ew-resize; }
.handle[data-handle=se] { right: -6px; bottom: -6px; cursor: nwse-resize; }
.handle[data-handle=s]  { left: calc(50% - 6px); bottom: -6px; cursor: ns-resize; }
.handle[data-handle=sw] { left: -6px; bottom: -6px; cursor: nesw-resize; }
.handle[data-handle=w]  { left: -6px; top: calc(50% - 6px); cursor: ew-resize; }

.hint { color: var(--muted); font-size: 11.5px; margin: 0; text-align: center; }

/* ── action bar ──────────────────────────────────────── */
.actionbar {
  flex: none;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 24px;
  border-top: 1px solid var(--line);
  background: rgba(15, 21, 29, 0.92);
  backdrop-filter: blur(10px);
}
.summary { color: var(--muted); font-size: 12.5px; }
.actionbar-right { display: flex; align-items: center; gap: 16px; }
.progress { display: flex; align-items: center; gap: 10px; min-width: 200px; }
.track { flex: 1; height: 5px; border-radius: 3px; background: var(--line); overflow: hidden; }
.bar { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), #7b5cff); transition: width .2s; }
.pct { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 34px; }

button.primary, a.primary {
  background: var(--accent); color: #fff; border: none;
  border-radius: 10px; padding: 10px 20px;
  font: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer; text-decoration: none; display: inline-block;
}
button.primary:hover, a.primary:hover { background: #3f7ae8; }
button.primary:disabled { background: var(--line); color: #5c6674; cursor: not-allowed; }

/* ── result ──────────────────────────────────────────── */
.result {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(5, 8, 12, 0.72);
  display: grid; place-items: center; padding: 24px;
  backdrop-filter: blur(4px);
}
.result-inner {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 16px;
  max-width: min(420px, 92vw); width: 100%;
  box-shadow: var(--shadow);
}
.result-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.result-head h3 { margin: 0; font-size: 14px; }
.result video {
  width: 100%; max-height: 62vh; border-radius: 12px;
  background: #000; display: block; object-fit: contain;
}
.result-actions { display: flex; align-items: center; gap: 14px; margin-top: 14px; }
.result-actions .meta { margin: 0; }

/* ── toast ───────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: 76px; transform: translateX(-50%);
  background: #2a1d1d; border: 1px solid #5a3030; color: #ffd9d5;
  padding: 10px 16px; border-radius: 10px; font-size: 12.5px;
  max-width: 560px; white-space: pre-wrap; z-index: 30;
  box-shadow: var(--shadow);
}
