/* ============ Elfy Crush — стиль ============ */
:root {
  --bg-deep: #0d1320;
  --panel: rgba(16, 24, 40, 0.72);
  --panel-light: rgba(255, 255, 255, 0.07);
  --stroke: rgba(255, 255, 255, 0.12);
  --text: #eef4ff;
  --text-dim: #9fb0cc;
  --gold: #ffc94d;
  --gold-deep: #f5a623;
  --mint: #7df0c3;
  --danger: #ff6b81;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  --radius: 20px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg-deep);
  font-family: 'Nunito', 'Segoe UI', system-ui, sans-serif;
  color: var(--text);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: pointer;
  z-index: 0; /* явно под UI */
}

#ui {
  position: fixed;
  inset: 0;
  pointer-events: none; /* сам UI-слой не ловит события, ловят его дети */
  z-index: 1; /* и явно над канвасом — независимо от GPU-слоёв */
}

/* ---------- Экраны ---------- */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  pointer-events: none;
}
.screen.active { display: flex; }
.screen.active > * { pointer-events: auto; }

/* ---------- Кнопки ---------- */
.btn {
  font-family: 'Comfortaa', 'Nunito', sans-serif;
  font-weight: 700;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  color: var(--text);
  background: var(--panel-light);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--stroke);
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}
.btn:hover { transform: translateY(-2px) scale(1.03); filter: brightness(1.12); }
.btn:active { transform: scale(0.95); }

.btn-primary {
  background: linear-gradient(180deg, #ffd977, var(--gold-deep) 55%, #d9820f);
  color: #35230a;
  border: none;
  box-shadow: 0 6px 24px rgba(245, 166, 35, 0.45), inset 0 2px 0 rgba(255, 255, 255, 0.5);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35);
}
.btn-primary:hover { box-shadow: 0 10px 32px rgba(245, 166, 35, 0.6), inset 0 2px 0 rgba(255,255,255,0.5); }

.btn-big {
  font-size: 26px;
  padding: 18px 68px;
  letter-spacing: 0.04em;
}

.btn-round {
  width: 48px;
  height: 48px;
  font-size: 20px;
  display: grid;
  place-items: center;
  border-radius: 50%;
}

.btn-glass {
  padding: 12px 30px;
  font-size: 16px;
}

/* ---------- Главное меню ---------- */
#screen-menu {
  align-items: center;
  justify-content: center;
}
.menu-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 26px;
  animation: rise-in 0.8s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
  padding: 24px;
}
@keyframes rise-in {
  from { opacity: 0; transform: translateY(34px) scale(0.96); }
  to { opacity: 1; transform: none; }
}

.logo {
  font-family: 'Comfortaa', sans-serif;
  font-weight: 700;
  font-size: clamp(56px, 12vw, 108px);
  line-height: 0.95;
  text-align: center;
  filter: drop-shadow(0 8px 30px rgba(125, 240, 195, 0.25));
  animation: logo-float 4.5s ease-in-out infinite;
}
.logo-elfy {
  display: block;
  background: linear-gradient(180deg, #eafff5, #7df0c3 60%, #35c391);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.logo-crush {
  display: block;
  background: linear-gradient(180deg, #fff2cf, var(--gold) 55%, #f08a1c);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
@keyframes logo-float {
  0%, 100% { transform: translateY(0) rotate(-1deg); }
  50% { transform: translateY(-10px) rotate(1deg); }
}

.tagline {
  font-size: 17px;
  color: var(--text-dim);
  letter-spacing: 0.02em;
}
.menu-row { display: flex; gap: 14px; }
.menu-hint {
  margin-top: 8px;
  font-size: 13px;
  color: rgba(159, 176, 204, 0.65);
}

/* ---------- Карта уровней ---------- */
#screen-map { background: transparent; }

.map-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  gap: 12px;
  background: linear-gradient(180deg, rgba(10, 15, 26, 0.9), rgba(10, 15, 26, 0));
}
.map-header h2 {
  font-family: 'Comfortaa', sans-serif;
  font-size: 22px;
  letter-spacing: 0.04em;
}

#map-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px 24px 60vh; /* снизу большой запас, чтобы путь уходил в туман */
  scrollbar-width: none;
  -webkit-mask-image: linear-gradient(180deg, transparent 0, #000 60px, #000 calc(100% - 45vh), transparent 100%);
  mask-image: linear-gradient(180deg, transparent 0, #000 60px, #000 calc(100% - 45vh), transparent 100%);
}
#map-scroll::-webkit-scrollbar { display: none; }

#map-path {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 26px;
  max-width: 420px;
  margin: 0 auto;
}

.level-node {
  position: relative;
  width: 84px;
  height: 84px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  font-family: 'Comfortaa', sans-serif;
  font-weight: 700;
  font-size: 26px;
  color: #3a2606;
  background: radial-gradient(circle at 32% 28%, #ffe9ad, var(--gold) 55%, #e28f14);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.4), 0 0 0 5px rgba(255, 255, 255, 0.08), inset 0 3px 6px rgba(255,255,255,0.55);
  transition: transform 0.18s ease;
}
.level-node:hover { transform: scale(1.09); }
.level-node:active { transform: scale(0.94); }

.level-node.locked {
  background: radial-gradient(circle at 32% 28%, #3b4658, #232c3c 60%, #171e2b);
  color: #61708a;
  cursor: default;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4), inset 0 2px 4px rgba(255,255,255,0.08);
}
.level-node.locked:hover { transform: none; }

.level-node .node-stars {
  position: absolute;
  bottom: -12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 1px;
  font-size: 17px;
  letter-spacing: -2px;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.5));
}
.node-stars .s { color: #566179; }
.node-stars .s.on { color: var(--gold); text-shadow: 0 0 6px rgba(255, 201, 77, 0.8); }

.level-node.current {
  animation: node-pulse 1.6s ease-in-out infinite;
}
@keyframes node-pulse {
  0%, 100% { box-shadow: 0 8px 22px rgba(0, 0, 0, 0.4), 0 0 0 0 rgba(125, 240, 195, 0.55), inset 0 3px 6px rgba(255,255,255,0.55); }
  50% { box-shadow: 0 8px 22px rgba(0, 0, 0, 0.4), 0 0 0 14px rgba(125, 240, 195, 0), inset 0 3px 6px rgba(255,255,255,0.55); }
}

/* чередующиеся смещения — тропа виляет */
#map-path .level-node:nth-child(4n+1) { align-self: flex-start; transform: rotate(-6deg); }
#map-path .level-node:nth-child(4n+1):hover { transform: rotate(-6deg) scale(1.09); }
#map-path .level-node:nth-child(4n+3) { align-self: flex-end; transform: rotate(5deg); }
#map-path .level-node:nth-child(4n+3):hover { transform: rotate(5deg) scale(1.09); }

#map-more { text-align: center; color: var(--text-dim); padding-top: 8px; font-size: 14px; }

/* ---------- HUD ---------- */
#hud { justify-content: space-between; }

.hud-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  gap: 10px;
  background: linear-gradient(180deg, rgba(10, 15, 26, 0.85), rgba(10, 15, 26, 0));
}

.hud-center {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.hud-level {
  text-align: center;
  line-height: 1.05;
  font-family: 'Comfortaa', sans-serif;
}
.hud-level span { font-size: 26px; font-weight: 700; }
.hud-level small { display: block; font-size: 11px; color: var(--text-dim); letter-spacing: 0.08em; text-transform: uppercase; }

.hud-moves {
  min-width: 76px;
  text-align: center;
  padding: 8px 14px;
  border-radius: 18px;
  background: var(--panel);
  border: 1px solid var(--stroke);
  backdrop-filter: blur(8px);
  font-size: 30px;
  font-weight: 900;
  line-height: 1;
  box-shadow: var(--shadow);
}
.hud-moves small { display: block; font-size: 10px; font-weight: 600; color: var(--text-dim); letter-spacing: 0.08em; text-transform: uppercase; margin-top: 3px; }
.hud-moves.low { animation: moves-low 0.9s ease-in-out infinite; color: var(--danger); border-color: rgba(255, 107, 129, 0.5); }
@keyframes moves-low {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.07); }
}

.hud-bottom {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px 16px;
  background: linear-gradient(0deg, rgba(10, 15, 26, 0.88), rgba(10, 15, 26, 0));
}

#hud-objectives { display: flex; gap: 10px; flex-wrap: wrap; }

.objective {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid var(--stroke);
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
  font-weight: 800;
  font-size: 15px;
}
.objective canvas { width: 30px; height: 30px; display: block; }
.objective .obj-progress { color: var(--text-dim); font-weight: 700; font-size: 14px; }
.objective.done .obj-progress { color: var(--mint); }
.objective.done { border-color: rgba(125, 240, 195, 0.45); }

.hud-score-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
  min-width: 150px;
}

.hud-score-bar {
  position: relative;
  width: 160px;
  height: 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--stroke);
  overflow: visible;
}
#hud-score-fill {
  position: absolute;
  inset: 1px;
  width: 0%;
  max-width: calc(100% - 2px);
  border-radius: 999px;
  background: linear-gradient(90deg, #7df0c3, #ffd977);
  box-shadow: 0 0 10px rgba(125, 240, 195, 0.55);
  transition: width 0.45s cubic-bezier(0.2, 0.8, 0.3, 1);
}
.star-pip {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 15px;
  color: #4a5670;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
  transition: color 0.3s ease, transform 0.3s cubic-bezier(0.2, 0.9, 0.3, 1.6), text-shadow 0.3s ease;
}
.star-pip[data-star="1"] { left: 33%; }
.star-pip[data-star="2"] { left: 66%; }
.star-pip[data-star="3"] { left: 100%; }
.star-pip.on {
  color: var(--gold);
  transform: translate(-50%, -50%) scale(1.35);
  text-shadow: 0 0 12px rgba(255, 201, 77, 0.9);
}

#hud-score-num {
  font-size: 15px;
  font-weight: 900;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

/* ---------- Модалки ---------- */
#modal-root {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(6, 9, 16, 0.6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  pointer-events: auto;
  z-index: 50;
  animation: fade-in 0.25s ease both;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal {
  width: min(92vw, 400px);
  padding: 30px 26px 26px;
  border-radius: 28px;
  background: linear-gradient(180deg, rgba(30, 40, 62, 0.95), rgba(16, 22, 38, 0.95));
  border: 1px solid var(--stroke);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  text-align: center;
  animation: modal-pop 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.35) both;
}
@keyframes modal-pop {
  from { opacity: 0; transform: translateY(30px) scale(0.9); }
  to { opacity: 1; transform: none; }
}

.modal h3 {
  font-family: 'Comfortaa', sans-serif;
  font-size: 26px;
  margin-bottom: 6px;
}
.modal .modal-sub { color: var(--text-dim); font-size: 15px; margin-bottom: 18px; }
.modal .modal-btns { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; }
.modal .btn { padding: 14px; font-size: 17px; }

.modal-stars {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 14px 0 4px;
  font-size: 46px;
  height: 60px;
}
.modal-stars .ms {
  color: #39435c;
  transform: scale(0);
  animation: star-pop 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.7) forwards;
}
.modal-stars .ms.on { color: var(--gold); text-shadow: 0 0 22px rgba(255, 201, 77, 0.75); }
.modal-stars .ms:nth-child(2) { animation-delay: 0.35s; font-size: 58px; }
.modal-stars .ms:nth-child(1) { animation-delay: 0.15s; }
.modal-stars .ms:nth-child(3) { animation-delay: 0.55s; }
@keyframes star-pop { to { transform: scale(1); } }

.modal-stats { display: flex; justify-content: center; gap: 22px; margin-top: 10px; }
.modal-stats div { display: flex; flex-direction: column; gap: 2px; }
.modal-stats b { font-size: 20px; }
.modal-stats span { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.06em; }

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 4px;
  font-size: 16px;
  font-weight: 800;
}
.toggle {
  position: relative;
  width: 56px;
  height: 30px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  background: #2c3650;
  transition: background 0.25s ease;
}
.toggle::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #8fa0c2;
  transition: transform 0.25s cubic-bezier(0.2, 0.9, 0.3, 1.4), background 0.25s ease;
}
.toggle.on { background: #2a6b52; }
.toggle.on::after { transform: translateX(26px); background: var(--mint); box-shadow: 0 0 10px rgba(125, 240, 195, 0.6); }

/* ---------- Тосты ---------- */
#toast {
  position: absolute;
  left: 50%;
  top: 18%;
  transform: translateX(-50%);
  padding: 12px 26px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--stroke);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
  font-family: 'Comfortaa', sans-serif;
  font-weight: 700;
  font-size: 17px;
  z-index: 40;
  pointer-events: none;
  animation: toast-in 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.3) both;
}
#toast.hide { animation: toast-out 0.3s ease both; }
@keyframes toast-in { from { opacity: 0; transform: translateX(-50%) translateY(-18px) scale(0.9); } to { opacity: 1; transform: translateX(-50%); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(-50%) translateY(-14px); } }

.hidden { display: none !important; }

/* ---------- Гайды по механикам ---------- */
#guide-root {
  position: absolute;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(6, 9, 16, 0.72);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  pointer-events: auto;
  animation: fade-in 0.3s ease both;
}

.guide-card {
  width: min(92vw, 420px);
  padding: 26px 24px 22px;
  border-radius: 28px;
  background: linear-gradient(180deg, rgba(32, 43, 66, 0.97), rgba(17, 23, 40, 0.97));
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  text-align: center;
  animation: guide-pop 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.3) both;
}
@keyframes guide-pop {
  from { opacity: 0; transform: translateY(36px) scale(0.92); }
  to { opacity: 1; transform: none; }
}

.guide-card .guide-kicker {
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--mint);
  margin-bottom: 10px;
}

.guide-card canvas {
  width: 100%;
  max-width: 340px;
  height: auto;
  display: block;
  margin: 0 auto 8px;
  border-radius: 18px;
  background: rgba(8, 12, 22, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.07);
}

.guide-card h3 {
  font-family: 'Comfortaa', sans-serif;
  font-size: 24px;
  margin: 10px 0 8px;
}

.guide-card p {
  font-size: 15px;
  line-height: 1.55;
  color: var(--text-dim);
  min-height: 3em;
}
.guide-card p b { color: var(--text); }

.guide-dots {
  display: flex;
  justify-content: center;
  gap: 7px;
  margin: 14px 0 16px;
}
.guide-dots .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  transition: background 0.25s ease, transform 0.25s ease;
}
.guide-dots .dot.on {
  background: var(--mint);
  transform: scale(1.35);
  box-shadow: 0 0 8px rgba(125, 240, 195, 0.7);
}

.guide-btns .btn { width: 100%; padding: 14px; font-size: 17px; }

.guide-hint {
  margin-top: 10px;
  font-size: 12px;
  color: rgba(159, 176, 204, 0.55);
}

/* на мобилке — карточка снизу, как шторка */
@media (max-width: 560px) {
  #guide-root { align-items: flex-end; padding: 12px; }
  .guide-card { border-radius: 26px 26px 18px 18px; padding-bottom: max(20px, env(safe-area-inset-bottom)); }
  .guide-card p { min-height: 2.6em; }
}

.btn-help {
  width: 42px;
  height: 42px;
  font-size: 19px;
  font-family: 'Nunito', sans-serif;
  font-weight: 900;
}

/* ---------- Мелкие экраны ---------- */
@media (max-width: 480px) {
  .btn-big { font-size: 22px; padding: 16px 54px; }
  .hud-moves { min-width: 64px; font-size: 24px; padding: 6px 10px; }
  .hud-score-bar { width: 120px; }
  .objective { font-size: 13px; padding: 6px 10px; }
}
