* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #05060a;
  color: #e8e8f0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
}

#app {
  display: flex;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

#canvas-wrap {
  position: relative;
  flex: 1 1 auto;
  overflow: hidden;
}

#scene-canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: radial-gradient(ellipse at center, #0a0d1a 0%, #020204 100%);
}

#map-canvas {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
  width: 100%;
  height: 100%;
  background: #05060a;
  cursor: grab;
  touch-action: none;
  -webkit-touch-callout: none;
  user-select: none;
}

/* Floating HUD toolbar for controls that change how the preview itself renders. Quick one-click
   toggles (view mode, wireframe, debug zones) live directly in the toolbar; the rest (rotation
   speed/pivot, HDR background) are one click away in the panel below it. */
.preview-toolbar {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 2;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  max-width: calc(100% - 28px);
}

#preview-overlay-toggle-btn,
.toggle-btn {
  background: rgba(12, 14, 22, 0.85);
  backdrop-filter: blur(4px);
  margin: 0;
}

.toggle-btn.active {
  background: rgba(74, 111, 255, 0.35);
  border-color: #4a6fff;
  color: #fff;
}

#preview-overlay-panel {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 2;
  width: 300px;
  max-width: calc(100vw - 28px);
  max-height: calc(100vh - 90px);
  overflow-y: auto;
  background: rgba(12, 14, 22, 0.92);
  backdrop-filter: blur(6px);
  border: 1px solid #22263a;
  border-radius: 10px;
  padding: 14px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

.overlay-section {
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid #1c2033;
}

.overlay-section:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

#panel {
  flex: 0 0 320px;
  max-width: 320px;
  height: 100%;
  overflow-y: auto;
  background: #0c0e16;
  border-left: 1px solid #22263a;
  padding: 16px;
}

.panel-section {
  margin-bottom: 22px;
  padding-bottom: 18px;
  border-bottom: 1px solid #1c2033;
}

.panel-section:last-child {
  border-bottom: none;
}

h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #8b90ad;
  margin: 0 0 10px 0;
}

label {
  display: block;
  font-size: 12px;
  color: #b7bad2;
  margin-bottom: 10px;
}

label input[type="range"],
label input[type="text"],
label input[type="number"],
label select {
  display: block;
  width: 100%;
  margin-top: 4px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
}

.checkbox-label input {
  margin: 0;
}

.val {
  float: right;
  color: #6f7593;
}

button {
  background: #1c2033;
  color: #e8e8f0;
  border: 1px solid #2c3150;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 12px;
  cursor: pointer;
  margin-right: 6px;
  margin-bottom: 6px;
}

button:hover {
  background: #262c46;
}

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

.danger-btn {
  background: #3a1620;
  border-color: #5a2030;
}

.danger-btn:hover {
  background: #4a1c28;
}

.file-btn {
  display: inline-block;
  background: #1c2033;
  border: 1px solid #2c3150;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 12px;
  cursor: pointer;
  margin-right: 6px;
  margin-bottom: 6px;
}

.file-btn:hover {
  background: #262c46;
}

.hidden {
  display: none !important;
}

.muted {
  color: #6f7593;
  font-size: 12px;
}

.error-text {
  color: #ff6b7f;
  font-size: 12px;
}

#image-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 220px;
  overflow-y: auto;
}

.image-list-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid transparent;
  font-size: 12px;
}

.image-list-item:hover {
  background: #161a2a;
}

.image-list-item.selected {
  background: #1c2242;
  border-color: #3b4270;
}

.image-list-item img {
  width: 28px;
  height: 28px;
  object-fit: contain;
  background: #05060a;
  border-radius: 3px;
}

.row-delete-btn {
  flex: 0 0 auto;
  margin: 0;
  padding: 0 6px;
  line-height: 20px;
  background: transparent;
  border: none;
  color: #6f7593;
  font-size: 15px;
}

.row-delete-btn:hover {
  color: #ff6b7f;
  background: transparent;
}

.image-list-item .name {
  flex: 1 1 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.camera-panel {
  margin-top: 10px;
  padding: 10px;
  background: #12162400;
  border: 1px solid #2c3150;
  border-radius: 8px;
}

.camera-panel video {
  width: 100%;
  border-radius: 6px;
  background: #000;
}

.camera-panel .row {
  margin-top: 8px;
}

#capture-progress {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

#capture-progress progress {
  flex: 1 1 auto;
}

#edit-dialog-preview-col {
  flex: 0 0 auto;
  margin-bottom: 14px;
}

#edit-preview-wrap {
  border-radius: 6px;
  overflow: hidden;
  background-color: #1a1a1a;
  background-image:
    linear-gradient(45deg, #2a2a2a 25%, transparent 25%),
    linear-gradient(-45deg, #2a2a2a 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #2a2a2a 75%),
    linear-gradient(-45deg, transparent 75%, #2a2a2a 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
}

#edit-preview {
  display: block;
  width: 100%;
  height: auto;
  touch-action: none;
  -webkit-touch-callout: none;
  user-select: none;
}

.curve-canvas {
  display: block;
  width: 100%;
  height: 180px;
  background: #05060a;
  border: 1px solid #2c3150;
  border-radius: 6px;
  cursor: crosshair;
  touch-action: none;
  -webkit-touch-callout: none;
  user-select: none;
}

hr {
  border: none;
  border-top: 1px solid #1c2033;
  margin: 14px 0;
}

/* Editing an image happens in a popover instead of inline in the side panel — centered on
   desktop, full-screen on mobile (see the media query below) so it's usable on small screens.
   The dialog itself never scrolls as a whole; #edit-dialog-body (or, on desktop, just the
   controls column within it) scrolls internally instead — that's what lets the close button
   stay anchored to the dialog's own corner via plain position:absolute, unaffected by whatever
   is scrolled internally, instead of needing sticky-positioning tricks. */
dialog#edit-dialog {
  position: relative;
  width: min(420px, 92vw);
  max-height: 88vh;
  overflow: hidden;
  background: #0c0e16;
  color: #e8e8f0;
  border: 1px solid #22263a;
  border-radius: 10px;
  padding: 16px;
}

/* display must only be set for the [open] state — an unconditional `display: flex` here would
   have higher specificity than the browser's default `dialog:not([open]) { display: none }` and
   override it, making the dialog permanently visible regardless of open/closed state. */
dialog#edit-dialog[open] {
  display: flex;
  flex-direction: column;
}

dialog#edit-dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
}

#edit-dialog-close-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  background: transparent;
  border: none;
  font-size: 20px;
  line-height: 1;
  padding: 4px 8px;
  margin: 0;
  color: #b7bad2;
}

#edit-dialog-close-btn:hover {
  color: #fff;
  background: transparent;
}

#edit-dialog-header {
  flex: 0 0 auto;
  padding-right: 32px; /* keep the title clear of the close button in the corner */
  margin-bottom: 12px;
}

#edit-dialog-header h2 {
  margin: 0;
}

#edit-dialog-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

/* Enough room to put the preview beside the controls instead of stacking them. */
@media (min-width: 641px) {
  dialog#edit-dialog[open] {
    width: min(760px, 94vw);
  }

  #edit-dialog-body {
    flex-direction: row;
    gap: 20px;
    overflow: visible;
  }

  #edit-dialog-preview-col {
    flex: 0 0 260px;
    margin-bottom: 0;
  }

  #edit-dialog-controls-col {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    overflow-y: auto;
    padding-right: 16px;
  }
}

dialog#capture-compat-dialog {
  width: min(420px, 92vw);
  background: #0c0e16;
  color: #e8e8f0;
  border: 1px solid #22263a;
  border-radius: 10px;
  padding: 20px;
}

dialog#capture-compat-dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
}

#capture-compat-header h2 {
  margin: 0 0 12px 0;
}

#capture-compat-body p {
  font-size: 13px;
  line-height: 1.5;
  color: #cfd2e6;
  margin: 0 0 12px 0;
}

#capture-compat-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

@media (max-width: 640px) {
  dialog#edit-dialog {
    width: 100vw;
    height: 100vh;
    max-width: none;
    max-height: none;
    margin: 0;
    border-radius: 0;
    inset: 0;
  }

  #preview-overlay-panel {
    width: calc(100vw - 28px);
  }

  /* Keep the preview pinned to the top of the body's own scrollbox while the controls below it
     scroll past — no padding-cancellation needed here since #edit-dialog-body has no padding of
     its own (the dialog's padding lives outside it). */
  #edit-dialog-preview-col {
    position: sticky;
    top: 0;
    background: #0c0e16;
    z-index: 1;
    padding-bottom: 4px;
    box-shadow: 0 6px 10px -6px rgba(0, 0, 0, 0.5);
  }

  /* The preview is square, so scaling it to the full (narrow) mobile width would otherwise make
     it roughly as tall as it is wide — capping the height instead keeps most of the full-screen
     dialog free for the actual controls. */
  #edit-preview-wrap {
    display: flex;
    justify-content: center;
    max-height: 30vh;
  }

  #edit-preview {
    width: auto;
    height: 30vh;
    max-width: 100%;
  }
}
