/* ──────────────────────────────────────────────────────────
   DICA — Y2K Film Camera
   Apple Camera 풍 플랫 다크 · 사진/영상 · 가로·세로 완벽 대응
   ────────────────────────────────────────────────────────── */

:root {
  --accent: #ffd400;            /* iOS 카메라 선택 옐로 */
  --rec: #ff3b30;
  --stamp: #ff7a18;
  --dim: rgba(255, 255, 255, 0.55);
  --dock: #000;
  --st: env(safe-area-inset-top, 0px);
  --sb: env(safe-area-inset-bottom, 0px);
  --sl: env(safe-area-inset-left, 0px);
  --sr: env(safe-area-inset-right, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  height: 100%; background: #000; color: #fff; overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Pretendard",
               "Apple SD Gothic Neo", system-ui, sans-serif;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  overscroll-behavior: none;
}
.hidden { display: none !important; }
button { font-family: inherit; color: #fff; background: none; border: none; }

/* ── 전체 골격 ── */
.cam { position: fixed; inset: 0; display: flex; flex-direction: column; background: #000; }
.stage { position: relative; flex: 1; overflow: hidden; background: #000; touch-action: none; }
.stage video, .stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.stage video { object-fit: cover; z-index: 0; }   /* 디코딩용 베이스 */
.stage canvas { z-index: 1; }                       /* 필터 구운 뷰파인더 */

/* ── 상단 HUD ── */
.hud-top {
  position: absolute; top: 0; left: 0; right: 0; z-index: 3;
  display: flex; justify-content: center;
  padding: calc(var(--st) + 12px) 16px 12px;
  pointer-events: none;
}
.rec-timer {
  display: inline-flex; align-items: center; gap: 7px;
  background: rgba(0, 0, 0, 0.5); border-radius: 999px;
  padding: 5px 12px; font-variant-numeric: tabular-nums;
  font-size: 0.82rem; font-weight: 600; letter-spacing: 0.04em;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.rec-timer i { width: 8px; height: 8px; border-radius: 50%; background: var(--rec); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.25; } }

.flash { position: absolute; inset: 0; z-index: 4; background: #fff; opacity: 0; pointer-events: none; }
.flash.fire { animation: flash 0.3s ease-out; }
@keyframes flash { 0% { opacity: 0.9; } 100% { opacity: 0; } }

/* 배율 버튼 클러스터 (0.5×/1×/2×/3×) — iOS식 */
.zoom-cluster {
  display: flex; align-items: center; justify-content: center; gap: 4px;
  background: rgba(0, 0, 0, 0.4); border-radius: 999px; padding: 4px;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border: 0.5px solid rgba(255, 255, 255, 0.14);
  transition: opacity 0.2s;
}
.zoom-cluster.dim { opacity: 0.25; }
.zc-btn {
  min-width: 30px; height: 30px; padding: 0 7px; border-radius: 999px;
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.01em;
  color: rgba(255, 255, 255, 0.72); background: transparent;
  font-variant-numeric: tabular-nums; touch-action: manipulation;
  transition: color 0.18s, background 0.18s, transform 0.18s;
}
.zc-btn.active { color: var(--accent); background: rgba(255, 255, 255, 0.14); transform: scale(1.06); }

/* 줌 다이얼 (핀치/드래그 시 등장) — 반투명 패널 위 곡선 눈금 */
.zoom-dial {
  position: absolute; z-index: 7; left: 50%; bottom: 10px; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 12px 6px; border-radius: 20px;
  background: rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(7px); -webkit-backdrop-filter: blur(7px);
  opacity: 0; pointer-events: none; transition: opacity 0.2s ease;
}
.zoom-dial.show { opacity: 1; pointer-events: auto; }
.dial-val {
  font-size: 1.5rem; font-weight: 800; color: var(--accent);
  font-variant-numeric: tabular-nums; text-shadow: 0 1px 8px rgba(0, 0, 0, 0.7);
}
.dial-canvas { display: block; touch-action: none; }   /* 표시 크기는 sizeDial()이 지정 */

/* ── 도크(컨트롤) — 세로: 하단 바 ── */
.dock {
  background: var(--dock);
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  padding: 12px 0 calc(var(--sb) + 14px);
}
.dock-left { display: flex; flex-direction: column; align-items: center; gap: 14px; width: 100%; }
.ctrl-mid { display: flex; align-items: center; justify-content: center; gap: 14px; width: 100%; max-width: 380px; padding: 0 14px; }
.ctrl-mid .preset-wheel { flex: 1 1 auto; max-width: 200px; }
.ctrl-mid .zoom-cluster { flex: 0 0 auto; }

/* 모드 스위치 */
.mode-switch { display: flex; gap: 22px; }
.m-btn {
  font-size: 0.78rem; font-weight: 700; letter-spacing: 0.12em;
  color: var(--dim); padding: 4px 2px; transition: color 0.2s;
}
.m-btn.active { color: var(--accent); }

/* 프리셋 휠 */
.preset-wheel {
  position: relative; width: 100%; max-width: 360px; height: 30px; overflow: hidden;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 18%, #000 82%, transparent);
          mask-image: linear-gradient(90deg, transparent, #000 18%, #000 82%, transparent);
}
.pw-track {
  position: absolute; top: 0; left: 50%; height: 100%;
  display: flex; align-items: center;
  transition: transform 0.28s cubic-bezier(0.22, 0.61, 0.36, 1);
  will-change: transform;
}
.pw-item {
  flex: 0 0 auto; padding: 0 18px; height: 100%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.72rem; font-weight: 600; letter-spacing: 0.14em; white-space: nowrap;
  color: var(--dim); transition: color 0.2s, transform 0.2s;
}
.pw-item.active { color: var(--accent); transform: scale(1.08); }
.pw-marker {
  position: absolute; left: 50%; bottom: -1px; transform: translateX(-50%);
  width: 4px; height: 4px; border-radius: 50%; background: var(--accent); opacity: 0.9;
}

/* 셔터 행 */
.shutter-row {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; max-width: 360px; padding: 0 36px;
}
.shutter {
  width: 74px; height: 74px; border-radius: 50%;
  border: 4px solid #fff; display: grid; place-items: center;
  transition: transform 0.1s;
}
.shutter:active { transform: scale(0.96); }
.s-core {
  width: 60px; height: 60px; border-radius: 50%; background: #fff;
  transition: width 0.22s, height 0.22s, border-radius 0.22s, background 0.22s;
}
.shutter.video .s-core { background: var(--rec); }
.shutter.recording { border-color: rgba(255, 59, 48, 0.45); }
.shutter.recording .s-core { width: 26px; height: 26px; border-radius: 7px; background: var(--rec); }

.round-btn, .thumb-btn {
  width: 46px; height: 46px; border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, 0.12); color: #fff;
  transition: transform 0.12s, background 0.2s;
}
.round-btn:active, .thumb-btn:active { transform: scale(0.9); }
.thumb-btn { background-size: cover; background-position: center; border: 1px solid rgba(255, 255, 255, 0.25); }

/* ──────────────────────────────────────────────
   가로 모드 — 뷰파인더 풀스크린 + 우측 세로 오버레이 컨트롤(애플 카메라식)
   ────────────────────────────────────────────── */
@media (orientation: landscape) {
  .cam { display: block; }                          /* flex 해제 */
  .stage { position: absolute; inset: 0; }          /* 뷰파인더가 화면 전체(100vw×100vh)를 채움 */

  .dock {                                            /* 우측 오버레이(자리 차지 X): [좌:모드·프리셋·배율] [우:셔터] */
    position: absolute; top: 0; right: 0; bottom: 0; z-index: 6;
    width: auto; height: auto;
    flex-direction: row; align-items: center; justify-content: flex-end; gap: 16px;
    padding: 14px calc(var(--sr) + 12px) 14px 18px;
    background: linear-gradient(to left, rgba(0, 0, 0, 0.62) 48%, rgba(0, 0, 0, 0));
  }
  .dock-left { flex-direction: column; align-items: center; gap: 16px; width: auto; }
  .ctrl-mid { flex-direction: column; align-items: center; gap: 12px; width: auto; max-width: none; padding: 0; }
  .ctrl-mid .preset-wheel { flex: 0 0 auto; max-width: none; }
  .mode-switch { flex-direction: column; gap: 12px; }
  .zoom-cluster { flex-direction: column; }

  /* 프리셋: 세로 휠 */
  .preset-wheel.vertical {
    width: 110px; height: 128px; max-width: none;
    -webkit-mask-image: linear-gradient(180deg, transparent, #000 18%, #000 82%, transparent);
            mask-image: linear-gradient(180deg, transparent, #000 18%, #000 82%, transparent);
  }
  .preset-wheel.vertical .pw-track { flex-direction: column; left: 0; top: 50%; width: 100%; height: auto; }
  .preset-wheel.vertical .pw-item { padding: 7px 0; height: auto; }
  .preset-wheel.vertical .pw-marker { left: -1px; bottom: auto; top: 50%; transform: translateY(-50%); }

  /* 우측 셔터 열: 카메라전환·셔터·앨범 세로 */
  .shutter-row { flex-direction: column; width: auto; max-width: none; padding: 0; gap: 22px; }

  /* 다이얼: 좌측 영역 하단 중앙(우측 도크와 안 겹침) */
  .zoom-dial { left: calc(50% - 90px); bottom: calc(var(--sb) + 12px); }
  .ver { left: calc(var(--sl) + 12px); }
}

/* 빌드 버전 뱃지(캐시 확인용) */
.ver {
  position: absolute; left: calc(var(--sl) + 10px); bottom: calc(var(--sb) + 8px); z-index: 3;
  font-size: 9px; letter-spacing: 0.1em; color: rgba(255, 255, 255, 0.42); pointer-events: none;
}

/* ──────────────────────────────────────────────
   권한 프라이머 (최초 1회)
   ────────────────────────────────────────────── */
.perm {
  position: absolute; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center; padding: 24px;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(20px) saturate(1.2); -webkit-backdrop-filter: blur(20px) saturate(1.2);
}
.perm-card {
  width: 100%; max-width: 340px; text-align: center;
  background: rgba(28, 28, 30, 0.72); border: 0.5px solid rgba(255, 255, 255, 0.14);
  border-radius: 26px; padding: 30px 26px 24px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}
.perm-icon {
  width: 64px; height: 64px; margin: 0 auto 16px; border-radius: 18px;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(160deg, #3a3a3c, #1c1c1e);
  border: 0.5px solid rgba(255, 255, 255, 0.16);
}
.perm-card h1 { font-size: 1.22rem; font-weight: 700; letter-spacing: -0.01em; }
.perm-card p { margin-top: 10px; font-size: 0.9rem; line-height: 1.55; color: rgba(255, 255, 255, 0.7); }
.perm-btn {
  margin-top: 22px; width: 100%; padding: 0.95rem; border-radius: 14px;
  background: #fff; color: #000; font-size: 1rem; font-weight: 600;
  transition: transform 0.12s, opacity 0.2s;
}
.perm-btn:active { transform: scale(0.97); }
.perm-err { margin-top: 12px; min-height: 1em; font-size: 0.82rem; color: #ff6b6b; }

/* ──────────────────────────────────────────────
   결과 미리보기
   ────────────────────────────────────────────── */
.result {
  position: fixed; inset: 0; z-index: 30; background: #000;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: calc(var(--st) + 16px) 16px calc(var(--sb) + 16px);
}
.result-media { flex: 1; display: flex; align-items: center; justify-content: center; width: 100%; min-height: 0; }
.result-img, .result-vid { max-width: 100%; max-height: 100%; border-radius: 12px; box-shadow: 0 16px 50px rgba(0, 0, 0, 0.6); }
.result-bar { display: flex; gap: 12px; width: 100%; max-width: 440px; margin-top: 18px; }
.ghost-btn, .primary-btn {
  flex: 1; padding: 0.95rem 0; border-radius: 14px; font-size: 1rem; font-weight: 600;
  transition: transform 0.12s;
}
.ghost-btn { background: rgba(255, 255, 255, 0.12); }
.primary-btn { background: #fff; color: #000; }
.ghost-btn:active, .primary-btn:active { transform: scale(0.97); }
.save-hint { margin-top: 12px; font-size: 0.78rem; color: var(--dim); text-align: center; line-height: 1.5; max-width: 440px; }
.save-hint b { color: #fff; }
