:root {
  --bg: #060818;
  --ink: #eceaf4;
  --ink-dim: rgba(236, 234, 244, 0.6);
  --ink-faint: rgba(236, 234, 244, 0.32);
  --gold: #ffd9a0;
  --gold-soft: rgba(255, 217, 160, 0.75);
  --gold-glow: rgba(255, 200, 130, 0.28);
  --violet: #b3a4ff;
  --violet-glow: rgba(157, 140, 255, 0.3);
  --card-bg: rgba(16, 19, 44, 0.62);
  --card-border: rgba(255, 255, 255, 0.12);
}

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

html {
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(120% 90% at 50% 0%, #0c1135 0%, #070a22 45%, var(--bg) 100%);
  color: var(--ink);
  font-family: "Inter", system-ui, sans-serif;
  font-weight: 300;
  overflow-x: hidden;
}

/* soft aurora drifting behind the stars — a sky that feels alive */
#aurora {
  position: fixed;
  inset: -20%;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(42% 36% at 22% 24%, rgba(140, 110, 255, 0.16), transparent 70%),
    radial-gradient(36% 30% at 78% 18%, rgba(255, 185, 120, 0.12), transparent 70%),
    radial-gradient(48% 42% at 62% 82%, rgba(90, 180, 255, 0.1), transparent 70%);
  filter: blur(48px);
  animation: aurora-drift 50s ease-in-out infinite alternate;
}

@keyframes aurora-drift {
  from {
    transform: translate3d(-3%, -2%, 0) rotate(-2deg) scale(1);
  }
  to {
    transform: translate3d(3%, 2%, 0) rotate(2deg) scale(1.08);
  }
}

/* explicit CSS size: the buffers are devicePixelRatio-scaled, and without
   this a retina canvas would display at 2x and shift everything drawn on it */
#sky {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 0;
}

/* letters dissolve into these sparks and fly off to space */
#particles {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 5;
  pointer-events: none;
}

#banner {
  position: relative;
  z-index: 2;
  text-align: center;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  color: #ffd9a0;
  background: rgba(255, 200, 120, 0.08);
  border-bottom: 1px solid rgba(255, 200, 120, 0.2);
  padding: 0.6rem 1rem;
}

#banner code {
  font-family: ui-monospace, monospace;
  color: #ffe6c4;
}

header {
  position: relative;
  z-index: 2;
  text-align: center;
  padding: 2.75rem 1.5rem 0;
}

.eyebrow {
  font-size: 0.72rem;
  letter-spacing: 0.45em;
  text-transform: uppercase;
  color: var(--gold-soft);
  margin-bottom: 1rem;
}

.title {
  font-family: "Cormorant Garamond", serif;
  font-weight: 400;
  font-size: clamp(2.2rem, 5.5vw, 3.4rem);
  letter-spacing: 0.04em;
  background: linear-gradient(115deg, #ffffff 15%, var(--gold) 50%, var(--violet) 88%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 1.6rem rgba(255, 210, 150, 0.18));
}

.subtitle {
  margin-top: 1rem;
  font-size: 0.92rem;
  line-height: 1.8;
  color: var(--ink-dim);
}

#app {
  position: relative;
  z-index: 1;
  width: min(92rem, 100%);
  margin: 0 auto;
  padding: 1.5rem 1.5rem 0;
  /* let drags in the open middle reach the globe behind */
  pointer-events: none;
}

/* always paint above the full-screen globe canvas (z-index 0) so the form
   stays visible and tappable no matter how close the camera gets */
#feed-section,
#compose {
  position: relative;
  z-index: 2;
  pointer-events: auto;
}

header,
footer {
  pointer-events: none;
}

/* ---------- globe: borderless, the whole screen is its sky ---------- */
#globe-section {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: auto;
}

/* warm halo cradling the globe */
#globe-section::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(44rem, 95vw);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 200, 130, 0.07) 0%, rgba(140, 110, 255, 0.06) 45%, transparent 70%);
  pointer-events: none;
}

#globe {
  width: 100%;
  height: 100%;
  cursor: grab;
}

#globe:active {
  cursor: grabbing;
}

.globe-tip {
  font-family: "Cormorant Garamond", serif;
  font-size: 1rem;
  max-width: 16rem;
  padding: 0.5rem 0.75rem;
  background: rgba(7, 9, 26, 0.88);
  border: 1px solid rgba(255, 217, 160, 0.3);
  border-radius: 0.6rem;
  color: var(--ink);
}

/* ---------- compose ---------- */
#compose {
  width: min(34rem, 100%);
  margin: 1.75rem auto 0;
  text-align: center;
}

#sun-widget {
  margin-bottom: 2.5rem;
  padding-top: 0.75rem;
}

/* the sun floats where it truly is in this view — projected from the real
   solar position, hidden whenever the globe stands in front of it */
#sun {
  position: fixed;
  left: 0;
  top: 0;
  width: 5.5rem;
  height: 5.5rem;
  z-index: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.8s ease;
  will-change: transform;
  border-radius: 50%;
  background: radial-gradient(circle at 36% 34%, #fff8e8 0%, #ffe3ae 38%, #ffc070 68%, #ff9d5c 88%);
  box-shadow:
    0 0 2.5rem rgba(255, 195, 115, 0.55),
    0 0 6rem rgba(255, 170, 90, 0.3),
    0 0 11rem rgba(255, 160, 80, 0.15);
  animation: sun-breathe 7s ease-in-out infinite alternate;
}

@keyframes sun-breathe {
  from {
    box-shadow:
      0 0 2.5rem rgba(255, 195, 115, 0.55),
      0 0 6rem rgba(255, 170, 90, 0.3),
      0 0 11rem rgba(255, 160, 80, 0.15);
  }
  to {
    box-shadow:
      0 0 3.2rem rgba(255, 200, 125, 0.7),
      0 0 7.5rem rgba(255, 175, 95, 0.4),
      0 0 13rem rgba(255, 165, 85, 0.2);
  }
}

#sun-info {
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold-soft);
}

#sun-quote {
  margin-top: 0.6rem;
  font-family: "Cormorant Garamond", serif;
  font-style: italic;
  font-size: 1.02rem;
  line-height: 1.5;
  color: var(--ink-dim);
}

#form {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  align-items: center;
}

#message {
  width: 100%;
  background: rgba(16, 19, 44, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 1rem;
  color: var(--ink);
  font-family: "Cormorant Garamond", serif;
  font-size: 1.25rem;
  line-height: 1.6;
  padding: 1.15rem 1.3rem;
  resize: none;
  outline: none;
  backdrop-filter: blur(10px);
  transition: border-color 0.4s ease, box-shadow 0.4s ease;
}

#message::placeholder {
  color: var(--ink-faint);
  font-style: italic;
}

#message:focus {
  border-color: rgba(255, 217, 160, 0.45);
  box-shadow: 0 0 2.4rem var(--gold-glow);
}

#send {
  font-family: "Inter", sans-serif;
  font-weight: 400;
  font-size: 0.85rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #1a1430;
  background: linear-gradient(120deg, #ffe3b8, var(--gold) 55%, #f3c98a);
  border: none;
  border-radius: 999px;
  padding: 0.9rem 2.2rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  box-shadow: 0 0 1.6rem var(--gold-glow);
  transition: box-shadow 0.3s ease, transform 0.3s ease, opacity 0.3s ease;
}

#send:disabled {
  opacity: 0.4;
  cursor: default;
  box-shadow: none;
}

#send:not(:disabled):hover {
  box-shadow: 0 0 2.6rem rgba(255, 200, 130, 0.45);
  transform: translateY(-1px);
}

#send .star {
  color: #6a4fd8;
}

.hint {
  margin-top: 0.9rem;
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  color: var(--ink-faint);
}

.error {
  margin-top: 0.75rem;
  font-size: 0.8rem;
  color: #ff9d9d;
}

/* ---------- feed ---------- */
#feed-section {
  margin: 3.5rem auto 3rem;
}

.feed-title {
  font-family: "Cormorant Garamond", serif;
  font-weight: 400;
  font-size: 1.45rem;
  letter-spacing: 0.06em;
  text-align: center;
  margin-bottom: 1.5rem;
  color: var(--ink-dim);
}

#wish-count {
  color: var(--gold);
}

.empty {
  text-align: center;
  font-style: italic;
  color: var(--ink-faint);
}

#feed {
  columns: 2 16rem;
  column-gap: 1.1rem;
}

#feed-sentinel {
  height: 1px;
}

.card {
  position: relative;
  break-inside: avoid;
  margin-bottom: 1.1rem;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 1rem;
  padding: 1.15rem 1.25rem;
  cursor: pointer;
  backdrop-filter: blur(14px);
  transition: border-color 0.3s ease, box-shadow 0.3s ease, transform 0.3s ease;
}

.card:hover,
.card:focus-visible {
  border-color: rgba(255, 217, 160, 0.4);
  box-shadow: 0 0 1.8rem rgba(255, 200, 130, 0.16);
  transform: translateY(-2px);
  outline: none;
}

/* a freshly sent wish takes no space at all until its stars fly over;
   then the card grows open and the words fade into it */
.card-hidden {
  opacity: 0;
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  margin-bottom: 0;
  border-color: transparent;
  overflow: hidden;
}

.card-arrive {
  overflow: hidden;
  animation: card-grow 1.2s cubic-bezier(0.2, 0.8, 0.3, 1) forwards;
}

@keyframes card-grow {
  0% {
    opacity: 0;
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    margin-bottom: 0;
    transform: scale(0.92);
    border-color: rgba(255, 217, 160, 0.7);
    box-shadow: 0 0 2.5rem rgba(255, 200, 130, 0.45);
  }
  55% {
    opacity: 1;
    max-height: 22rem;
    padding-top: 1.15rem;
    padding-bottom: 1.15rem;
    margin-bottom: 1.1rem;
    transform: scale(1.01);
    border-color: rgba(255, 217, 160, 0.7);
    box-shadow: 0 0 2.5rem rgba(255, 200, 130, 0.45);
  }
  100% {
    opacity: 1;
    max-height: 22rem;
    padding-top: 1.15rem;
    padding-bottom: 1.15rem;
    margin-bottom: 1.1rem;
    transform: scale(1);
    border-color: var(--card-border);
    box-shadow: 0 0 0 rgba(0, 0, 0, 0);
  }
}

/* the words settle into the card a beat after it opens */
.card-arrive .card-text,
.card-arrive .card-meta,
.card-arrive .share {
  animation: wish-text-in 0.7s ease 0.5s backwards;
}

@keyframes wish-text-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.card-text {
  font-family: "Cormorant Garamond", serif;
  font-size: 1.15rem;
  line-height: 1.55;
  color: var(--ink);
  white-space: pre-wrap;
  word-break: break-word;
}

.card-meta {
  margin-top: 0.85rem;
  padding-right: 1.8rem;
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  color: var(--ink-faint);
}

.card-meta::before {
  content: "✦ ";
  color: var(--gold-soft);
}

.share {
  position: absolute;
  right: 0.7rem;
  bottom: 0.65rem;
  display: grid;
  place-items: center;
  width: 1.6rem;
  height: 1.6rem;
  background: none;
  border: none;
  border-radius: 0.45rem;
  color: var(--ink-faint);
  cursor: pointer;
  transition: color 0.25s ease, background 0.25s ease;
}

.share:hover {
  color: var(--gold);
  background: rgba(255, 217, 160, 0.08);
}

.share.busy {
  color: var(--gold);
  animation: share-pulse 0.9s ease infinite;
}

@keyframes share-pulse {
  50% {
    opacity: 0.4;
  }
}

/* ---------- popup ---------- */
#popup {
  position: fixed;
  z-index: 3;
  left: 50%;
  bottom: 2rem;
  transform: translateX(-50%);
  width: min(28rem, calc(100% - 2rem));
  background: rgba(10, 12, 30, 0.93);
  border: 1px solid rgba(255, 217, 160, 0.35);
  border-radius: 1.1rem;
  box-shadow: 0 0 3rem rgba(255, 200, 130, 0.2);
  padding: 1.5rem 1.75rem;
  backdrop-filter: blur(10px);
  animation: popup-in 0.35s ease;
}

@keyframes popup-in {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(0.75rem);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

#popup-close {
  position: absolute;
  top: 0.5rem;
  right: 0.85rem;
  background: none;
  border: none;
  color: var(--ink-dim);
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
}

#popup-close:hover {
  color: var(--ink);
}

#popup-text {
  font-family: "Cormorant Garamond", serif;
  font-size: 1.3rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 40vh;
  overflow-y: auto;
}

#popup-meta {
  margin-top: 1rem;
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  color: var(--ink-faint);
}

#popup-meta::before {
  content: "✦ ";
  color: var(--gold-soft);
}

/* ---------- journey: letters rise from the globe into the sky ---------- */
#journey {
  position: fixed;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: end center;
  padding-bottom: 3.5rem;
  text-align: center;
  background: rgba(6, 8, 24, 0.55);
  pointer-events: none;
  transition: background 0.6s ease;
}

#capsule {
  font-family: "Cormorant Garamond", serif;
  font-size: 1.45rem;
  line-height: 1.65;
  max-width: 30rem;
  padding: 0 1.5rem;
  color: var(--ink);
  text-shadow: 0 0 1.6rem var(--gold-glow);
  white-space: pre-wrap;
  word-break: break-word;
}

#capsule span {
  transition: opacity 0.5s ease, transform 0.5s ease, filter 0.5s ease;
}

#journey-sub {
  margin-top: 1.25rem;
  font-size: 0.78rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--gold-soft);
  animation: sub-fade 5s ease forwards;
}

@keyframes sub-fade {
  0%,
  20% {
    opacity: 0;
  }
  40%,
  80% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

footer {
  position: relative;
  z-index: 2;
  text-align: center;
  padding: 1.5rem;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
}

/* ---------- mobile & narrow screens: globe small, compose in reach ---------- */
@media (max-width: 69.99rem) {
  header {
    padding: 1.25rem 1.25rem 0;
  }

  .eyebrow {
    font-size: 0.62rem;
    margin-bottom: 0.5rem;
  }

  .title {
    font-size: clamp(1.7rem, 7vw, 2.4rem);
  }

  .subtitle {
    margin-top: 0.6rem;
    font-size: 0.8rem;
    line-height: 1.55;
  }

  .subtitle br {
    display: none;
  }

  #app {
    padding: 0 1rem;
  }

  /* the sun disc still floats in the sky; its caption block steps aside */
  #sun-widget {
    display: none;
  }

  /* leave the upper screen to the globe, write from below */
  #compose {
    margin-top: 38vh;
  }

  #message {
    font-size: 1.05rem;
    line-height: 1.45;
    padding: 0.8rem 1rem;
    height: 6.75rem; /* ~3 lines — keeps the button above the fold */
  }

  #form {
    gap: 0.8rem;
  }

  #send {
    padding: 0.75rem 1.7rem;
    font-size: 0.78rem;
  }

  .hint {
    margin-top: 0.55rem;
    font-size: 0.62rem;
  }

  #feed-section {
    margin: 2.5rem auto 2rem;
  }

  .feed-title {
    font-size: 1.2rem;
  }

  #popup {
    bottom: 1rem;
  }

  /* keep the farewell line off the send button — center it over the globe */
  #journey {
    place-items: center;
    padding-bottom: 0;
  }

  #journey-sub {
    margin-top: 0;
  }
}

/* ---------- desktop: feed | globe | compose ---------- */
@media (min-width: 70rem) {
  #app {
    display: grid;
    grid-template-areas: "feed . compose";
    grid-template-columns: minmax(17rem, 22rem) minmax(0, 1fr) minmax(19rem, 24rem);
    gap: 2.25rem;
    align-items: start;
  }

  #feed-section {
    grid-area: feed;
    margin: 0;
    position: sticky;
    top: 1.25rem;
    max-height: calc(100vh - 2.5rem);
    overflow-y: auto;
    padding-right: 0.4rem;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 217, 160, 0.25) transparent;
  }

  #feed-section::-webkit-scrollbar {
    width: 5px;
  }

  #feed-section::-webkit-scrollbar-thumb {
    background: rgba(255, 217, 160, 0.2);
    border-radius: 99px;
  }

  #feed {
    columns: auto;
    display: block;
  }

  .feed-title {
    font-size: 1.25rem;
    text-align: left;
  }

  .empty {
    text-align: left;
  }

  /* sun rises at the top of the column, the message box settles at the bottom */
  #compose {
    grid-area: compose;
    margin: 0;
    position: sticky;
    top: 1.5rem;
    width: 100%;
    display: flex;
    flex-direction: column;
    min-height: clamp(24rem, 62vh, 38rem);
  }

  #sun-widget {
    margin-bottom: 0;
    padding-top: 0.5rem;
  }

  #form {
    margin-top: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  #aurora {
    animation: none;
  }
  .card:hover {
    transform: none;
  }
}
