/* ============================================
   Midnight Bakery 🌙 — CSS Custom Properties
   ============================================ */
:root {
  --bg-primary: #08043b;
  --bg-secondary: #2a1f25;
  --bg-card: #352a30;
  --text-primary: #f5e6d3;
  --text-secondary: #c9a87c;
  --accent-warm: #e8a44a;
  --accent-glow: #f0c674;
  --progress-bg: #4a3a40;
  --progress-fill: #e8a44a;
  --tap-target-min: 48px;
  --transition-speed: 0.32s;
}

/* ============================================
   Gender Vote Themes — light backgrounds
   ============================================ */
body.theme-boy {
  --bg-primary: #d6eaf8;
  --bg-secondary: #c3ddf1;
  --bg-card: #b0d4f1;
  --text-primary: #1a3a5c;
  --text-secondary: #3a6a9e;
  --accent-warm: #5a9fd4;
  --accent-glow: #2e7dba;
  --progress-bg: #a8cce8;
  --progress-fill: #5a9fd4;
}

body.theme-girl {
  --bg-primary: #fce4ec;
  --bg-secondary: #f8d0da;
  --bg-card: #f3b8c8;
  --text-primary: #5c1a2a;
  --text-secondary: #9e3a5a;
  --accent-warm: #e07090;
  --accent-glow: #c94e72;
  --progress-bg: #e8a8b8;
  --progress-fill: #e07090;
}

body.theme-boy,
body.theme-girl {
  transition: background-color 0.6s ease, color 0.6s ease;
}

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

html {
  height: 100%;
  overflow: hidden;
}

body {
  height: 100%;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  position: fixed;
  width: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

/* ============================================
   Game Container — viewport-contained
   ============================================ */
.game-container {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  position: relative;
  overflow: hidden;
  max-width: 100vw;
}

/* ============================================
   Screen Sections — only one visible at a time
   ============================================ */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity var(--transition-speed) ease;
  opacity: 0;
  pointer-events: none;
}

.screen.active {
  opacity: 1;
  pointer-events: auto;
  z-index: 1;
}

.screen.hidden {
  opacity: 0;
  pointer-events: none;
  z-index: 0;
}

.screen-content {
  text-align: center;
  padding: 1.5rem;
  width: 100%;
  max-width: 480px;
}

/* ============================================
   Intro Screen
   ============================================ */
.intro-title {
  font-size: clamp(1.5rem, 5vw, 2.5rem);
  color: var(--accent-glow);
  margin-bottom: 2rem;
  line-height: 1.3;
  min-height: 2.6em;
}

/* ============================================
   Name Prompt Screen
   ============================================ */
.name-input {
  display: block;
  width: 100%;
  max-width: 320px;
  margin: 0 auto 1rem;
  min-height: var(--tap-target-min);
  padding: 0.75rem 1rem;
  border: 2px solid var(--bg-card);
  border-radius: 12px;
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: clamp(1rem, 3vw, 1.25rem);
  text-align: center;
  outline: none;
  transition: border-color var(--transition-speed) ease;
}

.name-input:focus {
  border-color: var(--accent-warm);
}

.name-input::placeholder {
  color: var(--text-secondary);
  opacity: 0.6;
}

.name-error {
  color: #e87c7c;
  font-size: 0.9rem;
  margin-bottom: 1rem;
  min-height: 1.2em;
  visibility: hidden;
}

.name-error.visible {
  visibility: visible;
}

.name-submit {
  display: block;
  margin: 0 auto;
}

.name-submit:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ============================================
   Gender Guess Buttons
   ============================================ */
.gender-guess-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 2rem;
  opacity: 0;
}

.screen.active .gender-guess-container {
  animation: fadeInUp 0.8s ease-out 0.8s forwards;
}

.gender-guess-prompt {
  font-size: clamp(1rem, 3vw, 1.2rem);
  color: var(--text-secondary);
  margin-bottom: 1rem;
  min-height: 1.4em;
}

.gender-buttons {
  display: flex;
  gap: 1.5rem;
}

.gender-btn.tap-target {
  min-width: var(--tap-target-min);
  min-height: var(--tap-target-min);
  font-size: clamp(2rem, 8vw, 3rem);
  padding: 0.5rem 1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-speed) ease, transform 0.15s ease, border-color 0.2s ease;
}

.gender-btn-boy {
  border-color: #7cb5ec;
}

.gender-btn-girl {
  border-color: #f0a0b0;
}

.gender-btn.selected {
  transform: scale(1.12);
}

/* Prevent sticky :active shrink on mobile touch for gender buttons */
.gender-btn:active {
  transform: none;
  background: inherit;
}
.gender-btn.selected:active {
  transform: scale(1.12);
}
.gender-btn-boy.selected:active {
  background: rgba(124, 181, 236, 0.25);
}
.gender-btn-girl.selected:active {
  background: rgba(240, 160, 176, 0.25);
}

.gender-btn-boy.selected {
  background: rgba(124, 181, 236, 0.25);
  border-color: #7cb5ec;
}

.gender-btn-girl.selected {
  background: rgba(240, 160, 176, 0.25);
  border-color: #f0a0b0;
}

/* ============================================
   Tap Targets — minimum 48x48px
   ============================================ */
.tap-target {
  min-width: var(--tap-target-min);
  min-height: var(--tap-target-min);
  padding: 0.875rem 1.75rem;
  border: 2px solid var(--accent-warm);
  border-radius: 12px;
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: clamp(1rem, 3vw, 1.25rem);
  cursor: pointer;
  transition: background var(--transition-speed) ease, transform 0.15s ease;
}

.tap-target:active {
  transform: scale(0.96);
  background: var(--bg-secondary);
}

/* Loading spinner for buttons */
@keyframes spin {
  to { transform: rotate(360deg); }
}

.tap-target.loading {
  position: relative;
  pointer-events: none;
  opacity: 0.7;
}

.tap-target.loading::after {
  content: '';
  display: block;
  width: 22px;
  height: 22px;
  margin: 0 auto;
  border: 3px solid var(--text-secondary);
  border-top-color: var(--accent-glow);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

/* ============================================
   Oven Screen
   ============================================ */
.oven-instruction {
  font-size: clamp(1rem, 3.5vw, 1.25rem);
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
  line-height: 1.4;
  min-height: 2.8em;
}

.oven-emoji {
  font-size: clamp(3rem, 12vw, 5rem);
  padding: 1rem 1.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: background 0.2s ease, transform 0.1s ease;
}

.oven-emoji.oven-tapped {
  background: var(--accent-warm);
  transform: scale(1.08);
}

.oven-emoji:disabled {
  opacity: 0.5;
  pointer-events: none;
}

/* ============================================
   Progress Bar
   ============================================ */
.progress-bar-container {
  width: 100%;
  max-width: 320px;
  height: 24px;
  background: var(--progress-bg);
  border-radius: 12px;
  margin: 1.5rem auto;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-warm), var(--accent-glow));
  border-radius: 12px;
  transition: width 0.3s ease;
}

.week-count {
  font-size: clamp(1.4rem, 5vw, 2rem);
  color: var(--text-primary);
  margin-top: 0.5rem;
  margin-bottom: 0.25rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.phase-text {
  font-size: clamp(0.9rem, 3vw, 1.1rem);
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
  text-align: center;
  min-height: 1.4em;
}

.phase-text.flip {
  animation: phaseFlip 0.4s ease-out;
}

@keyframes phaseFlip {
  0% {
    opacity: 0;
    transform: translateY(8px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ============================================
   Cookie Animation Container
   ============================================ */
.cookie-animation-container {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 10;
}

/* ============================================
   Cookie Animation Container
   ============================================ */
.cookie-animation-container {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 10;
}

.cookie-emoji {
  position: absolute;
  font-size: 1.8rem;
  will-change: transform, opacity;
  animation: cookieFly 1.5s ease-out forwards;
}

@keyframes cookieFly {
  0% {
    transform: translate(0, 0) rotate(0deg);
    opacity: 1;
  }
  70% {
    opacity: 1;
  }
  100% {
    transform: translate(var(--tx), var(--ty)) rotate(var(--rot));
    opacity: 0;
  }
}

/* ============================================
   Reveal Screen
   ============================================ */
.baby-emoji {
  font-size: clamp(4rem, 15vw, 6rem);
  margin-bottom: 1.5rem;
  line-height: 1;
  transform: scale(0);
  opacity: 0;
}

.reveal-message {
  font-size: clamp(1.1rem, 4vw, 1.5rem);
  color: var(--accent-glow);
  line-height: 1.4;
  max-width: 360px;
  margin: 0 auto;
  opacity: 0;
  transform: translateY(20px);
  min-height: 2.8em;
}

/* Baby pop-out animation — triggers when reveal screen becomes active */
.screen.active .baby-emoji {
  animation: babyPopOut 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* Message fade-in — starts after baby pop-out finishes */
.screen.active .reveal-message {
  animation: fadeInUp 0.8s ease-out 0.8s forwards;
}

/* ============================================
   Reveal Keyframes (Req 3.1, 3.2, 3.4)
   ============================================ */
@keyframes babyPopOut {
  0% {
    transform: scale(0);
    opacity: 0;
  }
  50% {
    opacity: 1;
    transform: scale(1.2);
  }
  70% {
    transform: scale(0.9);
  }
  85% {
    transform: scale(1.1);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes fadeInUp {
  0% {
    opacity: 0;
    transform: translateY(20px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ============================================
   Language Switcher
   ============================================ */
.lang-switcher {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 100;
  display: flex;
  gap: 6px;
}

.lang-btn {
  width: 48px;
  height: 40px;
  background: transparent;
  border: 2px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  opacity: 0.45;
  transition: opacity 0.3s ease, border-color 0.3s ease, background 0.3s ease;
}

.lang-btn img {
  display: block;
  border-radius: 2px;
}

.lang-btn:hover {
  opacity: 0.75;
}

.lang-btn.lang-active {
  opacity: 1;
  border-color: var(--accent-warm);
  background: var(--bg-card);
}

/* ============================================
   Responsive — ensure no horizontal scroll
   320px–1440px
   ============================================ */
@media (min-width: 768px) {
  .screen-content {
    max-width: 560px;
  }

  .progress-bar-container {
    max-width: 400px;
    height: 28px;
  }
}

@media (min-width: 1024px) {
  .screen-content {
    max-width: 640px;
  }
}

/* Landscape orientation on mobile */
@media (max-height: 480px) and (orientation: landscape) {
  .intro-title {
    font-size: clamp(1.2rem, 4vw, 1.8rem);
    margin-bottom: 1rem;
  }

  .oven-emoji {
    font-size: clamp(2rem, 8vw, 3rem);
    padding: 0.5rem 1rem;
  }

  .baby-emoji {
    font-size: clamp(2.5rem, 10vw, 4rem);
    margin-bottom: 0.75rem;
  }

  .progress-bar-container {
    margin: 0.75rem auto;
  }
}

/* ============================================
   Message Screen (Leave a Message feature)
   ============================================ */

/* Smooth reveal for message prompt on reveal screen */

.message-prompt {
  margin-top: 1.5rem;
  visibility: hidden;
}

.message-prompt.visible {
  visibility: visible;
  animation: messageFadeIn 0.5s ease-out forwards;
}

@keyframes messageFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.message-prompt-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Message screen layout */
.message-screen-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 1.5rem;
  width: 100%;
  max-width: 480px;
  max-height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Ultrasound image — responsive */
.ultrasound-img {
  max-width: 100%;
  width: 280px;
  border-radius: 16px;
  object-fit: cover;
}

/* Message title heading */
.message-title {
  font-size: clamp(1.2rem, 4vw, 1.6rem);
  color: var(--accent-glow);
  line-height: 1.3;
}

/* Message textarea — styled like .name-input, auto-expanding */
.message-input {
  display: block;
  width: 100%;
  max-width: 320px;
  min-height: 100px;
  max-height: 200px;
  padding: 0.75rem 1rem;
  border: 2px solid var(--bg-card);
  border-radius: 12px;
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: clamp(1rem, 3vw, 1.25rem);
  font-family: inherit;
  text-align: center;
  outline: none;
  resize: none;
  overflow-y: auto;
  transition: border-color var(--transition-speed) ease;
}

.message-input:focus {
  border-color: var(--accent-warm);
}

.message-input::placeholder {
  color: var(--text-secondary);
  opacity: 0.6;
}

/* Character count */
.message-char-count {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* Submit and Edit buttons — extend .tap-target (class already applied in HTML) */
.message-submit:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.message-edit {
  border-color: var(--text-secondary);
}

/* Confirmation text — always reserves space, toggled via visibility */
.message-confirmation {
  font-size: clamp(1rem, 3vw, 1.15rem);
  color: var(--accent-glow);
  visibility: hidden;
}

.message-confirmation.visible {
  visibility: visible;
}

/* ============================================
   Message Screen — Responsive
   ============================================ */
@media (min-width: 768px) {
  .message-screen-content {
    max-width: 560px;
  }

  .message-input {
    max-width: 400px;
  }

  .ultrasound-img {
    width: 340px;
  }
}

@media (min-width: 1024px) {
  .message-screen-content {
    max-width: 640px;
  }

  .ultrasound-img {
    width: 400px;
  }
}

@media (max-height: 480px) and (orientation: landscape) {
  .ultrasound-img {
    width: 180px;
  }

  .message-screen-content {
    gap: 0.5rem;
    padding: 0.75rem;
  }

  .message-title {
    font-size: clamp(1rem, 3vw, 1.3rem);
  }
}
