:root {
  --bg: #0e0e0f;
  --panel: #17171a;
  --panel-2: #1f1f23;
  --line: #2a2a2f;
  --accent: #e8e6e1;
  --signal: #e0a458;
  --text: #ecebe7;
  --muted: #8d8c88;
  --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
button { font: inherit; color: inherit; }

/* no double-tap zoom or text selection when tapping controls quickly */
html, body, button, .shutterbar, .viewfinder, .gallery, .controls { touch-action: manipulation; }
button, .shutterbar, .viewfinder, .gallery img, .viewer { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
button { -webkit-tap-highlight-color: transparent; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 16px 14px calc(16px + env(safe-area-inset-bottom));
}

:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }

.app { width: 100%; max-width: 480px; display: flex; flex-direction: column; gap: 16px; }

.icon {
  width: 22px; height: 22px; fill: none; stroke: currentColor;
  stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round;
}
.icon-lg { width: 36px; height: 36px; stroke-width: 1.2; color: var(--muted); }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: baseline; justify-content: space-between; padding: 0 2px; }
.topbar h1 { font-size: 0.95rem; font-weight: 600; letter-spacing: 0.04em; }
.datestamp { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 0.78rem; }

/* ---------- viewfinder ---------- */
.viewfinder {
  position: relative; width: 100%; aspect-ratio: 1 / 1;
  background: #000; border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--line);
}
.viewfinder video, .viewfinder canvas {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
}
.viewfinder video.mirrored { transform: scaleX(-1); }

/* keep the <video> decodable but invisible when WebGL renders the preview */
.video-hidden {
  position: absolute; width: 2px !important; height: 2px !important;
  opacity: 0.01; pointer-events: none; bottom: 0; left: 0;
}

.placeholder {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px; padding: 24px;
  text-align: center; font-size: 0.9rem; color: var(--muted);
  background: var(--panel); z-index: 5;
}

.flash {
  position: absolute; inset: 0; z-index: 6; background: #fff;
  opacity: 0; pointer-events: none; transition: opacity 60ms linear;
}
.flash.on { opacity: 0.95; transition: none; }

.hud {
  position: absolute; top: 10px; z-index: 4; padding: 3px 8px; border-radius: 99px;
  font-size: 0.72rem; font-variant-numeric: tabular-nums; letter-spacing: 0.03em;
  background: rgba(0,0,0,0.45); backdrop-filter: blur(6px); pointer-events: none;
}
.hud-left { left: 10px; }
.hud-right { right: 10px; }

.countdown {
  position: absolute; inset: 0; z-index: 7; display: flex; align-items: center;
  justify-content: center; font-size: 6rem; font-weight: 200; pointer-events: none;
  text-shadow: 0 2px 20px rgba(0,0,0,0.6);
}

/* ---------- buttons ---------- */
.primary-btn {
  background: var(--text); color: #111; border: 0; border-radius: 99px;
  padding: 10px 20px; font-weight: 600; font-size: 0.88rem; cursor: pointer;
}
.primary-btn:hover { background: #fff; }

.shutterbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.icon-btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  min-width: 46px; height: 46px; border-radius: 50%;
  background: var(--panel); border: 1px solid var(--line); cursor: pointer;
  transition: background 120ms, border-color 120ms;
}
.icon-btn:hover:not(:disabled) { background: var(--panel-2); border-color: #3a3a40; }
.icon-btn:disabled { opacity: 0.35; cursor: default; }
.icon-btn[aria-pressed="true"], .icon-btn[aria-expanded="true"] { border-color: var(--signal); color: var(--signal); }
.text-btn { font-size: 0.78rem; font-variant-numeric: tabular-nums; padding: 0 10px; border-radius: 99px; }
.badge {
  position: absolute; top: -3px; right: -3px; font-size: 0.62rem; font-weight: 600;
  background: var(--signal); color: #111; border-radius: 99px; padding: 1px 5px;
}
.badge:empty { display: none; }

.shutter {
  width: 70px; height: 70px; border-radius: 50%; flex-shrink: 0;
  border: 3px solid var(--text); background: transparent; cursor: pointer;
  padding: 4px; transition: transform 80ms;
  background-clip: content-box; background-color: var(--text);
}
.shutter:hover:not(:disabled) { background-color: #fff; }
.shutter:active:not(:disabled) { transform: scale(0.92); }
.shutter:disabled { opacity: 0.35; cursor: default; }

/* ---------- controls ---------- */
.controls {
  background: var(--panel); border-radius: var(--radius); padding: 14px;
  display: flex; flex-direction: column; gap: 12px; border: 1px solid var(--line);
}
.presets { display: flex; gap: 6px; flex-wrap: wrap; }
.preset {
  background: transparent; border: 1px solid var(--line); border-radius: 99px;
  padding: 5px 12px; font-size: 0.78rem; color: var(--muted); cursor: pointer;
}
.preset:hover { color: var(--text); }
.preset[aria-pressed="true"] { color: #111; background: var(--text); border-color: var(--text); }

.sliders { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px 14px; }
.slider { display: flex; flex-direction: column; gap: 6px; font-size: 0.74rem; color: var(--muted); }
.slider span { display: flex; justify-content: space-between; }
.slider output { font-variant-numeric: tabular-nums; color: var(--text); }
.slider input[type="range"] { width: 100%; accent-color: var(--text); }

.toggles { display: flex; gap: 16px; align-items: center; }
.toggle { display: flex; align-items: center; gap: 6px; font-size: 0.78rem; color: var(--text); cursor: pointer; }
.toggle input { accent-color: var(--text); }
.link-btn { margin-left: auto; background: none; border: 0; color: var(--muted); font-size: 0.78rem; cursor: pointer; text-decoration: underline; }
.link-btn:hover { color: var(--text); }

/* ---------- gallery ---------- */
.gallery { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.gallery:empty { display: none; }
.gallery img {
  width: 72px; height: 72px; object-fit: cover; border-radius: 10px;
  border: 1px solid var(--line); cursor: pointer; flex-shrink: 0;
}
.gallery img:hover { border-color: var(--text); }

.note { text-align: center; font-size: 0.72rem; color: var(--muted); }
.note.keys { margin-top: -8px; opacity: 0.7; }
@media (hover: none) { .note.keys { display: none; } }

.version {
  position: fixed; right: 10px; bottom: calc(8px + env(safe-area-inset-bottom));
  font-size: 0.68rem; color: var(--muted); opacity: 0.6;
  font-variant-numeric: tabular-nums; pointer-events: none; user-select: none;
}

.hidden { display: none !important; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: #111; padding: 9px 16px; border-radius: 99px;
  font-size: 0.82rem; z-index: 80; max-width: 90vw;
}

/* ---------- full-screen viewer ---------- */
.viewer {
  position: fixed; inset: 0; z-index: 50; background: rgba(8,8,9,0.96);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  flex-direction: column; gap: 16px;
}
.viewer img { max-width: 100%; max-height: 72vh; border-radius: 10px; }
.viewer-bar { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; align-items: center; max-width: 100%; }
.viewer-count { color: var(--muted); font-size: 0.78rem; min-width: 48px; text-align: center; font-variant-numeric: tabular-nums; }

/* ---------- phones: full-height layout, controls pinned to the bottom ---------- */
@media (max-width: 640px) {
  html { height: 100%; }
  body { padding: 0; min-height: 100dvh; }
  .app {
    max-width: none; min-height: 100dvh; gap: 12px;
    padding: calc(10px + env(safe-area-inset-top)) 12px 0;
  }
  .topbar { order: 0; }
  .viewfinder { order: 1; border-radius: 12px; }
  .gallery { order: 2; }
  /* Adjust opens as a sheet above the shutter bar: the page never grows,
     and a tall panel scrolls inside itself instead of the whole view */
  .controls {
    --bar-h: calc(101px + env(safe-area-inset-bottom));
    position: fixed; left: 12px; right: 12px; bottom: calc(var(--bar-h) + 8px); z-index: 15;
    max-width: 456px; margin: 0 auto;
    max-height: min(46dvh, calc(100dvh - var(--bar-h) - 72px)); overflow-y: auto;
    overscroll-behavior: contain; box-shadow: 0 8px 28px rgba(0,0,0,0.55);
  }
  .note { order: 4; }
  .shutterbar {
    order: 5; margin: auto -12px 0; position: sticky; bottom: 0; z-index: 20;
    padding: 12px 18px calc(12px + env(safe-area-inset-bottom));
    background: rgba(14,14,15,0.92); backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
  }
  .icon-btn { min-width: 52px; height: 52px; }
  .text-btn { min-width: 52px; }
  .shutter { width: 76px; height: 76px; }
  .sliders { grid-template-columns: 1fr 1fr; gap: 12px 18px; }
  .slider input[type="range"] { height: 28px; }
  .preset { padding: 8px 14px; }
  .toggle { padding: 4px 0; }
}

.select-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 0.78rem; color: var(--muted); }
.select-row select {
  flex: 1; min-width: 0; max-width: 70%; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 8px; font: inherit;
}
