:root {
  --app-h: 100dvh;
  --bg: #101114;
  --card: rgba(18, 20, 26, 0.9);
  --line: rgba(255, 255, 255, 0.12);
  --text: #ffffff;
  --muted: rgba(255, 255, 255, 0.76);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

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

[hidden] {
  display: none !important;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Helvetica Neue", Arial, sans-serif;
}

body {
  overscroll-behavior: none;
}

img,
video {
  user-select: none;
  -webkit-user-drag: none;
}

button,
a {
  touch-action: manipulation;
}

.app {
  position: relative;
  width: 100%;
  height: var(--app-h);
  overflow: hidden;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
}

.screen.is-active {
  display: block;
}

.screen-start {
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.14), transparent 34%),
    linear-gradient(180deg, #171b24 0%, #0e1014 100%);
}

.start-card {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(92vw, 460px);
  transform: translate(-50%, -50%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 28px;
  padding: calc(28px + var(--safe-top)) 22px calc(24px + var(--safe-bottom)) 22px;
  backdrop-filter: blur(16px);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.34);
  text-align: center;
}

.eyebrow {
  margin: 0 0 10px;
  font-size: 12px;
  letter-spacing: 0.12em;
  color: rgba(255, 255, 255, 0.7);
}

.start-card h1 {
  margin: 0;
  font-size: clamp(28px, 7vw, 38px);
  line-height: 1.05;
}

.lead {
  margin: 16px 0 22px;
  font-size: 16px;
  line-height: 1.75;
  color: var(--muted);
}

.howto {
  margin-top: 18px;
  display: grid;
  gap: 8px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.78);
}

.note {
  margin: 18px 0 0;
  font-size: 13px;
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.68);
}

.screen-camera {
  background: #000;
}

.stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #000;
  touch-action: none;
}

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

.camera-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(
      180deg,
      rgba(0, 0, 0, 0.54) 0%,
      rgba(0, 0, 0, 0.08) 18%,
      rgba(0, 0, 0, 0.04) 72%,
      rgba(0, 0, 0, 0.38) 100%
    );
}

.sticker-layer {
  position: absolute;
  inset: 0;
  touch-action: none;
}

.sticker {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 220px;
  height: 220px;
  transform: translate(-50%, -50%);
  overflow: visible;
  will-change: transform, width, height, left, top;
}

.sticker-shadow-img,
.sticker-img {
  position: absolute;
  pointer-events: none;
}

.sticker-shadow-img {
  object-fit: contain;
  opacity: 0.8;
}

.sticker-img {
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 12px 18px rgba(0, 0, 0, 0.18));
}

.top-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: calc(var(--safe-top) + 12px) calc(var(--safe-right) + 14px) 0 calc(var(--safe-left) + 14px);
  pointer-events: none;
}

.top-title,
.top-status {
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.45);
}

.top-title {
  justify-self: center;
  font-size: 13px;
  letter-spacing: 0.05em;
  color: rgba(255, 255, 255, 0.88);
}

.top-status {
  justify-self: end;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.78);
  min-width: 54px;
  text-align: right;
}

.icon-btn {
  pointer-events: auto;
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(0, 0, 0, 0.38);
  color: #fff;
  height: 38px;
  min-width: 56px;
  border-radius: 999px;
  padding: 0 14px;
  font-size: 14px;
  backdrop-filter: blur(12px);
}

.hint-pill {
  position: absolute;
  left: 50%;
  top: calc(var(--safe-top) + 66px);
  transform: translateX(-50%);
  z-index: 9;
  max-width: calc(100vw - 28px);
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.36);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: rgba(255, 255, 255, 0.92);
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
  backdrop-filter: blur(12px);
  pointer-events: none;
}

.bottom-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  padding: 14px calc(var(--safe-right) + 14px) calc(var(--safe-bottom) + 18px) calc(var(--safe-left) + 14px);
  pointer-events: none;
}

.bottom-controls .btn {
  pointer-events: auto;
}

.capture-flash {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
}

.capture-flash.is-on {
  animation: flashInOut 220ms ease;
}

@keyframes flashInOut {
  0% { opacity: 0; }
  15% { opacity: 0.92; }
  100% { opacity: 0; }
}

.preview-modal {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: calc(var(--safe-top) + 20px) 16px calc(var(--safe-bottom) + 20px) 16px;
  background: rgba(0, 0, 0, 0.74);
  backdrop-filter: blur(14px);
}

.preview-card {
  width: min(94vw, 520px);
  max-height: calc(var(--app-h) - 48px - var(--safe-top) - var(--safe-bottom));
  overflow: auto;
  border-radius: 28px;
  background: rgba(18, 20, 26, 0.96);
  border: 1px solid var(--line);
  padding: 18px 18px 20px;
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.42);
}

.preview-eyebrow {
  margin: 0 0 14px;
  text-align: center;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.9);
}

.result-image,
.result-video {
  display: block;
  width: 100%;
  max-height: min(62vh, 720px);
  border-radius: 20px;
  background: #0a0a0a;
  object-fit: contain;
}

.preview-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.preview-note {
  margin: 14px 2px 0;
  text-align: center;
  font-size: 12px;
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.7);
}

.btn {
  appearance: none;
  border: none;
  border-radius: 18px;
  min-height: 52px;
  padding: 0 14px;
  font-size: 15px;
  font-weight: 700;
  text-decoration: none;
  display: inline-grid;
  place-items: center;
  text-align: center;
}

.btn-lg {
  min-height: 56px;
  font-size: 16px;
}

.btn-primary {
  background: #ffffff;
  color: #101114;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.btn-video {
  background: #ff4d4f;
  color: #fff;
}

.btn-video.is-recording {
  background: #ffffff;
  color: #111;
}

.btn-ghost {
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.16);
}

.btn:disabled,
.icon-btn:disabled {
  opacity: 0.45;
}

@media (max-width: 520px) {
  .bottom-controls {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .preview-actions {
    grid-template-columns: 1fr;
  }
}
.preview-modal[hidden] {
  display: none !important;
}