* { box-sizing: border-box; }
body {
  margin: 0; padding: 24px 16px 48px;
  font-family: system-ui, "Malgun Gothic", sans-serif;
  background: #17161c; color: #f2f0ef;
  display: flex; flex-direction: column; align-items: center; gap: 20px;
}
h1 { margin: 0; font-size: 26px; letter-spacing: 2px; }
h1 em { font-style: normal; color: #ff6b95; }

section { display: flex; flex-direction: column; align-items: center; gap: 14px; }

/* section 의 display:flex 가 hidden 속성(UA 의 display:none)을 이겨버린다 — 되돌려 놓는다 */
[hidden] { display: none; }

.cam-wrap {
  position: relative; width: min(90vw, 420px); aspect-ratio: 4/3;
  border-radius: 14px; overflow: hidden; background: #000;
}
/* video 는 렌더 소스일 뿐, 보이는 건 그 위에 겹친 #preview.
   ponytail: display:none 으로 숨기면 iOS 사파리가 video 디코딩을 멈춘다 — 그래서 깔고 덮는다.
   #preview, #count, #flash 가 DOM 순서상 뒤라 알아서 위에 그려진다 (z-index 불필요) */
#cam, #preview { position: absolute; inset: 0; width: 100%; height: 100%; }
#cam { object-fit: cover; }

#count {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 96px; font-weight: 700; color: #fff; text-shadow: 0 2px 12px #000;
  pointer-events: none;
}
#flash {
  position: absolute; inset: 0; background: #fff; opacity: 0;
  pointer-events: none;
}
#flash.on { animation: flash .35s ease-out; }
@keyframes flash { from { opacity: .9; } to { opacity: 0; } }

#msg { margin: 0; font-size: 14px; color: #a09da8; min-height: 20px; }

#flip {
  position: absolute; top: 10px; right: 10px;
  width: 38px; height: 38px; padding: 0; font-size: 18px; line-height: 1;
  background: rgba(0, 0, 0, .45); color: #fff; backdrop-filter: blur(4px);
}

#presets { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
#presets button {
  padding: 8px 16px; font-size: 14px;
  background: #2b2833; color: #cbc8d2; border: 1px solid #3d3947;
}
#presets button[aria-pressed="true"] { background: #ff6b95; color: #fff; border-color: #ff6b95; }

#hint { margin: 0; font-size: 12px; color: #7d7a86; }

button {
  font: inherit; font-size: 16px; padding: 12px 28px; border: 0;
  border-radius: 999px; background: #ff6b95; color: #fff; cursor: pointer;
}
button:disabled { background: #4a4752; color: #8b8794; cursor: default; }
button.ghost { background: transparent; color: #cbc8d2; border: 1px solid #4a4752; }

.row { display: flex; gap: 10px; }

#panel {
  width: min(90vw, 420px); padding: 12px 16px;
  background: #211f28; border-radius: 12px; font-size: 13px;
}
#panel summary { cursor: pointer; color: #cbc8d2; }
#controls { display: grid; gap: 8px; margin: 12px 0; }
#controls label {
  display: grid; grid-template-columns: 56px 1fr 44px; align-items: center; gap: 10px;
  color: #a09da8;
}
#controls input { width: 100%; accent-color: #ff6b95; }
#controls label:has(input:disabled) { opacity: .45; }
#controls output { text-align: right; font-variant-numeric: tabular-nums; }
#reset { font-size: 13px; padding: 6px 16px; }

/* 결과는 img 로 보여준다 — iOS 에서 길게 눌러 "사진에 추가" 가 되려면 canvas 로는 안 된다 */
#shot { width: min(70vw, 280px); height: auto; border-radius: 6px; display: block; cursor: pointer; }
#saveMsg { margin: 0; max-width: min(80vw, 320px); text-align: center;
           font-size: 13px; color: #ffb3c8; }

#caption {
  font: inherit; font-size: 15px; text-align: center; width: min(70vw, 280px);
  padding: 8px 12px; border-radius: 8px; border: 1px solid #4a4752;
  background: #211f28; color: #f2f0ef;
}

#frames { display: flex; gap: 10px; }
#frames button {
  width: 40px; height: 40px; padding: 0; border-radius: 50%;
  border: 2px solid transparent; outline-offset: 2px;
}
#frames button[aria-pressed="true"] { border-color: #ff6b95; }
