html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #061828;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

#game {
  display: block;
  width: 100vw;
  height: 100vh;
  position: relative;
  z-index: 1;
}

#hitFlash {
  position: fixed;
  inset: 0;
  z-index: 15;
  pointer-events: none;
  opacity: 0;
  background:
    radial-gradient(circle at center, rgba(255, 255, 255, 0.35) 0%, transparent 28%),
    radial-gradient(circle at center, rgba(255, 30, 50, 0.72) 0%, rgba(180, 0, 30, 0.38) 32%, transparent 68%),
    radial-gradient(circle at center, transparent 45%, rgba(120, 0, 20, 0.55) 100%);
  transition: none;
}

#hitFlash.active {
  animation: hitFlashPulse 0.62s ease-out forwards;
}

@keyframes hitFlashPulse {
  0% {
    opacity: 1;
    filter: brightness(1.4) saturate(1.3);
  }
  12% {
    opacity: 0.95;
    filter: brightness(1.2) saturate(1.15);
  }
  28% {
    opacity: 0.75;
    filter: brightness(1) saturate(1);
  }
  50% {
    opacity: 0.45;
  }
  100% {
    opacity: 0;
    filter: brightness(1) saturate(1);
  }
}

#diamondFlash {
  position: fixed;
  inset: 0;
  z-index: 15;
  pointer-events: none;
  opacity: 0;
  background:
    radial-gradient(circle at center, rgba(255, 255, 220, 0.75) 0%, rgba(255, 220, 80, 0.45) 18%, transparent 42%),
    radial-gradient(circle at center, rgba(255, 200, 60, 0.55) 0%, rgba(255, 150, 20, 0.22) 38%, transparent 72%),
    radial-gradient(circle at 25% 35%, rgba(255, 255, 180, 0.4) 0%, transparent 45%),
    radial-gradient(circle at 75% 65%, rgba(255, 210, 80, 0.35) 0%, transparent 40%),
    radial-gradient(circle at center, transparent 50%, rgba(180, 120, 0, 0.25) 100%);
  transition: none;
}

#diamondFlash.active {
  animation: diamondFlashPulse 1.15s ease-out forwards;
}

@keyframes diamondFlashPulse {
  0% {
    opacity: 1;
    filter: brightness(1.6) saturate(1.4);
  }
  18% {
    opacity: 0.92;
    filter: brightness(1.35) saturate(1.25);
  }
  40% {
    opacity: 0.65;
    filter: brightness(1.15) saturate(1.1);
  }
  65% {
    opacity: 0.35;
  }
  100% {
    opacity: 0;
    filter: brightness(1) saturate(1);
  }
}

#touchControls {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 12;
  display: none;
}

@media (pointer: coarse), (max-width: 900px) {
  #touchControls {
    display: block;
  }
}

#touchControls .dpad {
  display: grid;
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: repeat(3, 52px);
  gap: 6px;
}

#touchControls .dpad button:nth-child(1) { grid-column: 2; grid-row: 1; }
#touchControls .dpad button:nth-child(2) { grid-column: 1; grid-row: 2; }
#touchControls .dpad button:nth-child(3) { grid-column: 2; grid-row: 3; }
#touchControls .dpad button:nth-child(4) { grid-column: 3; grid-row: 2; }

#touchControls button {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  padding: 0;
  font-size: 20px;
  font-weight: 800;
  color: #052033;
  background: linear-gradient(180deg, rgba(232, 251, 255, 0.95), rgba(94, 207, 255, 0.92));
  border: 1px solid rgba(120, 210, 255, 0.55);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.28);
  touch-action: manipulation;
  user-select: none;
}

#touchControls button:active {
  transform: scale(0.94);
  filter: brightness(0.96);
}

#hud {
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 10;
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  color: #e8f8ff;
  background: linear-gradient(135deg, rgba(0, 30, 55, 0.82), rgba(0, 50, 80, 0.65));
  border: 1px solid rgba(120, 210, 255, 0.5);
  border-radius: 14px;
  padding: 12px 18px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(12px);
  font-size: 15px;
  letter-spacing: 0.02em;
}

#hud strong {
  color: #7bd9ff;
  font-weight: 700;
}

#hud span {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.music-toggle {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 11;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border: 1px solid rgba(120, 210, 255, 0.55);
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(0, 30, 55, 0.88), rgba(0, 50, 80, 0.72));
  color: #e8f8ff;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(12px);
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
}

.music-toggle:hover {
  border-color: rgba(160, 230, 255, 0.85);
  transform: translateY(-1px);
}

.music-toggle:active {
  transform: translateY(0);
}

.music-toggle-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  background: rgba(110, 207, 255, 0.22);
  color: #9ee8ff;
  font-size: 1rem;
  line-height: 1;
}

.music-toggle.is-off {
  border-color: rgba(255, 255, 255, 0.18);
  color: rgba(232, 248, 255, 0.72);
}

.music-toggle.is-off .music-toggle-icon {
  background: rgba(255, 255, 255, 0.08);
  color: rgba(232, 248, 255, 0.45);
}

.music-toggle:focus-visible {
  outline: 2px solid #7bd9ff;
  outline-offset: 2px;
}

.camera-reset {
  position: fixed;
  top: 62px;
  right: 14px;
  z-index: 11;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border: 1px solid rgba(120, 210, 255, 0.55);
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(0, 30, 55, 0.88), rgba(0, 50, 80, 0.72));
  color: #e8f8ff;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(12px);
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
}

.camera-reset:hover {
  border-color: rgba(160, 230, 255, 0.85);
  transform: translateY(-1px);
}

.camera-reset:active {
  transform: translateY(0);
}

.camera-reset:focus-visible {
  outline: 2px solid #7bd9ff;
  outline-offset: 2px;
}

#overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  color: white;
  background: radial-gradient(circle at center, rgba(0, 80, 140, 0.55), rgba(0, 0, 0, 0.88));
}

#overlay.show-start-image {
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(to bottom, rgba(6, 24, 40, 0.92) 0%, rgba(6, 24, 40, 0.35) 18%, transparent 34%, transparent 72%, rgba(6, 24, 40, 0.88) 100%);
  pointer-events: none;
  transition: background 0.9s ease;
}

#overlay.show-start-image.title-splash-bg {
  background: #061828;
  pointer-events: auto;
  cursor: pointer;
}

.start-layout {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  width: 100%;
}

.start-hero {
  flex: 0 0 auto;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 10px 16px 0;
  max-height: min(34vh, 280px);
  pointer-events: none;
  transition:
    flex 1.05s cubic-bezier(0.34, 1.12, 0.64, 1),
    max-height 1.05s cubic-bezier(0.34, 1.12, 0.64, 1),
    padding 1.05s ease;
}

.start-layout.title-splash .start-hero {
  flex: 1 1 100%;
  max-height: 100%;
  padding: 0;
}

.start-layout.title-compact .start-hero {
  flex: 0 0 auto;
  max-height: min(34vh, 280px);
  padding: 10px 16px 0;
}

.start-hero-image {
  max-width: min(100%, 920px);
  max-height: min(34vh, 280px);
  width: auto;
  height: auto;
  object-fit: contain;
  object-position: center;
  filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.45));
  transition:
    max-width 1.05s cubic-bezier(0.34, 1.12, 0.64, 1),
    max-height 1.05s cubic-bezier(0.34, 1.12, 0.64, 1),
    width 1.05s cubic-bezier(0.34, 1.12, 0.64, 1),
    height 1.05s cubic-bezier(0.34, 1.12, 0.64, 1),
    filter 1.05s ease;
}

.start-layout.title-splash .start-hero-image {
  max-width: 100%;
  max-height: 100%;
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 16px 48px rgba(0, 0, 0, 0.55));
}

.start-layout.title-compact .start-hero-image {
  max-width: min(100%, 920px);
  max-height: min(34vh, 280px);
  width: auto;
  height: auto;
}

.start-demo-view {
  flex: 1 1 auto;
  min-height: 140px;
  pointer-events: none;
  transition:
    opacity 0.85s ease 0.2s,
    transform 0.85s cubic-bezier(0.34, 1.15, 0.64, 1) 0.2s,
    flex 1.05s ease,
    min-height 1.05s ease;
}

.start-layout.title-splash .start-demo-view {
  flex: 0 0 0;
  min-height: 0;
  opacity: 0;
  transform: translateY(20px);
  pointer-events: none;
}

.start-layout.title-compact .start-demo-view {
  flex: 1 1 auto;
  min-height: 140px;
  opacity: 1;
  transform: translateY(0);
}

.start-panel {
  flex: 0 0 auto;
  width: min(620px, calc(100vw - 24px));
  margin: 0 auto 18px;
  padding: 18px 22px 22px;
  border-radius: 20px;
  background: linear-gradient(160deg, rgba(6, 28, 52, 0.92), rgba(2, 14, 30, 0.9));
  border: 1px solid rgba(120, 210, 255, 0.42);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.55), 0 0 40px rgba(60, 180, 255, 0.08);
  text-align: center;
  pointer-events: auto;
  transition:
    opacity 0.85s ease 0.35s,
    transform 0.85s cubic-bezier(0.34, 1.15, 0.64, 1) 0.35s,
    max-height 1.05s ease,
    margin 1.05s ease,
    padding 1.05s ease;
}

.start-layout.title-splash .start-panel {
  opacity: 0;
  transform: translateY(28px);
  max-height: 0;
  margin: 0;
  padding: 0;
  overflow: hidden;
  visibility: hidden;
  pointer-events: none;
}

.start-layout.title-compact .start-panel {
  opacity: 1;
  transform: translateY(0);
  max-height: 520px;
  margin: 0 auto 18px;
  padding: 18px 22px 22px;
  visibility: visible;
  pointer-events: auto;
}

.start-help {
  margin: 0 0 16px;
  text-align: left;
  color: #c8ecff;
}

.start-help summary {
  cursor: pointer;
  font-weight: 600;
  color: #9ee8ff;
  margin-bottom: 8px;
}

.start-help p {
  line-height: 1.55;
  margin: 0 0 12px;
}

#overlay:not(.show-start-image) {
  display: grid;
  place-items: center;
}

#overlay:not(.show-start-image) .start-layout {
  display: none;
}

.modal-panel[hidden] {
  display: none !important;
}

body:has(#overlay.show-start-image:not(.hidden)) #hud,
body:has(#overlay.show-start-image:not(.hidden)) #touchControls,
body:has(#overlay.show-start-image:not(.hidden)) .camera-reset {
  display: none;
}

#overlay .panel {
  position: relative;
  z-index: 1;
}

#overlay.hidden {
  display: none;
}

#overlay.victory {
  background: radial-gradient(circle at center, rgba(255, 210, 80, 0.35), rgba(20, 10, 0, 0.92));
}

#overlay.victory .panel {
  border-color: rgba(255, 220, 120, 0.65);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6), 0 0 80px rgba(255, 200, 60, 0.25);
}

#overlay.victory .panel h1 {
  background: linear-gradient(180deg, #fff8d0, #ffd34e);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.panel {
  width: min(620px, calc(100vw - 32px));
  background: linear-gradient(160deg, rgba(6, 28, 52, 0.95), rgba(2, 14, 30, 0.92));
  border: 1px solid rgba(120, 210, 255, 0.4);
  border-radius: 22px;
  padding: 32px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6), 0 0 60px rgba(60, 180, 255, 0.08);
  text-align: center;
}

.panel h1 {
  margin: 0 0 16px;
  font-size: clamp(32px, 6vw, 58px);
  letter-spacing: 0.04em;
  background: linear-gradient(180deg, #ffffff, #7bd9ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.panel p {
  line-height: 1.55;
  color: #c8ecff;
}

.intro-caption {
  margin: 0 0 18px;
  padding: 14px 18px;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(0, 90, 160, 0.45), rgba(0, 40, 80, 0.55));
  border: 1px solid rgba(120, 210, 255, 0.45);
  box-shadow: 0 0 24px rgba(60, 180, 255, 0.12);
  font-size: clamp(15px, 2.8vw, 18px);
  line-height: 1.45;
  min-height: 2.8em;
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.intro-caption.is-updating {
  opacity: 0.55;
  transform: scale(0.985);
}

.keys {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(120, 210, 255, 0.15);
  border-radius: 14px;
  padding: 16px;
  margin: 18px 0;
}

button {
  cursor: pointer;
  border: 0;
  border-radius: 999px;
  padding: 14px 28px;
  font-weight: 800;
  font-size: 17px;
  color: #052033;
  background: linear-gradient(180deg, #e8fbff, #5ecfff);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3), 0 0 20px rgba(100, 200, 255, 0.2);
  transition: transform 0.15s ease, filter 0.15s ease;
}

button:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

button:active {
  transform: translateY(1px);
}
