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

:root {
  --pink-50: #fdf2f8;
  --pink-100: #fce4ec;
  --pink-200: #f8bbd0;
  --pink-300: #f48fb1;
  --pink-400: #f06292;
  --pink-500: #e91e63;
  --pink-600: #c2185b;
  --pink-700: #ad1457;
  --card-bg: rgba(255, 255, 255, 0.78);
  --card-border: rgba(255, 255, 255, 0.55);
  --shadow: 0 8px 32px rgba(233, 30, 99, 0.10);
  --shadow-hover: 0 12px 48px rgba(233, 30, 99, 0.18);
}

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  min-height: 100dvh;
  min-height: 100vh;
  background: linear-gradient(135deg, #fce4ec, #f8bbd0, #f48fb1, #f06292, #ec407a, #f48fb1, #fce4ec);
  background-size: 400% 400%;
  animation: gradientShift 12s ease infinite;
  background-attachment: fixed;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  position: relative;
  overflow-x: hidden;
  color: #3d2a36;
}

@keyframes gradientShift {
  0%   { background-position: 0% 50%; }
  25%  { background-position: 100% 0%; }
  50%  { background-position: 100% 100%; }
  75%  { background-position: 0% 100%; }
  100% { background-position: 0% 50%; }
}

/* ===== Particle Canvas ===== */
#particleCanvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

/* ===== Decorative Corner Flowers ===== */
.deco-flower {
  position: fixed;
  font-size: 2rem;
  pointer-events: none;
  z-index: 1;
  opacity: 0.22;
  animation: gentleSway 5s ease-in-out infinite;
}
.deco-top-left    { top: 1rem; left: 1rem; }
.deco-top-right   { top: 1rem; right: 1rem; animation-delay: 1s; }
.deco-bottom-left { bottom: 1rem; left: 1rem; animation-delay: 2s; }
.deco-bottom-right { bottom: 1rem; right: 1rem; animation-delay: 3s; }

@keyframes gentleSway {
  0%, 100% { transform: rotate(-5deg) scale(1); }
  50%      { transform: rotate(5deg) scale(1.08); }
}

/* ===== Container & Card ===== */
.container {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  animation: cardEntrance 0.7s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes cardEntrance {
  from { opacity: 0; transform: translateY(30px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.card {
  background: var(--card-bg);
  backdrop-filter: blur(28px) saturate(1.6);
  -webkit-backdrop-filter: blur(28px) saturate(1.6);
  border: 1px solid var(--card-border);
  border-radius: 40px;
  padding: 2.5rem 1.75rem;
  box-shadow: var(--shadow);
  transition: box-shadow 0.3s ease, transform 0.3s ease;
}

.card:hover {
  box-shadow: var(--shadow-hover);
}

/* ===== Header ===== */
.header-badge {
  text-align: center;
  font-size: 2.6rem;
  margin-bottom: 0.5rem;
  animation: gentlePulse 3s ease-in-out infinite;
  filter: drop-shadow(0 2px 8px rgba(233,30,99,0.12));
}

@keyframes gentlePulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.08); }
}

.title {
  font-family: 'Playfair Display', Georgia, serif;
  font-weight: 700;
  font-size: 2.2rem;
  line-height: 1.15;
  text-align: center;
  color: #4a1a36;
  margin-bottom: 0.75rem;
  letter-spacing: -0.02em;
}

.subtitle {
  text-align: center;
  font-size: 0.95rem;
  line-height: 1.6;
  color: #6b4a5d;
  margin-bottom: 1.75rem;
  font-weight: 400;
}

/* ── Rainbow animated R ── */
.r-letter {
  display: inline-block;
  font-family: 'Playfair Display', serif;
  font-weight: 700;
  font-size: 1.3em;
  background: linear-gradient(90deg, #e91e63, #f06292, #ffd700, #f06292, #e91e63, #c2185b);
  background-size: 300% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: rainbowR 4s linear infinite;
}

@keyframes rainbowR {
  0%   { background-position: 0% 50%; }
  100% { background-position: 300% 50%; }
}

/* ── R-letter interactive states ── */
.r-letter {
  transition: transform 0.2s ease, text-shadow 0.2s ease;
  cursor: default;
}

/* Rejection on keystroke (subtle) */
.r-letter.r-reject-keystroke {
  animation: rRejectQuick 0.5s ease;
}

/* Happy acceptance on keystroke (subtle) */
.r-letter.r-accept-keystroke {
  animation: rAcceptQuick 0.4s ease;
}

/* Full rejection animation (on submit) */
.r-letter.r-reject {
  animation: rRejectDramatic 0.9s ease;
}

/* Full acceptance animation (on valid submit) */
.r-letter.r-accept {
  animation: rAcceptDramatic 0.6s ease;
}

@keyframes rRejectQuick {
  0%   { transform: scale(1); }
  30%  { transform: scale(1.25) rotate(-5deg); }
  60%  { transform: scale(1.15) rotate(3deg); }
  100% { transform: scale(1) rotate(0deg); }
}

@keyframes rAcceptQuick {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.2) rotate(-3deg); }
  70%  { transform: scale(0.95); }
  100% { transform: scale(1); }
}

@keyframes rRejectDramatic {
  0%   { transform: scale(1); text-shadow: 0 0 0 rgba(244,63,94,0); }
  15%  { transform: scale(1.6) rotate(-8deg); text-shadow: 0 0 30px rgba(244,63,94,0.6), 0 0 60px rgba(244,63,94,0.3); }
  40%  { transform: scale(1.3) rotate(5deg); text-shadow: 0 0 20px rgba(244,63,94,0.4); }
  65%  { transform: scale(1.5) rotate(-3deg); text-shadow: 0 0 25px rgba(244,63,94,0.5); }
  100% { transform: scale(1) rotate(0deg); text-shadow: 0 0 0 rgba(244,63,94,0); }
}

@keyframes rAcceptDramatic {
  0%   { transform: scale(1); }
  30%  { transform: scale(1.5) rotate(-5deg); }
  55%  { transform: scale(0.9) rotate(2deg); }
  80%  { transform: scale(1.15); }
  100% { transform: scale(1); }
}

/* ── Card shake ── */
.card-shake {
  animation: cardShakeAnim 0.5s ease;
}

@keyframes cardShakeAnim {
  0%, 100% { transform: translateX(0); }
  12%     { transform: translateX(-8px) rotate(-0.5deg); }
  25%     { transform: translateX(8px) rotate(0.5deg); }
  37%     { transform: translateX(-6px) rotate(-0.3deg); }
  50%     { transform: translateX(6px) rotate(0.3deg); }
  62%     { transform: translateX(-4px); }
  75%     { transform: translateX(4px); }
  87%     { transform: translateX(-2px); }
}

/* ── X-burst container ── */
.x-burst-container {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  overflow: hidden;
}

.x-piece {
  position: absolute;
  font-weight: 700;
  animation: xBurstOut ease-out forwards;
  opacity: 0;
}

@keyframes xBurstOut {
  0%   { transform: translate(0, 0) scale(1) rotate(0deg); opacity: 1; }
  100% { transform: translate(var(--dx, 80px), var(--dy, -120px)) scale(0) rotate(360deg); opacity: 0; }
}

/* ===== Alerts ===== */
.alert {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.875rem 1rem;
  border-radius: 16px;
  margin-bottom: 1.25rem;
  font-size: 0.9rem;
  line-height: 1.5;
  animation: slideIn 0.35s ease-out;
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.alert-success {
  background: linear-gradient(135deg, #fce4ec, #f8bbd0);
  color: #6b1a3a;
  border: 1px solid rgba(233,30,99,0.08);
}

.alert-error {
  background: linear-gradient(135deg, #ffe4e6, #fecdd3);
  color: #7f1d1d;
  border: 1px solid rgba(244,63,94,0.08);
}

.alert-icon {
  font-size: 1.3rem;
  flex-shrink: 0;
}

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

/* ===== Celebration Stamp ===== */
.stamp-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.stamp-overlay.visible {
  opacity: 1;
}

.stamp-card {
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(20px);
  border-radius: 32px;
  padding: 2.5rem 3rem;
  text-align: center;
  box-shadow: 0 20px 60px rgba(233,30,99,0.2);
  animation: stampPop 0.5s cubic-bezier(0.16, 1, 0.3, 1) both;
  transform-origin: center;
}

@keyframes stampPop {
  0%   { transform: scale(0.5) rotate(-8deg); opacity: 0; }
  60%  { transform: scale(1.08) rotate(2deg); opacity: 1; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

.stamp-emoji {
  font-size: 3.5rem;
  margin-bottom: 0.5rem;
  animation: gentlePulse 1.5s ease-in-out infinite;
}

.stamp-name {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 2.8rem;
  font-weight: 700;
  background: linear-gradient(135deg, #e91e63, #c2185b);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  line-height: 1.2;
}

.stamp-label {
  font-size: 1rem;
  color: #8a5a75;
  margin-top: 0.25rem;
  font-weight: 500;
}

/* ===== Form ===== */
.name-form {
  margin-bottom: 1.5rem;
}

.input-wrapper {
  margin-bottom: 0.75rem;
}

.input-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #8a5a75;
  margin-bottom: 0.5rem;
}

/* Input ring — glow wrapper */
.input-ring {
  position: relative;
  border-radius: 22px;
  transition: box-shadow 0.3s ease;
}
.input-ring:focus-within {
  box-shadow: 0 0 0 4px rgba(240, 98, 146, 0.18), 0 0 24px rgba(233, 30, 99, 0.06);
}
.input-ring[data-valid="true"] {
  box-shadow: 0 0 0 4px rgba(233, 30, 99, 0.12), 0 0 30px rgba(233, 30, 99, 0.08);
}
.input-ring[data-invalid="true"] {
  box-shadow: 0 0 0 4px rgba(244, 63, 94, 0.14);
}

/* Input */
#nameInput {
  display: block;
  width: 100%;
  padding: 1rem 1.25rem;
  font-family: 'Inter', sans-serif;
  font-size: 1.1rem;
  font-weight: 500;
  color: #2d1a26;
  background: rgba(255, 255, 255, 0.7);
  border: 2px solid rgba(233, 30, 99, 0.12);
  border-radius: 20px;
  outline: none;
  transition: all 0.25s ease;
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  text-transform: uppercase;
}

#nameInput::placeholder {
  color: #c99bb3;
  font-weight: 400;
  font-size: 1rem;
  text-transform: none;
}

#nameInput:focus {
  border-color: var(--pink-400);
  background: rgba(255, 255, 255, 0.95);
}

/* Valid state */
#nameInput[data-valid="true"] {
  border-color: #ec407a;
  background: rgba(255, 255, 255, 0.95);
}

/* Invalid state */
#nameInput[data-invalid="true"] {
  border-color: #f43f5e;
  animation: shakeX 0.4s ease;
}

@keyframes shakeX {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-6px); }
  40%      { transform: translateX(6px); }
  60%      { transform: translateX(-4px); }
  80%      { transform: translateX(4px); }
}

/* Hint and live error */
.input-hint {
  margin-top: 0.4rem;
  font-size: 0.75rem;
  color: #a07088;
  padding-left: 0.25rem;
  transition: all 0.3s ease;
}

.live-error {
  margin-top: 0.4rem;
  font-size: 0.78rem;
  font-weight: 500;
  color: #f43f5e;
  padding-left: 0.25rem;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.3s ease, opacity 0.3s ease, margin 0.3s ease;
}

.live-error.visible {
  max-height: 40px;
  opacity: 1;
  margin-top: 0.4rem;
}

.hidden { display: none !important; }

/* ===== Submit Button ===== */
.submit-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 1rem 1.5rem;
  font-family: 'Inter', sans-serif;
  font-size: 1.05rem;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, #e91e63, #c2185b);
  border: none;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.25s ease;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(233,30,99,0.25);
}

.submit-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, #f06292, #e91e63);
  opacity: 0;
  transition: opacity 0.3s ease;
  border-radius: 20px;
}

.submit-btn:hover::before,
.submit-btn:focus-visible::before {
  opacity: 1;
}

.submit-btn:active {
  transform: scale(0.97);
}

.submit-btn .btn-text,
.submit-btn .btn-icon {
  position: relative;
  z-index: 2;
}

.submit-btn.loading {
  pointer-events: none;
}

/* Ripple effect */
.ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  transform: scale(0);
  animation: rippleAnim 0.6s ease-out;
  pointer-events: none;
  z-index: 1;
}

@keyframes rippleAnim {
  to { transform: scale(4); opacity: 0; }
}

.btn-spinner {
  width: 20px;
  height: 20px;
  border: 2.5px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  position: relative;
  z-index: 2;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== Total Counter ===== */
.total-section {
  text-align: center;
  padding-top: 1.5rem;
  border-top: 1.5px solid rgba(233, 30, 99, 0.08);
  position: relative;
}

.total-number {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 2.8rem;
  font-weight: 700;
  color: var(--pink-500);
  line-height: 1;
  margin-bottom: 0.2rem;
  transition: transform 0.3s ease;
}

.total-number.bump {
  animation: numberBump 0.5s ease;
}

@keyframes numberBump {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.3); }
  100% { transform: scale(1); }
}

.total-label {
  font-size: 0.8rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #a07088;
}

/* ===== Footer ===== */
.footer-note {
  text-align: center;
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.7);
  margin-top: 1.25rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

/* ===== Confetti ===== */
.confetti-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
  overflow: hidden;
}

.confetti-piece {
  position: absolute;
  animation: confettiFall linear forwards;
}

@keyframes confettiFall {
  0%   { transform: translateY(0) rotate(0deg) scale(1) translateX(0); opacity: 1; }
  25%  { transform: translateY(25vh) rotate(180deg) scale(1.1) translateX(30px); }
  50%  { transform: translateY(55vh) rotate(360deg) scale(0.9) translateX(-20px); }
  75%  { transform: translateY(80vh) rotate(540deg) scale(1.05) translateX(40px); opacity: 0.8; }
  100% { transform: translateY(110vh) rotate(720deg) scale(0.3) translateX(-10px); opacity: 0; }
}

/* ===== Responsive ===== */
@media (max-width: 440px) {
  body {
    padding: 0.75rem;
    align-items: flex-start;
    padding-top: 2rem;
  }

  .card {
    padding: 2rem 1.25rem;
    border-radius: 32px;
  }

  .title {
    font-size: 1.9rem;
  }

  #nameInput {
    font-size: 1rem;
    padding: 0.875rem 1rem;
  }

  .total-number {
    font-size: 2.4rem;
  }

  .deco-flower {
    font-size: 1.4rem;
    opacity: 0.18;
  }

  .stamp-name {
    font-size: 2.2rem;
  }

  .stamp-card {
    padding: 2rem 1.5rem;
  }
}

@media (min-width: 768px) {
  .container {
    padding: 2rem 0;
  }
}

/* ===== Reduced Motion ===== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  body {
    animation: none;
    background: linear-gradient(160deg, #fce4ec 0%, #f8bbd0 28%, #f48fb1 55%, #f06292 100%);
  }

  #particleCanvas {
    display: none;
  }

  .x-burst-container {
    display: none;
  }

  #rLetter {
    animation: none !important;
    text-shadow: none !important;
  }

  .card-shake {
    animation: none !important;
  }

  .confetti-container {
    display: none;
  }

  .stamp-overlay {
    display: none;
  }
}

/* ===== Meaning reveal on success ===== */
.alert-body { display: block; }
.alert-meaning {
  display: block;
  margin-top: 0.4rem;
  font-size: 0.85rem;
  line-height: 1.4;
  font-style: italic;
  color: #6b1a3a;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.4s ease, transform 0.4s ease;
}
.alert-meaning.show { opacity: 1; transform: translateY(0); }
.alert-meaning.loading { color: #a07088; opacity: 0.85; }
