.ruins-challenge {
  position: fixed;
  inset: 0;
  z-index: 420;
  display: grid;
  place-items: center;
  background: rgba(4, 8, 16, 0.72);
  backdrop-filter: blur(6px);
  touch-action: none;
  transition: opacity 0.32s ease, background 0.32s ease;
}

.ruins-challenge[hidden] {
  display: none;
}

.ruins-challenge.is-resolving {
  pointer-events: none;
}

.ruins-challenge.is-fading {
  opacity: 0;
  background: rgba(255, 255, 255, 0.55);
}

.ruins-challenge__panel {
  width: min(560px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
  overflow: auto;
  padding: 18px 18px 14px;
  border-radius: 16px;
  border: 1px solid var(--panel-border);
  background: linear-gradient(165deg, rgba(14, 22, 40, 0.97), rgba(8, 12, 22, 0.96));
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  transition: opacity 0.28s ease, transform 0.28s ease, filter 0.28s ease;
}

.ruins-challenge.is-resolving .ruins-challenge__panel {
  filter: saturate(1.15);
}

.ruins-challenge.is-fading .ruins-challenge__panel {
  opacity: 0;
  transform: scale(1.04);
  filter: brightness(2.4);
}

.ruins-challenge__title {
  margin: 0 0 4px;
  font-family: Syne, "Segoe UI", sans-serif;
  font-size: 22px;
  font-weight: 800;
  color: #f8fafc;
}

.ruins-challenge__progress {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #7dd3fc;
}

.ruins-challenge__hint {
  margin: 0 0 12px;
  font-size: 13px;
  line-height: 1.4;
  color: var(--text-dim);
}

.ruins-challenge.is-wrong .ruins-challenge__hint {
  color: #fca5a5;
}

.ruins-challenge.is-resolving .ruins-challenge__hint {
  color: #fef9c3;
}

.ruins-challenge__prompt {
  margin: 0 0 14px;
  font-size: 15px;
  font-weight: 700;
  color: #e2e8f0;
  text-align: center;
}

.ruins-challenge__targets {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 14px;
  min-height: 72px;
  margin: 0 0 18px;
  padding: 16px;
  border-radius: 12px;
  border: 1px solid rgba(56, 189, 248, 0.22);
  background:
    radial-gradient(ellipse at center, rgba(56, 189, 248, 0.12), transparent 70%),
    #0a121c;
}

.ruins-challenge__targets .type-icon {
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.45));
}

.ruins-challenge__choices {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  transform-origin: center;
}

.ruins-challenge__choices.is-charging {
  animation:
    ruins-challenge-shake 1.2s ease-in forwards,
    ruins-challenge-glow 1.2s ease-in forwards;
}

.ruins-challenge__choices.is-charging::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 12px;
  pointer-events: none;
  background: rgba(255, 255, 255, 0);
  mix-blend-mode: screen;
  animation: ruins-challenge-whiteout 1.2s ease-in forwards;
}

.ruins-challenge__choices.is-whiteout::after {
  background: rgba(255, 255, 255, 1);
}

.ruins-challenge__choice {
  display: grid;
  place-items: center;
  min-height: 64px;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.28);
  background: rgba(11, 18, 32, 0.92);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.12s ease;
}

.ruins-challenge__choice:hover {
  border-color: rgba(125, 211, 252, 0.55);
  background: rgba(15, 28, 48, 0.96);
  transform: translateY(-1px);
}

.ruins-challenge__choice:focus-visible {
  outline: 2px solid #38bdf8;
  outline-offset: 2px;
}

.ruins-challenge__choice.is-wrong {
  border-color: rgba(248, 113, 113, 0.85);
  background: rgba(69, 10, 10, 0.55);
  animation: ruins-challenge-wrong 0.42s ease;
}

.ruins-challenge__choice.is-correct {
  border-color: rgba(74, 222, 128, 0.9);
  background: rgba(20, 83, 45, 0.55);
}

.ruins-challenge.is-resolving .ruins-challenge__choice {
  cursor: default;
}

.ruins-challenge__actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 14px;
}

.ruins-challenge__cancel {
  border: 0;
  border-radius: 10px;
  padding: 8px 14px;
  background: rgba(148, 163, 184, 0.16);
  color: #e2e8f0;
  font-weight: 700;
  cursor: pointer;
}

.ruins-challenge__cancel:hover {
  background: rgba(148, 163, 184, 0.28);
}

@keyframes ruins-challenge-wrong {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-4px);
  }
  75% {
    transform: translateX(4px);
  }
}

@keyframes ruins-challenge-shake {
  0% {
    transform: translate(0, 0) scale(1);
  }
  18% {
    transform: translate(-2px, 1px) scale(1.01);
  }
  36% {
    transform: translate(3px, -2px) scale(1.02);
  }
  54% {
    transform: translate(-4px, 3px) scale(1.03);
  }
  72% {
    transform: translate(5px, -4px) scale(1.045);
  }
  88% {
    transform: translate(-6px, 5px) scale(1.06);
  }
  100% {
    transform: translate(0, 0) scale(1.08);
  }
}

@keyframes ruins-challenge-glow {
  0% {
    filter: brightness(1) saturate(1);
    box-shadow: 0 0 8px rgba(250, 250, 255, 0.15);
  }
  55% {
    filter: brightness(1.55) saturate(1.25);
    box-shadow:
      0 0 18px rgba(250, 250, 255, 0.45),
      0 0 36px rgba(125, 211, 252, 0.35);
  }
  100% {
    filter: brightness(2.4) saturate(0.4);
    box-shadow:
      0 0 28px rgba(255, 255, 255, 0.9),
      0 0 54px rgba(255, 255, 255, 0.65);
  }
}

@keyframes ruins-challenge-whiteout {
  0% {
    background: rgba(255, 255, 255, 0);
  }
  55% {
    background: rgba(255, 255, 255, 0.2);
  }
  78% {
    background: rgba(255, 255, 255, 0.55);
  }
  100% {
    background: rgba(255, 255, 255, 1);
  }
}

@media (max-width: 480px) {
  .ruins-challenge__choices {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
