* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: #05061A;
  color: #fff;
  font-family: Arial, Helvetica, sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.back-link {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 100;
  font: 600 14px/1 Arial, sans-serif;
  color: #22D3EE;
  text-decoration: none;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(10, 15, 44, 0.7);
  border: 1px solid rgba(34, 211, 238, 0.35);
  backdrop-filter: blur(6px);
  transition: background 0.15s ease, transform 0.15s ease;
}
.back-link.story-link { left: auto; right: 16px; }
.back-link:hover { background: rgba(34, 211, 238, 0.16); transform: translateY(-1px); }

#stage {
  position: relative;
  width: 630px;
  height: 360px;
  max-width: 100vw;
  overflow: hidden;
  background: #000;
  box-shadow: 0 0 24px rgba(0,0,0,0.6);
}

@media (max-width: 660px) {
  #stage {
    width: 100vw;
    height: calc(100vw * 360 / 630);
  }
}

.screen {
  position: absolute;
  inset: 0;
  opacity: 0;
  transform: scale(0.97);
  pointer-events: none;
  transition: opacity 0.32s ease, transform 0.32s ease;
  z-index: 1;
}
.screen.active {
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
  z-index: 2;
  transition: opacity 0.32s ease, transform 0.32s cubic-bezier(0.34, 1.4, 0.64, 1);
}

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

.link-btn {
  position: absolute;
  transform: translate(-50%, -50%) scale(1);
  background: none;
  border: none;
  color: #ffff00;
  font: bold 20px/1.1 Arial, sans-serif;
  text-shadow: 1px 1px 2px #000;
  cursor: pointer;
  padding: 4px 8px;
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1), color 0.15s ease, text-shadow 0.15s ease;
  opacity: 0;
  animation: menuItemIn 0.5s cubic-bezier(0.22, 1, 0.36, 1) forwards;
  animation-delay: var(--stagger, 0s);
}
.link-btn:hover { color: #fff; transform: translate(-50%, -50%) scale(1.1); text-shadow: 0 0 10px rgba(255,255,255,0.8); }
.link-btn:active { transform: translate(-50%, -50%) scale(0.93); }
.link-btn.dark { color: #000; text-shadow: none; }
.link-btn.dark:hover { text-shadow: 0 0 8px rgba(0,0,0,0.35); }
.link-btn.small { font-size: 15px; }

#screen-menu .link-btn:nth-of-type(1) { --stagger: 0.05s; }
#screen-menu .link-btn:nth-of-type(2) { --stagger: 0.15s; }
#screen-menu .link-btn:nth-of-type(3) { --stagger: 0.25s; }
#screen-menu .link-btn:nth-of-type(4) { --stagger: 0.35s; }

@keyframes menuItemIn {
  from { opacity: 0; transform: translate(-50%, -30%) scale(0.85); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

@keyframes titlePulse {
  0%, 100% { filter: drop-shadow(0 0 0 rgba(255,255,0,0)); }
  50% { filter: drop-shadow(0 0 14px rgba(255,230,120,0.85)); }
}
#screen-menu .bg { animation: titlePulse 3.2s ease-in-out infinite; }

.level-title {
  position: absolute;
  left: 50%;
  top: 12%;
  transform: translate(-50%, -50%);
  margin: 0;
  font-size: 26px;
  color: #000;
}

.level-btn, .icon-btn {
  position: absolute;
  transform: translate(-50%, -50%) scale(1);
  cursor: pointer;
  border: none;
  background: none;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), filter 0.15s ease;
}
.level-btn { width: 40%; }
.level-btn:hover, .level-btn-hard:hover { transform: translate(-50%, -50%) scale(1.08); }
.level-btn:active, .level-btn-hard:active { transform: translate(-50%, -50%) scale(0.94); }

.level-btn-hard {
  width: 40%;
  padding: 10px 6px;
  font: bold 22px/1.1 Arial, sans-serif;
  color: #000;
  background: linear-gradient(#f2704a, #d94d1a);
  border: 3px solid #000;
  border-radius: 10px;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,0.25);
  transform: translate(-50%, -50%) scale(1);
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), filter 0.15s ease;
}
.level-btn-hard:hover { filter: brightness(1.08); }
.level-btn-hard:active { filter: brightness(0.95); }
.icon-btn { width: 48px; height: 48px; object-fit: contain; border-radius: 50%; }
.icon-btn:hover { filter: brightness(1.25); transform: translate(-50%, -50%) scale(1.15) rotate(-8deg); }
.icon-btn:active { transform: translate(-50%, -50%) scale(0.92); }

.quiz-box {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 20px 30px;
  background: #f5f5f0;
  color: #000;
  text-align: center;
}

#quiz-question {
  font-size: 19px;
  font-weight: bold;
  margin: 0;
  min-height: 3em;
}

.quiz-choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
}

.quiz-choice {
  padding: 10px 8px;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  border: 2px solid #333;
  border-radius: 6px;
  background: #fff;
  transform: scale(1);
  transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}
.quiz-choice:hover:not(:disabled) { background: #ffe680; transform: scale(1.04); }
.quiz-choice:active:not(:disabled) { transform: scale(0.96); }
.quiz-choice.correct { background: #7be07b; border-color: #2e7d32; animation: choicePop 0.4s ease; box-shadow: 0 0 14px rgba(46,125,50,0.5); }
.quiz-choice.wrong { background: #f08080; border-color: #b71c1c; animation: choiceShake 0.4s ease; }

@keyframes choicePop {
  0% { transform: scale(1); }
  40% { transform: scale(1.12); }
  100% { transform: scale(1); }
}
@keyframes choiceShake {
  0%, 100% { transform: translateX(0) scale(1); }
  20% { transform: translateX(-6px) scale(1.02); }
  40% { transform: translateX(6px) scale(1.02); }
  60% { transform: translateX(-4px) scale(1.02); }
  80% { transform: translateX(4px) scale(1.02); }
}

#quiz-question {
  animation: questionIn 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes questionIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

#quiz-feedback {
  font-size: 20px;
  font-weight: bold;
  margin: 0;
  animation: feedbackPop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
#quiz-feedback.correct { color: #2e7d32; }
#quiz-feedback.wrong { color: #b71c1c; }
@keyframes feedbackPop {
  from { opacity: 0; transform: scale(0.7); }
  to { opacity: 1; transform: scale(1); }
}

#quiz-score { font-size: 13px; margin: 0; color: #555; }

.hidden { display: none !important; }

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: #7ec8e3;
}

#btn-pause {
  position: absolute;
  right: 8px;
  bottom: 8px;
  padding: 6px 14px;
  font-weight: bold;
  cursor: pointer;
  transform: scale(1);
  transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1);
}
#btn-pause:hover { transform: scale(1.08); }
#btn-pause:active { transform: scale(0.92); }

#pause-overlay {
  position: absolute;
  inset: 0;
  background: rgba(30, 0, 60, 0.55);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: #fff;
  font-size: 28px;
  font-weight: bold;
  animation: pausePopIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes pausePopIn {
  from { opacity: 0; backdrop-filter: blur(0); }
  to { opacity: 1; }
}
#pause-overlay p {
  animation: pausePopIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  transform-origin: center;
}
#pause-overlay button {
  font-size: 16px;
  padding: 8px 20px;
  cursor: pointer;
  transform: scale(1);
  transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1);
}
#pause-overlay button:hover { transform: scale(1.08); }
#pause-overlay button:active { transform: scale(0.94); }

.gameover-title {
  position: absolute;
  left: 50%;
  top: 15%;
  transform: translateX(-50%);
  margin: 0;
  font-size: 18px;
  padding: 2px 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  color: #a00;
  animation: gameOverIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes gameOverIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-16px) scale(0.8); }
  to { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

.highscore-list {
  position: absolute;
  left: 57%;
  top: 24%;
  width: 38%;
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 2px 10px rgba(0,0,0,0.25);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 16px;
  color: #000;
  font-weight: bold;
  font-size: 13px;
}
.highscore-list > div {
  opacity: 0;
  animation: rowIn 0.35s ease forwards;
  animation-delay: calc(var(--i, 0) * 0.05s);
}
.highscore-list > div.new-score {
  color: #b8860b;
  animation: rowIn 0.35s ease forwards, rowGlow 1.4s ease 0.4s 2;
}
@keyframes rowIn {
  from { opacity: 0; transform: translateX(-6px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes rowGlow {
  0%, 100% { text-shadow: none; }
  50% { text-shadow: 0 0 8px rgba(184,134,11,0.9); }
}
