/* ============================================================
   Побег от Блокировки — тема и оверлеи (дизайн-контракт)
   Палитра киберпространства, аркадная типографика, glitch/HUD.
   Игровое поле рисует Phaser; здесь — HUD и экраны поверх canvas.
   ============================================================ */

:root {
  --bg:        #0b1026;
  --surface:   #161b3d;
  --surface-2: #1c2350;
  --text:      #e8ecff;
  --muted:     #7c86c4;
  --border:    #2a3168;
  --cyan:      #22d3ee;
  --magenta:   #f038c0;
  --green:     #4ade80;
  --danger:    #ff4d6d;

  --font-title: 'Press Start 2P', 'VT323', monospace;
  --font-hud:   'VT323', 'Press Start 2P', monospace;
  --font-body:  'Inter', system-ui, -apple-system, sans-serif;

  --radius: 16px;
  --glow-cyan: 0 0 18px rgba(34, 211, 238, 0.55);
  --glow-mag:  0 0 18px rgba(240, 56, 192, 0.5);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  text-rendering: optimizeLegibility;
}

/* Полноэкранный корень: canvas + оверлей */
#game-root {
  --gx: 50%;
  --gy: 10%;
  position: fixed;
  inset: 0;
  overflow: hidden;
  /* Фон-подложка (виден в letterbox-полях Scale.FIT); свечение мягко
     движется через --gx/--gy, обновляемые requestAnimationFrame. */
  background:
    radial-gradient(120% 82% at var(--gx) var(--gy), #131a45 0%, var(--bg) 58%, #070b1c 100%);
}

#game {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
#game canvas { display: block; }

/* Оверлей: по умолчанию прозрачен для кликов, интерактив включают дети */
#ui {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

/* ── HUD ─────────────────────────────────────────────────── */
.hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 12px;
  padding: 16px 20px;
  transition: opacity 0.4s ease;
}
.hud.is-hidden { opacity: 0; pointer-events: none; }

.hud-cell { display: flex; flex-direction: column; gap: 2px; }
.hud-left  { align-items: flex-start; }
.hud-right { align-items: flex-end; }
.hud-center { align-items: center; padding-top: 4px; }

.hud-label {
  font-family: var(--font-body);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}
.hud-value {
  font-family: var(--font-hud);
  font-size: 40px;
  line-height: 0.9;
  color: var(--text);
  text-shadow: var(--glow-cyan);
  font-variant-numeric: tabular-nums;
}
.hud-right .hud-value { color: var(--cyan); }

.hud-level {
  font-family: var(--font-title);
  font-size: 13px;
  line-height: 1.5;
  text-align: center;
  color: var(--magenta);
  text-shadow: var(--glow-mag);
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(11, 16, 38, 0.55);
  backdrop-filter: blur(4px);
  max-width: 46vw;
}

/* ── Всплывающая подпись зоны ─────────────────────────────── */
.toast {
  position: absolute;
  top: 22%;
  left: 50%;
  transform: translate(-50%, -8px);
  max-width: min(88vw, 640px);
  text-align: center;
  font-family: var(--font-body);
  font-size: 18px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--text);
  padding: 14px 22px;
  border-radius: 14px;
  background: rgba(22, 27, 61, 0.72);
  border: 1px solid var(--cyan);
  box-shadow: var(--glow-cyan);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease, transform 0.35s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.glitch { animation: toastGlitch 0.45s steps(2) 2; }
@keyframes toastGlitch {
  0%   { text-shadow: -2px 0 var(--magenta), 2px 0 var(--cyan); }
  50%  { text-shadow: 2px 0 var(--magenta), -2px 0 var(--cyan); }
  100% { text-shadow: 0 0 var(--magenta); }
}

/* ── Кнопки паузы / звука ─────────────────────────────────── */
.controls {
  position: absolute;
  right: 16px;
  bottom: 16px;
  display: flex;
  gap: 10px;
  pointer-events: auto;
  transition: opacity 0.4s ease;
}
.controls.is-hidden { opacity: 0; pointer-events: none; }
.ctrl-btn {
  width: 48px;
  height: 48px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(22, 27, 61, 0.82);
  color: var(--text);
  font-size: 17px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s ease, box-shadow 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.ctrl-btn:hover, .ctrl-btn:focus-visible {
  color: var(--cyan);
  border-color: var(--cyan);
  box-shadow: var(--glow-cyan);
  transform: translateY(-2px);
  outline: none;
}
.ctrl-btn:active { transform: scale(0.94); }

/* ── Экраны-оверлеи ───────────────────────────────────────── */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(120% 90% at 50% 30%, rgba(11,16,38,0.72) 0%, rgba(7,11,28,0.9) 100%);
  backdrop-filter: blur(6px);
  pointer-events: auto;
  animation: fadeIn 0.45s ease both;
}
.screen.is-active { display: flex; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.card {
  width: min(92vw, 520px);
  background: linear-gradient(180deg, rgba(28,35,80,0.92), rgba(18,22,52,0.94));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 34px 30px;
  text-align: center;
  box-shadow: 0 24px 70px rgba(0,0,0,0.55), inset 0 1px 0 rgba(255,255,255,0.05);
}

/* Логотип / заголовок стартового экрана */
.logo { display: flex; flex-direction: column; align-items: center; gap: 16px; margin-bottom: 14px; }
.logo-plane {
  font-size: 40px;
  color: var(--cyan);
  filter: drop-shadow(var(--glow-cyan));
  animation: bob 2.4s ease-in-out infinite;
}
@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(-6deg); }
  50%      { transform: translateY(-10px) rotate(4deg); }
}
.title {
  font-family: var(--font-title);
  font-size: clamp(20px, 4.6vw, 40px);
  line-height: 1.35;
  margin: 0;
  color: var(--text);
  letter-spacing: 0.02em;
}
/* Glitch-заголовок */
.glitch { position: relative; text-shadow: var(--glow-cyan); }
.glitch::before, .glitch::after {
  content: attr(data-text);
  position: absolute;
  left: 0; top: 0;
  width: 100%;
  clip-path: inset(0 0 0 0);
}
.glitch::before { color: var(--magenta); animation: glitchA 3.2s infinite steps(2); opacity: 0.7; }
.glitch::after  { color: var(--cyan);    animation: glitchB 2.6s infinite steps(2); opacity: 0.7; }
@keyframes glitchA {
  0%,92%,100% { transform: translate(0,0); }
  93% { transform: translate(-3px,-1px); }
  96% { transform: translate(3px,1px); }
}
@keyframes glitchB {
  0%,90%,100% { transform: translate(0,0); }
  91% { transform: translate(3px,1px); }
  95% { transform: translate(-3px,-1px); }
}

.slogan {
  font-size: 16px;
  line-height: 1.5;
  color: var(--muted);
  margin: 0 auto 26px;
  max-width: 40ch;
}

/* Кнопки */
.btn {
  font-family: var(--font-title);
  font-size: 13px;
  line-height: 1;
  letter-spacing: 0.04em;
  color: #08132a;
  background: linear-gradient(135deg, var(--cyan), #67e8f9);
  border: none;
  border-radius: 12px;
  padding: 18px 26px;
  min-height: 52px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--glow-cyan);
  transition: transform 0.12s ease, box-shadow 0.18s ease, filter 0.15s ease;
}
.btn i { font-size: 14px; }
.btn:hover, .btn:focus-visible {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 0 26px rgba(34,211,238,0.8);
  filter: brightness(1.06);
  outline: none;
}
.btn:active { transform: scale(0.96); }
.btn-primary { color: #06121f; }
.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: none;
}
.btn-ghost:hover, .btn-ghost:focus-visible {
  border-color: var(--magenta);
  color: var(--magenta);
  box-shadow: var(--glow-mag);
}
.btn-blink { animation: blink 1.3s ease-in-out infinite; }
@keyframes blink {
  0%, 100% { box-shadow: 0 0 10px rgba(34,211,238,0.4); }
  50%      { box-shadow: 0 0 30px rgba(34,211,238,0.95); }
}

.hint {
  margin: 22px 0 0;
  font-size: 14px;
  color: var(--muted);
}
.key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  padding: 3px 7px;
  margin: 0 2px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: rgba(11,16,38,0.6);
  color: var(--text);
  font-family: var(--font-hud);
  font-size: 18px;
}

/* Результаты (проигрыш/победа) */
.result-badge {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-title);
  font-size: 15px;
  padding: 12px 18px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text);
  margin-bottom: 18px;
}
.result-badge.danger  { color: var(--danger); border-color: var(--danger); box-shadow: 0 0 18px rgba(255,77,109,0.4); }
.result-badge.success { color: var(--green);  border-color: var(--green);  box-shadow: 0 0 18px rgba(74,222,128,0.4); }

.comment {
  font-size: 17px;
  line-height: 1.5;
  color: var(--text);
  margin: 0 auto 22px;
  max-width: 36ch;
}
.scores { display: flex; gap: 16px; justify-content: center; margin-bottom: 26px; }
.score-box {
  flex: 1;
  max-width: 180px;
  padding: 14px 10px;
  border-radius: 12px;
  background: rgba(11,16,38,0.5);
  border: 1px solid var(--border);
}
.score-cap {
  display: block;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}
.score-num {
  font-family: var(--font-hud);
  font-size: 44px;
  line-height: 0.9;
  color: var(--cyan);
  text-shadow: var(--glow-cyan);
  font-variant-numeric: tabular-nums;
}
.pause-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* Загрузочный экран */
.boot { text-align: center; }
.boot-plane {
  font-size: 44px;
  color: var(--cyan);
  filter: drop-shadow(var(--glow-cyan));
  animation: fly 1.4s ease-in-out infinite;
}
@keyframes fly {
  0%   { transform: translateX(-14px) rotate(-8deg); opacity: 0.5; }
  50%  { transform: translateX(14px)  rotate(6deg);  opacity: 1; }
  100% { transform: translateX(-14px) rotate(-8deg); opacity: 0.5; }
}
.boot-text {
  margin-top: 16px;
  font-family: var(--font-hud);
  font-size: 24px;
  color: var(--muted);
  letter-spacing: 0.08em;
}
.dots::after { content: ''; animation: dots 1.4s steps(4, end) infinite; }
@keyframes dots {
  0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } 100% { content: ''; }
}

/* ── Адаптив (< 768px) ────────────────────────────────────── */
@media (max-width: 768px) {
  .hud { padding: 10px 12px; }
  .hud-value { font-size: 30px; }
  .hud-label { font-size: 10px; }
  .hud-level { font-size: 10px; padding: 6px 10px; max-width: 42vw; }
  .card { padding: 28px 20px; }
  .slogan { font-size: 15px; }
  .toast { font-size: 16px; top: 20%; }
  .score-num { font-size: 36px; }
}
/* Очень узкие экраны — прячем название уровня в HUD */
@media (max-width: 420px) {
  .hud-center { display: none; }
  .btn { font-size: 12px; padding: 16px 20px; }
}
@media (max-height: 430px) {
  .hud-value { font-size: 26px; }
  .card { padding: 20px 18px; }
  .logo { margin-bottom: 8px; }
  .slogan { margin-bottom: 16px; }
  .hint { margin-top: 14px; }
}

/* Уважение к prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  .btn-blink, .logo-plane, .boot-plane, .glitch::before, .glitch::after { animation: none; }
}
