/* ===== Tokens ===== */
:root {
  --night: #1a1120;
  --night-2: #2a1830;
  --plum: #3d2442;
  --cream: #f7eee6;
  --paper: #fbf5ec;
  --ink: #3a2430;
  --ink-soft: #6e5260;
  --rose: #f0a8bd;
  --rose-deep: #c4587a;
  --envelope: #e9c9c4;
  --envelope-dark: #d7aba6;
  --focus: #ffd27a;

  --font-display: "Cormorant Garamond", "Iowan Old Style", Georgia, serif;
  --font-hand: "Caveat", "Segoe Print", "Bradley Hand", cursive;
  --font-mono: "DM Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;

  --fade: 1200ms;
  --ease: cubic-bezier(.22, .61, .36, 1);
}

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

html {
  background: var(--night);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--cream);
  font-family: var(--font-display);
  font-size: 1.125rem;
  line-height: 1.5;
  background:
    radial-gradient(1200px 700px at 15% -10%, rgba(240, 168, 189, .16), transparent 60%),
    radial-gradient(900px 600px at 100% 40%, rgba(124, 74, 140, .22), transparent 60%),
    linear-gradient(180deg, var(--night) 0%, var(--night-2) 55%, var(--plum) 100%);
  background-attachment: fixed;
  overflow-x: hidden;
}

html.is-locked,
html.is-locked body { overflow: hidden; }

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

button { font: inherit; color: inherit; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 4px;
  border-radius: 6px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 16px; top: -100px;
  z-index: 100;
  padding: .6rem 1rem;
  background: var(--paper);
  color: var(--ink);
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: .85rem;
  text-decoration: none;
}
.skip-link:focus { top: 16px; }

/* ===== Opening ===== */
.opening { display: none; }

.js .opening {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(2rem, 6vh, 4rem);
  padding: 24px 16px;
  background:
    radial-gradient(800px 500px at 50% 40%, rgba(240, 168, 189, .12), transparent 70%),
    var(--night);
  transition: opacity var(--fade) var(--ease), visibility 0s linear var(--fade);
}

.opening.is-leaving {
  opacity: 0;
  visibility: hidden;
}

.opening__stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.75rem;
  width: min(100%, 52rem);
  min-height: 12rem;
  justify-content: center;
}

.opening__line {
  margin: 0;
  text-align: center;
  font-family: var(--font-display);
  font-weight: 500;
  font-style: italic;
  font-size: clamp(1.9rem, 5.2vw, 3.6rem);
  line-height: 1.2;
  text-wrap: balance;
  color: var(--cream);
  opacity: 0;
  transform: translateY(8px);
  filter: blur(4px);
  transition:
    opacity var(--fade) var(--ease),
    transform var(--fade) var(--ease),
    filter var(--fade) var(--ease);
}

.opening__line.is-visible {
  opacity: 1;
  transform: none;
  filter: none;
}

.opening__dots {
  display: flex;
  gap: .6rem;
  margin: 0;
  padding: 0;
  list-style: none;
}
.opening__dots li {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: rgba(247, 238, 230, .22);
  transition: background .6s var(--ease), transform .6s var(--ease);
}
.opening__dots li.is-active {
  background: var(--rose);
  transform: scale(1.3);
}

.sound-prompt {
  display: inline-flex;
  align-items: center;
  gap: .7rem;
  padding: .85rem 1.5rem .85rem 1.2rem;
  border: 1.5px solid rgba(240, 168, 189, .55);
  border-radius: 999px;
  background: rgba(240, 168, 189, .08);
  color: var(--cream);
  font-family: var(--font-mono);
  font-size: .95rem;
  letter-spacing: .04em;
  cursor: pointer;
  animation: breathe 3.2s ease-in-out infinite;
  transition: background .3s, border-color .3s;
}
.sound-prompt:hover { background: rgba(240, 168, 189, .16); }
.sound-prompt__icon { display: inline-flex; color: var(--rose); }

.sound-prompt.is-on {
  animation: none;
  border-color: rgba(240, 168, 189, .3);
  background: transparent;
}
.sound-prompt.is-on .wave { animation: wave 1.6s ease-in-out infinite; }
.sound-prompt.is-on .wave + .wave { animation-delay: .3s; }

.sound-prompt.is-error {
  animation: none;
  border-color: rgba(247, 238, 230, .25);
  color: rgba(247, 238, 230, .75);
}

@keyframes breathe {
  0%, 100% { box-shadow: 0 0 0 0 rgba(240, 168, 189, .0); }
  50%      { box-shadow: 0 0 0 10px rgba(240, 168, 189, .12); }
}
@keyframes wave {
  0%, 100% { opacity: .35; }
  50%      { opacity: 1; }
}

/* "Geç": sits under each opening line and fades in/out with it */
.opening__skip {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  min-height: 44px;
  padding: .6rem 1.4rem;
  border: 1.5px solid rgba(247, 238, 230, .35);
  border-radius: 999px;
  background: rgba(247, 238, 230, .06);
  color: var(--cream);
  font-family: var(--font-mono);
  font-size: .9rem;
  letter-spacing: .06em;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--fade) var(--ease), background .3s, border-color .3s;
}
.opening__skip.is-visible {
  opacity: 1;
  pointer-events: auto;
}
.opening__skip:hover {
  border-color: var(--rose);
  background: rgba(240, 168, 189, .14);
}
.opening__skip span { color: var(--rose); }

/* ===== Gallery ===== */
.gallery {
  width: min(100% - 32px, 1120px);
  margin: 0 auto;
  padding: clamp(4rem, 12vh, 8rem) 0 4rem;
}
.gallery:focus { outline: none; }

.pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(1.5rem, 5vw, 4.5rem);
  align-items: start;
  margin-bottom: clamp(3rem, 10vh, 7rem);
}

/* Diagonal rhythm: odd pairs drop the right card, even pairs drop the left card */
.pair:nth-of-type(odd) .universe:nth-child(2),
.pair:nth-of-type(even) .universe:nth-child(1) {
  margin-top: clamp(6rem, 22vh, 14rem);
}

.universe {
  --tilt: -1.4deg;
  margin: 0;
  padding: 12px 12px 0;
  background: var(--paper);
  color: var(--ink);
  border-radius: 4px;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, .6) inset,
    0 18px 40px -18px rgba(0, 0, 0, .65),
    0 4px 12px rgba(0, 0, 0, .25);
  transform: rotate(var(--tilt));
}
.universe:nth-child(2) { --tilt: 1.2deg; }

.universe__frame {
  aspect-ratio: var(--ar, 1);
  max-height: 72vh;
  margin-inline: auto;
  background: #efe5da;
  border-radius: 2px;
  overflow: hidden;
}
.universe__frame img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.universe figcaption {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: .75rem;
  padding: .55rem .25rem .8rem;
}
.universe__name {
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: clamp(1.45rem, 2.4vw, 1.9rem);
  line-height: 1.1;
  color: var(--ink);
}
.universe__no {
  order: 2;
  flex: none;
  font-family: var(--font-mono);
  font-size: .72rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.universe.is-missing .universe__frame {
  display: grid;
  place-items: center;
  border: 2px dashed rgba(58, 36, 48, .3);
}
.universe.is-missing img { display: none; }
.universe__missing {
  padding: 1rem;
  text-align: center;
  font-family: var(--font-mono);
  font-size: .8rem;
  color: var(--ink-soft);
}

/* Reveal: cards drift gently down into place */
.js .universe.will-reveal {
  opacity: 0;
  transform: translateY(-28px) rotate(var(--tilt));
  transition: opacity 1.4s var(--ease), transform 1.6s var(--ease);
}
.js .universe.will-reveal.is-revealed {
  opacity: 1;
  transform: rotate(var(--tilt));
}
.js .pair .universe.will-reveal:nth-child(2) { transition-delay: .25s; }

/* ===== Letter ===== */
.letter-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2rem 16px clamp(5rem, 14vh, 9rem);
}

.envelope {
  --w: min(340px, 82vw);
  position: relative;
  width: var(--w);
  aspect-ratio: 34 / 22;
  margin-top: calc(var(--w) * .4);
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  perspective: 900px;
  transition: transform .4s var(--ease);
}
.envelope:hover:not(.is-open) { transform: translateY(-4px) rotate(-1deg); }
.envelope:focus-visible { outline-offset: 10px; }

.envelope > span:not(.visually-hidden) { position: absolute; display: block; }

.envelope__back {
  inset: 0;
  background: var(--envelope-dark);
  border-radius: 8px;
  box-shadow: 0 24px 50px -20px rgba(0, 0, 0, .7);
}

.envelope__paper {
  left: 7%;
  right: 7%;
  top: 8%;
  height: 84%;
  padding: 14% 10% 0;
  background: var(--paper);
  border-radius: 4px;
  z-index: 1;
  transition: transform 1s var(--ease) .55s;
}
.envelope__paper span {
  display: block;
  height: 3px;
  margin-bottom: 12%;
  border-radius: 2px;
  background: rgba(58, 36, 48, .18);
}
.envelope__paper span:nth-child(2) { width: 80%; }
.envelope__paper span:nth-child(3) { width: 55%; }

.envelope__pocket {
  inset: 0;
  z-index: 2;
  background: var(--envelope);
  border-radius: 0 0 8px 8px;
  clip-path: polygon(0 0, 50% 56%, 100% 0, 100% 100%, 0 100%);
}

.envelope__flap {
  left: 0;
  right: 0;
  top: 0;
  height: 62%;
  z-index: 3;
  background: #f1d6d1;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: top center;
  transition: transform .7s var(--ease), z-index 0s linear .35s;
}

.envelope__seal {
  left: 50%;
  top: 62%;
  z-index: 4;
  width: 44px;
  height: 44px;
  margin: -22px 0 0 -22px;
  display: grid !important;
  place-items: center;
  border-radius: 50%;
  background: var(--rose-deep);
  color: var(--paper);
  font-size: 1.15rem;
  line-height: 1;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .3), inset 0 -2px 0 rgba(0, 0, 0, .15);
  transition: opacity .3s var(--ease), transform .3s var(--ease);
}

.envelope.is-open { cursor: default; }
.envelope.is-open .envelope__seal { opacity: 0; transform: scale(.6); }
.envelope.is-open .envelope__flap { transform: rotateX(180deg); z-index: 0; }
.envelope.is-open .envelope__paper { transform: translateY(-58%); }

.envelope__hint {
  margin: 1.25rem 0 0;
  font-family: var(--font-hand);
  font-size: 1.5rem;
  color: var(--rose);
  transition: opacity .4s;
}
.envelope.is-open + .envelope__hint { opacity: 0; }

.letter {
  width: min(100%, 40rem);
  margin-top: 2.5rem;
  padding: clamp(1.75rem, 6vw, 3.5rem) clamp(1.25rem, 6vw, 3.5rem);
  background:
    repeating-linear-gradient(180deg, transparent 0 calc(1.8em - 1px), rgba(58, 36, 48, .06) calc(1.8em - 1px) 1.8em),
    var(--paper);
  color: var(--ink);
  border-radius: 6px;
  box-shadow: 0 30px 60px -28px rgba(0, 0, 0, .75);
  opacity: 0;
  transform: translateY(24px);
  transition: opacity 1s var(--ease), transform 1s var(--ease);
}
.letter.is-visible { opacity: 1; transform: none; }

.letter__text {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.15rem, 2.6vw, 1.35rem);
  font-weight: 500;
  line-height: 1.8;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}
.letter__text.is-error {
  font-family: var(--font-mono);
  font-size: .9rem;
  color: var(--ink-soft);
}

/* ===== Floating sound control ===== */
.sound-toggle {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 40;
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  padding: .6rem 1rem;
  border: 1px solid rgba(240, 168, 189, .45);
  border-radius: 999px;
  background: rgba(26, 17, 32, .82);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: var(--cream);
  font-family: var(--font-mono);
  font-size: .8rem;
  letter-spacing: .04em;
  cursor: pointer;
}
.sound-toggle[hidden] { display: none; }
.sound-toggle:hover { border-color: var(--rose); }
.sound-toggle__icon { color: var(--rose); font-size: 1rem; }
.sound-toggle[data-state="off"] .sound-toggle__icon { opacity: .45; text-decoration: line-through; }

/* ===== Toast / noscript ===== */
.toast {
  position: fixed;
  left: 50%;
  bottom: 72px;
  z-index: 60;
  width: max-content;
  max-width: calc(100% - 32px);
  margin: 0;
  padding: .7rem 1.1rem;
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: .8rem;
  line-height: 1.4;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .4);
  opacity: 0;
  transform: translate(-50%, 10px);
  pointer-events: none;
  transition: opacity .4s var(--ease), transform .4s var(--ease);
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

.noscript {
  margin: 16px;
  padding: 1rem;
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: .9rem;
}

/* ===== Mobile ===== */
@media (max-width: 720px) {
  .pair {
    grid-template-columns: 1fr;
    gap: 2.5rem;
    margin-bottom: 2.5rem;
  }
  .pair .universe { margin-top: 0 !important; width: 90%; }
  .universe:nth-child(1) { justify-self: start; --tilt: -1deg; }
  .universe:nth-child(2) { justify-self: end;   --tilt: 1deg; }
  .universe__frame { max-height: 78vh; }
  .universe { padding: 9px 9px 0; }
}

@media (max-width: 380px) {
  .pair .universe { width: 100%; }
}

/* ===== Reduced motion ===== */
@media (prefers-reduced-motion: reduce) {
  :root { --fade: 1ms; }
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
    transition-delay: 0s !important;
  }
  .opening__line { transform: none; filter: none; }
  .js .universe.will-reveal { opacity: 1; transform: rotate(var(--tilt)); }
  .envelope:hover:not(.is-open) { transform: none; }
}
