/* ===================== Root variables ===================== */
:root{
  --ui-font: "Silkscreen", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;

  /* menu buttons */
  --btn-radius: 32px;
  --btn-shadow: 0 8px 24px rgba(0,0,0,.25);
  --btn-focus: 0 0 0 3px rgba(52,195,145,.35);

  --btnp-bg:#2ea0ff; --btnp-bg-hover:#45acff; --btnp-bg-active:#1e89e2; --btnp-fg:#06121a;
  --btno-fg:#e5f2ff; --btno-border:#4a6173; --btno-border-hover:#8fb2c8;

  /* blurred game background */
  --game-bg-url: url('assets/game-bg.jpg');
  --game-bg-blur: 12px;
  --game-bg-darken: 0.45; /* 0..1 */
}

/* ===================== Global base ===================== */
html, body,
button, input, select, textarea,
#top-bar, #status, .popup, #nav button, .levels-row button {
  font-family: var(--ui-font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  margin: 0;
  background-color: #121212;
  color: #eee;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  min-height: 100vh;
}

/* скрываем игровой интерфейс, пока открыто меню */
body.menu #top-bar,
body.menu #nav,
body.menu #status,
body.menu #game { display: none !important; }

/* ===================== Top area (status, nav, HUD) ===================== */

/* заголовок уровня */
#status {
  margin: 12px 0 8px;
  font-size: clamp(20px, 2.4vw, 28px);
  letter-spacing: .8px;
  text-transform: uppercase;
  text-align: center;
}

/* панель HUD: слева [timer][stats] …… справа [user][leaderboard] */
#top-bar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  width: min(96vw, 1200px);
  margin: 0 auto 8px;
  padding: 0 8px;
  box-sizing: border-box;
}
#top-bar .right-side { display: flex; align-items: center; gap: 10px; margin-left: auto; }

/* навигация уровней */
#nav {
  display:flex; gap:10px; justify-content:center; align-items:center;
  margin: 4px 0 10px;
}
#nav button{
  background:#2a2a2a; color:#eee; border:1px solid #555;
  padding:6px 12px; font-size:14px; border-radius:10px; cursor:pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,.2);
}
#nav button:hover{ filter:brightness(1.06); }

/* пилюли HUD */
#timer, #stats, #userBadge, #leaderboardBtn{
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 12px;
  box-shadow: 0 6px 18px rgba(0,0,0,.22);
}

/* таймер слева */
#timer{
  font-size: clamp(16px, 1.6vw, 18px);
  padding: 6px 12px;
  margin-right: 10px;
}

/* статы рядом с таймером — крупнее */
#stats{
  font-size: clamp(22px, 2.4vw, 30px);
  padding: 10px 14px;
}

/* ник и кнопка справа */
#userBadge{
  color:#ddd; font-size: 13px; padding: 6px 10px;
}
#leaderboardBtn{
  color:#fff; font-size: 14px; padding: 8px 14px; cursor:pointer; border: none;
}
#leaderboardBtn:hover{ filter: brightness(1.06); }

/* немного воздуха над полем */
#game{ margin-top: 6px; }

/* табличные цифры для счётчиков */
#timer, #stats, #leaderboardContent, #globalLbContent {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1, "lnum" 1;
}

/* ===================== Game blurred background ===================== */
#game-bg{
  position: fixed;
  inset: 0;
  z-index: 0;                 /* под всем интерфейсом */
  pointer-events: none;
  background-image: var(--game-bg-url);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  filter: blur(var(--game-bg-blur)) brightness(var(--game-bg-darken)) saturate(.95);
  transform: scale(1.04);     /* прячем края после blur */
}
#game-bg::after{
  content:"";
  position:absolute; inset:0;
  background: radial-gradient(120% 90% at 50% 40%,
               rgba(0,0,0,0) 0%, rgba(0,0,0,.32) 70%, rgba(0,0,0,.55) 100%);
}

/* поднимаем основные блоки игры над фоном */
#status, #top-bar, #nav, #game { position: relative; z-index: 1; }

/* ===================== Modals ===================== */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 999;               /* поверх HUD и фона */
}
.popup {
  background: #1e1e1e;
  padding: 20px;
  border: 2px solid #666;
  border-radius: 8px;
  text-align: center;
  max-height: 80vh;
  overflow-y: auto;
  animation: popupFade 0.2s ease-in-out;
}
.popup input {
  padding: 10px;
  margin-top: 10px;
  width: 220px;
  font-size: 16px;
  background: #333;
  color: #eee;
  border: 1px solid #555;
  border-radius: 4px;
}
.popup button {
  padding: 10px 20px;
  margin-top: 12px;
  background: #3c9;
  border: none;
  font-size: 16px;
  cursor: pointer;
  border-radius: 6px;
}
@keyframes popupFade {
  from { transform: scale(0.94); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}

/* ===================== Game board ===================== */
#game {
  display: grid;
  gap: 0;
  border: 4px solid #444;
  background-color: #000;
  position: relative;
}
.cell { position: relative; }
.cell img { width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; pointer-events: none; }
.end-marker { width: 80%; height: 80%; object-fit: contain; image-rendering: pixelated; pointer-events: none; }

/* overlays/sprites */
.overlay-layer { position: absolute; left: 0; top: 0; pointer-events: none; }
.sprite { position: absolute; left: 0; top: 0; will-change: transform; }
.sprite-img { width: 80%; height: 80%; object-fit: contain; image-rendering: pixelated; pointer-events: none; }

/* laser */
.laser {
  background: linear-gradient(0deg, rgba(255,90,90,0.95), rgba(255,180,180,0.65));
  box-shadow: 0 0 10px rgba(255,120,120,0.9), 0 0 22px rgba(255,70,70,0.6);
  border-radius: 2px;
}

/* damage effects */
.rat-hit { animation: ratHit 0.22s ease-in-out; filter: hue-rotate(310deg) brightness(1.3) drop-shadow(0 0 8px rgba(255,80,80,0.8)); }
@keyframes ratHit { 0%{opacity:.4} 50%{opacity:1} 100%{opacity:.7} }

.rat-invuln { animation: ratBlink .25s linear infinite; }
@keyframes ratBlink { 0%,49%{opacity:.55} 50%,100%{opacity:1} }

/* enemy explosion */
.boom {
  position: absolute;
  background: radial-gradient(circle, rgba(255,220,120,0.95) 0%, rgba(255,120,60,0.8) 50%, rgba(255,60,60,0.0) 70%);
  border-radius: 50%;
  box-shadow: 0 0 14px rgba(255,140,70,0.9), 0 0 28px rgba(255,90,40,0.7);
  animation: boomPop .28s ease-out forwards;
  pointer-events: none;
  z-index: 7;
}
@keyframes boomPop { 0%{transform:scale(.6);opacity:.85} 80%{transform:scale(1.1);opacity:.9} 100%{transform:scale(1);opacity:0} }

/* ===================== Main menu ===================== */
#menuOverlay { position: fixed; inset: 0; }
#menuOverlay .menu-bg {
  position: absolute; inset: 0;
  background: #0f0f0f center/cover no-repeat;
  background-image: url('assets/menu-bg.jpg');
  filter: brightness(0.7);
}
#menuOverlay .menu-center{
  position: relative; z-index: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  width: 100%; height: 100%;
}
.title { text-shadow: 0 2px 10px rgba(0,0,0,.6); }
.title-script {
  font-family: "Great Vibes", system-ui, -apple-system, "Segoe UI", cursive;
  font-weight: 400; letter-spacing: 0.5px;
  font-size: clamp(40px, 7vw, 92px); line-height: 1.05;
}
.title-old {
  font-family: "Cinzel Decorative", "Cinzel", Georgia, serif;
  font-weight: 700; letter-spacing: 1.5px;
  font-size: clamp(44px, 7.6vw, 96px); line-height: 1.05;
  -webkit-text-stroke: 0.6px rgba(0,0,0,0.25);
}
#menuOverlay .title{ margin:0; transform: translateY(-8vh); }
#menuOverlay .menu-buttons{
  display:flex; flex-direction:column; align-items:center; gap:14px; margin-top:26vh;
}
@media (max-width: 640px){
  #menuOverlay .title{ transform: translateY(-6vh); }
  #menuOverlay .menu-buttons{ margin-top: 5vh; gap: 12px; }
}

/* ===================== Menu buttons ===================== */
.btn{
  display:inline-flex; align-items:center; justify-content:center;
  width: clamp(200px, 32vw, 280px);
  padding: 14px 22px;
  font: inherit; font-weight: 600; letter-spacing:.2px;
  border: 0; border-radius: var(--btn-radius);
  cursor: pointer; user-select:none;
  transition: transform .08s ease, filter .15s ease, box-shadow .15s ease, background-color .2s ease, border-color .2s ease, color .2s ease;
  box-shadow: var(--btn-shadow);
}
.btn:focus{ outline: none; box-shadow: var(--btn-shadow), var(--btn-focus); }
.btn:hover{ transform: translateY(-1px); filter: brightness(1.03); }
.btn:active{ transform: translateY(1px) scale(.99); }

.btn-lg{ padding: 16px 24px; font-size: clamp(16px,1.6vw,20px); }
.btn-sm{ padding: 8px 14px; font-size: 14px; }

.btn-primary{ background: var(--btnp-bg); color: var(--btnp-fg); }
.btn-primary:hover{ background: var(--btnp-bg-hover); }
.btn-primary:active{ background: var(--btnp-bg-active); }

.btn-outline{
  background: transparent; color: var(--btno-fg);
  border: 1.5px solid var(--btno-border);
  box-shadow: none;
}
.btn-outline:hover{ border-color: var(--btno-border-hover); color:#fff; }

.btn-ghost{
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.12);
  backdrop-filter: blur(4px);
  color:#eee;
}
.btn-ghost:hover{ background: rgba(255,255,255,.09); }

/* === No page scroll while playing (menu unaffected) === */
body:not(.menu){ overflow-y: hidden; }

/* === Lift the HUD a bit, tighten vertical spacing === */
#status{ margin: 6px 0 4px !important; }
#nav{ margin: 0 0 4px !important; }
#top-bar{ margin: -6px auto 4px !important; }
#game{ margin-top: 2px !important; }

#timer, #stats{
  height: 34px;
  padding: 0 12px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
}

@media (max-width: 640px){
  #top-bar{ margin: -4px auto 4px !important; }
  #timer, #stats{ height: 32px; padding: 0 10px; }
}

/* ===== Menu footer links ===== */
#menuOverlay .menu-footer{
  position: absolute;
  left: 0; right: 0; bottom: 24px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 40px;
  z-index: 2;
  pointer-events: auto;
}
#menuOverlay .menu-footer .social{
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-radius: 12px;
  text-decoration: none;
  color: #e9eef3;
  background: rgba(0,0,0,.35);
  border: 1px solid rgba(255,255,255,.12);
  backdrop-filter: blur(4px);
  box-shadow: 0 8px 24px rgba(0,0,0,.30);
  transition: transform .12s ease, filter .2s ease, background .2s ease;
  font-family: var(--ui-font);
  font-size: clamp(14px, 1.4vw, 18px);
}
#menuOverlay .menu-footer .social:hover{
  transform: translateY(-1px);
  filter: brightness(1.08);
  background: rgba(0,0,0,.45);
}
#menuOverlay .menu-footer .social img{
  width: 28px;
  height: 28px;
  object-fit: contain;
  display: block;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.5));
}
@media (max-width: 700px){
  #menuOverlay .menu-footer{ gap: 16px; bottom: 16px; }
  #menuOverlay .menu-footer .social{ padding: 8px 12px; font-size: 14px; }
  #menuOverlay .menu-footer .social img{ width: 22px; height: 22px; }
}

/* ===== Win overlay ===== */
#winOverlay{ display:none; }
#winOverlay.overlay{ align-items: center; justify-content: center; }
.win-video{
  position:absolute; inset:0;
  width:100%; height:100%;
  object-fit: contain;
  object-position: center;
  background: #000;
  z-index: 0;
}
.win-mask{
  position:absolute; inset:0;
  background: radial-gradient(100% 100% at 50% 50%, rgba(0,0,0,.25) 0%, rgba(0,0,0,.6) 60%, rgba(0,0,0,.8) 100%);
  z-index: 1;
}
.win-box{
  position: relative; z-index: 2;
  width: min(92vw, 780px);
  padding: 24px 22px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,.18);
  background: rgba(0,0,0,.45);
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
  text-align: center;
}
.win-title{
  margin: 0 0 8px;
  font-size: clamp(18px, 2.6vw, 32px);
  letter-spacing: .08em;
  text-transform: uppercase;
}
.win-sub{
  opacity: .9;
  letter-spacing: .06em;
  margin-bottom: 16px;
  font-size: clamp(14px, 1.6vw, 18px);
}
.win-actions{
  display:flex; flex-wrap: wrap; gap: 14px; justify-content: center;
}
#cheeseBoard{
  display:none;
  text-align:left;
  margin-top:16px;
  padding-top:10px;
  border-top:1px solid rgba(255,255,255,.16);
  max-height: 35vh;  /* влезает Top 10 */
  overflow:auto;
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
}
/* How-to modal */
.kbd{
  display:inline-block;
  padding:2px 6px;
  border:1px solid #666;
  border-radius:4px;
  background:#1d1f22;
  margin:0 2px;
  font-family:ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size:12px;
}

/* список ближе к тексту, пунктов больше воздуха */
.howto-list{
  list-style: disc;
  list-style-position: inside; /* точка «внутри», ближе к тексту */
  margin:14px 0 18px;
  padding:0;
}
.howto-list li{
  margin:10px 0;
}
/* Мгновенное позиционирование спрайта: без анимаций, через GPU */
#ratSprite, .rat-sprite {
  position: absolute;
  will-change: transform;
  image-rendering: pixelated;
  transition: none !important;
}
