/* ============================================================
   DESIGN TOKENS
   ============================================================ */
:root {
  --ink: #1b1310;
  --ink-soft: #2a1e19;
  --amber: #e3a35c;
  --amber-deep: #c47f3c;
  --rose: #c98a86;
  --cream: #f4ead9;
  --dusty-pink: #d9a9a0;
  --warm-gray: #a9998e;
  --plum: #3a2436;

  --panel-bg: rgba(24, 16, 13, 0.52);
  --panel-bg-strong: rgba(20, 13, 10, 0.68);
  --panel-border: rgba(244, 234, 217, 0.14);

  --font-display: "Cormorant Garamond", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --font-hand: "Caveat", "Segoe Script", cursive;
  --font-ui: "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 9px;

  --shadow-soft: 0 18px 50px rgba(0, 0, 0, 0.45);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

/* ============================================================
   RESET / BASE
   ============================================================ */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow-x: hidden;
}
body {
  font-family: var(--font-ui);
  background: var(--ink);
  color: var(--cream);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
img { max-width: 100%; display: block; }
button { font-family: inherit; cursor: pointer; }
a { color: inherit; }

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

/* Focus visibility */
button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 3px;
  border-radius: 6px;
}

/* ============================================================
   APP SHELL
   ============================================================ */
#app {
  position: relative;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
}

.page {
  position: fixed;
  inset: 0;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.7s var(--ease);
}
.page.is-active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* ============================================================
   BACKGROUND LAYER
   ============================================================ */
.scene {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background-color: var(--ink);
}
.scene__img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 35%;
  transform: scale(1.03);
  transition: transform 8s var(--ease), object-position 0.6s var(--ease);
}
.page.is-active .scene__img { transform: scale(1); }
.scene--focus-zoom .page.is-active .scene__img { transform: scale(1.045); }

.scene__overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to top,
    rgba(10, 6, 5, 0.72) 0%,
    rgba(10, 6, 5, 0.28) 38%,
    rgba(10, 6, 5, 0.06) 62%,
    rgba(10, 6, 5, 0.18) 100%
  );
  pointer-events: none;
}

/* Placeholder background for pages without art yet */
.scene--placeholder .scene__img { display: none; }
.scene--placeholder .scene__bg-fallback {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 20% 20%, rgba(227, 163, 92, 0.14), transparent 55%),
    radial-gradient(circle at 80% 75%, rgba(58, 36, 54, 0.45), transparent 55%),
    linear-gradient(160deg, #241a16 0%, #1b1310 55%, #150f0d 100%);
}
.scene--placeholder .scene__bg-fallback::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    repeating-linear-gradient(45deg, rgba(244,234,217,0.02) 0 2px, transparent 2px 26px);
}
.placeholder-note {
  display: none;
  position: absolute;
  left: 50%;
  top: 44%;
  transform: translate(-50%, -50%);
  text-align: center;
  font-family: var(--font-hand);
  font-size: clamp(1.3rem, 3vw, 1.9rem);
  color: rgba(244, 234, 217, 0.38);
  letter-spacing: 0.02em;
  pointer-events: none;
  max-width: 70%;
}
.scene--placeholder .placeholder-note { display: block; }
.placeholder-note small {
  display: block;
  margin-top: 6px;
  font-family: var(--font-ui);
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  color: rgba(244, 234, 217, 0.22);
}

/* Rain shimmer for Page 3 */
.rain-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background-image: repeating-linear-gradient(
    100deg,
    transparent 0,
    transparent 18px,
    rgba(244, 234, 217, 0.05) 19px,
    transparent 21px
  );
  background-size: 140% 140%;
  animation: rainFall 0.6s linear infinite;
  transition: opacity 0.6s var(--ease);
}
.rain-layer.is-active { opacity: 1; }
@keyframes rainFall {
  0% { background-position: 0 0; }
  100% { background-position: -40px 120px; }
}
@media (prefers-reduced-motion: reduce) {
  .rain-layer { animation: none !important; }
}

/* ============================================================
   PROGRESS INDICATOR
   ============================================================ */
.progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 40;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 12px 0;
  pointer-events: none;
}
.progress__dot {
  pointer-events: auto;
  width: 30px;
  height: 30px;
  min-width: 30px;
  min-height: 30px;
  border-radius: 50%;
  border: 1px solid var(--panel-border);
  background: var(--panel-bg);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: rgba(244, 234, 217, 0.55);
  font-size: 0.68rem;
  font-family: var(--font-ui);
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.progress__dot.is-current {
  background: var(--amber);
  color: var(--ink);
  border-color: var(--amber);
  transform: scale(1.08);
}
.progress__dot.is-unlocked:not(.is-current) {
  color: var(--cream);
  border-color: rgba(244, 234, 217, 0.3);
}
.progress__dot.is-locked {
  opacity: 0.4;
  cursor: not-allowed;
}
.progress__dot:disabled { pointer-events: none; }

@media (max-width: 480px) {
  .progress__dot { width: 26px; height: 26px; min-width: 26px; min-height: 26px; font-size: 0.58rem; }
  .progress {
    gap: 4px;
    justify-content: flex-start;
    padding-left: calc(env(safe-area-inset-left, 0px) + 10px);
    padding-right: calc(env(safe-area-inset-right, 0px) + 64px);
    padding-top: calc(env(safe-area-inset-top, 0px) + 10px);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex-wrap: nowrap;
  }
  .progress::-webkit-scrollbar { display: none; }
}

/* ============================================================
   MUSIC CONTROL
   ============================================================ */
.music-control {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  right: calc(env(safe-area-inset-right, 0px) + 12px);
  z-index: 41;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-radius: 999px;
  padding: 6px 10px;
}
.music-control button {
  width: 32px;
  height: 32px;
  min-width: 32px;
  min-height: 32px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--cream);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  transition: transform 0.2s var(--ease), background 0.2s var(--ease);
}
.music-control button:hover { background: rgba(244,234,217,0.12); }
.music-control button:active { transform: scale(0.9); }
.music-control__label {
  font-size: 0.62rem;
  color: rgba(244, 234, 217, 0.5);
  letter-spacing: 0.04em;
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.music-control.is-unavailable { opacity: 0.55; }
.yt-player-hidden {
  position: fixed;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  left: -9999px;
}
.music-control .eq {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 12px;
}
.music-control .eq span {
  width: 2px;
  background: var(--amber);
  border-radius: 2px;
  animation: eqBounce 0.9s ease-in-out infinite;
}
.music-control .eq span:nth-child(2) { animation-delay: 0.15s; }
.music-control .eq span:nth-child(3) { animation-delay: 0.3s; }
.music-control:not(.is-playing) .eq span { animation-play-state: paused; height: 3px !important; }
@keyframes eqBounce {
  0%, 100% { height: 3px; }
  50% { height: 12px; }
}

/* ============================================================
   FLOATING PANEL
   ============================================================ */
.panel-wrap {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
  padding-left: calc(env(safe-area-inset-left, 0px) + 16px);
  padding-right: calc(env(safe-area-inset-right, 0px) + 16px);
  z-index: 10;
}
@media (min-width: 860px) {
  .panel-wrap { align-items: center; justify-content: flex-end; padding: 6vh 7vw; }
}

.panel {
  width: 100%;
  max-width: 460px;
  max-height: 78vh;
  max-height: 78dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-radius: var(--radius-lg);
  padding: 22px 20px;
  box-shadow: var(--shadow-soft);
  transform: translateY(0);
  transition: transform 0.45s var(--ease), box-shadow 0.45s var(--ease);
  scrollbar-width: thin;
}
@media (min-width: 860px) {
  .panel { padding: 26px 24px; max-height: 84vh; }
}
.panel.is-lifted {
  transform: translateY(-6px);
  box-shadow: 0 26px 60px rgba(0,0,0,0.55);
}

.panel__eyebrow {
  font-family: var(--font-hand);
  font-size: 1.05rem;
  color: var(--amber);
  margin: 0 0 4px;
}
.panel__title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(1.5rem, 4vw, 2.1rem);
  line-height: 1.15;
  margin: 0 0 10px;
  color: var(--cream);
}
.panel__body {
  font-size: 0.95rem;
  line-height: 1.6;
  color: rgba(244, 234, 217, 0.82);
  margin: 0 0 16px;
}
.panel__note {
  font-family: var(--font-hand);
  font-size: 1.25rem;
  color: var(--dusty-pink);
  margin: 10px 0 0;
}

/* Page 3 — combined memory reveal, made the visual focus after replay */
.memory-reveal {
  margin-top: 16px;
  padding: 20px 18px;
  text-align: center;
  border-radius: var(--radius-md);
  background: linear-gradient(160deg, rgba(227, 163, 92, 0.20), rgba(58, 36, 54, 0.38));
  border: 1px solid rgba(227, 163, 92, 0.4);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}
.memory-reveal__line {
  font-family: var(--font-hand);
  font-size: 1.7rem;
  color: var(--amber);
  margin: 0 0 8px;
  line-height: 1.2;
}
.memory-reveal__sub {
  font-family: var(--font-ui);
  font-size: 0.88rem;
  color: rgba(244, 234, 217, 0.85);
  margin: 0;
}

/* ============================================================
   FORM ELEMENTS
   ============================================================ */
.answer-form {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}
.answer-form label { display: block; }
.answer-input {
  flex: 1;
  min-height: 44px;
  min-width: 0;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(244, 234, 217, 0.22);
  background: rgba(0, 0, 0, 0.25);
  color: var(--cream);
  font-family: var(--font-ui);
  font-size: 16px; /* prevents iOS auto-zoom on focus */
  transition: border-color 0.25s var(--ease), background 0.25s var(--ease);
}
.answer-input::placeholder { color: rgba(244, 234, 217, 0.42); }
.answer-input:focus {
  border-color: var(--amber);
  background: rgba(0, 0, 0, 0.35);
  outline: none;
}
.answer-input:disabled {
  opacity: 0.85;
  border-color: rgba(227, 163, 92, 0.5);
  background: rgba(227, 163, 92, 0.08);
  color: var(--cream);
  cursor: default;
}
.answer-submit {
  border: none;
  min-height: 44px;
  min-width: 44px;
  border-radius: var(--radius-md);
  padding: 0 18px;
  background: var(--amber);
  color: var(--ink);
  font-weight: 700;
  font-size: 0.9rem;
  transition: transform 0.2s var(--ease), background 0.2s var(--ease);
  flex-shrink: 0;
}
.answer-submit:hover { background: var(--amber-deep); }
.answer-submit:active { transform: scale(0.95); }

.response-line {
  margin-top: 14px;
  font-family: var(--font-hand);
  font-size: 1.3rem;
  color: var(--amber);
  min-height: 1.6em;
  opacity: 0;
  transform: translateY(6px);
  transition: all 0.5s var(--ease);
}
.response-line.is-visible { opacity: 1; transform: translateY(0); }
.response-line.is-soft { color: var(--dusty-pink); }

/* ============================================================
   BUTTONS (shared)
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  border: 1px solid rgba(244, 234, 217, 0.28);
  background: rgba(244, 234, 217, 0.08);
  color: var(--cream);
  border-radius: var(--radius-md);
  padding: 11px 20px;
  font-size: 0.9rem;
  font-weight: 600;
  transition: all 0.25s var(--ease);
}
.btn:hover { background: rgba(244, 234, 217, 0.16); }
.btn:active { transform: scale(0.96); }
.btn--primary {
  background: var(--amber);
  color: var(--ink);
  border-color: var(--amber);
}
.btn--primary:hover { background: var(--amber-deep); }
.btn--primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  background: rgba(244, 234, 217, 0.12);
  color: rgba(244, 234, 217, 0.5);
  border-color: transparent;
}
.btn--ghost {
  background: transparent;
  border-color: rgba(244, 234, 217, 0.3);
}
.btn--wide { width: 100%; }

/* ============================================================
   NAV ROW (back / next)
   ============================================================ */
.nav-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 20px;
}
.nav-row .btn { flex: 1; }

/* ============================================================
   MEMORY CARDS (Page 04)
   ============================================================ */
.memory-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 14px 0 18px;
}
@media (max-width: 420px) {
  .memory-grid { grid-template-columns: repeat(2, 1fr); }
}
.memory-card {
  position: relative;
  aspect-ratio: 1 / 1.1;
  border: none;
  border-radius: var(--radius-sm);
  background: rgba(0,0,0,0.28);
  border: 1px solid rgba(244,234,217,0.18);
  color: var(--cream);
  overflow: hidden;
  perspective: 600px;
}
.memory-card__inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.6s var(--ease);
}
.memory-card.is-open .memory-card__inner { transform: rotateY(180deg); }
.memory-card.is-open {
  border-color: rgba(227, 163, 92, 0.55);
  box-shadow: 0 0 0 1px rgba(227, 163, 92, 0.35), 0 6px 18px rgba(227, 163, 92, 0.18);
}
.memory-card__face {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  text-align: center;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.memory-card__face--front {
  font-family: var(--font-hand);
  font-size: 1.05rem;
  background: linear-gradient(160deg, rgba(217,169,160,0.14), rgba(58,36,54,0.28));
}
.memory-card__face--back {
  transform: rotateY(180deg);
  font-size: 0.72rem;
  line-height: 1.4;
  background: linear-gradient(160deg, rgba(227,163,92,0.22), rgba(20,13,10,0.6));
  color: rgba(244,234,217,0.92);
}
.memory-card:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }

/* ============================================================
   POLAROID / STICKER FLOURISHES
   ============================================================ */
.floating-heart {
  position: absolute;
  bottom: -10%;
  font-size: 1.1rem;
  color: var(--rose);
  opacity: 0.85;
  animation: floatUp 4.5s ease-in forwards;
  pointer-events: none;
  z-index: 30;
}
@keyframes floatUp {
  0% { transform: translateY(0) translateX(0) scale(0.8); opacity: 0; }
  10% { opacity: 0.9; }
  100% { transform: translateY(-70vh) translateX(var(--drift, 20px)) scale(1.2); opacity: 0; }
}

/* ============================================================
   BEGIN OVERLAY
   ============================================================ */
.begin-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background:
    radial-gradient(circle at 50% 30%, rgba(227,163,92,0.10), transparent 60%),
    linear-gradient(160deg, #201613 0%, #150f0d 70%);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  transition: opacity 0.8s var(--ease), visibility 0.8s var(--ease);
}
.begin-overlay.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.begin-overlay__inner { max-width: 420px; }
.begin-overlay__title {
  font-family: var(--font-display);
  font-size: clamp(2rem, 6vw, 2.8rem);
  margin: 0 0 8px;
  color: var(--cream);
}
.begin-overlay__sub {
  font-family: var(--font-hand);
  font-size: 1.2rem;
  color: var(--dusty-pink);
  margin: 0 0 28px;
}

/* ============================================================
   FINAL PAGE EXTRAS
   ============================================================ */
.final-reveal {
  animation: fadeIn 1s var(--ease);
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.final-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}
.final-controls .btn { flex: 1 1 auto; font-size: 0.8rem; padding: 9px 14px; }

/* ============================================================
   SMALL PHONE REFINEMENTS (~320–360px)
   ============================================================ */
@media (max-width: 360px) {
  .panel { padding: 18px 16px; border-radius: var(--radius-md); }
  .panel__title { font-size: clamp(1.3rem, 6vw, 1.7rem); }
  .panel__body { font-size: 0.88rem; }
  .answer-form { flex-wrap: nowrap; }
  .answer-submit { padding: 0 14px; font-size: 0.82rem; }
  .nav-row { gap: 8px; }
  .nav-row .btn { padding: 10px 10px; font-size: 0.82rem; }
  .memory-grid { gap: 8px; }
  .music-control { padding: 4px 8px; gap: 6px; }
  .music-control__label { max-width: 54px; font-size: 0.56rem; }
}

/* Landscape phones: shrink the panel and let it hug the bottom without
   swallowing the whole viewport height. */
@media (max-height: 480px) and (orientation: landscape) {
  .panel { max-height: 92vh; padding: 14px 18px; }
  .panel-wrap { align-items: center; padding: 10px 16px; }
  .begin-overlay__title { font-size: clamp(1.4rem, 5vw, 2rem); }
}

/* ============================================================
   REDUCED MOTION
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .scene__img { transform: none !important; }
}

/* ============================================================
   FONT FALLBACK GUARD (offline safety)
   ============================================================ */
@font-face {
  font-family: "Cormorant Garamond";
  src: local("Georgia");
  font-display: swap;
}
