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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #6eb5ff;
  font-family: "Segoe UI", system-ui, sans-serif;
}

#game {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 20, 30, 0.72);
  backdrop-filter: blur(6px);
}

#overlay.hidden { display: none; }

.panel {
  max-width: 380px;
  margin: 1rem;
  padding: 1.4rem 1.5rem;
  border-radius: 14px;
  background: linear-gradient(160deg, #2d2d44 0%, #1a1a28 100%);
  color: #f0f3ff;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
  border: 2px solid #4a4a6a;
}

.panel h1 {
  font-size: 1.45rem;
  margin-bottom: 0.35rem;
  color: #fff;
}

.panel p {
  font-size: 0.88rem;
  color: #b8c0e0;
  margin-bottom: 0.75rem;
}

.panel ul {
  list-style: none;
  font-size: 0.82rem;
  color: #c8d0ef;
  margin-bottom: 1rem;
  line-height: 1.55;
}

.panel li::before { content: "▸ "; color: #7eb8ff; }

.hint-mobile { display: none; }
body.is-touch .hint-desktop { display: none; }
body.is-touch .hint-mobile { display: list-item; }

.setup-form {
  margin-bottom: 1rem;
}

.setup-form label,
.setup-label {
  display: block;
  font-size: 0.78rem;
  color: #b8c0e0;
  margin-bottom: 0.35rem;
}

.setup-label { margin-top: 0.65rem; }

#player-name {
  width: 100%;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  border: 1px solid #4a4a6a;
  background: #1a1a28;
  color: #fff;
  font-size: 0.95rem;
}

.avatar-colors {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.avatar-color {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  cursor: pointer;
}

.avatar-color.selected {
  border-color: #fff;
  box-shadow: 0 0 0 2px #00b06f;
}

.turnstile-wrap {
  margin-top: 0.35rem;
  min-height: 72px;
}

.turnstile-wrap #turnstile-widget {
  display: flex;
  justify-content: center;
  min-height: 65px;
}

.captcha-status,
.room-status {
  font-size: 0.75rem;
  color: #9aa8d0;
  margin-top: 0.35rem;
}

.room-status { margin-bottom: 0; }

.hud-players {
  font-size: 0.68rem;
  color: rgba(255, 255, 255, 0.75);
}

.hud-player {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.hud-name {
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.85);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

#btn-play {
  width: 100%;
  padding: 0.75rem 1rem;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  background: linear-gradient(180deg, #00b06f 0%, #00875a 100%);
  color: #fff;
  box-shadow: 0 4px 0 #005c3d;
}

#btn-play:hover { filter: brightness(1.08); }
#btn-play:active { transform: translateY(2px); box-shadow: 0 2px 0 #005c3d; }
#btn-play:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: none;
  transform: none;
  box-shadow: 0 4px 0 #005c3d;
}

#hud {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}

#hud[hidden] { display: none !important; }

.crosshair {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 28px;
  height: 28px;
  margin: -14px 0 0 -14px;
  pointer-events: none;
  z-index: 5;
  opacity: 0.92;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.crosshair-ring {
  position: absolute;
  inset: 0;
  border: 2px solid rgba(255, 255, 255, 0.95);
  border-radius: 50%;
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.45),
    0 0 6px rgba(0, 0, 0, 0.35);
}

.crosshair-dot {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 4px;
  height: 4px;
  margin: -2px 0 0 -2px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5);
}

.crosshair-line {
  position: absolute;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4);
}

.crosshair-line-n,
.crosshair-line-s {
  left: 50%;
  width: 2px;
  height: 6px;
  margin-left: -1px;
}

.crosshair-line-e,
.crosshair-line-w {
  top: 50%;
  width: 6px;
  height: 2px;
  margin-top: -1px;
}

.crosshair-line-n { top: -2px; }
.crosshair-line-s { bottom: -2px; }
.crosshair-line-e { right: -2px; }
.crosshair-line-w { left: -2px; }

.crosshair.is-valid .crosshair-ring {
  border-color: #7dffb8;
}

.crosshair.is-valid .crosshair-dot,
.crosshair.is-valid .crosshair-line {
  background: #7dffb8;
}

.crosshair.is-blocked .crosshair-ring {
  border-color: #ff8a80;
}

.crosshair.is-blocked .crosshair-dot,
.crosshair.is-blocked .crosshair-line {
  background: #ff8a80;
}

body.is-touch .crosshair {
  display: none;
}

.hud-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.65rem 0.85rem;
  pointer-events: none;
  z-index: 3;
}

.hud-right {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  pointer-events: auto;
}

.logo {
  font-weight: 800;
  font-size: 0.95rem;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  letter-spacing: 0.02em;
}

#hud-blocks {
  font-size: 0.78rem;
  color: #fff;
  background: rgba(0, 0, 0, 0.45);
  padding: 0.25rem 0.55rem;
  border-radius: 6px;
}

.btn-help {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.4);
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  font-size: 1.05rem;
  font-weight: 800;
  cursor: pointer;
  line-height: 1;
  touch-action: manipulation;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.btn-help:hover,
.btn-help:focus-visible {
  background: rgba(30, 136, 229, 0.75);
  border-color: rgba(255, 255, 255, 0.7);
  outline: none;
}

.controls-modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(10, 14, 24, 0.72);
  backdrop-filter: blur(5px);
  pointer-events: auto;
}

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

.controls-sheet {
  width: min(640px, 100%);
  max-height: min(88vh, 720px);
  overflow: auto;
  padding: 1.15rem 1.25rem 1.25rem;
  border-radius: 16px;
  background: linear-gradient(165deg, #2f3148 0%, #171825 100%);
  color: #eef1ff;
  border: 2px solid #4a4a6a;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.controls-sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.controls-sheet-head h2 {
  font-size: 1.2rem;
  font-weight: 800;
}

.btn-help-close {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}

.btn-help-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

.controls-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}

.controls-col h3 {
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #8eb8ff;
  margin-bottom: 0.45rem;
}

.controls-col ul {
  list-style: none;
  font-size: 0.84rem;
  line-height: 1.55;
  color: #cfd6f0;
}

.controls-col li {
  margin-bottom: 0.35rem;
  padding-left: 0.15rem;
}

.controls-col kbd {
  display: inline-block;
  min-width: 1.35em;
  padding: 0.08rem 0.35rem;
  margin: 0 0.08rem;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(0, 0, 0, 0.4);
  font-size: 0.75rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  text-align: center;
}

.controls-foot {
  margin-top: 0.9rem;
  font-size: 0.78rem;
  color: #9aa3c7;
}

body.is-touch .controls-desktop {
  opacity: 0.72;
}

body:not(.is-touch) .controls-mobile {
  opacity: 0.72;
}

@media (max-width: 560px) {
  .controls-cols {
    grid-template-columns: 1fr;
  }
}

.hotbar {
  position: absolute;
  bottom: 1.2rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 0.35rem;
  padding: 0.35rem;
  background: rgba(0, 0, 0, 0.55);
  border-radius: 10px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  pointer-events: auto;
  z-index: 11;
}

.hotbar-slot {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  cursor: default;
  position: relative;
}

.hotbar-slot.selected {
  border-color: #fff;
  box-shadow: 0 0 0 2px #00b06f;
}

.hotbar-slot span {
  position: absolute;
  bottom: 2px;
  right: 4px;
  font-size: 0.65rem;
  color: #fff;
  text-shadow: 0 1px 2px #000;
  font-weight: 700;
}

.hint {
  position: absolute;
  bottom: 4.5rem;
  width: 100%;
  text-align: center;
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.75);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}

#touch-controls {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

#touch-controls[hidden] { display: none !important; }

.pad-label {
  position: absolute;
  left: 50%;
  bottom: -1.15rem;
  transform: translateX(-50%);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.7);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  white-space: nowrap;
}

.joystick {
  position: absolute;
  left: 1rem;
  bottom: 1.6rem;
  width: 128px;
  height: 128px;
  pointer-events: auto;
  touch-action: none;
  z-index: 11;
}

.joystick-base {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.35);
  border: 2px solid rgba(255, 255, 255, 0.25);
}

.joystick-stick {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 48px;
  height: 48px;
  margin: -24px 0 0 -24px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  transition: transform 0.05s linear;
}

.joystick.is-active .joystick-base {
  border-color: rgba(255, 255, 255, 0.45);
  background: rgba(0, 0, 0, 0.45);
}

.look-zone {
  position: absolute;
  right: 1rem;
  bottom: 9.2rem;
  width: 128px;
  height: 128px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.28);
  border: 2px solid rgba(126, 184, 255, 0.4);
  pointer-events: auto;
  touch-action: none;
  z-index: 11;
  box-shadow: inset 0 0 24px rgba(30, 136, 229, 0.18);
}

.look-zone-ring {
  position: absolute;
  inset: 18%;
  border-radius: 50%;
  border: 1px dashed rgba(255, 255, 255, 0.22);
  pointer-events: none;
}

.look-zone-dot {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 28px;
  height: 28px;
  margin: -14px 0 0 -14px;
  border-radius: 50%;
  background: rgba(126, 184, 255, 0.9);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  transition: transform 0.05s linear;
}

.look-zone.is-active {
  border-color: rgba(126, 184, 255, 0.75);
  background: rgba(0, 20, 40, 0.42);
}

.touch-actions {
  position: absolute;
  right: 1rem;
  bottom: 1.6rem;
  display: grid;
  grid-template-columns: repeat(2, 58px);
  grid-template-rows: repeat(2, 58px);
  gap: 0.5rem;
  pointer-events: auto;
  z-index: 11;
}

.touch-btn {
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.42);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.touch-btn-main {
  font-size: 1.15rem;
  background: rgba(0, 0, 0, 0.5);
}

.touch-btn:active,
.touch-btn.is-held {
  background: rgba(255, 255, 255, 0.22);
  transform: scale(0.96);
}

#btn-jump {
  background: rgba(0, 135, 90, 0.72);
  border-color: rgba(180, 255, 220, 0.45);
}

#btn-place {
  background: rgba(30, 136, 229, 0.72);
}

#btn-break {
  background: rgba(229, 57, 53, 0.72);
}

#btn-break.is-selected {
  box-shadow: 0 0 0 3px #fff, 0 0 12px rgba(229, 57, 53, 0.8);
}

#btn-place.is-selected {
  box-shadow: 0 0 0 3px #fff, 0 0 12px rgba(30, 136, 229, 0.8);
}

#btn-run.is-held {
  background: rgba(253, 216, 53, 0.55);
  color: #1a1a28;
}

body.is-touch .hotbar {
  bottom: 10.5rem;
}

body.is-touch .hint {
  display: none;
}

@media (max-width: 480px) {
  .joystick {
    width: 112px;
    height: 112px;
    left: 0.65rem;
    bottom: 1.4rem;
  }

  .look-zone {
    width: 112px;
    height: 112px;
    right: 0.65rem;
    bottom: 8.6rem;
  }

  .touch-actions {
    right: 0.65rem;
    bottom: 1.4rem;
    grid-template-columns: repeat(2, 52px);
    grid-template-rows: repeat(2, 52px);
  }

  .hotbar-slot {
    width: 38px;
    height: 38px;
  }

  body.is-touch .hotbar {
    bottom: 9.6rem;
  }
}
