:root {
  color-scheme: light;
  --bg: #f4f6f2;
  --surface: #ffffff;
  --ink: #1e2428;
  --muted: #697177;
  --line: #d9ded7;
  --stage: #111418;
  --primary: #246b4d;
  --primary-strong: #185239;
  --accent: #c54b38;
  --focus: #4f68d7;
  --good: #1f8a55;
  --warn: #b26818;
  --shadow: 0 12px 28px rgba(29, 36, 40, 0.08);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
}

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

button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(79, 104, 215, 0.32);
  outline-offset: 2px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 72px;
  padding: 14px clamp(16px, 3vw, 32px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 5;
}

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

.brand strong,
.brand span {
  display: block;
}

.brand strong {
  font-size: 1rem;
  line-height: 1.2;
}

.brand span {
  color: var(--muted);
  font-size: 0.86rem;
}

.brand-mark {
  width: 34px;
  height: 42px;
  border-radius: 6px;
  background:
    linear-gradient(145deg, transparent 0 44%, rgba(197, 75, 56, 0.18) 44% 56%, transparent 56%),
    #ffffff;
  border: 2px solid var(--ink);
  box-shadow: 6px 5px 0 rgba(36, 107, 77, 0.22);
  flex: 0 0 auto;
}

.system-status {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.status-pill.ok {
  border-color: rgba(31, 138, 85, 0.35);
  color: var(--good);
}

.status-pill.warn {
  border-color: rgba(178, 104, 24, 0.38);
  color: var(--warn);
}

.app-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 360px);
  gap: clamp(16px, 2.4vw, 28px);
  padding: clamp(16px, 3vw, 32px);
}

.workspace {
  min-width: 0;
}

.stage {
  position: relative;
  width: 100%;
  min-height: 420px;
  aspect-ratio: 16 / 9;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    var(--stage);
  background-size: 42px 42px;
  border: 1px solid #252a31;
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

#sourceVideo {
  display: none;
}

#frameCanvas,
#overlayCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

#frameCanvas {
  background: #0f1114;
}

#overlayCanvas {
  cursor: crosshair;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 14px;
  color: #f4f6f2;
  pointer-events: none;
}

.empty-state.hidden {
  display: none;
}

.empty-state strong {
  font-size: clamp(1.1rem, 2vw, 1.45rem);
}

.empty-card {
  width: min(18vw, 94px);
  aspect-ratio: 5 / 7;
  border-radius: 8px;
  border: 2px solid rgba(255, 255, 255, 0.76);
  background:
    radial-gradient(circle at 50% 32%, rgba(197, 75, 56, 0.9) 0 9%, transparent 10%),
    radial-gradient(circle at 40% 46%, rgba(197, 75, 56, 0.9) 0 8%, transparent 9%),
    radial-gradient(circle at 60% 46%, rgba(197, 75, 56, 0.9) 0 8%, transparent 9%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0.04));
  transform: rotate(-6deg);
}

.capture-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.capture-strip > div {
  min-height: 70px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

.capture-strip strong {
  display: block;
  margin-top: 5px;
  font-size: clamp(1rem, 2vw, 1.24rem);
  overflow-wrap: anywhere;
}

#sourceMetric {
  font-size: 0.96rem;
  line-height: 1.25;
}

.control-panel {
  align-self: start;
  display: grid;
  gap: 14px;
  min-width: 0;
}

.panel-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 16px;
  box-shadow: 0 8px 20px rgba(29, 36, 40, 0.05);
}

.panel-section h2 {
  margin: 0 0 14px;
  font-size: 0.92rem;
  letter-spacing: 0;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.primary-button {
  background: var(--primary);
  color: white;
}

.primary-button:hover:not(:disabled) {
  background: var(--primary-strong);
}

.secondary-button {
  background: #242a30;
  color: #ffffff;
}

.quiet-button {
  width: 100%;
  margin-top: 10px;
  background: #eef2ed;
  color: var(--ink);
  border: 1px solid var(--line);
}

.control-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 8px;
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 700;
}

.control-field:first-of-type {
  margin-top: 0;
}

.control-field output {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
  margin: 8px 0 16px;
}

input[type="range"]:last-child {
  margin-bottom: 0;
}

.detections-section {
  min-height: 220px;
}

.detection-list {
  display: grid;
  gap: 8px;
}

.detection-item {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 58px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafbf8;
}

.mini-card {
  width: 34px;
  height: 46px;
  border: 2px solid #20242a;
  border-radius: 5px;
  background: #ffffff;
  display: grid;
  place-items: center;
  font-size: 0.68rem;
  font-weight: 900;
}

.detection-name {
  min-width: 0;
}

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

.detection-name span,
.confidence-tag,
.muted {
  color: var(--muted);
  font-size: 0.82rem;
}

.confidence-tag {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

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

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

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

  .system-status {
    justify-content: flex-start;
  }

  .stage {
    min-height: 300px;
  }

  .capture-strip,
  .control-panel {
    grid-template-columns: 1fr 1fr;
  }

  .detections-section {
    grid-column: 1 / -1;
  }
}

@media (max-width: 520px) {
  .app-layout {
    padding: 12px;
  }

  .capture-strip,
  .control-panel {
    grid-template-columns: 1fr;
  }

  .button-row {
    grid-template-columns: 1fr;
  }
}
