/* Полноэкранный flex: поле + боковая панель */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  min-height: 100%;
  overflow: hidden;
  font-family: system-ui, "Segoe UI", Roboto, sans-serif;
  background: #0d0d0f;
  color: #e8e6e3;
  overscroll-behavior: none;
}

:root {
  --ui-scale: 1;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --app-height: 100vh;
  --joystick-size: clamp(88px, 27vw, 120px);
  --menu-right-width: 86px;
}

@supports (height: 100dvh) {
  :root {
    --app-height: 100dvh;
  }
}

body.ui-contrast {
  filter: contrast(1.16) saturate(1.06);
}

body.ui-reduced-motion *,
body.ui-reduced-motion *::before,
body.ui-reduced-motion *::after {
  animation: none !important;
  transition: none !important;
}

.app-root {
  display: flex;
  flex-direction: row;
  width: 100%;
  min-height: 100vh;
  min-height: 100svh;
  height: var(--app-height);
  max-height: var(--app-height);
}

.game-area {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
  background: #111;
  touch-action: none;
  font-size: calc(16px * var(--ui-scale));
  overflow: hidden;
}

.mini-map {
  position: absolute;
  right: 12px;
  top: calc(var(--safe-top) + 12px);
  width: 180px;
  height: 120px;
  border: 1px solid rgba(200, 190, 170, 0.55);
  background: rgba(8, 8, 10, 0.7);
  border-radius: 8px;
  z-index: 6;
}

.event-feed {
  position: absolute;
  left: 50%;
  top: calc(var(--safe-top) + 16px);
  transform: translateX(-50%);
  z-index: 8;
  display: grid;
  gap: 6px;
  width: min(90vw, 360px);
  pointer-events: none;
}

.event-feed__item {
  justify-self: center;
  background: rgba(12, 12, 16, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  padding: 0.25rem 0.65rem;
  font-size: 0.78rem;
  color: #efe7d8;
}

.ingame-menu-btn {
  position: absolute;
  top: calc(var(--safe-top) + 10px);
  left: calc(var(--safe-left) + 10px);
  z-index: 7;
  border: 1px solid rgba(208, 200, 181, 0.45);
  border-radius: 8px;
  background: rgba(20, 20, 26, 0.78);
  color: #e8e6e3;
  padding: 0.35rem 0.62rem;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.1s ease;
  text-decoration: none;
  line-height: 1.1;
  min-height: 34px;
}

.ingame-menu-btn:hover {
  border-color: rgba(232, 168, 56, 0.75);
}

.ingame-menu-btn:active {
  transform: scale(0.98);
}

.ingame-menu-btn[hidden] {
  display: none !important;
}

#btn-back-to-games {
  z-index: 12;
}

.ingame-menu-btn--right {
  left: auto;
  right: calc(var(--safe-right) + 10px);
  z-index: 12;
  min-width: var(--menu-right-width);
  text-align: center;
}

.ingame-menu-btn--help {
  left: auto;
  right: calc(var(--safe-right) + var(--menu-right-width) + 18px);
  z-index: 12;
  width: 34px;
  padding-inline: 0;
  text-align: center;
}

/* Красное мерцание при критически низкой еде или воде (выживание) */
.vital-danger-overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  background: radial-gradient(
    ellipse 85% 75% at 50% 45%,
    rgba(220, 40, 30, 0.22) 0%,
    rgba(140, 0, 0, 0.55) 55%,
    rgba(90, 0, 0, 0.65) 100%
  );
  mix-blend-mode: multiply;
  animation: vital-danger-flicker 0.38s ease-in-out infinite alternate;
}

@keyframes vital-danger-flicker {
  from {
    opacity: 0.42;
  }
  to {
    opacity: 0.88;
  }
}

@media (prefers-reduced-motion: reduce) {
  .vital-danger-overlay {
    animation: none;
    opacity: 0.5;
  }
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.sidebar {
  flex: 0 0 88px;
  width: 88px;
  max-width: 14vw;
  min-height: 0;
  height: 100%;
  padding: 0.5rem 0.4rem 0.65rem;
  background: #16161a;
  border-left: 1px solid #2a2a32;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.35rem;
}

.sidebar[hidden] {
  display: none !important;
}

.sidebar__top {
  flex: 0 0 auto;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.hud-timer {
  font-variant-numeric: tabular-nums;
  font-size: clamp(0.85rem, 2.8vw, 1.05rem);
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #f4a020;
  line-height: 1.2;
}

.hud-steps {
  font-size: clamp(0.65rem, 2.2vw, 0.78rem);
  color: #b8b4ad;
  line-height: 1.25;
}

.hud-score {
  font-size: clamp(0.7rem, 2.4vw, 0.85rem);
  font-weight: 600;
  color: #f0c030;
  line-height: 1.25;
  font-variant-numeric: tabular-nums;
}

.sound-toggle {
  align-self: center;
  margin-top: 0.1rem;
  width: 34px;
  height: 30px;
  padding: 0;
  border-radius: 8px;
  border: 2px solid rgba(120, 118, 130, 0.45);
  background: linear-gradient(180deg, #3a3844, #2a2830);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  color: #e8e6e3;
}

.sound-toggle:hover {
  border-color: rgba(180, 175, 200, 0.5);
}

.sound-toggle:active {
  transform: scale(0.96);
}

.hud-survival {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  width: 100%;
}

/* Иначе display:flex перебивает атрибут hidden — UI выживания не скрывается */
.hud-survival[hidden],
.hud-survival-gear[hidden],
.hud-lives[hidden],
.vital-danger-overlay[hidden] {
  display: none !important;
}

.hud-lives {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  align-items: center;
  width: 100%;
}

.hud-lives__hearts {
  display: flex;
  flex-direction: row;
  gap: 4px;
  justify-content: center;
  font-size: 0.95rem;
  line-height: 1;
  letter-spacing: 0.02em;
}

.hud-lives__heart {
  display: inline-block;
  user-select: none;
}

.hud-lives__heart--on {
  color: #e45858;
  text-shadow: 0 0 6px rgba(228, 88, 88, 0.55);
}

.hud-lives__heart--half {
  color: #e45858;
  opacity: 0.58;
  text-shadow: 0 0 4px rgba(228, 88, 88, 0.35);
}

.hud-lives__heart--off {
  color: #3a3844;
  opacity: 0.55;
}

.vital {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  align-items: stretch;
}

.vital__label {
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #8a8680;
}

.vital__bar {
  height: 7px;
  border-radius: 4px;
  background: #2a2830;
  border: 1px solid #3a3844;
  overflow: hidden;
}

.vital__fill {
  height: 100%;
  width: 100%;
  transform-origin: left center;
  transform: scaleX(1);
  transition: transform 0.12s linear;
  border-radius: 3px;
}

.vital__fill--food {
  background: linear-gradient(90deg, #6b4420, #c4783a);
}

.vital__fill--water {
  background: linear-gradient(90deg, #1a5080, #3a9ecf);
}

.overlay-stats {
  width: 100%;
  max-width: 280px;
  margin: 0 auto 1.15rem;
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.88rem;
  text-align: left;
  font-variant-numeric: tabular-nums;
}

.endgame-vp {
  width: 100%;
  max-width: 440px;
  margin: 0 auto 0.65rem;
  border-radius: 12px;
  border: 1px solid rgba(232, 168, 56, 0.36);
  background: radial-gradient(circle at 15% 20%, rgba(232, 168, 56, 0.2), rgba(20, 20, 26, 0.95) 60%);
  padding: 0.65rem 0.7rem 0.72rem;
}

.endgame-vp__title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #c8b895;
}

.endgame-vp__value {
  margin-top: 0.08rem;
  font-size: clamp(1.25rem, 5.3vw, 1.7rem);
  font-weight: 800;
  color: #f0c87a;
  line-height: 1.1;
}

.endgame-vp__meta {
  margin-top: 0.15rem;
  font-size: 0.74rem;
  color: #b9b3a5;
}

#overlay-win .endgame-vp {
  border-color: rgba(232, 168, 56, 0.42);
  background: radial-gradient(circle at 15% 20%, rgba(232, 168, 56, 0.24), rgba(20, 20, 26, 0.95) 60%);
}

#overlay-win .endgame-vp__value {
  color: #f4d38f;
}

#overlay-win .endgame-card {
  border-color: rgba(232, 168, 56, 0.16);
  background: rgba(232, 168, 56, 0.06);
}

#overlay-lose .endgame-vp {
  border-color: rgba(196, 88, 88, 0.44);
  background: radial-gradient(circle at 15% 20%, rgba(196, 88, 88, 0.24), rgba(20, 20, 26, 0.95) 60%);
}

#overlay-lose .endgame-vp__title {
  color: #d0a4a4;
}

#overlay-lose .endgame-vp__value {
  color: #f0b3b3;
}

#overlay-lose .endgame-vp__meta {
  color: #c4a9a9;
}

#overlay-lose .endgame-card {
  border-color: rgba(196, 88, 88, 0.2);
  background: rgba(196, 88, 88, 0.07);
}

#overlay-lose .endgame-breakdown {
  border-color: rgba(196, 88, 88, 0.26);
  background: rgba(196, 88, 88, 0.05);
}

.endgame-cards {
  width: 100%;
  max-width: 440px;
  margin: 0 auto 0.65rem;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.38rem;
}

.endgame-card {
  display: grid;
  grid-template-columns: 1.1rem 1fr auto;
  align-items: center;
  gap: 0.35rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.03);
  padding: 0.33rem 0.42rem;
}

.endgame-card__icon {
  font-size: 0.85rem;
  text-align: center;
}

.endgame-card__label {
  font-size: 0.72rem;
  color: #b6b2aa;
  text-align: left;
}

.endgame-card__value {
  font-size: 0.78rem;
  color: #eae6dc;
  font-variant-numeric: tabular-nums;
}

.endgame-breakdown {
  width: 100%;
  max-width: 440px;
  margin: 0 auto 0.62rem;
  text-align: left;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 0.38rem 0.46rem;
  background: rgba(255, 255, 255, 0.02);
}

.endgame-breakdown summary {
  cursor: pointer;
  user-select: none;
  font-size: 0.8rem;
  color: #ddd6c7;
}

.endgame-breakdown .overlay-stats {
  margin: 0.45rem auto 0.1rem;
  max-width: none;
  background: rgba(0, 0, 0, 0.2);
}

.overlay-stats__row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.32rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.overlay-stats__row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.overlay-stats__k {
  color: #9a9690;
  flex-shrink: 0;
}

.overlay-stats__v {
  color: #e8e6e3;
  font-weight: 600;
  text-align: right;
}

.hud-keys {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  align-items: center;
  min-height: 12px;
}

/* Силуэт ключа (как на поле): круг + стержень с бородкой */
.hud-key-dot {
  width: 16px;
  height: 11px;
  border: none;
  border-radius: 0;
  flex-shrink: 0;
  background-color: var(--key-color, #888);
  opacity: 0.42;
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 16'%3E%3Ccircle fill='%23fff' cx='8.5' cy='8' r='5'/%3E%3Cpath fill='%23fff' d='M13 5.8h14.2v1.3h1.5v4.8h-1.5V11h-6.5v2.2h-2V5.8zm8.5 1h2.3v2.4h-2.3z'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 16'%3E%3Ccircle fill='%23fff' cx='8.5' cy='8' r='5'/%3E%3Cpath fill='%23fff' d='M13 5.8h14.2v1.3h1.5v4.8h-1.5V11h-6.5v2.2h-2V5.8zm8.5 1h2.3v2.4h-2.3z'/%3E%3C/svg%3E");
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
}

.hud-key-dot--held {
  opacity: 1;
  filter: drop-shadow(0 0 4px color-mix(in srgb, var(--key-color) 75%, transparent));
}

/* Вертикальный факел на всю высоту панели */
.torch-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  justify-content: center;
  align-items: stretch;
  padding: 0.2rem 0;
}

.torch-device {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  flex: 1 1 auto;
  min-height: 48px;
  width: min(36px, 82%);
}

/* Мягкое свечение снаружи (мерцание) */
.torch-aura {
  position: absolute;
  left: 50%;
  bottom: 18px;
  width: 48px;
  height: 65%;
  transform: translateX(-50%);
  border-radius: 50% 50% 45% 45%;
  background: radial-gradient(
    ellipse 55% 70% at 50% 100%,
    rgba(255, 140, 40, 0.45) 0%,
    rgba(255, 90, 20, 0.12) 45%,
    transparent 70%
  );
  filter: blur(6px);
  pointer-events: none;
  z-index: 0;
  animation: torch-aura-pulse 1.8s ease-in-out infinite;
}

@keyframes torch-aura-pulse {
  0%,
  100% {
    opacity: 0.55;
    transform: translateX(-50%) scale(1, 1);
  }
  33% {
    opacity: 0.85;
    transform: translateX(-50%) scale(1.06, 1.04);
  }
  55% {
    opacity: 0.65;
    transform: translateX(-50%) scale(0.96, 1.02);
  }
}

/* Корпус факела: обмотка + углубление под «огонь» */
.torch-bar {
  position: relative;
  z-index: 1;
  width: 100%;
  flex: 1 1 auto;
  min-height: 40px;
  border-radius: 10px 10px 4px 4px;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.35) 0%, transparent 22%, transparent 78%, rgba(0, 0, 0, 0.35) 100%),
    repeating-linear-gradient(
      -28deg,
      #3a2e22 0px,
      #3a2e22 3px,
      #2d241c 3px,
      #2d241c 6px
    );
  border: 1px solid #1a1510;
  box-shadow:
    inset 0 2px 6px rgba(0, 0, 0, 0.55),
    inset 0 -1px 0 rgba(255, 200, 120, 0.06),
    0 0 0 1px rgba(60, 48, 36, 0.9);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.torch-bar__fill {
  position: relative;
  width: 100%;
  height: 100%;
  transform-origin: bottom center;
  transform: scaleY(1);
  transition: transform 0.15s linear;
  border-radius: 8px 8px 2px 2px;
  background:
    linear-gradient(
      180deg,
      #fff8e0 0%,
      #ffe566 12%,
      #ffcc33 28%,
      #ff8c1a 52%,
      #e04d18 78%,
      #6b2010 100%
    );
  box-shadow:
    inset 0 -6px 14px rgba(255, 80, 20, 0.5),
    inset 0 4px 10px rgba(255, 255, 255, 0.35);
  filter: saturate(1.15);
  animation: torch-body-flicker 0.45s ease-in-out infinite alternate;
}

@keyframes torch-body-flicker {
  0% {
    filter: saturate(1.1) brightness(0.98);
  }
  100% {
    filter: saturate(1.25) brightness(1.08);
  }
}

@media (prefers-reduced-motion: reduce) {
  .torch-aura,
  .torch-bar__fill,
  .torch-flame--a,
  .torch-flame--b,
  .torch-flame--c {
    animation: none;
  }

  .torch-aura {
    opacity: 0.55;
  }
}

/* Слои языков пламени */
.torch-flame {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 140%;
  height: 100%;
  margin-left: -70%;
  pointer-events: none;
  border-radius: 50% 50% 40% 40% / 70% 70% 30% 30%;
  mix-blend-mode: screen;
  opacity: 0.65;
}

.torch-flame--a {
  background: radial-gradient(ellipse 50% 85% at 50% 100%, rgba(255, 255, 255, 0.95) 0%, rgba(255, 220, 80, 0.4) 35%, transparent 62%);
  animation: torch-tongue-a 0.35s ease-in-out infinite alternate;
}

.torch-flame--b {
  background: radial-gradient(ellipse 45% 75% at 48% 100%, rgba(255, 180, 60, 0.9) 0%, rgba(255, 100, 30, 0.35) 40%, transparent 65%);
  animation: torch-tongue-b 0.42s ease-in-out infinite alternate;
  animation-delay: -0.12s;
}

.torch-flame--c {
  width: 110%;
  margin-left: -55%;
  background: radial-gradient(ellipse 40% 60% at 52% 100%, rgba(255, 240, 200, 0.55) 0%, transparent 55%);
  animation: torch-tongue-c 0.28s ease-in-out infinite alternate;
  animation-delay: -0.2s;
}

@keyframes torch-tongue-a {
  0% {
    opacity: 0.5;
    transform: translateX(-2px) scale(1, 1);
  }
  100% {
    opacity: 0.85;
    transform: translateX(2px) scale(1.04, 1.02);
  }
}

@keyframes torch-tongue-b {
  0% {
    opacity: 0.45;
    transform: translateX(3px) scale(0.98, 1.03);
  }
  100% {
    opacity: 0.75;
    transform: translateX(-3px) scale(1.02, 0.98);
  }
}

@keyframes torch-tongue-c {
  0% {
    opacity: 0.35;
    transform: scale(1.06, 1.05);
  }
  100% {
    opacity: 0.65;
    transform: scale(0.94, 0.97);
  }
}

/* Деревянная рукоять */
.torch-handle {
  flex: 0 0 auto;
  width: 72%;
  height: 14px;
  margin-top: 2px;
  border-radius: 0 0 8px 8px;
  background: linear-gradient(90deg, #1f1812 0%, #4a3828 35%, #5c4432 50%, #3d2e22 65%, #1a1410 100%);
  box-shadow:
    inset 0 2px 3px rgba(0, 0, 0, 0.5),
    0 2px 4px rgba(0, 0, 0, 0.4);
  border: 1px solid #0f0c0a;
  border-top: none;
  z-index: 1;
}

/* Оверлеи */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 8, 10, 0.82);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 10;
  touch-action: pan-y;
  padding: calc(var(--safe-top) + 8px) calc(var(--safe-right) + 8px) calc(var(--safe-bottom) + 8px) calc(var(--safe-left) + 8px);
}

.overlay--visible {
  opacity: 1;
  pointer-events: auto;
}

.overlay__panel {
  text-align: center;
  padding: 2rem 2.5rem;
  border-radius: 12px;
  background: #1c1c22;
  border: 1px solid #353540;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  max-width: 90%;
  max-height: calc(var(--app-height) - var(--safe-top) - var(--safe-bottom) - 16px);
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.overlay__panel--endgame {
  width: min(560px, 94vw);
  max-height: calc(var(--app-height) - var(--safe-top) - var(--safe-bottom) - 16px);
  overflow: auto;
  padding: 1.1rem 0.9rem 0.95rem;
}

#overlay-win .overlay__panel--endgame {
  border-color: rgba(232, 168, 56, 0.45);
  box-shadow:
    0 14px 42px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(232, 168, 56, 0.18);
  background:
    radial-gradient(circle at 12% 12%, rgba(232, 168, 56, 0.14), transparent 42%),
    linear-gradient(180deg, #201c16, #17171d);
}

#overlay-lose .overlay__panel--endgame {
  border-color: rgba(196, 88, 88, 0.45);
  box-shadow:
    0 14px 42px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(196, 88, 88, 0.2);
  background:
    radial-gradient(circle at 14% 14%, rgba(190, 72, 72, 0.16), transparent 42%),
    linear-gradient(180deg, #231819, #17171d);
}

.overlay__panel--menu {
  max-width: min(1040px, 96vw);
  max-height: calc(var(--app-height) - var(--safe-top) - var(--safe-bottom) - 16px);
  padding: 1.35rem 1rem 1.5rem;
}

.overlay__panel--settings {
  position: relative;
  width: min(560px, 94vw);
  max-height: calc(var(--app-height) - var(--safe-top) - var(--safe-bottom) - 16px);
  overflow: auto;
  text-align: left;
  padding: 1.25rem 1rem 1rem;
}

.modal-close-x {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid rgba(210, 206, 198, 0.35);
  background: rgba(18, 18, 24, 0.78);
  color: #e8e6e3;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}

.modal-close-x:hover {
  border-color: rgba(232, 168, 56, 0.75);
}

.overlay__btn--centered {
  display: block;
  margin-left: auto;
  margin-right: auto;
}

@media (min-width: 720px) {
  .overlay__panel--menu {
    padding: 1.75rem 1.75rem 2rem;
  }
}

.overlay__title {
  margin: 0 0 1.25rem;
  font-size: clamp(1.5rem, 5vw, 2rem);
  font-weight: 700;
}

.overlay__title--menu {
  margin-bottom: 0.35rem;
}

.menu-survival {
  margin: 0 auto 0.85rem;
  max-width: 420px;
  text-align: left;
}

.menu-survival--off {
  margin-bottom: 0.85rem;
}

.menu-survival__hint {
  margin: 0.4rem 0 0;
  padding-left: 3.1rem;
  font-size: 0.72rem;
  line-height: 1.25;
  color: #7a7670;
  white-space: normal;
  overflow-wrap: anywhere;
  min-height: 0.9rem;
}

.menu-survival--off .menu-survival__hint {
  visibility: hidden;
}

.toggle-switch {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.65rem;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.toggle-switch__input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.toggle-switch__track {
  position: relative;
  flex-shrink: 0;
  width: 44px;
  height: 24px;
  border-radius: 12px;
  background: #3a3842;
  border: 1px solid #4a4855;
  transition:
    background 0.2s ease,
    border-color 0.2s ease;
}

.toggle-switch__track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #c8c4bc;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  transition: transform 0.2s ease;
}

.toggle-switch__input:checked + .toggle-switch__track {
  background: linear-gradient(180deg, #6b4420, #4a2e18);
  border-color: #c48830;
}

.toggle-switch__input:checked + .toggle-switch__track::after {
  transform: translateX(20px);
  background: #f4d080;
}

.toggle-switch__input:focus-visible + .toggle-switch__track {
  box-shadow: 0 0 0 2px rgba(232, 168, 56, 0.45);
}

.toggle-switch__text {
  font-size: 0.95rem;
  font-weight: 600;
  color: #e8e6e3;
}

.overlay__lead {
  margin: 0 0 1.1rem;
  font-size: 0.82rem;
  color: #8a8680;
  line-height: 1.4;
}

.menu-run-config {
  display: grid;
  gap: 0.5rem;
  margin: 0 auto 0.75rem;
  max-width: 420px;
  text-align: left;
}

.menu-run-config__row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.menu-field {
  display: grid;
  gap: 0.25rem;
  font-size: 0.8rem;
  color: #b8b4ac;
}

.menu-input {
  width: 100%;
  border-radius: 8px;
  border: 1px solid #4e4a44;
  background: #111216;
  color: #e8e6e3;
  padding: 0.45rem 0.55rem;
  font: inherit;
}

.menu-btn-small {
  padding: 0.45rem 0.75rem;
  font-size: 0.82rem;
}

.menu-help {
  margin: 0 auto 0.75rem;
  max-width: 420px;
  text-align: left;
  border: 1px solid #32323a;
  border-radius: 8px;
  padding: 0.45rem 0.55rem;
  color: #b8b4ac;
}

.menu-help summary {
  cursor: pointer;
  color: #d8d2c8;
}

.menu-help ul {
  margin: 0.45rem 0 0;
  padding-left: 1rem;
  font-size: 0.78rem;
  line-height: 1.35;
}

.help-cards {
  display: grid;
  gap: 0.45rem;
  margin-top: 0.55rem;
}

.help-card {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 0.55rem;
  align-items: start;
  padding: 0.35rem 0.4rem;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
}

.help-card__icon {
  width: 34px;
  height: 34px;
  margin-top: 2px;
  pointer-events: none;
}

.help-card__text strong {
  display: block;
  font-size: 0.8rem;
  line-height: 1.2;
  color: #e8e6e3;
}

.help-card__text p {
  margin: 0.2rem 0 0;
  font-size: 0.75rem;
  line-height: 1.32;
  color: #b8b4ac;
}

.help-card__icon--trap {
  border-radius: 8px;
  border: 1px solid rgba(120, 118, 130, 0.5);
  background: rgba(24, 24, 30, 0.88);
  position: relative;
}

.help-card__icon--spike::before {
  content: '';
  position: absolute;
  left: 7px;
  top: 8px;
  width: 18px;
  height: 16px;
  background: #b94a4a;
  clip-path: polygon(10% 100%, 32% 20%, 50% 100%, 68% 20%, 90% 100%);
}

.help-card__icon--mud::before {
  content: '';
  position: absolute;
  left: 6px;
  top: 12px;
  width: 20px;
  height: 12px;
  border-radius: 50%;
  background: rgba(108, 79, 46, 0.9);
  border: 1px solid rgba(52, 35, 18, 0.9);
}

.help-card__icon--enemy {
  display: grid;
  place-items: center;
  border-radius: 8px;
  border: 1px solid rgba(200, 110, 120, 0.4);
  background: linear-gradient(145deg, #4a1f24, #6b3038);
  font-size: 1.1rem;
}

.menu-accessibility {
  margin: 0 auto 0.75rem;
  max-width: 420px;
  display: grid;
  gap: 0.5rem;
  text-align: left;
}

.choice-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.6rem;
}

@media (min-width: 720px) {
  .choice-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.choice-grid .diff-card {
  min-height: 100px;
}

.diff-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.65rem;
  width: 100%;
  text-align: left;
  margin-bottom: 1rem;
}

@media (min-width: 640px) {
  .diff-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
    align-items: stretch;
  }
}

.diff-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  margin: 0;
  padding: 0.85rem 1rem 1rem;
  cursor: pointer;
  font: inherit;
  color: #e8e6e3;
  text-align: left;
  border-radius: 10px;
  border: 1px solid #3a3a44;
  background: linear-gradient(165deg, #24242c 0%, #1a1a20 100%);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  transition:
    border-color 0.18s ease,
    box-shadow 0.18s ease,
    transform 0.12s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.diff-card:hover {
  border-color: #5a5548;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
}

.diff-card:focus {
  outline: none;
}

.diff-card:focus-visible {
  border-color: #e8a838;
  box-shadow: 0 0 0 2px rgba(232, 168, 56, 0.45);
}

.diff-card:active {
  transform: scale(0.99);
}

.diff-card--easy {
  border-top: 3px solid #5cb88a;
}

.diff-card--medium {
  border-top: 3px solid #e8a838;
}

.diff-card--hard {
  border-top: 3px solid #c75c5c;
}

.diff-card__label {
  display: block;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  margin-bottom: 0.15rem;
}

.diff-card__hook {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: #a8a49c;
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.diff-card__list {
  margin: 0;
  padding: 0 0 0 1.1rem;
  font-size: 0.78rem;
  line-height: 1.45;
  color: #b8b4ac;
}

.diff-card__list li {
  margin-bottom: 0.28rem;
}

.diff-card__list li:last-child {
  margin-bottom: 0;
}

.menu-top {
  margin-top: 0.35rem;
  border-top: 1px solid #32323a;
  padding-top: 0.8rem;
  text-align: left;
}

.menu-top__title {
  margin: 0 0 0.45rem;
  font-size: 0.9rem;
  color: #e8e6e3;
  letter-spacing: 0.01em;
}

.menu-top-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.55rem;
}

@media (min-width: 720px) {
  .menu-top-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.menu-top-col {
  border: 1px solid #34343c;
  border-radius: 8px;
  padding: 0.42rem;
  background: rgba(255, 255, 255, 0.02);
}

.menu-top-col__title {
  margin: 0 0 0.35rem;
  font-size: 0.78rem;
  font-weight: 700;
  color: #d5d0c7;
}

.menu-top__state {
  margin: 0;
  font-size: 0.78rem;
  color: #9e9a92;
}

.menu-top__list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.3rem;
}

.menu-top__item {
  display: grid;
  grid-template-columns: 1.45rem 1.35rem 1fr auto;
  gap: 0.35rem;
  align-items: center;
  padding: 0.24rem 0.35rem;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.02);
}

.menu-top__rank {
  color: #d0c29d;
  font-weight: 700;
  font-size: 0.76rem;
}

.menu-top__badge {
  width: 1.35rem;
  text-align: center;
  font-size: 0.8rem;
}

.menu-top__badge--won {
  color: #d7bb6b;
}

.menu-top__badge--lost {
  color: #c68686;
}

.menu-top__name {
  color: #e8e6e3;
  font-size: 0.74rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.menu-top__meta {
  font-size: 0.7rem;
  color: #aba79f;
}

.overlay__btn {
  cursor: pointer;
  padding: 0.65rem 1.75rem;
  font-size: 1rem;
  font-weight: 600;
  color: #111;
  background: #e8a838;
  border: none;
  border-radius: 8px;
  transition: filter 0.15s ease, transform 0.1s ease;
}

.overlay__btn:hover {
  filter: brightness(1.08);
}

.overlay__btn:active {
  transform: scale(0.98);
}

.overlay__btn--menu {
  margin-top: 0.45rem;
  background: #5a5f73;
  color: #f2f2f2;
}

.overlay__panel--pause {
  width: min(420px, 92vw);
  padding: 1.4rem 1rem 1.1rem;
  max-height: calc(var(--app-height) - var(--safe-top) - var(--safe-bottom) - 16px);
  overflow-y: auto;
}

.pause-actions {
  display: grid;
  gap: 0.55rem;
}

.pause-actions__btn {
  width: 100%;
}

.pause-actions__btn--back {
  margin-top: 0.2rem;
  background: #5a5f73;
  color: #f2f2f2;
}

.name-entry {
  margin: 0 auto 1rem;
  width: min(460px, 100%);
  text-align: left;
}

.name-entry__result {
  margin: 0 0 0.7rem;
  color: #b8b4ac;
  font-size: 0.84rem;
  line-height: 1.45;
}

.name-entry__label {
  display: block;
  margin-bottom: 0.35rem;
  color: #e8e6e3;
  font-size: 0.85rem;
}

.name-entry__input {
  width: 100%;
  min-width: 0;
  border-radius: 8px;
  border: 1px solid #4e4a44;
  background: #111216;
  color: #e8e6e3;
  font: inherit;
  padding: 0.55rem 0.65rem;
}

.name-entry__input:focus-visible {
  outline: none;
  border-color: #e8a838;
  box-shadow: 0 0 0 2px rgba(232, 168, 56, 0.3);
}

/* Руки + сумка: внизу слева, на уровне джойстика */
.hud-survival-gear {
  position: absolute;
  left: calc(var(--safe-left) + 12px);
  bottom: calc(var(--safe-bottom) + 12px);
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  max-width: calc(100% - var(--joystick-size) - 42px - var(--safe-right));
  pointer-events: none;
}

.hud-role {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 0.34rem;
  padding: 0.24rem 0.42rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(14, 14, 18, 0.8);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.hud-role[hidden] {
  display: none !important;
}

.hud-role__figure {
  display: inline-grid;
  place-items: center;
  width: 1.26rem;
  height: 1.26rem;
  border-radius: 50%;
  font-size: 0.78rem;
  background: rgba(255, 255, 255, 0.07);
}

.hud-role__name {
  font-size: 0.7rem;
  font-weight: 700;
  color: #ded7c8;
  letter-spacing: 0.02em;
}

.hud-role--warrior .hud-role__figure {
  background: linear-gradient(145deg, rgba(122, 88, 38, 0.78), rgba(204, 150, 64, 0.58));
}

.hud-role--thief .hud-role__figure {
  background: linear-gradient(145deg, rgba(64, 94, 118, 0.78), rgba(88, 140, 180, 0.58));
}

.hud-role--mage .hud-role__figure {
  background: linear-gradient(145deg, rgba(98, 72, 126, 0.78), rgba(164, 112, 208, 0.58));
}

.hud-hands-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

.hud-hands {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  gap: 6px;
  pointer-events: auto;
}

.hand-slot {
  position: relative;
  flex: 0 0 auto;
  width: clamp(30px, 8vw, 42px);
  height: clamp(30px, 8vw, 42px);
  border-radius: 10px;
  border: 2px solid rgba(120, 118, 130, 0.45);
  box-sizing: border-box;
  transition: border-color 0.12s ease, transform 0.08s ease;
}

.hand-slot__durability {
  position: absolute;
  left: 50%;
  bottom: 2px;
  transform: translateX(-50%);
  font-size: 0.5rem;
  line-height: 1;
  letter-spacing: 0.08em;
  color: #f2e6c8;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.85);
  pointer-events: none;
}

.hand-slot--empty {
  background: rgba(28, 28, 34, 0.78);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  background-image: repeating-linear-gradient(
    -45deg,
    transparent,
    transparent 3px,
    rgba(255, 255, 255, 0.04) 3px,
    rgba(255, 255, 255, 0.04) 5px
  );
}

.hand-slot--stick,
.hand-slot--sword,
.hand-slot--axe,
.hand-slot--shield,
.hand-slot--tool {
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.hand-slot--stick:active,
.hand-slot--sword:active,
.hand-slot--axe:active,
.hand-slot--shield:active,
.hand-slot--tool:active {
  transform: scale(0.94);
}

.hand-slot--stick {
  background: linear-gradient(145deg, #4a3518, #7a5530);
  border-color: rgba(180, 130, 70, 0.5);
}

.hand-slot--stick::after {
  content: '';
  display: block;
  width: 18%;
  height: 62%;
  margin: 16% auto 0;
  border-radius: 2px;
  background: linear-gradient(180deg, #8a6640, #5a4020);
  transform: rotate(-18deg);
}

.hand-slot--sword {
  background: linear-gradient(145deg, #3a3d48, #5a5e6a);
  border-color: rgba(180, 190, 210, 0.45);
}

.hand-slot--sword::after {
  content: '';
  display: block;
  width: 22%;
  height: 58%;
  margin: 10% auto 0;
  background: linear-gradient(160deg, #d0d4dc, #808890);
  clip-path: polygon(50% 0%, 85% 88%, 50% 78%, 15% 88%);
}

.hand-slot--axe {
  background: linear-gradient(145deg, #3a3835, #5a5650);
  border-color: rgba(140, 135, 125, 0.5);
}

.hand-slot--axe::after {
  content: '';
  display: block;
  width: 70%;
  height: 55%;
  margin: 8% auto 0;
  background: linear-gradient(105deg, #9a9ca5 35%, #5a5248 35%);
  clip-path: polygon(8% 40%, 55% 25%, 92% 35%, 70% 100%, 35% 95%, 25% 55%);
}

.hand-slot--shield {
  background: linear-gradient(145deg, #3a3c42, #52565e);
  border-color: rgba(160, 165, 175, 0.45);
}

.hand-slot--shield::after {
  content: '';
  display: block;
  width: 56%;
  height: 68%;
  margin: 12% auto 0;
  border-radius: 50%;
  background: radial-gradient(
    circle at 32% 28%,
    #e4e8ec 0%,
    #9ca2ac 38%,
    #5c6068 72%,
    #2e3036 100%
  );
  box-shadow:
    inset 0 0 0 2px rgba(0, 0, 0, 0.28),
    inset -3px -4px 8px rgba(0, 0, 0, 0.25);
}

.hand-slot--tool {
  background: linear-gradient(145deg, #354452, #556779);
  border-color: rgba(130, 170, 205, 0.5);
}

.hand-slot--tool::after {
  content: '';
  display: block;
  width: 22%;
  height: 62%;
  margin: 14% auto 0;
  border-radius: 2px;
  background: linear-gradient(180deg, #c8d6e4, #7c8f9f);
  transform: rotate(-22deg);
  box-shadow: 0 -6px 0 -4px rgba(210, 230, 245, 0.8);
}

.hud-inventory__label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #9a9690;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}

.hud-inventory__slots {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  gap: 5px;
  pointer-events: auto;
}

.inv-slot {
  position: relative;
  flex: 0 0 auto;
  width: clamp(28px, 7.5vw, 38px);
  height: clamp(28px, 7.5vw, 38px);
  border-radius: 8px;
  border: 2px solid rgba(120, 118, 130, 0.45);
  box-sizing: border-box;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.inv-slot__count {
  position: absolute;
  right: 2px;
  bottom: 2px;
  z-index: 2;
  min-width: 13px;
  padding: 0 3px;
  font-size: 0.62rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
  text-align: center;
  color: #f8f6f2;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.85);
  background: rgba(12, 12, 16, 0.72);
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  pointer-events: none;
}

.inv-slot--empty {
  background: rgba(32, 32, 38, 0.72);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.inv-slot--food,
.inv-slot--water,
.inv-slot--medkit {
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.inv-slot--food {
  background: linear-gradient(145deg, #5a3818, #9a5a28);
  border-color: rgba(200, 140, 80, 0.55);
  box-shadow:
    inset 0 1px 0 rgba(255, 200, 140, 0.15),
    0 2px 8px rgba(0, 0, 0, 0.35);
}

.inv-slot--food::after {
  content: '';
  display: block;
  width: 55%;
  height: 42%;
  margin: 28% auto 0;
  border-radius: 3px;
  background: rgba(220, 170, 100, 0.55);
}

.inv-slot--water {
  background: linear-gradient(145deg, #153a5c, #256898);
  border-color: rgba(90, 160, 220, 0.5);
  box-shadow:
    inset 0 1px 0 rgba(180, 220, 255, 0.12),
    0 2px 8px rgba(0, 0, 0, 0.35);
}

.inv-slot--water::after {
  content: '';
  display: block;
  width: 46%;
  height: 52%;
  margin: 22% auto 0;
  border-radius: 50% 50% 45% 45%;
  background: linear-gradient(180deg, rgba(180, 230, 255, 0.45), rgba(80, 140, 200, 0.35));
}

.inv-slot--medkit {
  background: linear-gradient(145deg, #6a1e1e, #b33a3a);
  border-color: rgba(220, 110, 110, 0.55);
  box-shadow:
    inset 0 1px 0 rgba(255, 185, 185, 0.16),
    0 2px 8px rgba(0, 0, 0, 0.35);
}

.inv-slot--medkit::after {
  content: '';
  display: block;
  width: 52%;
  height: 52%;
  margin: 24% auto 0;
  background:
    linear-gradient(90deg, transparent 38%, rgba(245, 240, 236, 0.92) 38%, rgba(245, 240, 236, 0.92) 62%, transparent 62%),
    linear-gradient(180deg, transparent 38%, rgba(245, 240, 236, 0.92) 38%, rgba(245, 240, 236, 0.92) 62%, transparent 62%);
}

/* Джойстик: зона внизу справа */
.joystick-zone {
  position: absolute;
  right: calc(var(--safe-right) + 12px);
  bottom: calc(var(--safe-bottom) + 12px);
  width: var(--joystick-size);
  height: var(--joystick-size);
  z-index: 5;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.joystick-base {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(40, 40, 48, 0.65);
  border: 2px solid rgba(120, 118, 130, 0.5);
}

.joystick-knob {
  position: absolute;
  width: 44px;
  height: 44px;
  margin-left: -22px;
  margin-top: -22px;
  left: 50%;
  top: 50%;
  border-radius: 50%;
  background: rgba(232, 168, 56, 0.9);
  border: 2px solid rgba(255, 255, 255, 0.35);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

@media (max-width: 600px) {
  .app-root {
    flex-direction: column;
  }

  .sidebar {
    flex: 0 0 auto;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: stretch;
    width: 100%;
    max-width: none;
    height: auto;
    min-height: 112px;
    max-height: min(35dvh, 210px);
    border-left: none;
    border-top: 1px solid #2a2a32;
    padding: 0.45rem 0.5rem;
    gap: 0.5rem;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .sidebar__top {
    flex: 0 0 auto;
    justify-content: center;
    min-width: clamp(4.1rem, 20vw, 5.1rem);
    text-align: left;
  }

  .torch-wrap {
    flex: 1 1 auto;
    min-height: 72px;
    padding: 0;
  }

  .torch-device {
    width: min(36px, 100%);
    max-width: 40px;
  }

  .torch-bar {
    min-height: 0;
  }

  .torch-aura {
    width: 44px;
    filter: blur(5px);
  }
}

@media (max-width: 520px) {
  :root {
    --menu-right-width: 78px;
    --joystick-size: clamp(84px, 30vw, 106px);
  }

  .overlay {
    align-items: flex-start;
  }

  .overlay__panel {
    max-width: 100%;
  }

  .ingame-menu-btn {
    padding: 0.3rem 0.5rem;
    font-size: 0.76rem;
  }

  .ingame-menu-btn--help {
    width: 30px;
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  .app-root {
    flex-direction: row;
  }

  .sidebar {
    flex: 0 0 78px;
    width: 78px;
    max-width: 22vw;
    height: 100%;
    max-height: none;
    border-top: none;
    border-left: 1px solid #2a2a32;
    padding: 0.36rem 0.3rem 0.5rem;
    overflow: hidden;
  }

  .sidebar__top {
    min-width: 0;
    text-align: center;
  }

  .hud-survival-gear {
    bottom: calc(var(--safe-bottom) + 8px);
  }

  .joystick-zone {
    bottom: calc(var(--safe-bottom) + 8px);
  }
}
