/* ===== Reset & Base ===== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}
html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'PingFang SC', 'Microsoft YaHei', 'Noto Sans SC', sans-serif;
  background: #0a0a1a;
  color: #fff;
  user-select: none;
  -webkit-user-select: none;
  position: relative;
}

/* ===== App Container (750x1334 fixed design) ===== */
.app-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 750px;
  height: 1334px;
  transform-origin: 0 0;
  overflow: hidden;
  z-index: 1;
  background: #0a0a1a;
}

/* ===== Fonts ===== */
.font-number {
  font-family: 'DIN', 'Alibaba PuHuiTi', Arial, sans-serif;
  font-feature-settings: 'tnum';
}
.font-heavy {
  font-weight: 900;
  font-family: 'PingFang SC', 'Microsoft YaHei', 'Noto Sans SC', sans-serif;
}
.font-medium {
  font-weight: 500;
}

/* ===== HUD ===== */
#hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 100;
  padding: 12px 20px 8px;
  display: none;
  background: linear-gradient(180deg, rgba(0,0,0,0.7) 0%, transparent 100%);
}
#hud.visible { display: block; }

#timer-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}
#timer-icon { font-size: 16px; }
#timer-display {
  font-family: 'DIN', 'Alibaba PuHuiTi', Arial, sans-serif;
  font-size: 28px;
  font-weight: 700;
  color: #FFC700;
  text-shadow: 0 0 12px rgba(255,199,0,0.4);
  min-width: 50px;
}
#timer-display.warning {
  color: #FF3B30;
  animation: timerPulse 0.5s ease infinite;
}

#progress-container {
  width: 100%;
  height: 6px;
  background: rgba(255,255,255,0.15);
  border-radius: 3px;
  overflow: hidden;
}
#progress-bar {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #FFC700, #FF9A00);
  border-radius: 3px;
  transition: width 0.3s ease;
}

/* ===== Pages ===== */
.page {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: none;
  z-index: 1;
  overflow: hidden;
}
.page.active {
  opacity: 1;
  visibility: visible;
  z-index: 10;
  animation: pageIn 0.5s ease forwards;
}
.page.exit {
  animation: pageOut 0.4s ease forwards;
}

@keyframes pageIn {
  0% { opacity: 0; transform: translateX(40px); }
  100% { opacity: 1; transform: translateX(0); }
}
@keyframes pageOut {
  0% { opacity: 1; transform: translateX(0); }
  100% { opacity: 0; transform: translateX(-40px); }
}

.bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding: 0 24px 10%;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 14px 36px;
  border-radius: 20px;
  border: 2.5px solid #000;
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  position: relative;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}
.btn:active {
  transform: scale(0.96);
}

.btn-primary {
  background: linear-gradient(135deg, #FFC700, #FF9A00);
  color: #000;
  box-shadow: 0 4px 20px rgba(255,199,0,0.4);
  font-size: 22px;
  padding: 16px 48px;
}
.btn-primary:active {
  box-shadow: 0 2px 10px rgba(255,199,0,0.3);
}

.btn-choice {
  background: linear-gradient(135deg, #FFC700, #FF9A00);
  color: #000;
  box-shadow: 0 4px 15px rgba(255,199,0,0.3);
  padding: 12px 28px;
  font-size: 18px;
  min-width: 120px;
}

.btn-secondary {
  background: rgba(255,255,255,0.1);
  color: #fff;
  border-color: rgba(255,255,255,0.3);
  backdrop-filter: blur(8px);
}

.btn-small {
  padding: 10px 24px;
  font-size: 16px;
  border-radius: 16px;
}

/* ===== Choice Grid ===== */
.choice-group {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 10px;
}

/* ===== Page Title / Text ===== */
.page-title {
  font-size: 32px;
  font-weight: 900;
  text-align: center;
  text-shadow: 0 2px 12px rgba(0,0,0,0.6);
  line-height: 1.3;
}
.page-subtitle {
  font-size: 16px;
  text-align: center;
  opacity: 0.8;
  margin-top: 8px;
  text-shadow: 0 1px 8px rgba(0,0,0,0.5);
  line-height: 1.5;
}
.page-text {
  font-size: 18px;
  text-align: center;
  opacity: 0.9;
  text-shadow: 0 1px 8px rgba(0,0,0,0.5);
  line-height: 1.6;
}

/* ===== Text Section Positioning ===== */
.text-section {
  position: absolute;
  z-index: 2;
  width: 100%;
  padding: 0 24px;
}
.text-section.top {
  top: 14%;
}
.text-section.middle {
  top: 50%;
  transform: translateY(-50%);
}
.text-section.bottom {
  bottom: 22%;
}

/* ===== Page 1: Cover ===== */
#page-1 .main-title {
  font-size: 36px;
  font-weight: 900;
  text-align: center;
  text-shadow: 0 4px 20px rgba(0,0,0,0.7);
  line-height: 1.3;
  margin-bottom: 8px;
}
#page-1 .main-subtitle {
  font-size: 15px;
  text-align: center;
  opacity: 0.85;
  margin-bottom: 20px;
  text-shadow: 0 2px 10px rgba(0,0,0,0.5);
}
#page-1 .tagline {
  font-size: 13px;
  text-align: center;
  opacity: 0.5;
  margin-bottom: 30px;
  text-shadow: 0 2px 8px rgba(0,0,0,0.5);
}

/* ===== Page 2: Order ===== */
#order-card {
  width: 88%;
  max-width: 340px;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(12px);
  border-radius: 20px;
  padding: 20px 24px;
  border: 1.5px solid rgba(255,199,0,0.3);
  margin-bottom: 16px;
}
#order-card .order-item {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 4px;
}
#order-card .order-detail {
  font-size: 14px;
  opacity: 0.7;
  margin-bottom: 2px;
}
#order-card .order-price {
  font-size: 18px;
  font-weight: 700;
  color: #FFC700;
  margin-top: 8px;
}
#order-card .order-time {
  font-size: 14px;
  color: #FF3B30;
  margin-top: 4px;
}

.danmaku-container {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 1;
}
.danmaku {
  position: absolute;
  white-space: nowrap;
  font-size: 13px;
  padding: 4px 10px;
  background: rgba(0,0,0,0.5);
  border-radius: 12px;
  color: #fff;
  animation: danmakuFly 6s linear forwards;
  pointer-events: none;
}
@keyframes danmakuFly {
  0% { transform: translateX(100%); opacity: 0; }
  5% { opacity: 1; }
  80% { opacity: 1; }
  100% { transform: translateX(-120%); opacity: 0; }
}

/* ===== Page 3: Traffic Light ===== */
.traffic-light {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  margin: 0 auto 8px;
}
.traffic-light.red { background: #FF3B30; box-shadow: 0 0 20px #FF3B30; }
.traffic-light.green { background: #34C759; box-shadow: 0 0 20px #34C759; }

/* ===== Page 5: Battery ===== */
.battery-icon {
  width: 60px;
  height: 30px;
  border: 3px solid #fff;
  border-radius: 5px;
  position: relative;
  margin: 0 auto 12px;
}
.battery-icon::after {
  content: '';
  position: absolute;
  right: -8px;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 12px;
  background: #fff;
  border-radius: 0 2px 2px 0;
}
.battery-fill {
  position: absolute;
  left: 2px;
  top: 2px;
  bottom: 2px;
  width: 20%;
  background: #FF3B30;
  border-radius: 2px;
  animation: batteryBlink 0.8s ease infinite;
}
@keyframes batteryBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ===== Page 6: Rain Game ===== */
#game-canvas {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  display: none;
}
#game-canvas.active { display: block; }

/* ===== Page 7: Building Grid ===== */
.building-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  width: 85%;
  max-width: 320px;
  margin: 0 auto;
}
.building-btn {
  aspect-ratio: 1;
  background: linear-gradient(135deg, #FFC700, #FF9A00);
  border: 2.5px solid #000;
  border-radius: 16px;
  font-size: 26px;
  font-weight: 900;
  color: #000;
  cursor: pointer;
  transition: transform 0.15s ease;
  box-shadow: 0 2px 10px rgba(255,199,0,0.3);
}
.building-btn:active { transform: scale(0.92); }
.building-btn.correct {
  background: linear-gradient(135deg, #34C759, #28A745);
  animation: correctPop 0.4s ease;
}
.building-btn.wrong {
  background: linear-gradient(135deg, #FF3B30, #DC3545);
  animation: wrongShake 0.4s ease;
}

/* ===== Page 8: Elevator ===== */
#elevator-display {
  font-family: 'DIN', 'Alibaba PuHuiTi', Arial, sans-serif;
  font-size: 72px;
  font-weight: 700;
  color: #FFC700;
  text-shadow: 0 0 30px rgba(255,199,0,0.3);
  text-align: center;
  margin-bottom: 10px;
}
#elevator-display.warning {
  color: #FF3B30;
  animation: timerPulse 0.4s ease infinite;
}

/* ===== Page 9: Result ===== */
.result-container {
  text-align: center;
}
.result-grade {
  font-size: 80px;
  font-weight: 900;
  text-shadow: 0 0 40px rgba(255,199,0,0.5);
  margin-bottom: 8px;
}
.result-grade.S { color: #FFC700; text-shadow: 0 0 50px rgba(255,199,0,0.6); }
.result-grade.A { color: #34C759; text-shadow: 0 0 40px rgba(52,199,89,0.5); }
.result-grade.B { color: #FF9A00; text-shadow: 0 0 30px rgba(255,154,0,0.4); }
.result-grade.C { color: #FF3B30; text-shadow: 0 0 30px rgba(255,59,48,0.4); }
.result-label {
  font-size: 24px;
  font-weight: 700;
  margin-top: 4px;
}
.result-label.S { color: #FFC700; }
.result-label.A { color: #34C759; }
.result-label.B { color: #FF9A00; }
.result-label.C { color: #FF3B30; }

/* ===== Page 10: Poster ===== */
.poster-card {
  width: 88%;
  max-width: 340px;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(16px);
  border-radius: 24px;
  padding: 28px 24px;
  border: 2px solid rgba(255,199,0,0.2);
  text-align: center;
}
.poster-grade-big {
  font-size: 64px;
  font-weight: 900;
  margin-bottom: 4px;
}
.poster-grade-big.S { color: #FFC700; }
.poster-grade-big.A { color: #34C759; }
.poster-grade-big.B { color: #FF9A00; }
.poster-grade-big.C { color: #FF3B30; }
.poster-stats {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin: 16px 0;
  padding: 12px 0;
  border-top: 1px solid rgba(255,255,255,0.1);
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.poster-stat-item {
  text-align: center;
}
.poster-stat-value {
  font-family: 'DIN', 'Alibaba PuHuiTi', Arial, sans-serif;
  font-size: 28px;
  font-weight: 700;
  color: #FFC700;
}
.poster-stat-label {
  font-size: 11px;
  opacity: 0.6;
  margin-top: 2px;
}
.poster-quote {
  font-size: 15px;
  opacity: 0.7;
  margin: 12px 0 20px;
  line-height: 1.5;
}

/* ===== Toast ===== */
#toast {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 200;
  padding: 12px 28px;
  border-radius: 12px;
  font-size: 18px;
  font-weight: 700;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s ease, top 0.25s ease;
}
#toast.show {
  opacity: 1;
}
#toast.success {
  background: rgba(52,199,89,0.9);
  color: #fff;
}
#toast.error {
  background: rgba(255,59,48,0.9);
  color: #fff;
}
#toast.info {
  background: rgba(0,0,0,0.8);
  color: #FFC700;
}

/* ===== Screen Effects ===== */
#screen-flash {
  position: absolute;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.1s ease;
}
#screen-flash.red { opacity: 1; background: rgba(255,0,0,0.25); }
#screen-flash.green { opacity: 1; background: rgba(0,255,0,0.15); }
#screen-flash.fade-out {
  opacity: 0;
  transition: opacity 0.3s ease;
}

/* ===== Particles ===== */
.particle-container {
  position: absolute;
  inset: 0;
  z-index: 55;
  pointer-events: none;
  overflow: hidden;
}
.particle {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  pointer-events: none;
  animation: particleFly 1s ease-out forwards;
}
.particle.gold { background: #FFC700; box-shadow: 0 0 6px #FFC700; }
.particle.green { background: #34C759; box-shadow: 0 0 6px #34C759; }
@keyframes particleFly {
  0% { opacity: 1; transform: translate(0, 0) scale(1); }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0); }
}

/* ===== Timer Pulse (low time) ===== */
@keyframes timerPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(1.1); }
}

/* ===== Button Bounce (on appear) ===== */
.btn-bounce {
  animation: btnBounce 0.5s ease forwards 0.3s;
  opacity: 0;
}
@keyframes btnBounce {
  0% { opacity: 0; transform: scale(0.8); }
  60% { opacity: 1; transform: scale(1.05); }
  100% { opacity: 1; transform: scale(1); }
}

/* ===== Correct/Wrong Animations ===== */
@keyframes correctPop {
  0% { transform: scale(1); }
  50% { transform: scale(1.15); }
  100% { transform: scale(1); }
}
@keyframes wrongShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

/* ===== Loading ===== */
#loading {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #0a0a1a;
  color: #FFC700;
  font-size: 16px;
  gap: 16px;
}
#loading.hidden { display: none; }
#loading .spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255,199,0,0.2);
  border-top-color: #FFC700;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
