/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --flower-color: #f9a8c4;
}

html, body {
  height: 100%;
  overflow-x: hidden;
}

html {
  background-color: #1a0530;
}

html::before {
  content: '';
  position: fixed;
  inset: 0;
  background: linear-gradient(160deg, #1a0530 0%, #3d0f5e 40%, #6b1e8e 70%, #c2185b 100%);
  z-index: -1;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  background: transparent;
  font-family: system-ui, -apple-system, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  overscroll-behavior: none;
  padding-bottom: calc(48px + env(safe-area-inset-bottom));
  padding-top: env(safe-area-inset-top);
}

/* ── Hearts Layer ─────────────────────────────────────────────────────────── */
#hearts-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  overflow: hidden;
}

.heart {
  position: absolute;
  bottom: -20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  animation: float-up var(--dur, 6s) ease-in forwards;
  will-change: transform, opacity;
}

.heart-icon {
  line-height: 1;
  filter: drop-shadow(0 0 6px currentColor);
}

.heart-msg {
  font-size: 0.58em;
  color: inherit;
  white-space: nowrap;
  font-style: italic;
  letter-spacing: 0.02em;
  opacity: 0.85;
}

/* ── Scene ────────────────────────────────────────────────────────────────── */
#scene {
  position: relative;
  width: 320px;
  height: 420px;
  flex-shrink: 0;
}

#vase-svg {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 160px;
  height: 200px;
  z-index: 3;
  filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.4));
}

#flower-stage {
  position: absolute;
  bottom: 158px;
  left: 0;
  width: 100%;
  height: 290px;
  z-index: 2;
  overflow: visible;
}

/* ── Flower Units ─────────────────────────────────────────────────────────── */
.flower-unit {
  transform-box: fill-box;
  transform-origin: bottom center;
}

.stem {
  stroke: #4ade80;
  stroke-width: 3;
  stroke-linecap: round;
  fill: none;
  filter: drop-shadow(0 0 3px rgba(74, 222, 128, 0.4));
}

.leaf {
  fill: #4ade80;
  opacity: 0;
}

.bloom {
  opacity: 0;
  transform-box: fill-box;
  transform-origin: 50% 100%;
  transform: scale(0.2);
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.3));
}

/* ── Animations ───────────────────────────────────────────────────────────── */
@keyframes stem-grow {
  to { stroke-dashoffset: 0; }
}

@keyframes leaf-in {
  from { opacity: 0; transform: scale(0.5); }
  to   { opacity: 0.85; transform: scale(1); }
}

@keyframes bloom-in {
  0%   { opacity: 0; transform: scale(0.2); }
  55%  { opacity: 1; transform: scale(1.15); }
  75%  { transform: scale(0.95); }
  100% { opacity: 1; transform: scale(1); }
}

@keyframes sway {
  0%   { transform: rotate(var(--sway-from, -4deg)); }
  50%  { transform: rotate(var(--sway-to, 4deg)); }
  100% { transform: rotate(var(--sway-from, -4deg)); }
}

@keyframes float-up {
  0%   { transform: translateY(0)       scale(1);   opacity: 0;   }
  12%  {                                            opacity: 1;   }
  88%  {                                            opacity: 0.7; }
  100% { transform: translateY(-88vh)   scale(0.5); opacity: 0;   }
}

/* Animation classes added by JS */
.stem.growing {
  animation: stem-grow 1.3s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

.leaf.leafing {
  animation: leaf-in 0.5s ease-out forwards;
}

.bloom.blooming {
  animation: bloom-in 0.9s cubic-bezier(0.22, 1.0, 0.36, 1) forwards;
}

.flower-unit.swaying {
  animation: sway var(--sway-dur, 3.5s) ease-in-out infinite;
}

/* ── Settings Toggle ──────────────────────────────────────────────────────── */
#settings-toggle {
  position: fixed;
  top: calc(20px + env(safe-area-inset-top));
  right: calc(20px + env(safe-area-inset-right));
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.10);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: rgba(255, 255, 255, 0.85);
  font-size: 22px;
  cursor: pointer;
  z-index: 200;
  transition: transform 0.4s ease, background 0.2s, color 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

#settings-toggle:hover {
  transform: rotate(90deg);
  background: rgba(255, 255, 255, 0.18);
  color: white;
}

/* ── Settings Panel ───────────────────────────────────────────────────────── */
#settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  height: 100dvh;
  width: 270px;
  background: rgba(18, 6, 34, 0.78);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-left: 1px solid rgba(255, 255, 255, 0.12);
  z-index: 150;
  padding: calc(28px + env(safe-area-inset-top)) 22px 28px;
  transform: translateX(100%);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-y: auto;
}

#settings-panel.open {
  transform: translateX(0);
}

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 32px;
  color: white;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

#settings-close {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.5);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  padding: 4px 6px;
  border-radius: 4px;
  transition: color 0.2s, background 0.2s;
}

#settings-close:hover {
  color: white;
  background: rgba(255, 255, 255, 0.08);
}

.settings-section {
  margin-bottom: 32px;
}

.settings-section h3 {
  color: rgba(255, 255, 255, 0.5);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  margin-bottom: 14px;
}

/* ── Type Buttons ─────────────────────────────────────────────────────────── */
.type-buttons {
  display: flex;
  gap: 8px;
}

.type-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 4px 8px;
  background: rgba(255, 255, 255, 0.07);
  border: 2px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  color: rgba(255, 255, 255, 0.6);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}

.type-btn svg {
  width: 54px;
  height: 54px;
  overflow: visible;
}

.type-btn:hover {
  background: rgba(255, 255, 255, 0.13);
  border-color: rgba(255, 255, 255, 0.28);
  color: rgba(255, 255, 255, 0.9);
}

.type-btn.active {
  background: rgba(249, 168, 196, 0.18);
  border-color: rgba(249, 168, 196, 0.7);
  color: white;
}

/* ── Colour Swatches ──────────────────────────────────────────────────────── */
.swatch-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.swatch {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.18);
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
  flex-shrink: 0;
}

.swatch:hover {
  transform: scale(1.18);
}

.swatch.active {
  border-color: white;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.35);
  transform: scale(1.1);
}

.swatch-custom {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px dashed rgba(255, 255, 255, 0.35);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.6);
  font-size: 16px;
  font-weight: 300;
  line-height: 1;
  position: relative;
  flex-shrink: 0;
  transition: transform 0.15s, border-color 0.15s, color 0.15s;
}

.swatch-custom:hover {
  transform: scale(1.18);
  border-color: rgba(255, 255, 255, 0.6);
  color: white;
}

.swatch-custom input[type="color"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
  border-radius: 50%;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  #scene {
    width: 280px;
    height: 370px;
  }

  #vase-svg {
    width: 136px;
    height: 170px;
  }

  #flower-stage {
    bottom: 134px;
    height: 260px;
  }

  #settings-panel {
    width: 100vw;
    border-left: none;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    height: auto;
    max-height: 80vh;
    top: auto;
    bottom: 0;
    right: 0;
    transform: translateY(100%);
    border-radius: 16px 16px 0 0;
  }

  #settings-panel.open {
    transform: translateY(0);
  }

  body {
    padding-bottom: calc(32px + env(safe-area-inset-bottom));
  }

  #settings-panel {
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
}

@media (prefers-reduced-motion: reduce) {
  .stem.growing,
  .leaf.leafing,
  .bloom.blooming,
  .flower-unit.swaying,
  .heart {
    animation: none;
  }

  .stem.growing {
    stroke-dashoffset: 0;
  }

  .bloom.blooming {
    opacity: 1;
    transform: scale(1);
  }

  .leaf.leafing {
    opacity: 0.85;
  }
}
