/* ═══════════════════════════════════════════════════════════════
   DIGITAL LETTER — style.css
   "Words that stay, long after the moment."
   ═══════════════════════════════════════════════════════════════ */

/* ── Google Fonts ─────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,300;0,400;0,600;1,300;1,400;1,600&family=EB+Garamond:ital,wght@0,400;0,500;1,400;1,500&family=Caveat:wght@400;500;700&family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;1,9..40,300&family=Sacramento&family=DM+Serif+Display:ital@0;1&display=swap');

/* ── CSS Reset ────────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ══════════════════════════════════════════════════════════════
   THEME TOKENS
   ══════════════════════════════════════════════════════════════ */
:root {
  /* Default: blush-cream */
  --bg: #fdf6ee;
  --bg-card: #fef9f3;
  --bg-card2: #fffdf8;
  --text: #2c1b14;
  /* Deep espresso / darker ink */
  --text-light: #7a5c4d;
  --text-faint: #c4a898;
  --accent: #d4a5a5;
  --accent-soft: #f0d6d6;
  --gold: #c9a96e;
  --gold-soft: #e8d5b0;
  --shadow: rgba(180, 120, 100, 0.10);
  --shadow-deep: rgba(100, 60, 40, 0.14);
  --border: rgba(212, 165, 165, 0.25);
  --tape-color: rgba(212, 185, 165, 0.38);

  /* Typography */
  --font-display: 'Cormorant Garamond', serif;
  --font-body: 'Caveat', cursive;
  --font-script: 'Caveat', cursive;
  --font-ui: 'DM Sans', system-ui, sans-serif;
  --font-signature: 'Sacramento', cursive;

  /* Spacing */
  --letter-max-width: 820px;
  --letter-padding-v: 4.5rem;
  --letter-padding-h: 5.5rem;
  --letter-padding-h-mobile: 1.85rem;

  /* Envelope Default (Blush) */
  --env-bg: #ecdccb;
  --env-fold: #d1bba4;
  /* Darkened even more */
  --env-fold-bottom: #c4ab92;
  /* Darkened even more */
  --env-flap-open: #dfcebd;
  --env-label-bg: #faf7f2;
  --env-border: rgba(180, 150, 130, 0.45);
  --env-shadow: rgba(160, 130, 110, 0.2);
  --env-texture-opacity: 0.08;

  /* Default Seal Colors */
  --seal-bg: #bf4c30;
  --seal-inner: #8b2d1a;
  --seal-accent: #a83a23;
  --seal-text: #fde8e0;
}

/* ── Sage Theme ────────────────────────────────────────────────── */
[data-theme="sage"] {
  --bg: #f4f7f2;
  --bg-card: #f8faf6;
  --bg-card2: #fafcf9;
  --text: #2d3a2e;
  --text-light: #6a856b;
  --text-faint: #a8c4a9;
  --accent: #7a9e7e;
  --accent-soft: #cce0cd;
  --gold: #a89468;
  --gold-soft: #d9cfa8;
  --shadow: rgba(80, 120, 80, 0.09);
  --tape-color: rgba(180, 210, 180, 0.38);

  /* Envelope Sage */
  --env-bg: #e6ede5;
  --env-fold: #dee6dd;
  --env-fold-bottom: #f0f4ef;
  --env-flap-open: #d8e0d7;
  --env-label-bg: #f8faf7;
  --env-border: rgba(122, 158, 126, 0.2);
  --env-shadow: rgba(80, 100, 80, 0.1);
}

/* ── Dusty Rose Theme ─────────────────────────────────────────── */
[data-theme="dusty-rose"] {
  --bg: #fdf0f0;
  --bg-card: #fff5f5;
  --bg-card2: #fffafb;
  --text: #2b1820;
  /* Deep blackberry / darker ink */
  --text-light: #804051;
  --text-faint: #c49898;
  --accent: #c4858a;
  --accent-soft: #f0cccd;
  --gold: #c9a96e;
  --gold-soft: #e8d5b0;
  --shadow: rgba(180, 100, 110, 0.10);
  --tape-color: rgba(212, 165, 170, 0.38);

  /* Envelope Rose */
  --env-bg: #f2e4e4;
  --env-fold: #dbbfbf;
  /* Darkened even more */
  --env-fold-bottom: #c9a9a9;
  /* Darkened even more */
  --env-flap-open: #dfcece;
  --env-label-bg: #fffafa;
  --env-border: rgba(196, 133, 138, 0.3);
  --env-shadow: rgba(180, 130, 130, 0.15);
}

/* ── Midnight Theme ───────────────────────────────────────────── */
[data-theme="midnight"] {
  --bg: #0f1729;
  --bg-card: #141e35;
  --bg-card2: #18243e;
  --text: #e8dcc8;
  --text-light: #a0947c;
  --text-faint: #5a5040;
  --accent: #6b8cba;
  --accent-soft: #2a3d5c;
  --gold: #c9a96e;
  --gold-soft: #4a3820;
  --shadow: rgba(0, 0, 0, 0.35);
  --shadow-deep: rgba(0, 0, 0, 0.5);
  --border: rgba(107, 140, 186, 0.18);
  --tape-color: rgba(107, 140, 186, 0.25);

  /* Envelope Midnight (Midnight Blue) */
  --env-bg: #141e35;
  --env-fold: #18243e;
  --env-fold-bottom: #1c2b4a;
  --env-flap-open: #0f1729;
  --env-label-bg: #141e35;
  --env-border: rgba(107, 140, 186, 0.2);
  --env-shadow: rgba(0, 0, 0, 0.4);
  --env-texture-opacity: 0.03;
  --text: #e8dcc8;
  /* Goldish text */

  /* Seal Midnight (Deep Red) */
  --seal-bg: #9b1c2e;
  --seal-inner: #7a1220;
  --seal-accent: #c94060;
  --seal-text: #fde8e8;
}

/* ── Crimson Theme ────────────────────────────────────────────── */
[data-theme="crimson"] {
  --bg: #1a050a;
  --bg-card: #250810;
  --bg-card2: #2d0a14;
  --text: #f8e8e0;
  --text-light: #d4a090;
  --text-faint: #8a4a40;
  --accent: #c03050;
  --accent-soft: #4d0f1a;
  --gold: #d4a780;
  --gold-soft: #5a2a1a;
  --shadow: rgba(0, 0, 0, 0.35);
  --shadow-deep: rgba(0, 0, 0, 0.55);
  --border: rgba(192, 48, 80, 0.25);
  --tape-color: rgba(192, 48, 80, 0.3);

  /* Envelope Crimson */
  --env-bg: #250810;
  --env-fold: #2d0a14;
  --env-fold-bottom: #350c18;
  --env-flap-open: #1a050a;
  --env-label-bg: #250810;
  --env-border: rgba(192, 48, 80, 0.28);
  --env-shadow: rgba(0, 0, 0, 0.45);
  --env-texture-opacity: 0.02;

  /* Seal Crimson (Wine Red) */
  --seal-bg: #a82035;
  --seal-inner: #8b1828;
  --seal-accent: #d04060;
  --seal-text: #f8e8e0;
}

/* ── Obsidian Theme ───────────────────────────────────────────── */
[data-theme="obsidian"] {
  --bg: #050a07;
  --bg-card: #0a100c;
  --bg-card2: #0e1610;
  --text: #d8e8d0;
  --text-light: #6a9870;
  --text-faint: #2a4830;
  --accent: #2d6a4f;
  --accent-soft: #0d2018;
  --gold: #7ab89a;
  --gold-soft: #152a1e;
  --shadow: rgba(0, 0, 0, 0.45);
  --shadow-deep: rgba(0, 0, 0, 0.65);
  --border: rgba(45, 106, 79, 0.22);
  --tape-color: rgba(45, 106, 79, 0.28);

  /* Envelope Obsidian */
  --env-bg: #0a100c;
  --env-fold: #0e1610;
  --env-fold-bottom: #121c14;
  --env-flap-open: #050a07;
  --env-label-bg: #0a100c;
  --env-border: rgba(45, 106, 79, 0.25);
  --env-shadow: rgba(0, 0, 0, 0.55);
  --env-texture-opacity: 0.03;

  /* Seal Obsidian (Emerald/Gold) */
  --seal-bg: #2d6a4f;
  --seal-inner: #1b4332;
  --seal-accent: #52b788;
  --seal-text: #d8e8d0;
}

/* ══════════════════════════════════════════════════════════════
   BASE
   ══════════════════════════════════════════════════════════════ */
html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  font-size: 18px;
  line-height: 1.75;
  color: var(--text);
  background-color: var(--bg);
  min-height: 100%;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.4s ease, color 0.4s ease;
}

/* Subtle paper noise overlay */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.032;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.72' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 200px 200px;
}

/* ══════════════════════════════════════════════════════════════
   TYPOGRAPHY UTILITIES
   ══════════════════════════════════════════════════════════════ */
.font-caveat { font-family: 'Caveat', cursive !important; }
.font-dancing { font-family: 'Dancing Script', cursive !important; }
.font-shadows { font-family: 'Shadows Into Light', cursive !important; }
.font-indie { font-family: 'Indie Flower', cursive !important; }
.font-cormorant { font-family: 'Cormorant Garamond', serif !important; }
.font-dmsans { font-family: 'DM Sans', sans-serif !important; }
.font-sacramento { font-family: 'Sacramento', cursive !important; font-size: 1.4em; } /* Sacramento needs to be slightly larger */

.size-small { font-size: 1.15rem !important; line-height: 1.6 !important; }
.size-medium { font-size: 1.42rem !important; line-height: 1.95 !important; }
.size-large { font-size: 1.75rem !important; line-height: 2.1 !important; }

/* ══════════════════════════════════════════════════════════════
   STATE SCREENS
   ══════════════════════════════════════════════════════════════ */
.state-screen {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  width: 100%;
}

.state-screen.hidden {
  display: none !important;
}

/* ══════════════════════════════════════════════════════════════
   MAINTENANCE STATE
   ══════════════════════════════════════════════════════════════ */
#state-maintenance {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  text-align: center;
  background-color: var(--bg);
}

.maintenance-content {
  max-width: 450px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  animation: fadeUp 1s ease both;
}

.maint-icon {
  width: 64px;
  height: 64px;
  margin-bottom: 0.5rem;
  opacity: 0.8;
}

#state-maintenance h1 {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 2.2rem;
  font-weight: 400;
  color: var(--text);
  margin: 0;
}

#state-maintenance p {
  font-family: var(--font-ui);
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--text-light);
  margin: 0;
  opacity: 0.8;
}

.maint-footer {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-family: var(--font-ui);
  font-size: 0.65rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-top: 1rem;
}

.maint-footer .dot {
  width: 3px;
  height: 3px;
  background: var(--gold);
  border-radius: 50%;
  opacity: 0.5;
}

/* ══════════════════════════════════════════════════════════════
   LOADING STATE
   ══════════════════════════════════════════════════════════════ */
#state-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  min-height: 100vh;
}

.loading-emblem {
  width: 72px;
  height: 72px;
  opacity: 0.75;
}

.loading-ring {
  transform-origin: 30px 30px;
  animation: spin-slow 10s linear infinite;
}

.loading-label {
  font-family: var(--font-ui);
  font-size: 0.65rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--text-faint);
  animation: breathe 2.5s ease-in-out infinite;
}

@keyframes spin-slow {
  to {
    transform: rotate(360deg);
  }
}

@keyframes breathe {

  0%,
  100% {
    opacity: 0.5;
  }

  50% {
    opacity: 1;
  }
}

/* ══════════════════════════════════════════════════════════════
   ENVELOPE STATE
   ══════════════════════════════════════════════════════════════ */
#state-envelope {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  overflow: hidden;
}

.envelope-scene {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2.5rem;
  animation: fadeUp 0.9s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.envelope-hint {
  font-family: var(--font-ui);
  font-size: 0.62rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--text-faint);
  animation: float-hint 2.2s ease-in-out infinite;
  user-select: none;
}

@keyframes float-hint {

  0%,
  100% {
    opacity: 0.5;
    transform: translateY(0);
  }

  50% {
    opacity: 1;
    transform: translateY(-4px);
  }
}

@keyframes float-envelope {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-8px);
  }
}

/* Wrapper — clickable */
.envelope-wrapper {
  cursor: pointer;
  position: relative;
  width: 420px;
  height: 280px;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  animation: float-envelope 4s ease-in-out infinite;
}

.envelope-wrapper:focus-visible .envelope-body {
  outline: 2px solid var(--gold);
  outline-offset: 4px;
}

/* ── Envelope body (the main rectangle) ── */
.envelope-body {
  width: 100%;
  height: 100%;
  position: relative;
  background: var(--env-bg);
  background-image: url('https://www.transparenttextures.com/patterns/natural-paper.png');
  border: 1px solid var(--env-border);
  box-shadow:
    0 4px 20px var(--env-shadow),
    0 25px 70px rgba(0, 0, 0, 0.15);
  overflow: hidden;
  transition: box-shadow 0.3s, transform 0.3s;

  /* Hide white-spot pattern on dark themes */
  [data-theme="midnight"] &,
  [data-theme="crimson"] &,
  [data-theme="obsidian"] & {
    background-image: none;
  }

  /* Grained texture */
  &::before {
    content: '';
    position: absolute;
    inset: 0;
    opacity: var(--env-texture-opacity);
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    pointer-events: none;
  }
}

.envelope-wrapper:hover .envelope-body {
  transform: translateY(-4px) scale(1.01);
  box-shadow:
    0 8px 32px var(--shadow),
    0 32px 80px var(--shadow-deep);
}

/* ── Inside folds (decorative V-lines) ────── */
.env-folds {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;

  /* Left triangle */
  &::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 0;
    border-top: 140px solid transparent;
    border-bottom: 140px solid transparent;
    border-left: 160px solid var(--env-fold);
    filter: drop-shadow(4px 0 8px rgba(0, 0, 0, 0.08));
  }

  /* Right triangle */
  &::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 0;
    height: 0;
    border-top: 140px solid transparent;
    border-bottom: 140px solid transparent;
    border-right: 160px solid var(--env-fold);
    filter: drop-shadow(-4px 0 8px rgba(0, 0, 0, 0.08));
  }
}

.env-bottom-fold {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 0;
  border-left: 210px solid transparent;
  border-right: 210px solid transparent;
  border-bottom: 155px solid var(--env-fold-bottom);
  z-index: 4;
  filter: drop-shadow(0 -5px 12px rgba(0, 0, 0, 0.08));
}

/* ── Letter peeking from inside ────────── */
.env-letter-peek {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 78%;
  height: 80px;
  background: var(--bg-card2);
  border: 1px solid var(--border);
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 1.5rem;
  transition: transform 0.6s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 -2px 12px var(--shadow);
}

/* Lines on the peeking letter */
.env-letter-lines {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.env-letter-lines span {
  display: block;
  height: 1px;
  background: var(--accent);
  opacity: 0.22;
  border-radius: 1px;
}

.env-letter-lines span:nth-child(1) {
  width: 100%;
}

.env-letter-lines span:nth-child(2) {
  width: 78%;
}

.env-letter-lines span:nth-child(3) {
  width: 55%;
}

/* ── Flap (upper triangle, animates open) ── */
.env-flap {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 10;
  transform-origin: top center;
  transition: transform 1.1s cubic-bezier(0.19, 1, 0.22, 1);

  /* Triangle pointing down (closed flap) */
  height: 0;
  border-left: 210px solid transparent;
  border-right: 210px solid transparent;
  border-top: 120px solid var(--env-bg);

  /* Flap border — fake with filter */
  filter: drop-shadow(0 2px 5px var(--env-shadow));
}

/* Wax seal — positioned on envelope body, centered over flap tip */
.env-seal {
  position: absolute;
  /* flap tip is at top:120px; seal is 72px tall; center it: 120 - 36 = 84px */
  top: 84px;
  left: 50%;
  transform: translateX(-50%);
  width: 72px;
  height: 72px;
  z-index: 30;
  /* above everything */
  transition: opacity 0.6s, transform 0.6s ease-out;
}

/* Recipient name on envelope front */
.env-recipient {
  position: absolute;
  /* flap tip: 120px, seal bottom: 84+72=156px, add 12px gap = 168px */
  top: 168px;
  left: 50%;
  transform: translateX(-50%);
  width: 82%;
  background: var(--env-label-bg);
  border: 1px solid var(--env-border);
  box-shadow: 0 4px 12px var(--env-shadow);
  padding: 0.9rem 1rem;
  text-align: center;
  z-index: 20;
  /* above the folds */
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  pointer-events: none;
  border-radius: 2px;
  /* subtle inner lines */
  background-image: repeating-linear-gradient(to bottom, transparent, transparent 32px, var(--env-border) 32px, var(--env-border) 33px);
}

.env-to-label {
  font-family: var(--font-ui);
  font-size: 0.65rem;
  letter-spacing: 0.45em;
  text-transform: uppercase;
  color: var(--text-light);
  background: var(--env-label-bg);
  padding: 0 8px;
  z-index: 1;
}

.env-to-name {
  font-family: var(--font-body);
  font-size: 2.6rem;
  color: var(--text);
  opacity: 0.95;
  line-height: 0.7;
  z-index: 1;
}

/* ── OPEN animation classes ────────────── */
/* Applied by JS when user taps */
.envelope-wrapper.is-opening {
  animation: none !important;
  transform: translateY(15px) scale(1.03);
  transition: transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.envelope-wrapper.is-opening .env-flap {
  transform: perspective(600px) rotateX(-180deg);
  border-top-color: var(--env-flap-open);
}

.envelope-wrapper.is-opening .env-seal {
  opacity: 0;
  transform: translateX(-50%) translateY(-20px) scale(0.6);
}

.envelope-wrapper.is-opening .env-letter-peek {
  transform: translateX(-50%) translateY(-100px);
  transition: transform 0.9s cubic-bezier(0.16, 1, 0.3, 1) 0.2s;
}

.envelope-wrapper.is-opening .env-recipient {
  opacity: 0;
  transform: translateX(-50%) translateY(10px);
  transition: opacity 0.3s, transform 0.3s;
}

/* Whole scene fades & shrinks out before letter state */
.envelope-scene.is-exit {
  animation: env-exit 0.6s cubic-bezier(0.4, 0, 1, 1) forwards;
}

@keyframes env-exit {
  0% {
    transform: scale(1);
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: scale(0.85) translateY(30px);
  }
}

@media (max-width: 400px) {
  .envelope-wrapper {
    width: 280px;
  }

  .env-fold-bottom {
    border-left-width: 140px;
    border-right-width: 140px;
    border-bottom-width: 100px;
  }

  .env-fold-left {
    border-bottom-width: 210px;
    border-right-width: 140px;
  }

  .env-fold-right {
    border-bottom-width: 210px;
    border-left-width: 140px;
  }

  .env-flap {
    border-left-width: 140px;
    border-right-width: 140px;
    border-top-width: 100px;
  }
}

/* ══════════════════════════════════════════════════════════════
   LETTER STATE — OUTER SCROLL
   ══════════════════════════════════════════════════════════════ */
#state-letter {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
}

/* Paper ambient background gradient */
.paper-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 70% 50% at 20% 10%, rgba(212, 165, 165, 0.07) 0%, transparent 60%),
    radial-gradient(ellipse 60% 40% at 85% 90%, rgba(201, 169, 110, 0.06) 0%, transparent 55%);
}

.letter-scroll {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: var(--letter-max-width);
  padding: var(--letter-padding-v) 1.5rem;
  padding-bottom: 8rem;
  /* space for music player */
  margin: 0 auto;
  /* Animasi dikelola lewat .letter-paper.is-revealing untuk efek yang lebih dramatis */
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(28px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ══════════════════════════════════════════════════════════════
   LETTER PAPER — THE MAIN CARD
   ══════════════════════════════════════════════════════════════ */
.letter-paper {
  background: var(--bg-card);
  border: 1px solid var(--border);
  box-shadow:
    0 1px 3px var(--shadow),
    0 8px 32px var(--shadow),
    0 32px 80px rgba(0, 0, 0, 0.04);
  padding: var(--letter-padding-v) var(--letter-padding-h);
  position: relative;
  border-radius: 2px;
  overflow: visible;

  /* Paper Stack Effect */
  &::before {
    content: '';
    position: absolute;
    inset: -4px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    z-index: -1;
    transform: rotate(-1deg);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.03);
  }

  &::after {
    content: '';
    position: absolute;
    inset: -2px;
    background: var(--bg-card2);
    border: 1px solid var(--border);
    z-index: -2;
    transform: rotate(0.6deg);
  }

  /* Ruled lines — subtle */
  background-image: repeating-linear-gradient(var(--bg-card),
    var(--bg-card) 1.85rem,
    rgba(212, 165, 165, 0.035) 1.85rem,
    rgba(212, 165, 165, 0.035) 1.9rem);
  background-position: 0 5.5rem;

  /* Disable Stack Effect and Ruled Lines on Dark Themes */
  /* Disable Stack Effect and Ruled Lines on Dark Themes */
  [data-theme="midnight"] &,
  [data-theme="crimson"] &,
  [data-theme="obsidian"] & {
    &::before, &::after { display: none; }
    background-image: none !important; /* Clean paper, no lines */
    border: 1px solid rgba(255, 255, 255, 0.05); /* Very faint border */
    border-radius: 4px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
  }
}

/* ── Premium Handmade Paper Texture ───────────────────────────── */
.letter-paper.is-premium-paper {
  background-color: #fdfbf7 !important; /* Warm Bone/Cotton White */
  background-image: 
    /* Subtler ruled lines for premium */
    repeating-linear-gradient(rgba(0,0,0,0),
      rgba(0,0,0,0) 1.85rem,
      rgba(60, 30, 20, 0.012) 1.85rem,
      rgba(60, 30, 20, 0.012) 1.9rem),
    /* Handmade fiber texture overlay */
    url("https://www.transparenttextures.com/patterns/natural-paper.png") !important;
  background-blend-mode: multiply;
  background-size: 450px auto !important; /* Fixed scale for high-DPI consistency */
  border: none !important; /* Let clip-path handle the edge */
  
  /* Deckle Edge (Rough Torn Edge Effect) */
  clip-path: polygon(
    0% 1%, 5% 0%, 10% 1.2%, 15% 0%, 20% 0.8%, 25% 0%, 30% 1%, 35% 0%, 40% 1.1%, 45% 0%, 50% 0.9%, 55% 0%, 60% 1.2%, 65% 0%, 70% 1%, 75% 0%, 80% 1.1%, 85% 0%, 90% 0.8%, 95% 0%, 100% 1.5%,
    99% 5%, 100% 10%, 98.5% 15%, 100% 20%, 99.2% 25%, 100% 30%, 98.8% 35%, 100% 40%, 99% 45%, 100% 50%, 98.6% 55%, 100% 60%, 99.1% 65%, 100% 70%, 98.7% 75%, 100% 80%, 99.2% 85%, 100% 90%, 98.9% 95%, 100% 99%,
    95% 100%, 90% 98.8%, 85% 100%, 80% 99.1%, 75% 100%, 70% 98.7%, 65% 100%, 60% 99.2%, 55% 100%, 50% 98.9%, 45% 100%, 40% 99.1%, 35% 100%, 30% 98.8%, 25% 100%, 20% 99%, 15% 100%, 10% 98.7%, 5% 100%, 0% 98.5%,
    1% 95%, 0% 90%, 1.2% 85%, 0% 80%, 0.8% 75%, 0% 70%, 1.1% 65%, 0% 60%, 0.9% 55%, 0% 50%, 1.2% 45%, 0% 40%, 1% 35%, 0% 30%, 1.1% 25%, 0% 20%, 0.8% 15%, 0% 10%, 1.5% 5%, 0% 0%
  );

  /* Deep Paper Shadow */
  box-shadow: 
    0 12px 40px rgba(60, 30, 20, 0.1),
    0 2px 4px rgba(60, 30, 20, 0.05) !important;
}

/* ── Premium Envelope Styling ───────────────────────────────── */
.is-premium-envelope .envelope-body {
  background-image: url("https://www.transparenttextures.com/patterns/natural-paper.png") !important;
  background-blend-mode: multiply;
}

/* Premium Flap with Deckle Edge & Texture */
.is-premium-envelope .env-flap {
  border: none !important;
  width: 100%;
  height: 155px;
  background-color: var(--env-flap-open);
  background-image: url("https://www.transparenttextures.com/patterns/natural-paper.png") !important;
  background-blend-mode: multiply;
  /* Rough triangular clip-path */
  clip-path: polygon(
    0% 0%, 100% 0%,
    95% 10%, 90% 20%, 85% 30.5%, 80% 40%, 75% 50.8%, 70% 60%, 65% 70.2%, 60% 80%, 55% 90.5%, 50% 100%,
    45% 90.8%, 40% 80%, 35% 70.5%, 30% 60%, 25% 50.2%, 20% 40%, 15% 30.8%, 10% 20%, 5% 10.5%, 0% 0%
  );
}

/* Envelope Folds Premium Texture Overlay */
.is-premium-envelope .env-folds::before,
.is-premium-envelope .env-folds::after,
.is-premium-envelope .env-bottom-fold {
  background-image: url("https://www.transparenttextures.com/patterns/natural-paper.png");
  background-blend-mode: multiply;
  background-size: 200px 200px;
}

/* Specific adjustment for dark premium themes */
[data-theme="midnight"] .is-premium-envelope .envelope-body,
[data-theme="midnight"] .is-premium-envelope .env-flap,
[data-theme="crimson"] .is-premium-envelope .envelope-body,
[data-theme="crimson"] .is-premium-envelope .env-flap,
[data-theme="obsidian"] .is-premium-envelope .envelope-body,
[data-theme="obsidian"] .is-premium-envelope .env-flap {
  background-blend-mode: soft-light;
}

/* Ink absorption effect for text on premium paper */
.letter-paper.is-premium-paper .letter-body p, 
.letter-paper.is-premium-paper .letter-title, 
.letter-paper.is-premium-paper .letter-to, 
.letter-paper.is-premium-paper .letter-from {
  /* Menghapus mix-blend-mode: multiply karena merusak visibilitas di tema gelap */
  opacity: 1;
  filter: contrast(1.1);
  text-shadow: 0.3px 0.3px 0.5px rgba(0,0,0,0.05);
}

/* Specific adjustment for dark premium themes if needed */
[data-theme="midnight"] .letter-paper.is-premium-paper,
[data-theme="crimson"] .letter-paper.is-premium-paper,
[data-theme="obsidian"] .letter-paper.is-premium-paper {
  background-color: var(--bg-card) !important;
  background-image: url("https://www.transparenttextures.com/patterns/natural-paper.png") !important;
  background-blend-mode: soft-light !important;
  background-size: 500px auto !important;
  clip-path: none; /* Keep straight edges for dark modern look */
  border: 1px solid rgba(255,255,255,0.08) !important;
}

/* ══════════════════════════════════════════════════════════════
   LETTER PAPER — ENTRY ANIMATION (Rising From Depth)
   ══════════════════════════════════════════════════════════════ */

/* Default state: tersembunyi sampai class ditambahkan oleh JS */
.letter-paper {
  opacity: 0;
}

/* Class ditambahkan oleh script.js sesaat setelah state letter tampil */
.letter-paper.is-revealing {
  animation: paperRise 1.3s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes paperRise {
  0% {
    opacity: 0;
    transform: scale(0.9) translateY(40px);
    filter: blur(14px);
    box-shadow:
      0 1px 3px var(--shadow),
      0 8px 32px var(--shadow),
      0 0 0 rgba(212, 165, 165, 0);
  }

  40% {
    opacity: 0.7;
    filter: blur(4px);
  }

  70% {
    /* Warm glow pulse seolah cahaya lilin menyorot */
    box-shadow:
      0 1px 3px var(--shadow),
      0 8px 32px var(--shadow),
      0 0 60px var(--accent-soft);
  }

  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
    filter: blur(0);
    box-shadow:
      0 1px 3px var(--shadow),
      0 8px 32px var(--shadow),
      0 32px 80px rgba(0, 0, 0, 0.04);
  }
}

/* ══════════════════════════════════════════════════════════════
   RECIPIENT PHOTO — soft polaroid at the top of the letter
   ══════════════════════════════════════════════════════════════ */
.letter-photo {
  width: min(240px, 66%);
  margin: 0.5rem auto 2.5rem;
  padding: 10px 10px 12px;
  background: #fffdf9;
  border: 1px solid var(--border);
  box-shadow:
    0 2px 6px rgba(60, 30, 20, 0.05),
    0 12px 32px var(--shadow);
  transform: rotate(-1.5deg);
  position: relative;
  animation: photoReveal 1.1s cubic-bezier(0.16, 1, 0.3, 1) both 0.25s;
}

@keyframes photoReveal {
  from {
    opacity: 0;
    transform: rotate(-1.5deg) translateY(18px) scale(0.96);
  }

  to {
    opacity: 1;
    transform: rotate(-1.5deg) translateY(0) scale(1);
  }
}

.letter-photo::before {
  content: '';
  position: absolute;
  top: -11px;
  left: 50%;
  width: 64px;
  height: 20px;
  background: var(--tape-color);
  border: 1px solid var(--border);
  transform: translateX(-50%) rotate(1.5deg);
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 12%, #000 88%, transparent);
  mask-image: linear-gradient(90deg, transparent, #000 12%, #000 88%, transparent);
  z-index: 2;
}

.letter-photo-frame {
  position: relative;
  overflow: hidden;
  aspect-ratio: 2 / 3;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(255, 255, 255, 0.85), transparent 60%),
    linear-gradient(155deg, var(--accent-soft), var(--bg-card2));
}

.letter-photo-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.7s ease;
}

.letter-photo.is-loaded .letter-photo-frame {
  aspect-ratio: auto;
}

.letter-photo.is-loaded .letter-photo-img {
  height: auto;
  opacity: 1;
}

.letter-photo-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gold);
  font-size: 1.9rem;
  opacity: 0;
  transition: opacity 0.5s ease;
}

.letter-photo.is-failed .letter-photo-fallback {
  opacity: 0.65;
}

.letter-photo.is-failed .letter-photo-img {
  display: none;
}

.letter-photo-caption {
  font-family: 'Caveat', cursive;
  font-size: 1.05rem;
  color: var(--text-light);
  text-align: center;
  margin-top: 0.55rem;
  line-height: 1.2;
}

/* Washi Tape at Top Center */
.letter-tape {
  position: absolute;
  top: -16px;
  left: 50%;
  transform: translateX(-50%) rotate(-1deg);
  width: 100px;
  height: 32px;
  background: var(--tape-color);
  backdrop-filter: blur(1px);
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 10%, #000 90%, transparent);
  mask-image: linear-gradient(90deg, transparent, #000 10%, #000 90%, transparent);
  border: 1px solid var(--border);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  z-index: 20;
}

/* ══════════════════════════════════════════════════════════════
   LETTER HEADER
   ══════════════════════════════════════════════════════════════ */
.letter-header {
  text-align: center;
  margin-bottom: 2.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.ornament-top {
  width: 200px;
  max-width: 100%;
  opacity: 0;
  transform: scale(0.95);
  animation: ornamentFadeUp 1.2s cubic-bezier(0.16, 1, 0.3, 1) forwards 0.2s;
}

.letter-title {
  font-family: var(--font-display);
  font-style: italic;
  font-size: clamp(2.8rem, 8vw, 3.4rem);
  font-weight: 400;
  color: var(--text);
  margin-top: 0.2rem;
  line-height: 1;
  position: relative;
  display: inline-block;
  text-align: center;
}

.letter-title-underline {
  width: 400px;
  max-width: 115%;
  margin-top: -1.25rem;
  margin-bottom: 0.5rem;
  opacity: 0;
  transform: translateY(5px);
  animation: ornamentFadeUp 1.2s cubic-bezier(0.16, 1, 0.3, 1) forwards 0.4s;
}

.letter-title-underline svg path:not([d*="L"]) {
  stroke-dasharray: 600;
  stroke-dashoffset: 600;
  animation: drawOrnament 2.5s cubic-bezier(0.4, 0, 0.2, 1) forwards 0.6s;
}

.letter-title-underline svg path[d*="L"],
.letter-title-underline svg circle {
  opacity: 0;
  transform: scale(0);
  transform-origin: center;
  animation: popPoint 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* Diamond center */
.letter-title-underline svg path[d*="L"] {
  animation-delay: 1.3s;
  transform-origin: 200px 32px;
}

/* End points */
.letter-title-underline svg circle:nth-child(3) {
  animation-delay: 1.5s;
}

/* Gold left */
.letter-title-underline svg circle:nth-child(4) {
  animation-delay: 1.5s;
}

/* Gold right */
.letter-title-underline svg circle:nth-child(6) {
  animation-delay: 1.7s;
}

/* Pink left */
.letter-title-underline svg circle:nth-child(7) {
  animation-delay: 1.7s;
}

/* Pink right */

@keyframes ornamentFadeUp {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes drawOrnament {
  to {
    stroke-dashoffset: 0;
  }
}

@keyframes popPoint {
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.letter-date {
  font-family: 'Caveat', cursive;
  font-weight: 700;
  font-style: normal;
  font-size: 1.1rem;
  letter-spacing: 0.05em;
  text-transform: none;
  color: var(--text-light);
  margin-top: 0.45rem;
  opacity: 1;
}

.letter-date:empty {
  display: none;
}

/* ══════════════════════════════════════════════════════════════
   SALUTATION
   ══════════════════════════════════════════════════════════════ */
.letter-salutation {
  margin-bottom: 1.75rem;
}

.letter-to {
  font-family: var(--font-signature);
  font-size: clamp(2.6rem, 7vw, 3.2rem);
  color: var(--text);
  line-height: 0.8;
  display: inline-block;
  opacity: 0.95;
  position: relative;
  margin-bottom: 2.2rem;
}

.letter-to::after,
.letter-to::before {
  content: '';
  position: absolute;
  left: 0;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
}

.letter-to::after {
  bottom: -6px;
  width: 100%;
  opacity: 0.45;
  transform: rotate(0.5deg);
}

.letter-to::before {
  bottom: -12px;
  width: 80%;
  opacity: 0.25;
  transform: rotate(-0.4deg);
}

/* ══════════════════════════════════════════════════════════════
   LETTER BODY — PARAGRAPHS
   ══════════════════════════════════════════════════════════════ */
.letter-body {
  font-family: var(--font-body);
  font-size: 1.42rem;
  font-weight: 500;
  /* handwriting stays, slightly heavier for comfortable reading */
  line-height: 1.95;
  letter-spacing: 0.005em;
  color: var(--text);
  opacity: 0.88;
  /* soft ink, not pure black */
}

.letter-body p {
  margin-bottom: 1.6rem;
}

.letter-body p:last-child {
  margin-bottom: 0;
}

/* ── Typewriter cursor ─────────────────────────────────────── */
.typewriter-cursor {
  display: inline-block;
  width: 2px;
  height: 1.05em;
  background: var(--accent);
  margin-left: 2px;
  vertical-align: text-bottom;
  border-radius: 1px;
  animation: blink-cursor 0.85s step-end infinite;
}

@keyframes blink-cursor {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0;
  }
}



/* ══════════════════════════════════════════════════════════════
   LETTER FOOTER
   ══════════════════════════════════════════════════════════════ */
.letter-footer {
  margin-top: 3rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.letter-closing-wrap {
  text-align: right;
  padding-right: 0.5rem;
}

.letter-from {
  font-family: var(--font-signature);
  font-size: clamp(2.2rem, 6vw, 2.8rem);
  color: var(--text);
  line-height: 1;
  display: inline-block;
  opacity: 0.82;
  position: relative;
}

.letter-from::after,
.letter-from::before {
  content: '';
  position: absolute;
  right: 0;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
}

.letter-from::after {
  bottom: -4px;
  width: 100%;
  opacity: 0.7;
  transform: rotate(-0.5deg);
}

.letter-from::before {
  bottom: -11px;
  width: 75%;
  opacity: 0.45;
  transform: rotate(0.6deg);
}

.footer-divider {
  width: 200px;
  margin: 0 auto;
  opacity: 0.55;
}

/* Fallback shown inside the secret-memory polaroid when a photo fails */
.memory-fallback {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(155deg, #fdfaf5, #eadfd3);
  color: #c9a96e;
  font-size: 2.2rem;
}



/* ══════════════════════════════════════════════════════════════
   MUSIC PLAYER FAB
   ══════════════════════════════════════════════════════════════ */
#music-player-fab {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  background: var(--bg-card2);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text);
  transition: transform 0.25s ease, box-shadow 0.25s ease, opacity 0.3s ease;
  box-shadow: 0 4px 16px var(--shadow);
  cursor: pointer;
  opacity: 0;
}

#music-player-fab.visible { opacity: 1; }
#music-player-fab:hover { transform: scale(1.1); box-shadow: 0 8px 24px var(--shadow-deep); }

#music-fab-icon {
  font-size: 1rem;
  line-height: 1;
  transition: opacity 0.3s ease;
  display: inline-block;
}

@keyframes musicPulse {
  0% { transform: scale(1) rotate(-8deg); }
  50% { transform: scale(1.2) rotate(8deg); }
  100% { transform: scale(1) rotate(-8deg); }
}

#music-player-fab:not(.muted) #music-fab-icon {
  animation: musicPulse 1.5s infinite ease-in-out;
}

#music-player-fab.muted #music-fab-icon {
  opacity: 0.5;
  animation: none;
}

.music-slash {
  position: absolute;
  width: 18px;
  height: 2px;
  background: var(--text);
  transform: rotate(-45deg) scaleX(0);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 2px;
  transform-origin: center;
}

#music-player-fab.muted .music-slash {
  transform: rotate(-45deg) scaleX(1);
}

/* ══════════════════════════════════════════════════════════════
   RESPONSIVE — MOBILE
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 640px) {
  :root {
    --letter-padding-v: 2.5rem;
    --letter-padding-h: var(--letter-padding-h-mobile);
  }

  .letter-scroll {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
    padding-top: 2.5rem;
    padding-bottom: 7rem;
  }

  .letter-paper::before {
    display: none;
  }



}

@media (max-width: 380px) {
  :root {
    --letter-padding-h-mobile: 1.25rem;
  }

  .letter-body {
    font-size: 1rem;
  }
}

/* ══════════════════════════════════════════════════════════════
   UTILITY
   ══════════════════════════════════════════════════════════════ */
.hidden {
  display: none !important;
}

/* ══════════════════════════════════════════════════════════════
   PASSWORD GATE — Premium Security Overlay
   ══════════════════════════════════════════════════════════════ */
#password-gate {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  /* Fallback */
  background: color-mix(in srgb, var(--bg), transparent 30%);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  padding: 20px;
  transition: opacity 0.7s cubic-bezier(0.4, 0, 0.2, 1);
}

#password-gate.hidden {
  display: none !important;
}

#password-gate .gate-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-card);
  padding: 45px 35px;
  border-radius: 45px;
  box-shadow: 0 40px 100px -20px var(--shadow-deep);
  border: 1px solid var(--border);
  text-align: center;
  position: relative;
  overflow: hidden;
}

#password-gate .gate-card::before {
  content: '';
  position: absolute;
  top: -60px;
  right: -60px;
  width: 140px;
  height: 140px;
  background: radial-gradient(circle, rgba(212, 163, 115, 0.08) 0%, transparent 70%);
  border-radius: 50%;
}

#password-gate .gate-icon-box {
  width: 70px;
  height: 70px;
  background: var(--bg-card2);
  border: 1px solid var(--border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 28px;
  color: var(--gold);
}

#password-gate .gate-title {
  font-family: var(--font-display);
  font-size: 1.1rem;
  letter-spacing: 0.35em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}

#password-gate .gate-desc {
  font-family: var(--font-ui);
  font-size: 0.7rem;
  color: var(--text-light);
  letter-spacing: 0.05em;
  margin-bottom: 35px;
  line-height: 1.6;
}

#password-gate #gate-hint-container {
  margin-bottom: 35px;
  border-top: 1px solid #f9f4f0;
  padding-top: 25px;
}

#password-gate .hint-label {
  font-family: var(--font-ui);
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.25em;
  color: var(--text-faint);
  margin-bottom: 6px;
  display: block;
}

#password-gate #gate-hint-text {
  font-family: var(--font-body);
  font-size: 1.45rem;
  color: var(--accent);
  line-height: 1.2;
}

#password-gate .gate-input-wrapper {
  position: relative;
  margin-bottom: 24px;
}

#password-gate input {
  width: 100%;
  background: var(--bg-card2);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 18px 24px;
  text-align: center;
  font-family: var(--font-body);
  font-size: 1.4rem;
  color: var(--text);
  transition: all 0.3s ease;
  outline: none;
}

#password-gate input:focus {
  background: var(--bg-card);
  border-color: var(--gold);
  box-shadow: 0 10px 30px var(--shadow);
}

#password-gate input::placeholder {
  font-size: 0.9rem;
  color: #d8ced1;
  font-family: var(--font-ui);
  letter-spacing: 0.1em;
}

#password-gate #btn-gate-verify {
  width: 100%;
  background: var(--text);
  color: var(--bg-card);
  border: none;
  padding: 22px;
  border-radius: 28px;
  font-family: var(--font-ui);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.4em;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
  box-shadow: 0 15px 35px var(--shadow);
}

#password-gate #btn-gate-verify:hover {
  background: #333;
  transform: translateY(-2px);
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.18);
}

#password-gate #btn-gate-verify:active {
  transform: translateY(0);
}

#password-gate #gate-error {
  margin-top: 18px;
  font-family: var(--font-ui);
  font-size: 0.65rem;
  color: #f28b82;
  font-weight: 700;
  letter-spacing: 0.05em;
}

@keyframes gateShake {

  0%,
  100% {
    transform: translateX(0);
  }

  25% {
    transform: translateX(-10px);
  }

  75% {
    transform: translateX(10px);
  }
}

.gate-shake {
  animation: gateShake 0.4s ease-in-out !important;
}
