:root {
  --navy-950: #060b18;
  --navy-900: #0a1330;
  --navy-800: #101c44;
  --navy-700: #16265c;
  --bg-top: #4e5e74;
  --bg-bottom: #23344b;
  --blue: #00bbff;
  --blue-light: #4fd7e8;
  --cyan: #4fd7e8;
  --white: #f4f7ff;
  --dim: #a9b4d6;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
  color: var(--white);
  font-family: "Segoe UI", Roboto, -apple-system, BlinkMacSystemFont, Helvetica, Arial, sans-serif;
  touch-action: none;
}

#stage {
  position: fixed;
  inset: 0;
}

/* ---------- Layers ---------- */
#camera-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}

#three-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#gesture-layer {
  position: absolute;
  inset: 0;
  z-index: 5;
  touch-action: none;
}

/* ---------- Shared screen chrome ---------- */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: calc(20px + var(--safe-top)) 20px calc(20px + var(--safe-bottom));
  z-index: 10;
}

/* ---------- Landscape guard ---------- */
/* Above every .screen (z-index 10) so it covers whatever's underneath — loading,
   picker, placing, preview — no matter which one was active when the device got
   rotated. */
.rotate-overlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
  background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
}
.rotate-overlay.hidden { display: none; }
.rotate-overlay > div {
  max-width: 280px;
}
.rotate-overlay svg {
  margin-bottom: 14px;
  animation: rotate-hint 1.8s ease-in-out infinite;
}
.rotate-overlay h2 {
  font-size: 19px;
  margin: 0 0 8px;
}
.rotate-overlay p {
  color: var(--dim);
  font-size: 14px;
  line-height: 1.5;
  margin: 0;
}
@keyframes rotate-hint {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(-90deg); }
}

.screen.hidden { display: none; }

.brandbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.brandbar .wordmark-logo {
  height: 20px;
  width: auto;
  display: block;
}

.brandbar .tag {
  font-size: 10.5px;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  border: 1px solid rgba(255,255,255,0.15);
  padding: 4px 10px;
  border-radius: 999px;
}

/* ---------- Loading / permission ---------- */
#screen-loading {
  align-items: center;
  justify-content: center;
  text-align: center;
  background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
}

.pulse-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--blue);
  box-shadow: 0 0 24px var(--blue);
  margin: 0 auto 18px;
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.5); opacity: 0.5; }
}

#screen-loading h2, #screen-error h2 {
  font-size: 19px;
  margin: 0 0 8px;
}
#screen-loading p, #screen-error p {
  color: var(--dim);
  font-size: 14px;
  max-width: 300px;
  line-height: 1.5;
  margin: 0 auto;
}

#screen-error {
  align-items: center;
  justify-content: center;
  text-align: center;
  background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
}

/* ---------- Desktop / non-mobile QR fallback ---------- */
#screen-qr {
  align-items: center;
  justify-content: center;
  text-align: center;
  background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
}
.qr-box {
  max-width: 320px;
  margin: 0 auto;
}
#screen-qr h2 {
  font-size: 19px;
  margin: 0 0 8px;
}
#screen-qr p {
  color: var(--dim);
  font-size: 14px;
  line-height: 1.5;
  margin: 0 auto;
}
.qr-frame {
  background: #ffffff;
  padding: 16px;
  border-radius: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 20px 0 14px;
  min-width: 220px;
  min-height: 220px;
}
#screen-qr .qr-url {
  font-size: 12px;
  word-break: break-all;
  color: var(--blue-light);
}

/* ---------- Product picker ---------- */
#screen-picker {
  justify-content: flex-end;
  /* Same top-to-bottom fade as before (transparent at top so the live camera shows
     through, opaque toward the bottom so the picker UI stays legible) — just retinted
     to the new bg-top/bg-bottom instead of flat navy. */
  background: linear-gradient(180deg, rgba(78,94,116,0) 0%, rgba(35,52,75,0.55) 45%, rgba(35,52,75,0.92) 100%);
  pointer-events: none;
}
#screen-picker .brandbar,
#screen-picker .picker-panel { pointer-events: auto; }

.picker-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.picker-title {
  font-size: 18px;
  font-weight: 800;
  margin: 0 0 2px;
}
.picker-sub {
  font-size: 13px;
  color: var(--dim);
  margin: 0 0 4px;
}

.product-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.product-card {
  background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
  border: 1px solid rgba(94,161,255,0.25);
  border-radius: 18px;
  padding: 10px 10px 14px;
  text-align: center;
  cursor: pointer;
}
.product-card:active { transform: scale(0.97); }

.product-card canvas {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: block;
  border-radius: 12px;
}

.product-card .p-name {
  font-weight: 800;
  font-size: 14px;
  margin-top: 8px;
}
.product-card .p-sub {
  font-size: 11.5px;
  color: var(--dim);
  margin-top: 2px;
}

/* ---------- Placing screen ---------- */
/* This section covers the full viewport (inset:0) so the drag/pinch/rotate
   gestures underneath (#gesture-layer) can reach the 3D overlay. Only the
   actual controls opt back in with pointer-events:auto — everything else
   here must stay pass-through, or touches never reach the model. */
#screen-placing {
  justify-content: space-between;
  pointer-events: none;
}
#screen-placing .placing-top,
#screen-placing .placing-bottom {
  pointer-events: auto;
}

.placing-top {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.hint-pill {
  align-self: center;
  background: rgba(6,11,24,0.6);
  border: 1px solid rgba(255,255,255,0.12);
  backdrop-filter: blur(6px);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 12.5px;
  color: var(--white);
  text-align: center;
  max-width: 88%;
}

.mode-row {
  display: flex;
  gap: 4px;
  background: rgba(6,11,24,0.6);
  border: 1px solid rgba(255,255,255,0.12);
  backdrop-filter: blur(6px);
  padding: 4px;
  border-radius: 999px;
}

.mode-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: transparent;
  color: var(--dim);
  font-size: 12.5px;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 999px;
  white-space: nowrap;
}

.mode-btn svg {
  display: block;
  flex: 0 0 auto;
}

.mode-btn.active {
  background: linear-gradient(180deg, var(--blue-light), var(--blue));
  color: white;
}

.placing-bottom {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.capture-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
  width: 100%;
}

.icon-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(16,28,68,0.75);
  border: 1px solid rgba(255,255,255,0.15);
  color: var(--white);
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.shutter-btn {
  width: 74px;
  height: 74px;
  border-radius: 50%;
  background: var(--white);
  border: 4px solid rgba(255,255,255,0.35);
  box-shadow: 0 0 0 3px var(--blue);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--bg-bottom);
}
.shutter-btn svg { display: block; flex: 0 0 auto; }
.shutter-btn:active { transform: scale(0.94); }

/* ---------- Filter bar (Instagram-style carousel) ---------- */
.filter-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  gap: 10px;
}

.filter-toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(16,28,68,0.75);
  color: var(--white);
  font-size: 12.5px;
  font-weight: 700;
  padding: 9px 16px;
  border-radius: 999px;
}
.filter-toggle svg { display: block; flex: 0 0 auto; }
.filter-toggle.active {
  background: linear-gradient(180deg, var(--blue-light), var(--blue));
  border-color: transparent;
}

.filter-panel {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.filter-panel.hidden { display: none; }

.filter-name {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--white);
  text-shadow: 0 1px 6px rgba(0,0,0,0.6);
}

.filter-strip {
  width: 100%;
  display: flex;
  gap: 14px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  padding: 4px calc(50% - 30px);
  scrollbar-width: none;
}
.filter-strip::-webkit-scrollbar { display: none; }

.filter-chip {
  flex: 0 0 auto;
  scroll-snap-align: center;
  width: 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

.filter-chip .swatch {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid rgba(255,255,255,0.25);
  background: #1a1f2e;
}
.filter-chip .swatch img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.filter-chip.active .swatch {
  border-color: var(--blue-light);
  box-shadow: 0 0 0 2px var(--blue);
}
.filter-chip .chip-label {
  font-size: 9.5px;
  color: var(--dim);
  text-align: center;
  white-space: nowrap;
}
.filter-chip.active .chip-label {
  color: var(--white);
  font-weight: 700;
}

/* ---------- Preview screen ---------- */
#screen-preview {
  justify-content: space-between;
  background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
}

.preview-frame {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 22px;
  overflow: hidden;
  margin: 8px 0 16px;
  background: #000;
}
.preview-frame img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.preview-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 16px 20px;
  border-radius: 14px;
  border: none;
  font-size: 15.5px;
  font-weight: 800;
  cursor: pointer;
}
.btn-primary {
  background: linear-gradient(180deg, var(--blue-light), var(--blue));
  color: white;
}
.btn-ghost {
  background: rgba(255,255,255,0.06);
  color: var(--white);
  border: 1px solid rgba(255,255,255,0.14);
}
.save-hint {
  text-align: center;
  color: var(--dim);
  font-size: 12px;
  margin-top: 2px;
}