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

:root {
  --cream: #f5f0e8;
  --warm-white: #faf7f2;
  --blush: #d4a5a5;
  --sage: #8a9e8a;
  --charcoal: #2c2c2c;
  --gold: #b8965a;
  --gold-light: #d4b07a;
  --dark: #1a1a1a;
}

body {
  font-family: 'Jost', sans-serif;
  background: var(--dark);
  color: var(--cream);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

.screen { display: none; min-height: 100vh; flex-direction: column; }
.screen.active { display: flex; }

/* ── WELCOME ── */
#screen-welcome {
  background: var(--dark);
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 30px;
  position: relative;
  overflow: hidden;
}
#screen-welcome::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 60% 40% at 20% 10%, rgba(180,150,90,0.12) 0%, transparent 60%),
    radial-gradient(ellipse 50% 60% at 80% 90%, rgba(212,165,165,0.10) 0%, transparent 60%);
  pointer-events: none;
}
.welcome-ornament {
  font-size: 13px; letter-spacing: 0.35em; color: var(--gold);
  text-transform: uppercase; font-weight: 200; margin-bottom: 18px;
  opacity: 0; animation: fadeUp 0.8s ease forwards 0.2s;
}
.welcome-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: clamp(42px, 12vw, 68px); font-weight: 300; line-height: 1.1;
  color: var(--cream); opacity: 0; animation: fadeUp 0.8s ease forwards 0.4s;
}
.welcome-title em { font-style: italic; color: var(--gold-light); }
.welcome-date {
  font-size: 12px; letter-spacing: 0.3em; color: rgba(245,240,232,0.45);
  margin-top: 16px; font-weight: 200;
  opacity: 0; animation: fadeUp 0.8s ease forwards 0.6s;
}
.welcome-divider {
  width: 1px; height: 60px;
  background: linear-gradient(to bottom, transparent, var(--gold), transparent);
  margin: 32px auto; opacity: 0; animation: fadeUp 0.8s ease forwards 0.7s;
}
.welcome-message {
  font-family: 'Cormorant Garamond', serif; font-size: 18px;
  font-style: italic; font-weight: 300; color: rgba(245,240,232,0.7);
  max-width: 280px; line-height: 1.7;
  opacity: 0; animation: fadeUp 0.8s ease forwards 0.9s;
}
.welcome-shots {
  display: flex; align-items: center; gap: 10px; margin: 32px auto;
  opacity: 0; animation: fadeUp 0.8s ease forwards 1.0s;
}
.shot-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--gold); opacity: 0.3; }
.shot-dot.active { opacity: 1; }
.welcome-shots-label { font-size: 11px; letter-spacing: 0.25em; color: var(--gold); font-weight: 300; }
.btn-primary {
  background: transparent; border: 1px solid var(--gold); color: var(--gold);
  padding: 16px 44px; font-family: 'Jost', sans-serif; font-size: 11px;
  font-weight: 300; letter-spacing: 0.35em; text-transform: uppercase;
  cursor: pointer; transition: all 0.3s ease; position: relative; overflow: hidden;
  opacity: 0; animation: fadeUp 0.8s ease forwards 1.2s;
}
.btn-primary::before {
  content: ''; position: absolute; inset: 0; background: var(--gold);
  transform: scaleX(0); transform-origin: left; transition: transform 0.3s ease; z-index: -1;
}
.btn-primary:active::before { transform: scaleX(1); }
.btn-primary:active { color: var(--dark); }

/* ── CAMERA ── */
#screen-camera { background: #000; position: relative; overflow: hidden; }
#video-feed { width: 100%; height: 100vh; object-fit: cover; display: block; }
.camera-overlay { position: absolute; inset: 0; pointer-events: none; }
.frame-corner { position: absolute; width: 32px; height: 32px; border-color: rgba(245,240,232,0.6); border-style: solid; }
.frame-corner.tl { top: 60px; left: 20px; border-width: 1px 0 0 1px; }
.frame-corner.tr { top: 60px; right: 20px; border-width: 1px 1px 0 0; }
.frame-corner.bl { bottom: 160px; left: 20px; border-width: 0 0 1px 1px; }
.frame-corner.br { bottom: 160px; right: 20px; border-width: 0 1px 1px 0; }

.camera-top-bar {
  position: absolute; top: 0; left: 0; right: 0;
  padding: 16px 20px 12px; display: flex; align-items: center; justify-content: space-between;
  background: linear-gradient(to bottom, rgba(0,0,0,0.6), transparent);
}
.camera-title-small { font-family: 'Cormorant Garamond', serif; font-size: 14px; font-style: italic; color: rgba(245,240,232,0.8); font-weight: 300; }
.shots-counter { display: flex; align-items: baseline; gap: 4px; }
.shots-remaining { font-size: 28px; font-weight: 200; color: var(--cream); line-height: 1; font-family: 'Cormorant Garamond', serif; }
.shots-label { font-size: 9px; letter-spacing: 0.2em; color: rgba(245,240,232,0.5); font-weight: 300; }

.camera-bottom-bar {
  position: absolute; bottom: 0; left: 0; right: 0;
  padding: 20px 30px 40px; display: flex; align-items: center; justify-content: space-between;
  background: linear-gradient(to top, rgba(0,0,0,0.7), transparent);
  pointer-events: all;
}
.btn-gallery-thumb {
  width: 52px; height: 52px; border-radius: 4px; overflow: hidden;
  border: 1px solid rgba(245,240,232,0.3); cursor: pointer;
  background: rgba(255,255,255,0.1); transition: transform 0.2s; flex-shrink: 0;
}
.btn-gallery-thumb:active { transform: scale(0.95); }
.btn-gallery-thumb img { width: 100%; height: 100%; object-fit: cover; }
.shutter-btn {
  width: 72px; height: 72px; border-radius: 50%; background: transparent;
  border: 2px solid rgba(245,240,232,0.8); cursor: pointer; position: relative;
  transition: all 0.15s ease; -webkit-tap-highlight-color: transparent;
}
.shutter-btn::after {
  content: ''; position: absolute; inset: 6px; border-radius: 50%;
  background: var(--cream); transition: all 0.15s ease;
}
.shutter-btn:active { transform: scale(0.93); }
.shutter-btn:active::after { background: var(--gold-light); }
.shutter-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.btn-flip-cam {
  width: 52px; height: 52px; background: rgba(255,255,255,0.1);
  border: 1px solid rgba(245,240,232,0.3); border-radius: 50%;
  color: var(--cream); cursor: pointer; font-size: 20px;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.3s ease; flex-shrink: 0;
}
.btn-flip-cam:active { transform: rotate(180deg) scale(0.95); }
.flash-overlay {
  position: absolute; inset: 0; background: white;
  opacity: 0; pointer-events: none; transition: opacity 0.05s ease;
}
.flash-overlay.flash { opacity: 1; }
.film-strip {
  position: absolute; bottom: 108px; left: 0; right: 0; height: 2px;
  background: repeating-linear-gradient(90deg, rgba(184,150,90,0.4) 0px, rgba(184,150,90,0.4) 6px, transparent 6px, transparent 12px);
}

/* Upload status indicator */
.upload-status {
  position: absolute; top: 60px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px;
  background: rgba(0,0,0,0.6); padding: 6px 14px; border-radius: 20px;
  font-size: 10px; letter-spacing: 0.2em; color: rgba(245,240,232,0.7);
  font-weight: 300; opacity: 0; transition: opacity 0.3s;
  white-space: nowrap;
}
.upload-status.visible { opacity: 1; }
.upload-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--gold); animation: pulse 1s ease infinite;
}
.upload-dot.success { background: #6bbd6b; animation: none; }
.upload-dot.error { background: #bd6b6b; animation: none; }

/* ── GALLERY ── */
#screen-gallery { background: var(--dark); flex-direction: column; }
.gallery-header {
  padding: 20px 24px 16px; border-bottom: 1px solid rgba(245,240,232,0.08);
  display: flex; align-items: center; justify-content: space-between; flex-shrink: 0;
}
.gallery-header-title { font-family: 'Cormorant Garamond', serif; font-size: 22px; font-style: italic; font-weight: 300; color: var(--cream); }
.gallery-header-count { font-size: 11px; letter-spacing: 0.2em; color: var(--gold); font-weight: 300; }
.btn-back {
  background: none; border: none; color: var(--gold); font-family: 'Jost', sans-serif;
  font-size: 11px; letter-spacing: 0.25em; cursor: pointer; padding: 8px 0;
  display: flex; align-items: center; gap: 8px; font-weight: 300;
}
.gallery-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; overflow-y: auto; flex: 1; }
.gallery-item { aspect-ratio: 1; overflow: hidden; cursor: pointer; position: relative; }
.gallery-item img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform 0.3s ease; }
.gallery-item:active img { transform: scale(1.05); }
.gallery-item .upload-badge {
  position: absolute; bottom: 4px; right: 4px;
  width: 16px; height: 16px; border-radius: 50%; font-size: 9px;
  display: flex; align-items: center; justify-content: center;
}
.upload-badge.uploading { background: rgba(0,0,0,0.6); animation: pulse 1s ease infinite; }
.upload-badge.done { background: rgba(0,0,0,0.5); }
.upload-badge.failed { background: rgba(180,80,80,0.7); }
.gallery-empty {
  grid-column: 1/-1; text-align: center; padding: 80px 40px;
  color: rgba(245,240,232,0.3);
}
.gallery-empty-icon { font-size: 48px; margin-bottom: 16px; opacity: 0.3; }
.gallery-empty p { font-family: 'Cormorant Garamond', serif; font-size: 18px; font-style: italic; font-weight: 300; }
.gallery-footer {
  padding: 16px 24px 32px; border-top: 1px solid rgba(245,240,232,0.08);
  display: flex; gap: 12px; flex-shrink: 0;
}
.btn-secondary {
  flex: 1; background: transparent; border: 1px solid rgba(245,240,232,0.2);
  color: rgba(245,240,232,0.6); padding: 14px 20px; font-family: 'Jost', sans-serif;
  font-size: 10px; font-weight: 300; letter-spacing: 0.3em; text-transform: uppercase;
  cursor: pointer; transition: all 0.3s;
}
.btn-secondary:active { border-color: var(--gold); color: var(--gold); }

/* ── DONE ── */
#screen-done {
  background: var(--dark); align-items: center; justify-content: center;
  text-align: center; padding: 40px 30px; position: relative;
}
#screen-done::before {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(ellipse 80% 60% at 50% 50%, rgba(184,150,90,0.08) 0%, transparent 70%);
}
.done-icon { font-size: 52px; margin-bottom: 24px; animation: fadeUp 0.6s ease forwards; }
.done-title {
  font-family: 'Cormorant Garamond', serif; font-size: 36px; font-weight: 300;
  font-style: italic; color: var(--cream); margin-bottom: 12px;
  animation: fadeUp 0.6s ease forwards 0.2s; opacity: 0;
}
.done-message {
  font-size: 13px; font-weight: 200; letter-spacing: 0.1em; color: rgba(245,240,232,0.5);
  line-height: 1.8; max-width: 260px; margin: 0 auto 32px;
  animation: fadeUp 0.6s ease forwards 0.4s; opacity: 0;
}
.shot-strip { display: flex; gap: 3px; flex-wrap: wrap; justify-content: center; max-width: 240px; margin: 0 auto; }
.shot-pip { width: 8px; height: 8px; border-radius: 1px; background: rgba(184,150,90,0.2); transition: background 0.3s; }
.shot-pip.used { background: var(--gold); }

/* ── LIGHTBOX ── */
.lightbox {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.95);
  z-index: 100; align-items: center; justify-content: center; flex-direction: column;
}
.lightbox.active { display: flex; }
.lightbox img { max-width: 100%; max-height: 80vh; object-fit: contain; }
.lightbox-close { position: absolute; top: 20px; right: 20px; background: none; border: none; color: var(--cream); font-size: 24px; cursor: pointer; }
.lightbox-actions { display: flex; gap: 16px; margin-top: 20px; }
.lightbox-actions button {
  background: none; border: 1px solid rgba(245,240,232,0.3); color: var(--cream);
  padding: 10px 24px; font-family: 'Jost', sans-serif; font-size: 11px;
  letter-spacing: 0.25em; cursor: pointer; transition: all 0.3s;
}
.lightbox-actions button:active { border-color: var(--gold); color: var(--gold); }

/* ── PREVIEW ── */
#screen-preview {
  background: #000;
  position: relative;
  overflow: hidden;
  align-items: center;
  justify-content: center;
}

#preview-img {
  width: 100%;
  height: 100vh;
  object-fit: cover;
  display: block;
}

.preview-top-bar {
  position: absolute;
  top: 0; left: 0; right: 0;
  padding: 20px;
  display: flex;
  justify-content: center;
  background: linear-gradient(to bottom, rgba(0,0,0,0.55), transparent);
}

.preview-shots-badge {
  font-size: 11px;
  letter-spacing: 0.25em;
  color: var(--gold);
  font-weight: 300;
  text-transform: uppercase;
}

.preview-bottom-bar {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  padding: 24px 24px 44px;
  display: flex;
  gap: 14px;
  background: linear-gradient(to top, rgba(0,0,0,0.7), transparent);
}

.preview-btn {
  flex: 1;
  padding: 16px;
  font-family: 'Jost', sans-serif;
  font-size: 11px;
  font-weight: 300;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.2s ease;
  border-radius: 2px;
  -webkit-tap-highlight-color: transparent;
}

.preview-btn--retake {
  background: transparent;
  border: 1px solid rgba(245,240,232,0.35);
  color: rgba(245,240,232,0.7);
}
.preview-btn--retake:active {
  background: rgba(245,240,232,0.1);
}

.preview-btn--use {
  background: transparent;
  border: 1px solid var(--gold);
  color: var(--gold);
  position: relative;
  overflow: hidden;
}
.preview-btn--use::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--gold);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.25s ease;
  z-index: -1;
}
.preview-btn--use:active::before { transform: scaleX(1); }
.preview-btn--use:active { color: var(--dark); }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes pulse {
  0%, 100% { opacity: 1; } 50% { opacity: 0.3; }
}

canvas { display: none; }

:root {
  --bg:        #fafaf8;
  --surface:   #ffffff;
  --accent:    #c9908a;
  --accent-dk: #b07872;
  --text:      #2c2c2c;
  --muted:     #8a8a8a;
  --radius:    14px;
  --transition: 180ms ease;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ── Page layout ──────────────────────────────────────────────── */
.page {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 20px env(safe-area-inset-bottom, 20px);
  max-width: 480px;
  margin: 0 auto;
}

/* ── Header ───────────────────────────────────────────────────── */
.header {
  text-align: center;
  padding: 48px 0 28px;
}

.header__date {
  font-size: 12px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 500;
  margin-bottom: 8px;
}

.header__title {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: clamp(32px, 10vw, 44px);
  font-weight: 400;
  line-height: 1.15;
  color: var(--text);
  margin-bottom: 10px;
}

.header__sub {
  font-size: 15px;
  color: var(--muted);
  font-weight: 400;
}

/* ── Main ─────────────────────────────────────────────────────── */
.main {
  width: 100%;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  padding-bottom: 40px;
}

/* ── Counter pill ─────────────────────────────────────────────── */
.counter {
  background: var(--surface);
  border: 1.5px solid #ece8e6;
  border-radius: 999px;
  padding: 8px 20px;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.counter #counter-used {
  color: var(--accent);
  font-weight: 700;
}

/* ── Capture area ─────────────────────────────────────────────── */
.capture-area {
  width: 100%;
  display: flex;
  justify-content: center;
}

#file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* ── Buttons ──────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  padding: 15px 28px;
  min-height: 52px;
  transition: transform var(--transition), opacity var(--transition), background var(--transition);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.45; pointer-events: none; }

.btn--primary {
  background: var(--accent);
  color: #fff;
}
.btn--primary:active { background: var(--accent-dk); }

.btn--secondary {
  background: transparent;
  color: var(--accent);
  border: 1.5px solid var(--accent);
}

.btn--large {
  width: 100%;
  font-size: 18px;
  padding: 20px;
  min-height: 64px;
  border-radius: 18px;
}

.btn__icon { font-size: 22px; line-height: 1; }

/* ── Preview ──────────────────────────────────────────────────── */
.preview-area {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.preview-img {
  width: 100%;
  max-height: 60vh;
  object-fit: contain;
  border-radius: var(--radius);
  background: #f0eeec;
}

.preview-actions {
  display: flex;
  gap: 12px;
}

.preview-actions .btn {
  flex: 1;
}

/* ── Done state ───────────────────────────────────────────────── */
.done-area {
  text-align: center;
  padding: 20px 0;
}

.done-area__emoji { font-size: 56px; margin-bottom: 12px; }
.done-area__msg   { font-size: 20px; font-weight: 600; margin-bottom: 8px; }
.done-area__sub   { font-size: 15px; color: var(--muted); }

/* ── Spinner ──────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2.5px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #2c2c2c;
  color: #fff;
  font-size: 15px;
  font-weight: 500;
  padding: 14px 24px;
  border-radius: 12px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 250ms ease, transform 250ms ease;
  z-index: 100;
  max-width: calc(100vw - 40px);
  text-align: center;
}

.toast--visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast--success { background: #3a7d44; }
.toast--error   { background: #b94040; }
