:root {
  color-scheme: dark;
  --bg: #0a0a0b;
  --panel: #151518;
  --panel-2: #202024;
  --text: #f7f7f8;
  --muted: #a7a7ae;
  --line: rgba(255, 255, 255, 0.12);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: #000; }
body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; }
button:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }

.app-shell {
  width: min(100%, 480px);
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
  position: relative;
  overflow: hidden;
  box-shadow: 0 0 80px rgba(0,0,0,.65);
}

.screen {
  min-height: 100dvh;
  padding: calc(14px + var(--safe-top)) 14px calc(18px + var(--safe-bottom));
}
.screen[hidden] { display: none !important; }

.camera-screen {
  display: grid;
  grid-template-rows: auto minmax(230px, 1fr) auto auto auto auto;
  gap: 12px;
}

.topbar {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand-logo {
  width: 128px;
  height: 50px;
  object-fit: contain;
  object-position: left center;
  background: #fff;
  border-radius: 12px;
}
.status-pill {
  max-width: 210px;
  padding: 7px 10px;
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.camera-stage {
  position: relative;
  width: 100%;
  min-height: 260px;
  max-height: 58dvh;
  aspect-ratio: 9 / 14;
  overflow: hidden;
  border-radius: 28px;
  background: #050505;
  border: 1px solid var(--line);
  transform: translateZ(0);
}
.camera-stage video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transform: translateZ(0);
  will-change: transform, filter;
}
.camera-stage.is-front video { transform: scaleX(-1) translateZ(0); }
.camera-shade {
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 -90px 90px rgba(0,0,0,.25), inset 0 70px 80px rgba(0,0,0,.12);
}
.countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  font-size: clamp(84px, 27vw, 150px);
  font-weight: 900;
  text-shadow: 0 5px 30px rgba(0,0,0,.6);
}
.countdown:empty { display: none; }
.shot-progress {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(0,0,0,.48);
  backdrop-filter: blur(10px);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.flash {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
}
.flash.is-on { animation: flash .18s ease-out; }
@keyframes flash { 0% { opacity: .9; } 100% { opacity: 0; } }

.filter-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 2px 1px;
}
.filter-strip::-webkit-scrollbar { display: none; }
.filter-chip,
.mode-button,
.text-button,
.primary-action,
.secondary-action,
.round-button {
  border: 0;
  color: var(--text);
  cursor: pointer;
}
.filter-chip {
  flex: 0 0 auto;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 13px;
}
.filter-chip.is-selected { background: #f5f5f5; color: #090909; }

.mode-switch {
  padding: 4px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  background: var(--panel);
  border-radius: 14px;
}
.mode-button {
  min-height: 42px;
  border-radius: 11px;
  background: transparent;
  color: var(--muted);
  font-weight: 750;
}
.mode-button.is-selected { background: #f5f5f5; color: #090909; }

.capture-controls {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 18px;
  padding: 3px 16px 0;
}
.round-button {
  justify-self: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--panel-2);
  font-size: 25px;
}
.capture-button {
  width: 78px;
  height: 78px;
  border: 5px solid #fff;
  background: transparent;
  border-radius: 50%;
  padding: 6px;
  cursor: pointer;
}
.capture-button span {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: #fff;
  transition: transform .15s ease, border-radius .15s ease;
}
.capture-button:active span { transform: scale(.9); }
.capture-button.is-busy { opacity: .55; pointer-events: none; }
.capture-button.is-busy span { border-radius: 18px; transform: scale(.68); }
.round-button:disabled, .mode-button:disabled, .filter-chip:disabled { opacity: .4; cursor: default; }
.helper-text { margin: 0; text-align: center; color: var(--muted); font-size: 12px; }

.preview-screen {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto auto;
  gap: 12px;
}
.preview-header {
  display: grid;
  grid-template-columns: 72px 1fr 72px;
  align-items: center;
  min-height: 48px;
}
.preview-header h1 { margin: 0; text-align: center; font-size: 17px; }
.text-button { background: transparent; color: #fff; padding: 10px 0; text-align: left; }
.header-spacer { display: block; }
.poster-wrap {
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
}
#previewCanvas {
  display: block;
  height: min(100%, calc(100dvh - 230px));
  max-width: 100%;
  aspect-ratio: 9 / 16;
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 12px 40px rgba(0,0,0,.45);
}
.preview-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}
.preview-actions { display: flex; gap: 8px; }
.preview-actions > button { flex: 1; }
.primary-action, .secondary-action {
  min-height: 52px;
  border-radius: 15px;
  font-weight: 800;
}
.primary-action { background: #fff; color: #090909; }
.secondary-action { background: var(--panel-2); color: #fff; }
.primary-action:disabled, .secondary-action:disabled { opacity: .5; }
.privacy-note { margin: 0; text-align: center; color: var(--muted); font-size: 11px; line-height: 1.4; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(22px + var(--safe-bottom));
  transform: translate(-50%, 18px);
  width: min(calc(100% - 36px), 420px);
  padding: 11px 14px;
  border-radius: 13px;
  background: rgba(34,34,38,.96);
  color: #fff;
  text-align: center;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
  z-index: 20;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 600px) {
  body { background: #050506; }
  .app-shell { border-inline: 1px solid rgba(255,255,255,.06); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
