:root {
  color-scheme: light;
  --bg-gradient: radial-gradient(circle at top, #ffecd2, #fcb69f 45%, #f16688 100%);
  --card-bg: rgba(255, 255, 255, 0.85);
  --accent: #ff6f61;
  --accent-dark: #db3f52;
  --success: #3fc380;
  --shadow: 0 12px 24px rgba(0, 0, 0, 0.18);
  --text-main: #3b2e4a;
  --text-light: #5d4f72;
}

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg-gradient);
  font-family: "Noto Sans SC", "PingFang SC", "Hiragino Sans GB", "Helvetica Neue", Arial, sans-serif;
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
}

#game {
  width: min(960px, 95vw);
  min-height: 90vh;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 32px;
  padding: 24px clamp(16px, 4vw, 48px) 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  backdrop-filter: blur(12px);
}

#game-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

#game-header h1 {
  margin: 0;
  font-size: clamp(1.8rem, 5vw, 2.6rem);
  letter-spacing: 0.05em;
}

#progress {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.progress-orb {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.45);
  border: 2px solid rgba(255, 255, 255, 0.7);
  display: grid;
  place-items: center;
  font-size: 0.8rem;
  color: var(--text-light);
  transition: transform 0.3s ease, background 0.3s ease;
}

.progress-orb.completed {
  background: linear-gradient(135deg, var(--success), #a8e6cf);
  color: #fff;
  transform: scale(1.05);
  border-color: rgba(255, 255, 255, 0.9);
}

#screen-container {
  flex: 1;
  display: grid;
}

.screen {
  display: none;
  align-self: center;
}

.screen.active {
  display: block;
  animation: fadeIn 0.4s ease;
}

.card {
  background: var(--card-bg);
  border-radius: 24px;
  padding: clamp(18px, 3vw, 32px);
  box-shadow: var(--shadow);
  text-align: center;
}

.card.wide {
  max-height: 70vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card h2 {
  margin: 0 0 12px;
  font-size: clamp(1.6rem, 4vw, 2.2rem);
}

.card p {
  font-size: clamp(1rem, 2.7vw, 1.2rem);
  line-height: 1.6;
  margin: 0 0 16px;
  color: var(--text-light);
}

.scene-showcase {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.scene-frame {
  width: min(100%, 360px);
  border-radius: 18px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.7);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.scene-frame img {
  display: block;
  width: 100%;
  border-radius: 12px;
  image-rendering: pixelated;
}

.scene-frame.small {
  width: min(100%, 260px);
  margin: 0 auto 12px;
}

.scene-caption {
  margin: 0;
  font-size: clamp(0.95rem, 2.7vw, 1.1rem);
  color: var(--text-main);
}

.scene-banner {
  width: 100%;
  aspect-ratio: 18 / 5;
  border-radius: 16px;
  background-size: cover;
  background-position: center;
  margin-bottom: 16px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
  image-rendering: pixelated;
  background-repeat: no-repeat;
}

.battle-hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.energy-meter {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.energy-meter .label {
  font-size: 0.9rem;
  color: var(--text-light);
  text-align: left;
}

.energy-track {
  position: relative;
  width: 100%;
  height: 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.55);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
  overflow: hidden;
}

#energy-fill {
  position: absolute;
  inset: 0;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #ffd166, #ff9f1c);
  transition: width 0.4s ease;
  transform-origin: left center;
}

#energy-fill.pulse {
  animation: energyPulse 0.6s ease;
}

.streak-indicator {
  min-width: 96px;
  padding: 8px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.7);
  color: var(--accent-dark);
  font-weight: 700;
  text-align: center;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.streak-indicator.hot {
  background: linear-gradient(135deg, rgba(255, 111, 97, 0.85), rgba(255, 180, 92, 0.85));
  color: #fff7f0;
}

.scenario-story {
  margin: 0 0 12px;
  font-size: clamp(0.95rem, 2.6vw, 1.1rem);
  line-height: 1.5;
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.65);
  border-radius: 14px;
  padding: 12px 16px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.05);
}

.math-hook {
  margin: 0 0 16px;
  font-size: clamp(0.9rem, 2.4vw, 1.05rem);
  color: var(--text-light);
  background: rgba(255, 255, 255, 0.55);
  border-radius: 14px;
  padding: 10px 14px;
  text-align: left;
}

.battle-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.info-card {
  background: rgba(255, 255, 255, 0.6);
  border-radius: 16px;
  padding: 12px 16px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.05);
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.92rem;
  color: var(--text-main);
}

.info-card.plant {
  border-left: 4px solid rgba(109, 207, 142, 0.8);
}

.info-card.zombie {
  border-left: 4px solid rgba(255, 138, 128, 0.85);
}

.info-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  color: var(--text-main);
  font-size: 1rem;
}

.info-header .icon {
  font-size: 1.1rem;
}

.info-card p {
  margin: 0;
  line-height: 1.5;
}

.wave-preview {
  font-size: 0.85rem;
  color: var(--accent-dark);
}

button {
  font: inherit;
  border: none;
  border-radius: 18px;
  padding: 14px 22px;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.3s ease;
  touch-action: manipulation;
}

button:active {
  transform: scale(0.96);
}

button.cta {
  background: linear-gradient(135deg, var(--accent), #ff9a8b);
  color: #fff;
  box-shadow: 0 10px 20px rgba(255, 111, 97, 0.35);
}

button.cta:hover,
button.cta:focus {
  background: linear-gradient(135deg, #ff7c73, #ffb199);
}

button.ghost {
  background: rgba(255, 255, 255, 0.55);
  color: var(--accent);
  border: 2px solid rgba(255, 255, 255, 0.7);
}

.stage-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 14px;
  margin: 16px 0 24px;
}

.stage-button {
  background: rgba(255, 255, 255, 0.75);
  border-radius: 20px;
  padding: 16px;
  min-height: 110px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 8px;
  border: 2px solid transparent;
  box-shadow: 0 8px 14px rgba(0, 0, 0, 0.12);
  position: relative;
  overflow: hidden;
}

.stage-button.completed {
  border-color: var(--success);
  box-shadow: 0 10px 18px rgba(63, 195, 128, 0.25);
}

.stage-button .stage-level {
  font-size: 1.6rem;
  font-weight: 700;
}

.stage-button .stage-name {
  font-size: 0.95rem;
  color: var(--text-light);
}

.stage-button .stage-helper {
  font-size: 0.85rem;
  color: rgba(59, 46, 74, 0.7);
}

.stage-thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 12px;
  background-size: cover;
  background-position: center;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06);
}

.stage-button.completed .stage-thumb {
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.85);
  filter: saturate(1.2);
}

#question {
  font-size: clamp(1.4rem, 5vw, 2rem);
  font-weight: 700;
  margin-bottom: 18px;
}

.answer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
}

.answer-button {
  background: rgba(255, 255, 255, 0.8);
  font-size: clamp(1rem, 2.7vw, 1.3rem);
  font-weight: 600;
}

.answer-button.correct {
  background: linear-gradient(135deg, var(--success), #8de6a8);
  color: #fff;
}

.answer-button.wrong {
  background: linear-gradient(135deg, #ffd166, #ff9f1c);
  color: #3b2e4a;
}

#feedback {
  min-height: 28px;
  font-weight: 600;
  color: var(--accent-dark);
  margin-top: 12px;
}

.battle-log {
  margin: 14px 0 20px;
  max-height: 160px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 4px;
}

.battle-entry {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.7);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.05);
  font-size: 0.9rem;
  color: var(--text-main);
}

.battle-entry.success {
  background: linear-gradient(135deg, rgba(99, 229, 164, 0.85), rgba(181, 241, 203, 0.85));
  color: #0b422e;
}

.battle-entry.fail {
  background: linear-gradient(135deg, rgba(255, 198, 109, 0.85), rgba(255, 170, 94, 0.85));
  color: #5a3819;
}

.battle-entry .status {
  font-weight: 700;
}

.battle-entry .expression {
  font-weight: 600;
}

.battle-entry .detail {
  font-size: 0.85rem;
  color: inherit;
}

.table-grid {
  flex: 1;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(9, minmax(60px, 1fr));
  gap: 6px;
  padding-right: 8px;
}

.table-cell {
  background: rgba(255, 255, 255, 0.8);
  border-radius: 12px;
  padding: 8px 6px;
  font-weight: 600;
  display: grid;
  place-items: center;
  position: relative;
  min-height: 60px;
}

.table-cell.lit {
  background: linear-gradient(135deg, rgba(63, 195, 128, 0.9), rgba(168, 230, 207, 0.95));
  color: #fff;
}

.table-cell .tip {
  position: absolute;
  bottom: 4px;
  font-size: 0.7rem;
  opacity: 0.9;
}

#table-hint {
  min-height: 32px;
  font-size: 0.95rem;
  color: var(--text-light);
}

#game-footer {
  text-align: center;
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.85);
}

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

@keyframes energyPulse {
  0% {
    box-shadow: 0 0 0 rgba(255, 159, 28, 0.0);
    transform: scaleY(1);
  }
  50% {
    box-shadow: 0 0 12px rgba(255, 190, 92, 0.6);
    transform: scaleY(1.1);
  }
  100% {
    box-shadow: 0 0 0 rgba(255, 159, 28, 0.0);
    transform: scaleY(1);
  }
}

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

#challenge-screen .card.shake {
  animation: cardShake 0.45s ease;
}

@media (max-width: 720px) {
  #game {
    border-radius: 0;
    min-height: 100vh;
    width: 100vw;
    padding: clamp(16px, 4vw, 32px);
  }

  .card {
    border-radius: 20px;
  }

  .stage-grid {
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  }

  .scene-banner {
    aspect-ratio: 16 / 7;
  }

  .battle-hud {
    flex-direction: column;
    align-items: stretch;
  }

  .streak-indicator {
    align-self: flex-end;
  }

  .battle-cards {
    grid-template-columns: 1fr;
  }

  .table-grid {
    grid-template-columns: repeat(3, minmax(80px, 1fr));
    grid-auto-rows: 80px;
  }
}
