*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: #000;
  color: #eee;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

#preview-area {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #000;
  overflow: hidden;
}

#preview,
#auto-cal-still {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.scale-bar-label {
  position: absolute;
  z-index: 3;
  margin: 0;
  padding: 0;
  color: #fff;
  font: 12px system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  text-shadow: 0 0 2px #000, 0 1px 2px #000;
  pointer-events: none;
  white-space: nowrap;
  transform: translateY(-100%);
}

#overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: auto;
  touch-action: none;
}

#overlay.measure-cursor {
  cursor: crosshair;
}

#overlay.scale-bar-cursor {
  cursor: grab;
}

#overlay.scale-bar-dragging {
  cursor: grabbing;
}

#overlay.calibration-cursor {
  cursor: grab;
}

#overlay.calibration-cursor:active {
  cursor: grabbing;
}

.camera-idle-layer {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: rgba(0, 0, 0, 0.55);
  text-align: center;
  pointer-events: auto;
}

.camera-idle-inner {
  display: flex;
  max-width: 26rem;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.camera-idle-headline {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.45;
  color: #eee;
}

.camera-idle-detail {
  margin: 0;
  max-width: 100%;
  font-size: 0.8rem;
  line-height: 1.35;
  color: #aaa;
  word-break: break-word;
}

.camera-start-btn {
  padding: 0.65rem 1.35rem;
  font-size: 1rem;
}

#error-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: rgba(0, 0, 0, 0.75);
  color: #f88;
  text-align: center;
  font-size: 1rem;
  z-index: 5;
}

#error-overlay.hidden {
  display: none;
}

#capture-flash {
  position: absolute;
  inset: 0;
  background: rgba(0, 255, 80, 0.35);
  pointer-events: none;
  z-index: 4;
  opacity: 0;
  transition: opacity 0.08s ease-out;
}

#capture-flash.visible {
  opacity: 1;
}

#control-bar {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
  padding: 0.65rem 1rem;
  font-size: 0.875rem;
  background: rgba(30, 30, 30, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.control-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.capture-button-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.btn-cancel-burst {
  color: #f87171;
}

.mode-row {
  gap: 0;
}

.mode-row.is-disabled {
  opacity: 0.45;
  pointer-events: none;
}

.segmented {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  user-select: none;
}

.segmented span {
  padding: 0.35rem 0.75rem;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(0, 0, 0, 0.3);
}

.segmented:first-child span {
  border-radius: 6px 0 0 6px;
}

.segmented:last-child span {
  border-radius: 0 6px 6px 0;
  margin-left: -1px;
}

.segmented input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented input[type="radio"]:checked + span,
.segmented input[type="radio"]:focus-visible + span {
  background: rgba(80, 140, 255, 0.45);
  border-color: rgba(120, 170, 255, 0.8);
}


.burst-controls label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.875rem;
}

.toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  user-select: none;
}

.toggle-label input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  accent-color: #508cff;
}

input[type="number"] {
  width: 4.5rem;
  padding: 0.25rem 0.35rem;
  font-size: inherit;
  background: #111;
  border: 1px solid #444;
  color: #eee;
  border-radius: 4px;
}

button {
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: #2a2a2a;
  color: #eee;
  cursor: pointer;
  font-size: 0.875rem;
}

button:hover:not(:disabled) {
  background: #3a3a3a;
}

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

button.primary {
  background: #2563eb;
  border-color: #3b82f6;
}

.help-link {
  align-self: center;
  font-size: 0.875rem;
  color: #93c5fd;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.help-link:hover {
  color: #bfdbfe;
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

#calibration-dialog,
#auto-cal-fail-dialog {
  max-width: 22rem;
  padding: 1rem;
  border: 1px solid #444;
  border-radius: 10px;
  background: #222;
  color: #eee;
}

#calibration-dialog::backdrop,
#auto-cal-fail-dialog::backdrop {
  background: rgba(0, 0, 0, 0.65);
}

#calibration-dialog h2,
#auto-cal-fail-dialog h2 {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
}

#calibration-dialog p,
#auto-cal-fail-dialog p {
  margin: 0 0 1rem;
  font-size: 0.9rem;
  color: #bbb;
}

#calibration-dialog label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.9rem;
}

#calibration-mm {
  width: 6rem;
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1.25rem;
  justify-content: flex-end;
}

.label {
  font-size: 0.875rem;
  color: #bbb;
}