/* ====================================================
   SIMONE BIRTHDAY CARD — STYLESHEET
   Three states: state-prompt | state-birthday | state-garbled
   ==================================================== */

/* ── Reset & Base ──────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg:          #0a0a0f;
  --bg-mid:      #0d1120;
  --ice:         #a8d8f0;
  --ice-dim:     rgba(168, 216, 240, 0.45);
  --ice-glow:    rgba(168, 216, 240, 0.15);
  --rose:        #f0c8d8;
  --rose-dim:    rgba(240, 200, 216, 0.35);
  --white:       #f0f4ff;
  --muted:       rgba(168, 216, 240, 0.3);
  --card-bg:     rgba(255, 255, 255, 0.03);
  --card-border: rgba(168, 216, 240, 0.08);
  --font-sans:   'Inter', system-ui, sans-serif;
  --font-serif:  'Cormorant Garamond', Georgia, serif;
  --radius:      12px;
}

html, body {
  height: 100%;
  width: 100%;
  overflow-x: hidden;
}

body {
  background: var(--bg);
  color: var(--ice);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Screens ───────────────────────────────────────── */
.screen {
  position: fixed;
  inset: 0;
  transition: opacity 0.6s ease, filter 0.6s ease;
}

.screen.hidden {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

/* ── Particle Canvas ───────────────────────────────── */
.particle-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.particle-canvas.active {
  opacity: 1;
}

/* ── Key Photo Overlay ─────────────────────────────── */
.key-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(10, 10, 15, 0.97);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.45s ease;
}

.key-overlay.hidden { display: none; }

.key-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.key-overlay-frame {
  position: relative;
  width: min(280px, 75vw);
  aspect-ratio: 1;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow:
    0 0 0 1px rgba(168, 216, 240, 0.18),
    0 0 50px rgba(168, 216, 240, 0.12),
    0 24px 64px rgba(0, 0, 0, 0.6);
}

.key-overlay-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Scan line sweeps top→bottom over ~1.4s */
.key-overlay-scan {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 3px;
  background: linear-gradient(to right,
    transparent 0%,
    rgba(168, 216, 240, 0.3) 20%,
    var(--ice) 50%,
    rgba(168, 216, 240, 0.3) 80%,
    transparent 100%
  );
  box-shadow: 0 0 18px 4px rgba(168, 216, 240, 0.45);
  animation: keyScan 2.2s cubic-bezier(0.4, 0, 0.6, 1) forwards;
}

.key-overlay-vignette {
  position: absolute;
  inset: 0;
  background: radial-gradient(
    ellipse at center,
    transparent 35%,
    rgba(10, 10, 15, 0.55) 100%
  );
  pointer-events: none;
}

.key-overlay-frame,
.key-overlay-label {
  transition: opacity 0.35s ease;
}

.key-overlay-label {
  margin-top: 1.75rem;
  font-size: 0.65rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0;
  animation: fadeIn 0.5s ease 0.5s forwards;
}

/* Loading state — after scan, frame + label fade out, spinner fades in */
.key-overlay.loading .key-overlay-frame,
.key-overlay.loading .key-overlay-label {
  opacity: 0;
  pointer-events: none;
}

.key-overlay-spinner {
  position: absolute;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid rgba(168, 216, 240, 0.15);
  border-top-color: var(--ice);
  animation: spin 0.8s linear infinite;
  opacity: 0;
  transition: opacity 0.35s ease;
}

.key-overlay.loading .key-overlay-spinner {
  opacity: 1;
}

@keyframes keyScan {
  0%   { top: 0%; opacity: 0; }
  8%   { opacity: 1; }
  92%  { opacity: 1; }
  100% { top: 100%; opacity: 0; }
}

/* ====================================================
   STATE: PROMPT
   ==================================================== */
#prompt-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  background: var(--bg);
}

.prompt-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2.5rem;
  padding: 2rem;
  width: 100%;
  max-width: 480px;
}

.prompt-question {
  font-family: var(--font-serif);
  font-size: clamp(1.25rem, 4vw, 2rem);
  font-weight: 300;
  font-style: italic;
  color: var(--ice);
  text-align: center;
  letter-spacing: 0.01em;
  line-height: 1.4;
  opacity: 0;
  transform: translateY(12px);
  animation: fadeUp 1.2s ease 0.3s forwards;
}

.drop-zone {
  position: relative;
  width: 100%;
  max-width: 320px;
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  cursor: pointer;
  border-radius: var(--radius);
  border: 1px solid transparent;
  transition: border-color 0.3s ease, box-shadow 0.3s ease, background 0.3s ease;
  opacity: 0;
  animation: fadeUp 1.2s ease 0.7s forwards;
}

.drop-zone::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  border: 1px dashed var(--muted);
  transition: border-color 0.3s ease;
  pointer-events: none;
}

.drop-zone:hover,
.drop-zone:focus,
.drop-zone.drag-over {
  background: var(--ice-glow);
  box-shadow: 0 0 40px var(--ice-glow), inset 0 0 20px rgba(168, 216, 240, 0.04);
  outline: none;
}

.drop-zone:hover::before,
.drop-zone:focus::before,
.drop-zone.drag-over::before {
  border-color: var(--ice-dim);
}

.drop-zone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

.drop-icon {
  width: 40px;
  height: 40px;
  color: var(--ice-dim);
  transition: color 0.3s ease;
}

.drop-zone:hover .drop-icon,
.drop-zone.drag-over .drop-icon {
  color: var(--ice);
}

.drop-icon svg {
  width: 100%;
  height: 100%;
}

.drop-hint {
  font-size: 0.7rem;
  font-weight: 400;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  transition: color 0.3s ease;
}

.drop-zone:hover .drop-hint,
.drop-zone.drag-over .drop-hint {
  color: var(--ice-dim);
}

/* Processing indicator */
.processing-indicator {
  width: 24px;
  height: 24px;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.processing-indicator.active {
  opacity: 1;
}

.processing-indicator.active::after {
  content: '';
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 1px solid var(--muted);
  border-top-color: var(--ice);
  animation: spin 0.8s linear infinite;
}

/* ====================================================
   STATE: BIRTHDAY
   ==================================================== */
#birthday-screen {
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 5;
  background: linear-gradient(160deg, #050510 0%, #0d1228 50%, #120c1a 100%);
  -webkit-overflow-scrolling: touch;
}

/* Hero */
.bday-hero {
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: clamp(2rem, 8vw, 6rem) clamp(1.5rem, 6vw, 4rem);
  position: relative;
}

.bday-hero::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 1px;
  height: 80px;
  background: linear-gradient(to bottom, var(--ice-dim), transparent);
}

.bday-title {
  font-family: var(--font-serif);
  font-size: clamp(2.5rem, 8vw, 6rem);
  font-weight: 300;
  color: var(--white);
  line-height: 1.15;
  letter-spacing: -0.01em;
  margin-bottom: 1.5rem;
  text-wrap: balance; /* distributes lines evenly when wrapping */
}

.bday-title .char {
  display: inline-block;
  opacity: 0;
  transform: translateY(20px);
  animation: charReveal 0.5s ease forwards;
}

.bday-subtitle {
  font-family: var(--font-serif);
  font-size: clamp(0.9rem, 2.5vw, 1.1rem);
  font-weight: 300;
  font-style: italic;
  color: var(--ice-dim);
  letter-spacing: 0.06em;
}

/* Divider */
.bday-divider {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  width: 100%;
  max-width: 600px;
  margin: 4rem auto;
  padding: 0 2rem;
  opacity: 0;
  animation: fadeIn 0.8s ease forwards;
}

.bday-divider::before,
.bday-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(to right, transparent, var(--card-border), transparent);
}

.bday-divider-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--ice-dim);
}

/* Letter */
.bday-letter {
  max-width: 680px;
  margin: 0 auto;
  padding: 0 clamp(1.5rem, 6vw, 4rem) 5rem;
}

.bday-letter-para {
  font-family: var(--font-serif);
  font-size: clamp(1.05rem, 2.5vw, 1.3rem);
  font-weight: 300;
  line-height: 1.95;
  color: var(--white);
  margin-bottom: 1.75em;
  overflow-wrap: break-word;
  opacity: 0;
  transform: translateY(14px);
  animation: cardReveal 0.8s ease forwards;
}

.bday-letter-para:last-child { margin-bottom: 0; }

/* Photos — asymmetric collage grid */
.bday-photos {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 0.75rem;
  max-width: 960px;
  margin: 0 auto;
  padding: 0 clamp(1rem, 4vw, 2.5rem) 7rem;
}

/* Default fallback: 2-up */
.bday-photo { grid-column: span 6; }

/* Asymmetric layout for up to 6 photos */
.bday-photo:nth-child(1) { grid-column: span 7; aspect-ratio: 3/2; }
.bday-photo:nth-child(2) { grid-column: span 5; aspect-ratio: 2/3; }
.bday-photo:nth-child(3) { grid-column: span 4; aspect-ratio: 1;   }
.bday-photo:nth-child(4) { grid-column: span 4; aspect-ratio: 4/3; }
.bday-photo:nth-child(5) { grid-column: span 4; aspect-ratio: 1;   }
.bday-photo:nth-child(6) { grid-column: 3 / span 8; aspect-ratio: 16/9; }

.bday-photo {
  --rot: 0deg;
  position: relative;
  overflow: hidden;
  border-radius: 8px;
  opacity: 0;
  transform: scale(0.96) rotate(var(--rot));
  animation: photoReveal 0.75s ease forwards;
  transition: transform 0.35s ease, box-shadow 0.35s ease, z-index 0s;
  z-index: 0;
}

.bday-photo:hover {
  transform: scale(1.04) rotate(var(--rot));
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.65);
  z-index: 2;
}

.bday-photo img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Tablet: simplified 2-col, drop asymmetric spans */
@media (min-width: 640px) and (max-width: 899px) {
  .bday-photo:nth-child(1),
  .bday-photo:nth-child(2) { grid-column: span 6; aspect-ratio: 4/3; }
  .bday-photo:nth-child(3),
  .bday-photo:nth-child(4),
  .bday-photo:nth-child(5) { grid-column: span 4; aspect-ratio: 1; }
  .bday-photo:nth-child(6) { grid-column: span 6; aspect-ratio: 4/3; }
}

/* Audio Player */
.bday-player {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 64px;
  background: rgba(10, 10, 15, 0.92);
  border-top: 1px solid var(--card-border);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 clamp(1rem, 4vw, 2rem);
  z-index: 50;
  opacity: 0;
  transform: translateY(100%);
  animation: playerReveal 0.6s ease forwards;
}

.player-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--ice-glow);
  border: 1px solid var(--ice-dim);
  color: var(--ice);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s ease, transform 0.15s ease;
}

.player-btn:hover {
  background: rgba(168, 216, 240, 0.2);
  transform: scale(1.05);
}

.player-btn svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

.player-track {
  flex: 1;
  height: 2px;
  background: rgba(168, 216, 240, 0.1);
  border-radius: 1px;
  cursor: pointer;
  position: relative;
}

.player-progress {
  height: 100%;
  width: 0%;
  background: var(--ice);
  border-radius: 1px;
  transition: width 0.1s linear;
}

.player-time {
  font-size: 0.7rem;
  color: var(--muted);
  letter-spacing: 0.08em;
  flex-shrink: 0;
  min-width: 70px;
  text-align: right;
}

/* ====================================================
   STATE: GARBLED
   ==================================================== */
#garbled-screen {
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 5;
  background: #080810;
  animation: hueShift 30s linear infinite;
}

.garbled-nav {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  gap: 2rem;
  padding: 1rem clamp(1rem, 4vw, 3rem);
  background: rgba(8, 8, 16, 0.9);
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 10;
}

.garbled-logo {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.4);
  letter-spacing: 0.1em;
  flex-shrink: 0;
}

.garbled-nav-items {
  display: flex;
  gap: 1.5rem;
  list-style: none;
  overflow: hidden;
}

.garbled-nav-items li {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.2);
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.garbled-main {
  padding: clamp(2rem, 6vw, 5rem) clamp(1.5rem, 6vw, 4rem);
  max-width: 860px;
  margin: 0 auto;
}

.garbled-section {
  margin-bottom: 4rem;
}

.garbled-heading {
  font-family: var(--font-serif);
  font-size: clamp(1.4rem, 3vw, 2.2rem);
  font-weight: 300;
  color: rgba(255, 255, 255, 0.25);
  margin-bottom: 1.5rem;
  letter-spacing: 0.02em;
}

.garbled-p {
  font-family: var(--font-sans);
  font-size: clamp(0.8rem, 1.8vw, 0.9rem);
  color: rgba(255, 255, 255, 0.15);
  line-height: 1.75;
  margin-bottom: 1rem;
  letter-spacing: 0.01em;
}

.garbled-footer {
  border-top: 1px solid rgba(255, 255, 255, 0.04);
  padding: 2rem clamp(1.5rem, 6vw, 4rem);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}

.garbled-footer-text {
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.1);
  letter-spacing: 0.06em;
}

/* Retry button */
.retry-btn {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  padding: 0.6rem 1.2rem;
  background: rgba(10, 10, 15, 0.85);
  border: 1px solid rgba(168, 216, 240, 0.2);
  border-radius: 20px;
  color: var(--ice-dim);
  font-family: var(--font-sans);
  font-size: 0.7rem;
  font-weight: 400;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  z-index: 20;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: border-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.retry-btn:hover {
  border-color: var(--ice);
  color: var(--ice);
  box-shadow: 0 0 16px var(--ice-glow);
}

/* ====================================================
   ANIMATIONS
   ==================================================== */
@keyframes fadeUp {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  to { opacity: 1; }
}

@keyframes charReveal {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes cardReveal {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes photoReveal {
  to {
    opacity: 1;
    transform: scale(1) rotate(var(--rot));
  }
}

@keyframes playerReveal {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@keyframes hueShift {
  0%   { filter: hue-rotate(0deg); }
  50%  { filter: hue-rotate(12deg) brightness(0.97); }
  100% { filter: hue-rotate(0deg); }
}

/* Prompt screen exit animation */
#prompt-screen.exiting {
  opacity: 0;
  filter: blur(8px);
  pointer-events: none;
}

/* ====================================================
   RESPONSIVE ADJUSTMENTS
   ==================================================== */

/* iPhone SE / small phones */
@media (max-width: 375px) {
  .drop-zone {
    max-width: 260px;
    aspect-ratio: 1;
  }

  /* Scale title down so it doesn't overflow narrow viewports */
  .bday-title {
    font-size: clamp(1.8rem, 9vw, 2.5rem);
  }
}

/* Mobile: stack photos, alternate alignment for a staggered feel */
@media (max-width: 639px) {
  .bday-photos {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding-bottom: 7rem;
  }

  /* Remove all forced aspect-ratios — let each photo's natural
     dimensions (portrait or landscape) determine the container height */
  .bday-photo,
  .bday-photo:nth-child(1),
  .bday-photo:nth-child(2),
  .bday-photo:nth-child(3),
  .bday-photo:nth-child(4),
  .bday-photo:nth-child(5),
  .bday-photo:nth-child(6) {
    width: 88%;
    aspect-ratio: unset;
    align-self: flex-start;
  }

  /* Natural dimensions: full width, proportional height, no crop */
  .bday-photos .bday-photo img {
    height: auto;
    object-fit: initial;
  }

  .bday-photo:nth-child(even) {
    align-self: flex-end;
  }
}

/* Tablets */
@media (min-width: 768px) {
  .bday-hero {
    min-height: 100vh;
  }
}

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* Safe area insets (iPhone notch/home bar) */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .bday-player {
    padding-bottom: calc(0.5rem + env(safe-area-inset-bottom));
    height: calc(64px + env(safe-area-inset-bottom));
  }
  .retry-btn {
    bottom: calc(1.5rem + env(safe-area-inset-bottom));
  }
}
