* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}
html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  overscroll-behavior: none;
}
body {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100dvh;
  font-family: "Jua", sans-serif;
  touch-action: none;
}
#app {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
#loading {
  color: #88aaff;
  font-size: 20px;
  text-align: center;
  padding: 40px;
}
#game-container {
  position: relative;
  width: 100vw;
  height: 100dvh;
  display: none;
  overflow: hidden;
}
#game-container canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  margin: auto;
}
#quiz-overlay {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(0, 4, 22, 0.82);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
#quiz-overlay.active {
  display: flex;
}
#quiz-panel {
  background: linear-gradient(160deg, #061830, #0a2040);
  border: 1.5px solid #1a4480;
  border-radius: 14px;
  padding: 28px 32px;
  width: 520px;
  max-width: 95%;
  box-shadow: 0 8px 40px #000a;
}
#quiz-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
#quiz-obj-icon {
  font-size: 28px;
}
#quiz-obj-name {
  font-size: 15px;
  color: #88aacc;
  font-family: "Jua", sans-serif;
}
#quiz-question {
  font-size: 15px;
  color: #ddeeff;
  line-height: 1.65;
  margin-bottom: 18px;
  white-space: pre-wrap;
  font-family: "Jua", sans-serif;
}
#quiz-choices {
  display: flex;
  flex-direction: column;
  gap: 9px;
}
.choice-btn {
  background: #0d2244;
  border: 1.5px solid #1a4480;
  color: #cce0ff;
  font-size: clamp(14px, 2.6vw, 18px);
  min-height: 48px;
  padding: 10px 14px;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  font-family: "Jua", sans-serif;
  transition:
    background 0.18s,
    border-color 0.18s;
  touch-action: manipulation;
}
.choice-btn:hover:not(:disabled) {
  background: #143366;
  border-color: #3366aa;
}
.choice-btn.correct {
  background: #0d3322;
  border-color: #33aa66;
  color: #88ffcc;
}
.choice-btn.wrong {
  background: #330d0d;
  border-color: #aa3333;
  color: #ffaaaa;
}
.choice-btn.show-ans {
  background: #1a3311;
  border-color: #55aa33;
  color: #aaff88;
}
#quiz-feedback {
  display: none;
  text-align: center;
}
#feedback-emoji {
  font-size: 40px;
  margin-bottom: 8px;
}
#feedback-title {
  font-size: 22px;
  font-family: "Jua", sans-serif;
  margin-bottom: 14px;
}
#feedback-explain {
  font-size: 13px;
  color: #aabbcc;
  line-height: 1.7;
  white-space: pre-wrap;
  margin-bottom: 12px;
  font-family: "Jua", sans-serif;
}
#feedback-retry-note {
  font-size: 12px;
  color: #ff9955;
  margin-bottom: 16px;
  font-family: "Jua", sans-serif;
}
#feedback-close {
  background: #117733;
  border: none;
  color: #fff;
  font-size: 14px;
  padding: 10px 24px;
  border-radius: 8px;
  cursor: pointer;
  font-family: "Jua", sans-serif;
}
#flash-msg {
  display: none;
  position: absolute;
  top: 45px;
  left: 50%;
  transform: translateX(-50%);
  background: #111a33dd;
  color: #ffdd44;
  border: 1px solid #3355aa;
  border-radius: 8px;
  padding: 8px 18px;
  font-size: 13px;
  font-family: "Jua", sans-serif;
  z-index: 300;
  pointer-events: none;
}
@keyframes flashAnim {
  0% {
    opacity: 0;
    transform: translateX(-50%) translateY(-8px);
  }
  10% {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
  80% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}
#clear-popup {
  display: none;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: linear-gradient(135deg, #061830dd, #0d2a50dd);
  border: 2px solid #2255aa;
  border-radius: 16px;
  padding: 32px 44px;
  text-align: center;
  z-index: 250;
  box-shadow: 0 10px 50px #000c;
}
.cp-emoji {
  font-size: 46px;
  margin-bottom: 10px;
}
.cp-title {
  font-size: 24px;
  color: #88ddff;
  font-family: "Jua", sans-serif;
  margin-bottom: 8px;
}
.cp-desc {
  font-size: 15px;
  color: #aabbcc;
  font-family: "Jua", sans-serif;
}

#touch-controls {
  display: none;
  position: absolute;
  left: max(14px, env(safe-area-inset-left));
  bottom: max(14px, env(safe-area-inset-bottom));
  width: 166px;
  height: 166px;
  z-index: 150;
  pointer-events: none;
  user-select: none;
}
#touch-controls.active {
  display: block;
}
#orientation-hint {
  display: none;
}
.move-btn {
  position: absolute;
  width: 58px;
  height: 58px;
  border: 2px solid #8ec9ff;
  background: #061c3ecc;
  color: #fff;
  border-radius: 18px;
  font-size: 25px;
  font-family: system-ui, sans-serif;
  box-shadow: 0 4px 16px #0009;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
}
.move-btn:active,
.move-btn.pressed {
  background: #1769aaee;
  transform: scale(0.94);
}
.move-btn.up {
  left: 54px;
  top: 0;
}
.move-btn.left {
  left: 0;
  top: 54px;
}
.move-btn.down {
  left: 54px;
  top: 108px;
}
.move-btn.right {
  left: 108px;
  top: 54px;
}

@media (max-height: 520px) {
  #touch-controls {
    transform: scale(0.78);
    transform-origin: left bottom;
  }
  #quiz-panel {
    padding: 16px 20px;
    max-height: 94dvh;
    overflow-y: auto;
  }
  #quiz-question {
    margin-bottom: 10px;
    line-height: 1.45;
  }
  #quiz-choices {
    gap: 6px;
  }
  .choice-btn {
    min-height: 42px;
    padding: 7px 10px;
  }
}

@media (orientation: portrait) {
  #game-container canvas {
    position: absolute;
    top: 16%;
    left: 0;
  }
  #touch-controls {
    bottom: 7%;
    transform: scale(0.88);
    transform-origin: left bottom;
  }
  #orientation-hint {
    display: block;
    position: absolute;
    top: max(18px, env(safe-area-inset-top));
    left: 50%;
    transform: translateX(-50%);
    color: #88bde8;
    font-size: 14px;
    white-space: nowrap;
  }
  #quiz-panel {
    width: min(92vw, 520px);
    padding: 20px;
  }
}
