:root {
  --bg: #0b0d0f;
  --surface: #16191d;
  --surface-2: #22262c;
  --text: #eef1f4;
  --muted: #9aa3ad;
  --accent: #38bd94;
  --accent-text: #04140f;
  --danger: #f07167;
  --radius: 12px;
  --gap: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

/* Camera */

#camera { background: #000; }

#video, #outline {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
#video { object-fit: cover; }
#outline { pointer-events: none; }

.status {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 16px);
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  color: var(--text);
  white-space: nowrap;
  max-width: calc(100% - 32px);
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  padding: 12px 16px;
}
.bar.top {
  padding-top: calc(env(safe-area-inset-top) + 12px);
  background: var(--surface);
}
.bar.bottom {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding-bottom: calc(env(safe-area-inset-bottom) + 24px);
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.6));
}
.bar-spacer, #upload-label { width: 96px; }

.shutter {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 4px solid #fff;
  background: rgba(255, 255, 255, 0.25);
  cursor: pointer;
  padding: 0;
}
.shutter:active { background: rgba(255, 255, 255, 0.6); }
.shutter:disabled { opacity: 0.4; cursor: default; }

/* Buttons */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 8px 14px;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}
.button:disabled { opacity: 0.5; cursor: default; }
.button.primary { background: var(--accent); color: var(--accent-text); font-weight: 600; }
#camera .button { background: rgba(0, 0, 0, 0.55); }

/* Editor and corners */

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--bg);
}
/* Out of the layout, centred: its size follows the stage's and must not feed
   back into it (editor.js sizes it to fit). */
#page {
  position: absolute;
  inset: 0;
  margin: auto;
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.5);
}
#crop-stage { padding: 0; }
#crop-canvas { width: 100%; height: 100%; touch-action: none; }

.busy {
  position: absolute;
  bottom: 24px;
  margin: 0;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.6);
  color: var(--muted);
}

.hint {
  margin: 0;
  padding: 12px 16px calc(env(safe-area-inset-bottom) + 12px);
  background: var(--surface);
  color: var(--muted);
  text-align: center;
}

.tools {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  padding: 12px 16px calc(env(safe-area-inset-bottom) + 12px);
  background: var(--surface);
  max-height: 45vh;
  overflow-y: auto;
}

.segmented {
  display: flex;
  gap: 4px;
  margin: 0;
  padding: 4px;
  border: 0;
  border-radius: var(--radius);
  background: var(--bg);
}
.segmented legend { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.segmented > button, .segmented > label {
  flex: 1;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}
.segmented > [aria-checked="true"], .segmented > label:has(input:checked) {
  background: var(--surface-2);
  color: var(--text);
}
.segmented input { position: absolute; opacity: 0; pointer-events: none; }

.actions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.actions .button { padding: 8px 6px; font-size: 14px; }
#compare { touch-action: none; }

.sliders {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 6px 20px;
}
.sliders label, .field {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  color: var(--muted);
  font-size: 14px;
}
.sliders output, .field output { color: var(--text); font-variant-numeric: tabular-nums; }
.sliders input, .field input, .field select { grid-column: 1 / -1; width: 100%; }
input[type="range"] { accent-color: var(--accent); margin: 6px 0; }

/* Export dialog */

dialog {
  width: min(400px, calc(100% - 32px));
  padding: 20px;
  border: 0;
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog h2 { margin: 0 0 16px; font-size: 18px; }
dialog .field { margin-top: 16px; }
dialog select {
  margin-top: 6px;
  min-height: 40px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
}
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(env(safe-area-inset-bottom) + 120px);
  margin: 0 auto;
  max-width: 480px;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  border-left: 4px solid var(--danger);
  z-index: 10;
}

@media (min-width: 900px) {
  /* Side by side on a wide screen: the page, and the controls beside it. */
  #editor { display: grid; grid-template-columns: 1fr 380px; grid-template-rows: auto minmax(0, 1fr); }
  #editor .bar.top { grid-column: 1 / -1; }
  #editor .tools { max-height: none; }
  .sliders { grid-template-columns: 1fr; }
}
