* {
  box-sizing: border-box;
  font-family: system-ui, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
}

body {
  margin: 0;
  padding: 16px;
  background: #f7f7f8;
  color: #111;
  height: 100vh;
  overflow: hidden;
}

main {
  max-width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

h1 {
  margin: 0;
  font-size: clamp(1.2rem, 2vw, 1.8rem);
  flex-shrink: 0;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
  padding: 8px 0;
}

.controls button,
.controls select,
.controls input {
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid #ccc;
  background: #fff;
  font-size: 14px;
}

.controls button {
  cursor: pointer;
}

.controls button:hover {
  background: #f0f0f0;
}

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

.mode-toggle {
  display: flex;
  gap: 0;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid #ccc;
  position: relative;
}

.mode-btn {
  border: none;
  border-radius: 0;
  background: #fff;
  padding: 8px 16px;
  cursor: pointer;
  position: relative;
  z-index: 1;
  transition: color 0.2s ease;
}

.mode-btn:hover {
  background: #f0f0f0;
}

.mode-btn.active {
  background: #333;
  color: #fff;
}

.mode-btn.active:hover {
  background: #333;
  color: #fff;
}

.mode-btn:first-child {
  border-right: 1px solid #ccc;
}


label {
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Main viewport container - side by side on large screens */
.viewport {
  display: flex;
  flex-direction: row;
  gap: 16px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* Each section takes equal space */
#camera-section,
#preview-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

#camera-section h2,
#preview-section h2 {
  margin: 0 0 8px 0;
  font-size: clamp(0.9rem, 1.5vw, 1.2rem);
  flex-shrink: 0;
}

.video-container {
  flex: 1;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

#preview {
  flex: 1;
  border: 1px dashed #ccc;
  border-radius: 8px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  overflow: auto;
}

#preview svg {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
}

/* Stack vertically on smaller screens */
@media (max-width: 768px) {
  body {
    padding: 12px;
    overflow: auto;
  }

  main {
    height: auto;
  }

  .viewport {
    flex-direction: column;
  }

  #camera-section,
  #preview-section {
    min-height: 40vh;
  }
}

/* Further adjustments for very small screens */
@media (max-width: 480px) {
  .controls {
    gap: 6px;
  }

  .controls button,
  .controls select,
  .controls input {
    padding: 6px 10px;
    font-size: 13px;
  }

  #camera-section,
  #preview-section {
    min-height: 35vh;
  }
}
