:root {
  color-scheme: dark;
  --bg: #101418;
  --panel: #171d22;
  --panel-strong: #20272e;
  --text: #f4f7f8;
  --muted: #98a5ac;
  --line: #2d373f;
  --green: #42d779;
  --yellow: #f2c94c;
  --red: #ff4d4f;
  --blue: #58a6ff;
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.32);
}

:root.light {
  color-scheme: light;
  --bg: #eef2f3;
  --panel: #ffffff;
  --panel-strong: #f4f7f8;
  --text: #101418;
  --muted: #5d6b73;
  --line: #d7e0e4;
  --shadow: 0 22px 70px rgba(28, 43, 52, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(66, 215, 121, 0.12), transparent 30%),
    linear-gradient(315deg, rgba(88, 166, 255, 0.13), transparent 34%),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  min-height: calc(100vh - 32px);
  margin: 16px auto;
}

.workspace {
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.workspace {
  display: grid;
  grid-template-rows: auto auto minmax(420px, 1fr);
  min-width: 0;
}

.site-notice {
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

.site-notice strong {
  color: var(--text);
}

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

.control-strip {
  justify-content: flex-start;
  flex-wrap: wrap;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  order: 2;
}

.camera-stage {
  order: 3;
}

.topbar {
  order: 1;
}

.brand,
.topbar-actions,
.header-steps,
.model-chip,
.file-list div,
.toggle-row {
  display: flex;
  align-items: center;
}

.brand {
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--green);
}

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

.brand h1 {
  font-size: 1.35rem;
  line-height: 1.1;
}

.brand p,
.header-steps,
.file-list {
  color: var(--muted);
}

.topbar-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.header-steps {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.header-steps li {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-strong);
  white-space: nowrap;
}

.header-steps span {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--green) 16%, var(--panel-strong));
  color: var(--green);
  font-size: 0.78rem;
  font-weight: 800;
}

.model-chip {
  gap: 8px;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  background: var(--panel-strong);
  color: var(--muted);
  border-radius: 999px;
  white-space: nowrap;
}

.icon-button,
.primary-button,
.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}

.icon-button {
  width: 42px;
  padding: 0;
  background: var(--panel-strong);
  color: var(--text);
}

.primary-button {
  padding: 0 18px;
  background: var(--green);
  border-color: color-mix(in srgb, var(--green), black 12%);
  color: #07140c;
  font-weight: 750;
}

.secondary-button {
  padding: 0 16px;
  background: var(--panel-strong);
  color: var(--text);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.camera-stage {
  display: grid;
  grid-template-columns: minmax(360px, 640px) minmax(300px, 340px);
  justify-content: center;
  align-items: start;
  gap: 18px;
  min-height: 0;
  padding: 18px;
}

.video-wrap {
  position: relative;
  width: 100%;
  max-width: 640px;
  aspect-ratio: 1 / 1;
  min-height: 0;
  overflow: hidden;
  background: #070a0d;
  border: 1px solid var(--line);
  border-radius: 8px;
}

video,
#overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#overlay {
  pointer-events: none;
  z-index: 2;
}

video {
  z-index: 1;
  background: #070a0d;
}

.empty-state[hidden] {
  display: none !important;
}

.empty-state,
.alert-frame {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
  z-index: 3;
}

.empty-state {
  background:
    radial-gradient(circle at center, rgba(88, 166, 255, 0.12), transparent 42%),
    #090d10;
}

.empty-state svg {
  width: 54px;
  height: 54px;
  color: var(--blue);
}

.empty-state h2 {
  margin: 0;
  font-size: 1.45rem;
}

.empty-state p {
  max-width: 360px;
  margin: 0;
  color: var(--muted);
}

.alert-frame {
  display: none;
  border: 14px solid var(--red);
  color: var(--red);
  font-size: clamp(2.5rem, 8vw, 7rem);
  font-weight: 900;
  letter-spacing: 0;
  text-shadow: 0 2px 28px rgba(255, 77, 79, 0.4);
  z-index: 4;
}

.alert-frame.active {
  display: grid;
}

.status-panel {
  display: grid;
  align-content: start;
  gap: 16px;
  min-width: 0;
}

.status-main,
.meter-block,
.metrics-grid,
.sparkline {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
}

.status-main,
.meter-block {
  padding: 16px;
}

.status-label,
.meter-head span,
.metrics-grid span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
}

.status-main strong {
  display: block;
  margin-top: 4px;
  font-size: 2rem;
  line-height: 1.05;
}

.meter-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.meter {
  height: 12px;
  overflow: hidden;
  background: color-mix(in srgb, var(--bg) 78%, var(--panel));
  border-radius: 999px;
}

.meter span {
  display: block;
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--yellow), var(--red));
  border-radius: inherit;
  transition: width 180ms ease;
}

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

.metrics-grid div {
  min-width: 0;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.metrics-grid div:nth-child(odd) {
  border-right: 1px solid var(--line);
}

.metrics-grid div:nth-last-child(-n + 2) {
  border-bottom: 0;
}

.metrics-grid strong {
  display: block;
  margin-top: 4px;
  font-size: 1.15rem;
}

.sparkline {
  width: 100%;
  height: 112px;
}

.toggle-row {
  gap: 8px;
  min-height: 42px;
  padding: 0 4px 0 8px;
  color: var(--muted);
}

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

.file-list {
  display: grid;
  gap: 10px;
}

.file-list div {
  gap: 9px;
  min-width: 0;
}

.file-list span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

svg {
  width: 19px;
  height: 19px;
}

@media (max-width: 1120px) {
  .camera-stage {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .video-wrap,
  .status-panel {
    width: min(100%, 640px);
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: 100%;
    min-height: 100vh;
    margin: 0;
  }

  .workspace,
  .site-notice,
  .video-wrap,
  .status-main,
  .meter-block,
  .metrics-grid,
  .sparkline {
    border-radius: 0;
  }

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

  .topbar,
  .control-strip {
    padding: 14px;
  }

  .site-notice {
    padding: 14px;
  }

  .control-strip {
    position: sticky;
    top: 0;
    z-index: 10;
    background: color-mix(in srgb, var(--panel) 96%, transparent);
  }

  .primary-button,
  .secondary-button {
    min-height: 46px;
    flex: 1 1 132px;
  }

  .toggle-row {
    flex: 1 1 100%;
    min-height: 34px;
  }

  .model-chip {
    display: none;
  }

  .topbar-actions {
    width: 100%;
    justify-content: space-between;
  }

  .header-steps {
    flex: 1 1 auto;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .header-steps::-webkit-scrollbar {
    display: none;
  }

  .header-steps li {
    min-height: 34px;
    padding: 0 9px;
    font-size: 0.86rem;
  }

  .camera-stage {
    padding: 14px;
  }

  .video-wrap {
    width: 100%;
    max-width: none;
    aspect-ratio: 1 / 1;
  }

}
