/* Общие настройки страницы: запрещаем прокрутку и выделение, чтобы
   на телефоне игра не «уезжала» и не появлялись лупа и меню копирования. */
* {
  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%);
}

/* Вспышка при поимке и смерти: blood — кровь по краям, dark — темнота */
#scare-flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0;
}

#scare-flash.blood {
  background: radial-gradient(ellipse at center, rgba(90, 0, 0, 0.25) 20%, rgba(110, 0, 0, 0.9) 100%);
}

#scare-flash.dark {
  background: #000;
}

#scare-flash.short {
  animation: scare-flash 0.7s ease-out;
}

#scare-flash.long {
  animation: scare-flash 3s ease-in-out;
}

@keyframes scare-flash {
  0% { opacity: 0; }
  12% { opacity: 1; }
  100% { opacity: 0; }
}

/* Ложная поимка: экран заливает красным на секунду */
#scare-flash.grab {
  background: radial-gradient(ellipse at center, rgba(150, 0, 0, 0.55) 10%, rgba(70, 0, 0, 0.97) 90%);
  animation: scare-grab 1.1s ease-out;
}

/* Вспышка, в которой исчезает бабушка */
#scare-flash.white {
  background: #f4f0e6;
  animation: scare-flash 0.45s ease-out;
}

@keyframes scare-grab {
  0% { opacity: 0; }
  5% { opacity: 1; }
  70% { opacity: 0.9; }
  100% { opacity: 0; }
}

/* Скример во весь экран: лицо крупнее экрана и трясётся */
#scare-screen {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: #000;
  overflow: hidden;
  display: none;
  z-index: 5;
}

#scare-screen.on {
  display: block;
}

#scare-screen canvas {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 115vh;
  height: 115vh;
  image-rendering: pixelated;
  transform: translate(-50%, -50%);
}

#scare-screen.on canvas {
  animation: scare-screen 0.38s steps(8) forwards;
}

@keyframes scare-screen {
  0% { transform: translate(-50%, -50%) scale(0.8); }
  25% { transform: translate(-46%, -53%) scale(1.05); }
  50% { transform: translate(-54%, -48%) scale(1.15); }
  75% { transform: translate(-48%, -52%) scale(1.25); }
  100% { transform: translate(-51%, -49%) scale(1.35); }
}

#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-battery {
  position: absolute;
  left: calc(10px + env(safe-area-inset-left));
  top: calc(26px + env(safe-area-inset-top));
  width: 54px;
  height: 7px;
  padding: 1px;
  border: 1px solid rgba(217, 210, 197, 0.45);
}

#hud-battery-level {
  height: 100%;
  background: rgba(217, 210, 197, 0.7);
}

#hud-battery.low {
  border-color: rgba(200, 60, 60, 0.9);
}

#hud-battery.low #hud-battery-level {
  background: rgba(200, 60, 60, 0.9);
}

/* Значок шума: деления загораются по громкости */
#hud-noise {
  position: absolute;
  left: 50%;
  bottom: calc(14px + env(safe-area-inset-bottom));
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 22px;
  transform: translateX(-50%);
  opacity: 0;
  transition: opacity 0.4s;
}

#hud-noise.visible {
  opacity: 1;
  transition: opacity 0.05s;
}

#hud-noise span {
  width: 7px;
  background: rgba(217, 210, 197, 0.2);
}

#hud-noise span:nth-child(1) { height: 8px; }
#hud-noise span:nth-child(2) { height: 14px; }
#hud-noise span:nth-child(3) { height: 22px; }

#hud-noise.level-1 span:nth-child(1),
#hud-noise.level-2 span:nth-child(-n + 2) {
  background: #e8dfd0;
}

#hud-noise.level-3 span {
  background: #d23c3c;
}

/* Предмет в руках */
#hud-item {
  position: absolute;
  right: calc(16px + env(safe-area-inset-right));
  bottom: calc(14px + env(safe-area-inset-bottom));
  font-size: 15px;
  color: #e8dfd0;
  text-shadow: 0 0 4px #000, 0 0 2px #000;
}

body.touch #hud-item {
  right: auto;
  left: 50%;
  bottom: calc(44px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
}

/* Подсказка, что можно сделать с предметом перед игроком */
#hud-prompt {
  position: absolute;
  left: 50%;
  top: 58%;
  transform: translateX(-50%);
  max-width: 80%;
  font-size: 15px;
  text-align: center;
  color: #e8dfd0;
  text-shadow: 0 0 4px #000, 0 0 2px #000;
}

/* Вид из укрытия */
#hide-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

#hide-overlay.hide-wardrobe {
  background: repeating-linear-gradient(0deg, #080605 0 22px, transparent 22px 40px);
}

#hide-overlay.hide-bed {
  background: linear-gradient(180deg, #060504 0 70%, transparent 70% 96%, #060504 96%);
}

#hide-overlay.hide-stove {
  background: radial-gradient(ellipse 34% 26% at 50% 55%, transparent 90%, #050403 100%);
}

#hide-overlay.hide-barrel {
  background: radial-gradient(circle at 50% 42%, transparent 13%, #070504 15%);
}

/* Что случилось с игроком: пойман, сидит за столом, стал призраком */
#status-overlay {
  position: fixed;
  inset: 0;
  padding: 44px 16px 0;
  pointer-events: none;
  font-size: 19px;
  text-align: center;
  color: #e8dfd0;
  text-shadow: 0 0 4px #000, 0 0 2px #000;
}

#status-overlay.danger {
  box-shadow: inset 0 0 90px 24px rgba(120, 0, 0, 0.85);
}

/* Кот на голове: видно только узкую щель между лапами */
#status-overlay.blind {
  background: radial-gradient(ellipse 32% 14% at 50% 60%, rgba(40, 0, 0, 0.2) 40%, #050000 100%);
}

#status-overlay.ghost {
  background: rgba(70, 105, 150, 0.12);
  box-shadow: inset 0 0 120px 30px rgba(120, 160, 210, 0.3);
}

/* Полоска удержания кнопки */
#hold-progress {
  position: absolute;
  left: 50%;
  top: 64%;
  width: 180px;
  height: 8px;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid #3f3532;
}

#hold-progress-level {
  width: 0;
  height: 100%;
  background: #a31d1d;
}

/* Наушники Бибо слышат монстра за стеной */
#hud-sense {
  position: absolute;
  left: 50%;
  top: 14%;
  transform: translateX(-50%);
  pointer-events: none;
  font-size: 16px;
  color: #2fc4d6;
  text-shadow: 0 0 3px #000;
}

/* Вступительная сцена */
#intro {
  position: fixed;
  inset: 0;
  z-index: 30;
  pointer-events: none;
}

.intro-bar {
  position: absolute;
  left: 0;
  right: 0;
  height: 11vh;
  background: #000;
}

.intro-top {
  top: 0;
}

.intro-bottom {
  bottom: 0;
}

#intro-subtitle {
  position: absolute;
  left: 50%;
  bottom: calc(13vh + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(760px, 88vw);
  margin: 0;
  text-align: center;
  font-size: clamp(16px, 2.6vw, 24px);
  line-height: 1.4;
  color: #f0e6d6;
  text-shadow: 0 2px 4px #000, 0 0 12px #000;
}

#btn-skip-intro {
  position: absolute;
  right: calc(14px + env(safe-area-inset-right));
  bottom: calc(2vh + env(safe-area-inset-bottom));
  pointer-events: auto;
}

/* Роль в режиме «Предатель» и подсказка тайного действия */
#hud-role {
  position: absolute;
  left: 8px;
  top: calc(30px + env(safe-area-inset-top));
  max-width: 45%;
  pointer-events: none;
  white-space: pre-line;
  font-size: 13px;
  line-height: 1.4;
  color: #d9d2c5;
  text-shadow: 0 0 3px #000;
}

#hud-role.intro {
  max-width: 70%;
  font-size: 20px;
  color: #e0574a;
}

/* Голосование: справа, игра под ним продолжается */
#vote-panel {
  position: fixed;
  right: 8px;
  top: calc(56px + env(safe-area-inset-top));
  z-index: 20;
  width: min(300px, 46vw);
  max-height: 70vh;
  overflow-y: auto;
  padding: 10px;
  background: rgba(10, 8, 8, 0.88);
  border: 1px solid #3f3532;
  font-size: 14px;
}

#vote-title {
  margin-bottom: 8px;
  color: #d9d2c5;
}

#vote-list button,
#btn-vote-close {
  display: block;
  width: 100%;
  min-height: 40px;
  margin-bottom: 6px;
  text-align: left;
  background: #1b1716;
  border: 1px solid #3f3532;
}

#vote-list button.mine {
  background: #5e1212;
  border-color: #a31d1d;
}

#vote-list .voters {
  display: block;
  font-size: 11px;
  color: #8f877a;
}

#btn-vote-close {
  text-align: center;
}

/* Итог партии в лобби */
#lobby-result {
  margin: 0 0 14px;
  white-space: pre-line;
  font-size: 17px;
  color: #d94a3a;
}

/* Замок бани: отмычка бежит по положениям, нажимать надо на нужном */
#lock-hud {
  position: absolute;
  left: 50%;
  top: 22%;
  transform: translateX(-50%);
  pointer-events: none;
  text-align: center;
  color: #e8dfd0;
  text-shadow: 0 0 3px #000;
}

#lock-pins {
  margin-bottom: 6px;
  font-size: 15px;
}

#lock-cells {
  display: flex;
  gap: 6px;
}

#lock-cells span {
  width: 38px;
  height: 38px;
  line-height: 38px;
  font-size: 18px;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid #3f3532;
}

#lock-cells span.active {
  background: #a31d1d;
  border-color: #e8dfd0;
}

#code-input {
  display: block;
  width: 100%;
  margin: 0 0 12px;
  padding: 10px;
  font-size: 28px;
  letter-spacing: 6px;
  text-align: center;
}

#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;
}

/* ===== Главное меню ===== */

.screen-menu {
  background:
    radial-gradient(ellipse at 50% 35%, rgba(60, 8, 8, 0.25), transparent 60%),
    radial-gradient(ellipse at center, rgba(0, 0, 0, 0.35) 30%, rgba(0, 0, 0, 0.92) 100%);
}

/* Туман медленно ползёт по низу экрана */
.menu-fog {
  position: fixed;
  inset: auto -50% 0 -50%;
  height: 45%;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 30% 80%, rgba(150, 150, 160, 0.13), transparent 55%),
    radial-gradient(ellipse at 70% 90%, rgba(130, 130, 140, 0.1), transparent 60%);
  animation: fog-drift 40s linear infinite alternate;
}

@keyframes fog-drift {
  from { transform: translateX(-8%); }
  to { transform: translateX(8%); }
}

.menu-layout {
  position: relative;
  margin: auto;
  width: 100%;
  max-width: 440px;
  text-align: center;
}

.title-block {
  margin-bottom: 22px;
}

.game-title {
  margin: 0;
  font-family: "Ruslan Display", Georgia, serif;
  font-size: clamp(38px, 9vw, 60px);
  line-height: 1.05;
  letter-spacing: 2px;
  color: #b01e1e;
  text-shadow:
    0 0 12px rgba(176, 30, 30, 0.55),
    0 3px 0 #2a0505,
    0 0 40px rgba(0, 0, 0, 0.9);
  animation: title-flicker 7s infinite;
}

/* Изредка буквы гаснут, как старая неоновая вывеска */
@keyframes title-flicker {
  0%, 92%, 100% { opacity: 1; }
  93% { opacity: 0.35; }
  94% { opacity: 1; }
  96% { opacity: 0.6; }
  97% { opacity: 1; }
}

.game-subtitle {
  margin-top: 8px;
  font-size: 13px;
  letter-spacing: 6px;
  text-transform: uppercase;
  color: #8f877a;
}

.tagline {
  margin: 14px 0 0;
  font-style: italic;
  font-size: 15px;
  color: #b3aa9b;
}

.menu-card {
  padding: 18px;
  background: rgba(12, 9, 9, 0.78);
  border: 1px solid #3a2a26;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.8), inset 0 0 30px rgba(80, 10, 10, 0.12);
}

.menu-card > button,
.menu-settings > button,
.menu-settings .setting > button {
  display: block;
  width: 100%;
  min-height: 46px;
  margin: 0 0 8px;
  font-size: 17px;
}

button.primary,
.menu-card .primary {
  background: linear-gradient(#6e1515, #4a0d0d);
  border: 1px solid #b52222;
  color: #f0e6d6;
  letter-spacing: 1px;
  transition: background 0.2s, box-shadow 0.2s;
}

button.primary:hover:not(:disabled) {
  background: linear-gradient(#871a1a, #5a1010);
  box-shadow: 0 0 16px rgba(181, 34, 34, 0.45);
}

.big-button {
  min-height: 54px !important;
  font-size: 20px !important;
}

.ghost-button {
  min-height: 40px;
  padding: 6px 12px;
  background: rgba(27, 23, 22, 0.8);
  border: 1px solid #3f3532;
  color: #d9d2c5;
}

.ghost-button:hover:not(:disabled) {
  background: #2a2120;
}

.seats-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.seats-row .setting-title {
  margin: 0;
}

.stepper {
  display: flex;
  align-items: center;
  gap: 4px;
}

.stepper button {
  width: 40px;
  height: 40px;
  font-size: 22px;
  background: #1b1716;
  border: 1px solid #3f3532;
}

.stepper span {
  min-width: 36px;
  font-size: 22px;
  color: #f0e6d6;
}

.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0;
  font-size: 13px;
  color: #6f675c;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #3a2a26;
}

.menu-settings {
  margin-top: 14px;
  text-align: left;
}

.menu-settings summary {
  cursor: pointer;
  padding: 8px 0;
  color: #8f877a;
  text-align: center;
  list-style: none;
}

.menu-settings summary::after {
  content: ' ▾';
}

.menu-settings[open] summary::after {
  content: ' ▴';
}

.menu-version {
  margin-top: 14px;
  font-size: 12px;
  color: #5f574c;
}

/* ===== Лобби ===== */

#lobby {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

#lobby > * {
  pointer-events: auto;
}

/* Пока игрок выбирает внешность, игра за меню размыта */
body.editing #game {
  filter: blur(5px) brightness(0.7);
}

#lobby-top {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top));
  left: calc(10px + env(safe-area-inset-left));
  right: calc(10px + env(safe-area-inset-right));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
}

.room-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  background: rgba(12, 9, 9, 0.8);
  border: 1px solid #3a2a26;
  pointer-events: auto;
}

.chip-label {
  font-size: 12px;
  color: #8f877a;
  text-transform: uppercase;
  letter-spacing: 1px;
}

#lobby-code {
  font-family: "Courier New", monospace;
  font-size: 26px;
  font-weight: bold;
  letter-spacing: 5px;
  color: #f0e6d6;
}

#lobby-count {
  padding: 6px 10px;
  background: rgba(12, 9, 9, 0.8);
  border: 1px solid #3a2a26;
  font-size: 14px;
}

#lobby-result {
  position: absolute;
  top: calc(64px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  width: min(560px, 90vw);
  margin: 0;
  padding: 10px 14px;
  background: rgba(40, 6, 6, 0.85);
  border: 1px solid #7a1818;
  text-align: center;
}

.lobby-card {
  position: absolute;
  top: calc(64px + env(safe-area-inset-top));
  max-height: calc(100% - 74px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px;
  background: rgba(12, 9, 9, 0.88);
  border: 1px solid #3a2a26;
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.7);
}

.lobby-card h2 {
  margin: 0 0 10px;
  font-family: "Ruslan Display", Georgia, serif;
  font-size: 22px;
}

#editor {
  left: calc(10px + env(safe-area-inset-left));
  width: min(470px, 58vw);
}

#room-card {
  right: calc(10px + env(safe-area-inset-right));
  width: min(300px, 36vw);
}

.editor-body {
  display: flex;
  gap: 12px;
}

#look-preview {
  flex: none;
  width: 140px;
  height: 192px;
  background: radial-gradient(ellipse at 50% 40%, #2a1d18, #0a0706);
  border: 1px solid #3a2a26;
  image-rendering: pixelated;
}

.editor-fields {
  flex: 1;
  min-width: 0;
}

.editor-fields .field input {
  min-height: 38px;
}

.look-row {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 6px;
}

.look-row .look-label {
  flex: 0 0 34%;
  font-size: 13px;
  color: #8f877a;
}

.look-row button {
  flex: none;
  width: 32px;
  height: 32px;
  padding: 0;
  background: #1b1716;
  border: 1px solid #3f3532;
}

.look-row .look-value {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.swatch {
  flex: none;
  width: 14px;
  height: 14px;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

/* Голос: три звука, у каждого выбор, прослушивание и запись */
.voice-block {
  margin-top: 12px;
}

.voice-hint {
  font-size: 12px;
  color: #6f675c;
}

.voice-row .look-label {
  flex: 0 0 18%;
}

.voice-row .play-button,
.voice-row .record-button {
  width: auto;
  min-width: 36px;
  padding: 0 6px;
}

.voice-row .record-button {
  color: #e0574a;
}

.voice-row .record-button.recording {
  background: #5e1212;
  color: #f0e6d6;
}

#voice-message {
  margin: 6px 0 0;
  min-height: 1em;
}

/* Кнопки всегда видны внизу карточки, даже если поля пришлось листать */
.editor-buttons {
  position: sticky;
  bottom: -14px;
  display: flex;
  gap: 8px;
  margin: 12px -14px -14px;
  padding: 10px 14px;
  background: rgba(12, 9, 9, 0.97);
  border-top: 1px solid #3a2a26;
}

body.editing #lobby-result {
  display: none;
}

#lobby-result {
  cursor: pointer;
}

.editor-buttons button {
  flex: 1;
  min-height: 46px;
  font-size: 16px;
}

#room-card .ghost-button {
  width: 100%;
  margin-top: 14px;
}

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

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

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

#lobby-players .ready {
  color: #7fbf6a;
}

#lobby-players li.empty {
  color: #4f483f;
  font-style: italic;
}

/* Игрок готов: внизу полоса с главным */
#ready-bar {
  position: absolute;
  left: 50%;
  bottom: calc(14px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(520px, 92vw);
  padding: 12px 14px;
  background: rgba(12, 9, 9, 0.82);
  border: 1px solid #3a2a26;
  text-align: center;
}

#ready-text {
  margin-bottom: 10px;
  font-size: 16px;
}

.ready-buttons {
  display: flex;
  gap: 8px;
}

.ready-buttons button {
  flex: 1;
  min-height: 46px;
  font-size: 17px;
}

#lobby button:disabled {
  opacity: 0.45;
  cursor: default;
}

#ready-bar .hint {
  margin: 8px 0 0;
}

/* Отсчёт перед стартом */
#countdown {
  position: absolute;
  left: 50%;
  top: 40%;
  transform: translate(-50%, -50%);
  font-family: "Ruslan Display", Georgia, serif;
  font-size: 120px;
  color: #b01e1e;
  text-shadow: 0 0 30px rgba(176, 30, 30, 0.7), 0 4px 0 #2a0505;
  pointer-events: none;
}

/* Узкий экран (телефон стоя): карточки друг под другом */
@media (max-width: 640px) {
  #editor,
  #room-card {
    position: static;
    width: auto;
    max-height: none;
    margin: 8px;
  }

  body.editing #lobby {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    pointer-events: auto;
  }

  body.editing #lobby-top {
    position: static;
    flex-wrap: wrap;
    margin: calc(8px + env(safe-area-inset-top)) 8px 0;
  }

  .editor-body {
    flex-direction: column;
    align-items: center;
  }

  .editor-fields {
    width: 100%;
  }

  #look-preview {
    width: 110px;
    height: 150px;
  }
}

/* Низкий экран (телефон лёжа): всё мельче */
@media (max-height: 460px) {
  .lobby-card {
    top: calc(52px + env(safe-area-inset-top));
    max-height: calc(100% - 60px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    padding: 10px;
  }

  .editor-buttons {
    bottom: -10px;
    margin: 8px -10px -10px;
    padding: 8px 10px;
  }

  #look-preview {
    width: 100px;
    height: 138px;
  }

  .look-row {
    margin-top: 3px;
  }

  .look-row button {
    width: 28px;
    height: 28px;
  }

  #lobby-code {
    font-size: 20px;
  }

  .title-block {
    margin-bottom: 10px;
  }

  .tagline {
    display: none;
  }

  .game-title {
    font-size: 36px;
  }
}


/* Полоса о потере связи */
#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-apply {
  background: rgba(120, 24, 24, 0.55);
  border-color: rgba(220, 90, 70, 0.75);
  font-weight: bold;
}

/* Тайное действие предателя: тёмное, чтобы не бросалось в глаза соседу */
.tbtn-secret {
  background: rgba(40, 10, 30, 0.55);
  border-color: rgba(150, 60, 120, 0.6);
}

.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;
}
