:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --panel: #ffffff;
  --panel-2: #eef1f4;
  --text: #101317;
  --muted: #66707c;
  --line: #d9dee5;
  --accent: #ff6a00;
  --accent-dark: #c64f00;
  --danger: #b42318;
  --ok: #067647;
  --shadow: 0 16px 48px rgba(17, 24, 39, 0.12);
}

* {
  box-sizing: border-box;
}

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

button,
input,
textarea {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  gap: 18px;
  min-height: 100vh;
  padding: 18px;
}

.stage-panel,
.control-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.stage-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.15;
}

h2 {
  font-size: 15px;
}

.status {
  max-width: 360px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.status.is-ok {
  color: var(--ok);
}

.status.is-error {
  color: var(--danger);
}

.stage {
  position: relative;
  flex: 1;
  min-height: 640px;
  background: #111318;
  overflow: hidden;
}

.stage-video,
.stage-canvas,
.debug-canvas,
.stage-empty {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.stage-video {
  object-fit: cover;
}

.stage-video.is-mirrored {
  transform: scaleX(-1);
}

.stage-canvas,
.debug-canvas {
  pointer-events: none;
}

.debug-canvas {
  z-index: 3;
}

.stage-empty {
  z-index: 4;
  display: grid;
  place-content: center;
  gap: 8px;
  padding: 24px;
  background: linear-gradient(135deg, rgba(17, 19, 24, 0.92), rgba(17, 19, 24, 0.74));
  color: #fff;
  text-align: center;
}

.stage-empty strong {
  font-size: 24px;
}

.stage-empty span {
  color: rgba(255, 255, 255, 0.72);
}

.stage-empty.is-hidden {
  display: none;
}

.stage-actions,
.split-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.stage-actions {
  padding: 14px 20px;
  border-top: 1px solid var(--line);
}

.button,
.text-button {
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}

.button {
  min-height: 40px;
  padding: 0 14px;
  background: #e8ebef;
  color: var(--text);
  font-weight: 650;
}

.button:hover {
  background: #dde2e8;
}

.button.primary {
  background: var(--accent);
  color: #fff;
}

.button.primary:hover {
  background: var(--accent-dark);
}

.text-button {
  background: transparent;
  color: var(--accent-dark);
  font-weight: 700;
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: calc(100vh - 36px);
  overflow: auto;
  padding: 16px;
}

.control-group {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
}

.control-group.compact {
  display: grid;
  gap: 10px;
}

.group-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.group-title span {
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.file-drop {
  display: grid;
  gap: 6px;
  padding: 14px;
  border: 1px dashed #adb6c2;
  border-radius: 8px;
  background: #fafbfc;
  cursor: pointer;
}

.file-drop span {
  font-weight: 700;
}

.file-drop small {
  color: var(--muted);
  line-height: 1.4;
}

.file-drop input {
  color: var(--muted);
}

.inline-load {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-top: 10px;
}

.inline-load input {
  min-width: 0;
  height: 40px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.field-note {
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.control-grid {
  display: grid;
  gap: 12px;
}

.control-row {
  display: grid;
  grid-template-columns: 170px minmax(0, 1fr) 70px;
  align-items: start;
  gap: 10px;
}

.control-row label {
  color: #29313a;
  font-size: 13px;
  font-weight: 650;
}

.param-label {
  display: grid;
  gap: 4px;
  line-height: 1.25;
}

.param-label small,
.toggle-row small {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  line-height: 1.35;
}

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

.control-row input[type="number"] {
  width: 70px;
  height: 34px;
  margin-top: 1px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  text-align: right;
}

.toggle-row {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  color: #29313a;
  font-size: 14px;
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

textarea {
  width: 100%;
  min-height: 180px;
  resize: vertical;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: #111827;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
}

.split-actions {
  margin-top: 10px;
}

@media (max-width: 1040px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .control-panel {
    max-height: none;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 0;
  }

  .stage-panel,
  .control-panel {
    border-radius: 0;
    box-shadow: none;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .stage {
    min-height: 68vh;
  }

  .control-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .control-row input[type="number"] {
    width: 100%;
    text-align: left;
  }
}
