/* ===== RESET & BASE ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #f2ede3;
  --ink: #1a1a1a;
  --ink-soft: #555555;
  --ink-light: #999999;
  --leaf-dark-green: #2d6a3f;
  --leaf-mid-green: #3d8b52;
  --leaf-light-green: #6ab872;
  --leaf-yellow: #c9b44a;
  --leaf-orange: #d4884a;
  --leaf-pink: #d46a8a;
  --card-bg: #fffef9;
  --card-border: #ddd5c8;
  --gold: #c9a84c;
  --font-heading: 'Libre Baskerville', serif;
  --font-body: 'Libre Baskerville', serif;
  --font-hand: 'Pangolin', cursive;
  --font-mono: 'DM Mono', monospace;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Paper grain overlay */
#grain-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.04;
}

/* ===== PAGE LAYOUT ===== */
.page {
  max-width: 600px;
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
}

/* ===== HEADER ===== */
.header {
  text-align: center;
  margin-bottom: 2rem;
}

.header-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.85rem;
  border: 1.5px solid var(--ink);
  border-radius: 50px;
  margin-bottom: 1rem;
}

.header-mascot {
  width: 22px;
  height: auto;
}

.badge-text {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.03em;
}

.header-title {
  font-family: var(--font-heading);
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
  line-height: 1.2;
}

.header-subtitle {
  font-family: var(--font-hand);
  font-size: 1.35rem;
  color: var(--ink-soft);
  margin-bottom: 1rem;
}

.header-note {
  font-family: var(--font-hand);
  font-style: italic;
  font-size: 1.1rem;
  color: var(--ink-light);
  max-width: 420px;
  margin: 0 auto;
  line-height: 1.5;
}

/* ===== STATS BAR ===== */
.stats-bar {
  display: flex;
  justify-content: center;
  gap: 2.5rem;
  margin-bottom: 1.5rem;
}

.stat {
  text-align: center;
}

.stat-value {
  display: block;
  font-family: var(--font-mono);
  font-size: 1.4rem;
  font-weight: 500;
  line-height: 1.2;
}

.stat-label {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--ink-light);
  letter-spacing: 0.02em;
}

/* ===== PROGRESS BAR ===== */
.progress-section {
  margin-bottom: 1.5rem;
  max-width: 400px;
  margin-left: auto;
  margin-right: auto;
}

.progress-label {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.12em;
  color: var(--ink-light);
  margin-bottom: 0.4rem;
  text-align: center;
}

.progress-bar {
  height: 5px;
  background: #e0dbd2;
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 0.5rem;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--leaf-dark-green);
  border-radius: 3px;
  transition: width 0.8s cubic-bezier(0.22, 1, 0.36, 1);
}

.progress-stages {
  display: flex;
  justify-content: space-between;
}

.stage {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--ink-light);
  transition: color 0.3s;
}

.stage.active {
  color: var(--leaf-dark-green);
  font-weight: 500;
}

/* ===== TREE SCENE ===== */
.tree-scene {
  position: relative;
  width: 100%;
  max-width: 550px;
  margin: 0 auto 2rem;
  /* Aspect ratio matches tree images 768:1370 */
  aspect-ratio: 768 / 1370;
}

.tree-images {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.tree-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  transition: opacity 0.8s ease;
  pointer-events: none;
}

.leaves-container {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* ===== INDIVIDUAL LEAF ===== */
.leaf {
  position: absolute;
  cursor: pointer;
  pointer-events: auto;
  opacity: 0;
  transform: scale(0);
  animation: leaf-appear 0.5s ease forwards;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.15));
  transform-origin: center bottom;
}

.leaf img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  display: block;
}

.leaf:hover {
  transform: scale(1.3) rotate(var(--leaf-rotation, 0deg)) !important;
  filter: drop-shadow(0 3px 6px rgba(0,0,0,0.25));
  z-index: 10;
}

@keyframes leaf-appear {
  0% {
    opacity: 0;
    transform: scale(0) rotate(0deg);
  }
  60% {
    opacity: 1;
    transform: scale(1.1) rotate(var(--leaf-rotation, 0deg));
  }
  100% {
    opacity: 1;
    transform: scale(1) rotate(var(--leaf-rotation, 0deg));
  }
}

@keyframes leaf-sway {
  0%, 100% {
    transform: scale(1) rotate(var(--leaf-rotation, 0deg)) translateY(0);
  }
  33% {
    transform: scale(1) rotate(calc(var(--leaf-rotation, 0deg) + 4deg)) translateY(-1.5px);
  }
  66% {
    transform: scale(1) rotate(calc(var(--leaf-rotation, 0deg) - 2deg)) translateY(0.5px);
  }
}

.leaf.placed {
  animation: leaf-appear 0.5s ease forwards, leaf-sway ease-in-out infinite;
  animation-delay: var(--leaf-delay, 0s), calc(var(--leaf-delay, 0s) + 0.5s);
  animation-duration: 0.5s, var(--sway-duration, 3.5s);
}

/* Mascot */
.scene-mascot {
  position: absolute;
  width: 60px;
  height: auto;
  bottom: 2%;
  right: 16%;
  transform: rotate(-5deg);
  transform-origin: bottom center;
  animation: mascot-sit 3s ease-in-out infinite;
  pointer-events: none;
  z-index: 5;
}

@keyframes mascot-sit {
  0%, 100% { transform: rotate(-5deg) translateY(0); }
  50% { transform: rotate(-3deg) translateY(-2px); }
}

/* ===== WISH POPUP (DESKTOP) ===== */
.wish-popup {
  position: absolute;
  background: var(--card-bg);
  border: 1.5px solid var(--card-border);
  border-radius: 10px;
  padding: 0.85rem 1rem;
  max-width: 250px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.07);
  z-index: 20;
  opacity: 0;
  transform: scale(0.92);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}

.wish-popup.visible {
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
}

.wish-popup-close {
  position: absolute;
  top: 0.3rem;
  right: 0.5rem;
  background: none;
  border: none;
  font-size: 1.1rem;
  color: var(--ink-light);
  cursor: pointer;
  line-height: 1;
}

.wish-popup-content .wish-item {
  margin-bottom: 0.6rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid #eee;
}

.wish-popup-content .wish-item:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.wish-item-author {
  font-family: var(--font-hand);
  font-size: 1.05rem;
  color: var(--ink);
  margin-bottom: 0.15rem;
}

.wish-item-text {
  font-family: var(--font-hand);
  font-size: 0.9rem;
  color: var(--ink-soft);
  line-height: 1.4;
}

/* ===== WISH BOTTOM SHEET (MOBILE) ===== */
.wish-sheet {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  background: rgba(0,0,0,0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}

.wish-sheet[hidden] {
  display: none;
}

.wish-sheet.visible {
  opacity: 1;
  pointer-events: auto;
}

.wish-sheet-inner {
  width: 100%;
  background: var(--card-bg);
  border-radius: 16px 16px 0 0;
  padding: 1rem 1.25rem 2rem;
  position: relative;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
  max-height: 60vh;
  overflow-y: auto;
}

.wish-sheet.visible .wish-sheet-inner {
  transform: translateY(0);
}

.wish-sheet-handle {
  width: 36px;
  height: 4px;
  background: #d0cbc3;
  border-radius: 2px;
  margin: 0 auto 0.75rem;
}

.wish-sheet-close {
  position: absolute;
  top: 0.75rem;
  right: 1rem;
  background: none;
  border: none;
  font-size: 1.4rem;
  color: var(--ink-light);
  cursor: pointer;
}

.wish-sheet-content .wish-item {
  margin-bottom: 0.8rem;
  padding-bottom: 0.8rem;
  border-bottom: 1px solid #eee;
}

.wish-sheet-content .wish-item:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

/* ===== WISH FORM ===== */
.wish-form-section {
  margin-bottom: 2.5rem;
}

.wish-form-card {
  background: var(--card-bg);
  border: 1.5px solid var(--card-border);
  border-radius: 14px;
  padding: 1.5rem;
}

.form-title {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
  text-align: center;
}

.form-subtitle {
  font-family: var(--font-hand);
  font-size: 1rem;
  color: var(--ink-light);
  text-align: center;
  margin-bottom: 1rem;
}

.prompt-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: center;
  margin-bottom: 1rem;
}

.pill {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  padding: 0.3rem 0.65rem;
  border: 1px solid var(--card-border);
  border-radius: 50px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.pill:hover, .pill.active {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}

.form-input,
.form-textarea {
  display: block;
  width: 100%;
  font-family: var(--font-hand);
  font-size: 1.05rem;
  padding: 0.65rem 0.75rem;
  border: 1.5px solid var(--card-border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  outline: none;
  transition: border-color 0.2s;
}

.form-input:focus,
.form-textarea:focus {
  border-color: var(--ink-light);
}

.form-input {
  margin-bottom: 0.6rem;
}

.form-textarea {
  resize: vertical;
  min-height: 80px;
  margin-bottom: 0.8rem;
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: #bbb5a8;
}

/* Photo upload area */
.photo-upload-area {
  margin-bottom: 0.8rem;
}

.photo-upload-label {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  padding: 0.5rem 1rem;
  border: 1.5px dashed var(--card-border);
  border-radius: 8px;
  cursor: pointer;
  color: var(--ink-soft);
  transition: border-color 0.2s, background 0.2s;
}

.photo-upload-label:hover {
  border-color: var(--ink-light);
  background: rgba(0,0,0,0.02);
}

.photo-preview {
  display: block;
  max-width: 120px;
  max-height: 90px;
  border-radius: 6px;
  margin-top: 0.5rem;
  object-fit: cover;
}

.form-submit {
  display: block;
  width: 100%;
  font-family: var(--font-hand);
  font-size: 1.15rem;
  padding: 0.7rem 1.5rem;
  border: none;
  border-radius: 8px;
  background: var(--ink);
  color: var(--bg);
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}

.form-submit:hover {
  opacity: 0.88;
}

.form-submit:active {
  transform: scale(0.98);
}

.form-submit:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ===== FOOTER ===== */
.footer {
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--ink-light);
  padding: 1rem 0;
  letter-spacing: 0.02em;
}

/* ===== MODAL OVERLAY ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(242, 237, 227, 0.93);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s;
  padding: 1.5rem 1rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.modal-overlay[hidden] {
  display: none;
}

.modal-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  transform: scale(0.92);
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.modal-overlay.visible .modal-content {
  transform: scale(1);
}

/* ===== POLAROID CARD ===== */
.polaroid-card {
  position: relative;
  width: 270px;
  aspect-ratio: 54 / 86;
  background: #ffffff;
  border-radius: 4px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow:
    0 4px 16px rgba(0,0,0,0.15),
    0 12px 40px rgba(0,0,0,0.12);
  transform: rotate(var(--polaroid-rotation, -1deg));
}

.polaroid-photo-area {
  flex: 1;
  background: #f5f0e8;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  margin: 10px 10px 0 10px;
}

.polaroid-photo-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.polaroid-strip {
  padding: 0.7rem 0.85rem 0.6rem;
  min-height: 72px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.polaroid-wish {
  font-family: var(--font-hand);
  font-size: 0.82rem;
  color: var(--ink);
  line-height: 1.35;
  margin-bottom: 0.25rem;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.polaroid-name {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--ink-soft);
  margin-bottom: 0.35rem;
}

.polaroid-branding {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 0.5rem;
  color: var(--ink-light);
  letter-spacing: 0.02em;
}

/* ===== MODAL ACTIONS ===== */
.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
  justify-content: center;
}

.btn-primary, .btn-secondary {
  font-family: var(--font-hand);
  font-size: 1.05rem;
  padding: 0.6rem 1.2rem;
  border-radius: 8px;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

.btn-primary {
  background: var(--ink);
  color: var(--bg);
  border: none;
}

.btn-share {
  background: var(--leaf-dark-green);
}

.btn-secondary {
  background: transparent;
  color: var(--ink);
  border: 1.5px solid var(--ink);
}

.btn-primary:hover, .btn-secondary:hover {
  opacity: 0.85;
}

.btn-primary:active, .btn-secondary:active {
  transform: scale(0.97);
}

/* ===== LOADING OVERLAY ===== */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  transition: opacity 0.5s;
}

.loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-text {
  font-family: var(--font-hand);
  font-size: 1.2rem;
  color: var(--ink-light);
  animation: loading-pulse 1.5s ease-in-out infinite;
}

@keyframes loading-pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 600px) {
  .page {
    padding: 1.5rem 1rem 2.5rem;
  }

  .header-title {
    font-size: 1.6rem;
  }

  .header-subtitle {
    font-size: 1.15rem;
  }

  .header-note {
    font-size: 0.95rem;
  }

  .stats-bar {
    gap: 1.8rem;
  }

  .tree-scene {
    width: 92vw;
    max-width: none;
  }

  .scene-mascot {
    width: 45px;
  }

  .polaroid-card {
    width: 250px;
  }

  .wish-form-card {
    padding: 1.2rem;
  }

  .modal-actions {
    flex-direction: column;
    align-items: center;
  }

  .btn-primary, .btn-secondary {
    width: 100%;
    max-width: 250px;
    text-align: center;
  }
}

@media (min-width: 600px) and (max-width: 900px) {
  .tree-scene {
    max-width: 500px;
  }
}
