:root {
  --bg: #050505;
  --white: #ffffff;
  --overlay: rgba(0, 0, 0, 0.34);
  --overlay-strong: rgba(0, 0, 0, 0.82);
  --grid: rgba(255, 255, 255, 0.35);
  --shadow: 0 18px 70px rgba(0, 0, 0, 0.35);
  --safe-bottom: max(18px, env(safe-area-inset-bottom));
  --safe-top: max(18px, env(safe-area-inset-top));
  --system-indigo: #5856d6;
}

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

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--white);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif;
  overscroll-behavior: none;
}

body {
  min-height: 100vh;
}

button,
input {
  font: inherit;
}

.app-shell {
  position: relative;
  width: 100%;
  height: 100vh;
  overflow: hidden;
  background: #111;
}

.background-video,
.background-blur {
  position: absolute;
  inset: 0;
}

.background-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform-origin: center center;
  filter: saturate(1.05);
}

.background-blur {
  backdrop-filter: blur(28px);
  background: rgba(5, 5, 5, 0.28);
}

.camera-stage {
  position: absolute;
  inset: 0;
  display: flex;
}

.pane {
  position: relative;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--safe-top) + 20px) 12px calc(var(--safe-bottom) + 110px);
  transition: opacity 0.25s ease, width 0.25s ease, flex-basis 0.25s ease;
}

.pane.hidden {
  opacity: 0;
  pointer-events: none;
  width: 0;
  flex: 0 0 0;
  padding-left: 0;
  padding-right: 0;
}

.pane-right.full {
  flex: 1 1 100%;
}

.camera-frame,
.frame-button {
  position: relative;
  width: min(100%, calc((100vh - var(--safe-top) - var(--safe-bottom) - 130px) * 0.75));
  aspect-ratio: 3 / 4;
  background: transparent;
  border: 0;
  padding: 0;
}

.frame-button {
  cursor: pointer;
}

.frame-button .camera-frame {
  width: 100%;
  height: 100%;
}

.camera-video,
.generated-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: transparent;
}

.camera-video {
  object-fit: cover;
  transform-origin: center center;
}

.generated-image {
  object-fit: contain;
}

.grid-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(to right, transparent 33.1%, var(--grid) 33.1%, var(--grid) 33.7%, transparent 33.7%, transparent 66.3%, var(--grid) 66.3%, var(--grid) 66.9%, transparent 66.9%),
    linear-gradient(to bottom, transparent 33.1%, var(--grid) 33.1%, var(--grid) 33.7%, transparent 33.7%, transparent 66.3%, var(--grid) 66.3%, var(--grid) 66.9%, transparent 66.9%);
}

.focus-ring {
  position: absolute;
  width: 72px;
  height: 72px;
  border: 2px solid rgba(255, 255, 255, 0.95);
  border-radius: 18px;
  transform: translate(-50%, -50%);
  z-index: 5;
  pointer-events: none;
  box-shadow: 0 0 0 9999px rgba(255, 255, 255, 0);
}

.focus-ring.hidden {
  display: none;
}

.focus-ring.show {
  display: block;
  animation: focus-pop 0.6s ease forwards;
}

@keyframes focus-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(1.25);
  }

  20% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.92);
  }
}

.zoom-rail {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 5;
}

.zoom-value {
  min-width: 56px;
  padding: 4px 8px;
  border-radius: 8px;
  background: var(--overlay);
  text-align: center;
  font-size: 12px;
  font-weight: 600;
}

.zoom-dial {
  width: 28px;
  height: min(62vh, 360px);
  transform: rotate(-90deg);
  accent-color: #fff;
  background: transparent;
}

.gallery-thumb {
  position: absolute;
  left: 10px;
  bottom: 10px;
  width: 56px;
  height: 56px;
  overflow: hidden;
  border-radius: 10px;
  border: 0;
  padding: 0;
  background: var(--overlay);
  box-shadow: var(--shadow);
}

.gallery-thumb.hidden {
  display: none;
}

.gallery-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.status-wrap {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 132px);
  transform: translateX(-50%);
  width: min(95vw, 620px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  z-index: 15;
}

.status-wrap.hidden {
  display: none;
}

.status-label {
  padding: 11px 16px;
  border-radius: 10px;
  background: var(--overlay);
  text-align: center;
  font-size: 16px;
  font-weight: 600;
  white-space: pre-line;
}

.progress-wrap {
  width: min(72vw, 380px);
  height: 6px;
  overflow: hidden;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.18);
}

.progress-wrap.hidden {
  display: none;
}

.progress-bar {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: #fff;
  transition: width 0.18s ease;
}

.bottom-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(var(--safe-bottom) + 26px);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(30px, 10vw, 82px);
  z-index: 20;
}

.action-button {
  border: 0;
  background: transparent;
  color: var(--white);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
}

.action-button:disabled {
  opacity: 0.45;
}

.action-button-ai {
  width: 70px;
  height: 55px;
}

.action-button-ai img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.action-button-capture {
  width: 55px;
  height: 55px;
}

.action-button-capture img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.action-button-flip {
  width: 70px;
  height: 55px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(18px);
  font-size: 31px;
  line-height: 1;
}

.spinner {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 62px;
  height: 62px;
  margin-left: -31px;
  margin-top: -31px;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.22);
  border-top-color: #fff;
  animation: spin 0.8s linear infinite;
}

.spinner.hidden {
  display: none;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.region-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--overlay-strong);
  text-align: center;
  z-index: 30;
}

.region-overlay.hidden {
  display: none;
}

.region-overlay p {
  margin: 0;
  max-width: min(82vw, 420px);
  font-size: 18px;
  font-weight: 600;
}

.viewer-modal {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: rgba(0, 0, 0, 0.98);
  z-index: 40;
}

.viewer-modal.hidden {
  display: none;
}

.viewer-chrome {
  position: absolute;
  left: 0;
  right: 0;
  top: var(--safe-top);
  display: flex;
  justify-content: space-between;
  padding: 14px;
  z-index: 2;
}

.viewer-close,
.viewer-save {
  border: 0;
  color: var(--white);
  background: var(--overlay);
  border-radius: 12px;
  padding: 10px 14px;
}

.viewer-body {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: calc(var(--safe-top) + 40px) 12px calc(var(--safe-bottom) + 70px);
}

.viewer-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.viewer-nav {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 999px;
  background: var(--overlay);
  color: var(--white);
  font-size: 34px;
  line-height: 1;
}

.viewer-dots {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 14px);
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
}

.viewer-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.32);
}

.viewer-dot.active {
  background: rgba(255, 255, 255, 0.95);
}

@media (max-width: 900px) {
  .camera-frame,
  .frame-button {
    width: min(100%, calc((100vh - var(--safe-top) - var(--safe-bottom) - 150px) * 0.75));
  }

  .zoom-rail {
    right: 4px;
  }
}

@media (max-width: 680px) {
  .pane {
    padding-left: 8px;
    padding-right: 8px;
  }

  .zoom-dial {
    height: 180px;
  }

  .bottom-bar {
    gap: 38px;
  }
}
