* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  overflow: hidden;
  background: #000;
  font-family: 'IBM Plex Mono', monospace;
  cursor: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

#scene-container {
  width: 100vw;
  height: 100vh;
  position: fixed;
  top: 0;
  left: 0;
}

#scene-container canvas {
  display: block;
  touch-action: none;
}

#click-to-play {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  cursor: pointer;
}

.play-inner {
  text-align: center;
}

.play-title {
  font-family: 'Bungee', cursive;
  font-size: 64px;
  color: #FFD700;
  text-shadow: 4px 4px 0 #C7000A, 8px 8px 0 rgba(0,0,0,0.3);
  margin-bottom: 20px;
  animation: bob 1.5s ease-in-out infinite;
}

.play-sub {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 24px;
  color: #fff;
  animation: pulse 1.2s ease-in-out infinite;
}

/* Show/hide desktop vs mobile text */
.mobile-only { display: none; }
.desktop-only { display: block; }

@media (hover: none) and (pointer: coarse) {
  .mobile-only { display: block; }
  .desktop-only { display: none; }
}

@media (max-width: 768px) {
  .play-title {
    font-size: 36px;
  }
  .play-sub {
    font-size: 18px;
  }
}

@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

#hud {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 100;
}

#crosshair {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
}

.ch {
  position: absolute;
  background: #fff;
  border-radius: 1px;
  box-shadow: 0 0 3px rgba(0,0,0,0.5);
}

.ch-h {
  width: 20px; height: 2px;
  top: -1px; left: -10px;
}

.ch-v {
  width: 2px; height: 20px;
  top: -10px; left: -1px;
}

#title {
  position: absolute;
  top: 16px; left: 20px;
  font-family: 'Bungee', cursive;
  font-size: 22px;
  color: #fff;
  text-shadow: 2px 2px 0 rgba(0,0,0,0.5);
  letter-spacing: 1px;
}

#block-count {
  position: absolute;
  top: 18px; right: 20px;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  text-shadow: 1px 1px 0 rgba(0,0,0,0.5);
  background: rgba(0,0,0,0.35);
  padding: 6px 14px;
  border-radius: 6px;
}

#color-palette {
  position: absolute;
  bottom: 50px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  pointer-events: all;
  background: rgba(0,0,0,0.4);
  padding: 8px 12px;
  border-radius: 10px;
  backdrop-filter: blur(4px);
}

.color-swatch {
  width: 36px;
  height: 36px;
  border-radius: 5px;
  cursor: pointer;
  border: 3px solid transparent;
  transition: border-color 0.15s, transform 0.15s;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
  position: relative;
}

.color-swatch:hover {
  transform: scale(1.15);
}

.color-swatch.selected {
  border-color: #fff;
  transform: scale(1.1);
  box-shadow: 0 0 10px rgba(255,255,255,0.4);
}

.color-swatch .key-hint {
  position: absolute;
  bottom: -16px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  color: rgba(255,255,255,0.6);
  font-family: 'IBM Plex Mono', monospace;
}

#controls-hint {
  position: absolute;
  bottom: 100px;
  left: 20px;
  font-size: 12px;
  color: rgba(255,255,255,0.7);
  background: rgba(0,0,0,0.35);
  padding: 10px 14px;
  border-radius: 8px;
  line-height: 1.8;
  transition: opacity 0.5s;
}

#controls-hint.hidden {
  opacity: 0;
  pointer-events: none;
}

#max-blocks-msg {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: 'Bungee', cursive;
  font-size: 20px;
  color: #FF4444;
  text-shadow: 2px 2px 0 rgba(0,0,0,0.5);
  background: rgba(0,0,0,0.6);
  padding: 12px 24px;
  border-radius: 10px;
}

#footer {
  position: fixed;
  bottom: 8px;
  right: 16px;
  z-index: 200;
}

#footer a {
  color: rgba(255,255,255,0.35);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  text-decoration: none;
  transition: color 0.2s;
}

#footer a:hover {
  color: rgba(255,255,255,0.7);
}

/* =============== MOBILE CONTROLS =============== */

#mobile-controls {
  display: none;
  pointer-events: none;
}

/* Show mobile controls on touch devices */
@media (hover: none) and (pointer: coarse) {
  #mobile-controls {
    display: block;
  }

  #controls-hint {
    display: none !important;
  }

  .color-swatch .key-hint {
    display: none;
  }

  #color-palette {
    bottom: 160px;
    padding: 6px 8px;
    gap: 4px;
  }

  .color-swatch {
    width: 28px;
    height: 28px;
    border-width: 2px;
  }

  #title {
    font-size: 16px;
    top: 12px;
    left: 12px;
  }

  #block-count {
    font-size: 12px;
    top: 14px;
    right: 12px;
    padding: 4px 10px;
  }

  #footer {
    bottom: 4px;
    right: 8px;
  }

  #footer a {
    font-size: 9px;
  }
}

/* Joystick Zone */
#joystick-zone {
  position: absolute;
  bottom: 30px;
  left: 20px;
  width: 150px;
  height: 150px;
  pointer-events: all;
  touch-action: none;
}

#joystick-base {
  position: absolute;
  width: 130px;
  height: 130px;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.3);
  border: 4px solid rgba(255, 255, 255, 0.25);
  box-shadow: 
    inset 0 0 20px rgba(0,0,0,0.2),
    0 0 0 2px rgba(0,0,0,0.15);
}

#joystick-knob {
  position: absolute;
  width: 56px;
  height: 56px;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.45);
  border: 3px solid rgba(255, 255, 255, 0.6);
  box-shadow: 
    0 2px 8px rgba(0,0,0,0.3),
    inset 0 1px 0 rgba(255,255,255,0.4);
  transition: background 0.1s;
}

#joystick-knob.active {
  background: rgba(255, 255, 255, 0.65);
  border-color: rgba(255, 255, 255, 0.85);
}

/* Mobile Buttons */
#mobile-buttons {
  position: absolute;
  bottom: 30px;
  right: 15px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-end;
  pointer-events: all;
  touch-action: none;
}

.mobile-btn {
  font-family: 'Bungee', cursive;
  font-size: 14px;
  letter-spacing: 1px;
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  text-shadow: 1px 1px 0 rgba(0,0,0,0.4);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: transform 0.08s, box-shadow 0.08s;
}

.mobile-btn:active,
.mobile-btn.pressed {
  transform: scale(0.92);
}

#btn-jump {
  width: 80px;
  height: 80px;
  background: linear-gradient(180deg, #4FC3F7 0%, #0288D1 100%);
  border-bottom: 4px solid #01579B;
  border-right: 2px solid #01579B;
  box-shadow: 0 4px 12px rgba(2, 136, 209, 0.4);
  font-size: 13px;
}

#btn-jump:active, #btn-jump.pressed {
  border-bottom-width: 2px;
  box-shadow: 0 2px 6px rgba(2, 136, 209, 0.3);
}

#btn-place {
  width: 72px;
  height: 56px;
  background: linear-gradient(180deg, #66BB6A 0%, #2E7D32 100%);
  border-bottom: 4px solid #1B5E20;
  border-right: 2px solid #1B5E20;
  box-shadow: 0 4px 12px rgba(46, 125, 50, 0.4);
  font-size: 12px;
}

#btn-place:active, #btn-place.pressed {
  border-bottom-width: 2px;
  box-shadow: 0 2px 6px rgba(46, 125, 50, 0.3);
}

#btn-remove {
  width: 72px;
  height: 56px;
  background: linear-gradient(180deg, #EF5350 0%, #C62828 100%);
  border-bottom: 4px solid #8E0000;
  border-right: 2px solid #8E0000;
  box-shadow: 0 4px 12px rgba(198, 40, 40, 0.4);
  font-size: 12px;
}

#btn-remove:active, #btn-remove.pressed {
  border-bottom-width: 2px;
  box-shadow: 0 2px 6px rgba(198, 40, 40, 0.3);
}

/* Layout: Jump on right, Place+Remove stacked next to jump */
@media (hover: none) and (pointer: coarse) {
  #mobile-buttons {
    flex-direction: row-reverse;
    align-items: flex-end;
    gap: 8px;
    bottom: 30px;
    right: 15px;
  }

  #btn-jump {
    align-self: flex-end;
  }

  .mobile-btn-stack {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
}