:root {
  --bg: #111214;
  --fg: #f4f1ea;
  --muted: #8b8a86;
  --accent: #ffcc33;
  --danger: #ff6b5b;
  --panel: #1c1d20;
  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: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

.viewfinder {
  position: relative;
  flex: 1;
  overflow: hidden;
  background: #000;
}

.viewfinder { touch-action: none; }

video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.focus-ring {
  position: absolute;
  width: 76px;
  height: 76px;
  margin: -38px 0 0 -38px;
  border: 1.5px solid var(--accent);
  border-radius: 4px;
  opacity: 0;
  pointer-events: none;
}
.focus-ring.go { animation: focus 900ms ease-out; }
@keyframes focus {
  0% { opacity: 1; transform: scale(1.4); }
  25% { opacity: 1; transform: scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: scale(1); }
}

.torch {
  position: absolute;
  top: calc(14px + env(safe-area-inset-top));
  left: 14px;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, .45);
  color: var(--fg);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.torch[hidden] { display: none; }
.torch.on { background: var(--accent); color: #111; }

.zoom-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  pointer-events: none;
}
.zoom-bar > * { pointer-events: auto; }

.lenses {
  display: flex;
  gap: 6px;
  padding: 4px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .4);
}
.lenses[hidden], .zoom-badge[hidden] { display: none; }

.lens, .zoom-badge {
  min-width: 36px;
  height: 36px;
  padding: 0 8px;
  border: 0;
  border-radius: 999px;
  background: rgba(30, 30, 32, .7);
  color: var(--fg);
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
.lens.active { color: var(--accent); background: rgba(30, 30, 32, .95); font-size: 13px; }
.zoom-badge { color: var(--accent); background: rgba(0, 0, 0, .55); }

.flash {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
}
.flash.go { animation: flash 280ms ease-out; }
@keyframes flash { 0% { opacity: .85; } 100% { opacity: 0; } }

.cam-msg {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  text-align: center;
  color: var(--muted);
}
.cam-msg[hidden] { display: none; }

.btn {
  display: inline-block;
  padding: 12px 22px;
  border-radius: 999px;
  background: var(--accent);
  color: #111;
  font-weight: 600;
}

.controls {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 20px 28px calc(20px + env(safe-area-inset-bottom));
  background: var(--bg);
}

.shutter {
  width: 78px;
  height: 78px;
  border-radius: 50%;
  border: 4px solid var(--fg);
  background: transparent;
  padding: 5px;
  cursor: pointer;
}
.shutter span {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--fg);
  transition: transform 120ms;
}
.shutter:active span { transform: scale(.88); background: var(--accent); }
.shutter:disabled { opacity: .4; }

.thumb-btn, .icon-btn {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  border: 0;
  padding: 0;
  background: var(--panel);
  color: var(--fg);
  position: relative;
  cursor: pointer;
}
.thumb-btn { justify-self: start; }
.icon-btn { justify-self: end; border-radius: 50%; }

.thumb-btn img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 12px;
  display: block;
}
.thumb-btn img:not([src]) { visibility: hidden; }

.count {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--accent);
  color: #111;
  font-size: 12px;
  font-weight: 700;
  line-height: 20px;
}

.toast {
  position: fixed;
  left: 50%;
  top: calc(16px + env(safe-area-inset-top));
  transform: translate(-50%, -20px);
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(20, 20, 22, .9);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms, transform 180ms;
  white-space: nowrap;
  z-index: 10;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.ok::before { content: "✓ "; color: var(--accent); }
.toast.err { color: var(--danger); }

/* Recent sheet */
.sheet {
  width: 100%;
  max-width: 640px;
  max-height: 85vh;
  margin: auto auto 0;
  padding: 0 0 env(safe-area-inset-bottom);
  border: 0;
  border-radius: 20px 20px 0 0;
  background: var(--panel);
  color: var(--fg);
  display: none;
  flex-direction: column;
}
.sheet[open] { display: flex; animation: up 200ms ease-out; }
.sheet::backdrop { background: rgba(0, 0, 0, .55); }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }

.sheet header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 18px 18px 10px;
}
.sheet h2 { margin: 0; font-size: 18px; }
.hint { color: var(--muted); font-size: 12px; flex: 1; }
.close {
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 18px;
  padding: 4px 8px;
  cursor: pointer;
}

.grid {
  list-style: none;
  margin: 0;
  padding: 4px 14px 14px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  overflow-y: auto;
}
.grid li { position: relative; aspect-ratio: 1; }
.grid .pic {
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  border-radius: 10px;
  overflow: hidden;
  background: #000;
  cursor: pointer;
}
.grid img { width: 100%; height: 100%; object-fit: cover; display: block; }
.grid time {
  position: absolute;
  left: 6px;
  bottom: 6px;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 6px;
  background: rgba(0, 0, 0, .6);
  pointer-events: none;
}
.grid .del {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 0;
  background: rgba(0, 0, 0, .6);
  color: var(--fg);
  font-size: 13px;
  cursor: pointer;
}

.empty { color: var(--muted); text-align: center; padding: 30px 0; margin: 0; }
.empty[hidden] { display: none; }

.sheet footer { padding: 4px 18px 16px; text-align: center; }
.link { border: 0; background: none; font: inherit; cursor: pointer; padding: 8px; }
.danger { color: var(--danger); }
