/* =========================================================
   OUR CONSTELLATION — STYLES
   ---------------------------------------------------------
   Contents:
     1. Reset & base
     2. Palette & type (CSS custom properties)
     3. App shell & layout
     4. Opening sequence (cinematic intro messages)
     5. Stars — memory stars & the one future star
     6. Constellation lines (SVG)
     7. Hint
     8. Memory card + polaroid photos
     9. Buttons & focus states
     10. Responsive tweaks
     11. Reduced motion
   ========================================================= */

/* ---------- 1. Reset & base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: #04060a;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-sans);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  padding: 0;
}

img { max-width: 100%; display: block; }
p { margin: 0; }

/* ---------- 2. Palette & type ---------- */
:root {
  /* Deep navy fading to near-black — the night sky */
  --bg-top: #0c1322;
  --bg-bottom: #04060a;

  /* Warm parchment ink, used for all text */
  --ink: #f4f1e6;
  --ink-muted: rgba(244, 241, 230, 0.64);

  /* The one accent: warm starlight gold, used only for completed
     memory stars and constellation lines */
  --gold: #ffe3ad;
  --gold-dim: rgba(255, 227, 173, 0.6);
  --line-color: rgba(255, 227, 173, 0.42);

  /* Cool, quiet color for the hundreds of tiny distant stars, and for
     the future star — deliberately NOT warm gold, so it still reads
     as "not yet written" rather than "completed memory" */
  --star-cool: rgba(228, 233, 245, 0.95);

  /* The one line that reaches the future star — same cool, quiet
     family as the future star itself, and noticeably dimmer than the
     warm gold lines connecting completed memories */
  --line-color-future: rgba(228, 233, 245, 0.26);

  --card-bg: rgba(9, 13, 22, 0.78);
  --card-border: rgba(244, 241, 230, 0.1);

  /* Serif for anything emotional (messages, titles) — feels personal
     and a little literary. Sans for anything functional (buttons,
     dates, labels) — quiet and gets out of the way. */
  --font-serif: Georgia, 'Iowan Old Style', 'Palatino Linotype', Palatino, 'Book Antiqua', serif;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

/* ---------- 3. App shell & layout ---------- */
#app {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: radial-gradient(ellipse 120% 70% at 50% -10%, var(--bg-top), var(--bg-bottom) 65%);
}

#bg-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  transition: opacity 2.2s ease, transform 0.9s cubic-bezier(.22,.61,.36,1);
  transform-origin: 50% 50%;
}
#bg-canvas.is-visible { opacity: 1; }
#bg-canvas.zoomed { transform: scale(1.12); }

#sky-container {
  position: absolute;
  inset: 0;
  transition: transform 0.9s cubic-bezier(.22,.61,.36,1), filter 0.9s ease;
  transform-origin: 50% 50%;
}
#sky-container.zoomed { transform: scale(1.65); }

#constellation-lines,
#stars-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

body.is-focused .star:not(.star--active) { opacity: 0.2; transition: opacity 0.5s ease; }
body.is-focused .constellation-line { opacity: 0.28; transition: opacity 0.5s ease; }

/* ---------- 4. Opening sequence ---------- */
.opening-sequence {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(24px, var(--safe-top)) max(32px, var(--safe-right)) max(24px, var(--safe-bottom)) max(32px, var(--safe-left));
  pointer-events: none;
}

.opening-line {
  max-width: 480px;
  margin: 0;
  text-align: center;
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 400;
  font-size: clamp(1.15rem, 4.6vw, 1.7rem);
  line-height: 1.55;
  color: var(--ink);
}

/* The second message: fades in on its own, after the trace finishes */
.opening-line--standalone {
  position: absolute;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 1.05s ease, transform 1.05s cubic-bezier(.22,.61,.36,1);
}
.opening-line--standalone.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* The first message + "Discover Our Sky" button: fade in together,
   then wait — the trace only starts once this is tapped. */
.opening-message {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 1.05s ease, transform 1.05s cubic-bezier(.22,.61,.36,1);
  pointer-events: none;
}
.opening-message.is-visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.opening-button {
  font-family: var(--font-sans);
  font-size: 0.78rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink);
  background: transparent;
  border: 1px solid rgba(244, 241, 230, 0.45);
  padding: 15px 34px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.3s ease, border-color 0.3s ease, transform 0.15s ease;
  touch-action: manipulation;
}
.opening-button:active {
  transform: scale(0.96);
  background: rgba(244, 241, 230, 0.12);
}
@media (hover: hover) and (pointer: fine) {
  .opening-button:hover {
    background: rgba(244, 241, 230, 0.1);
    border-color: rgba(244, 241, 230, 0.7);
  }
}

/* ---------- 5. Stars ---------- */
.star {
  position: absolute;
  width: 34px;
  height: 34px;
  margin-left: -17px;
  margin-top: -17px;
  border-radius: 50%;
  opacity: 0;
  transform: scale(0.25);
  transition: opacity 0.34s ease, transform 0.34s cubic-bezier(.22,.75,.28,1);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.star.is-visible { transform: scale(1); }
.star--memory.is-visible { opacity: 1; }

.star::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  transition: box-shadow 0.4s ease;
}

.star--memory { cursor: pointer; }
.star--memory::before {
  width: 9px;
  height: 9px;
  background: radial-gradient(circle, #fffaee 0%, var(--gold) 55%, rgba(255, 227, 173, 0) 78%);
  box-shadow: 0 0 8px 2px rgba(255, 214, 150, 0.55), 0 0 22px 7px rgba(255, 214, 150, 0.22);
  animation: starPulse 4.5s ease-in-out infinite;
  animation-delay: var(--pulse-delay, 0s);
}
.star--memory.star--active::before {
  box-shadow: 0 0 16px 5px rgba(255, 214, 150, 0.85), 0 0 44px 16px rgba(255, 214, 150, 0.4);
}

/* --- The one unlabeled path star: a real, unusually bright star from
       that night's sky, not tied to any memory, so it's bigger/brighter
       than the rest but not tappable. --- */
.star--feature { cursor: default; }
.star--feature::before {
  width: 13px;
  height: 13px;
  background: radial-gradient(circle, #fffaee 0%, var(--gold) 55%, rgba(255, 227, 173, 0) 78%);
  box-shadow: 0 0 12px 4px rgba(255, 214, 150, 0.75), 0 0 34px 12px rgba(255, 214, 150, 0.32);
  animation: starPulse 4.5s ease-in-out infinite;
  animation-delay: var(--pulse-delay, 0s);
}
.star--feature.is-visible { opacity: 1; }

/* The center/path star is the shared signature point: no memory card,
   just the smaller D ♥ N signature floating horizontally above the glow. */
.star--feature .signature-lockup {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 12px);
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.42em;
  transform: translateX(-50%);
  font-family: var(--font-serif);
  font-size: clamp(0.95rem, 2.55vw, 1.55rem);
  font-weight: 500;
  letter-spacing: 0.035em;
  line-height: 1;
  color: #fffaf0;
  text-shadow: 0 0 12px rgba(255, 227, 173, 0.7), 0 0 26px rgba(255, 214, 150, 0.34);
  white-space: nowrap;
  pointer-events: none;
}
.star--feature .signature-letter {
  display: inline-block;
}
.star--feature .signature-heart {
  display: inline-block;
  font-size: 0.84em;
  line-height: 1;
}

/* --- The future star --- */
.star--future {
  cursor: pointer;
  width: 10px;
  height: 10px;
  margin-left: -5px;
  margin-top: -5px;
}
.star--future::before {
  width: 6px;
  height: 6px;
  background: radial-gradient(circle, #eef1fb 0%, var(--star-cool) 55%, rgba(228, 233, 245, 0) 78%);
  box-shadow: 0 0 6px 2px rgba(228, 233, 245, 0.3);
  animation: starPulse 6.5s ease-in-out infinite;
  animation-delay: var(--pulse-delay, 0s);
}
.star--future.is-visible { opacity: 0.6; }
.star--future.star--active::before {
  box-shadow: 0 0 10px 3px rgba(228, 233, 245, 0.5), 0 0 26px 9px rgba(228, 233, 245, 0.25);
}

@keyframes starPulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.35); }
}

/* ---------- 6. Constellation lines ---------- */
.constellation-line {
  fill: none;
  stroke: var(--line-color);
  stroke-width: 1.1px;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
  filter: drop-shadow(0 0 2.5px rgba(255, 214, 150, 0.45));
}

/* The one line reaching the future star: cool-toned and quiet rather
   than warm gold, and it only fades in once the future star itself
   does — never drawn as part of the main left-to-right trace. */
.constellation-line--future {
  stroke: var(--line-color-future);
  filter: drop-shadow(0 0 1.5px rgba(228, 233, 245, 0.25));
  opacity: 0;
  transition: opacity 0.9s ease;
}
.constellation-line--future.is-visible {
  opacity: 1;
}

/* ---------- 7. Hint ---------- */
.hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: max(28px, var(--safe-bottom));
  text-align: center;
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 0.85rem;
  color: var(--ink-muted);
  opacity: 0;
  transition: opacity 1s ease;
  z-index: 3;
  pointer-events: none;
}
.hint.is-visible { opacity: 1; }
.hint.is-dismissed { opacity: 0; }

/* ---------- 8. Memory card ---------- */
#dim-overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 4, 8, 0.4);
  backdrop-filter: blur(7px) brightness(0.55);
  -webkit-backdrop-filter: blur(7px) brightness(0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
  z-index: 8;
}
#dim-overlay.is-visible { opacity: 1; pointer-events: auto; }

.memory-card {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(0.94);
  width: min(92vw, 420px);
  max-height: min(84vh, 84dvh);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 18px;
  padding: 28px 24px max(28px, var(--safe-bottom));
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.44s ease, transform 0.52s cubic-bezier(.22,.61,.36,1);
  z-index: 12;
  box-shadow: 0 30px 80px rgba(0,0,0,0.5);
}
.memory-card.is-open {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
  pointer-events: auto;
}

.close-button {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--ink-muted);
  font-size: 0.9rem;
  transition: background 0.25s ease, color 0.25s ease;
}
.close-button:active { background: rgba(244,241,230,0.1); color: var(--ink); }

.card-date {
  margin-bottom: 6px;
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold-dim);
}
.card-title {
  margin: 0 0 18px;
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: clamp(1.3rem, 4.6vw, 1.7rem);
  line-height: 1.3;
}
.card-date:empty,
.card-title:empty { display: none; }

.card-photos {
  display: flex;
  justify-content: center;
  gap: 14px;
  overflow-x: auto;
  padding: 4px 2px 16px;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
}
.polaroid {
  flex: 0 0 auto;
  background: #f7f3e8;
  padding: 8px 8px 22px;
  border-radius: 2px;
  box-shadow: 0 12px 26px rgba(0,0,0,0.45);
  scroll-snap-align: center;
  transform: rotate(var(--rot, -2deg));
}
.polaroid:nth-child(1) { --rot: -3deg; }
.polaroid:nth-child(2) { --rot: 2deg; }
.polaroid:nth-child(3) { --rot: -1.5deg; }
.polaroid:nth-child(4) { --rot: 2.5deg; }
.polaroid img {
  /* Keep each photo at its own natural proportions (no forced crop),
     just bounded so it fits comfortably in the card. */
  width: auto;
  height: auto;
  max-width: min(72vw, 280px);
  max-height: 54vh;
  object-fit: contain;
  border-radius: 1px;
}
.card-description {
  margin-bottom: 12px;
  font-size: 1rem;
  line-height: 1.7;
}
.card-extra {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--card-border);
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 0.95rem;
  color: var(--ink-muted);
}
.card-extra[hidden] { display: none; }

.memory-card.no-image .card-photos { display: none; }
.memory-card.no-image .card-content { text-align: center; }

/* --- The future star's card: a small collage of every memory photo
       so far, split into two clusters that sandwich the message
       instead of one photo strip. --- */
.memory-card.is-future .card-content {
  display: flex;
  flex-direction: column;
  text-align: center;
}
.memory-card.is-future .card-photos--collage {
  /* Let its two children act as direct flex items of .card-content,
     so `order` can place one cluster above and one below the text. */
  display: contents;
}
.collage-group {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  padding: 4px 2px;
}
.memory-card.is-future .collage-top { order: -1; }
.memory-card.is-future .card-description { order: 0; }
.memory-card.is-future .collage-bottom { order: 1; }

.memory-card.is-future .card-description {
  margin: 18px 0;
  font-family: var(--font-serif);
  font-style: italic;
  font-size: clamp(1.1rem, 4.4vw, 1.35rem);
  line-height: 1.65;
  padding: 0 4px;
}

.polaroid--mini {
  padding: 4px 4px 12px;
  box-shadow: 0 6px 14px rgba(0,0,0,0.4);
}
.polaroid--mini img {
  width: clamp(44px, 15vw, 64px);
  height: clamp(44px, 15vw, 64px);
  max-width: none;
  max-height: none;
  object-fit: cover;
  border-radius: 1px;
}
.collage-group .polaroid--mini:nth-child(5n+1) { --rot: -7deg; }
.collage-group .polaroid--mini:nth-child(5n+2) { --rot: 5deg; }
.collage-group .polaroid--mini:nth-child(5n+3) { --rot: -3deg; }
.collage-group .polaroid--mini:nth-child(5n+4) { --rot: 6deg; }
.collage-group .polaroid--mini:nth-child(5n+5) { --rot: -5deg; }

/* ---------- 9. Buttons & focus states ---------- */
.primary-button, .ghost-button {
  font-family: var(--font-sans);
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink);
  background: transparent;
  border: 1px solid rgba(244, 241, 230, 0.38);
  padding: 15px 30px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.3s ease, border-color 0.3s ease, transform 0.15s ease;
  touch-action: manipulation;
}
.primary-button:active, .ghost-button:active { transform: scale(0.96); background: rgba(244,241,230,0.1); }
@media (hover: hover) and (pointer: fine) {
  .primary-button:hover, .ghost-button:hover {
    background: rgba(244, 241, 230, 0.08);
    border-color: rgba(244, 241, 230, 0.65);
  }
}

/* Visible keyboard focus everywhere it's needed */
button:focus-visible {
  outline: 2px solid var(--gold-dim);
  outline-offset: 3px;
  border-radius: 999px;
}
.star:focus-visible::before {
  box-shadow: 0 0 0 4px rgba(255, 227, 173, 0.55), 0 0 10px 3px rgba(255, 214, 150, 0.6);
}
.close-button:focus-visible {
  outline-offset: 0;
}

/* ---------- 10. Responsive ---------- */
@media (min-width: 720px) {
  .memory-card { width: min(60vw, 480px); }
  .polaroid img { max-width: min(34vw, 300px); }
}

/* ---------- 11. Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}


/* Smooth photo/card entrance */
.card-photos:not(.card-photos--collage) {
  overflow-x: auto;
}

.card-photos .polaroid {
  opacity: 0;
  transform: translateY(8px) scale(0.985) rotate(var(--rot, -2deg));
  transition: opacity 0.5s ease, transform 0.55s cubic-bezier(.22,.61,.36,1);
}
.memory-card.is-open .card-photos:not(.card-photos--collage) {
  overflow-x: auto;
}

.card-photos .polaroid {
  opacity: 1;
  transform: translateY(0) scale(1) rotate(var(--rot, -2deg));
}
.card-photos .polaroid:nth-child(2) { transition-delay: 0.06s; }
.card-photos .polaroid:nth-child(3) { transition-delay: 0.11s; }
.card-photos .polaroid:nth-child(4) { transition-delay: 0.16s; }
.card-photos .polaroid:nth-child(5) { transition-delay: 0.21s; }
.card-photos .polaroid:nth-child(6) { transition-delay: 0.26s; }

/* Hide the secondary opening message entirely when there is no text. */
.opening-line--standalone:empty { display: none; }
