/* Общие настройки страницы: запрещаем прокрутку и выделение, чтобы
   на телефоне игра не «уезжала» и не появлялись лупа и меню копирования. */
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: fixed;
  inset: 0;
  background: #000;
  color: #d9d2c5;
  font-family: Georgia, "Times New Roman", serif;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

[hidden] {
  display: none !important;
}

/* Игровое изображение: низкое разрешение растягивается на весь экран
   без сглаживания — так получается «пиксельный» вид PS1. */
#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  touch-action: none;
}

/* Затемнение по краям экрана */
#vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 45%, rgba(0, 0, 0, 0.75) 100%);
}

#crosshair {
  position: fixed;
  left: 50%;
  top: 50%;
  width: 3px;
  height: 3px;
  margin: -1px 0 0 -1px;
  background: rgba(230, 220, 200, 0.45);
  pointer-events: none;
  display: none;
}

body.playing #crosshair {
  display: block;
}

/* Подсказки поверх игры */
#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  font-family: "Courier New", monospace;
}

#hud-stats {
  position: absolute;
  left: calc(10px + env(safe-area-inset-left));
  top: calc(8px + env(safe-area-inset-top));
  font-size: 12px;
  color: rgba(217, 210, 197, 0.6);
}

#hud-toast {
  position: absolute;
  left: 50%;
  bottom: 18%;
  transform: translateX(-50%);
  max-width: 80%;
  padding: 6px 12px;
  background: rgba(0, 0, 0, 0.6);
  font-size: 14px;
  text-align: center;
  opacity: 0;
  transition: opacity 0.25s;
}

#hud-toast.visible {
  opacity: 1;
}

/* Экраны меню и паузы */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  background: rgba(0, 0, 0, 0.82);
}

.panel {
  margin: auto;
  width: 100%;
  max-width: 420px;
  text-align: center;
}

h1 {
  margin: 0 0 4px;
  font-size: 42px;
  font-weight: normal;
  letter-spacing: 2px;
  color: #a31d1d;
  text-shadow: 0 0 18px rgba(163, 29, 29, 0.6);
}

h2 {
  margin: 0 0 8px;
  font-size: 30px;
  font-weight: normal;
  color: #a31d1d;
}

.hint {
  margin: 0 0 16px;
  font-size: 14px;
  color: #8f877a;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.panel > button {
  display: block;
  width: 100%;
  min-height: 46px;
  margin: 0 0 8px;
  padding: 10px;
  font-size: 18px;
  background: #1b1716;
  border: 1px solid #3f3532;
}

.panel > button:hover {
  background: #2a2120;
}

.panel > button.primary {
  background: #5e1212;
  border-color: #a31d1d;
}

.panel > button.primary:hover {
  background: #7a1818;
}

.panel button:disabled {
  opacity: 0.5;
  cursor: default;
}

.setting {
  margin-top: 16px;
}

.setting-title {
  margin-bottom: 6px;
  font-size: 15px;
  color: #b3aa9b;
}

.segmented {
  display: flex;
  gap: 4px;
}

.segmented button {
  flex: 1;
  min-height: 42px;
  background: #1b1716;
  border: 1px solid #3f3532;
}

.segmented button.selected {
  background: #5e1212;
  border-color: #a31d1d;
}

input[type="range"] {
  width: 100%;
  height: 28px;
  accent-color: #a31d1d;
}

.help {
  margin-top: 16px;
  font-size: 13px;
  line-height: 1.5;
  color: #8f877a;
}

body:not(.touch) #help-touch,
body.touch #help-pc {
  display: none;
}

/* Поля ввода. Размер шрифта 16px не даёт iPhone приближать страницу при наборе. */
input[type="text"] {
  width: 100%;
  min-height: 46px;
  padding: 8px 10px;
  font: inherit;
  font-size: 16px;
  color: inherit;
  background: #0f0c0b;
  border: 1px solid #3f3532;
  border-radius: 0;
  -webkit-user-select: text;
  user-select: text;
}

input[type="text"]:focus {
  outline: 1px solid #a31d1d;
}

.field {
  display: block;
  margin-bottom: 10px;
}

.field .setting-title {
  display: block;
}

.join-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.join-row input {
  flex: 1;
  min-width: 0;
  text-align: center;
  letter-spacing: 3px;
}

.join-row button {
  flex: 0 0 104px;
  font-size: 18px;
  background: #1b1716;
  border: 1px solid #3f3532;
}

#notice-text {
  margin: 0 0 18px;
  font-size: 19px;
  line-height: 1.4;
  white-space: pre-line;
}

/* Лобби */
#lobby-code {
  margin-bottom: 10px;
  font-family: "Courier New", monospace;
  font-size: 46px;
  font-weight: bold;
  letter-spacing: 8px;
  color: #d9d2c5;
}

#lobby-players {
  list-style: none;
  margin: 0;
  padding: 0;
  text-align: left;
}

#lobby-players li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 10px;
  border-bottom: 1px solid #2a2321;
  font-size: 16px;
}

#lobby-players .role {
  flex: none;
  font-size: 13px;
  color: #8f877a;
}

#lobby .panel > button#btn-start {
  margin-top: 14px;
}

#lobby-hint {
  margin-top: 8px;
}

/* Полоса о потере связи */
#reconnecting {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  z-index: 50;
  padding: 8px;
  background: rgba(94, 18, 18, 0.92);
  text-align: center;
  font-size: 15px;
}

/* Управление на телефоне */
#touch-ui {
  position: fixed;
  inset: 0;
  touch-action: none;
}

#zone-move,
#zone-look {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
  touch-action: none;
}

#zone-move {
  left: 0;
}

#zone-look {
  right: 0;
}

#stick-base {
  position: absolute;
  left: 0;
  top: 0;
  width: 110px;
  height: 110px;
  margin: -55px 0 0 -55px;
  border-radius: 50%;
  border: 2px solid rgba(217, 210, 197, 0.25);
  background: rgba(0, 0, 0, 0.2);
  pointer-events: none;
}

#stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  border-radius: 50%;
  background: rgba(217, 210, 197, 0.35);
}

.tbtn {
  position: absolute;
  right: calc(var(--r) + env(safe-area-inset-right));
  bottom: calc(var(--b) + env(safe-area-inset-bottom));
  width: 58px;
  height: 58px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid rgba(217, 210, 197, 0.3);
  background: rgba(20, 16, 15, 0.45);
  color: rgba(230, 222, 208, 0.85);
  font-family: Arial, sans-serif;
  font-size: 12px;
  touch-action: none;
}

.tbtn-small {
  width: 50px;
  height: 50px;
  font-size: 10px;
}

.tbtn-top {
  top: calc(6px + env(safe-area-inset-top));
  bottom: auto;
}

.tbtn-main {
  width: 84px;
  height: 84px;
  font-size: 15px;
}

.tbtn.active {
  background: rgba(163, 29, 29, 0.6);
  border-color: rgba(220, 70, 70, 0.8);
}

#btn-menu {
  top: calc(6px + env(safe-area-inset-top));
  right: calc(8px + env(safe-area-inset-right));
  bottom: auto;
  width: 42px;
  height: 42px;
  font-size: 20px;
}

/* Просьба повернуть телефон: только на телефоне, в игре и в вертикальном положении */
#rotate-hint {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  font-size: 20px;
  background: #000;
}

.rotate-icon {
  font-size: 56px;
  margin-bottom: 8px;
  color: #a31d1d;
}

@media (orientation: portrait) {
  body.touch.playing #rotate-hint {
    display: flex;
  }
}

/* Сообщение об ошибке */
#error-box {
  position: fixed;
  left: 8px;
  right: 8px;
  bottom: 8px;
  z-index: 100;
  max-height: 50%;
  overflow: auto;
  padding: 10px;
  background: #400;
  border: 1px solid #f55;
  color: #fff;
  font-family: "Courier New", monospace;
  font-size: 13px;
  white-space: pre-wrap;
  -webkit-user-select: text;
  user-select: text;
}
