:root {
  color-scheme: dark;
  --navy: #050b16;
  --cyan: #9eeafa;
  --gold: #edc58a;
  --text: #fff5e9;
  --muted: #a4b7c9;
  font-family: system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  --ambient-focus: 50% 11rem;
  isolation: isolate;
  margin: 0;
  min-height: 100svh;
  color: var(--text);
  background:
    radial-gradient(ellipse at 52% 43%, transparent 20%, #01030bb8 95%),
    linear-gradient(90deg, #71d9f21c 1px, transparent 1px) 8% 0 / 5rem 100% no-repeat,
    linear-gradient(90deg, #e7be8520 1px, transparent 1px) 93% 0 / 2rem 100% no-repeat,
    radial-gradient(ellipse at var(--ambient-focus), #0b3857 0, #061527 34%, transparent 66%),
    linear-gradient(155deg, #01040d, #030c19 52%, #02040a 92%);
}

.scenery {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 17% 100%, #1477aa5e, transparent 48%),
    radial-gradient(ellipse at 98% 0%, #9e683e37, transparent 35%);
}

.scenery::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 89% 17%, #c68a442e, transparent 48%),
    radial-gradient(ellipse at 72% 100%, #d39d5030, transparent 44%);
  opacity: 0;
}

body[data-conversation-module="about-luis"] .scenery::before { opacity: 1; }

.scenery::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 76% 36%, #c38a494f, transparent 65%),
    radial-gradient(ellipse at 43% 100%, #b5783c5c, transparent 63%),
    linear-gradient(105deg, #050d1f55, transparent);
  opacity: 0;
}

body[data-conversation-module="letter-intro"] .scenery::after { opacity: .66; }
body[data-conversation-module="letter-open"] .scenery::after { opacity: 1; }
body[data-conversation-module="mission"] .scenery::after { opacity: .45; }

.energy-floor {
  position: absolute;
  inset: auto 0 0;
  display: block;
  width: 100%;
  height: clamp(13rem, 48vh, 34rem);
}

.binary-rain {
  position: absolute;
  inset: 0 0 18%;
  display: flex;
  justify-content: space-around;
  gap: .2rem;
  overflow: hidden;
  mask-image: linear-gradient(#000 55%, transparent);
}

.binary-rain span {
  --binary-duration: 26s;
  --binary-delay: -8s;
  --binary-opacity: .45;
  flex: 0 0 1ch;
  width: 1ch;
  min-width: 0;
  color: #58e2ff;
  opacity: var(--binary-opacity);
  font: .68rem/1.25 Consolas, monospace;
  word-break: break-all;
  align-self: flex-start;
}

.binary-rain span:nth-child(3n + 2) {
  --binary-duration: 34s;
  --binary-delay: -22s;
  --binary-opacity: .26;
  color: #2a9edc;
  margin-top: 4vh;
}

.binary-rain span:nth-child(3n) {
  --binary-duration: 22s;
  --binary-delay: -13s;
  --binary-opacity: .61;
  margin-top: -3vh;
}

.binary-rain span:nth-child(4n) { margin-top: 9vh; }
.binary-rain span:nth-child(5n) { --binary-delay: -3s; }

.circuit-pulse {
  visibility: hidden;
  stroke: #b0f5ff;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-dasharray: 6 94;
}

.pulse-right { stroke: #ffd08c; }

@media (max-width: 47.99rem) {
  .binary-rain span:nth-child(n+9),
  .pulse-center { display: none; }
  .energy-floor { height: clamp(10rem, 35vh, 20rem); }
  .floor-grid { opacity: .55; }
}

/* Capas ambientales dentro del viewport y detrás de la invitación. */
body::before,
body::after {
  content: "";
  position: fixed;
  inset: .75rem;
  z-index: -1;
  pointer-events: none;
}

body::before {
  background:
    radial-gradient(ellipse clamp(9rem, 25vw, 24rem) 13rem at var(--ambient-focus), #1ab6e72b, transparent),
    radial-gradient(ellipse 22rem 16rem at 92% 76%, #b3814422, transparent);
}

body::after {
  background:
    radial-gradient(circle at 9% 19%, #94e8ff80 0 1px, transparent 2px),
    radial-gradient(circle at 24% 35%, #9af5ff88 0 1px, transparent 2px),
    radial-gradient(circle at 42% 11%, #e7be857f 0 1px, transparent 2px),
    radial-gradient(circle at 74% 27%, #b4efff6e 0 1px, transparent 2px),
    radial-gradient(circle at 90% 54%, #edc58a80 0 1px, transparent 2px),
    radial-gradient(circle at 13% 68%, #77d9ff65 0 1px, transparent 2px),
    radial-gradient(circle at 32% 81%, #e7be8566 0 1px, transparent 2px),
    radial-gradient(circle at 83% 89%, #80e6ff75 0 1px, transparent 2px),
    linear-gradient(90deg, #70cee536, transparent) 9% 19% / 3.2rem 1px no-repeat,
    linear-gradient(0deg, transparent, #70cee52b) 9% 19% / 1px 2rem no-repeat,
    linear-gradient(270deg, #e7be8533, transparent) 93% 76% / 4rem 1px no-repeat,
    linear-gradient(180deg, #e7be852b, transparent) 93% 76% / 1px 2rem no-repeat;
}

.invitation {
  width: min(100%, 76rem);
  margin-inline: auto;
  padding: clamp(1rem, 4vw, 3rem);
}

.masthead {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: .35rem 1rem;
  padding-bottom: .9rem;
  border-bottom: 1px solid transparent;
  border-image: linear-gradient(90deg, #62e0ff, #19516c 25%, #17334a 74%, #e3b97e) 1;
}

.masthead h1 {
  margin: 0;
  color: var(--cyan);
  font-size: clamp(.95rem, 2vw, 1.25rem);
  letter-spacing: .24em;
  text-shadow: 0 0 .9rem #43c9f5a8;
}

.masthead span {
  color: var(--muted);
  font-size: .85rem;
}

.welcome {
  display: grid;
  align-items: center;
  gap: 1rem;
  min-width: 0;
}

.welcome[hidden] { display: none; }
.welcome > .conversation[hidden] { display: none; }

.activation-panel {
  text-align: center;
}

.activation-copy {
  width: 100%;
}

.activation-copy h2 {
  margin: 0;
  color: var(--text);
  font: normal clamp(1.75rem, 4vw, 2.9rem)/1.12 Georgia, serif;
}

.activation-copy p {
  margin: .85rem 0 1.3rem;
  color: var(--muted);
  line-height: 1.5;
}

.activation-copy button {
  min-height: 3rem;
  justify-content: center;
  text-align: center;
  box-shadow: 0 0 1rem #e9b97235;
}

.activation-status {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 1rem;
  color: var(--cyan);
  letter-spacing: .1em;
  pointer-events: none;
}

body[data-activation="standby"] .projection svg { opacity: .46; }
body[data-activation="standby"] :is(.orbit-cyan, .orbit-gold) { opacity: .35; }
body[data-activation="standby"] .projection::before,
body[data-activation="standby"] .projection::after { opacity: .28; }
body[data-activation="standby"] .scenery { opacity: .68; }
body[data-activation="activating"] .activation-copy { opacity: 0; }

.projection {
  position: relative;
  isolation: isolate;
  width: min(100%, 16rem);
  min-width: 0;
  margin-inline: auto;
}

.projection::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 85% 10% 0;
  pointer-events: none;
  background: radial-gradient(ellipse, #4de7ffbb, #1474db60 37%, transparent 72%);
}

.projection::after {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 88% 15% 3.5%;
  pointer-events: none;
  border: 1px solid #45d8fbb8;
  border-bottom-color: #dba46eaa;
  border-radius: 50%;
  box-shadow: 0 0 1.3rem #00b8ff74, inset 0 -.12rem .7rem #178ded8a;
}

.projection svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: hidden;
}

.projection.farewell-pulse :is(.core, .orbit) {
  filter: sepia(var(--farewell-glow, 0)) saturate(calc(1 + 2 * var(--farewell-glow, 0)))
    brightness(calc(1 + .5 * var(--farewell-glow, 0)))
    drop-shadow(0 0 5px rgb(255 194 103 / var(--farewell-glow, 0)));
}

.projection.farewell-pulse::before {
  background:
    radial-gradient(ellipse, rgb(255 210 133 / var(--farewell-glow, 0)), transparent 65%),
    radial-gradient(ellipse, #4de7ffbb, #1474db60 37%, transparent 72%);
}

.conversation {
  position: relative;
  min-width: 0;
  padding: clamp(1rem, 4vw, 2.5rem);
  border: 1px solid #458da9;
  border-radius: 1.25rem;
  background: linear-gradient(154deg, #071b2af8, #030d19f5 68%, #082637f5) padding-box;
  box-shadow: 0 1.25rem 3rem #000d, 0 0 1.15rem #1db8ff35, inset 0 0 1.4rem #0999db1e;
}

.conversation::before,
.conversation::after {
  content: "";
  position: absolute;
  width: 2.5rem;
  height: 2rem;
  pointer-events: none;
}

.conversation::before {
  inset: -1px auto auto -1px;
  border-top: 1px solid #9deeff;
  border-left: 1px solid #62d9fa;
  border-top-left-radius: inherit;
  filter: drop-shadow(0 0 4px #37cfff);
}

.conversation::after {
  inset: auto -1px -1px auto;
  border-right: 1px solid #f5cc92;
  border-bottom: 1px solid #f5cc92;
  border-bottom-right-radius: inherit;
  filter: drop-shadow(0 0 4px #f5cc92);
}

.conversation-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .6rem 1rem;
}

.conversation-header h2 {
  margin: 0;
  color: var(--gold);
  font-size: .74rem;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
}

progress {
  width: min(6rem, 100%);
  height: .3rem;
  appearance: none;
  accent-color: var(--gold);
  border: 0;
  border-radius: 1rem;
  background: #293e50;
}

progress::-webkit-progress-bar { background: #293e50; border-radius: 1rem; }
progress::-webkit-progress-value { background: var(--gold); border-radius: 1rem; }
progress::-moz-progress-bar { background: var(--gold); border-radius: 1rem; }

.message {
  margin-block: 1.3rem;
  font-family: Georgia, serif;
  font-size: clamp(1.13rem, 2.3vw, 1.58rem);
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.message p { margin: 0; }
.message p + p { margin-top: .75em; }
.message p:first-child { color: #fff; }

button,
.whatsapp-contact {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: .7rem;
  min-height: 2.75rem;
  max-width: 100%;
  padding: .55rem .9rem;
  border: 1px solid #c39b64;
  border-radius: .65rem;
  color: #ffe2ae;
  background: #091521;
  box-shadow: inset 0 0 .65rem #d9a25219, 0 0 .75rem #e9b97222;
  font: inherit;
  font-size: .93rem;
  text-align: left;
  cursor: pointer;
}

button[hidden] { display: none; }
button:enabled:hover,
a.whatsapp-contact:hover { background: #272318; box-shadow: 0 0 1rem #f9bc6060; }
button:enabled:active,
a.whatsapp-contact:active { background: #41301b; box-shadow: inset 0 0 .75rem #d9a2524b; }
button:disabled { color: var(--gold); border-color: #a7875c; cursor: default; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 4px; }

.letter-envelope {
  position: relative;
  width: min(100%, 15rem);
  aspect-ratio: 1.65;
  margin: .25rem auto 1.25rem;
  border: 1px solid #a98050;
  border-radius: .55rem;
  background:
    linear-gradient(33deg, #091726 49.4%, #a9805080 50%, transparent 50.6%) left / 51% 100% no-repeat,
    linear-gradient(-33deg, #091726 49.4%, #a9805080 50%, transparent 50.6%) right / 51% 100% no-repeat,
    linear-gradient(150deg, #132d42, #081421);
  box-shadow: 0 .7rem 1.7rem #0008, 0 0 1.5rem #e2aa562e;
  perspective: 40rem;
}

.letter-flap {
  position: absolute;
  inset: 0 0 35%;
  background: #b28a55;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: top;
}

.letter-flap::after {
  content: "";
  position: absolute;
  inset: 0 0 2px;
  background: linear-gradient(170deg, #263e52, #0d2034 75%);
  clip-path: inherit;
}

.letter-seal {
  position: absolute;
  top: 62%;
  left: 50%;
  translate: -50% -50%;
  display: grid;
  place-items: center;
  width: 2rem;
  aspect-ratio: 1;
  border: 1px solid #dfb57a;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 28%, #805c37, #352014);
  color: #ffe2aa;
  font: italic 1rem Georgia, serif;
}

.letter-stage {
  width: min(100%, 46rem);
  margin-inline: auto;
  padding-block: clamp(2rem, 7vw, 4.5rem);
}

.letter-stage .letter-envelope {
  width: min(78%, 16rem);
  margin-bottom: -.8rem;
}

.letter-stage .letter-flap { transform: rotateX(155deg); }
.letter-stage .letter-seal { opacity: 0; }

@media (max-width: 47.99rem) {
  /* La solapa abierta ocupa espacio por encima del cuerpo del sobre. */
  .letter-stage { padding-block-start: 8rem; }
}

@media (min-width: 48rem) {
  .letter-stage { padding-block-start: 7.25rem; }
}

.letter-paper {
  position: relative;
  padding: clamp(1.25rem, 6vw, 3.75rem);
  border: 1px solid #c9a56f;
  border-radius: .45rem;
  background:
    repeating-linear-gradient(0deg, #65421d05 0 1px, transparent 1px 5px),
    linear-gradient(145deg, #fff9ed, #f2e4cc);
  box-shadow: 0 1.1rem 3rem #0009, 0 0 2rem #dfac6026;
  color: #35261f;
  font-family: Georgia, serif;
  font-size: clamp(1.05rem, 2.5vw, 1.24rem);
  line-height: 1.65;
  overflow-wrap: anywhere;
}

.letter-paper h2 {
  margin: 0 0 1.1em;
  padding-bottom: .45em;
  border-bottom: 1px solid #c6a370;
  font-size: clamp(1.65rem, 5vw, 2.6rem);
  font-weight: normal;
  line-height: 1.2;
}

.letter-paper h2:focus-visible { outline-color: #805523; }
.letter-signature { margin-block: 1.2em; font-size: 1.42em; font-style: italic; }

.decision-options:not([hidden]) {
  display: grid;
  width: 100%;
  gap: .65rem;
}

.decision-options button {
  width: 100%;
  min-height: 3rem;
  overflow-wrap: anywhere;
  border-color: #69a8bd;
}

.decision-options button:hover,
.decision-options button:focus-visible { border-color: var(--gold); }

.date-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: .7rem;
}

.date-card {
  display: grid;
  grid-template-columns: 1.55rem minmax(0, 1fr);
  align-items: start;
  gap: .2rem .65rem;
  padding: .75rem;
  border: 1px solid #4d859c;
  border-radius: .65rem;
  background: linear-gradient(145deg, #103048b8, #081726e8);
  color: var(--text);
}

.date-icon {
  grid-row: span 2;
  color: var(--gold);
}

.date-icon svg { display: block; width: 100%; }
.date-description { grid-column: 2; color: var(--muted); font-size: .86rem; }

.decision-options .date-card[aria-pressed="true"],
.date-summary {
  border-color: var(--gold);
  box-shadow: inset 3px 0 var(--gold), 0 0 1rem #edc58a26;
}

.date-summary-label {
  grid-column: 1 / -1;
  margin-bottom: .35rem;
  color: var(--gold);
  font-size: .77rem;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.whatsapp-preview {
  grid-column: 1 / -1;
  min-width: 0;
  margin-top: .7rem;
  padding-top: .7rem;
  border-top: 1px solid #497082;
  font-size: .9rem;
}

.whatsapp-preview p {
  margin: .5rem 0 0;
  color: var(--muted);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  user-select: text;
}

.whatsapp-contact {
  width: 100%;
  min-height: 3rem;
  overflow-wrap: anywhere;
  text-decoration: none;
}

.mission-farewell {
  color: var(--text);
  font-family: Georgia, serif;
  line-height: 1.55;
}

.mission-farewell p { margin: .65rem 0 0; }
.mission-farewell p:last-child { color: var(--gold); }

@media (min-width: 48rem) {
  .date-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.experience-end {
  margin: 0;
  color: var(--gold);
  font-size: .9rem;
  letter-spacing: .08em;
}

body[data-conversation-module="finished"] .scenery { opacity: .23; }
body[data-conversation-module="finished"] .projection { opacity: .32; }

@media (min-width: 48rem) {
  body { --ambient-focus: 28% clamp(16rem, 42vh, 27rem); }

  .welcome {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
    gap: clamp(1.5rem, 4vw, 4rem);
    padding-block: clamp(.75rem, 2vh, 1.5rem);
  }

  .projection { width: min(100%, 31rem); }

  .conversation-header { width: 100%; }
}

/* La carta y los viewports pequeños conservan el flujo del documento. */
@media (min-width: 64rem) and (min-height: 42rem) {
  .invitation:has(> .welcome:not([hidden])) {
    height: 100vh;
    height: 100dvh;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    padding-block: clamp(1rem, 3vh, 2.25rem);
  }

  .welcome:not([hidden]) {
    min-height: 0;
    padding-block: 0;
    container-type: size;
  }

  .projection {
    width: min(100%, 31rem, calc((100vh - 7rem) * .91));
  }

  @supports (width: 1cqh) {
    .projection { width: min(100%, 31rem, 91cqh); }
  }

  .conversation {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    max-height: 100%;
    padding-block: clamp(1rem, 3vh, 2rem);
  }

  .conversation > :not(.conversation-body) { flex-shrink: 0; }

  .conversation-body {
    min-height: 0;
    width: 100%;
    overflow-y: auto;
    margin-block: .85rem;
  }

  .conversation-body:focus-visible { outline-offset: -2px; }

  .conversation-body .message {
    margin-block: 0;
    padding: .35rem;
    font-size: clamp(1.1rem, min(2vw, 3.2vh), 1.58rem);
  }

  #conversation-details:not(:empty) { margin-block: .5rem; }

  .conversation:has(.whatsapp-preview) {
    min-height: 0;
    max-height: calc(100vh - 7rem);
  }

  @supports (height: 1cqh) {
    .conversation:has(.whatsapp-preview) { max-height: 100cqh; }
  }

  .conversation:has(.whatsapp-preview) .conversation-body,
  .conversation:has(.whatsapp-preview) #conversation-details {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  .conversation:has(.whatsapp-preview) .conversation-body { overflow: visible; }
  .conversation:has(.whatsapp-preview) .message { flex-shrink: 0; }

  .conversation:has(.whatsapp-preview) .date-summary {
    min-height: 0;
    grid-template-rows: auto auto auto minmax(0, 1fr);
  }

  .date-summary:has(.whatsapp-preview) .date-icon { grid-area: 2 / 1 / span 2; }
  .date-summary:has(.whatsapp-preview) > strong { grid-area: 2 / 2; }
  .date-summary:has(.whatsapp-preview) .date-description { grid-row: 3; }
  .whatsapp-preview { grid-row: 4; align-self: stretch; min-height: 0; overflow-y: auto; }
  .whatsapp-preview:focus-visible { outline-offset: -2px; }
}
