:root {
  --bg: #08131f;
  --panel: rgba(4, 12, 18, 0.84);
  --text: #f1f5f9;
  --muted: #b7c6d3;
  --accent: #d94747;
  --unlock: #1ba871;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  width: 100%;
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 20% 0%, #1c334b 0%, var(--bg) 55%);
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

#mapShell {
  position: fixed;
  inset: 0;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#mapShell.map-shake {
  animation: map-shake 220ms cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

#map {
  width: 100%;
  height: 100%;
}

.status-banner {
  display: none;
}

.hidden {
  display: none !important;
}

.reload-hold-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.92);
  backdrop-filter: blur(2px);
}

.reload-hold-text {
  color: #ffd6d6;
  font-size: clamp(26px, 7vw, 44px);
  font-weight: 800;
  letter-spacing: 1px;
  text-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
  animation: reload-hold-breathe 1.2s ease-in-out infinite;
}

.map-fail-scene {
  --map-fail-shift-y: -8vh;
  position: fixed;
  inset: 0;
  z-index: 3;
  background: #000;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 12px;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 520ms ease;
}

.map-fail-scene.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.map-fail-earth-wrap {
  width: min(54vw, 54vh);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  position: relative;
  z-index: 1;
  opacity: 0;
  transform: translateY(var(--map-fail-shift-y)) scale(0.92);
  transition: opacity 560ms ease, transform 560ms ease;
}

.map-fail-scene.is-visible .map-fail-earth-wrap {
  opacity: 1;
  transform: translateY(var(--map-fail-shift-y)) scale(1);
}

.map-fail-earth {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background:
    radial-gradient(circle at 33% 24%, rgba(137, 224, 255, 0.98) 0%, rgba(77, 174, 243, 0.96) 27%, rgba(28, 114, 212, 0.96) 57%, rgba(10, 50, 121, 0.98) 100%),
    radial-gradient(circle at 72% 74%, rgba(8, 43, 112, 0.78) 0%, transparent 60%),
    radial-gradient(circle at 18% 88%, rgba(5, 32, 86, 0.68) 0%, transparent 55%);
  box-shadow: inset -20px -18px 42px rgba(0, 0, 0, 0.34), inset 10px 12px 24px rgba(255, 255, 255, 0.12),
    0 14px 30px rgba(0, 0, 0, 0.62);
  position: relative;
  overflow: hidden;
}

.map-fail-earth::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(26% 17% at 28% 34%, rgba(126, 210, 119, 0.95) 0%, rgba(77, 164, 68, 0.94) 70%, transparent 73%),
    radial-gradient(17% 11% at 41% 43%, rgba(103, 190, 98, 0.93) 0%, rgba(61, 143, 56, 0.94) 74%, transparent 76%),
    radial-gradient(24% 14% at 58% 34%, rgba(130, 215, 126, 0.93) 0%, rgba(82, 168, 76, 0.94) 68%, transparent 71%),
    radial-gradient(16% 10% at 66% 48%, rgba(118, 206, 111, 0.9) 0%, rgba(67, 151, 63, 0.94) 70%, transparent 73%),
    radial-gradient(13% 9% at 22% 56%, rgba(111, 198, 105, 0.88) 0%, rgba(63, 146, 59, 0.92) 72%, transparent 75%),
    radial-gradient(12% 8% at 52% 62%, rgba(116, 202, 108, 0.86) 0%, rgba(62, 143, 58, 0.92) 72%, transparent 75%);
  filter: saturate(1.08);
  opacity: 0.95;
}

.map-fail-earth::after {
  content: "";
  position: absolute;
  inset: 6%;
  border-radius: 50%;
  background:
    radial-gradient(30% 12% at 26% 26%, rgba(255, 255, 255, 0.26), transparent 72%),
    radial-gradient(28% 11% at 70% 36%, rgba(255, 255, 255, 0.22), transparent 74%),
    radial-gradient(34% 10% at 46% 70%, rgba(255, 255, 255, 0.18), transparent 76%);
  mix-blend-mode: screen;
  pointer-events: none;
}

.map-fail-bandage {
  position: absolute;
  top: 58%;
  left: 52%;
  width: 46%;
  height: 19%;
  transform: translateX(-50%) rotate(-9deg);
  border-radius: 18px;
  background: linear-gradient(180deg, #fdf2d7, #efdab7 55%, #e9d2ac);
  border: 2px solid #d4b58c;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  z-index: 3;
}

.map-fail-bandage::before {
  content: "";
  position: absolute;
  top: 24%;
  left: 27%;
  width: 46%;
  height: 52%;
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(214, 166, 121, 0.72), rgba(196, 144, 101, 0.66));
}

.map-fail-bandage::after {
  content: "";
  position: absolute;
  inset: 10%;
  border-radius: 12px;
  background-image: radial-gradient(rgba(174, 130, 95, 0.42) 1.4px, transparent 1.8px);
  background-size: 11px 11px;
  opacity: 0.45;
}

.map-fail-tape {
  position: fixed;
  z-index: 2;
  left: calc(-28px - env(safe-area-inset-left));
  right: calc(-28px - env(safe-area-inset-right));
  width: auto;
  text-align: center;
  color: #1f1f1f;
  background: #ffd938;
  border-top: 4px solid #282828;
  border-bottom: 4px solid #282828;
  padding: 10px 0;
  font-size: clamp(14px, 3vw, 20px);
  font-weight: 900;
  letter-spacing: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
  top: calc(50% + min(54vw, 54vh) * 0.25 + var(--map-fail-shift-y));
  transform: rotate(-2.8deg);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(0, 0, 0, 0.16) inset;
  opacity: 0;
  animation: map-fail-tape-sway 1.9s ease-in-out infinite;
  transition: opacity 620ms ease;
}

.map-fail-scene.is-visible .map-fail-tape {
  opacity: 1;
}

.map-fail-tape::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(
      112deg,
      rgba(0, 0, 0, 0.16) 0,
      rgba(0, 0, 0, 0.16) 5px,
      rgba(0, 0, 0, 0.03) 5px,
      rgba(0, 0, 0, 0.03) 18px
    );
  mix-blend-mode: multiply;
  opacity: 0.5;
  animation: map-fail-tape-ripple 1.3s linear infinite;
  pointer-events: none;
}

.map-fail-tape::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(
      180deg,
      rgba(255, 255, 255, 0.24) 0%,
      rgba(255, 255, 255, 0.1) 26%,
      rgba(255, 255, 255, 0) 56%
    ),
    radial-gradient(110% 38% at 50% 50%, rgba(255, 255, 255, 0.2), transparent 64%);
  opacity: 0.5;
  animation: map-fail-tape-crease 1.7s ease-in-out infinite;
  pointer-events: none;
}

.map-fail-countdown {
  position: fixed;
  left: 50%;
  top: calc(50% + min(54vw, 54vh) * 0.66 + var(--map-fail-shift-y));
  margin: 0;
  color: #ffe2a8;
  font-size: clamp(26px, 7vw, 44px);
  font-weight: 900;
  letter-spacing: 1px;
  text-shadow: 0 4px 14px rgba(0, 0, 0, 0.6);
  opacity: 0;
  transform: translate(-50%, 10px);
  transition: opacity 620ms ease, transform 620ms ease;
}

.map-fail-scene.is-visible .map-fail-countdown {
  opacity: 1;
  transform: translate(-50%, 0);
}

body.map-fail .map-home-btn {
  display: none;
}

.map-home-btn {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top));
  right: calc(10px + env(safe-area-inset-right));
  z-index: 6;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid rgba(0, 0, 0, 0.22);
  background: rgba(255, 255, 255, 0.92);
  color: #111;
  font-size: 24px;
  line-height: 1;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.26);
}

.map-home-btn:active {
  transform: scale(0.96);
}

.hud-panel {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--panel), rgba(4, 12, 18, 0));
}

.score-block {
  display: flex;
  align-items: center;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.36);
  backdrop-filter: blur(6px);
}

.score-line {
  margin: 0;
  color: var(--text);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.score-value-inline {
  color: #ffd989;
  font-size: 24px;
  font-variant-numeric: tabular-nums;
}

.cards-row {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 2px;
  scroll-behavior: smooth;
}

.cards-row.collapsed {
  overflow-x: hidden;
}

#specialCards {
  display: none;
  gap: 10px;
}

.cards-row.expanded #specialCards {
  display: flex;
}

.tool-rack {
  margin-left: auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding-right: 2px;
}

.cards-row.expanded .tool-rack {
  display: none;
}

.tool-star {
  position: relative;
  border: none;
  background: transparent;
  display: grid;
  justify-items: center;
  align-content: end;
  gap: 0;
  padding: 0 4px 12px 0;
  cursor: pointer;
  line-height: 1;
}

.tool-frame {
  width: 36px;
  height: 36px;
  border-radius: 11px;
  border: 2px solid #8f97a3;
  background: #111722;
  overflow: hidden;
  display: grid;
  place-items: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  animation: tool-star-breathe 1.6s ease-in-out infinite;
}

.tool-icon {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  filter: grayscale(1) saturate(0.15) brightness(0.86);
}

.tool-star-l2 .tool-frame {
  width: 42px;
  height: 42px;
}

.tool-star-l3 .tool-frame {
  width: 48px;
  height: 48px;
  background: #05070d;
}

.tool-star-l1 .tool-icon {
  width: 100%;
  height: 100%;
  transform: translate(0, 0);
}

.tool-star-l2 .tool-icon {
  width: 88%;
  height: 88%;
  transform: translate(0, 0);
}

.tool-star-l3 .tool-icon {
  width: 50%;
  height: 50%;
  object-fit: contain;
  transform: translate(0, 0);
}

.tool-star-count {
  position: absolute;
  right: -2px;
  bottom: 0;
  font-size: 11px;
  font-weight: 700;
  color: #d7dde5;
}

.tool-star.has-stock .tool-frame {
  border-color: #f3cf6a;
  background: #15253a;
}

.tool-star.has-stock .tool-icon {
  filter: none;
}

.tool-star.has-stock .tool-star-count {
  color: #ffe398;
}

.tool-star.is-active .tool-frame {
  border-color: #ffe27f;
  animation: tool-star-breathe 1.6s ease-in-out infinite, tool-star-hop 0.5s ease-in-out infinite;
}

.tool-star.is-fake {
  cursor: default;
}

.tool-star:disabled {
  cursor: not-allowed;
  opacity: 0.9;
}

.character-card {
  min-width: 106px;
  max-width: 112px;
  padding: 8px;
  border-radius: 12px;
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.2);
  text-align: center;
  transition: transform 180ms ease, border-color 180ms ease;
}

.card-toggle {
  position: relative;
  cursor: pointer;
}

.card-toggle-arrow {
  position: absolute;
  top: 4px;
  right: 4px;
  font-size: 20px;
  font-weight: 800;
  line-height: 1;
  color: #ff2d2d;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
  box-shadow: none;
  animation: card-arrow-breathe 1.6s ease-in-out infinite;
}

.character-card img {
  width: 44px;
  height: 44px;
  object-fit: contain;
  display: block;
  margin: 0 auto 4px;
}

.character-card h3 {
  margin: 0;
  font-size: 12px;
  color: #1f1f1f;
  line-height: 1.2;
}

.character-card.locked:not(.card-toggle) h3 {
  color: transparent;
  user-select: none;
}

.character-card p {
  margin: 4px 0 0;
  font-size: 16px;
  font-weight: 700;
  color: #101010;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.character-card.locked {
  filter: grayscale(1);
  opacity: 0.8;
}

.character-card.unlocked {
  border-color: rgba(27, 168, 113, 0.8);
  transform: translateY(-2px);
  filter: none;
  opacity: 1;
}

.pop-gain {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 9;
  pointer-events: none;
  color: #ff4b4b;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0.4px;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  transform: translate(-50%, -45%);
  opacity: 0;
}

.pop-gain.animate {
  animation: pop-gain-float 1500ms ease-out forwards;
}

.query-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgba(5, 14, 21, 0.46);
  backdrop-filter: blur(2px);
  display: grid;
  place-items: center;
  pointer-events: auto;
}

.query-overlay.hidden {
  display: none;
}

.query-overlay-text {
  color: #ffd2d2;
  font-size: clamp(24px, 7vw, 42px);
  font-weight: 800;
  letter-spacing: 1px;
  text-shadow: 0 6px 16px rgba(0, 0, 0, 0.34);
  animation: query-overlay-pulse 1.1s ease-in-out infinite;
}

#collectLayer {
  position: fixed;
  inset: 0;
  z-index: 12;
  pointer-events: none;
}

.collect-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 45%, rgba(255, 85, 85, 0.18), rgba(2, 8, 12, 0.68));
  pointer-events: auto;
}

.collect-overlay.dismissed {
  animation: collect-overlay-out 620ms ease forwards;
}

.collect-sparkle {
  position: absolute;
  width: min(70vw, 460px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 200, 110, 0.45), rgba(255, 69, 69, 0.07) 62%, transparent 70%);
  animation: collect-sparkle-pulse 1000ms ease-in-out infinite;
  filter: blur(1px);
}

.collect-card {
  position: relative;
  border: none;
  background: transparent;
  cursor: pointer;
  width: min(54vw, 310px);
  transform-style: preserve-3d;
  animation: collect-card-bounce 760ms ease-out both;
}

.collect-card-faces {
  position: relative;
  transform-style: preserve-3d;
  animation: collect-card-flip 1500ms cubic-bezier(0.2, 0.72, 0, 1) both;
}

.collect-face {
  background: #ffffff;
  border: 2px solid rgba(0, 0, 0, 0.24);
  border-radius: 18px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.35), 0 0 18px rgba(255, 119, 119, 0.2);
  padding: 14px 14px 16px;
  min-height: 230px;
  backface-visibility: hidden;
}

.collect-face img {
  width: 118px;
  height: 118px;
  object-fit: contain;
  margin: 18px auto 8px;
  display: block;
}

.collect-face h4 {
  margin: 0;
  text-align: center;
  font-size: 24px;
  letter-spacing: 0.4px;
  color: #161616;
}

.collect-face-back {
  position: absolute;
  inset: 0;
  transform: rotateY(180deg);
}

.collect-label {
  margin: 10px 0 2px;
  text-align: center;
  color: #ffd572;
  font-size: 18px;
  font-weight: 800;
}

.collect-hint {
  margin: 0;
  text-align: center;
  color: #ffd4d4;
  font-size: 13px;
  letter-spacing: 0.2px;
}

.collect-card.collect-card-exit {
  animation: collect-card-shrink 640ms cubic-bezier(0.22, 0.76, 0.24, 1) forwards;
}

.collect-card.collect-card-exit-fade {
  animation: collect-card-fade 460ms ease forwards;
}

@media (min-width: 720px) {
  .hud-panel {
    max-width: 640px;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: calc(100% - 24px);
    border-radius: 18px 18px 0 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  #mapShell.map-shake {
    animation: none;
  }
  .card-toggle-arrow {
    animation: none;
  }
  .tool-frame {
    animation: none;
  }
  .tool-star.is-active .tool-frame {
    animation: none;
  }
  .query-overlay-text {
    animation: none;
  }
  .pop-gain.animate {
    animation: none;
    opacity: 1;
  }
  .collect-overlay {
    animation: none;
  }
  .collect-sparkle {
    animation: none;
  }
  .collect-card-faces {
    animation: none;
    transform: rotateY(180deg);
  }
  .reload-hold-text {
    animation: none;
  }
  .map-fail-tape,
  .map-fail-tape::before,
  .map-fail-tape::after {
    animation: none;
  }
}

@keyframes map-shake {
  0% {
    transform: translate3d(0, 0, 0);
  }
  20% {
    transform: translate3d(-7px, 2px, 0);
  }
  40% {
    transform: translate3d(7px, -2px, 0);
  }
  60% {
    transform: translate3d(-5px, 1px, 0);
  }
  80% {
    transform: translate3d(5px, -1px, 0);
  }
  100% {
    transform: translate3d(0, 0, 0);
  }
}

@keyframes pop-gain-float {
  0% {
    opacity: 0;
    transform: translate(-50%, -10%) scale(0.86);
  }
  10% {
    opacity: 1;
  }
  62% {
    opacity: 0.98;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -220%) scale(1.04);
  }
}

@keyframes card-arrow-breathe {
  0% {
    transform: scale(0.94);
    opacity: 0.86;
  }
  50% {
    transform: scale(1.08);
    opacity: 1;
  }
  100% {
    transform: scale(0.94);
    opacity: 0.86;
  }
}

@keyframes collect-card-flip {
  0% {
    transform: rotateY(0deg) scale(0.88);
  }
  35% {
    transform: rotateY(540deg) scale(1.03);
  }
  75% {
    transform: rotateY(980deg) scale(1.01);
  }
  100% {
    transform: rotateY(900deg) scale(1);
  }
}

@keyframes collect-card-bounce {
  0% {
    transform: translateY(28px) scale(0.9);
    opacity: 0;
  }
  100% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

@keyframes collect-sparkle-pulse {
  0% {
    transform: scale(0.94);
    opacity: 0.72;
  }
  50% {
    transform: scale(1.05);
    opacity: 1;
  }
  100% {
    transform: scale(0.94);
    opacity: 0.72;
  }
}

@keyframes collect-overlay-out {
  0% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

@keyframes collect-card-shrink {
  0% {
    transform: translate(0, 0) scale(1);
    opacity: 1;
  }
  100% {
    transform: translate(var(--collect-exit-x, 0), var(--collect-exit-y, 140px)) scale(0.22);
    opacity: 0;
  }
}

@keyframes collect-card-fade {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  100% {
    transform: scale(0.7);
    opacity: 0;
  }
}

@keyframes tool-star-breathe {
  0% {
    transform: scale(0.95);
    filter: brightness(0.95);
  }
  50% {
    transform: scale(1.1);
    filter: brightness(1.12);
  }
  100% {
    transform: scale(0.95);
    filter: brightness(0.95);
  }
}

@keyframes tool-star-hop {
  0% {
    translate: 0 0;
  }
  50% {
    translate: 0 -4px;
  }
  100% {
    translate: 0 0;
  }
}

@keyframes query-overlay-pulse {
  0% {
    opacity: 0.8;
  }
  50% {
    opacity: 1;
  }
  100% {
    opacity: 0.8;
  }
}

@keyframes reload-hold-breathe {
  0% {
    opacity: 0.72;
    transform: scale(0.97);
  }
  50% {
    opacity: 1;
    transform: scale(1.03);
  }
  100% {
    opacity: 0.72;
    transform: scale(0.97);
  }
}

@keyframes map-fail-tape-sway {
  0% {
    transform: rotate(-3.4deg) translate3d(0, -1px, 0) skewX(-1.4deg) scaleX(1.002);
  }
  50% {
    transform: rotate(-0.2deg) translate3d(0, 4px, 0) skewX(2.2deg) scaleX(0.996);
  }
  100% {
    transform: rotate(-3.4deg) translate3d(0, -1px, 0) skewX(-1.4deg) scaleX(1.002);
  }
}

@keyframes map-fail-tape-ripple {
  0% {
    background-position: 0 0;
  }
  100% {
    background-position: 34px 0;
  }
}

@keyframes map-fail-tape-crease {
  0% {
    transform: translateY(-1px) skewX(-1deg);
    opacity: 0.42;
  }
  50% {
    transform: translateY(2px) skewX(2.4deg);
    opacity: 0.62;
  }
  100% {
    transform: translateY(-1px) skewX(-1deg);
    opacity: 0.42;
  }
}
