:root {
  --bg: #000;
  --fg: #fff;
  --glass: rgba(20, 20, 24, 0.55);
  --glass-strong: rgba(20, 20, 24, 0.85);
  --accent: #ff3d7f;
  --tile: 64px;
  --gap: 14px;
  --ring: 84px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 500 15px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

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

#stage { position: absolute; inset: 0; overflow: hidden; background: #000; }
#stage video { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
#stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }

#flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
#flash.go { animation: flash 0.35s ease-out; }
@keyframes flash { from { opacity: 0.9; } to { opacity: 0; } }

/* ---- top bar */
.topbar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 10px;
  padding: calc(var(--safe-top) + 12px) 16px 12px;
  background: linear-gradient(rgba(0,0,0,0.45), transparent);
}
.spacer { flex: 1; }
/* Bars pass taps through to the camera view (tap = take photo); only their controls catch them. */
.topbar, .bottombar { pointer-events: none; }
.topbar > *, #carousel, #lastShot { pointer-events: auto; }

.icon-btn {
  width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center;
  border: 0; background: var(--glass);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; }
.icon-btn:active { transform: scale(0.92); }

.chip {
  border: 0; border-radius: 999px; padding: 10px 16px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  font-weight: 600;
}
.chip.primary { background: var(--accent); }
.chip:active { transform: scale(0.96); }

.status {
  position: absolute; left: 50%; top: calc(var(--safe-top) + 72px);
  transform: translate(-50%, -6px);
  padding: 8px 14px; border-radius: 999px;
  background: var(--glass-strong); white-space: nowrap;
  opacity: 0; transition: opacity 0.2s, transform 0.2s; pointer-events: none;
}
.status.show { opacity: 1; transform: translate(-50%, 0); }

.toast {
  position: absolute; left: 50%; bottom: calc(var(--safe-bottom) + 150px);
  transform: translateX(-50%);
  font-size: 18px; font-weight: 700; text-shadow: 0 1px 6px rgba(0,0,0,0.7);
  opacity: 0; transition: opacity 0.25s; pointer-events: none; white-space: nowrap;
}
.toast.show { opacity: 1; }

.grab { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(var(--safe-bottom) + 190px); }
.grab:active { transform: translateX(-50%) scale(0.96); }

/* ---- bottom bar / carousel */
.bottombar {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 28px 0 calc(var(--safe-bottom) + 28px);
  background: linear-gradient(transparent, rgba(0,0,0,0.5));
}

#carousel {
  position: relative;
  overflow-x: auto; overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  padding: 10px 0;
}
#carousel::-webkit-scrollbar { display: none; }
#carouselTrack {
  display: flex; gap: var(--gap); width: max-content;
  padding: 0 calc(50vw - var(--tile) / 2);
}

.fx {
  position: relative; flex: none;
  width: var(--tile); height: var(--tile); padding: 0;
  border-radius: 50%; border: 2px solid rgba(255,255,255,0.75);
  overflow: hidden; background: #222;
  scroll-snap-align: center;
  transition: transform 0.15s;
}
.fx canvas { width: 100%; height: 100%; display: block; }
.fx .badge {
  position: absolute; right: 3px; bottom: 3px;
  font-size: 15px; line-height: 1;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.6));
}
.fx.active { border-color: transparent; }

#shutter {
  position: absolute; left: 50%; top: 28px;
  width: var(--ring); height: var(--ring);
  margin: calc((var(--tile) + 20px - var(--ring)) / 2) 0 0 calc(var(--ring) / -2);
  border-radius: 50%; border: 5px solid #fff; background: transparent;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.15), 0 2px 12px rgba(0,0,0,0.35);
  pointer-events: none; /* taps reach the centered tile, which captures */
}

#lastShot {
  position: absolute; left: 16px; bottom: calc(var(--safe-bottom) + 140px);
  width: 48px; height: 64px; padding: 0; border: 2px solid #fff; border-radius: 10px; overflow: hidden;
  background: #222; box-shadow: 0 2px 10px rgba(0,0,0,0.4);
}
#lastShot img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ---- effects grid */
#grid {
  position: absolute; inset: 0; overflow-y: auto;
  background: rgba(8, 8, 10, 0.96);
  padding: calc(var(--safe-top) + 12px) 12px calc(var(--safe-bottom) + 24px);
}
.grid-head { display: flex; align-items: center; justify-content: space-between; padding: 0 4px 12px; }
.grid-head h2 { margin: 0; font-size: 22px; }
#gridTiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (min-width: 700px) { #gridTiles { grid-template-columns: repeat(5, 1fr); } }
@media (min-width: 1100px) { #gridTiles { grid-template-columns: repeat(7, 1fr); } }
.grid-cat {
  grid-column: 1 / -1; margin: 14px 4px 2px;
  font-size: 13px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; opacity: 0.65;
}
.grid-cat:first-child { margin-top: 0; }
.grid-tile {
  position: relative; padding: 0; border: 0; border-radius: 14px; overflow: hidden;
  aspect-ratio: 3 / 4; background: #1b1b1f;
}
.grid-tile canvas { width: 100%; height: 100%; display: block; }
.grid-tile .label {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 18px 8px 7px; font-size: 13px; font-weight: 600; text-align: left;
  background: linear-gradient(transparent, rgba(0,0,0,0.75));
}
.grid-tile .badge { position: absolute; top: 6px; right: 7px; font-size: 16px; }
.grid-tile:active { transform: scale(0.97); }
body.grid-open .topbar, body.grid-open .bottombar { display: none; }

/* ---- viewer */
#viewer {
  position: absolute; inset: 0; background: rgba(0,0,0,0.92);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  padding: calc(var(--safe-top) + 16px) 16px calc(var(--safe-bottom) + 16px);
}
#viewer img { max-width: 100%; max-height: calc(100% - 80px); border-radius: 16px; -webkit-touch-callout: default; }
.viewer-actions { display: flex; gap: 12px; }

/* ---- start screen */
#startScreen {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  padding: 24px; text-align: center;
  background: radial-gradient(circle at 30% 20%, #6a1b9a, transparent 60%),
              radial-gradient(circle at 80% 80%, #ff3d7f, transparent 55%), #111;
}
#startScreen .logo { font-size: 44px; font-weight: 800; letter-spacing: -1px; }
#startScreen p { max-width: 320px; margin: 0; opacity: 0.9; }

/* ---- iOS install hint */
#iosHint {
  position: absolute; left: 16px; right: 16px; top: calc(var(--safe-top) + 70px);
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border-radius: 14px; background: var(--glass-strong);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}
#iosHint svg { width: 16px; height: 16px; fill: currentColor; vertical-align: -2px; }
#iosHint span { flex: 1; }
#iosHint button { border: 0; background: none; font-size: 18px; padding: 4px 6px; }
