/**
 * Глобальные стили клиента.
 * Зачем: сброс отступов, полноэкранный canvas, базовые стили для UI (экран входа, список игроков).
 * Если удалить: layout и внешний вид UI будут сломаны; на 3D-сцену не влияет.
 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

#app {
  width: 100%;
  height: 100%;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* Экран входа */
#entry-ui {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(14, 28, 52, 0.88);
  color: #eee;
  font-family: "Segoe UI", Arial, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overflow-y: auto;
}

#scene-container {
  z-index: 15;
}

.entry-ui.entry-ui--panel .in-room {
  z-index: 20;
}

.entry-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-width: 280px;
  max-width: 420px;
  padding: 1.6rem 1.5rem 1.4rem;
  background: #fbf7ef;
  color: #243044;
  border: 1px solid #c4a35a;
  border-radius: 10px;
}

.entry-kicker {
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #c4a35a;
}

.entry-title {
  font-size: 1.45rem;
  line-height: 1.25;
  color: #1a365d;
  font-weight: 700;
}

.entry-lead {
  font-size: 0.92rem;
  line-height: 1.45;
  color: #5c6570;
  margin-bottom: 0.25rem;
}

.entry-form label {
  font-size: 0.9rem;
  color: #1a365d;
}

.entry-form input {
  padding: 0.5rem 0.75rem;
  font-size: 1rem;
  border: 1px solid #c4a35a;
  border-radius: 6px;
  background: #fff;
  color: #243044;
}

.entry-form button {
  padding: 0.65rem 1rem;
  font-size: 1rem;
  background: #1a365d;
  color: #eee;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

.entry-form button:hover {
  background: #27497a;
}

.in-room-title {
  margin-bottom: 0.5rem;
  font-size: 1rem;
  opacity: 0.9;
}

#players-list {
  list-style: none;
}

#players-list li {
  padding: 0.25rem 0;
}

/* Панель «В комнате» — отдельный блок в углу, не перекрывает canvas */
.players-panel {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 20;
  min-width: 160px;
  background: rgba(26, 26, 46, 0.92);
  color: #eee;
  font-family: sans-serif;
  padding: 0.75rem 1rem;
  border-radius: 8px;
}

.players-panel .in-room-title {
  margin-bottom: 0.5rem;
  font-size: 1rem;
  opacity: 0.9;
}

.players-panel ul {
  list-style: none;
}

.players-panel li {
  padding: 0.25rem 0;
}

.voice-ui-wrap {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 20;
}

.voice-mute-btn {
  padding: 0.4rem 0.75rem;
  font-size: 0.9rem;
  background: rgba(15, 52, 96, 0.9);
  color: #eee;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

.voice-mute-btn:hover {
  background: rgba(26, 74, 122, 0.9);
}

/* HUD экскурсии */
.game-hud {
  font-family: "Segoe UI", Arial, sans-serif;
  pointer-events: none;
}

.hud-keys {
  position: fixed;
  left: 22.5rem;
  bottom: 1rem;
  z-index: 22;
  padding: 0.7rem 0.85rem;
  background: rgba(26, 26, 46, 0.78);
  color: #eee;
  border-radius: 8px;
  min-width: 200px;
}

.hud-keys-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.82rem;
  line-height: 1.45;
  opacity: 0.95;
}

.hud-keys kbd {
  display: inline-block;
  min-width: 4.6rem;
  padding: 0.12rem 0.35rem;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(196, 163, 90, 0.45);
  border-radius: 4px;
  font-size: 0.72rem;
  text-align: center;
  color: #e8d7a8;
}

.hud-prompt {
  position: fixed;
  left: 50%;
  bottom: 2.2rem;
  transform: translateX(-50%);
  z-index: 22;
  padding: 0.55rem 1.1rem;
  background: rgba(26, 54, 93, 0.92);
  color: #fff;
  border-radius: 8px;
  font-size: 0.95rem;
  letter-spacing: 0.01em;
  border: 1px solid rgba(196, 163, 90, 0.55);
  pointer-events: none;
}

.hud-inspect-btn {
  pointer-events: auto;
  position: fixed;
  right: 20px;
  bottom: 180px;
  z-index: 32;
  min-width: 96px;
  height: 44px;
  border: none;
  border-radius: 10px;
  background: rgba(26, 54, 93, 0.92);
  color: #fff;
  font-size: 0.9rem;
}

.hud-inspect-btn:active {
  background: rgba(15, 40, 72, 0.95);
}

.hud-crosshair {
  position: fixed;
  left: 50%;
  top: 50%;
  width: 8px;
  height: 8px;
  margin: -4px 0 0 -4px;
  z-index: 21;
  border: 2px solid rgba(255, 255, 255, 0.8);
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
}

html.pointer-locked .hud-crosshair {
  opacity: 1;
}

.inspect-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: rgba(12, 16, 28, 0.55);
  pointer-events: auto;
}

.inspect-overlay[hidden] {
  display: none;
}

.inspect-card {
  position: relative;
  width: min(520px, 100%);
  max-height: min(82vh, 720px);
  overflow: auto;
  padding: 1.6rem 1.5rem 1.35rem;
  background: #fbf7ef;
  color: #243044;
  border-radius: 10px;
  border: 1px solid #c4a35a;
}

.inspect-close {
  position: absolute;
  top: 0.8rem;
  right: 0.8rem;
  padding: 0.35rem 0.7rem;
  border: none;
  border-radius: 6px;
  background: #1a365d;
  color: #fff;
  cursor: pointer;
  font-size: 0.85rem;
}

.inspect-close:hover {
  background: #27497a;
}

.inspect-kicker {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #c4a35a;
  margin-bottom: 0.35rem;
  padding-right: 5rem;
}

.inspect-title {
  font-size: 1.45rem;
  line-height: 1.25;
  color: #1a365d;
  margin-bottom: 0.85rem;
  padding-right: 5rem;
}

.inspect-body p {
  font-size: 0.95rem;
  line-height: 1.45;
  margin-bottom: 0.7rem;
}

.inspect-bullets {
  margin: 0.3rem 0 0.9rem 1.1rem;
}

.inspect-bullets li {
  margin-bottom: 0.35rem;
  font-size: 0.92rem;
  line-height: 1.4;
}

.inspect-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.4rem;
}

.inspect-link {
  display: inline-block;
  padding: 0.45rem 0.8rem;
  background: #1a365d;
  color: #fff;
  text-decoration: none;
  border-radius: 6px;
  font-size: 0.88rem;
}

.inspect-link:hover {
  background: #27497a;
}

.inspect-footer {
  margin-top: 0.9rem;
  font-size: 0.82rem;
  color: #5c6570;
}

.minimap {
  pointer-events: auto;
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 22;
  padding: 0.45rem 0.45rem 0.35rem;
  background: rgba(26, 26, 46, 0.82);
  border-radius: 8px;
  color: #eee;
}

.minimap-zone {
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-align: center;
  color: #e8d7a8;
  margin-bottom: 0.3rem;
}

.minimap-canvas {
  display: block;
  width: 168px;
  height: 168px;
  border-radius: 4px;
  cursor: pointer;
}

.minimap-hint {
  font-size: 0.68rem;
  text-align: center;
  opacity: 0.7;
  margin-top: 0.25rem;
}

.hud-view-btn {
  pointer-events: auto;
  position: fixed;
  top: 1rem;
  right: 13.6rem;
  z-index: 22;
  padding: 0.4rem 0.7rem;
  border: none;
  border-radius: 6px;
  background: rgba(26, 54, 93, 0.92);
  color: #fff;
  font-size: 0.82rem;
  cursor: pointer;
}

.hud-view-btn:hover {
  background: rgba(39, 73, 122, 0.95);
}

.hud-mic-btn {
  pointer-events: auto;
  position: fixed;
  top: 3.2rem;
  right: 13.6rem;
  z-index: 22;
  padding: 0.4rem 0.7rem;
  border: none;
  border-radius: 6px;
  background: rgba(26, 26, 46, 0.92);
  color: #eee;
  font-size: 0.82rem;
  cursor: pointer;
}

.hud-mic-btn:hover {
  background: rgba(39, 73, 122, 0.95);
}

.hud-mic-btn--on {
  background: #1a365d;
  color: #fff;
}

.hud-mic-btn--err {
  background: #5c2a2a;
}

.hud-tour-btn {
  pointer-events: auto;
  position: fixed;
  top: 5.4rem;
  right: 13.6rem;
  z-index: 22;
  padding: 0.4rem 0.7rem;
  border: none;
  border-radius: 6px;
  background: rgba(26, 26, 46, 0.92);
  color: #eee;
  font-size: 0.82rem;
  cursor: pointer;
}

.hud-tour-btn:hover {
  background: rgba(39, 73, 122, 0.95);
}

.hud-tour-btn--on {
  background: #1a365d;
  color: #fff;
}

.hud-tour {
  position: fixed;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 24;
  max-width: min(560px, calc(100vw - 20rem));
  padding: 0.5rem 0.9rem;
  background: rgba(26, 54, 93, 0.94);
  color: #fff;
  border-radius: 8px;
  border: 1px solid rgba(196, 163, 90, 0.55);
  font-size: 0.88rem;
  line-height: 1.4;
  text-align: center;
  pointer-events: none;
}

.hud-status {
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 22;
  padding: 0.4rem 0.7rem;
  background: rgba(26, 26, 46, 0.82);
  color: #eee;
  border-radius: 6px;
  font-size: 0.8rem;
}

.hud-status--on {
  color: #d5e4d6;
}

.hud-players {
  position: fixed;
  top: 3.1rem;
  left: 1rem;
  z-index: 22;
  min-width: 140px;
  padding: 0.55rem 0.75rem;
  background: rgba(26, 26, 46, 0.82);
  color: #eee;
  border-radius: 8px;
  font-size: 0.82rem;
}

.hud-players-title {
  margin-bottom: 0.35rem;
  color: #e8d7a8;
  font-size: 0.78rem;
}

.hud-players-list {
  list-style: none;
}

.hud-players-list li {
  padding: 0.15rem 0;
}

.hall-chat {
  pointer-events: auto;
  position: fixed;
  left: 1rem;
  bottom: 1rem;
  z-index: 28;
  width: min(340px, calc(100vw - 2rem));
  background: #16162a;
  color: #f3f3f3;
  border-radius: 10px;
  border: 1px solid rgba(196, 163, 90, 0.55);
  padding: 0.65rem 0.7rem 0.6rem;
}

.hall-chat-title {
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #e8d7a8;
  margin-bottom: 0.4rem;
}

.hall-chat-log {
  min-height: 8.5rem;
  max-height: 12rem;
  overflow-y: auto;
  font-size: 0.9rem;
  line-height: 1.4;
  margin-bottom: 0.5rem;
  padding: 0.45rem 0.5rem;
  background: #0f1020;
  border-radius: 6px;
}

.hall-chat-line {
  margin-bottom: 0.35rem;
  word-break: break-word;
  color: #f4f4f4;
}

.hall-chat-line strong {
  color: #e8d7a8;
  font-weight: 600;
}

.hall-chat-form {
  display: flex;
  gap: 0.4rem;
}

.hall-chat-input {
  flex: 1;
  min-width: 0;
  padding: 0.45rem 0.55rem;
  border: 1px solid rgba(196, 163, 90, 0.55);
  border-radius: 6px;
  background: #0f1020;
  color: #fff;
  font-size: 0.9rem;
}

.hall-chat-input::placeholder {
  color: #9aa3b2;
}

.hall-chat-send {
  padding: 0.45rem 0.7rem;
  border: none;
  border-radius: 6px;
  background: #1a365d;
  color: #fff;
  font-size: 0.82rem;
  cursor: pointer;
}

.hall-chat-send:hover {
  background: #27497a;
}

.hall-chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}

.hall-chat-head .hall-chat-title {
  margin-bottom: 0;
}

.hall-chat-toggle {
  display: none;
  border: none;
  background: transparent;
  color: #e8d7a8;
  font-size: 0.78rem;
  cursor: pointer;
  padding: 0.15rem 0.2rem;
}

.mobile-controls {
  position: fixed;
  left: max(0.4rem, env(safe-area-inset-left));
  bottom: max(0.7rem, env(safe-area-inset-bottom));
  z-index: 30;
  touch-action: none;
  user-select: none;
  pointer-events: none;
}

.mobile-controls > * {
  pointer-events: auto;
}

.mobile-joystick {
  position: relative;
  width: 118px;
  height: 118px;
  border-radius: 50%;
  background: rgba(12, 18, 32, 0.42);
  border: 1px solid rgba(196, 163, 90, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}

.mobile-joystick-thumb {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
  position: absolute;
  left: 50%;
  top: 50%;
  margin: -24px 0 0 -24px;
  pointer-events: none;
}

.mobile-joystick.active .mobile-joystick-thumb {
  background: rgba(255, 255, 255, 0.88);
}

.mobile-jump {
  position: fixed;
  right: max(0.7rem, env(safe-area-inset-right));
  bottom: max(1.1rem, env(safe-area-inset-bottom));
  z-index: 30;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 1px solid rgba(196, 163, 90, 0.4);
  background: rgba(12, 18, 32, 0.48);
  color: #fff;
  font-size: 0.72rem;
  touch-action: manipulation;
}

.mobile-jump:active {
  background: rgba(26, 54, 93, 0.85);
}

body.inspect-open .mobile-controls,
body.inspect-open .mobile-jump,
body.chat-open .mobile-controls,
body.chat-open .mobile-jump,
body.chat-open .hud-inspect-btn,
body.chat-open .hud-prompt {
  visibility: hidden;
  pointer-events: none;
}

@media (max-width: 900px), (pointer: coarse) {
  .hud-keys {
    display: none;
  }

  .hud-players {
    display: none;
  }

  .hud-status {
    left: max(0.5rem, env(safe-area-inset-left));
    top: max(0.45rem, env(safe-area-inset-top));
    max-width: calc(100vw - 11.5rem);
    font-size: 0.72rem;
    padding: 0.32rem 0.55rem;
  }

  .minimap {
    top: max(0.45rem, env(safe-area-inset-top));
    right: max(0.45rem, env(safe-area-inset-right));
    bottom: auto;
    transform: none;
    padding: 0.3rem 0.3rem 0.2rem;
  }

  .minimap-canvas {
    width: 104px;
    height: 104px;
  }

  .minimap-hint {
    display: none;
  }

  .minimap-zone {
    font-size: 0.68rem;
    margin-bottom: 0.15rem;
  }

  .hud-view-btn,
  .hud-mic-btn,
  .hud-tour-btn {
    top: auto;
    bottom: auto;
    right: max(0.45rem, env(safe-area-inset-right));
    left: auto;
    min-height: 40px;
    max-width: 6.8rem;
    padding: 0.32rem 0.5rem;
    font-size: 0.72rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .hud-view-btn {
    top: calc(max(0.45rem, env(safe-area-inset-top)) + 8.35rem);
  }

  .hud-mic-btn {
    top: calc(max(0.45rem, env(safe-area-inset-top)) + 10.95rem);
  }

  .hud-tour-btn {
    top: calc(max(0.45rem, env(safe-area-inset-top)) + 13.55rem);
  }

  .hud-tour {
    top: calc(max(0.45rem, env(safe-area-inset-top)) + 4.6rem);
    left: max(0.5rem, env(safe-area-inset-left));
    right: 8.4rem;
    transform: none;
    max-width: none;
    font-size: 0.78rem;
    padding: 0.4rem 0.6rem;
    text-align: left;
  }

  .hud-prompt {
    bottom: 8.8rem;
    max-width: min(22rem, calc(100vw - 9.5rem));
    font-size: 0.82rem;
    padding: 0.4rem 0.75rem;
    text-align: center;
  }

  .hud-inspect-btn {
    right: max(0.7rem, env(safe-area-inset-right));
    bottom: calc(max(1.1rem, env(safe-area-inset-bottom)) + 5.1rem);
    min-width: 64px;
    height: 64px;
    border-radius: 50%;
    padding: 0.3rem;
    font-size: 0.72rem;
    line-height: 1.15;
  }

  .hall-chat {
    left: max(0.5rem, env(safe-area-inset-left));
    right: max(0.5rem, env(safe-area-inset-right));
    bottom: max(0.5rem, env(safe-area-inset-bottom));
    width: auto;
    padding: 0.55rem 0.6rem 0.5rem;
  }

  .hall-chat-toggle {
    display: block;
  }

  .hall-chat--collapsed {
    left: max(0.5rem, env(safe-area-inset-left));
    right: auto;
    top: calc(max(0.45rem, env(safe-area-inset-top)) + 2.7rem);
    bottom: auto;
    width: auto;
    min-height: 40px;
    padding: 0.28rem 0.7rem;
    display: flex;
    align-items: center;
  }

  .hall-chat--collapsed .hall-chat-log,
  .hall-chat--collapsed .hall-chat-form,
  .hall-chat--collapsed .hall-chat-head .hall-chat-title {
    display: none;
  }

  .hall-chat--collapsed .hall-chat-head {
    margin-bottom: 0;
  }

  .hall-chat-log {
    min-height: 6.5rem;
    max-height: min(28vh, 10rem);
    font-size: 0.84rem;
  }

  .hall-chat-input,
  .entry-form input {
    font-size: 16px;
  }

  .inspect-overlay {
    padding: max(0.6rem, env(safe-area-inset-top)) 0.6rem max(0.6rem, env(safe-area-inset-bottom));
    align-items: flex-end;
  }

  .inspect-card {
    width: 100%;
    max-height: min(78dvh, 640px);
    padding: 1.2rem 1rem 1.1rem;
  }

  .inspect-title {
    font-size: 1.2rem;
  }

  .entry-form button {
    flex-shrink: 0;
  }

  .entry-form {
    min-width: 0;
    width: min(420px, calc(100vw - 1.4rem));
    margin: 0.7rem;
    padding: 1.2rem 1rem 1.1rem;
    max-height: none;
  }

  .entry-title {
    font-size: 1.2rem;
  }

  .entry-lead {
    font-size: 0.86rem;
  }
}

html.is-touch .hud-keys {
  display: none;
}

html.is-touch .hud-prompt {
  bottom: 9.4rem;
}

@media (max-width: 420px) {
  .minimap-canvas {
    width: 88px;
    height: 88px;
  }

  .hud-view-btn {
    top: calc(max(0.45rem, env(safe-area-inset-top)) + 7.25rem);
  }

  .hud-mic-btn {
    top: calc(max(0.45rem, env(safe-area-inset-top)) + 9.85rem);
  }

  .hud-tour-btn {
    top: calc(max(0.45rem, env(safe-area-inset-top)) + 12.45rem);
  }

  .mobile-joystick {
    width: 104px;
    height: 104px;
  }

  .hud-tour {
    right: 7.4rem;
  }
}

@media (max-height: 500px) and (orientation: landscape) {
  .minimap-canvas {
    width: 72px;
    height: 72px;
  }

  .minimap-zone {
    display: none;
  }

  .hud-view-btn,
  .hud-mic-btn,
  .hud-tour-btn {
    min-height: 34px;
    padding: 0.22rem 0.45rem;
  }

  .hud-view-btn {
    top: calc(max(0.3rem, env(safe-area-inset-top)) + 5.7rem);
    right: max(0.4rem, env(safe-area-inset-right));
  }

  .hud-mic-btn {
    top: calc(max(0.3rem, env(safe-area-inset-top)) + 7.85rem);
  }

  .hud-tour-btn {
    top: calc(max(0.3rem, env(safe-area-inset-top)) + 10rem);
  }

  .mobile-joystick {
    width: 88px;
    height: 88px;
  }

  .mobile-jump,
  .hud-inspect-btn {
    width: 52px;
    height: 52px;
  }

  .hud-inspect-btn {
    bottom: calc(max(0.6rem, env(safe-area-inset-bottom)) + 4.2rem);
  }

  .hud-prompt {
    bottom: 6.4rem;
    font-size: 0.76rem;
  }

  .hall-chat-log {
    min-height: 4.2rem;
    max-height: 5.5rem;
  }

  .hall-chat--collapsed {
    top: max(0.35rem, env(safe-area-inset-top));
    left: 8.5rem;
  }
}

html.chat-focused .hall-chat {
  top: max(0.45rem, env(safe-area-inset-top));
  bottom: auto;
  left: max(0.5rem, env(safe-area-inset-left));
  right: max(0.5rem, env(safe-area-inset-right));
  width: auto;
}
