:root {
  color-scheme: dark;
  --bg: #0d0f10;
  --surface: #16191a;
  --surface-2: #1f2424;
  --surface-3: #282e2d;
  --line: #39403f;
  --line-soft: #252b2b;
  --text: #f2f5f2;
  --muted: #9da7a4;
  --green: #7ee08a;
  --cyan: #65d6ff;
  --red: #ff5f75;
  --amber: #ffc857;
  --magenta: #f67cff;
  --blue: #71a7ff;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
select,
input {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-rows: auto auto 1fr;
  overflow: hidden;
}

.topbar {
  min-height: 76px;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  background: #111414;
  border-bottom: 1px solid var(--line-soft);
}

.brand {
  min-width: 220px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #eef3ee;
  color: #101312;
  font-weight: 800;
}

.brand h1,
.brand p,
.panel h2,
.panel p {
  margin: 0;
}

.brand h1 {
  font-size: 18px;
  font-weight: 760;
}

.brand p,
.panel p {
  color: var(--muted);
  font-size: 12px;
}

.source-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.segmented {
  height: 38px;
  display: inline-grid;
  grid-auto-flow: column;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.segmented button {
  min-width: 58px;
  padding: 0 14px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.segmented button:last-child {
  border-right: 0;
}

.segmented button.active {
  background: #edf4ef;
  color: #101312;
  font-weight: 800;
}

.field,
.select-control,
.compact-toggle,
.preview-zoom,
.preview-fit {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.field select,
.field input,
.select-control select {
  height: 38px;
  min-width: 178px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  padding: 0 10px;
  outline: 0;
}

.field input {
  width: min(36vw, 360px);
}

.primary-action,
.icon-action {
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  cursor: pointer;
}

.primary-action {
  padding: 0 16px;
  background: var(--green);
  border-color: var(--green);
  color: #071008;
  font-weight: 800;
}

.icon-action {
  width: 42px;
  color: var(--red);
}

.fullscreen-action {
  color: var(--cyan);
  font-size: 18px;
  line-height: 1;
}

.fullscreen-action.active {
  background: var(--cyan);
  border-color: var(--cyan);
  color: #061015;
}

.hidden {
  display: none;
}

.meter-strip {
  min-height: 54px;
  padding: 8px 18px;
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  gap: 10px;
  background: #0f1111;
  border-bottom: 1px solid var(--line-soft);
}

.meter-strip div {
  min-width: 0;
  padding: 7px 10px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #151818;
}

.meter-strip span,
.meter-strip strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.meter-strip span {
  color: var(--muted);
  font-size: 11px;
}

.meter-strip strong {
  margin-top: 2px;
  font-size: 13px;
}

.workspace {
  min-height: 0;
  padding: 14px;
  overflow: hidden;
}

.scope-grid {
  --split-x: 50%;
  --split-y: 50%;
  position: relative;
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.grid-resize-handle {
  position: absolute;
  z-index: 8;
  padding: 0;
  border: 1px solid rgba(101, 214, 255, 0.55);
  background: rgba(101, 214, 255, 0.22);
  opacity: 0;
  transition:
    opacity 140ms ease,
    background 140ms ease;
}

.scope-grid:hover .grid-resize-handle,
.grid-resize-handle:focus-visible,
.grid-resize-handle.resizing {
  opacity: 1;
}

.grid-resize-handle:hover,
.grid-resize-handle.resizing {
  background: rgba(101, 214, 255, 0.42);
}

.grid-resize-handle-x {
  top: 0;
  bottom: 0;
  left: calc(var(--split-x) - 7px);
  width: 14px;
  cursor: col-resize;
}

.grid-resize-handle-y {
  left: 0;
  right: 0;
  top: calc(var(--split-y) - 7px);
  height: 14px;
  cursor: row-resize;
}

.grid-resize-handle-both {
  left: calc(var(--split-x) - 14px);
  top: calc(var(--split-y) - 14px);
  width: 28px;
  height: 28px;
  border-radius: 8px;
  cursor: move;
}

.panel {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.video-panel {
  grid-template-rows: auto minmax(0, 1fr) auto auto;
}

.panel.drag-over {
  outline: 2px solid var(--cyan);
  outline-offset: -3px;
}

.panel.dragging {
  opacity: 0.72;
}

.panel-head {
  min-height: 52px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--surface-2);
}

.panel-head > div {
  min-width: 0;
  flex: 1;
}

.panel h2 {
  font-size: 14px;
  font-weight: 760;
}

.drag-handle {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-3);
  color: var(--muted);
  cursor: grab;
  font-weight: 800;
}

.drag-handle:active {
  cursor: grabbing;
}

.compact-toggle input {
  accent-color: var(--green);
}

.preview-zoom {
  flex: 0 0 auto;
}

.preview-zoom input {
  width: 86px;
  accent-color: var(--cyan);
}

.preview-zoom output {
  width: 38px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.preview-fit {
  flex: 0 0 auto;
}

.preview-fit select {
  width: 70px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  padding: 0 8px;
  outline: 0;
}

.mode-action {
  height: 32px;
  min-width: 52px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-3);
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
}

.mode-action.active {
  background: var(--cyan);
  border-color: var(--cyan);
  color: #061015;
}

.select-control select {
  min-width: 102px;
  height: 32px;
}

.vector-select select {
  min-width: 74px;
}

[data-panel="vectorscope"] .select-control {
  gap: 5px;
}

[data-panel="vectorscope"] .select-control > span {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

[data-panel="vectorscope"] .select-control select {
  min-width: 74px;
}

.video-stage {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    #080a0a;
  background-size: 32px 32px;
}

.video-stage.framed {
  padding: 8px;
}

.video-frame {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.video-frame.framed {
  border: 1px solid var(--line);
}

.video-frame.rotated {
  position: relative;
  overflow: hidden;
}

#sourceVideo {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #050606;
}

#sourceVideo.portrait {
  object-fit: contain;
}

#sourceVideo.rotated {
  position: absolute;
  left: 50%;
  top: 50%;
  object-fit: contain;
}

#sourceVideo.mirrored {
  transform: scaleX(-1);
}

.camera-controls {
  max-height: 112px;
  padding: 8px 10px 10px;
  border-top: 1px solid var(--line-soft);
  background: #111414;
  overflow: auto;
}

.camera-controls-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
}

.camera-controls-head strong {
  color: var(--text);
  font-size: 12px;
}

.camera-control-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 10px;
}

.control-row {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(82px, 0.74fr) minmax(90px, 1fr) minmax(44px, auto);
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.control-row label,
.control-row output {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.control-row input[type="range"] {
  width: 100%;
  accent-color: var(--cyan);
}

.control-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--green);
}

.control-row select {
  min-width: 0;
  width: 100%;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  padding: 0 8px;
}

.source-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  padding: 24px;
  text-align: center;
  background: rgba(8, 10, 10, 0.72);
}

.source-overlay strong {
  font-size: 22px;
}

.source-overlay span {
  max-width: 440px;
  color: var(--muted);
  font-size: 13px;
}

canvas {
  width: 100%;
  height: 100%;
  min-height: 0;
  display: block;
  background: #070909;
}

.panel-foot {
  min-height: 34px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--line-soft);
  background: #121515;
  color: var(--muted);
  font-size: 12px;
}

.panel-foot span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 1080px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .source-bar {
    width: 100%;
    justify-content: flex-start;
  }

  .meter-strip {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .scope-grid {
    height: auto;
    min-height: 0;
    grid-template-columns: 1fr;
    grid-template-rows: repeat(4, minmax(320px, 44vh));
  }

  .grid-resize-handle {
    display: none;
  }

  .camera-control-list {
    grid-template-columns: 1fr;
  }

  .preview-zoom {
    order: 4;
    width: 100%;
  }

  .preview-zoom input {
    flex: 1;
    width: auto;
  }

  .preview-fit {
    order: 5;
  }
}

@media (max-width: 680px) {
  .topbar,
  .workspace,
  .meter-strip {
    padding-left: 10px;
    padding-right: 10px;
  }

  .meter-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .field,
  .bridge-field,
  .field input,
  .field select {
    width: 100%;
  }

  .source-bar {
    display: grid;
    grid-template-columns: 1fr auto auto;
  }

  .segmented,
  .field {
    grid-column: 1 / -1;
  }

  .scope-grid {
    grid-template-rows: repeat(4, minmax(300px, 56vh));
  }
}
