/* ============ CSS VARIABLES ============ */
:root {
  --warm-cream: #FFF8EC;
  --golden: #F5A623;
  --golden-light: #FFD680;
  --golden-deep: #E08B00;
  --bread-brown: #C47A2B;
  --soft-pink: #FFD6C4;
  --mint: #B8EDDB;
  --sky: #C8E8FF;
  --sky-dark: #7EC8F0;
  --text-dark: #3D2B1F;
  --text-mid: #7A5C3C;
  --white: #FFFFFF;
  --shadow: rgba(61,43,31,0.15);
  --radius-big: 28px;
  --radius-sm: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  font-family: 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: var(--warm-cream);
  user-select: none;
}

/* ============ SCREEN MANAGER ============ */
.screen {
  position: fixed; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity 0.5s ease;
  overflow: hidden;
}
.screen.active { opacity: 1; pointer-events: all; }

/* ============ BACKGROUND LAYERS ============ */
.bg-base {
  position: absolute; inset: 0;
  background: linear-gradient(180deg, #FFF3D6 0%, #FFE8B0 40%, #FFDDA0 100%);
  z-index: 0;
}

.bubbles {
  position: absolute; inset: 0; z-index: 1; overflow: hidden;
}
.bubble {
  position: absolute; border-radius: 50%;
  background: rgba(255,255,255,0.35);
  animation: floatBubble linear infinite;
}
@keyframes floatBubble {
  0%   { transform: translateY(110vh) scale(0.8); opacity:0; }
  10%  { opacity:0.6; }
  90%  { opacity:0.4; }
  100% { transform: translateY(-10vh) scale(1.1); opacity:0; }
}

/* Wheat dots background pattern */
.bg-dots {
  position: absolute; inset: 0; z-index: 1;
  background-image: radial-gradient(circle, rgba(245,166,35,0.12) 2px, transparent 2px);
  background-size: 28px 28px;
}

/* ============ LOGO BADGE ============ */
.logo-badge {
  position: absolute; top: 18px; left: 50%; transform: translateX(-50%);
  z-index: 100;
  display: flex; align-items: center; gap: 8px;
  background: var(--golden);
  border-radius: 30px;
  padding: 6px 18px;
  box-shadow: 0 4px 14px rgba(200,130,0,0.35);
}
.logo-text { color: #fff; font-size: 15px; font-weight: 800; letter-spacing: 2px; }
.logo-dot { width:6px; height:6px; background:#fff; border-radius:50%; opacity:0.7; }

/* ============ PROGRESS BAR ============ */
.progress-bar {
  position: absolute; top: 58px; left: 50%; transform: translateX(-50%);
  z-index: 100;
  display: flex; align-items: center; gap: 6px;
}
.prog-step {
  width: 28px; height: 6px; border-radius: 3px;
  background: rgba(245,166,35,0.25);
  transition: background 0.4s ease, transform 0.3s ease;
}
.prog-step.done { background: var(--golden); transform: scaleY(1.4); }
.prog-step.active { background: var(--golden-deep); transform: scaleY(1.6); }

/* ============ MASCOT: 麦小Q ============ */
.mascot-wrap {
  position: relative;
  width: 120px; height: 140px;
  animation: mascotBounce 1.2s ease-in-out infinite alternate;
}
@keyframes mascotBounce {
  0%   { transform: translateY(0); }
  100% { transform: translateY(-12px); }
}
.mascot-shadow {
  position: absolute; bottom: -8px; left: 50%; transform: translateX(-50%);
  width: 70px; height: 14px;
  background: rgba(180,120,40,0.2);
  border-radius: 50%;
  animation: shadowPulse 1.2s ease-in-out infinite alternate;
}
@keyframes shadowPulse { 0%{transform:translateX(-50%) scaleX(1);} 100%{transform:translateX(-50%) scaleX(0.75);} }

/* SVG mascot inline */
.mascot-svg { width: 120px; height: 130px; }

/* ============ SPEECH BUBBLE ============ */
.speech-bubble {
  position: relative;
  background: #fff;
  border-radius: 20px;
  padding: 14px 18px;
  box-shadow: 0 6px 22px var(--shadow);
  max-width: 290px;
  font-size: 14px; line-height: 1.7; color: var(--text-dark);
  border: 2.5px solid var(--golden-light);
}
.speech-bubble::after {
  content: '';
  position: absolute; bottom: -14px; left: 50%; transform: translateX(-50%);
  border: 8px solid transparent;
  border-top-color: #fff;
  filter: drop-shadow(0 3px 0 rgba(245,166,35,0.15));
}
.bubble-top::after { bottom: auto; top: -14px; border-top-color: transparent; border-bottom-color: #fff; }
.speech-bubble strong { color: var(--golden-deep); }

/* ============ BTN STYLES ============ */
.btn-main {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: linear-gradient(135deg, #F5A623 0%, #E08B00 100%);
  color: #fff; font-size: 17px; font-weight: 800;
  padding: 15px 32px; border-radius: 50px;
  border: none; cursor: pointer;
  box-shadow: 0 6px 22px rgba(224,139,0,0.45), 0 2px 0 rgba(255,255,255,0.3) inset;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  letter-spacing: 1px;
}
.btn-main:active { transform: scale(0.95); box-shadow: 0 3px 10px rgba(224,139,0,0.35); }
.btn-secondary {
  background: #fff; color: var(--golden-deep); border: 2.5px solid var(--golden);
  font-size: 14px; font-weight: 700; padding: 10px 24px; border-radius: 50px; cursor: pointer;
  transition: all 0.18s ease;
}
.btn-secondary:active { background: var(--golden-light); }

/* ============ DANMAKU ============ */
#danmaku-container {
  position: absolute; inset: 0; z-index: 50; overflow: hidden; pointer-events: none;
}
.danmaku-line {
  position: absolute;
  white-space: nowrap;
  font-size: 18px; font-weight: 800;
  color: var(--golden-deep);
  text-shadow: 0 0 12px rgba(245,166,35,0.6), 2px 2px 0 rgba(255,255,255,0.9);
  animation: danmakuFly 3.5s linear forwards;
  opacity: 0;
}
@keyframes danmakuFly {
  0%   { transform: translateX(110vw); opacity: 0; }
  8%   { opacity: 1; }
  85%  { opacity: 1; }
  100% { transform: translateX(-110vw); opacity: 0; }
}

/* ============ OPENING SCREEN ============ */
#screen-open { background: transparent; }

.open-notification {
  background: #fff;
  border-radius: 20px; padding: 18px 24px;
  box-shadow: 0 10px 40px rgba(61,43,31,0.2);
  display: flex; align-items: center; gap: 14px;
  max-width: 310px; width: 90%;
  border-left: 5px solid var(--golden);
  animation: notifSlideIn 0.7s cubic-bezier(0.34,1.56,0.64,1) both;
  z-index: 10; position: relative;
}
@keyframes notifSlideIn {
  0%   { transform: translateY(-60px) scale(0.85); opacity: 0; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}
.notif-icon {
  width: 44px; height: 44px; border-radius: 12px;
  background: linear-gradient(135deg, var(--golden) 0%, var(--golden-deep) 100%);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; flex-shrink: 0;
}
.notif-text h3 { font-size: 15px; color: var(--text-dark); font-weight: 800; }
.notif-text p { font-size: 12px; color: var(--text-mid); margin-top: 2px; }
.notif-time { position: absolute; top: 14px; right: 14px; font-size: 11px; color: #bbb; }

.open-cta {
  margin-top: 28px; z-index: 10; position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.open-title {
  font-size: 28px; font-weight: 900; color: var(--text-dark);
  text-shadow: 2px 2px 0 rgba(255,255,255,0.8);
  letter-spacing: 2px;
}
.open-sub { font-size: 14px; color: var(--text-mid); }

.sparkle { position: absolute; pointer-events: none; z-index: 5; }
.sparkle-dot {
  position: absolute; width: 8px; height: 8px; border-radius: 50%;
  background: var(--golden);
  animation: sparklePop 2s ease-in-out infinite;
}
@keyframes sparklePop {
  0%,100% { transform: scale(0.5); opacity: 0.3; }
  50%      { transform: scale(1.4); opacity: 1; }
}

/* ============ INTRO SCREEN ============ */
#screen-intro { background: transparent; flex-direction: column; justify-content: flex-end; padding-bottom: 0; }

.intro-scene {
  position: absolute; inset: 0; z-index: 2;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 80px 20px 20px;
  gap: 14px;
}

.factory-bg {
  position: absolute; bottom: 0; left: 0; right: 0; height: 35vh;
  z-index: 1;
}

.intro-card {
  background: rgba(255,255,255,0.95);
  border-radius: 28px; padding: 22px 22px 18px;
  width: 88%; max-width: 340px;
  box-shadow: 0 10px 40px rgba(61,43,31,0.18);
  border: 2px solid rgba(245,166,35,0.25);
  z-index: 10; position: relative;
  animation: cardRise 0.7s cubic-bezier(0.34,1.56,0.64,1) both 0.3s;
}
@keyframes cardRise {
  0%   { transform: translateY(50px); opacity: 0; }
  100% { transform: translateY(0); opacity: 1; }
}
.card-tag {
  display: inline-block;
  background: var(--golden);
  color: #fff; font-size: 11px; font-weight: 800;
  padding: 3px 10px; border-radius: 20px; margin-bottom: 8px;
  letter-spacing: 1px;
}
.card-text { font-size: 14px; line-height: 1.8; color: var(--text-dark); }
.card-text em { color: var(--golden-deep); font-style: normal; font-weight: 800; }

.intro-btn-row {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: linear-gradient(0deg, rgba(255,240,200,1) 60%, transparent);
  padding: 24px 24px 36px;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  z-index: 20;
}

/* ============ LEVEL HEADER ============ */
.level-header {
  position: absolute; top: 80px; left: 0; right: 0;
  padding: 0 20px;
  z-index: 10;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.level-badge {
  background: var(--golden);
  color: #fff; font-size: 12px; font-weight: 800;
  padding: 4px 14px; border-radius: 20px; letter-spacing: 1px;
}
.level-title {
  font-size: 18px; font-weight: 900; color: var(--text-dark);
  text-align: center; line-height: 1.4;
}
.level-desc {
  font-size: 13px; color: var(--text-mid);
  text-align: center; line-height: 1.6;
  background: rgba(255,255,255,0.7);
  border-radius: 14px; padding: 8px 14px;
  max-width: 320px;
}

/* ============ LEVEL 1: EGG QUIZ ============ */
#screen-l1 { background: transparent; }

.egg-options {
  display: flex; flex-direction: column; gap: 14px;
  width: 88%; max-width: 340px;
  margin-top: 4px;
  z-index: 10; position: relative;
}
.egg-option {
  background: #fff;
  border-radius: 20px;
  padding: 14px 18px;
  display: flex; align-items: center; gap: 14px;
  border: 3px solid transparent;
  box-shadow: 0 4px 16px var(--shadow);
  cursor: pointer;
  transition: all 0.25s ease;
  position: relative; overflow: hidden;
}
.egg-option:active { transform: scale(0.97); }
.egg-option.correct { border-color: #4CAF50; background: #F0FFF4; }
.egg-option.wrong   { border-color: #F44336; background: #FFF5F5; animation: shakeOpt 0.4s ease; }
.egg-option.disabled { pointer-events: none; }
@keyframes shakeOpt {
  0%,100%{transform:translateX(0)} 25%{transform:translateX(-6px)} 75%{transform:translateX(6px)}
}
.egg-emoji { font-size: 36px; flex-shrink: 0; }
.egg-info { flex: 1; }
.egg-name { font-size: 15px; font-weight: 800; color: var(--text-dark); }
.egg-desc { font-size: 12px; color: var(--text-mid); margin-top: 2px; }
.egg-result-icon {
  font-size: 22px;
  position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
  opacity: 0; transition: opacity 0.3s ease;
}
.egg-option.correct .egg-result-icon,
.egg-option.wrong   .egg-result-icon { opacity: 1; }

.feedback-toast {
  position: fixed; bottom: 120px; left: 50%; transform: translateX(-50%);
  background: rgba(40,40,40,0.92); color: #fff;
  padding: 10px 24px; border-radius: 30px; font-size: 14px; font-weight: 700;
  z-index: 200; opacity: 0; transition: opacity 0.3s;
  pointer-events: none; white-space: nowrap;
}
.feedback-toast.show { opacity: 1; }

/* ============ LEVEL 2: DRAG & DROP ============ */
#screen-l2 { background: transparent; flex-direction: column; justify-content: flex-start; }

.l2-layout {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  padding: 140px 16px 90px;
  gap: 16px;
  z-index: 10;
  overflow: hidden;
}
.l2-ingredients-row {
  display: flex; gap: 10px; flex-wrap: wrap; justify-content: center;
}
.ingredient-card {
  background: #fff; border-radius: 16px;
  padding: 10px 14px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  border: 2.5px solid var(--golden-light);
  box-shadow: 0 3px 12px var(--shadow);
  cursor: grab; user-select: none;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  min-width: 76px;
  touch-action: none;
}
.ingredient-card:active { transform: scale(1.08); box-shadow: 0 8px 24px rgba(245,166,35,0.3); }
.ingredient-card.matched { opacity: 0; pointer-events: none; transition: opacity 0.4s; }
.ingredient-card.dragging {
  position: fixed; z-index: 9999;
  transform: scale(1.12) rotate(3deg);
  box-shadow: 0 12px 36px rgba(245,166,35,0.4);
  pointer-events: none;
  transition: none;
}
.ing-icon { font-size: 28px; }
.ing-name { font-size: 11px; font-weight: 700; color: var(--text-dark); text-align: center; }
.ing-origin { font-size: 10px; color: var(--text-mid); text-align: center; }

.l2-factory {
  flex: 1;
  background: rgba(255,255,255,0.8);
  border-radius: 22px;
  border: 2.5px solid rgba(245,166,35,0.3);
  padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
  box-shadow: 0 4px 20px var(--shadow);
}
.factory-title {
  font-size: 13px; font-weight: 800; color: var(--golden-deep);
  text-align: center; letter-spacing: 1px;
}
.slots-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 10px; flex: 1;
}
.ingredient-slot {
  border: 2.5px dashed rgba(245,166,35,0.4);
  border-radius: 16px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 72px;
  transition: all 0.3s ease;
  background: rgba(255,248,236,0.6);
  position: relative;
}
.ingredient-slot.over { border-color: var(--golden); background: rgba(255,214,100,0.25); transform: scale(1.03); }
.ingredient-slot.filled {
  border-color: #4CAF50; border-style: solid;
  background: rgba(76,175,80,0.1);
  animation: slotLight 0.5s ease;
}
@keyframes slotLight {
  0%   { background: rgba(255,214,100,0.6); transform: scale(1.06); }
  100% { background: rgba(76,175,80,0.1); transform: scale(1); }
}
.slot-label { font-size: 11px; color: var(--text-mid); font-weight: 600; text-align: center; }
.slot-icon { font-size: 26px; }
.slot-check { font-size: 18px; position: absolute; top: 6px; right: 8px; opacity: 0; transition: opacity 0.3s; }
.ingredient-slot.filled .slot-check { opacity: 1; }

.l2-bottom-btn {
  position: absolute; bottom: 0; left: 0; right: 0;
  padding: 14px 24px 30px;
  background: linear-gradient(0deg, rgba(255,240,200,1) 60%, transparent);
  display: flex; justify-content: center; z-index: 20;
}

/* ============ LEVEL 3: CATCH GAME ============ */
#screen-l3 {
  background: transparent;
  flex-direction: column; justify-content: flex-start;
}

#game-canvas-wrap {
  position: absolute; inset: 0; z-index: 5;
  touch-action: none;
}
#game-canvas { width: 100%; height: 100%; display: block; }

.game-hud {
  position: absolute; top: 76px; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: center;
  padding: 0 20px; z-index: 20;
}
.hud-score, .hud-time, .hud-lives {
  background: rgba(255,255,255,0.92);
  border-radius: 20px; padding: 6px 14px;
  font-size: 14px; font-weight: 800; color: var(--text-dark);
  box-shadow: 0 3px 10px var(--shadow);
  display: flex; align-items: center; gap: 4px;
}
.hud-score span, .hud-time span { color: var(--golden-deep); font-size: 18px; }

.l3-countdown {
  position: absolute; inset: 0; z-index: 30;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,248,236,0.85);
  backdrop-filter: blur(4px);
  flex-direction: column; gap: 10px;
}
.countdown-num {
  font-size: 100px; font-weight: 900; color: var(--golden);
  text-shadow: 4px 4px 0 var(--golden-deep), 0 0 40px rgba(245,166,35,0.5);
  animation: countPulse 0.8s ease-out;
}
@keyframes countPulse {
  0%   { transform: scale(2); opacity: 0; }
  60%  { transform: scale(0.9); opacity: 1; }
  100% { transform: scale(1); }
}
.countdown-tip { font-size: 16px; color: var(--text-mid); font-weight: 700; }

/* ============ RESULT SCREEN ============ */
#screen-result {
  background: transparent;
  flex-direction: column; gap: 0;
}

.result-card {
  background: #fff; border-radius: 30px;
  width: 88%; max-width: 340px;
  padding: 30px 24px;
  box-shadow: 0 15px 50px rgba(61,43,31,0.2);
  border: 3px solid var(--golden-light);
  z-index: 10; position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  animation: resultPop 0.7s cubic-bezier(0.34,1.56,0.64,1) both;
}
@keyframes resultPop {
  0%   { transform: scale(0.6) rotate(-5deg); opacity: 0; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}
.result-trophy { font-size: 64px; animation: trophySpin 1s ease-out 0.5s both; }
@keyframes trophySpin {
  0%   { transform: rotate(-30deg) scale(0.5); }
  60%  { transform: rotate(10deg) scale(1.15); }
  100% { transform: rotate(0deg) scale(1); }
}
.result-title { font-size: 24px; font-weight: 900; color: var(--text-dark); text-align: center; }
.result-sub { font-size: 14px; color: var(--text-mid); text-align: center; line-height: 1.7; }
.result-score {
  background: var(--warm-cream);
  border-radius: 16px; padding: 14px 28px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  width: 100%;
}
.result-score-num { font-size: 42px; font-weight: 900; color: var(--golden-deep); }
.result-score-label { font-size: 12px; color: var(--text-mid); }

.result-coupon {
  background: linear-gradient(135deg, var(--golden) 0%, var(--golden-deep) 100%);
  border-radius: 20px; padding: 16px 22px;
  width: 100%;
  display: flex; flex-direction: column; gap: 6px;
  position: relative; overflow: hidden;
}
.result-coupon::before {
  content: '';
  position: absolute; left: -20px; top: 50%; transform: translateY(-50%);
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(255,255,255,0.15);
}
.result-coupon::after {
  content: '';
  position: absolute; right: -20px; top: 50%; transform: translateY(-50%);
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(255,255,255,0.15);
}
.coupon-label { font-size: 12px; color: rgba(255,255,255,0.85); font-weight: 700; }
.coupon-value { font-size: 28px; font-weight: 900; color: #fff; }
.coupon-code {
  font-size: 13px; color: rgba(255,255,255,0.9);
  background: rgba(255,255,255,0.2); border-radius: 8px;
  padding: 4px 10px; display: inline-block; letter-spacing: 2px; font-weight: 800;
}
.coupon-expire { font-size: 11px; color: rgba(255,255,255,0.7); }

.result-btns { display: flex; flex-direction: column; gap: 10px; width: 100%; }

/* ============ CONFETTI ============ */
.confetti-piece {
  position: fixed; z-index: 300;
  width: 8px; height: 10px;
  border-radius: 2px;
  pointer-events: none;
  animation: confettiFall linear forwards;
}
@keyframes confettiFall {
  0%   { transform: translateY(-20px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(110vh) rotate(720deg); opacity: 0; }
}

/* ============ STARS ANIMATE ============ */
.star-pop {
  position: fixed; z-index: 200; pointer-events: none;
  font-size: 24px;
  animation: starAnim 0.8s ease-out forwards;
}
@keyframes starAnim {
  0%   { transform: scale(0) rotate(0); opacity: 1; }
  60%  { transform: scale(1.4) rotate(20deg); opacity: 1; }
  100% { transform: scale(0.8) rotate(30deg) translateY(-40px); opacity: 0; }
}

/* ============ FACTORY ILLUSTRATION ============ */
.factory-illustration {
  position: absolute; bottom: 0; left: 0; right: 0;
  height: 30vh; z-index: 1;
}

/* ============ MISC ============ */
.hint-text {
  font-size: 12px; color: var(--text-mid);
  text-align: center; padding: 6px 0;
}

/* Hand cursor hint animation */
.touch-hint {
  position: absolute; bottom: 160px; right: 30px;
  font-size: 28px; z-index: 50;
  animation: touchHint 1.5s ease-in-out infinite;
  pointer-events: none;
}
@keyframes touchHint {
  0%,100%{ transform: translateX(0) rotate(0); }
  50%    { transform: translateX(-10px) rotate(-15deg); }
}

/* Wheat animation for l2 header */
.wheat-deco {
  display: flex; gap: 8px; justify-content: center; align-items: center;
  font-size: 16px;
}

/* Particle burst */
.particle {
  position: fixed; pointer-events: none; z-index: 9999;
  width: 6px; height: 6px; border-radius: 50%;
  animation: particleBurst ease-out forwards;
}
@keyframes particleBurst {
  0%   { opacity: 1; }
  100% { opacity: 0; transform: translate(var(--tx), var(--ty)) scale(0); }
}

/* ============ SCROLL INSTRUCTION ============ */
.swipe-hint {
  position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%);
  font-size: 11px; color: rgba(120,90,60,0.5);
  z-index: 10; pointer-events: none;
}
