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

html, body {
  height: 100%;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: radial-gradient(circle at 50% 15%, #2a1e4f, #120c24 75%);
  color: #fff;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  min-height: 100vh;
  padding: 16px;
  -webkit-user-select: none;
  user-select: none;
}

#app {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(640px, 100%);
  margin: auto 0;
}

/* ---------- HUD ---------- */
#hud {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.hud-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  padding: 6px 12px;
  min-width: 64px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.hud-item .label {
  font-size: 10px;
  letter-spacing: 1px;
  color: #bdb7d6;
  font-weight: 700;
}

.hud-item .value {
  font-size: 18px;
  font-weight: 800;
}

#sound-btn {
  margin-left: auto;
  width: 46px;
  height: 46px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  transition: transform 0.1s, background 0.2s;
}

#sound-btn:hover {
  background: rgba(255, 255, 255, 0.16);
}

#sound-btn:active {
  transform: scale(0.92);
}

#sound-btn.muted {
  opacity: 0.55;
}

/* ---------- Game area ---------- */
#game-wrap {
  position: relative;
  width: 100%;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
  background: #3a9460;
}

#overlay {
  position: absolute;
  inset: 0;
  display: flex;
  overflow-y: auto;
  padding: 12px;
  background: rgba(10, 6, 24, 0.68);
  border-radius: 14px;
}

.screen {
  text-align: center;
  padding: 24px;
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.hidden {
  display: none !important;
}

.title {
  font-size: 56px;
  font-weight: 900;
  letter-spacing: 2px;
  line-height: 1;
  background: linear-gradient(180deg, #ffe27a, #ff9d3f);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 4px 18px rgba(255, 150, 50, 0.35);
}

.tagline {
  color: #cfc8ea;
  font-size: 15px;
}

.screen h2 {
  font-size: 34px;
  font-weight: 900;
  letter-spacing: 1px;
}

.btn {
  cursor: pointer;
  border: none;
  border-radius: 999px;
  padding: 12px 26px;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 1px;
  color: #fff;
  background: linear-gradient(180deg, #5a6bff, #3f4fd8);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  transition: transform 0.08s, filter 0.15s;
}

.btn:hover {
  filter: brightness(1.12);
}

.btn:active {
  transform: scale(0.96);
}

.btn.primary {
  background: linear-gradient(180deg, #ffb347, #ff7a2e);
}

.howto-list {
  text-align: left;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 14px;
  color: #e8e4f7;
}

.howto-list li b {
  color: #ffd54f;
}

.final-score {
  font-size: 22px;
  color: #ffd54f;
  font-weight: 800;
}

#controls-hint {
  text-align: center;
  color: #a99fc9;
  font-size: 12px;
  letter-spacing: 0.5px;
}

/* ---------- Multiplayer menu & lobby ---------- */
.lobby-page {
  width: min(380px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.lobby-panel {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}

.field-label {
  font-size: 11px;
  letter-spacing: 1px;
  color: #bdb7d6;
  font-weight: 700;
  margin-top: 4px;
}

.text-input {
  width: 100%;
  max-width: 260px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 15px;
  text-align: center;
  outline: none;
}

.text-input:focus {
  border-color: #ffb347;
}

.code-input {
  font-family: "Consolas", "Menlo", "DejaVu Sans Mono", monospace;
  letter-spacing: 1px;
  font-weight: 600;
  text-transform: none;
}

.divider {
  width: 100%;
  max-width: 260px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: #8f86b8;
  font-size: 12px;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: rgba(255, 255, 255, 0.14);
}

.room-badge {
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: center;
  width: 100%;
  max-width: 320px;
}

.room-label {
  font-size: 12px;
  letter-spacing: 2px;
  color: #bdb7d6;
  font-weight: 700;
}

.room-code {
  font-family: "Consolas", "Menlo", "DejaVu Sans Mono", monospace;
  font-size: 14px;
  font-weight: 700;
  color: #ffd54f;
  word-break: break-all;
  line-height: 1.4;
}

.invite-row {
  display: flex;
  gap: 8px;
  width: 100%;
  max-width: 320px;
}

.invite-input {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  text-align: left;
  letter-spacing: 0;
}

.btn.small {
  padding: 10px 16px;
  font-size: 13px;
}

.qr-img {
  width: 150px;
  height: 150px;
  border-radius: 10px;
  background: #fff;
  padding: 6px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

.public-note {
  font-size: 12px;
  color: #bdb7d6;
  margin-top: 6px;
}

.status-msg {
  width: 100%;
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(47, 230, 168, 0.15);
  border: 1px solid rgba(47, 230, 168, 0.5);
  color: #b8ffd9;
  font-weight: 700;
  text-align: center;
}

.status-msg.error {
  background: rgba(255, 82, 82, 0.16);
  border-color: rgba(255, 82, 82, 0.5);
  color: #ffb4b4;
}

.toast {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  padding: 10px 18px;
  border-radius: 12px;
  background: rgba(20, 12, 40, 0.92);
  border: 1px solid rgba(255, 180, 80, 0.6);
  color: #ffd8a0;
  font-weight: 700;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  max-width: 90%;
  text-align: center;
}

.toast.error {
  border-color: rgba(255, 82, 82, 0.6);
  color: #ffb4b4;
}

.lobby-players {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  max-width: 260px;
}

.lobby-player {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.lobby-player.ready {
  border-color: #2fe6a8;
  background: rgba(47, 230, 168, 0.12);
}

.lobby-dot {
  width: 18px;
  text-align: center;
  color: #ffd54f;
  font-weight: 800;
}

.lobby-name {
  font-weight: 700;
}

/* ---------- Touch controls (mobile, portrait) ---------- */
#touch-controls {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 6px;
  touch-action: none;
}

.joystick {
  width: 150px;
  height: 150px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid rgba(255, 255, 255, 0.22);
  position: relative;
  touch-action: none;
  box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.4);
  -webkit-tap-highlight-color: transparent;
}

.joystick.active {
  border-color: #ffb347;
}

.joystick-thumb {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(255, 179, 71, 0.85), rgba(255, 122, 46, 0.65));
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  will-change: transform;
}

#touch-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.exit-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.12);
  color: #ffd0d0;
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

.exit-btn:active {
  background: rgba(255, 82, 82, 0.4);
  transform: scale(0.92);
}

.action-btn {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  border: 2px solid rgba(255, 179, 71, 0.7);
  background: radial-gradient(circle at 35% 30%, rgba(255, 179, 71, 0.55), rgba(255, 122, 46, 0.35));
  color: #fff;
  font-size: 42px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
}

.action-btn:active {
  transform: scale(0.92);
  filter: brightness(1.15);
}

@media (max-width: 560px) {
  #hud {
    flex-wrap: nowrap;
    gap: 4px;
  }

  .hud-item {
    flex: 1 1 0;
    min-width: 0;
    padding: 5px 2px;
    gap: 0;
    border-radius: 9px;
  }

  .hud-item .label {
    font-size: 8px;
    letter-spacing: 0.5px;
  }

  .hud-item .value {
    font-size: 13px;
    white-space: nowrap;
  }

  #sound-btn {
    width: 34px;
    height: 34px;
    min-width: 34px;
    flex: 0 0 34px;
    font-size: 15px;
    border-radius: 9px;
    margin-left: 0;
  }

  #app {
    gap: 8px;
  }

  .joystick {
    width: 140px;
    height: 140px;
  }

  .joystick-thumb {
    width: 58px;
    height: 58px;
  }

  .action-btn {
    width: 88px;
    height: 88px;
    font-size: 38px;
  }
}
