:root {
  --bg-top: #0b1524;
  --bg-bottom: #060b14;
  --card: #101b2a;
  --ink: #e7efff;
  --muted: #9eb0c9;
  --accent: #2aa2d0;
  --accent-2: #f06a3f;
  --ok: #42c172;
  --bad: #ff6f6f;
  --border: #2a3f58;
  --shadow: 0 16px 34px rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--ink);
  color-scheme: dark;
  background:
    radial-gradient(circle at 12% 10%, rgba(62, 122, 184, 0.26), transparent 38%),
    radial-gradient(circle at 88% 16%, rgba(248, 124, 73, 0.18), transparent 34%),
    linear-gradient(170deg, var(--bg-top), var(--bg-bottom));
  min-height: 100vh;
}

.app {
  width: min(1180px, 96vw);
  margin: 18px auto 24px;
}

.hud {
  background: rgba(12, 22, 36, 0.86);
  border: 1px solid #30475f;
  border-radius: 14px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
}

h1 {
  margin: 0 0 4px;
  letter-spacing: 0.03em;
  font-size: 1.75rem;
}

.subtitle {
  margin: 0;
  color: var(--muted);
}

.status-row {
  margin-top: 10px;
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

.status-row p {
  margin: 0;
  padding: 6px 10px;
  background: #16293f;
  border: 1px solid #2e4765;
  border-radius: 999px;
  font-size: 0.93rem;
}

.progress-track {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 6px;
}

.progress-dot {
  height: 18px;
  border-radius: 999px;
  background: #1a2f45;
  border: 1px solid #2e4968;
  transition: transform 180ms ease, background 180ms ease;
}

.progress-dot.active {
  transform: translateY(-1px);
  background: #366a97;
}

.progress-dot.complete {
  background: linear-gradient(90deg, #0e8c4a, #37b869);
  border-color: #228a4f;
}

.game-shell {
  margin-top: 14px;
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 14px;
}

.scene-card,
.quiz-card {
  background: var(--card);
  border-radius: 14px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.scene-card {
  padding: 12px;
}

#viewport {
  position: relative;
  width: 100%;
  height: 560px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid #36526f;
  background: #10273b;
}

#world {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 20% 18%, rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0) 40%),
    radial-gradient(circle at 76% 20%, rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 0) 42%),
    linear-gradient(180deg, #8fd3ff 0%, #c4e9ff 62%, #def4ff 100%);
  transform: translateY(0);
  transition: transform 760ms cubic-bezier(0.2, 0.7, 0.1, 1);
}

.layer {
  position: absolute;
  left: 0;
  width: 100%;
  overflow: hidden;
  isolation: isolate;
}

.layer-circle {
  border-radius: 50%;
}

.layer::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 50% 46%, rgba(255, 255, 255, 0.16), transparent 72%);
  opacity: 0.28;
  mix-blend-mode: soft-light;
  z-index: 1;
}

.layer-label {
  position: absolute;
  left: 10px;
  top: 14px;
  font-size: 0.73rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.82);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.35);
  font-weight: 700;
  z-index: 8;
  pointer-events: none;
  white-space: nowrap;
}

.sky {
  background:
    radial-gradient(circle at 20% 18%, rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0) 40%),
    radial-gradient(circle at 76% 20%, rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 0) 42%),
    linear-gradient(180deg, #8fd3ff 0%, #c4e9ff 62%, #def4ff 100%);
}

.crust {
  background:
    repeating-linear-gradient(
      118deg,
      rgba(69, 46, 33, 0.18) 0 12px,
      rgba(69, 46, 33, 0) 12px 34px
    ),
    radial-gradient(circle at 20% 35%, rgba(208, 168, 125, 0.33), transparent 48%),
    radial-gradient(circle at 74% 62%, rgba(255, 219, 180, 0.2), transparent 44%),
    linear-gradient(180deg, #9a7557 0%, #7d5c45 100%);
  background-blend-mode: multiply, screen, normal, normal;
}

.upper-mantle {
  background:
    repeating-linear-gradient(
      -32deg,
      rgba(255, 221, 162, 0.16) 0 14px,
      rgba(255, 221, 162, 0) 14px 36px
    ),
    radial-gradient(circle at 18% 34%, rgba(255, 209, 145, 0.34), transparent 44%),
    radial-gradient(circle at 78% 64%, rgba(255, 191, 116, 0.28), transparent 48%),
    linear-gradient(180deg, #f4a95a 0%, #d87a28 100%);
  background-blend-mode: soft-light, screen, normal, normal;
}

.mantle {
  background:
    repeating-radial-gradient(
      circle at 32% 46%,
      rgba(230, 162, 109, 0.16) 0 24px,
      rgba(230, 162, 109, 0) 24px 60px
    ),
    radial-gradient(circle at 16% 30%, rgba(224, 142, 86, 0.3), transparent 45%),
    radial-gradient(circle at 82% 68%, rgba(214, 111, 67, 0.34), transparent 46%),
    linear-gradient(180deg, #d86b31 0%, #a84321 100%);
  background-blend-mode: soft-light, normal, normal, normal;
}

.outer-core {
  background:
    repeating-linear-gradient(
      90deg,
      rgba(255, 208, 153, 0.14) 0 8px,
      rgba(255, 208, 153, 0) 8px 22px
    ),
    radial-gradient(circle at 26% 34%, rgba(255, 177, 118, 0.29), transparent 46%),
    radial-gradient(circle at 76% 70%, rgba(255, 136, 88, 0.34), transparent 48%),
    linear-gradient(180deg, #e4773a 0%, #ad3f25 100%);
  background-blend-mode: soft-light, screen, normal, normal;
}

.inner-core {
  background:
    repeating-linear-gradient(
      45deg,
      rgba(255, 245, 188, 0.16) 0 10px,
      rgba(255, 245, 188, 0) 10px 24px
    ),
    repeating-linear-gradient(
      -45deg,
      rgba(255, 175, 97, 0.12) 0 11px,
      rgba(255, 175, 97, 0) 11px 26px
    ),
    radial-gradient(circle at 50% 40%, rgba(255, 241, 173, 0.48), transparent 40%),
    radial-gradient(circle at 22% 72%, rgba(255, 198, 119, 0.33), transparent 40%),
    radial-gradient(circle at 78% 74%, rgba(255, 169, 97, 0.3), transparent 42%),
    linear-gradient(180deg, #ffd967 0%, #ee9e3a 60%, #d96d25 100%);
  background-blend-mode: screen, soft-light, normal, normal, normal, normal;
}

.convection-overlay {
  position: absolute;
  left: 0;
  width: 100%;
  pointer-events: none;
  z-index: 5;
}

.convection-track {
  position: absolute;
  border: 2px solid rgba(124, 20, 16, 0.3);
  border-radius: 999px;
  box-shadow: inset 0 0 14px rgba(255, 129, 102, 0.18);
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 117, 86, 0.1), transparent 72%);
}

.convection-overlay.upper .convection-track {
  opacity: 0.65;
}

.convection-overlay.deep .convection-track {
  opacity: 0.78;
}

.convection-arrow {
  position: absolute;
  left: 0;
  top: 0;
  width: 40px;
  height: 24px;
  --arrow-color: hsl(4 88% 55%);
  filter: drop-shadow(0 0 6px rgba(126, 12, 10, 0.55));
}

.convection-arrow::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  width: 24px;
  height: 6px;
  transform: translateY(-50%);
  border-radius: 999px;
  background: var(--arrow-color);
}

.convection-arrow::after {
  content: "";
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  border-top: 10px solid transparent;
  border-bottom: 10px solid transparent;
  border-left: 16px solid var(--arrow-color);
}

#drill {
  position: absolute;
  left: 50%;
  top: 0;
  width: 46px;
  transform: translate(-50%, -100%);
  z-index: 20;
  transition: top 760ms cubic-bezier(0.22, 0.71, 0.2, 1);
}

#drillHole {
  position: absolute;
  left: 50%;
  top: 175px;
  width: 46px;
  height: 0;
  transform: translateX(-50%);
  border-left: 1px solid rgba(25, 9, 8, 0.5);
  border-right: 1px solid rgba(25, 9, 8, 0.5);
  background:
    linear-gradient(90deg, rgba(18, 8, 8, 0.78), rgba(9, 4, 4, 0.96), rgba(18, 8, 8, 0.78));
  box-shadow:
    inset 0 0 12px rgba(0, 0, 0, 0.52),
    0 0 2px rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  z-index: 17;
  transition:
    height 760ms cubic-bezier(0.22, 0.71, 0.2, 1),
    opacity 220ms ease;
}

.drill-bit {
  width: 46px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.drill-body {
  position: relative;
  width: 38px;
  height: 48px;
  margin: 0 auto;
  border-radius: 0;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.4), transparent 42%),
    linear-gradient(180deg, #a7bdcc 0%, #6f8da2 60%, #4c6778 100%);
  border: 1px solid rgba(0, 0, 0, 0.3);
}

.drill-body::before {
  content: "";
  position: absolute;
  inset: -26% -45%;
  pointer-events: none;
  background:
    repeating-linear-gradient(
      38deg,
      rgba(240, 249, 255, 0.52) 0 7px,
      rgba(240, 249, 255, 0) 7px 14px
    );
  opacity: 0.7;
  animation: drillHelix 420ms linear infinite;
}

.drill-tip {
  width: 0;
  height: 0;
  margin: 0 auto;
  border-left: 19px solid transparent;
  border-right: 19px solid transparent;
  border-top: 32px solid #d8e4ea;
  filter: drop-shadow(0 2px 1px rgba(0, 0, 0, 0.35));
}

.drill-tip::after {
  content: "";
  position: relative;
  left: -12px;
  top: -30px;
  display: block;
  width: 24px;
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(236, 246, 255, 0.82), rgba(236, 246, 255, 0));
  transform: rotate(-12deg);
  animation: drillTipFlash 340ms linear infinite;
}

@keyframes drillHelix {
  from {
    transform: translateX(-12px);
  }
  to {
    transform: translateX(12px);
  }
}

@keyframes drillTipFlash {
  0% {
    opacity: 0.34;
  }
  50% {
    opacity: 0.82;
  }
  100% {
    opacity: 0.34;
  }
}

.quiz-card {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#loading {
  margin: 0;
  font-weight: 700;
  color: var(--muted);
}

.question-text {
  margin: 0;
  font-size: 1.08rem;
  line-height: 1.4;
}

.answer-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 9px;
  margin-top: 10px;
}

.answer-btn {
  width: 100%;
  text-align: left;
  border: 1px solid #2f4e6f;
  border-radius: 10px;
  background: #12283f;
  color: #e7f0ff;
  padding: 10px;
  font-size: 0.98rem;
  display: flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  transition: transform 100ms ease, background 160ms ease, border-color 160ms ease;
}

.answer-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  background: #1a3654;
  border-color: #4e7aa4;
}

.answer-btn:disabled {
  cursor: default;
}

.answer-btn.correct {
  border-color: #3cb668;
  background: #153626;
}

.answer-btn.wrong {
  border-color: #df5151;
  background: #3a1b1b;
}

.letter {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #2b4967;
  color: #eaf3ff;
  font-weight: 700;
  flex-shrink: 0;
}

.answer-text {
  line-height: 1.3;
}

.hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.feedback {
  min-height: 1.2em;
  margin: 0;
  font-weight: 700;
}

.feedback.good {
  color: var(--ok);
}

.feedback.bad {
  color: var(--bad);
}

.feedback.win {
  color: #ad5a00;
}

.restart {
  align-self: flex-start;
  border: 0;
  border-radius: 10px;
  background: linear-gradient(180deg, #2f8fca, #1e658f);
  color: #fff;
  font-weight: 700;
  padding: 10px 16px;
  cursor: pointer;
}

.success-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 16% 20%, rgba(134, 205, 255, 0.26), transparent 34%),
    radial-gradient(circle at 78% 16%, rgba(255, 170, 91, 0.24), transparent 36%),
    linear-gradient(180deg, rgba(5, 14, 26, 0.88), rgba(3, 10, 20, 0.94));
  opacity: 0;
  pointer-events: none;
  transition: opacity 320ms ease;
}

.success-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.success-panel {
  position: relative;
  width: min(920px, 94vw);
  height: min(640px, 88vh);
  border-radius: 20px;
  overflow: hidden;
  border: 1px solid rgba(186, 219, 255, 0.26);
  background:
    radial-gradient(circle at 50% -10%, rgba(132, 200, 255, 0.28), transparent 42%),
    radial-gradient(circle at 50% 110%, rgba(255, 151, 89, 0.18), transparent 48%),
    linear-gradient(180deg, #0e233d 0%, #08172a 100%);
  box-shadow: 0 28px 60px rgba(0, 0, 0, 0.42);
}

.fireworks-layer,
.confetti-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.fireworks-layer {
  z-index: 6;
}

.confetti-layer {
  z-index: 8;
}

.victory-earth-wrap {
  position: absolute;
  left: 50%;
  top: 43%;
  width: min(68vmin, 460px);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  z-index: 5;
}

.victory-earth {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  overflow: hidden;
  background: #9b7658;
  box-shadow:
    0 0 0 2px rgba(255, 255, 255, 0.22),
    0 20px 40px rgba(4, 8, 18, 0.55);
  transform: scale(2.25) translateY(10%);
  opacity: 0;
}

.success-overlay.active .victory-earth {
  animation: earthZoomOut 1700ms cubic-bezier(0.2, 0.75, 0.1, 1) forwards;
}

.victory-ring {
  position: absolute;
  border-radius: 50%;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.crust-ring {
  width: 100%;
  height: 100%;
  background:
    repeating-linear-gradient(
      118deg,
      rgba(66, 43, 30, 0.2) 0 14px,
      rgba(66, 43, 30, 0) 14px 34px
    ),
    linear-gradient(180deg, #9a7456, #7e5d45);
}

.mantle-ring {
  width: 97%;
  height: 97%;
  background:
    radial-gradient(circle at 26% 32%, rgba(255, 202, 144, 0.36), transparent 36%),
    radial-gradient(circle at 76% 66%, rgba(255, 141, 89, 0.3), transparent 40%),
    linear-gradient(180deg, #e7823f, #cb5528);
}

.outer-core-ring {
  width: 54.6%;
  height: 54.6%;
  background:
    repeating-linear-gradient(
      90deg,
      rgba(255, 206, 160, 0.16) 0 8px,
      rgba(255, 206, 160, 0) 8px 20px
    ),
    linear-gradient(180deg, #e27537, #b44726);
}

.inner-core-ring {
  width: 19.2%;
  height: 19.2%;
  background:
    radial-gradient(circle at 42% 36%, rgba(255, 242, 175, 0.6), transparent 42%),
    linear-gradient(180deg, #ffd769, #e38a30);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.14);
}

.success-copy {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  width: min(560px, 92%);
  text-align: center;
  z-index: 10;
  color: #f6f9ff;
  background: rgba(6, 16, 31, 0.66);
  border: 1px solid rgba(170, 211, 255, 0.28);
  border-radius: 14px;
  padding: 14px 16px 16px;
  backdrop-filter: blur(3px);
}

.success-copy h2 {
  margin: 0 0 4px;
  font-size: 1.56rem;
  letter-spacing: 0.02em;
}

.success-copy p {
  margin: 0 0 10px;
  color: rgba(233, 241, 255, 0.9);
}

.success-copy .restart {
  align-self: center;
}

.firework {
  position: absolute;
  width: 0;
  height: 0;
  transform: translate(-50%, -50%);
}

.firework-flash {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: var(--spark-color);
  box-shadow: 0 0 16px var(--spark-color);
  animation: fireworkFlash 520ms ease-out forwards;
}

.firework-spark {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 2px;
  height: 2px;
  transform: rotate(var(--angle));
}

.firework-spark::before {
  content: "";
  position: absolute;
  left: -1px;
  top: 0;
  width: 3px;
  height: 20px;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--spark-color), transparent 86%);
  transform-origin: 50% 0%;
  animation: sparkFly var(--spark-duration) ease-out forwards;
}

.confetti-piece {
  position: absolute;
  top: -8%;
  width: 8px;
  height: 14px;
  border-radius: 2px;
  background: var(--confetti-color);
  opacity: 0.92;
  transform: translateX(0) rotate(0deg);
  animation: confettiFall var(--fall-duration) linear forwards;
  animation-delay: var(--fall-delay);
}

@keyframes earthZoomOut {
  0% {
    transform: scale(2.25) translateY(10%);
    opacity: 0;
  }
  20% {
    opacity: 1;
  }
  100% {
    transform: scale(1) translateY(0);
    opacity: 1;
  }
}

@keyframes fireworkFlash {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.4);
  }
  30% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(2.8);
  }
}

@keyframes sparkFly {
  0% {
    opacity: 0;
    transform: translateY(0) scaleY(0.25);
  }
  18% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateY(calc(-1 * var(--spark-distance))) scaleY(1);
  }
}

@keyframes confettiFall {
  0% {
    opacity: 0;
    transform: translateX(0) translateY(0) rotate(0deg);
  }
  12% {
    opacity: 0.95;
  }
  100% {
    opacity: 0.95;
    transform:
      translateX(var(--confetti-drift))
      translateY(110vh)
      rotate(var(--confetti-spin));
  }
}

.hidden {
  display: none;
}

@media (max-width: 980px) {
  .game-shell {
    grid-template-columns: 1fr;
  }

  #viewport {
    height: 460px;
  }
}

@media (max-width: 560px) {
  .app {
    width: min(100%, 98vw);
    margin: 10px auto 14px;
  }

  h1 {
    font-size: 1.4rem;
  }

  #viewport {
    height: 420px;
  }

  .quiz-card {
    padding: 14px;
  }

  .success-panel {
    height: min(640px, 92vh);
  }

  .victory-earth-wrap {
    top: 40%;
    width: min(76vmin, 370px);
  }

  .success-copy h2 {
    font-size: 1.28rem;
  }

  .success-copy p {
    font-size: 0.94rem;
  }
}
