:root {
  color-scheme: dark;
  --bg: #080d15;
  --surface: #111a28;
  --surface-2: #172235;
  --line: #2a3950;
  --text: #f5f7fb;
  --muted: #91a1b8;
  --accent: #7768ff;
  --accent-2: #a89eff;
  --ok: #43d9a3;
  --danger: #ff7285;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(800px circle at 84% -10%, rgba(119, 104, 255, .2), transparent 58%),
    linear-gradient(rgba(255,255,255,.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.018) 1px, transparent 1px),
    var(--bg);
  background-size: auto, 48px 48px, 48px 48px;
  font: 15px/1.5 Inter, "Segoe UI", Arial, sans-serif;
}

button, input, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.eyebrow { margin: 0 0 5px; color: var(--accent-2); font-size: 11px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 7px; font-size: clamp(27px, 4vw, 42px); line-height: 1.05; }
h2 { margin-bottom: 3px; font-size: 20px; }
p { color: var(--muted); }

input, select {
  width: 100%;
  min-height: 44px;
  padding: 10px 13px;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 11px;
  outline: none;
  background: #0a121e;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(119,104,255,.12); }
button {
  min-height: 42px;
  padding: 10px 15px;
  color: var(--text);
  border: 0;
  border-radius: 11px;
  font-weight: 750;
}
button:disabled { cursor: not-allowed; opacity: .5; }
.primary { background: linear-gradient(135deg, var(--accent), #4f8cff); }
.ghost { border: 1px solid var(--line); background: rgba(17,26,40,.7); }
.text-button { min-height: 0; padding: 5px 7px; color: var(--accent-2); background: transparent; }

.access-screen { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.access-card {
  width: min(440px, 100%);
  padding: clamp(25px, 5vw, 42px);
  border: 1px solid var(--line);
  border-radius: 24px;
  background: linear-gradient(150deg, rgba(23,34,53,.98), rgba(11,18,30,.98));
  box-shadow: 0 28px 90px rgba(0,0,0,.42);
}
.access-mark { display: grid; place-items: center; width: 52px; height: 52px; margin-bottom: 25px; color: var(--accent-2); border-radius: 16px; background: rgba(119,104,255,.16); }
.access-card label { display: grid; gap: 7px; margin: 24px 0 13px; color: var(--muted); font-size: 12px; font-weight: 700; }
.access-card .primary { width: 100%; }
.status { min-height: 20px; margin-top: 11px; color: var(--muted); font-size: 12px; }
.status.error { color: #ffc1ca; }

.app { width: min(1460px, calc(100% - 36px)); margin: 0 auto; padding: 28px 0 80px; }
.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 22px; padding: 0 4px; }
.topbar p { margin-bottom: 0; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.health { padding: 9px 12px; color: var(--ok); border: 1px solid rgba(67,217,163,.22); border-radius: 999px; background: rgba(67,217,163,.07); white-space: nowrap; }
.workflow { display: grid; gap: 16px; }
.panel { padding: clamp(18px, 2.5vw, 27px); border: 1px solid var(--line); border-radius: 20px; background: linear-gradient(145deg, rgba(20,30,46,.96), rgba(12,20,32,.97)); box-shadow: 0 15px 45px rgba(0,0,0,.16); }
.section-heading { display: flex; align-items: flex-start; gap: 13px; margin-bottom: 18px; }
.section-heading > span { display: grid; place-items: center; flex: 0 0 36px; height: 36px; color: var(--accent-2); border-radius: 11px; background: rgba(119,104,255,.14); font-weight: 850; }
.section-heading p, .results-heading p { margin: 0; }
.source-tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.source-tabs button { min-height: 36px; padding: 7px 12px; color: var(--muted); background: transparent; }
.source-tabs button.active { color: #fff; background: rgba(119,104,255,.16); }
.source-form { display: grid; grid-template-columns: minmax(260px,1fr) 145px 120px auto; gap: 9px; }
#probe-form { grid-template-columns: minmax(260px,1fr) auto; }

.results-heading { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 17px; }
.results-heading > div:last-child { display: flex; align-items: flex-start; gap: 4px; }
.video-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.video-card { position: relative; overflow: hidden; border: 1px solid var(--line); border-radius: 15px; background: #0b1421; }
.video-card.selected { border-color: rgba(119,104,255,.75); box-shadow: 0 0 0 2px rgba(119,104,255,.13); }
.video-card img { width: 100%; aspect-ratio: 16/10; object-fit: cover; background: #080d15; }
.video-card-copy { padding: 12px; }
.video-card h3 { min-height: 42px; margin: 0 0 7px; overflow: hidden; font-size: 14px; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.video-card small { display: block; overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; }
.video-card label { position: absolute; top: 9px; left: 9px; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: rgba(4,9,16,.82); }
.video-card input { width: 17px; min-height: 0; height: 17px; accent-color: var(--accent); }
.empty { grid-column: 1/-1; padding: 35px; color: var(--muted); border: 1px dashed var(--line); border-radius: 14px; text-align: center; }

.editor-grid { display: grid; grid-template-columns: minmax(280px, 420px) minmax(300px, 1fr); gap: clamp(20px, 4vw, 46px); align-items: start; }
.stage-column { display: grid; place-items: center; }
.video-stage { position: relative; width: min(100%, 330px); aspect-ratio: 9/16; overflow: hidden; border: 1px solid #34465f; border-radius: 24px; background: #05080d; box-shadow: 0 22px 60px rgba(0,0,0,.4); }
.video-stage > img { width: 100%; height: 100%; object-fit: cover; }
.stage-shade { position: absolute; inset: 0; background: linear-gradient(transparent 65%, rgba(0,0,0,.42)); pointer-events: none; }
.stage-hint { position: absolute; left: 10px; right: 10px; bottom: 10px; padding: 6px; color: #c7d2e1; border-radius: 8px; background: rgba(4,8,14,.62); font-size: 10px; text-align: center; pointer-events: none; }
.overlay-object { position: absolute; z-index: 2; left: 39%; top: 76%; width: 22%; cursor: grab; touch-action: none; }
.overlay-object:active { cursor: grabbing; }
.overlay-object img { display: block; width: 100%; filter: drop-shadow(0 4px 12px rgba(0,0,0,.35)); pointer-events: none; }
.editor-controls { display: grid; gap: 14px; }
.editor-controls > label:not(.upload-control) { display: grid; gap: 7px; color: var(--muted); font-size: 12px; font-weight: 700; }
.editor-controls label > span { display: flex; justify-content: space-between; }
input[type=range] { min-height: 0; height: 8px; padding: 0; accent-color: var(--accent); }
.upload-control { position: relative; display: grid; padding: 17px; border: 1px dashed #435670; border-radius: 13px; cursor: pointer; }
.upload-control input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.upload-control span, .empty-inline { color: var(--muted); font-size: 11px; }
.overlay-list { display: flex; flex-wrap: wrap; gap: 8px; }
.overlay-chip { display: flex; align-items: center; gap: 8px; max-width: 100%; padding: 7px 9px; border: 1px solid var(--line); border-radius: 10px; background: #0a121e; }
.overlay-chip.active { border-color: var(--accent); }
.overlay-chip button { min-height: 0; padding: 2px 5px; background: transparent; }
.overlay-chip strong { overflow: hidden; max-width: 250px; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.compact-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.compact-fields label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; }

.launch-actions { display: flex; justify-content: space-between; align-items: center; gap: 20px; }
.launch-actions div { display: grid; gap: 3px; }
.launch-actions small { color: var(--muted); }
.jobs { display: grid; gap: 9px; margin-top: 15px; }
.job { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 12px; align-items: center; padding: 13px 15px; border: 1px solid var(--line); border-radius: 13px; background: rgba(8,14,24,.6); }
.job strong, .job small { display: block; }
.job small { margin-top: 3px; color: var(--muted); }
.job[data-status=error] { border-color: rgba(255,114,133,.4); }
.job[data-status=done] { border-color: rgba(67,217,163,.35); }
.job a { padding: 9px 13px; color: #fff; border-radius: 10px; background: linear-gradient(135deg,var(--accent),#4f8cff); font-weight: 800; text-decoration: none; }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 10; max-width: 360px; padding: 12px 15px; border: 1px solid var(--line); border-radius: 12px; background: #172235; box-shadow: 0 15px 45px rgba(0,0,0,.4); }

@media (max-width: 850px) {
  .source-form { grid-template-columns: 1fr 1fr; }
  .source-form input { grid-column: 1/-1; }
  .editor-grid { grid-template-columns: 1fr; }
  .topbar, .launch-actions { align-items: stretch; flex-direction: column; }
  .topbar-actions { justify-content: space-between; }
}
@media (max-width: 540px) {
  .app { width: min(100% - 18px, 1460px); padding-top: 14px; }
  .panel { padding: 15px; border-radius: 16px; }
  .source-form, #probe-form, .compact-fields { grid-template-columns: 1fr; }
  .source-form input { grid-column: auto; }
  .results-heading { flex-direction: column; }
  .video-grid { grid-template-columns: 1fr; }
  .topbar-actions { align-items: stretch; flex-direction: column; }
  .job { grid-template-columns: 1fr; }
}
