:root {
  --tone-bg-a: #081423;
  --tone-bg-b: #142d4b;
  --tone-surface: rgba(11, 20, 36, 0.68);
  --tone-border: rgba(255, 255, 255, 0.2);
  --tone-text: #f2f4f7;
  --tone-muted: #d5deeb;
  --tone-accent-a: #f3d5b5;
  --tone-accent-b: #f6b9b4;
  --tone-chip: rgba(255, 255, 255, 0.16);
  --font-title: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
  --font-body: "Avenir Next", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--tone-text);
  background: linear-gradient(150deg, var(--tone-bg-a), var(--tone-bg-b));
  display: grid;
  place-items: center;
  padding: calc(20px + env(safe-area-inset-top, 0px))
    calc(20px + env(safe-area-inset-right, 0px))
    calc(20px + env(safe-area-inset-bottom, 0px))
    calc(20px + env(safe-area-inset-left, 0px));
  overflow-x: hidden;
}

.atmosphere {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(circle at 18% 16%, rgba(243, 213, 181, 0.24), transparent 45%),
    radial-gradient(circle at 82% 22%, rgba(121, 160, 196, 0.22), transparent 40%),
    radial-gradient(circle at 50% 88%, rgba(246, 185, 180, 0.16), transparent 35%);
  animation: hazeDrift 16s ease-in-out infinite alternate;
}

.app {
  width: min(920px, 100%);
  min-height: 72vh;
  border: 1px solid var(--tone-border);
  border-radius: 24px;
  backdrop-filter: blur(9px);
  background: var(--tone-surface);
  overflow: hidden;
  position: relative;
  z-index: 1;
  transition: background 500ms ease;
  display: grid;
  grid-template-rows: auto 1fr;
}

.hud-toggle {
  display: none;
}

.hud-panel {
  position: relative;
  z-index: 2;
}

.app::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px);
  background-size: 40px 40px;
  opacity: 0.12;
}

.app::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 520ms ease;
  z-index: 0;
}

.app.is-chapter-shifting::after {
  opacity: 0.55;
}

.app[data-chapter="light"] {
  --tone-bg-a: #0b1a30;
  --tone-bg-b: #21486b;
  --tone-surface: rgba(10, 22, 41, 0.64);
}

.app[data-chapter="light"]::after {
  background: radial-gradient(circle at 20% 25%, rgba(145, 195, 235, 0.38), transparent 52%);
}

.app[data-chapter="winter"] {
  --tone-bg-a: #171f31;
  --tone-bg-b: #2d3d56;
  --tone-surface: rgba(20, 26, 39, 0.72);
  --tone-accent-a: #d5dce9;
  --tone-accent-b: #c8d7e8;
}

.app[data-chapter="winter"]::after {
  background: radial-gradient(circle at 30% 20%, rgba(184, 198, 220, 0.34), transparent 55%);
}

.app[data-chapter="future"] {
  --tone-bg-a: #2f2b39;
  --tone-bg-b: #664754;
  --tone-surface: rgba(33, 22, 36, 0.68);
  --tone-accent-a: #f4d3a8;
  --tone-accent-b: #e6a4a0;
}

.app[data-chapter="future"]::after {
  background: radial-gradient(circle at 75% 24%, rgba(255, 198, 156, 0.34), transparent 54%);
}

.app[data-intensity="sobre"] {
  --tone-accent-a: #e8d8c5;
  --tone-accent-b: #e7c3bd;
}

.app[data-intensity="tendre"] {
  --tone-accent-a: #f3d5b5;
  --tone-accent-b: #f6b9b4;
}

.app[data-intensity="expressif"] {
  --tone-accent-a: #ffd2ac;
  --tone-accent-b: #f58ca0;
}

.app[data-time-mode="morning"] {
  --tone-surface: rgba(13, 24, 42, 0.62);
}

.app[data-time-mode="evening"] {
  --tone-surface: rgba(9, 16, 30, 0.78);
}

.music-control {
  position: relative;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 14px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.08);
}

.music-control > * {
  min-width: 0;
}

.story-progress {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px 4px;
}

.progress-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.28);
  transition: transform 180ms ease, background 180ms ease;
}

.progress-dot.is-active {
  background: rgba(255, 255, 255, 0.9);
  transform: scale(1.35);
}

.music-btn {
  font-size: 0.85rem;
  padding: 8px 14px;
  white-space: nowrap;
  flex: 0 0 auto;
}

#music-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

#music-toggle::before {
  content: "";
  width: 14px;
  height: 12px;
  display: inline-block;
  background:
    linear-gradient(to top, rgba(255, 255, 255, 0.9) 35%, transparent 35%) left 0 bottom / 3px 10px no-repeat,
    linear-gradient(to top, rgba(255, 255, 255, 0.9) 55%, transparent 55%) center bottom / 3px 10px no-repeat,
    linear-gradient(to top, rgba(255, 255, 255, 0.9) 75%, transparent 75%) right 0 bottom / 3px 10px no-repeat;
  opacity: 0.85;
}

#music-toggle.is-playing::before {
  animation: waveBounce 800ms ease-in-out infinite;
}

.music-btn.is-active {
  background: linear-gradient(120deg, var(--tone-accent-a), var(--tone-accent-b));
  color: #1f2432;
  border-color: transparent;
}

.music-title {
  margin: 0;
  font-size: 0.82rem;
  color: rgba(242, 244, 247, 0.82);
  max-width: 200px;
  text-align: right;
}

.private-symbols {
  margin: 0;
  font-size: 0.78rem;
  color: rgba(242, 244, 247, 0.9);
  background: var(--tone-chip);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  padding: 4px 10px;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.screen {
  display: none;
  min-height: 0;
  height: 100%;
  padding: clamp(24px, 6vw, 60px);
  animation: fadeUp 700ms ease;
  gap: 16px;
  align-content: center;
  overflow-wrap: anywhere;
  position: relative;
  overflow: hidden;
}

.screen > * {
  position: relative;
  z-index: 1;
}

.screen.has-bg-image::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(160deg, rgba(7, 13, 24, 0.56), rgba(7, 13, 24, 0.56)),
    var(--screen-bg-image);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  opacity: 0.9;
  z-index: 0;
}

.screen.has-bg-video::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(160deg, rgba(7, 13, 24, 0.52), rgba(7, 13, 24, 0.62));
  z-index: 0;
}

.screen-bg-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
  pointer-events: none;
}

.screen[data-screen="1"] .screen-bg-video {
  object-position: 85% center;
}

.screen[data-screen="1"].has-bg-video h1,
.screen[data-screen="1"].has-bg-video p,
.screen[data-screen="1"].has-bg-image h1,
.screen[data-screen="1"].has-bg-image p {
  width: fit-content;
  max-width: min(100%, 44rem);
  background: rgba(22, 27, 36, 0.46);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 14px;
  padding: 10px 14px;
  backdrop-filter: blur(4px);
}

.screen[data-screen="1"] {
  justify-items: end;
  text-align: right;
}

.screen[data-screen="1"] .btn {
  justify-self: end;
}

@media (max-width: 680px) {
  .screen[data-screen="1"] {
    justify-items: start;
    text-align: left;
    align-content: end;
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  }

  .screen[data-screen="1"] .btn {
    justify-self: center;
  }
}

.screen.is-active {
  display: grid;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0.02em;
  line-height: 1.08;
  font-family: var(--font-title);
}

h1 {
  font-size: clamp(2.3rem, 6vw, 4.2rem);
  max-width: 14ch;
}

h2 {
  font-size: clamp(1.85rem, 4.5vw, 3.1rem);
  max-width: 16ch;
}

p,
li {
  margin: 0;
  font-size: clamp(1.05rem, 2.5vw, 1.38rem);
  color: var(--tone-muted);
  line-height: 1.5;
  max-width: 62ch;
}

.chapter-kicker {
  text-transform: uppercase;
  font-size: 0.77rem;
  letter-spacing: 0.2em;
  color: rgba(242, 244, 247, 0.72);
}

.lines {
  list-style: none;
  padding: 0;
  display: grid;
  gap: 10px;
}

.lines li {
  opacity: 0;
  transform: translateY(10px);
  animation: lineIn 600ms ease forwards;
}

.screen[data-screen="2"] .lines li,
.screen[data-screen="4"] .lines li {
  max-width: 64ch;
}

.memory-frame {
  width: min(100%, 520px);
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.08);
  padding: 10px 10px 14px;
  box-shadow: 0 12px 30px rgba(5, 10, 19, 0.28);
  transform: rotate(-0.8deg);
  animation: photoReveal 850ms ease;
}

.media-carousel {
  width: min(100%, 520px);
  justify-self: center;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.08);
  padding: 10px 10px 14px;
  box-shadow: 0 12px 30px rgba(5, 10, 19, 0.28);
  transform: rotate(-0.8deg);
  animation: photoReveal 850ms ease;
}

.media-carousel-track {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  min-height: 0;
}

.media-slide {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 450ms ease;
}

.media-slide.is-active {
  opacity: 1;
}

.media-slide img,
.media-slide video {
  width: 100%;
  height: 100%;
  max-height: none;
  min-height: 0;
  object-fit: cover;
  border-radius: 0;
  display: block;
}

.media-slide.fit-contain img,
.media-slide.fit-contain video {
  object-fit: contain;
  background: rgba(7, 13, 24, 0.72);
}

.media-carousel figcaption {
  margin-top: 10px;
  font-size: 0.92rem;
  color: rgba(242, 244, 247, 0.9);
}

.adventure-card {
  width: min(100%, 560px);
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 14px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.07);
  backdrop-filter: blur(4px);
}

.adventure-card h3 {
  margin: 0 0 8px;
  font-family: var(--font-title);
  font-size: clamp(1.15rem, 2.8vw, 1.45rem);
  color: #fff3e1;
}

.adventure-card ul {
  margin: 0;
  padding-left: 1.1rem;
  display: grid;
  gap: 6px;
}

.adventure-card li {
  color: #f4e6d8;
}

.memory-frame img {
  width: 100%;
  height: auto;
  max-height: 320px;
  object-fit: cover;
  border-radius: 10px;
  display: block;
}

.memory-frame figcaption {
  margin-top: 10px;
  font-size: 0.92rem;
  color: rgba(242, 244, 247, 0.9);
}

.memory-placeholder {
  display: grid;
  place-items: center;
  min-height: 160px;
  border-radius: 10px;
  background:
    radial-gradient(circle at 20% 20%, rgba(243, 213, 181, 0.44), transparent 45%),
    linear-gradient(150deg, rgba(25, 42, 65, 0.95), rgba(38, 67, 95, 0.95));
  color: rgba(242, 244, 247, 0.92);
  text-align: center;
  padding: 16px;
}

.abstract-placeholder {
  background:
    radial-gradient(circle at 24% 26%, rgba(245, 205, 177, 0.38), transparent 42%),
    radial-gradient(circle at 70% 60%, rgba(196, 215, 234, 0.32), transparent 44%),
    linear-gradient(145deg, rgba(22, 34, 53, 0.95), rgba(45, 61, 88, 0.95));
}

.btn {
  justify-self: start;
  border: 0;
  border-radius: 999px;
  padding: 10px 18px;
  cursor: pointer;
  color: #1f2432;
  background: linear-gradient(120deg, var(--tone-accent-a), var(--tone-accent-b));
  font-family: var(--font-body);
  font-size: 0.94rem;
  letter-spacing: 0.02em;
  transition: transform 180ms ease, filter 180ms ease;
}

.btn:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
}

.btn.ghost {
  background: transparent;
  color: var(--tone-text);
  border: 1px solid rgba(255, 255, 255, 0.4);
}

.final-main {
  color: #fff8ed;
  font-size: clamp(1.35rem, 3.2vw, 1.95rem);
}

.final-sub {
  color: #ffe9d1;
}

#secret-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

#secret-input {
  width: min(360px, 100%);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.12);
  color: white;
  padding: 10px 12px;
  font-size: 1rem;
  min-width: 0;
}

#secret-input::placeholder {
  color: rgba(255, 255, 255, 0.65);
}

.secret-message {
  color: #fff3dd;
  font-style: italic;
}

.breathe-word {
  display: inline-block;
  color: #fff0cf;
  animation: wordBreathe 3.2s ease-in-out infinite;
}

.secret-bonus {
  width: min(100%, 420px);
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.08);
  padding: 10px;
}

.secret-bonus img,
.secret-bonus video {
  width: 100%;
  border-radius: 10px;
  display: block;
}

.secret-bonus-caption {
  margin-top: 8px;
  font-size: 0.9rem;
  color: rgba(242, 244, 247, 0.9);
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes lineIn {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes photoReveal {
  from {
    opacity: 0;
    transform: translateY(10px) rotate(-1.4deg) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) rotate(-0.8deg) scale(1);
  }
}

@keyframes hazeDrift {
  from {
    transform: scale(1) translateY(0);
  }
  to {
    transform: scale(1.04) translateY(-12px);
  }
}

@keyframes waveBounce {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-1px);
  }
}

@keyframes wordBreathe {
  0%,
  100% {
    transform: translateY(0);
    opacity: 0.92;
  }
  50% {
    transform: translateY(-1px);
    opacity: 1;
  }
}

@media (max-width: 680px) {
  body {
    place-items: stretch;
    padding: 0;
    min-height: 100dvh;
    overflow: hidden;
  }

  .app {
    height: 100dvh;
    min-height: 100dvh;
    width: 100%;
    border-radius: 0;
  }

  .screen {
    height: 100dvh;
    min-height: 100dvh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: calc(100px + env(safe-area-inset-bottom, 0px));
  }

  .screen[data-screen="1"] {
    height: 100dvh;
    min-height: 100dvh;
    overflow: hidden;
    padding-bottom: calc(150px + env(safe-area-inset-bottom, 0px));
  }

  .hud-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    right: calc(10px + env(safe-area-inset-right, 0px));
    top: calc(10px + env(safe-area-inset-top, 0px));
    z-index: 7;
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: 999px;
    background: rgba(17, 22, 33, 0.82);
    color: #f2f4f7;
    padding: 8px 14px;
    font-family: var(--font-body);
    font-size: 0.84rem;
    letter-spacing: 0.04em;
  }

  .hud-panel {
    display: none;
    position: absolute;
    left: calc(10px + env(safe-area-inset-left, 0px));
    right: calc(10px + env(safe-area-inset-right, 0px));
    top: calc(56px + env(safe-area-inset-top, 0px));
    z-index: 6;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 14px;
    background: rgba(10, 15, 25, 0.88);
    backdrop-filter: blur(8px);
    overflow: hidden;
  }

  .app.hud-open .hud-panel {
    display: block;
  }

  .music-control {
    justify-content: flex-start;
    padding: 10px;
    gap: 6px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    background: transparent;
  }

  .story-progress {
    justify-content: center;
    padding: 8px 10px 10px;
  }

  .music-title {
    max-width: none;
    text-align: left;
    order: 3;
    width: 100%;
  }

  .private-symbols {
    order: 4;
    width: fit-content;
    max-width: 100%;
  }

  .memory-frame {
    transform: none;
  }

  .media-carousel {
    transform: none;
    width: min(100%, 500px);
    justify-self: center;
  }

  .screen[data-screen="7"] .media-carousel,
  .screen[data-screen="7"] .memory-frame {
    justify-self: center;
    margin-inline: auto;
  }

  .screen {
    padding: 18px 14px 20px;
  }

  .screen[data-screen="7"] .adventure-card {
    justify-self: center;
    margin-inline: auto;
  }

  .screen.has-mobile-media-first > h1,
  .screen.has-mobile-media-first > h2 {
    order: 1;
  }

  .screen.has-mobile-media-first > .media-carousel {
    order: 2;
  }

  .screen.has-mobile-media-first > p,
  .screen.has-mobile-media-first > .lines {
    order: 3;
  }

  .screen.has-mobile-media-first > .btn,
  .screen.has-mobile-media-first > form,
  .screen.has-mobile-media-first > .secret-message {
    order: 4;
  }

  .btn {
    width: fit-content;
  }

  .screen [data-next] {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    z-index: 5;
    justify-self: auto;
    background:
      linear-gradient(120deg, var(--tone-accent-a), var(--tone-accent-b)),
      rgba(255, 255, 255, 0.16);
    box-shadow: 0 10px 24px rgba(5, 10, 19, 0.34);
    backdrop-filter: blur(4px);
  }
}

@media (max-width: 430px) {
  .app {
    border-radius: 18px;
  }

  .music-control {
    padding: 8px;
  }

  .music-btn {
    font-size: 0.78rem;
    padding: 7px 10px;
  }

  .music-title {
    font-size: 0.76rem;
  }

  .private-symbols {
    font-size: 0.72rem;
    padding: 3px 8px;
  }

  .screen {
    padding: 18px 14px 20px;
  }

  p,
  li {
    font-size: clamp(0.98rem, 4.3vw, 1.12rem);
    line-height: 1.46;
  }

  #secret-form {
    display: grid;
    width: 100%;
  }

  #secret-input {
    width: 100%;
  }
}

@media (max-height: 700px) and (orientation: landscape) {
  .music-control {
    padding: 8px 10px 6px;
  }

  .screen {
    padding-top: 16px;
    padding-bottom: 16px;
    gap: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .atmosphere,
  .screen,
  .lines li,
  .memory-frame {
    animation: none !important;
  }

  .btn {
    transition: none;
  }

  .app::after {
    transition: none;
  }
}
