*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --coral:     #FF6B6B;
  --coral-mid: #FF8C69;
  --coral-lt:  #FFD4C4;
  --coral-bg:  #FFF0EB;
  --page-bg:   #FDF6EF;
  --muted:     #C8ADA0;
  --card-bg:   #FFFFFF;
  --text:      #3D2B25;
}

html, body {
  height: 100%;
  background: var(--page-bg);
  font-family: 'DM Sans', sans-serif;
  color: var(--text);
  overflow: hidden;
}

/* Dot pattern background */
body::before {
  content: '';
  position: fixed; inset: 0; z-index: 0;
  background-image: radial-gradient(circle, #E8B4A045 1.5px, transparent 1.5px);
  background-size: 28px 28px;
  pointer-events: none;
}

/* ── Utility ────────────────────────────── */
.hidden { display: none !important; }
.screen {
  position: fixed; inset: 0; z-index: 1;
  display: flex; flex-direction: column;
  align-items: center;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.screen::-webkit-scrollbar { width: 4px; }
.screen::-webkit-scrollbar-thumb { background: var(--coral-lt); border-radius: 4px; }

/* ── Animations ─────────────────────────── */
@keyframes fadeIn  { from { opacity: 0 } to { opacity: 1 } }
@keyframes slideUp { from { opacity: 0; transform: translateY(28px) } to { opacity: 1; transform: translateY(0) } }
@keyframes blink   { 50% { opacity: 0 } }
@keyframes spin    { to { transform: rotate(360deg) } }
@keyframes pulse   { 0%,100% { box-shadow: 0 6px 20px #FF6B6B40 } 50% { box-shadow: 0 10px 32px #FF6B6B70 } }
@keyframes thumbPulse { 0%,100% { box-shadow: 0 0 0 3px #FF6B6B25 } 50% { box-shadow: 0 0 0 6px #FF6B6B15 } }
@keyframes countPop {
  0%   { transform: scale(1.5); opacity: 0 }
  20%  { transform: scale(1);   opacity: 1 }
  80%  { transform: scale(1);   opacity: 1 }
  100% { transform: scale(.65); opacity: 0 }
}
@keyframes shutterFlash { 0% { opacity: .85 } 100% { opacity: 0 } }

.anim-fade  { animation: fadeIn  .35s ease forwards }
.anim-slide { animation: slideUp .45s cubic-bezier(.16,1,.3,1) forwards }

/* ── Tag pill ───────────────────────────── */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--coral-bg); color: #C95A3A;
  font-size: 11px; font-weight: 700; letter-spacing: .06em;
  padding: 4px 12px; border-radius: 100px;
  border: 1.5px solid var(--coral-lt);
}

/* ── Blink dot ──────────────────────────── */
.dot-blink {
  width: 7px; height: 7px; border-radius: 50%;
  background: #FF4B4B;
  animation: blink 1.3s step-start infinite;
  display: inline-block;
}

/* ── Strip thumbs ───────────────────────── */
.thumb-row { display: flex; align-items: center; gap: 8px; }
.thumb {
  width: 60px; height: 36px; border-radius: 9px;
  border: 2px solid var(--coral-lt); background: var(--coral-bg);
  overflow: hidden; display: flex; align-items: center; justify-content: center;
  font-family: 'Nunito', sans-serif; font-size: 11px; font-weight: 800; color: var(--muted);
  transition: border-color .3s, box-shadow .3s; flex-shrink: 0;
}
.thumb.taken   { border-color: var(--coral-mid); box-shadow: 0 0 0 3px #FF8C6930 }
.thumb.active  { border-color: var(--coral); box-shadow: 0 0 0 3px #FF6B6B25; animation: thumbPulse 1.2s ease-in-out infinite }
.thumb img     { width: 100%; height: 100%; object-fit: cover }
.thumb-sep     { color: var(--coral-lt); font-size: 13px }

/* ── Camera frame ───────────────────────── */
.cam-wrap {
  width: 100%; position: relative;
  border-radius: 18px;
  border: 3px solid var(--coral-lt);
  box-shadow: 0 6px 32px #FF8C6918;
  overflow: hidden;
  background: var(--coral-bg);
}
.cam-wrap video { display: block; width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1) }

/* Corner decorations */
.corner { position: absolute; width: 18px; height: 18px; opacity: .55 }
.corner-tl { top: 10px; left: 10px;  border-top: 3px solid var(--coral-mid); border-left:  3px solid var(--coral-mid); border-radius: 4px 0 0 0 }
.corner-tr { top: 10px; right: 10px; border-top: 3px solid var(--coral-mid); border-right: 3px solid var(--coral-mid); border-radius: 0 4px 0 0 }
.corner-bl { bottom: 10px; left: 10px;  border-bottom: 3px solid var(--coral-mid); border-left:  3px solid var(--coral-mid); border-radius: 0 0 0 4px }
.corner-br { bottom: 10px; right: 10px; border-bottom: 3px solid var(--coral-mid); border-right: 3px solid var(--coral-mid); border-radius: 0 0 4px 0 }

/* HUD badges */
.hud {
  position: absolute; z-index: 5;
  background: rgba(255,255,255,.82); backdrop-filter: blur(4px);
  border-radius: 8px; padding: 4px 9px;
  font-family: 'Nunito', sans-serif; font-weight: 700; font-size: 11px; color: #C95A3A;
}
.hud-ts { color: #999; font-family: 'DM Sans', sans-serif; font-weight: 500 }

/* Error state */
#cameraError {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  background: #FFF5F0; border-radius: 16px;
}
.err-icon {
  width: 60px; height: 60px; border-radius: 16px;
  background: var(--coral-bg); display: flex; align-items: center; justify-content: center; font-size: 26px;
}

/* Countdown overlay */
#countdownOverlay {
  position: absolute; inset: 0; z-index: 20;
  background: rgba(255,245,240,.75); backdrop-filter: blur(3px);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
}
.countdown-num {
  font-family: 'Nunito', sans-serif; font-weight: 900;
  font-size: clamp(5rem, 22vw, 9rem);
  color: var(--coral); text-shadow: 0 4px 16px #FF6B6B35;
  animation: countPop 1s cubic-bezier(.16,1,.3,1) forwards;
}

/* ── Capture button ─────────────────────── */
.btn-capture {
  width: 86px; height: 86px; border-radius: 50%;
  background: linear-gradient(135deg, #FF8C69, #FF6B6B);
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: #fff; position: relative;
  animation: pulse 2s ease-in-out infinite;
  transition: transform .15s;
  flex-shrink: 0;
}
.btn-capture:active { transform: scale(.94) }
.btn-capture::before {
  content: ''; position: absolute; inset: -6px;
  border: 2px dashed #FF8C6950; border-radius: 50%;
}
.btn-capture svg { width: 36px; height: 36px }

/* ── Spinner ────────────────────────────── */
.spinner {
  width: 44px; height: 44px; border-radius: 50%;
  border: 3px solid #FFE0D5; border-top-color: var(--coral-mid);
  animation: spin .7s linear infinite;
}

/* ── Result: photo strip ────────────────── */
.strip {
  background: var(--card-bg); border-radius: 18px;
  box-shadow: 0 6px 32px #0000001A; overflow: hidden;
}
.strip-slot { border-bottom: 3px solid var(--page-bg); position: relative }
.strip-slot:last-of-type { border-bottom: none }
.strip-slot img { display: block; width: 100%; aspect-ratio: 565/585; object-fit: cover }
.slot-num {
  position: absolute; top: 7px; left: 9px;
  background: rgba(255,255,255,.88); border-radius: 6px;
  padding: 2px 8px; font-family: 'Nunito',sans-serif;
  font-size: 10px; font-weight: 800; color: var(--coral-mid);
}
.strip-footer {
  background: var(--coral-bg); padding: 8px 14px;
  display: flex; align-items: center; justify-content: space-between;
}

/* ── QR container ───────────────────────── */
.qr-box {
  background: var(--card-bg); border-radius: 16px;
  border: 2px dashed var(--coral-lt); padding: 14px;
}
.qr-box img { display: block; width: 160px; height: 160px; object-fit: contain }

/* ── Meta card ──────────────────────────── */
.meta-card {
  background: var(--card-bg); border-radius: 16px;
  border: 1.5px solid #FFE8DE; padding: 12px 16px;
  width: 100%;
}
.meta-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 0; border-bottom: 1px solid #FFF0EB;
  font-size: 12px;
}
.meta-row:last-child { border-bottom: none }
.meta-label { color: var(--muted) }
.meta-val { color: var(--coral-mid); font-weight: 600; font-size: 12px; text-align: right; max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap }

/* ── Buttons ────────────────────────────── */
.btn-primary {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 14px;
  background: var(--coral); color: #fff;
  font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 14px;
  border: none; border-radius: 100px; cursor: pointer;
  box-shadow: 0 4px 16px #FF6B6B35; transition: transform .15s, box-shadow .15s;
}
.btn-primary:active { transform: scale(.97) }

.btn-outline {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  width: 100%; padding: 12px;
  background: var(--coral-bg); color: var(--coral);
  font-family: 'Nunito', sans-serif; font-weight: 700; font-size: 13px;
  border: 2px solid var(--coral-lt); border-radius: 100px; cursor: pointer;
  text-decoration: none; transition: background .15s;
}
.btn-outline:hover { background: #FFE4DA }
.btn-retry {
  padding: 9px 20px; background: var(--coral-mid); color: #fff;
  border: none; border-radius: 100px; cursor: pointer;
  font-size: 13px; font-weight: 700; font-family: 'Nunito', sans-serif;
}

/* ── Shutter flash ──────────────────────── */
.shutter-flash {
  position: fixed; inset: 0; z-index: 9000;
  background: #fff;
  animation: shutterFlash .35s ease-out forwards;
  pointer-events: none;
}

/* ══════════════════════════════════════════
   SCREEN: CAMERA
══════════════════════════════════════════ */
#screenCamera {
  justify-content: space-between;
  padding: env(safe-area-inset-top, 16px) 16px env(safe-area-inset-bottom, 16px);
}

.cam-header { display: flex; flex-direction: column; align-items: center; gap: 8px; padding-top: 8px; width: 100% }

.cam-title {
  font-family: 'Nunito', sans-serif; font-weight: 900;
  font-size: clamp(26px, 7vw, 42px);
  color: var(--coral); line-height: 1;
}
.cam-sub { font-size: 11px; font-weight: 600; color: var(--muted); letter-spacing: .14em }

.cam-viewport { width: 100%; flex: 1; display: flex; align-items: center; padding: 5px 0 }

.cam-aspect { width: 100%; max-width: 400px;margin: 0 auto; aspect-ratio: 565 / 585; }

.cam-footer { display: flex; flex-direction: column; align-items: center; gap: 10px; padding-bottom: 8px; width: 100% }
.cam-instruction { font-size: 12px; font-weight: 500; color: var(--muted); letter-spacing: .07em; text-align: center }
.cam-btn-label {
  font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 11px;
  color: var(--coral-mid); letter-spacing: .1em; margin-top: 4px;
}

/* ══════════════════════════════════════════
   SCREEN: LOADING
══════════════════════════════════════════ */
#screenLoading { justify-content: center; align-items: center }
.loading-card {
  background: var(--card-bg); border-radius: 24px;
  padding: 40px 36px; text-align: center;
  box-shadow: 0 6px 32px #FF8C6912;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  max-width: 300px; width: 90%;
}

/* ══════════════════════════════════════════
   SCREEN: RESULT
══════════════════════════════════════════ */
#screenResult { justify-content: flex-start; align-items: center; padding: 24px 16px 32px }

.result-header { text-align: center; margin-bottom: 20px }
.result-title {
  font-family: 'Nunito', sans-serif; font-weight: 900;
  font-size: clamp(20px, 6vw, 28px); color: var(--coral);
}
.result-sub { font-size: 11px; font-weight: 600; color: var(--muted); letter-spacing: .1em; margin-top: 4px }

/* Two-column layout on wider screens */
.result-body {
  display: flex; flex-direction: column; align-items: center;
  gap: 24px; width: 100%; max-width: 880px;
}

.strip-col { width: 100%; max-width: 220px }
.actions-col {
  width: 100%; max-width: 340px;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}

@media (min-width: 700px) {
  .result-body {
    flex-direction: row; align-items: flex-start; justify-content: center;
  }
  .strip-col, .actions-col { max-width: 320px }
}

@media (min-width: 480px) {
  .thumb { width: 72px; height: 44px }
  .btn-capture { width: 100px; height: 100px }
  .btn-capture svg { width: 42px; height: 42px }
}

@media (max-height: 680px) {
  .cam-header { gap: 5px; padding-top: 4px }
  .cam-viewport { padding: 4px 0 }
  .cam-footer { gap: 6px; padding-bottom: 4px }
  .btn-capture { width: 76px; height: 76px }
}




/* ── Frame Selection Grid ── */
.frame-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 20px;
  width: 100%;
  max-width: 600px;
  padding: 20px;
}
.frame-item {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 10px;
  border: 3px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}
.frame-item:hover { transform: translateY(-5px); border-color: var(--coral-lt); }
.frame-item.active { border-color: var(--coral); box-shadow: 0 8px 24px #FF6B6B30; }
.frame-item img {
  width: 100%;
  aspect-ratio: 1/3; /* Sesuaikan dengan rasio photostrip */
  object-fit: cover;
  border-radius: 8px;
  background: #eee;
  margin-bottom: 8px;
}
.frame-item span { font-size: 12px; font-weight: 700; color: var(--text); }