:root {
  --primary: #0B3D91;
  --accent: #F28C00;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #5CA8EE;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, Arial, sans-serif;
  color: #fff;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  overscroll-behavior: none;
  -webkit-touch-callout: none;
  -webkit-text-size-adjust: 100%;
}

/* Сцена: на телефоне весь экран, на десктопе — поле по центру в пропорциях телефона */
#stage {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 100vw;
  transform: translateX(-50%);
  overflow: hidden;
  touch-action: none;
}
@media (pointer: fine) {
  html, body { background: #0E1626; }
  #stage { width: min(100vw, calc(100vh * 9 / 16)); box-shadow: 0 0 60px rgba(0, 0, 0, 0.5); }
}

#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

.hidden { display: none !important; }

/* Верхняя строка: жизни, этаж, очки */
#hud {
  position: absolute;
  top: calc(var(--safe-top) + 12px);
  left: 14px;
  right: 14px;
  display: flex;
  align-items: center;
  pointer-events: none;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  z-index: 5;
}
#hud > div { flex: 1; }
.hud-left { font-size: 20px; letter-spacing: 1px; }
.hud-center { text-align: center; font-size: 30px; font-weight: 800; line-height: 1; }
.hud-label { display: block; font-size: 12px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; opacity: 0.85; margin-bottom: 2px; }
#target { font-size: 16px; font-weight: 600; opacity: 0.75; }
.hud-right { text-align: right; }
.hud-right b {
  display: inline-block;
  min-width: 56px;
  padding: 6px 12px;
  border-radius: 14px;
  background: var(--accent);
  font-size: 22px;
  text-align: center;
  text-shadow: none;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 84px);
  transform: translateX(-50%) translateY(10px);
  padding: 10px 16px;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.7);
  font-size: 15px;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 20;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.icon-btn {
  position: absolute;
  right: 14px;
  bottom: calc(var(--safe-bottom) + 14px);
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.28);
  font-size: 22px;
  line-height: 48px;
  cursor: pointer;
  z-index: 15;
}

/* Экраны поверх игры */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: calc(var(--safe-top) + 28px) 28px calc(var(--safe-bottom) + 80px);
  text-align: center;
  background: linear-gradient(180deg, rgba(8, 20, 48, 0.25), rgba(8, 20, 48, 0.72));
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 10;
}
.screen h1 { margin: 0; font-size: 34px; font-weight: 800; line-height: 1.1; letter-spacing: -0.01em; }
.eyebrow { margin: 0; font-size: 13px; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase; color: var(--accent); }
.lead { margin: 0; font-size: 17px; line-height: 1.35; opacity: 0.92; max-width: 320px; }
.best { margin: 0; font-size: 15px; opacity: 0.85; min-height: 1em; }
.logo { width: 72%; max-width: 260px; height: auto; margin-bottom: 6px; image-rendering: pixelated; }

.stats { display: flex; gap: 10px; width: 100%; max-width: 330px; margin: 6px 0 2px; }
.stat {
  flex: 1;
  padding: 12px 6px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.14);
}
.stat b { display: block; font-size: 30px; font-weight: 800; line-height: 1.1; }
.stat span { font-size: 13px; opacity: 0.8; }
.stat:nth-child(2) b { color: var(--accent); }

.btn {
  display: block;
  width: 100%;
  max-width: 320px;
  min-height: 58px;
  border: 0;
  border-radius: 20px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 19px;
  font-weight: 700;
  text-decoration: none;
  line-height: 58px;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
  transition: transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn-light { background: #fff; color: var(--primary); }
.btn-ghost { background: rgba(255, 255, 255, 0.16); box-shadow: none; }
#play { min-height: 64px; line-height: 64px; font-size: 22px; margin-top: 6px; }

/* Загрузка */
#loading { background: linear-gradient(180deg, #5CA8EE, #BFE3FA); color: #0E1626; z-index: 30; }
#loading .eyebrow { color: var(--primary); }
.bar { width: 70%; max-width: 260px; height: 10px; border-radius: 6px; background: rgba(11, 61, 145, 0.18); overflow: hidden; }
#load-bar { width: 0; height: 100%; border-radius: 6px; background: var(--accent); transition: width 0.2s; }

/* Горизонтальный телефон: просим повернуть */
#rotate {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: #0E1626;
  text-align: center;
  font-size: 22px;
  font-weight: 700;
}
#rotate p { margin: 0; }
#rotate .small { font-size: 15px; font-weight: 400; opacity: 0.75; }
.phone-icon {
  width: 44px;
  height: 74px;
  border: 4px solid #fff;
  border-radius: 10px;
  animation: turn 1.8s ease-in-out infinite;
}
@keyframes turn { 0%, 30% { transform: rotate(-90deg); } 60%, 100% { transform: rotate(0deg); } }
@media (orientation: landscape) and (pointer: coarse) {
  #rotate { display: flex; }
}
