/* ========================================================
   Phir Milengey — dreamy love-letter redesign
   ======================================================== */

/* ========== Design tokens ========== */
:root {
  --ink: #7c1d47;          /* deep rose, primary text */
  --rose: #d81b60;         /* accent */
  --rose-soft: #e8638c;
  --blush: #f8d7e4;
  --glass: rgba(255, 252, 250, 0.5);
  --glass-border: rgba(255, 255, 255, 0.65);
  --shadow-rose: 0 24px 60px -22px rgba(216, 27, 96, 0.4);
  --font-display: "Cormorant Garamond", Georgia, serif;
  --font-hand: "Caveat", "Comic Sans MS", cursive;
  --font-type: "Special Elite", "Courier New", monospace;
}

/* ========== Base ========== */
* { -webkit-tap-highlight-color: transparent; }

body {
  font-family: var(--font-display);
  background: linear-gradient(165deg, #fff0f6 0%, #f8d7e4 48%, #fde8dc 100%);
  background-attachment: fixed;
  color: var(--ink);
  text-align: center;
  margin: 0;
  padding: 0;
  min-height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
  font-size: 1.5rem;
}
body.locked { overflow: hidden; }

::selection { background: rgba(216, 27, 96, 0.22); }

/* Soft film grain over everything */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 60;
  pointer-events: none;
  opacity: 0.045;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ========== Dreamy background glow ========== */
.bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}
.bg::before,
.bg::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  filter: blur(70px);
}
.bg::before {
  width: 60vmax; height: 60vmax;
  top: -22vmax; left: -16vmax;
  background: radial-gradient(circle, rgba(255, 178, 208, 0.55), transparent 65%);
  animation: drift1 26s ease-in-out infinite alternate;
}
.bg::after {
  width: 55vmax; height: 55vmax;
  bottom: -20vmax; right: -14vmax;
  background: radial-gradient(circle, rgba(255, 211, 176, 0.5), transparent 65%);
  animation: drift2 32s ease-in-out infinite alternate;
}
@keyframes drift1 {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to   { transform: translate3d(8vw, 6vh, 0) scale(1.12); }
}
@keyframes drift2 {
  from { transform: translate3d(0, 0, 0) scale(1.08); }
  to   { transform: translate3d(-7vw, -5vh, 0) scale(1); }
}

/* ========== Daytime sparkle dust + bokeh ========== */
.sparkles {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}
.sparkles span {
  position: absolute;
  border-radius: 50%;
  animation: twinkle ease-in-out infinite;
}

.bokeh {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}
.bokeh div {
  position: absolute;
  border-radius: 50%;
  filter: blur(7px);
  opacity: 0.32;
  animation: bokeh-drift ease-in-out infinite alternate;
}
.bokeh div:nth-child(1) { width: 110px; height: 110px; top: 12%; left: 6%;  background: radial-gradient(circle at 35% 35%, #ffc9dd, transparent 70%); animation-duration: 23s; }
.bokeh div:nth-child(2) { width: 70px;  height: 70px;  top: 28%; left: 78%; background: radial-gradient(circle at 35% 35%, #ffd9c4, transparent 70%); animation-duration: 27s; animation-delay: -6s; }
.bokeh div:nth-child(3) { width: 130px; height: 130px; top: 62%; left: 14%; background: radial-gradient(circle at 35% 35%, #f4c2ef, transparent 70%); animation-duration: 31s; animation-delay: -12s; }
.bokeh div:nth-child(4) { width: 56px;  height: 56px;  top: 75%; left: 70%; background: radial-gradient(circle at 35% 35%, #ffc9dd, transparent 70%); animation-duration: 21s; animation-delay: -3s; }
.bokeh div:nth-child(5) { width: 92px;  height: 92px;  top: 8%;  left: 46%; background: radial-gradient(circle at 35% 35%, #ffe3b8, transparent 70%); animation-duration: 25s; animation-delay: -16s; }
.bokeh div:nth-child(6) { width: 64px;  height: 64px;  top: 48%; left: 90%; background: radial-gradient(circle at 35% 35%, #f4c2ef, transparent 70%); animation-duration: 29s; animation-delay: -9s; }
.bokeh div:nth-child(7) { width: 84px;  height: 84px;  top: 85%; left: 40%; background: radial-gradient(circle at 35% 35%, #ffd9c4, transparent 70%); animation-duration: 24s; animation-delay: -19s; }
.bokeh div:nth-child(8) { width: 48px;  height: 48px;  top: 38%; left: 28%; background: radial-gradient(circle at 35% 35%, #ffc9dd, transparent 70%); animation-duration: 26s; animation-delay: -14s; }
@keyframes bokeh-drift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to   { transform: translate3d(5vw, -7vh, 0) scale(1.18); }
}

body.midnight .sparkles,
body.midnight .bokeh { display: none; }

/* ========== Falling petals ========== */
.petals {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  overflow: hidden;
}
.petal {
  position: absolute;
  top: -6vh;
  width: 15px; height: 15px;
  background: radial-gradient(circle at 30% 30%, #ffd6e5, #f297be);
  border-radius: 62% 38% 64% 36% / 58% 36% 64% 42%;
  opacity: 0.65;
  animation: fallA linear infinite;
}
.petal:nth-child(even) { animation-name: fallB; }
.petal:nth-child(1)  { left: 6%;  animation-duration: 15s; animation-delay: -3s;  width: 13px; height: 13px; }
.petal:nth-child(2)  { left: 16%; animation-duration: 19s; animation-delay: -9s;  width: 17px; height: 17px; }
.petal:nth-child(3)  { left: 27%; animation-duration: 13s; animation-delay: -6s; }
.petal:nth-child(4)  { left: 38%; animation-duration: 21s; animation-delay: -14s; width: 12px; height: 12px; }
.petal:nth-child(5)  { left: 49%; animation-duration: 16s; animation-delay: -2s;  width: 18px; height: 18px; }
.petal:nth-child(6)  { left: 58%; animation-duration: 18s; animation-delay: -11s; }
.petal:nth-child(7)  { left: 67%; animation-duration: 14s; animation-delay: -7s;  width: 13px; height: 13px; }
.petal:nth-child(8)  { left: 76%; animation-duration: 20s; animation-delay: -16s; width: 16px; height: 16px; }
.petal:nth-child(9)  { left: 86%; animation-duration: 15s; animation-delay: -4s; }
.petal:nth-child(10) { left: 94%; animation-duration: 17s; animation-delay: -12s; width: 12px; height: 12px; }
@keyframes fallA {
  0%   { transform: translate3d(0, 0, 0) rotate(0deg); }
  100% { transform: translate3d(7vw, 112vh, 0) rotate(340deg); }
}
@keyframes fallB {
  0%   { transform: translate3d(0, 0, 0) rotate(0deg); }
  100% { transform: translate3d(-6vw, 112vh, 0) rotate(-300deg); }
}

/* ========== LOCK SCREEN ========== */
#lock-screen {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 20;
  padding: 16px;
  box-sizing: border-box;
}

.lock-card {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: 30px;
  box-shadow: var(--shadow-rose);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  width: min(430px, calc(100vw - 40px));
  box-sizing: border-box;
  padding: 2.4rem 2rem 2rem;
  animation: card-rise 0.9s cubic-bezier(0.22, 1, 0.36, 1) both;
}
@keyframes card-rise {
  from { opacity: 0; transform: translateY(26px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.lock-emblem {
  font-size: 2.8rem;
  line-height: 1;
  margin-bottom: 0.9rem;
  animation: emblem-float 3.2s ease-in-out infinite;
  filter: drop-shadow(0 8px 14px rgba(216, 27, 96, 0.3));
}
@keyframes emblem-float {
  0%, 100% { transform: translateY(0) rotate(-3deg); }
  50%      { transform: translateY(-7px) rotate(3deg); }
}

#lock-text {
  font: italic 600 1.85rem/1.3 var(--font-display);
  color: var(--ink);
  margin: 0 0 1.3rem;
  min-height: 1.3em;
  white-space: pre-wrap;
}

/* Inputs */
input {
  font-family: var(--font-type);
  font-size: 1.05rem;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.55);
  border: 1.5px solid rgba(216, 27, 96, 0.25);
  border-radius: 999px;
  padding: 0.7rem 1.3rem;
  width: 100%;
  box-sizing: border-box;
  text-align: center;
  outline: none;
  letter-spacing: 0.06em;
  transition: border-color 0.25s ease, box-shadow 0.25s ease, background 0.25s ease;
}
input:focus {
  border-color: var(--rose);
  background: rgba(255, 255, 255, 0.8);
  box-shadow: 0 0 0 4px rgba(216, 27, 96, 0.14);
}
#password::placeholder { color: rgba(136, 14, 79, 0.4); letter-spacing: 0.04em; }

.hint {
  font-family: var(--font-type);
  opacity: 0.8;
  color: var(--rose);
  font-size: 0.88rem;
  line-height: 1.5;
  margin: 0.9rem 0 0;
}
.message {
  font-family: var(--font-type);
  margin: 0.7rem 0 0;
  color: var(--rose);
  font-size: 0.95rem;
}

.reveal-link {
  font-family: var(--font-hand);
  font-size: 1.45rem;
  margin-top: 1rem;
  color: var(--rose);
  text-decoration: none;
  cursor: pointer;
  display: inline-block;
  transition: transform 0.2s ease, color 0.2s ease;
}
.reveal-link:hover { color: var(--ink); transform: scale(1.06) rotate(-1.5deg); }

#revealMsg { display: block; }

#lock-screen.fade-out { opacity: 0; pointer-events: none; transition: opacity 0.6s ease; }

/* ========== MAIN CONTENT ========== */
#content {
  display: flex;
  flex-direction: column;
  justify-content: center;
  justify-content: safe center;   /* avoids top-clipping on tall poems */
  align-items: center;

  position: fixed;
  inset: 0;
  width: 100%;
  height: 100vh;       /* fallback */
  height: 100dvh;      /* mobile safe */
  box-sizing: border-box;
  padding: 68px 1rem 1rem;  /* top padding keeps heading clear of nav pills */
  overflow-y: auto;

  opacity: 0;
  transition: opacity 0.6s ease;
  z-index: 1;
}
#content.fade-in { opacity: 1; }

#content::-webkit-scrollbar { width: 6px; }
#content::-webkit-scrollbar-thumb { background: rgba(216, 27, 96, 0.3); border-radius: 6px; }
#content::-webkit-scrollbar-track { background: transparent; }

/* ========== Typewriter cursors ========== */
#lock-text::after, #birthday-message::after, #home-heading::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: 1em;
  background-color: var(--rose);
  margin-left: 6px;
  border-radius: 2px;
  vertical-align: -0.12em;
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 0%,50%{opacity:1} 50.01%,100%{opacity:0} }

#home-heading {
  cursor: pointer;
  font: italic 600 clamp(2.4rem, 6vw, 3.6rem)/1.15 var(--font-display);
  background: linear-gradient(120deg, #a40d45, #e8638c);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin: 0.6rem 0 0.8rem;
  filter: drop-shadow(0 6px 18px rgba(216, 27, 96, 0.2));
}

/* ========== Animations ========== */
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20%,60% { transform: translateX(-5px); }
  40%,80% { transform: translateX(5px); }
}
.shake { animation: shake 0.3s; border-color: var(--rose); }

/* ========== Utilities ========== */
.hidden { display: none; }

/* Timer pill */
#timer {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 32;
  font-family: var(--font-type);
  font-size: 0.95rem;
  color: var(--rose);
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  padding: 0.3rem 1rem;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 8px 22px -10px rgba(216, 27, 96, 0.35);
}
#timer::before { content: "♡ "; }

/* ========== Headings / Poem ========== */
h1 { font-size: 2rem; color: var(--rose); margin: 0 0 1rem; font-weight: normal; }

pre {
  white-space: pre-wrap;
  word-break: break-word;
  max-width: 100%;
  margin: 0;
}

#poem {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
  box-sizing: border-box;
}

/* The poem "paper" */
.poem-card {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: 26px;
  box-shadow: var(--shadow-rose);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  width: min(620px, calc(100vw - 36px));
  box-sizing: border-box;
  padding: 1.6rem 1.6rem 1.8rem;
  animation: card-rise 0.7s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.poem-card::before {
  content: "❀";
  display: block;
  font-size: 1.05rem;
  color: rgba(216, 27, 96, 0.45);
  margin-bottom: 0.8rem;
  letter-spacing: 0.5em;
}

#poem-text {
  display: block;
  margin: 0 auto;
  text-align: center;
  font-family: var(--font-display);
  font-size: 1.32rem;
  font-weight: 500;
  line-height: 1.7;
  color: var(--ink);
}

/* Tighter spacing while the table of contents is shown */
#poem-text.toc-mode {
  font-size: 1.1rem;
  line-height: 1.42;
}

/* Clickable poem titles on the home list — faint glowing underline */
.poem-link {
  color: var(--rose);
  font-weight: 600;
  cursor: pointer;
  padding: 0 0.25em 0.1em;
  border-radius: 0.5em 0.5em 0 0;
  text-decoration: none;
  border-bottom: 1.5px solid rgba(216, 27, 96, 0.35);
  box-shadow: 0 5px 9px -7px rgba(216, 27, 96, 0.85);
  transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, text-shadow 0.2s ease;
}
.poem-link:hover {
  background: rgba(216, 27, 96, 0.1);
  border-bottom-color: rgba(216, 27, 96, 0.75);
  box-shadow: 0 6px 12px -6px rgba(216, 27, 96, 1);
  text-shadow: 0 0 14px rgba(216, 27, 96, 0.35);
}
body.midnight .poem-link {
  border-bottom-color: rgba(255, 143, 184, 0.4);
  box-shadow: 0 5px 10px -7px rgba(255, 143, 184, 0.9);
}
body.midnight .poem-link:hover {
  border-bottom-color: rgba(255, 143, 184, 0.85);
  text-shadow: 0 0 14px rgba(255, 143, 184, 0.5);
}

/* Buttons hover dark in the dark */
body.midnight .pause-btn:hover,
body.midnight .poem-nav-btn:hover {
  background: rgba(62, 47, 102, 0.85);
}
body.midnight .pause-btn:disabled:hover { background: var(--glass); }

/* Final handwritten line */
#birthday-message {
  position: absolute;
  top: 75%;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  font-family: var(--font-hand);
  font-size: 2.1rem;
  color: var(--rose);
  white-space: nowrap;
}

/* Buttons */
button { all: unset; font-family: var(--font-type); cursor: pointer; }
button:focus { outline: none; }
button:focus-visible { outline: 2px solid rgba(216, 27, 96, 0.5); outline-offset: 3px; border-radius: 999px; }

/* Poem stage: arrows sit beside the card */
.poem-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  width: 100%;
}
.poem-nav-btn {
  font-size: 1.15rem;
  line-height: 1;
  color: var(--rose);
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: 50%;
  width: 46px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 10px 24px -12px rgba(216, 27, 96, 0.4);
  transition: transform 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}
.poem-nav-btn:hover {
  background: rgba(255, 255, 255, 0.75);
  transform: translateY(-2px) scale(1.06);
  box-shadow: 0 14px 28px -12px rgba(216, 27, 96, 0.5);
}
.poem-nav-btn:active { transform: translateY(0); }

/* Narrow screens: arrows drop below the card, centered together */
@media (max-width: 760px) {
  .poem-stage { flex-wrap: wrap; gap: 0 34px; }
  .poem-stage .poem-card { order: 1; }
  #back { order: 2; margin-top: 14px; }
  #next { order: 3; margin-top: 14px; }
}

/* Skip / Pause pills under the poem card */
.poem-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 14px;
}
.pause-btn {
  font-size: 0.9rem;
  color: var(--rose);
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  padding: 0.4rem 1.1rem;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 8px 20px -10px rgba(216, 27, 96, 0.35);
  transition: transform 0.2s ease, background 0.2s ease;
}
.pause-btn:hover { background: rgba(255, 255, 255, 0.75); transform: translateY(-1px); }
.left-actions {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 31;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
}
.left-actions .pause-btn { font-size: 0.95rem; padding: 0.45rem 1.25rem; }

/* ========== Poem gallery (parchment grid) ========== */
.gallery {
  position: fixed;
  inset: 0;
  z-index: 35;
  background: rgba(248, 215, 228, 0.72);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  overflow-y: auto;
  padding: 84px 22px 48px;
  box-sizing: border-box;
  animation: gallery-in 0.35s ease both;
}
@keyframes gallery-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.gallery.hidden { display: none; }

/* Close buttons sit in the flow, right under the content */
.overlay-close {
  display: block;
  margin: 1.6rem auto 0;
}

.gallery-title {
  font-family: var(--font-hand);
  font-size: 2rem;
  font-weight: 600;
  color: var(--rose);
  margin: 0 0 1.4rem;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 18px;
  max-width: 780px;
  margin: 0 auto;
}

.parchment {
  position: relative;
  display: block;
  box-sizing: border-box;
  text-align: center;
  background: linear-gradient(160deg, #fdf8ec, #f9ecd2 70%, #f3e2c0);
  border: 1px solid rgba(189, 154, 104, 0.35);
  border-radius: 14px 18px 12px 16px / 16px 12px 18px 14px;
  box-shadow:
    0 10px 24px -12px rgba(122, 74, 42, 0.45),
    inset 0 0 24px rgba(189, 154, 104, 0.18);
  padding: 1.4rem 1rem 1.2rem;
  cursor: pointer;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}
.parchment:nth-child(odd)  { transform: rotate(-0.8deg); }
.parchment:nth-child(even) { transform: rotate(0.7deg); }
.parchment:hover {
  transform: translateY(-6px) rotate(0deg) scale(1.04);
  box-shadow:
    0 20px 38px -14px rgba(216, 27, 96, 0.45),
    inset 0 0 24px rgba(189, 154, 104, 0.18);
}
.parchment h3 {
  font: italic 600 1.25rem/1.2 var(--font-display);
  color: #6d4a2a;
  margin: 0 0 0.5rem;
}
.parchment p {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 0.92rem;
  line-height: 1.45;
  color: rgba(109, 74, 42, 0.75);
  margin: 0;
  white-space: pre-line;
}
.parchment .seal {
  position: absolute;
  top: -10px;
  right: -8px;
  font-size: 1.3rem;
  transform: rotate(12deg);
  filter: drop-shadow(0 4px 8px rgba(216, 27, 96, 0.3));
}
.parchment.letter-card {
  background: linear-gradient(160deg, #fff2f6, #fbdde8 70%, #f7cdde);
  border-color: rgba(216, 27, 96, 0.3);
}
.parchment.letter-card h3 { color: #7c1d47; }
.parchment.letter-card p { color: rgba(124, 29, 71, 0.7); }

/* Composed date on the parchment cards */
.card-date {
  display: block;
  margin-top: 0.6rem;
  font-family: var(--font-type);
  font-size: 0.6rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(109, 74, 42, 0.5);
}
.parchment.letter-card .card-date { color: rgba(124, 29, 71, 0.45); }
body.midnight .parchment .card-date { color: rgba(234, 217, 251, 0.4); }
body.midnight .parchment.letter-card .card-date { color: rgba(255, 211, 227, 0.45); }

/* ========== Open when… envelopes ========== */
.envelope-grid { grid-template-columns: repeat(auto-fill, minmax(185px, 1fr)); }

/* Pager under the envelope grid */
.ow-pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 1.4rem;
}
.ow-page-label {
  font-family: var(--font-type);
  font-size: 0.85rem;
  letter-spacing: 0.1em;
  color: var(--rose);
}
.pause-btn:disabled { opacity: 0.35; cursor: default; }
.pause-btn:disabled:hover { transform: none; background: var(--glass); }

.envelope {
  position: relative;
  box-sizing: border-box;
  height: 150px;
  border-radius: 12px;
  background: linear-gradient(160deg, #fff0f6, #fbdde8);
  border: 1px solid rgba(216, 27, 96, 0.25);
  box-shadow: 0 10px 24px -12px rgba(216, 27, 96, 0.35);
  cursor: pointer;
  overflow: hidden;
  perspective: 320px;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}
.envelope:hover {
  transform: translateY(-5px);
  box-shadow: 0 18px 34px -14px rgba(216, 27, 96, 0.5);
}
.env-flap {
  position: absolute;
  left: 0; right: 0; top: 0;
  height: 44%;
  background: linear-gradient(180deg, #f7cdde, #f2b8d0);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: 50% 0;
  transition: transform 0.55s ease;
  z-index: 2;
}
.envelope.opened .env-flap { transform: rotateX(-178deg); }
.env-seal {
  position: absolute;
  top: 40%; left: 50%;
  transform: translate(-50%, -55%);
  z-index: 3;
  width: 30px; height: 30px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ff9fc2, #d81b60);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  box-shadow: 0 3px 8px rgba(136, 14, 79, 0.4);
  transition: opacity 0.35s ease, transform 0.35s ease;
}
.envelope.opened .env-seal { opacity: 0; transform: translate(-50%, -55%) scale(0.4); }
.env-label {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 52%;
  box-sizing: border-box;
  padding: 6px 10px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1;
  font-family: var(--font-type);
  font-size: 0.66rem;
  letter-spacing: 0.08em;
  color: rgba(124, 29, 71, 0.65);
}
.env-label em {
  display: block;
  font-family: var(--font-hand);
  font-style: normal;
  font-size: 1.22rem;
  line-height: 1.15;
  color: #7c1d47;
}

/* ========== Verse note modal ========== */
.note-modal {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  box-sizing: border-box;
  background: rgba(60, 20, 40, 0.35);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: gallery-in 0.3s ease both;
}
.note-modal.hidden { display: none; }
.note-paper {
  background: linear-gradient(160deg, #fdf8ec, #f7ebd0);
  border: 1px solid rgba(189, 154, 104, 0.4);
  border-radius: 18px;
  max-width: 430px;
  width: 100%;
  box-sizing: border-box;
  padding: 2rem 1.7rem 1.5rem;
  box-shadow:
    0 30px 60px -20px rgba(0, 0, 0, 0.45),
    inset 0 0 24px rgba(189, 154, 104, 0.18);
  animation: card-rise 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.note-label {
  font-family: var(--font-hand);
  font-size: 1.3rem;
  color: #c2185b;
  margin: 0 0 1rem;
}
.note-verse {
  font: italic 600 1.45rem/1.5 var(--font-display);
  color: #5d4023;
  margin: 0 0 0.6rem;
}
.note-ref {
  font-family: var(--font-type);
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(93, 64, 35, 0.7);
  margin: 0 0 1.1rem;
}
.note-extra {
  font-family: var(--font-hand);
  font-size: 1.4rem;
  color: #c2185b;
  margin: 0 0 1.3rem;
}

/* Standalone parchment poem reader — aged letter paper */
.poem-paper {
  max-width: 560px;
  max-height: min(82vh, 82dvh);
  overflow-y: auto;
  text-align: center;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='p'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 0.6 0 0 0 0 0.45 0 0 0 0 0.25 0 0 0 0.05 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23p)'/%3E%3C/svg%3E"),
    radial-gradient(ellipse at 16% 10%, rgba(189, 154, 104, 0.16), transparent 50%),
    radial-gradient(ellipse at 86% 92%, rgba(189, 154, 104, 0.2), transparent 55%),
    radial-gradient(ellipse at 68% 28%, rgba(255, 255, 255, 0.35), transparent 60%),
    linear-gradient(160deg, #fbf3e0, #f3e6c8 70%, #edd9b4);
  border: 1px solid rgba(168, 132, 82, 0.5);
  border-radius: 16px 22px 14px 20px / 20px 14px 22px 16px;  /* deckled edge */
  box-shadow:
    0 30px 60px -20px rgba(0, 0, 0, 0.5),
    inset 0 0 44px rgba(166, 124, 64, 0.22),
    inset 0 0 4px rgba(166, 124, 64, 0.2);
  /* opens plainly, no animation */
  animation: none;
  scrollbar-width: thin;
  scrollbar-color: rgba(141, 98, 42, 0.45) transparent;
}
.poem-paper::-webkit-scrollbar { width: 8px; }
.poem-paper::-webkit-scrollbar-thumb {
  background: rgba(141, 98, 42, 0.4);
  border-radius: 8px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.poem-paper::-webkit-scrollbar-track { background: transparent; }

/* little flourish at the top of the letter */
.pp-title::before {
  content: "❦";
  display: block;
  font-size: 1.05rem;
  color: rgba(141, 98, 42, 0.55);
  margin-bottom: 0.7rem;
}

body.midnight .poem-paper {
  background:
    radial-gradient(ellipse at 16% 10%, rgba(195, 177, 255, 0.12), transparent 50%),
    radial-gradient(ellipse at 86% 92%, rgba(195, 177, 255, 0.14), transparent 55%),
    linear-gradient(160deg, #443760, #34294b 70%, #2c2241);
  border-color: rgba(195, 177, 255, 0.38);
  box-shadow:
    0 30px 60px -20px rgba(0, 0, 0, 0.75),
    inset 0 0 44px rgba(130, 105, 195, 0.24);
  scrollbar-color: rgba(195, 177, 255, 0.4) transparent;
}
body.midnight .poem-paper::-webkit-scrollbar-thumb { background: rgba(195, 177, 255, 0.35); background-clip: padding-box; }
body.midnight .pp-title::before { color: rgba(195, 177, 255, 0.5); }
.pp-title {
  font: italic 600 1.7rem/1.2 var(--font-display);
  color: #5d4023;
  margin: 0 0 1rem;
}
body.midnight .pp-title { color: #ece0f8; }
.pp-text {
  font-family: var(--font-display);
  font-size: 1.18rem;
  font-weight: 500;
  line-height: 1.65;
  color: #5d4023;
  white-space: pre-wrap;
  margin: 0 0 1rem;
}
body.midnight .pp-text { color: #e4d6f2; }
/* composed date — pink so it stands out on the paper */
.note-paper .pp-date {
  margin-bottom: 1.2rem;
  color: #c2185b;
  font-size: 0.7rem;
  letter-spacing: 0.16em;
}
body.midnight .note-paper .pp-date { color: #ff9fc2; }
.pp-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 1rem;
}

/* Secrets page (easter egg tracker) */
.eggs-grid {
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  max-width: 640px;
}
.egg-card {
  box-sizing: border-box;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: 18px;
  padding: 1.1rem 0.7rem 1rem;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 10px 24px -14px rgba(216, 27, 96, 0.4);
}
.egg-card .big {
  display: block;
  font-size: 2rem;
  line-height: 1;
  margin-bottom: 0.5rem;
}
.egg-card .egg-label {
  font-family: var(--font-hand);
  font-size: 1.2rem;
  line-height: 1.2;
  color: var(--ink);
}
.egg-card.locked { opacity: 0.55; }
.egg-card.locked .egg-label { font-style: italic; }
.eggs-hint {
  font-family: var(--font-hand);
  font-size: 1.3rem;
  color: var(--rose);
  margin: 1.4rem 0 0;
}

/* Secrets page sits centered in the viewport */
#eggs.gallery:not(.hidden) {
  display: flex;
  flex-direction: column;
  justify-content: center;
  justify-content: safe center;
  align-items: center;
  padding-top: 24px;
}
#eggs .eggs-grid { width: 100%; }

/* ========== Midnight mode toggle + orange ========== */
/* Scenery toggle lives in the top bar, bigger than its neighbours */
.moon-btn {
  border-radius: 50%;
  padding: 0.55rem 0.65rem;
  font-size: 1.45rem !important;
  line-height: 1;
}
/* Pulse the moon while its tip is showing */
body.moon-tip-active .moon-btn {
  animation: moon-pulse 2.4s ease-in-out infinite;
}
@keyframes moon-pulse {
  0%, 100% { box-shadow: 0 8px 20px -10px rgba(216, 27, 96, 0.35); }
  50%      { box-shadow: 0 0 0 8px rgba(216, 27, 96, 0.18), 0 8px 20px -10px rgba(216, 27, 96, 0.35); }
}

/* Handwritten note + drawn arrow pointing UP at the scenery toggle.
   left/top are set by JS to track the button. */
.moon-tip {
  position: fixed;
  z-index: 34;
  cursor: pointer;
  animation: tip-bob 2.4s ease-in-out infinite;
  text-align: center;
  transform: translateX(-50%);
}
.moon-tip.hidden { display: none; }
.moon-tip p {
  font-family: var(--font-hand);
  font-weight: 600;
  font-size: 2rem;
  line-height: 1.12;
  color: var(--rose);
  margin: 0;
  transform: rotate(-6deg);
  text-shadow: 0 1px 10px rgba(255, 255, 255, 0.65);
}
body.midnight .moon-tip p { text-shadow: 0 1px 10px rgba(10, 5, 30, 0.8); }
.tip-arrow {
  position: absolute;
  width: 72px;
  height: 72px;
  left: 50%;       /* JS aims it precisely at the toggle */
  top: -64px;
  pointer-events: none;
}
.tip-arrow path {
  fill: none;
  stroke: var(--rose);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
@keyframes tip-bob {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50%      { transform: translateX(-50%) translateY(-6px); }
}

/* ========== Her constellation ========== */
#sky-stars {
  position: fixed;
  inset: 0;
  z-index: 4;
  pointer-events: none;
}
.her-star {
  all: unset;
  position: absolute;
  width: 26px;
  height: 26px;
  transform: translate(-50%, -50%);
  cursor: pointer;
  pointer-events: auto;
  filter: drop-shadow(0 0 7px rgba(255, 198, 110, 0.95)) drop-shadow(0 0 16px rgba(255, 150, 185, 0.55));
  transition: transform 0.2s ease;
}
.her-star:hover { transform: translate(-50%, -50%) scale(1.3); }
.her-star svg {
  width: 100%;
  height: 100%;
  display: block;
  animation: her-star-twinkle 4.2s ease-in-out infinite;
}
@keyframes her-star-twinkle {
  0%, 100% { transform: scale(1); opacity: 0.88; }
  50%      { transform: scale(1.16) rotate(8deg); opacity: 1; }
}
/* halo ring so her stars never blend into the background dust */
.her-star::before {
  content: "";
  position: absolute;
  inset: -7px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 205, 130, 0.55);
  animation: her-halo 3.4s ease-in-out infinite;
}
@keyframes her-halo {
  0%, 100% { transform: scale(0.9); opacity: 0.4; }
  50%      { transform: scale(1.15); opacity: 0.9; }
}

/* his stars: moonlit blue-lavender */
.her-star.star-aatir {
  filter: drop-shadow(0 0 7px rgba(140, 185, 255, 0.95)) drop-shadow(0 0 16px rgba(185, 168, 255, 0.6));
}
.her-star.star-aatir::before {
  border-color: rgba(165, 195, 255, 0.6);
}

/* daylight: deeper inks + bright white pop so stars never wash out on pink.
   the dark sky view keeps the glowing night palette in both modes. */
body:not(.midnight) #sky-stars .her-star svg path { fill: url(#her-star-grad-day); }
body:not(.midnight) #sky-stars .her-star {
  filter: drop-shadow(0 0 4px rgba(255, 255, 255, 0.95)) drop-shadow(0 0 10px rgba(194, 24, 91, 0.75));
}
body:not(.midnight) #sky-stars .her-star::before { border-color: rgba(163, 13, 73, 0.55); }
body:not(.midnight) #sky-stars .her-star.star-aatir svg path { fill: url(#aatir-star-grad-day); }
body:not(.midnight) #sky-stars .her-star.star-aatir {
  filter: drop-shadow(0 0 4px rgba(255, 255, 255, 0.95)) drop-shadow(0 0 10px rgba(80, 90, 220, 0.75));
}
body:not(.midnight) #sky-stars .her-star.star-aatir::before { border-color: rgba(80, 100, 220, 0.55); }

/* ========== Full-screen constellation view ========== */
.sky-view {
  position: fixed;
  inset: 0;
  z-index: 38;
  background:
    radial-gradient(ellipse at 72% 18%, rgba(125, 95, 205, 0.28), transparent 55%),
    radial-gradient(ellipse at 20% 80%, rgba(216, 27, 96, 0.12), transparent 55%),
    linear-gradient(170deg, #0d0920, #1d1538 60%, #120d28);
  animation: gallery-in 0.4s ease both;
}
.sky-view.hidden { display: none; }
#sky-lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
#sky-view-stars { position: absolute; inset: 0; }
#sky-view-stars .her-star { width: 30px; height: 30px; }
.sky-view-title {
  position: absolute;
  top: 22px;
  left: 0;
  right: 0;
  margin: 0;
  color: #ffd6e8;
  pointer-events: none; /* never block clicks on stars beneath */
}
.sky-count {
  position: absolute;
  top: 68px;
  left: 0;
  right: 0;
  margin: 0;
  text-align: center;
  font-family: var(--font-type);
  font-size: 0.82rem;
  letter-spacing: 0.12em;
  color: rgba(255, 214, 232, 0.65);
  pointer-events: none;
}
.sky-view-actions {
  position: absolute;
  bottom: calc(22px + env(safe-area-inset-bottom));
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 10px;
  pointer-events: none; /* the row never blocks stars; buttons stay clickable */
}
.sky-view-actions .pause-btn { pointer-events: auto; }
.sky-view .pause-btn {
  background: rgba(42, 30, 74, 0.65);
  border-color: rgba(255, 255, 255, 0.16);
  color: #ff9fc2;
}
.sky-view .pause-btn:hover { background: rgba(62, 47, 102, 0.85); }

#sky-overlay {
  position: fixed;
  inset: 0;
  z-index: 48;
  cursor: crosshair;
  background: rgba(255, 255, 255, 0.02);
}
#sky-overlay.hidden { display: none; }

.sky-banner {
  position: fixed;
  bottom: calc(26px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 49;
  margin: 0;
  font-family: var(--font-hand);
  font-size: 1.45rem;
  color: var(--rose);
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  padding: 0.5rem 1.4rem;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 12px 28px -12px rgba(216, 27, 96, 0.45);
  white-space: nowrap;
  animation: floaty-banner 2s ease-in-out infinite;
}
.sky-banner.hidden { display: none; }
@keyframes floaty-banner {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50%      { transform: translateX(-50%) translateY(-5px); }
}

.sky-paper .sky-text {
  font-family: var(--font-hand);
  font-size: 1.5rem;
  line-height: 1.3;
  color: var(--ink);
  margin: 0 0 0.7rem;
}
.sky-paper .sky-text em { color: var(--rose); font-style: normal; font-weight: 600; }
.sky-paper .sky-text.small { font-size: 1.15rem; opacity: 0.75; }
.note-paper.sky-paper {
  background: linear-gradient(160deg, #fff2f6, #fbdde8 70%, #f7cdde);
  border-color: rgba(216, 27, 96, 0.3);
}
body.midnight .note-paper.sky-paper {
  background: linear-gradient(160deg, #3d3158, #2f2548);
  border-color: rgba(195, 177, 255, 0.32);
}
body.midnight .sky-paper .sky-text { color: #f0e4fa; }

/* Hidden Chinese word eggs — they pulse softly to catch the eye */
.zh-egg {
  all: unset;
  position: fixed;
  z-index: 4;
  font-size: 0.9rem;
  color: rgba(136, 14, 79, 0.55);
  cursor: pointer;
  letter-spacing: 0.06em;
  transition: color 0.25s ease, opacity 0.6s ease;
  writing-mode: vertical-rl;
  animation: zh-pulse 3s ease-in-out infinite;
}
@keyframes zh-pulse {
  0%, 100% { opacity: 0.3; text-shadow: none; }
  50%      { opacity: 0.95; text-shadow: 0 0 12px rgba(216, 27, 96, 0.55); }
}
.zh-egg:hover { color: rgba(216, 27, 96, 0.85); }
.zh-egg.fading { animation: none; opacity: 0; pointer-events: none; }
/* Arabic name eggs read horizontally, noticeably larger */
.zh-egg.ar-egg {
  writing-mode: horizontal-tb;
  font-size: 1.6rem;
}
body.midnight .zh-egg { color: rgba(243, 220, 234, 0.22); }
body.midnight .zh-egg:hover { color: rgba(255, 143, 184, 0.8); }

/* Roaming oranges, hiding in plain sight */
.orange-roam {
  all: unset;
  position: fixed;
  z-index: 4;
  font-size: 0.95rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0.45;
  animation: orange-peek 6s ease-in-out infinite;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.orange-roam:hover { opacity: 1; transform: scale(1.25) rotate(10deg); }

/* A proper little jiggle every few seconds */
@keyframes orange-peek {
  0%, 74%, 100% { transform: rotate(-8deg); }
  78%           { transform: rotate(10deg) scale(1.12); }
  82%           { transform: rotate(-12deg) scale(1.05); }
  86%           { transform: rotate(8deg) scale(1.1); }
  90%           { transform: rotate(-8deg); }
}

.orange-toast {
  position: fixed;
  bottom: 64px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  z-index: 46;
  font-family: var(--font-hand);
  font-size: 1.45rem;
  color: #c2185b;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  padding: 0.5rem 1.4rem;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 12px 28px -12px rgba(216, 27, 96, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease, transform 0.4s ease;
  white-space: nowrap;
  margin: 0;
}
.orange-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
/* Bubble pinned next to the thing that was clicked */
.orange-toast.at-point {
  bottom: auto;
  transform: translate(-50%, calc(-100% - 6px));
  white-space: normal;
  max-width: min(260px, 80vw);
  text-align: center;
  border-radius: 16px;
}
.orange-toast.at-point.show { transform: translate(-50%, calc(-100% - 12px)); }

/* ========== Midnight sky (stars, moon, fireflies) ========== */
.stars, .moon, .fireflies { display: none; }

.stars {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}
.stars span {
  position: absolute;
  background: #fff;
  border-radius: 50%;
  animation: twinkle 3s ease-in-out infinite;
}
@keyframes twinkle {
  0%, 100% { opacity: 0.15; }
  50%      { opacity: 0.95; }
}

.moon {
  position: fixed;
  top: 52px;
  right: 70px;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  z-index: 1;
  pointer-events: none;
  background: transparent;
  box-shadow: inset -16px 7px 0 0 #f6e7c8;
  filter: drop-shadow(0 0 18px rgba(246, 231, 200, 0.55));
  transform: rotate(-18deg);
}

.fireflies {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  overflow: hidden;
}
.firefly {
  position: absolute;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: #ffe9a3;
  box-shadow: 0 0 10px 3px rgba(255, 233, 163, 0.7);
  animation: wanderA 16s ease-in-out infinite alternate, flicker 2.6s ease-in-out infinite;
}
.firefly:nth-child(even) { animation-name: wanderB, flicker; }
.firefly:nth-child(1)  { top: 22%; left: 12%; animation-duration: 17s, 2.2s; }
.firefly:nth-child(2)  { top: 65%; left: 20%; animation-duration: 13s, 3.1s; animation-delay: -4s, 0.4s; }
.firefly:nth-child(3)  { top: 35%; left: 32%; animation-duration: 19s, 2.7s; animation-delay: -8s, 1s; }
.firefly:nth-child(4)  { top: 78%; left: 45%; animation-duration: 14s, 2.3s; animation-delay: -2s, 0.7s; }
.firefly:nth-child(5)  { top: 18%; left: 58%; animation-duration: 16s, 3.4s; animation-delay: -10s, 0.2s; }
.firefly:nth-child(6)  { top: 55%; left: 68%; animation-duration: 12s, 2.5s; animation-delay: -6s, 1.3s; }
.firefly:nth-child(7)  { top: 30%; left: 82%; animation-duration: 18s, 2.9s; animation-delay: -12s, 0.5s; }
.firefly:nth-child(8)  { top: 72%; left: 88%; animation-duration: 15s, 2.1s; animation-delay: -3s, 0.9s; }
.firefly:nth-child(9)  { top: 48%; left: 8%;  animation-duration: 20s, 3.2s; animation-delay: -14s, 0.3s; }
.firefly:nth-child(10) { top: 85%; left: 30%; animation-duration: 13s, 2.6s; animation-delay: -7s, 1.1s; }
.firefly:nth-child(11) { top: 12%; left: 74%; animation-duration: 17s, 2.4s; animation-delay: -9s, 0.6s; }
.firefly:nth-child(12) { top: 60%; left: 52%; animation-duration: 14s, 3s;   animation-delay: -5s, 1.4s; }
@keyframes wanderA {
  from { transform: translate3d(0, 0, 0); }
  to   { transform: translate3d(12vw, -16vh, 0); }
}
@keyframes wanderB {
  from { transform: translate3d(0, 0, 0); }
  to   { transform: translate3d(-13vw, 14vh, 0); }
}
@keyframes flicker {
  0%, 100% { opacity: 0.15; }
  50%      { opacity: 1; }
}

/* ========== MIDNIGHT MODE (chaand raat) ========== */
body.midnight {
  --ink: #f3dcea;
  --rose: #ff8fb8;
  --glass: rgba(40, 28, 70, 0.55);
  --glass-border: rgba(255, 255, 255, 0.14);
  --shadow-rose: 0 24px 60px -22px rgba(8, 4, 26, 0.85);
  background: linear-gradient(170deg, #141029 0%, #251a45 55%, #1b1335 100%);
}
body.midnight .stars,
body.midnight .moon { display: block; }
body.midnight .fireflies { display: block; }
body.midnight .petals { display: none; }
body.midnight .bg::before { background: radial-gradient(circle, rgba(125, 95, 205, 0.3), transparent 65%); }
body.midnight .bg::after  { background: radial-gradient(circle, rgba(80, 65, 170, 0.28), transparent 65%); }
body.midnight #home-heading {
  background: linear-gradient(120deg, #ffaecb, #c3b1ff);
  -webkit-background-clip: text;
  background-clip: text;
  filter: drop-shadow(0 6px 18px rgba(195, 177, 255, 0.25));
}
body.midnight input {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 143, 184, 0.35);
  color: var(--ink);
}
body.midnight input:focus {
  background: rgba(255, 255, 255, 0.14);
  box-shadow: 0 0 0 4px rgba(255, 143, 184, 0.18);
}
body.midnight #password::placeholder { color: rgba(243, 220, 234, 0.4); }
body.midnight .poem-link:hover { background: rgba(255, 143, 184, 0.16); }
body.midnight .butterfly { opacity: 0.4; filter: brightness(1.7) saturate(0.7); }
body.midnight .gallery { background: rgba(18, 12, 38, 0.72); }
body.midnight .orange-toast { color: #ffb27a; }
body.midnight .lock-emblem { filter: drop-shadow(0 8px 14px rgba(195, 177, 255, 0.35)); }

/* Midnight: parchment becomes moonlit paper */
body.midnight .parchment {
  background: linear-gradient(160deg, #3b3052, #2f2645 70%, #281f3c);
  border-color: rgba(195, 177, 255, 0.28);
  box-shadow:
    0 10px 24px -12px rgba(0, 0, 0, 0.65),
    inset 0 0 24px rgba(130, 105, 195, 0.18);
}
body.midnight .parchment:hover {
  box-shadow:
    0 20px 38px -14px rgba(255, 143, 184, 0.4),
    inset 0 0 24px rgba(130, 105, 195, 0.18);
}
body.midnight .parchment h3 { color: #ead9fb; }
body.midnight .parchment p { color: rgba(234, 217, 251, 0.65); }
body.midnight .parchment.letter-card {
  background: linear-gradient(160deg, #4a2a44, #3c2138 70%, #311c30);
  border-color: rgba(255, 143, 184, 0.35);
}
body.midnight .parchment.letter-card h3 { color: #ffd3e3; }
body.midnight .parchment.letter-card p { color: rgba(255, 211, 227, 0.7); }

/* Midnight: envelopes under moonlight */
body.midnight .envelope {
  background: linear-gradient(160deg, #3c2d54, #2f2346);
  border-color: rgba(255, 143, 184, 0.28);
  box-shadow: 0 10px 24px -12px rgba(0, 0, 0, 0.6);
}
body.midnight .envelope:hover { box-shadow: 0 18px 34px -14px rgba(255, 143, 184, 0.45); }
body.midnight .env-flap { background: linear-gradient(180deg, #4c3a6b, #3e2f59); }
body.midnight .env-label { color: rgba(243, 220, 234, 0.55); }
body.midnight .env-label em { color: #f3dcea; }

/* Midnight: verse note */
body.midnight .note-modal { background: rgba(8, 4, 22, 0.55); }
body.midnight .note-paper {
  background: linear-gradient(160deg, #3d3158, #2f2548);
  border-color: rgba(195, 177, 255, 0.32);
  box-shadow:
    0 30px 60px -20px rgba(0, 0, 0, 0.75),
    inset 0 0 24px rgba(130, 105, 195, 0.2);
}
body.midnight .note-verse { color: #ece0f8; }
body.midnight .note-ref { color: rgba(236, 224, 248, 0.6); }
body.midnight .note-label,
body.midnight .note-extra { color: #ff9fc2; }

/* ========== Heart burst (on unlock) ========== */
.heart-burst {
  position: fixed;
  inset: 0;
  z-index: 40;
  pointer-events: none;
  overflow: hidden;
}
.heart-burst span {
  position: absolute;
  bottom: -8vh;
  opacity: 0;
  animation: rise-heart cubic-bezier(0.25, 0.4, 0.45, 1) forwards;
}
@keyframes rise-heart {
  0%   { transform: translate(0, 0) scale(0.5) rotate(0deg); opacity: 0; }
  10%  { opacity: 1; }
  70%  { opacity: 0.9; }
  100% { transform: translate(var(--drift, 0px), -112vh) scale(var(--scale, 1.1)) rotate(var(--spin, 18deg)); opacity: 0; }
}

/* ========== Optimized CSS Butterflies ========== */
.butterfly-container {
  position: fixed;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  contain: strict;
  overflow: hidden;
}

.butterfly {
  position: absolute;
  width: 48px;
  height: 48px;
  opacity: 0.85;
  pointer-events: none;
  /* will-change is rotated via JS to max 4 at a time */
}

/* Size/depth variations */
.butterfly:nth-child(1) { --size: 52px; opacity: 0.9; }
.butterfly:nth-child(2) { --size: 44px; opacity: 0.75; }
.butterfly:nth-child(3) { --size: 56px; opacity: 0.95; }
.butterfly:nth-child(4) { --size: 40px; opacity: 0.7; }
.butterfly:nth-child(5) { --size: 50px; opacity: 0.85; }
.butterfly:nth-child(6) { --size: 46px; opacity: 0.8; }
.butterfly:nth-child(7) { --size: 54px; opacity: 0.9; }
.butterfly:nth-child(8) { --size: 42px; opacity: 0.75; }
.butterfly:nth-child(9) { --size: 48px; opacity: 0.85; }
.butterfly:nth-child(10) { --size: 38px; opacity: 0.7; }
.butterfly:nth-child(11) { --size: 52px; opacity: 0.9; }
.butterfly:nth-child(12) { --size: 44px; opacity: 0.75; }

.butterfly {
  width: var(--size, 48px);
  height: var(--size, 48px);
}

/* Starting positions (spread across viewport using %) */
.butterfly:nth-child(1)  { top: 5%;  left: 8%; }
.butterfly:nth-child(2)  { top: 15%; left: 75%; }
.butterfly:nth-child(3)  { top: 30%; left: 20%; }
.butterfly:nth-child(4)  { top: 45%; left: 85%; }
.butterfly:nth-child(5)  { top: 60%; left: 12%; }
.butterfly:nth-child(6)  { top: 70%; left: 60%; }
.butterfly:nth-child(7)  { top: 20%; left: 45%; }
.butterfly:nth-child(8)  { top: 80%; left: 30%; }
.butterfly:nth-child(9)  { top: 10%; left: 90%; }
.butterfly:nth-child(10) { top: 55%; left: 5%; }
.butterfly:nth-child(11) { top: 35%; left: 70%; }
.butterfly:nth-child(12) { top: 85%; left: 55%; }

/* Flight path assignments via data attribute */
.butterfly[data-flight="1"] { animation: flight1 28s linear infinite; }
.butterfly[data-flight="2"] { animation: flight2 32s linear infinite; }
.butterfly[data-flight="3"] { animation: flight3 26s linear infinite; }

/* Stagger animation starts */
.butterfly:nth-child(2)  { animation-delay: -4s; }
.butterfly:nth-child(3)  { animation-delay: -8s; }
.butterfly:nth-child(4)  { animation-delay: -12s; }
.butterfly:nth-child(5)  { animation-delay: -16s; }
.butterfly:nth-child(6)  { animation-delay: -20s; }
.butterfly:nth-child(7)  { animation-delay: -3s; }
.butterfly:nth-child(8)  { animation-delay: -7s; }
.butterfly:nth-child(9)  { animation-delay: -11s; }
.butterfly:nth-child(10) { animation-delay: -15s; }
.butterfly:nth-child(11) { animation-delay: -19s; }
.butterfly:nth-child(12) { animation-delay: -23s; }

/* GPU-optimized flight paths using translate3d and percentages (no vw/vh) */
@keyframes flight1 {
  0%   { transform: translate3d(0, 0, 0) rotate(0deg); }
  25%  { transform: translate3d(calc(60vw - 100%), calc(25vh - 50%), 0) rotate(45deg); }
  50%  { transform: translate3d(calc(80vw - 100%), calc(70vh - 50%), 0) rotate(90deg); }
  75%  { transform: translate3d(calc(20vw - 50%), calc(85vh - 100%), 0) rotate(135deg); }
  100% { transform: translate3d(0, 0, 0) rotate(180deg); }
}

@keyframes flight2 {
  0%   { transform: translate3d(0, 0, 0) rotate(0deg); }
  25%  { transform: translate3d(calc(-40vw + 50%), calc(35vh - 50%), 0) rotate(-30deg); }
  50%  { transform: translate3d(calc(30vw - 50%), calc(60vh - 50%), 0) rotate(60deg); }
  75%  { transform: translate3d(calc(-20vw + 25%), calc(20vh - 25%), 0) rotate(120deg); }
  100% { transform: translate3d(0, 0, 0) rotate(180deg); }
}

@keyframes flight3 {
  0%   { transform: translate3d(0, 0, 0) rotate(0deg); }
  20%  { transform: translate3d(calc(50vw - 50%), calc(-15vh + 25%), 0) rotate(-45deg); }
  40%  { transform: translate3d(calc(70vw - 75%), calc(45vh - 50%), 0) rotate(30deg); }
  60%  { transform: translate3d(calc(25vw - 25%), calc(75vh - 75%), 0) rotate(90deg); }
  80%  { transform: translate3d(calc(-10vw + 10%), calc(40vh - 40%), 0) rotate(150deg); }
  100% { transform: translate3d(0, 0, 0) rotate(180deg); }
}

/* Hide extra butterflies on mobile (keep 8 max) */
.butterfly.mobile-hidden {
  display: block;
}

@media (max-width: 480px) {
  .butterfly.mobile-hidden {
    display: none;
  }
  .butterfly {
    opacity: 0.6;
  }
}

/* ========== MOBILE TUNING (≤ 480px) ========== */
@media (max-width: 480px) {
  html, body { font-size: 15px; }

  /* room for the wrapped top bar */
  #content { padding-top: 96px; }

  .lock-card { padding: 2rem 1.4rem 1.7rem; border-radius: 26px; }
  .lock-emblem { font-size: 2.3rem; }
  #lock-text { font-size: 1.45rem; }

  #home-heading { margin-top: 0.5rem; }

  .poem-card { padding: 1.4rem 1.1rem 1.6rem; border-radius: 22px; }
  #poem-text {
    font-size: 1.08rem;
    line-height: 1.65;
  }
  #poem-text.toc-mode { font-size: 0.98rem; line-height: 1.4; }
  #poem { padding-bottom: calc(56px + env(safe-area-inset-bottom)); }

  .poem-nav-btn { width: 42px; height: 42px; font-size: 1.05rem; }

  #timer {
    bottom: calc(env(safe-area-inset-bottom) + 14px);
    font-size: 0.88rem;
  }

  #birthday-message { font-size: 1.55rem; }

  .left-actions {
    top: 8px;
    width: calc(100vw - 16px);
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
  }
  .left-actions .pause-btn { font-size: 0.78rem; padding: 0.3rem 0.75rem; }
  .pause-btn { font-size: 0.85rem; padding: 0.35rem 0.9rem; }
  .gallery { padding: 70px 14px 36px; }
  .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
  .envelope-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .envelope { height: 134px; }
  .env-label em { font-size: 1.05rem; }
  .gallery-title { font-size: 1.7rem; }

  .moon-btn { font-size: 1.25rem !important; padding: 0.4rem 0.5rem; }
  .moon-tip p { font-size: 1.05rem; }
  .tip-arrow { width: 46px; height: 46px; top: -42px; }
  .moon { top: 64px; right: 30px; width: 44px; height: 44px; box-shadow: inset -11px 5px 0 0 #f6e7c8; }
  .note-verse { font-size: 1.25rem; }

  /* iOS: 16px inputs prevent the auto-zoom on focus */
  input { font-size: 16px; }

  /* lighter effects for mobile GPUs */
  .bg::before, .bg::after { filter: blur(38px); width: 70vmax; height: 70vmax; }
  .bokeh div:nth-child(n+5) { display: none; }
  .poem-paper { max-height: min(78vh, 78dvh); }
  .pp-text { font-size: 1.02rem; }
  .pp-title { font-size: 1.4rem; }
  .eggs-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
  .egg-card .big { font-size: 1.6rem; }
  .egg-card .egg-label { font-size: 1rem; }
  .eggs-hint { font-size: 1.1rem; }
  .ow-pager { flex-wrap: wrap; gap: 10px; }
}

/* ========== Reduced motion ========== */
@media (prefers-reduced-motion: reduce) {
  .bg::before, .bg::after,
  .petal,
  .lock-emblem,
  .update-note,
  .heart-burst span,
  .stars span,
  .firefly,
  .sparkles span,
  .bokeh div,
  .moon-tip,
  .orange-roam,
  .zh-egg {
    animation: none !important;
  }
  .petals, .heart-burst { display: none; }
  .butterfly {
    animation: none !important;
    opacity: 0.5;
  }
}
