/* ==========================================
   Variables & Theme Definitions (Japan Spring)
   ========================================== */
:root {
  --bg-color: #fff5f6; /* Soft sakura pink-white */
  --bg-gradient: linear-gradient(135deg, #e0f2fe 0%, #fff1f2 50%, #ffe4e6 100%); /* Pastel sky-blue to sakura pink */
  
  --card-bg: rgba(255, 255, 255, 0.55); /* White glassmorphism */
  --card-border: rgba(255, 255, 255, 0.7);
  --card-border-glow: rgba(255, 101, 132, 0.4);
  
  --primary: #ff6584; /* Sakura Pink */
  --primary-glow: rgba(255, 101, 132, 0.4);
  --secondary: #db2777; /* Deep Sakura/Rose */
  --accent: #f43f5e; /* Bright Cherry blossom red */
  
  --text-main: #4a373b; /* Deep cherry-wood charcoal (very readable) */
  --text-muted: #7d6b70; /* Muted rose-grey */
  --text-highlight: #be123c; /* Dark crimson-rose for focus */
  
  --font-sans: "Outfit", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-serif: "Playfair Display", Georgia, serif;
  
  --tree-shift-x: 220px;
}

/* ==========================================
   Global Resets & Scrollbars
   ========================================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg-color);
  background-image: var(--bg-gradient);
  color: var(--text-main);
  font-family: var(--font-sans);
  min-height: 100vh;
  overflow: hidden; /* Controlled overflow on desktop, scrollbar in panels */
  display: flex;
  justify-content: center;
  align-items: center;
  perspective: 1000px;
}

/* Custom Scrollbar for the Glass Panel */
::-webkit-scrollbar {
  width: 5px;
}
::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.3);
  border-radius: 10px;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 101, 132, 0.35);
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--primary);
}

/* ==========================================
   Welcome Overlay Screen
   ========================================== */
#welcome-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #e0f2fe 0%, #fff1f2 60%, #ffe4e6 100%);
  z-index: 1000;
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
  transition: opacity 0.8s cubic-bezier(0.4, 0, 0.2, 1), transform 0.8s ease;
  overflow: hidden;
}

#welcome-overlay.welcome-overlay--hidden {
  opacity: 0;
  transform: scale(1.05);
  pointer-events: none;
}

.welcome-content {
  max-width: 480px;
  padding: 20px;
  z-index: 10;
  animation: fadeInDown 1.2s ease-out;
}

.welcome-heart-container {
  position: relative;
  width: 90px;
  height: 90px;
  margin: 0 auto 30px;
}

.welcome-heart {
  font-size: 55px;
  line-height: 90px;
  animation: heartbeat 1.4s infinite cubic-bezier(0.25, 0.8, 0.25, 1);
  filter: drop-shadow(0 0 12px rgba(255, 101, 132, 0.5));
  cursor: default;
}

.welcome-heart-halo {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 70px;
  height: 70px;
  border: 2px solid var(--primary);
  border-radius: 50%;
  transform: translate(-50%, -50%) scale(1);
  opacity: 0.6;
  animation: pulse-halo 1.8s infinite ease-out;
  pointer-events: none;
}

#welcome-title {
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(to right, #4a373b, var(--secondary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 15px;
}

.welcome-subtitle {
  font-size: 1.05rem;
  color: var(--text-muted);
  margin-bottom: 25px;
  line-height: 1.6;
}

.welcome-dedication {
  font-size: 0.95rem;
  color: var(--text-muted);
  margin-bottom: 35px;
  text-transform: uppercase;
  letter-spacing: 2px;
}

.welcome-dedication span {
  color: var(--secondary);
  font-weight: 600;
  text-shadow: 0 0 8px rgba(219, 39, 119, 0.2);
}

#enter-btn {
  background: linear-gradient(135deg, var(--primary) 0%, #f43f5e 100%);
  color: #fff;
  border: none;
  padding: 14px 32px;
  font-size: 1.05rem;
  font-weight: 600;
  border-radius: 30px;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(255, 101, 132, 0.35), 0 0 0 0 rgba(255, 101, 132, 0.2);
  transition: all 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

#enter-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(255, 101, 132, 0.5), 0 0 0 6px rgba(255, 101, 132, 0.15);
}

#enter-btn:active {
  transform: translateY(1px);
}

/* Welcome Overlay Floating Hearts */
.intro-bg-hearts {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 1;
}

.intro-bg-hearts span {
  position: absolute;
  bottom: -50px;
  font-size: 20px;
  opacity: 0.25;
  animation: floatUp 8s infinite linear;
}

.intro-bg-hearts span:nth-child(1) { left: 10%; animation-delay: 0s; font-size: 24px; }
.intro-bg-hearts span:nth-child(2) { left: 30%; animation-delay: 1.5s; }
.intro-bg-hearts span:nth-child(3) { left: 55%; animation-delay: 3s; font-size: 28px; }
.intro-bg-hearts span:nth-child(4) { left: 75%; animation-delay: 4.5s; }
.intro-bg-hearts span:nth-child(5) { left: 90%; animation-delay: 6s; }

/* ==========================================
   Click to grow seed prompt
   ========================================== */
#click-prompt {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(255, 101, 132, 0.35);
  color: var(--text-main);
  padding: 10px 24px;
  border-radius: 20px;
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: 0.5px;
  box-shadow: 0 4px 15px rgba(255, 101, 132, 0.15), 0 0 10px rgba(255, 255, 255, 0.5);
  animation: bounceUpDown 2s infinite ease-in-out;
  transition: opacity 0.5s ease;
  z-index: 90;
}

#click-prompt.fade-out {
  opacity: 0;
  pointer-events: none;
}

/* ==========================================
   Viewport and Scaling Layout
   ========================================== */
#viewport {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

#main {
  position: relative;
  width: 1100px;
  height: 680px;
  transform-origin: center center;
}

/* ==========================================
   Canvas Tree Elements (Right side / Center)
   ========================================== */
canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
  transition: transform 1.6s cubic-bezier(0.76, 0, 0.24, 1);
  z-index: 5;
}

/* Canvas shifts to the right once tree grows to make space for letter content */
canvas.shifted {
  transform: translateX(var(--tree-shift-x));
}

/* ==========================================
   Left Side Glassmorphic Box Panel
   ========================================== */
.content-box {
  position: absolute;
  top: 30px;
  left: 40px;
  width: 480px;
  height: 620px;
  z-index: 20;
  overflow-y: auto;
  overflow-x: hidden;
  opacity: 0;
  transform: translateX(-30px);
  transition: opacity 1.2s cubic-bezier(0.2, 0.8, 0.2, 1), transform 1.2s cubic-bezier(0.2, 0.8, 0.2, 1);
  pointer-events: none; /* Ignore clicks while hidden */
  padding-right: 8px;
}

.content-box.content-box--visible {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto; /* Enable interaction */
}

/* Core Glassmorphism panels */
.glass-panel {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: 20px;
  padding: 26px;
  margin-bottom: 20px;
  box-shadow: 0 8px 32px 0 rgba(255, 101, 132, 0.08), inset 0 0 0 1px rgba(255, 255, 255, 0.4);
  transition: border 0.3s ease, box-shadow 0.3s ease;
}

.glass-panel:hover {
  border-color: var(--card-border-glow);
  box-shadow: 0 10px 35px 0 rgba(255, 101, 132, 0.15), 0 8px 32px 0 rgba(255, 101, 132, 0.08);
}

/* --- Letter Panel --- */
.letter-panel {
  line-height: 1.75;
}

.letter-panel p {
  font-family: var(--font-serif);
  font-size: 1.05rem;
  font-style: italic;
  color: var(--text-main);
  margin-bottom: 14px;
  text-shadow: 0 1px 1px rgba(255, 255, 255, 0.6);
}

.letter-panel p:last-child {
  margin-bottom: 0;
}

.typewriter-cursor {
  display: inline-block;
  margin-left: 3px;
  color: var(--primary);
  animation: blink 0.8s infinite steps(2);
  text-shadow: 0 0 6px var(--primary-glow);
}

.typewriter-cursor--done {
  animation: none;
  opacity: 0;
}

/* --- Clock / Counter Panel --- */
.clock-panel {
  text-align: center;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 1s ease 0.3s, transform 1s ease 0.3s;
}

#clock-text {
  font-size: 0.9rem;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 12px;
  font-weight: 600;
}

#clock-text .name {
  font-weight: 700;
}
#clock-text .highlight-her {
  color: var(--secondary);
  text-shadow: 0 0 8px rgba(219, 39, 119, 0.15);
}
#clock-text .highlight-you {
  color: var(--text-main);
}

#clock {
  font-family: var(--font-sans);
  font-weight: 500;
  color: var(--text-main);
  font-size: 0.95rem;
  letter-spacing: 0.5px;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
}

#clock .digit {
  font-family: var(--font-sans);
  font-weight: 800;
  font-size: 1.6rem;
  color: var(--secondary);
  background: rgba(255, 255, 255, 0.7);
  padding: 4px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 101, 132, 0.15);
  margin: 0 2px;
  min-width: 45px;
  display: inline-block;
  box-shadow: 0 3px 8px rgba(255, 101, 132, 0.08);
}

/* --- Section Headers --- */
.section-header {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--text-main);
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* --- Relationship Timeline --- */
.timeline-panel {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 1s ease 0.5s, transform 1s ease 0.5s;
}

#timeline-container {
  position: relative;
  padding-left: 20px;
  border-left: 2px solid rgba(255, 101, 132, 0.25);
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.timeline-card {
  position: relative;
}

/* Dot on the timeline vertical line */
.timeline-card::before {
  content: "";
  position: absolute;
  left: -27px;
  top: 6px;
  width: 12px;
  height: 12px;
  background-color: var(--bg-color);
  border: 2px solid var(--primary);
  border-radius: 50%;
  box-shadow: 0 0 6px var(--primary-glow);
  transition: all 0.3s ease;
  z-index: 2;
}

.timeline-card:hover::before {
  background-color: var(--primary);
  transform: scale(1.25);
}

.timeline-date {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--secondary);
  margin-bottom: 4px;
  letter-spacing: 1px;
}

.timeline-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 6px;
}

.timeline-text {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* --- Reasons generator --- */
.reasons-panel {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 1s ease 0.7s, transform 1s ease 0.7s;
}

#reason-card {
  min-height: 150px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  text-align: center;
  gap: 15px;
}

#reason-text {
  font-family: var(--font-serif);
  font-size: 1.15rem;
  font-style: italic;
  color: var(--text-highlight);
  line-height: 1.6;
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.25s ease, transform 0.25s ease;
  margin: auto 0;
}

#reason-next-btn {
  background: transparent;
  border: 1px solid rgba(255, 101, 132, 0.5);
  color: var(--secondary);
  padding: 10px 20px;
  font-size: 0.85rem;
  font-weight: 700;
  border-radius: 20px;
  cursor: pointer;
  letter-spacing: 0.5px;
  transition: all 0.3s ease;
  box-shadow: 0 3px 8px rgba(255, 101, 132, 0.06);
}

#reason-next-btn:hover {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
  box-shadow: 0 4px 15px rgba(255, 101, 132, 0.3);
  transform: translateY(-1px);
}

#reason-next-btn:active {
  transform: translateY(0);
}

/* --- Content box sign-off footer --- */
.content-footer {
  text-align: center;
  padding: 10px 0 30px;
  color: var(--text-muted);
  font-size: 0.8rem;
  letter-spacing: 1px;
}

.signature {
  margin-top: 15px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.visit-btn {
  display: inline-block;
  background: rgba(255, 101, 132, 0.08);
  border: 1px solid rgba(255, 101, 132, 0.35);
  color: var(--secondary);
  padding: 4px 12px;
  border-radius: 12px;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.7rem;
  transition: all 0.3s ease;
  box-shadow: 0 2px 5px rgba(255, 101, 132, 0.05);
}

.visit-btn:hover {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(255, 101, 132, 0.2);
}

.visit-btn:active {
  transform: translateY(0);
}

/* Helper Class for Fade in groups */
.fade-in-visible {
  opacity: 1 !important;
  transform: translateY(0) !important;
}

/* ==========================================
   Animations
   ========================================== */
@keyframes heartbeat {
  0% { transform: scale(1); }
  14% { transform: scale(1.12); }
  28% { transform: scale(1); }
  42% { transform: scale(1.12); }
  70% { transform: scale(1); }
}

@keyframes pulse-halo {
  0% { transform: translate(-50%, -50%) scale(0.9); opacity: 0.7; }
  100% { transform: translate(-50%, -50%) scale(1.6); opacity: 0; }
}

@keyframes blink {
  0%, 100% { opacity: 0; }
  50% { opacity: 1; }
}

@keyframes floatUp {
  0% { transform: translateY(0) rotate(0deg); opacity: 0.25; }
  100% { transform: translateY(-100vh) rotate(360deg); opacity: 0; }
}

@keyframes fadeInDown {
  0% { opacity: 0; transform: translateY(-30px); }
  100% { opacity: 1; transform: translateY(0); }
}

@keyframes bounceUpDown {
  0%, 100% { transform: translate(-50%, 0); }
  50% { transform: translate(-50%, -8px); }
}

/* ==========================================
   Mobile-mode body: CSS-only sakura petal background
   ========================================== */
body.mobile-mode {
  overflow-x: hidden;
  background-color: var(--bg-color);
  background-image: var(--bg-gradient);
}

body.mobile-mode::before {
  content: "🌸";
  position: fixed;
  font-size: 22px;
  opacity: 0.3;
  top: -40px;
  left: 15%;
  animation: floatDown 7s infinite linear;
  pointer-events: none;
  z-index: 0;
}
body.mobile-mode::after {
  content: "🌸";
  position: fixed;
  font-size: 18px;
  opacity: 0.25;
  top: -40px;
  left: 70%;
  animation: floatDown 9s 2s infinite linear;
  pointer-events: none;
  z-index: 0;
}

/* ==========================================
   Responsive Adaptations (Mobile Screen)
   ========================================== */
@media (max-width: 768px) {
  body {
    overflow: hidden; /* Lock until unlocked */
    align-items: center;
    min-height: 100vh;
  }

  body.unlocked {
    overflow-y: auto;
    overflow-x: hidden;
    align-items: flex-start;
  }

  /* Welcome screen stays perfectly centered on mobile */
  #welcome-overlay {
    padding: 24px;
    background: linear-gradient(160deg, #e0f2fe 0%, #fff1f2 55%, #ffe4e6 100%);
  }

  .welcome-content {
    padding: 10px;
  }

  #welcome-title {
    font-size: 1.85rem;
    line-height: 1.2;
  }

  .welcome-subtitle {
    font-size: 0.95rem;
    margin-bottom: 18px;
  }

  .welcome-dedication {
    font-size: 0.82rem;
    margin-bottom: 28px;
    letter-spacing: 1.5px;
  }

  #enter-btn {
    padding: 14px 36px;
    font-size: 1rem;
    width: 100%;
    max-width: 260px;
  }

  /* Hide canvases on mobile - handled by JS too */
  #ground-canvas,
  #static-canvas,
  #canvas {
    display: none !important;
  }

  /* Viewport & Main reset for mobile */
  #viewport {
    width: 100%;
    height: auto;
    display: block;
    overflow: visible;
  }

  #main {
    width: 100%;
    height: auto;
    display: block;
    transform: none !important;
  }

  /* Content box slides in from below */
  .content-box {
    position: relative;
    width: 92%;
    max-width: 500px;
    height: auto;
    left: auto;
    top: auto;
    margin: 24px auto 60px;
    padding: 0;
    opacity: 0;
    transform: translateY(30px);
    pointer-events: none;
    display: flex;
    flex-direction: column;
    gap: 0;
    transition: opacity 1s ease, transform 1s ease;
    z-index: 10;
  }

  .content-box.content-box--visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
  }

  /* Panels are fully opaque and readable on mobile */
  .glass-panel {
    background: rgba(255, 255, 255, 0.82);
    border: 1px solid rgba(255, 101, 132, 0.18);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 22px 20px;
    margin-bottom: 16px;
    border-radius: 18px;
    box-shadow: 0 4px 20px rgba(255, 101, 132, 0.1);
  }

  /* Letter panel text slightly smaller for narrow screens */
  .letter-panel p {
    font-size: 0.98rem;
    line-height: 1.7;
    margin-bottom: 12px;
  }

  /* Clock panel */
  .clock-panel {
    opacity: 0;
    transform: translateY(16px);
    transition: opacity 0.8s ease 0.2s, transform 0.8s ease 0.2s;
  }

  #clock-text {
    font-size: 0.78rem;
    letter-spacing: 1.2px;
    margin-bottom: 10px;
  }

  #clock {
    gap: 3px;
    flex-wrap: wrap;
    justify-content: center;
  }

  #clock .digit {
    font-size: 1.3rem;
    padding: 4px 7px;
    min-width: 36px;
    margin: 0 1px;
    background: rgba(255, 255, 255, 0.85);
  }

  /* Timeline */
  .timeline-panel {
    opacity: 0;
    transform: translateY(16px);
    transition: opacity 0.8s ease 0.35s, transform 0.8s ease 0.35s;
  }

  .section-header {
    font-size: 1.05rem;
    margin-bottom: 16px;
  }

  #timeline-container {
    padding-left: 18px;
    gap: 20px;
  }

  .timeline-card::before {
    left: -25px;
    width: 10px;
    height: 10px;
  }

  .timeline-date {
    font-size: 0.72rem;
  }

  .timeline-title {
    font-size: 0.9rem;
  }

  .timeline-text {
    font-size: 0.82rem;
  }

  /* Reasons */
  .reasons-panel {
    opacity: 0;
    transform: translateY(16px);
    transition: opacity 0.8s ease 0.5s, transform 0.8s ease 0.5s;
  }

  #reason-card {
    min-height: 130px;
    gap: 12px;
  }

  #reason-text {
    font-size: 1rem;
    line-height: 1.55;
  }

  #reason-next-btn {
    padding: 10px 22px;
    font-size: 0.82rem;
    width: 100%;
    max-width: 220px;
  }

  /* Footer */
  .content-footer {
    padding: 6px 0 30px;
    font-size: 0.75rem;
  }
}

/* Very small phones */
@media (max-width: 380px) {
  #welcome-title {
    font-size: 1.6rem;
  }

  .welcome-subtitle {
    font-size: 0.88rem;
  }

  #clock .digit {
    font-size: 1.1rem;
    padding: 3px 5px;
    min-width: 30px;
  }
}

/* ==========================================
   Extra Animations
   ========================================== */
@keyframes floatDown {
  0%   { transform: translateY(0) rotate(0deg);   opacity: 0.3; }
  100% { transform: translateY(110vh) rotate(180deg); opacity: 0; }
}
