/* Values from Figma "AR_UI" / Main / iPhone 17_MainArUi (402×874). */
:root {
  --bar: rgba(0, 0, 0, 0.72);
  --ink: #ffffff;
  --camera-bg: #ffffff;
  /* 1 design unit: the 874-unit-tall frame is scaled to the screen height. */
  --u: calc(100vh / 874);
  --u: calc(100dvh / 874);
  /* Horizontal design unit: the 402-unit-wide frame is scaled to the screen width. */
  --ux: calc(100vw / 402);
  /* Rectangle 2 (115) / Rectangle 1 (162), never smaller than the safe areas need. */
  --top-h: max(calc(115 * var(--u)), calc(env(safe-area-inset-top) + 48px));
  --bottom-h: max(calc(162 * var(--u)), calc(env(safe-area-inset-bottom) + 96px));
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #000;
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

/* The video must stay in the DOM and "visible" or iOS stops decoding frames,
   so shrink it to 1px instead of display:none. */
#video {
  position: fixed;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

#app {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

/* Camera fills the whole frame (white in the design); the bars overlay it. */
#viewport {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
  background: var(--camera-bg);
}

#gl {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* Rectangle 2 — 115 units tall, rgba(0,0,0,0.72); also covers the status bar / Dynamic Island. */
#top-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: var(--top-h);
  box-sizing: border-box;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 8px;
  padding: 0 12px 10px;
  background: var(--bar);
}

/* Rectangle 1 — 162 units tall, rgba(0,0,0,0.72), shutter centred in it. */
#bottom-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--bottom-h);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  justify-items: center;
  background: var(--bar);
}

/* Group 1 / Group 2 — #D7D7D7 corner brackets (45×53 with the stroke overhang).
   Top-left sits 16 units below the top bar, bottom-right 16 above the bottom bar. */
.corner {
  position: absolute;
  width: calc(45 * var(--u));
  height: calc(53 * var(--u));
  display: block;
  pointer-events: none;
}

.corner-tl {
  left: calc(15 * var(--ux));
  top: calc(var(--top-h) + 16 * var(--u));
}

.corner-br {
  right: calc(11 * var(--ux));
  bottom: calc(var(--bottom-h) + 16 * var(--u));
  transform: rotate(180deg);
}

/* Shutter — 100×100 component; ShutterPressed swaps in while held. */
#shutter {
  grid-column: 2;
  position: relative;
  width: calc(100 * var(--u));
  height: calc(100 * var(--u));
  min-width: 64px;
  min-height: 64px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: none;
}

/* The images never receive touches, so the tap always lands on the button, and the
   states swap via opacity: iOS Safari swallows the click when a tap changes
   visibility/display under the finger. */
#shutter img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
}

#shutter .pressed {
  opacity: 0;
}

#shutter.down .idle {
  opacity: 0;
}

#shutter.down .pressed {
  opacity: 1;
}

#mode {
  grid-column: 1;
}

#flip {
  grid-column: 3;
}

button {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  padding: 10px 18px;
  background: rgba(255, 255, 255, 0.12);
  color: var(--ink);
  font: 600 14px system-ui, -apple-system, sans-serif;
}

button:disabled {
  opacity: 0.5;
}

.side-btn {
  padding: 8px 14px;
  font-size: 13px;
}

/* Left end of the top bar; scan/upload stay on the right. */
#light {
  margin-right: auto;
}

#status {
  position: absolute;
  top: calc(var(--top-h) + 8px);
  right: 8px; /* the top-left corner bracket lives on the left */
  padding: 4px 8px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  font: 12px/1.4 ui-monospace, Menlo, Consolas, monospace;
  white-space: pre;
  pointer-events: none;
}

#status:empty {
  display: none;
}

/* Scan box: the central 70% of the camera area (GUIDE in main.js). */
#guide {
  position: absolute;
  top: 15%;
  left: 15%;
  right: 15%;
  bottom: 15%;
  border: 2px dashed rgba(255, 255, 255, 0.9);
  border-radius: 8px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

#toast {
  position: absolute;
  left: 50%;
  bottom: calc(var(--bottom-h) + 12px);
  transform: translateX(-50%);
  max-width: 90%;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  font: 13px/1.4 system-ui, -apple-system, sans-serif;
  text-align: center;
  pointer-events: none;
}

/* Figma "Focus" component (100×100), centred on the tap point (left/top set in main.js). */
#focus-ring {
  position: absolute;
  width: calc(100 * var(--u));
  height: calc(100 * var(--u));
  margin: calc(-50 * var(--u)) 0 0 calc(-50 * var(--u));
  display: block;
  pointer-events: none;
}

#focus-ring.on {
  animation: focus-ring 1.2s ease-out forwards;
}

@keyframes focus-ring {
  0% {
    transform: scale(1.5);
    opacity: 0;
  }
  15% {
    transform: scale(1);
    opacity: 1;
  }
  75% {
    opacity: 1;
  }
  100% {
    opacity: 0.4;
  }
}

/* White flash when a photo is taken. */
#flash {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
}

#flash.on {
  animation: flash 0.35s ease-out;
}

@keyframes flash {
  from {
    opacity: 0.85;
  }
  to {
    opacity: 0;
  }
}

/* Photo preview (iOS fallback for sharing). */
#photo {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 16px);
  box-sizing: border-box;
  background: var(--bar);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

#photo-img {
  min-height: 0;
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
  /* Re-enable the long-press "Save to Photos" menu that body's styles turn off. */
  -webkit-touch-callout: default;
  -webkit-user-select: auto;
  user-select: auto;
  touch-action: auto;
}

#photo-hint {
  margin: 0;
  color: #fff;
  font: 14px/1.4 system-ui, -apple-system, sans-serif;
  text-align: center;
}

/* Figma "iPhone 17 - 2" — full-screen intro; tapping anywhere starts the camera. */
#overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #ffffff;
  cursor: pointer;
}

/* "AR TEST figma" — Inter Regular 12, black, at (65, 302). */
#intro-text {
  position: absolute;
  left: calc(65 * var(--ux));
  top: calc(302 * var(--u));
  width: calc(275 * var(--ux));
  margin: 0;
  color: #000000;
  font: 400 calc(12 * var(--u)) / normal Inter, system-ui, -apple-system, sans-serif;
}

#error {
  position: absolute;
  left: calc(65 * var(--ux));
  right: calc(65 * var(--ux));
  top: calc(340 * var(--u));
  margin: 0;
  color: #c62828;
  font: 14px/1.5 system-ui, -apple-system, sans-serif;
}
