:root {
  color-scheme: dark;
  --bg: #161f2d;
  font-family: "Space Grotesk", "JetBrains Mono", system-ui, -apple-system, sans-serif;
  background-color: var(--bg);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #161f2d;
  overflow: hidden;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

#dungeon {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: #161f2d;
  z-index: 1;
}

.bg-noise {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image: linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
  background-size: 80px 80px, 80px 80px;
  mix-blend-mode: normal;
  opacity: 0.1;
}

.touch-controls {
  position: fixed;
  bottom: 18px;
  left: 18px;
  z-index: 10;
  width: 160px;
  height: 160px;
  display: none;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 8px;
  touch-action: none;
}

body.show-touch-controls .touch-controls {
  display: grid;
}

.touch-btn {
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(22, 26, 34, 0.72);
  color: #e7f1ff;
  border-radius: 12px;
  font-size: 18px;
  font-weight: 700;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(8px);
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.touch-btn:active,
.touch-btn.active {
  transform: translateY(2px);
  background: rgba(36, 43, 56, 0.82);
  box-shadow: 0 6px 10px rgba(0, 0, 0, 0.18);
}

.touch-btn.up {
  grid-column: 2 / 3;
  grid-row: 1 / 2;
}

.touch-btn.left {
  grid-column: 1 / 2;
  grid-row: 2 / 3;
}

.touch-btn.right {
  grid-column: 3 / 4;
  grid-row: 2 / 3;
}

.touch-btn.down {
  grid-column: 2 / 3;
  grid-row: 3 / 4;
}

.fire-btn {
  position: fixed;
  right: 18px;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  z-index: 10;
  width: 96px;
  height: 96px;
  border-radius: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  letter-spacing: 0.35px;
  background: linear-gradient(180deg, rgba(30, 36, 46, 0.9), rgba(19, 23, 32, 0.85));
  color: #e7f1ff;
  box-shadow: 0 12px 22px rgba(0, 0, 0, 0.38), 0 0 0 1px rgba(255, 255, 255, 0.05) inset;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

body.show-touch-controls .fire-btn {
  display: inline-flex;
}

.fire-btn.disabled {
  opacity: 0.55;
  filter: saturate(0.6);
}

.fire-btn:active,
.fire-btn.active {
  transform: translateY(2px);
  background: linear-gradient(180deg, rgba(40, 48, 60, 0.92), rgba(30, 36, 46, 0.88));
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.28), 0 0 0 1px rgba(255, 255, 255, 0.08) inset;
}

.fire-btn.hidden {
  display: none !important;
}

.player-name-label,
.remote-name-label {
  z-index: 5;
  background: rgba(15, 22, 36, 0.55);
  backdrop-filter: blur(6px);
  padding: 2px 12px;
  border-radius: 4px;
  font-weight: 600;
  text-transform: uppercase;
  color: #f6fbff;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.65), 0 0 20px rgba(246, 251, 255, 0.6);
  pointer-events: none;
  transition: opacity 0.2s ease;
  font-family: "Space Grotesk", "JetBrains Mono", system-ui, -apple-system, sans-serif;
  will-change: transform, opacity;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.player-name-label {
  position: fixed;
  top: 18px;
  right: 18px;
  font-size: 1.1rem;
  letter-spacing: 0.25em;
  white-space: nowrap;
  opacity: 1;
  transform: none;
}

.remote-name-label {
  position: absolute;
  top: 0;
  left: 0;
  font-size: 1rem;
  letter-spacing: 0.18em;
  white-space: nowrap;
  opacity: 0;
  transform: translate(-50%, -100%);
}
