:root {
  --pink: #ff1493;
  --pink-dark: #c2185b;
  --pink-light: #fce4ec;
  --dark: #121212;
  --white: #ffffff;
  --muted: #bdbdbd;
}

* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; min-height: 100%; font-family: "Poppins", "Segoe UI", sans-serif; }
body { background: var(--dark); color: var(--white); overflow: hidden; }
button, a { font: inherit; }
button { border: 0; }

.page {
  display: none;
  min-height: 100vh;
  width: 100%;
}

.page.active {
  display: flex;
}

/* Selection page needs its own scroll */
#page-selection {
  background: var(--dark);
  overflow-y: auto;
  overflow-x: hidden;
}
.selection-inner { width: min(1450px, 94vw); margin: auto; padding: 48px 0 60px; text-align: center; }
.selection-inner h1 { color: var(--pink); font-size: clamp(34px, 4vw, 56px); margin: 0 0 8px; font-weight: 800; letter-spacing: 2px; }
.subtitle { color: #e0e0e0; font-size: clamp(18px, 2vw, 22px); margin: 0 0 38px; }

.frame-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 22px; align-items: stretch; }
.frame-card { cursor: pointer; background: #1a1a1a; border: 3px solid #333; border-radius: 20px; padding: 18px; color: white; transition: .18s ease; }
.frame-card:hover { background: #242424; transform: translateY(-2px); }
.frame-card.selected { background: #2d1520; border-color: var(--pink); box-shadow: 0 0 0 2px rgba(255,20,147,.15); }
.frame-thumb-wrap { height: 280px; display: flex; justify-content: center; align-items: center; background: #0c0c0c; border-radius: 12px; overflow: hidden; padding: 10px; }
.frame-thumb { max-width: 100%; max-height: 100%; object-fit: contain; }
.frame-name { margin-top: 14px; color: white; font-size: 18px; font-weight: 800; }
.frame-card.selected .frame-name { color: var(--pink); }
.frame-description { color: #aaa; font-size: 13px; line-height: 1.45; margin-top: 6px; min-height: 38px; }

.primary-button, .secondary-button { cursor: pointer; display: inline-flex; justify-content: center; align-items: center; min-height: 58px; border-radius: 30px; padding: 12px 34px; font-weight: 800; text-decoration: none; transition: .18s ease; }
.primary-button { background: var(--pink); color: white; font-size: 20px; margin-top: 32px; }
.primary-button:hover { background: var(--pink-dark); }
.secondary-button { background: transparent; color: var(--pink); border: 2px solid var(--pink); font-size: 17px; }
.secondary-button:hover { background: var(--pink); color: white; }
.hint { color: #888; font-size: 13px; margin-top: 15px; }

#page-capture { background: #000; }
.capture-page { width: 100%; height: 100vh; display: flex; flex-direction: column; }
.camera-shell { position: relative; flex: 1; min-height: 0; display: flex; justify-content: center; align-items: center; background: #000; overflow: hidden; }
#camera { width: 100%; height: 100%; object-fit: contain; transform: scaleX(-1); background: #050505; }
.crop-guide { position: absolute; inset: 0; pointer-events: none; }
.crop-border { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(80vw, 1100px); aspect-ratio: 4 / 3; border: 4px solid rgba(255,255,255,.92); box-shadow: 0 0 0 9999px rgba(0,0,0,.42); }
.capture-status { position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%); padding: 10px 20px; border-radius: 999px; background: rgba(0,0,0,.7); color: white; font-weight: 800; font-size: 20px; }
.capture-actions { position: absolute; top: 20px; right: 20px; z-index: 5; }
.countdown-overlay { position: absolute; inset: 0; background: rgba(0,0,0,.35); display: flex; align-items: center; justify-content: center; z-index: 10; }
.countdown-overlay.hidden, .flash-overlay.hidden, .error-box.hidden { display: none; }
#countdown-number { color: var(--pink); font-size: min(26vw, 280px); line-height: 1; font-weight: 900; text-shadow: 0 0 40px rgba(0,0,0,.85); }
.flash-overlay { position: absolute; inset: 0; background: white; z-index: 20; opacity: .95; }

#page-processing { background: var(--dark); min-height: 100vh; align-items: center; justify-content: center; }
.processing-page { text-align: center; }
.processing-page h2 { color: var(--pink); font-size: clamp(30px, 4vw, 50px); margin: 20px 0 8px; }
.processing-page p { color: #b0b0b0; font-size: 20px; }
.loader { width: 76px; height: 76px; margin: 0 auto; border: 8px solid #333; border-top-color: var(--pink); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

#page-result {
  background: var(--dark);
  min-height: 100vh;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
}

.result-page {
  width: min(1400px, 94vw);
  margin: auto;
  padding: 40px 0 60px;
  text-align: center;
}
.result-page h2 { color: var(--pink); font-size: clamp(28px, 3.5vw, 44px); margin: 0 0 30px; }
.result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 38px; align-items: center; }
.result-photo-card { min-height: 560px; display: flex; justify-content: center; align-items: center; background: #000; border: 4px solid var(--pink); border-radius: 14px; overflow: hidden; }
#result-photo { max-width: 100%; max-height: 68vh; object-fit: contain; }
.qr-card { background: #1a1a1a; border: 2px solid rgba(255,20,147,.35); border-radius: 20px; padding: 36px; display: flex; flex-direction: column; align-items: center; }
#qr-image { width: min(320px, 60vw); aspect-ratio: 1; background: white; border: 8px solid white; border-radius: 10px; }
.qr-card h3 { margin: 20px 0 6px; font-size: 22px; }
.qr-card p { color: #ddd; margin: 0; }
.link-button { margin-top: 24px; }
.reset-timer { color: #ddd; font-style: italic; margin: 20px 0; }

.error-box { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.82); display: flex; justify-content: center; align-items: center; padding: 24px; }
.error-content { max-width: 620px; background: #1a1a1a; border: 2px solid var(--pink); border-radius: 20px; padding: 35px; text-align: center; }
.error-content h3 { color: var(--pink); font-size: 28px; }
.error-content p { color: #ddd; line-height: 1.6; }

.download-body { overflow: auto; background: var(--pink-light); color: var(--pink-dark); min-height: 100vh; }
.download-page { width: min(760px, 94vw); margin: auto; padding: 40px 0; }
.download-card { background: white; border-radius: 24px; padding: 28px; text-align: center; box-shadow: 0 14px 40px rgba(194,24,91,.16); }
.download-card h1 { color: var(--pink-dark); }
.download-preview { max-width: 100%; max-height: 70vh; object-fit: contain; border-radius: 12px; border: 4px solid var(--pink); }

@media (max-width: 1050px) {
  .frame-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .frame-thumb-wrap { height: 250px; }
}

@media (max-width: 760px) {
  #page-selection {
    height: 100dvh;
    min-height: 100dvh;
  }

  #page-result {
    height: 100dvh;
    min-height: 100dvh;
  }

  .frame-grid,
  .result-grid {
    grid-template-columns: 1fr;
  }

  .selection-inner {
    width: 92vw;
    padding: 30px 0 60px;
  }

  .frame-thumb-wrap {
    height: 230px;
  }

  .result-page {
    width: 92vw;
    padding: 30px 0 60px;
  }

  .result-photo-card {
    min-height: 0;
  }

  #result-photo {
    max-height: 45vh;
  }

  #qr-image {
    width: min(260px, 70vw);
  }

  #download-link {
    width: 100%;
  }

  #done-button {
    margin-top: 10px;
    margin-bottom: 20px;
  }
}