:root {
  --bg: #0b0b0c;
  --panel: #161618;
  --line: #2a2a2e;
  --text: #f4f1ec;
  --muted: #9a958f;
  --accent: #ff8a3d;
  --stamp: #ff9a3c;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }

#app {
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* 영상 요소는 화면에 보이지 않게 두되 iOS가 디코딩을 멈추지 않도록 DOM에 남겨둔다 */
#video { position: fixed; left: 0; top: 0; width: 2px; height: 2px; opacity: 0; pointer-events: none; }

/* ── 상단 바 ── */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: calc(10px + var(--safe-top)) 16px 10px;
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 56px;
  height: 34px;
  justify-content: center;
  padding: 0 12px;
  border-radius: 17px;
  background: var(--panel);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .02em;
}
.pill svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.pill.on { background: var(--accent); color: #1a0e05; }

/* ── 뷰파인더 ── */
.stage {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
}
.viewfinder {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  background: #000;
  touch-action: pan-y;
}
#view { display: block; width: 100%; height: 100%; }

.date-stamp {
  position: absolute;
  right: 5%;
  bottom: 3.2%;
  color: var(--stamp);
  font-family: "Courier New", ui-monospace, monospace;
  font-weight: 700;
  line-height: 1;
  letter-spacing: .04em;
  text-shadow: 0 0 .35em rgba(255, 110, 20, .85);
  pointer-events: none;
}

.filter-toast {
  position: absolute;
  left: 50%;
  top: 14px;
  transform: translate(-50%, -6px);
  padding: 6px 14px;
  border-radius: 14px;
  background: rgba(0, 0, 0, .45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-size: 14px;
  font-weight: 700;
  opacity: 0;
  transition: opacity .25s, transform .25s;
  pointer-events: none;
}
.filter-toast.show { opacity: 1; transform: translate(-50%, 0); }

.countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 96px;
  font-weight: 800;
  text-shadow: 0 2px 24px rgba(0, 0, 0, .5);
  pointer-events: none;
}

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

.cam-msg {
  position: absolute;
  inset: 0 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
  padding: 24px;
}
.cam-msg p { margin: 0; color: var(--muted); line-height: 1.6; white-space: pre-line; word-break: keep-all; }
.cam-msg-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 46px;
  padding: 0 20px;
  border-radius: 23px;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
}
.btn.primary { background: var(--accent); color: #1a0e05; }
.btn.ghost { background: var(--panel); border: 1px solid var(--line); }

/* ── 하단 컨트롤 ── */
.controls { padding: 10px 0 calc(14px + var(--safe-bottom)); }

.intensity {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px 8px;
  font-size: 12px;
  color: var(--muted);
}
.intensity.off { visibility: hidden; }
.intensity input { flex: 1; accent-color: var(--accent); height: 24px; }
.intensity output { width: 28px; text-align: right; font-variant-numeric: tabular-nums; }

.filter-strip {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  padding: 4px 16px 10px;
  scrollbar-width: none;
}
.filter-strip::-webkit-scrollbar { display: none; }

.filter-item {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  scroll-snap-align: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}
.filter-item canvas {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  background: var(--panel);
  outline: 2px solid transparent;
  outline-offset: 2px;
  transition: outline-color .15s;
}
.filter-item[aria-selected="true"] { color: var(--text); }
.filter-item[aria-selected="true"] canvas { outline-color: var(--accent); }

.shutter-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 6px 28px 0;
}
.last-thumb {
  justify-self: start;
  width: 46px;
  height: 46px;
  border-radius: 10px;
  background: var(--panel) center / cover no-repeat;
  border: 2px solid var(--line);
}
.last-thumb:disabled { opacity: .4; cursor: default; }

.shutter {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  border: 4px solid var(--text);
  display: grid;
  place-items: center;
}
.shutter span {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--text);
  transition: transform .12s, background .2s;
}
.shutter:active span { transform: scale(.88); }
.shutter.counting span { background: var(--accent); transform: scale(.6); border-radius: 12px; }

.round-btn {
  justify-self: end;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--panel);
  display: grid;
  place-items: center;
}
.round-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linejoin: round; stroke-linecap: round; }
.round-btn:disabled { opacity: .35; }

/* ── 결과 화면 ── */
.result {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
  gap: 16px;
}
.result-img-wrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
.result img { max-width: 100%; max-height: 100%; border-radius: 12px; display: block; -webkit-touch-callout: default; }
.result-bar { display: flex; gap: 10px; max-width: 488px; width: 100%; margin: 0 auto; }
.result-bar .btn { flex: 1; }
.result-hint { margin: 0; text-align: center; font-size: 12px; color: var(--muted); min-height: 1em; }
