:root {
  --panel-bg: rgba(7, 18, 40, 0.86);
  --panel-border: rgba(255, 255, 255, 0.36);
  --panel-text: #ffffff;
  --button-bg: rgba(255, 255, 255, 0.16);
  --button-bg-hover: rgba(255, 255, 255, 0.28);
  --button-border: rgba(255, 255, 255, 0.35);
  --glow: 0 0 24px rgba(137, 218, 255, 0.9), 0 0 54px rgba(63, 123, 255, 0.5);
  --gold-glow: 0 0 18px rgba(255, 237, 133, 0.95), 0 0 42px rgba(62, 189, 255, 0.7), 0 0 76px rgba(63, 123, 255, 0.45);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: #ffffff;
  font-family: Arial, Helvetica, sans-serif;
  touch-action: manipulation;
}

button,
input {
  font: inherit;
}

.hidden {
  display: none !important;
}

.intro,
.world,
.analyzer-viewer {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.fullscreen-media,
.map-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center center;
  user-select: none;
  -webkit-user-drag: none;
}

.gate-still {
  z-index: 10;
  opacity: 1;
}

.world {
  background: #ffffff;
}

.white-flash {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: #ffffff;
  opacity: 0;
  pointer-events: none;
  transition: opacity 850ms ease;
}

.white-flash.on {
  opacity: 1;
}

.white-flash.gate-slow {
  transition-duration: 1400ms;
}

.start-button,
.enter-gate-button {
  position: fixed;
  left: 50%;
  bottom: max(36px, env(safe-area-inset-bottom));
  z-index: 20;
  transform: translateX(-50%);
  padding: 14px 22px;
  border: 1px solid rgba(255, 255, 255, 0.78);
  border-radius: 999px;
  color: #ffffff;
  background: rgba(3, 23, 52, 0.78);
  box-shadow: var(--glow);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  cursor: pointer;
}

.enter-gate-button {
  background: rgba(8, 35, 72, 0.84);
  animation: buttonPulse 1.8s ease-in-out infinite;
}

@keyframes buttonPulse {
  0%, 100% {
    transform: translateX(-50%) scale(1);
  }
  50% {
    transform: translateX(-50%) scale(1.04);
  }
}

.menu-toggle {
  position: fixed;
  top: max(18px, env(safe-area-inset-top));
  right: max(18px, env(safe-area-inset-right));
  z-index: 30;
  width: 70px;
  height: 70px;
  border: 2px solid rgba(255, 255, 255, 0.92);
  border-radius: 999px;
  color: #ffffff;
  background:
    radial-gradient(circle at 35% 25%, rgba(255, 255, 255, 0.38), rgba(255, 255, 255, 0.08) 34%, transparent 36%),
    linear-gradient(135deg, rgba(0, 13, 33, 0.92), rgba(6, 18, 55, 0.92));
  box-shadow: var(--gold-glow), 0 12px 28px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  cursor: pointer;
  font-size: 36px;
  line-height: 1;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.65);
  animation: gearPulse 2.6s ease-in-out infinite;
}

.menu-toggle:hover {
  transform: scale(1.06);
}

.menu-toggle:focus-visible,
.start-button:focus-visible,
.enter-gate-button:focus-visible,
.back-button:focus-visible {
  outline: 3px solid rgba(255, 242, 139, 0.95);
  outline-offset: 3px;
}

@keyframes gearPulse {
  0%, 100% {
    box-shadow: var(--gold-glow), 0 12px 28px rgba(0, 0, 0, 0.45);
  }
  50% {
    box-shadow: 0 0 28px rgba(255, 247, 173, 1), 0 0 66px rgba(78, 214, 255, 0.9), 0 0 100px rgba(63, 123, 255, 0.58), 0 12px 28px rgba(0, 0, 0, 0.45);
  }
}

.menu-panel {
  position: fixed;
  top: calc(max(18px, env(safe-area-inset-top)) + 84px);
  right: max(18px, env(safe-area-inset-right));
  z-index: 31;
  width: min(360px, calc(100vw - 36px));
  max-height: calc(100vh - 116px);
  max-height: calc(100dvh - 116px);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  color: var(--panel-text);
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35), var(--glow);
  padding: 14px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.menu-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  font-size: 18px;
}

.small-icon-button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--button-border);
  border-radius: 999px;
  color: #ffffff;
  background: var(--button-bg);
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
}

.menu-button,
.panel-button,
.search-button,
.clear-button {
  width: 100%;
  display: block;
  margin: 8px 0;
  padding: 12px 14px;
  border: 1px solid var(--button-border);
  border-radius: 14px;
  color: #ffffff;
  background: var(--button-bg);
  cursor: pointer;
  text-align: left;
}

.menu-button:hover,
.panel-button:hover,
.search-button:hover,
.clear-button:hover,
.small-icon-button:hover {
  background: var(--button-bg-hover);
}

.panel-host {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.2);
}

.panel-title {
  margin: 0 0 10px;
  font-size: 16px;
}

.submenu-title {
  margin: 14px 0 8px;
  opacity: 0.9;
  font-weight: bold;
}

.empty-note,
.status-note {
  margin: 10px 0;
  color: rgba(255, 255, 255, 0.84);
  line-height: 1.4;
}

.search-row {
  display: flex;
  gap: 8px;
}

.search-input {
  min-width: 0;
  flex: 1;
  padding: 12px 14px;
  border: 1px solid var(--button-border);
  border-radius: 14px;
  color: #ffffff;
  outline: none;
  background: rgba(255, 255, 255, 0.12);
}

.search-input::placeholder {
  color: rgba(255, 255, 255, 0.68);
}

.search-button {
  width: auto;
  min-width: 92px;
  text-align: center;
}

.asset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(74px, 1fr));
  gap: 10px;
}

.asset-card {
  display: grid;
  place-items: center;
  min-height: 78px;
  padding: 8px;
  border: 1px solid var(--button-border);
  border-radius: 14px;
  color: #ffffff;
  background: rgba(255, 255, 255, 0.12);
  cursor: pointer;
}

.asset-card img {
  display: block;
  max-width: 100%;
  max-height: 62px;
  object-fit: contain;
  image-rendering: auto;
  pointer-events: none;
}

.spritesheet-thumb {
  width: 62px;
  height: 62px;
  background-repeat: no-repeat;
  background-size: 100% 1200%;
  background-position: center 0%;
  image-rendering: auto;
  pointer-events: none;
}

.asset-name {
  max-width: 100%;
  margin-top: 6px;
  font-size: 11px;
  line-height: 1.15;
  color: rgba(255, 255, 255, 0.88);
  text-align: center;
  word-break: break-word;
  pointer-events: none;
}

.sprite-search-wrap {
  position: sticky;
  top: -14px;
  z-index: 2;
  margin-bottom: 10px;
  padding: 0 0 10px;
  background: rgba(7, 18, 40, 0.96);
}

.sprite-search-input {
  width: 100%;
}

.sprite-result-count {
  margin: 8px 0 0;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.78);
}

.digivice-sprite {
  position: fixed;
  top: calc(max(18px, env(safe-area-inset-top)) + 88px);
  right: max(18px, env(safe-area-inset-right));
  z-index: 24;
  width: clamp(76px, 11vw, 155px);
  max-height: min(28vh, 155px);
  height: auto;
  object-fit: contain;
  filter: drop-shadow(0 10px 14px rgba(0, 0, 0, 0.5));
  pointer-events: auto;
  cursor: pointer;
  user-select: none;
  -webkit-user-drag: none;
}

.placed-sprites {
  position: fixed;
  inset: 0;
  z-index: 22;
  pointer-events: none;
}

.placed-sprite {
  position: absolute;
  left: 50%;
  top: auto;
  bottom: max(24px, env(safe-area-inset-bottom));
  width: clamp(72px, 13vw, 160px);
  height: auto;
  transform: translateX(-50%);
  cursor: grab;
  pointer-events: auto;
  user-select: none;
  touch-action: none;
}

.sprite-visual {
  display: block;
  width: 100%;
  filter: drop-shadow(0 10px 10px rgba(0, 0, 0, 0.35));
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.sprite-visual-img {
  height: auto;
}

.sprite-visual-sheet {
  aspect-ratio: 1 / 1;
  background-repeat: no-repeat;
  background-size: 100% 1200%;
  background-position: center 0%;
  animation: digimonIdleBreath 1.05s steps(1, end) infinite;
}

.placed-sprite.enemy-sprite .sprite-visual {
  transform: scaleX(-1);
}

.placed-delete-button {
  position: absolute;
  top: -6px;
  right: -6px;
  z-index: 3;
  width: 15px;
  height: 15px;
  display: grid;
  place-items: center;
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: 999px;
  color: #ffffff;
  background: rgba(170, 15, 32, 0.92);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
  padding: 0;
}

.placed-delete-button:hover {
  background: rgba(230, 24, 48, 0.96);
}

@keyframes digimonIdleBreath {
  0%,
  49.99% {
    background-position: center 0%;
  }

  50%,
  100% {
    background-position: center 9.090909%;
  }
}

.placed-sprite:active {
  cursor: grabbing;
}

.analyzer-viewer {
  z-index: 80;
  display: grid;
  place-items: center;
  background: #000000;
}

.analyzer-video,
.analyzer-image {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  object-fit: contain;
  object-position: center center;
  user-select: none;
  -webkit-user-drag: none;
}

.analyzer-video {
  background: #000000;
}

.back-button {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  left: max(16px, env(safe-area-inset-left));
  z-index: 82;
  padding: 12px 16px;
  border: 1px solid rgba(255, 255, 255, 0.75);
  border-radius: 999px;
  color: #ffffff;
  background: rgba(5, 12, 28, 0.72);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
  cursor: pointer;
}

.sprite-visual-sheet.battle-frame-locked {
  animation: none;
}

.battle-effect {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 27;
  width: clamp(46px, 7vw, 96px);
  height: auto;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
  transform: translate(-50%, -50%);
  opacity: 1;
  filter: drop-shadow(0 0 12px rgba(255, 255, 255, 0.8))
          drop-shadow(0 8px 12px rgba(0, 0, 0, 0.45));
  transition:
    left 780ms ease-in-out,
    top 780ms ease-in-out,
    opacity 180ms ease;
}

.battle-effect.mega {
  width: clamp(64px, 10vw, 140px);
  transition:
    left 1080ms ease-in-out,
    top 1080ms ease-in-out,
    opacity 220ms ease;
}

.battle-effect.flipped {
  transform: translate(-50%, -50%) scaleX(-1);
}

.evolution-row {
  display: grid;
  gap: 8px;
  margin: 10px 0 12px;
}

.evolution-select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--button-border);
  border-radius: 14px;
  color: #ffffff;
  background: rgba(255, 255, 255, 0.12);
  outline: none;
}

.evolution-select option {
  color: #000000;
}

.placed-sprite.evolving {
  animation: evolutionGlow 1.25s ease-in-out;
}

@keyframes evolutionGlow {
  0% {
    filter: drop-shadow(0 0 0 rgba(255, 255, 255, 0));
  }

  35% {
    filter:
      drop-shadow(0 0 18px rgba(255, 255, 255, 1))
      drop-shadow(0 0 34px rgba(98, 220, 255, 0.95))
      drop-shadow(0 0 54px rgba(88, 117, 255, 0.8));
  }

  100% {
    filter: drop-shadow(0 0 0 rgba(255, 255, 255, 0));
  }
}

.placed-sprite.evolving .placed-delete-button {
  opacity: 0;
  pointer-events: none;
}

.sprite-visual.evolution-fading {
  transition: opacity 520ms ease;
}

.sprite-visual.evolution-hidden {
  opacity: 0;
}

.evolution-effect {
  position: fixed;
  z-index: 28;
  overflow: hidden;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
  opacity: 1;
  clip-path: inset(100% 0 0 0);
  transition:
    clip-path 950ms ease-out,
    opacity 520ms ease;
  filter:
    drop-shadow(0 0 18px rgba(255, 255, 255, 0.95))
    drop-shadow(0 0 34px rgba(71, 203, 255, 0.9))
    drop-shadow(0 0 58px rgba(63, 123, 255, 0.62));
}

.evolution-effect.revealed {
  clip-path: inset(0 0 0 0);
}

.evolution-effect.fading {
  opacity: 0;
}

.evolution-effect img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
  user-select: none;
  -webkit-user-drag: none;
}

@media (max-width: 720px) {
  .battle-effect {
    width: clamp(42px, 14vw, 82px);
  }

  .battle-effect.mega {
    width: clamp(58px, 20vw, 120px);
  }
}

@media (max-width: 720px) {
  .intro .fullscreen-media,
  .intro .gate-still {
    object-fit: contain;
    background: #000000;
  }

  .menu-toggle {
    top: max(14px, env(safe-area-inset-top));
    right: max(14px, env(safe-area-inset-right));
    width: 62px;
    height: 62px;
    font-size: 32px;
  }

  .menu-panel {
    top: auto;
    left: max(12px, env(safe-area-inset-left));
    right: max(12px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
    width: auto;
    max-height: min(76vh, 620px);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    border-radius: 20px;
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
  }

  .search-row {
    flex-direction: column;
  }

  .search-button {
    width: 100%;
  }

  .battle-row {
    display: grid;
    gap: 8px;
    margin: 10px 0;
  }

  .battle-select {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--button-border);
    border-radius: 14px;
    color: #ffffff;
    background: rgba(255, 255, 255, 0.12);
    outline: none;
  }

  .battle-select option {
    color: #000000;
  }

  .battle-result {
    margin-top: 12px;
    padding: 12px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.1);
    line-height: 1.45;
  }

  .battle-result strong {
    color: #fff3a6;
  }

  .battle-result .winner {
    color: #b8ffdb;
    font-weight: bold;
  }

  .battle-result .loser {
    color: #ffb8c0;
  }

  .battle-warning {
    color: #ffe08a;
  }

  .digivice-sprite {
    top: calc(max(14px, env(safe-area-inset-top)) + 76px);
    right: max(14px, env(safe-area-inset-right));
    width: clamp(72px, 22vw, 130px);
    max-height: min(28vh, 130px);
  }

  .placed-sprite {
    width: clamp(70px, 25vw, 140px);
    bottom: max(18px, env(safe-area-inset-bottom));
  }

  .start-button,
  .enter-gate-button {
    width: min(360px, calc(100vw - 32px));
    white-space: normal;
  }
}
