* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; user-select: none; }
html, body { width: 100%; height: 100%; overflow: hidden; font-family: 'KaiTi', 'STKaiti', '楷体', 'Segoe UI', 'PingFang SC', sans-serif; background: #0a0a1a; touch-action: none; }
#app { width: 100%; height: 100%; position: relative; overflow: hidden; }
.page { position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: none; flex-direction: column; align-items: center; justify-content: center; }
.page.active { display: flex; }

/* ===== START PAGE ===== */
#page-start {
  background: linear-gradient(180deg, #060812 0%, #1a1030 25%, #0d1a3a 50%, #1a0d30 75%, #060812 100%);
  overflow: hidden;
}
#page-start::before {
  content: '';
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  background: radial-gradient(circle at 50% 30%, rgba(255,215,0,0.1), transparent 50%),
              radial-gradient(circle at 30% 70%, rgba(255,107,214,0.06), transparent 40%),
              radial-gradient(circle at 70% 60%, rgba(107,240,255,0.05), transparent 35%);
  z-index: 0;
}
.start-content {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 20px;
  max-width: 400px;
  width: 90%;
}
.start-icon {
  font-size: 80px;
  animation: iconFloat 3s ease-in-out infinite;
}
@keyframes iconFloat {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-10px) scale(1.05); }
}
.start-title {
  font-size: 36px;
  background: linear-gradient(135deg, #FFD700, #FF8C00, #FFD700);
  background-size: 300% 300%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: titleGradient 3s ease-in-out infinite;
  margin: 10px 0 4px;
  letter-spacing: 6px;
  text-shadow: none;
}
@keyframes titleGradient {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}
.start-sub {
  font-size: 13px;
  color: rgba(255,215,0,0.5);
  letter-spacing: 8px;
  margin-bottom: 24px;
}
.start-rules {
  background: rgba(255,215,0,0.05);
  border: 1px solid rgba(255,215,0,0.2);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 24px;
  text-align: left;
}
.rule-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  color: rgba(255, 255, 255, 0.8);
  font-size: 14px;
}
.rule-emoji {
  font-size: 20px;
  flex-shrink: 0;
  width: 28px;
  text-align: center;
}
.btn-start {
  display: block;
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: 25px;
  font-size: 20px;
  font-weight: bold;
  cursor: pointer;
  background: linear-gradient(135deg, #FF8C00, #FF6347);
  color: #fff;
  text-shadow: 0 1px 4px rgba(0,0,0,0.4);
  letter-spacing: 4px;
  box-shadow: 0 4px 25px rgba(255,140,0,0.4);
  transition: transform 0.15s;
  margin-bottom: 12px;
  touch-action: manipulation;
  font-family: inherit;
}
.btn-start:active { transform: scale(0.95); }
.btn-back {
  display: block;
  width: 100%;
  padding: 12px;
  border: 1px solid rgba(255,215,0,0.3);
  border-radius: 25px;
  font-size: 14px;
  cursor: pointer;
  background: rgba(255,215,0,0.06);
  color: rgba(255, 215, 0, 0.7);
  letter-spacing: 2px;
  transition: transform 0.15s;
  font-family: inherit;
}
.btn-back:active { transform: scale(0.95); }

/* ===== GAME PAGE ===== */
#page-game {
  background: linear-gradient(180deg, #060812 0%, #0a1530 50%, #060812 100%);
  min-height: 100vh;
}
.game-top {
  width: 100%;
  padding: 6px 10px;
  flex-shrink: 0;
}
.game-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(20, 15, 5, 0.85);
  border: 1px solid rgba(255,215,0,0.2);
  border-radius: 14px;
  padding: 6px 10px;
}
.game-top-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}
.game-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.game-info .level-name {
  font-size: 16px;
  font-weight: bold;
  letter-spacing: 2px;
  color: #FFD700;
  text-shadow: 0 0 8px rgba(255,215,0,0.3);
}
.game-info .level-num {
  font-size: 11px;
  color: rgba(255,215,0,0.5);
  letter-spacing: 2px;
}

/* ===== TOOL BUTTONS (hanzi style) ===== */
.tool-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1.5px solid rgba(255,215,0,0.3);
  background: linear-gradient(135deg, rgba(255,215,0,0.08), rgba(255,140,0,0.04));
  color: #FFD700;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  font-family: inherit;
  transition: transform 0.15s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  padding: 0;
}
.tool-btn:active { transform: scale(0.9); }
.tool-btn .tool-icon {
  width: 22px;
  height: 22px;
  stroke: #FFD700;
  fill: none;
}
.tool-btn .tool-emoji {
  font-size: 18px;
  line-height: 1;
}
.tool-btn:disabled {
  opacity: 0.4;
  cursor: default;
}
.tool-btn.muted .tool-icon {
  stroke: rgba(255,215,0,0.3);
}

.game-canvas-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  min-height: 0;
  overflow: hidden;
  position: relative;
  width: 100%;
  max-width: 100%;
}
#gameCanvas {
  border-radius: 12px;
  touch-action: none;
  box-shadow: 0 0 30px rgba(255,215,0,0.15), 0 0 15px rgba(255,140,0,0.08);
}

.game-bottom {
  width: 100%;
  padding: 8px 12px;
  flex-shrink: 0;
  display: flex;
  gap: 8px;
  align-items: center;
}
.btn-back-game {
  flex: 1;
  padding: 10px;
  border: 1px solid rgba(255,215,0,0.2);
  border-radius: 20px;
  font-size: 13px;
  cursor: pointer;
  background: rgba(255,215,0,0.05);
  color: rgba(255, 215, 0, 0.6);
  letter-spacing: 2px;
  transition: transform 0.15s;
  font-family: inherit;
  touch-action: manipulation;
}
.btn-back-game:active { transform: scale(0.98); }

.btn-help-ad {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 14px;
  border: 1.5px solid rgba(255,140,0,0.4);
  border-radius: 20px;
  background: linear-gradient(135deg, rgba(255,140,0,0.15), rgba(255,215,0,0.08));
  cursor: pointer;
  transition: transform 0.15s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  font-family: inherit;
  position: relative;
}
.btn-help-ad:active { transform: scale(0.95); }
.btn-help-ad:disabled {
  opacity: 0.4;
  cursor: default;
}
.btn-help-ad .help-ad-icon {
  font-size: 16px;
  line-height: 1;
}
.btn-help-ad .help-ad-text {
  font-size: 12px;
  color: rgba(255,215,0,0.85);
  letter-spacing: 1px;
}
.btn-help-ad .help-ad-badge {
  font-size: 10px;
  background: #FF8C00;
  color: #fff;
  padding: 2px 5px;
  border-radius: 4px;
  font-weight: bold;
  line-height: 1.2;
  min-width: 18px;
  text-align: center;
}

/* ===== MODALS ===== */
.modal {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(6, 8, 18, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s;
}
.modal.show {
  opacity: 1;
  visibility: visible;
}
.modal-content {
  text-align: center;
  padding: 28px 22px;
  max-width: 340px;
  width: 90%;
  background: linear-gradient(135deg, rgba(30,25,15,0.95), rgba(15,12,8,0.98));
  border: 1.5px solid rgba(255,215,0,0.3);
  border-radius: 20px;
  box-shadow: 0 0 40px rgba(255,215,0,0.1);
  transform: scale(0.9);
  transition: transform 0.3s;
}
.modal.show .modal-content { transform: scale(1); }
.modal-icon {
  font-size: 64px;
  animation: bounceIn 0.5s ease-out;
}
@keyframes bounceIn {
  0% { transform: scale(0); }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); }
}
.modal-title {
  font-size: 26px;
  background: linear-gradient(135deg, #FFD700, #FF8C00);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: none;
  margin: 10px 0 4px;
  letter-spacing: 4px;
}
.modal-sub {
  font-size: 16px;
  color: rgba(255, 255, 255, 0.85);
  margin-bottom: 4px;
}
.modal-num {
  font-size: 12px;
  color: rgba(255,215,0,0.5);
  letter-spacing: 4px;
  margin-bottom: 20px;
}
.modal-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.btn-next {
  padding: 14px;
  border: none;
  border-radius: 20px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  background: linear-gradient(135deg, #FF8C00, #FF6347);
  color: #fff;
  letter-spacing: 3px;
  box-shadow: 0 4px 20px rgba(255,140,0,0.4);
  transition: transform 0.15s;
  font-family: inherit;
}
.btn-next:active { transform: scale(0.95); }
.btn-retry {
  padding: 12px;
  border: 1px solid rgba(255,215,0,0.3);
  border-radius: 20px;
  font-size: 14px;
  cursor: pointer;
  background: rgba(255,215,0,0.06);
  color: rgba(255, 215, 0, 0.85);
  letter-spacing: 2px;
  transition: transform 0.15s;
  font-family: inherit;
}
.btn-retry:active { transform: scale(0.95); }
.btn-back-modal {
  padding: 10px;
  border: none;
  border-radius: 20px;
  font-size: 13px;
  cursor: pointer;
  background: transparent;
  color: rgba(255, 255, 255, 0.4);
  letter-spacing: 2px;
  transition: transform 0.15s;
  font-family: inherit;
}
.btn-back-modal:active { transform: scale(0.95); }

.modal-title-small {
  font-size: 22px;
  background: linear-gradient(135deg, #FFD700, #FF8C00);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin: 10px 0 16px;
  letter-spacing: 3px;
}

/* ===== TUTORIAL ===== */
.tutorial-content { padding: 24px 20px; }
.tutorial-steps { text-align: left; margin-bottom: 20px; }
.tut-step {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 0;
  color: rgba(255,255,255,0.85);
  font-size: 14px;
  line-height: 1.5;
  border-bottom: 1px solid rgba(255,215,0,0.08);
}
.tut-step:last-child { border-bottom: none; }
.tut-num {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, #FF8C00, #FF6347);
  color: #fff;
  font-size: 13px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.btn-got-it {
  display: block;
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 25px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  background: linear-gradient(135deg, #FF8C00, #FF6347);
  color: #fff;
  letter-spacing: 3px;
  box-shadow: 0 4px 20px rgba(255,140,0,0.4);
  transition: transform 0.15s;
  touch-action: manipulation;
  font-family: inherit;
}
.btn-got-it:active { transform: scale(0.95); }

/* ===== AD MODAL ===== */
.ad-content { padding: 24px 20px; text-align: center; }
.ad-desc {
  color: rgba(255,255,255,0.7);
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 16px;
}
.ad-countdown {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  position: relative;
  margin: 10px auto;
}
.ad-countdown svg { transform: rotate(-90deg); }
.ad-countdown circle { fill: none; stroke-width: 4; }
.ad-countdown .bg-circle { stroke: rgba(255,255,255,0.1); }
.ad-countdown .fg-circle {
  stroke: #FF8C00;
  stroke-linecap: round;
  transition: stroke-dashoffset 1s linear;
}
.ad-countdown .cd-text {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: 28px;
  color: #FFD700;
  font-weight: bold;
  font-variant-numeric: tabular-nums;
}
.btn-ad-watch {
  display: block;
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 25px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  background: linear-gradient(135deg, #FFD700, #FF8C00);
  color: #1a1a2e;
  letter-spacing: 3px;
  box-shadow: 0 4px 20px rgba(255,215,0,0.3);
  transition: transform 0.15s;
  margin-bottom: 8px;
  touch-action: manipulation;
  font-family: inherit;
}
.btn-ad-watch:active { transform: scale(0.95); }
.btn-ad-skip {
  display: block;
  width: 100%;
  padding: 10px;
  border: none;
  border-radius: 25px;
  font-size: 13px;
  cursor: pointer;
  background: transparent;
  color: rgba(255,255,255,0.4);
  letter-spacing: 2px;
  transition: color 0.2s;
  touch-action: manipulation;
  font-family: inherit;
}
.btn-ad-skip:active { color: rgba(255,255,255,0.7); }

/* ===== AD LOADING OVERLAY ===== */
.ad-loading-overlay {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  backdrop-filter: blur(4px);
}
.ad-loading-overlay.hidden { display: none; }
.ad-loading-content {
  text-align: center;
  padding: 30px;
  background: linear-gradient(135deg, rgba(30,25,15,0.95), rgba(15,12,8,0.98));
  border: 1.5px solid rgba(255,215,0,0.3);
  border-radius: 20px;
  box-shadow: 0 0 40px rgba(255,215,0,0.2);
}
.ad-loading-spinner {
  width: 50px;
  height: 50px;
  border: 4px solid rgba(255,215,0,0.1);
  border-top-color: #FFD700;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 16px;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
.ad-loading-text {
  font-size: 16px;
  color: #FFD700;
  margin-bottom: 8px;
  letter-spacing: 2px;
}
.ad-loading-tip {
  font-size: 12px;
  color: rgba(255,255,255,0.4);
}

/* ===== TOAST ===== */
.game-toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 14px 28px;
  background: rgba(0,0,0,0.9);
  border: 1px solid rgba(255,215,0,0.3);
  border-radius: 30px;
  color: #FFD700;
  font-size: 14px;
  text-shadow: 0 0 10px rgba(255,215,0,0.5);
  z-index: 600;
  animation: toastIn 0.3s ease-out;
}
@keyframes toastIn {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.8); }
  100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* ===== RESPONSIVE ===== */
@media (max-height: 500px) {
  .start-icon { font-size: 56px; }
  .start-title { font-size: 28px; }
  .start-rules { padding: 12px; margin-bottom: 16px; }
  .rule-item { font-size: 12px; }
  .game-canvas-wrap { padding: 4px; }
  .game-top { padding: 4px 8px; }
  .tool-btn { width: 40px; height: 40px; }
  .btn-help-ad { padding: 6px 10px; }
  .btn-help-ad .help-ad-text { font-size: 11px; }
}
