:root {
  --ink: #3a2410;
  --paper: #fff7e8;
  --muted: #8a6a48;
  --accent: #d9822b;
  --accent-dark: #a45f1c;
  --good: #2f7d32;
}

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

html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #2a1f14;
  font-family: Jost, system-ui, sans-serif;
  /* Игра — не страница: ни выделения текста, ни «лупы», ни прокрутки. */
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  overscroll-behavior: none;
}

/* touch-action: none — жесты пальцем достаются игре, а не браузеру. */
#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

button { font-family: inherit; cursor: pointer; }
.muted { color: var(--muted); }

.round {
  width: 44px; height: 44px; flex: 0 0 44px;
  border: none; border-radius: 50%;
  background: rgba(0, 0, 0, .35); color: #fff;
  font-size: 15px; font-weight: 800; letter-spacing: -1px;
}

/* --- верх в бою --- */
.hud {
  position: fixed; top: 0; left: 0; right: 0;
  padding: calc(8px + env(safe-area-inset-top)) 12px 0;
  color: #fff; pointer-events: none;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .6);
}
.hud button { pointer-events: auto; }
.hud-row { display: flex; align-items: center; justify-content: space-between; }
.hud-level { font-size: 19px; font-weight: 800; }

.weapon { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 16px; font-weight: 800; }
.weapon-now, .weapon-next { white-space: nowrap; }
.weapon-next { opacity: .85; font-weight: 500; }
.bar { position: relative; flex: 1; height: 18px; border-radius: 99px; background: rgba(0, 0, 0, .35); border: 2px solid rgba(255, 255, 255, .8); overflow: hidden; }
.bar i { position: absolute; inset: 0 auto 0 0; background: linear-gradient(90deg, #ffb238, #ffd24a); transition: width .3s; }
.bar.small { height: 8px; border-width: 0; background: rgba(58, 36, 16, .15); }
.bar.small i { background: var(--accent); }

.boss-track { position: relative; height: 6px; margin: 10px 22px 0 0; border-radius: 99px; background: rgba(0, 0, 0, .25); }
.boss-track i { position: absolute; inset: 0 auto 0 0; border-radius: 99px; background: #ff6a4a; transition: width .4s; }
.boss-track b { position: absolute; right: -22px; top: -9px; font-size: 15px; font-weight: 400; }
/* В битве с боссом полоса — его здоровье: толще и заметнее. */
.boss-track.fight { height: 12px; border: 2px solid rgba(255,255,255,.8); }
.boss-track.fight i { background: linear-gradient(90deg, #d4231a, #ff6a4a); }
.boss-track.fight b::before { content: "💀"; }
.boss-track.fight b { font-size: 0; }
.boss-track.fight b::before { font-size: 17px; }

.warning, .new-weapon {
  position: fixed; left: 0; right: 0; top: 17%;
  padding: 12px 0; text-align: center; color: #fff;
  font-size: 26px; font-weight: 800; letter-spacing: .06em;
  pointer-events: none;
}
.warning { background: rgba(150, 20, 10, .8); animation: blink .5s ease-in-out infinite alternate; }
.new-weapon { padding: 12px 16px; background: rgba(217, 130, 43, .92); font-size: 22px; letter-spacing: .02em; animation: pop .35s ease-out; }
@keyframes blink { from { opacity: .55; } to { opacity: 1; } }
@keyframes pop { from { transform: scale(1.4); opacity: 0; } }

/* --- экраны --- */
.screen {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  padding: calc(20px + env(safe-area-inset-top)) 20px calc(20px + env(safe-area-inset-bottom));
  background: rgba(20, 12, 5, .55);
}

/* --- главное меню: вариант А «Закат» (01.10) ---
   Экран fixed на всё окно, кнопки прижаты к низу: на высоком телефоне
   они не уезжают за край (на 100dvh в браузере Telegram уезжали). */
.menu-a {
  display: flex; flex-direction: column; align-items: stretch; place-items: stretch;
  padding: calc(12px + env(safe-area-inset-top)) 16px calc(18px + env(safe-area-inset-bottom));
  background: #2a160a url(art/menu/sunset.webp) center top / cover no-repeat;
  overflow: hidden;
  font-family: Nunito, Jost, system-ui, sans-serif;
}
/* Низ темнеет, чтобы кнопки читались поверх картинки. */
.menu-a::after {
  content: ""; position: absolute; inset: 50% 0 0; z-index: 0; pointer-events: none;
  background: linear-gradient(transparent, rgba(42, 22, 10, .55) 45%, rgba(29, 15, 6, .9));
}
.menu-a > * { position: relative; z-index: 1; }
.menu-a .ic { width: 1em; height: 1em; fill: currentColor; flex: none; }
.menu-top { display: flex; justify-content: space-between; align-items: center; }
.pill-coins {
  display: flex; align-items: center; gap: 6px; padding: 6px 14px 6px 8px;
  border: 3px solid var(--ink); border-radius: 999px; background: rgba(42, 22, 10, .72);
  color: #fff; font: 900 18px Nunito, sans-serif;
}
.pill-coins .ic { font-size: 26px; color: #ffc93c; }
.square {
  display: grid; place-items: center; width: 48px; height: 48px;
  border: 3px solid var(--ink); border-radius: 16px; background: rgba(42, 22, 10, .72);
  color: #fff; font-size: 26px;
}
.menu-logo { margin-top: 14px; text-align: center; }
.menu-logo h1 {
  margin: 0; color: #ffc93c; font: 900 clamp(34px, 11vw, 46px)/.95 Unbounded, sans-serif; letter-spacing: -1px;
  -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; text-shadow: 0 5px 0 var(--ink);
  transform: rotate(-3deg);
}
.menu-logo p {
  display: inline-block; margin: 12px 0 0; padding: 4px 14px; border-radius: 8px; background: var(--ink);
  color: #fff; font: 900 15px Nunito, sans-serif; letter-spacing: 3px; text-transform: uppercase; transform: rotate(-3deg);
}
/* Герои стоят на нижней кромке своей области, над кнопками. */
.menu-heroes { flex: 1; min-height: 150px; }
.menu-heroes img { position: absolute; bottom: 0; filter: drop-shadow(0 8px 6px rgba(0, 0, 0, .3)); transform-origin: 50% 100%; }
/* Мамонт 501×440; попона — на 60% ширины. Наездник сидит верхом, ноги
   свешиваются на попону. Мамонт смотрит влево — на героев. */
.menu-heroes .mount { position: absolute; right: -6%; bottom: 0; width: 60%; aspect-ratio: 501 / 440; transform-origin: 50% 100%; }
.menu-heroes .mount img { position: absolute; left: 0; bottom: 0; width: 100%; }
.menu-heroes .mount .rider { left: 45%; bottom: 50%; width: 30%; filter: none; }
.menu-actions { display: grid; gap: 12px; margin-top: 8px; }
.big-play {
  display: flex; align-items: center; justify-content: center; gap: 12px; min-height: 76px;
  border: 4px solid var(--ink); border-radius: 22px;
  background: linear-gradient(#ffc93c 55%, #e58a12);
  box-shadow: 0 7px 0 var(--ink), inset 0 4px 0 rgba(255, 255, 255, .5);
  color: var(--ink); font: 900 30px Unbounded, sans-serif; text-transform: uppercase;
}
.big-play .ic { font-size: 34px; }
.big-play small, .tile small { display: block; font: 900 14px Nunito, sans-serif; letter-spacing: .5px; text-transform: none; }
.big-play small { opacity: .75; }
.menu-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile {
  position: relative; display: flex; align-items: center; gap: 10px; min-height: 64px; padding: 0 12px;
  border: 4px solid var(--ink); border-radius: 22px;
  background: linear-gradient(#57b33e 55%, #2f7a24);
  box-shadow: 0 6px 0 var(--ink), inset 0 3px 0 rgba(255, 255, 255, .35);
  color: #fff; font: 900 18px Nunito, sans-serif; text-align: left; text-shadow: 0 2px 0 var(--ink);
}
.tile .ic { font-size: 30px; }
.tile small { opacity: .9; }
.badge {
  position: absolute; top: -10px; right: -6px; display: grid; place-items: center;
  min-width: 26px; height: 26px; padding: 0 6px; border: 3px solid var(--ink); border-radius: 999px;
  background: #e5322b; color: #fff; font: 900 13px Nunito, sans-serif; text-shadow: none;
}
.menu-a button:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
/* Герои зовут играть: двое машут (кадры сменяет main.js), третий прыгает —
   0–25% сидит на земле (кадр «присел»), дальше подлёт (кадр «прыжок»). */
@media (prefers-reduced-motion: no-preference) {
  .menu-heroes .bob { animation: hero-bob 2.4s ease-in-out infinite; }
  .menu-heroes .sway { animation: hero-sway 1.4s ease-in-out infinite; }
  .menu-heroes .jump { animation: hero-jump .9s linear infinite; }
}
@keyframes hero-bob { 50% { transform: translateY(-4px) rotate(-1.5deg); } }
@keyframes hero-sway { 0%, 100% { transform: rotate(-2deg); } 50% { transform: rotate(2deg) translateY(-2px); } }
@keyframes hero-jump { 0%, 25% { transform: translateY(0); } 45% { transform: translateY(-26px); } 62% { transform: translateY(-28px); } 85%, 100% { transform: translateY(0); } }

.primary {
  width: 100%; height: 58px; border: none; border-radius: 18px;
  background: var(--accent); color: #fff; font-size: 21px; font-weight: 800;
  box-shadow: 0 5px 0 var(--accent-dark);
}
.primary:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--accent-dark); }
.text { width: 100%; height: 44px; margin-top: 8px; border: none; background: none; color: var(--muted); font-size: 16px; font-weight: 700; }

/* панели: уровни, настройки */
.panel { place-items: start center; align-content: start; overflow-y: auto; background: rgba(30, 18, 8, .88); }
.panel > * { width: 100%; max-width: 380px; min-width: 0; }
.panel-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; color: #fff; }
.panel-head h2 { margin: 0; font-size: 24px; }

.era-block { margin-bottom: 18px; }
.era-block h3 { margin: 0 0 8px; color: #fff; font-size: 17px; }
.era-block.locked h3 { opacity: .55; }
.level-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.level-grid button {
  aspect-ratio: 1; border: none; border-radius: 14px;
  background: var(--paper); color: var(--ink); font-size: 19px; font-weight: 800;
  box-shadow: 0 3px 0 #d8c6a4;
}
.level-grid button.done { background: #e9f5e3; color: var(--good); box-shadow: 0 3px 0 #b9d6ad; }
.level-grid button.current { background: var(--accent); color: #fff; box-shadow: 0 3px 0 var(--accent-dark); }
.level-grid button:disabled { background: rgba(255, 255, 255, .12); color: rgba(255, 255, 255, .4); box-shadow: none; font-size: 15px; }
.soon { padding: 12px; border-radius: 14px; background: rgba(255, 255, 255, .08); color: rgba(255, 255, 255, .55); font-size: 14px; }

.toggle {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 10px; padding: 14px 16px; border-radius: 16px; background: var(--paper);
  color: var(--ink); font-size: 17px; font-weight: 700; cursor: pointer;
}
.toggle small { display: block; font-size: 12.5px; font-weight: 500; color: var(--muted); }
.toggle input { display: none; }
.toggle i { position: relative; flex: 0 0 50px; height: 30px; border-radius: 99px; background: #d8c6a4; transition: background .2s; }
.toggle i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); }
.toggle input:checked + i { background: var(--good); }
.toggle input:checked + i::after { transform: translateX(20px); }

.howto { margin-top: 8px; padding: 14px 16px; border-radius: 16px; background: rgba(255, 255, 255, .08); color: #f3e6d0; font-size: 14.5px; }
.howto b { color: #fff; font-size: 16px; }
.howto p { margin: 6px 0 0; }

/* окно конца боя и паузы */
.card {
  width: 100%; max-width: 340px; padding: 26px 22px 14px;
  border-radius: 22px; background: var(--paper); text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .35);
}
.card h1 { margin: 0; font-size: 32px; color: var(--ink); }
.card p { margin: 6px 0 18px; color: var(--muted); font-size: 16px; }

/* монеты и лагерь */
.coins { display: inline-flex; align-items: center; gap: 4px; font-weight: 800; color: #b7791f; }
.coins::before { content: "🪙"; }
.coins.big { margin-left: auto; padding-right: 2px; font-size: 20px; color: #ffd24a; white-space: nowrap; }
.panel-hint { margin: -4px 0 14px; color: #d8c3a2; font-size: 14px; }
.perk-list { display: grid; gap: 10px; }
.perk {
  display: grid; grid-template-columns: 48px minmax(0, 1fr) auto; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: 18px; background: var(--paper); color: var(--ink);
}
.perk-icon { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 14px; background: #f3e2c4; font-size: 26px; }
.perk b { display: block; font-size: 17px; }
.perk small { display: block; color: var(--muted); font-size: 13px; }
.perk-steps { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 5px; }
.perk-steps i { width: 8px; height: 6px; border-radius: 3px; background: #e2d2b3; }
.perk-steps i.on { background: var(--accent); }
.perk button {
  min-width: 78px; height: 44px; padding: 0 10px; border: none; border-radius: 14px;
  background: var(--good); color: #fff; font-size: 15px; font-weight: 800; box-shadow: 0 3px 0 #1f5a22;
}
.perk button:disabled { background: #d8c6a4; color: #fff; box-shadow: none; }
.perk button.max { background: none; color: var(--muted); box-shadow: none; }
.reward { display: inline-flex; gap: 6px; margin-top: 4px; padding: 6px 14px; border-radius: 99px; background: #fff0c8; color: #8a5a0c; font-weight: 800; font-size: 18px; }

/* --- карта уровней --- */
.map-screen { display: block; padding: 0; background: #3b2a26; }
.map-head {
  position: absolute; top: 0; left: 0; right: 0; z-index: 3;
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: linear-gradient(#2a1c14, rgba(42, 28, 20, 0)); color: #fff;
}
.map-head h2 { margin: 0; font-size: 22px; }
.map-scroll { position: absolute; inset: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.map { position: relative; margin: 0 auto; }
.map-art { display: block; }
.map-gate {
  position: absolute; left: 50%; transform: translateX(-50%);
  padding: 8px 16px; border-radius: 14px; background: rgba(0, 0, 0, .55); color: #fff;
  font-weight: 800; text-align: center; white-space: nowrap;
}
.map-gate small { display: block; font-weight: 500; opacity: .75; }

.node {
  position: absolute; transform: translate(-50%, -50%);
  width: 54px; height: 54px; border: 4px solid #fff; border-radius: 50%;
  background: #fff7e8; color: var(--ink); font-size: 20px; font-weight: 800;
  box-shadow: 0 5px 0 rgba(0, 0, 0, .3); padding: 0;
}
.node span { display: grid; place-items: center; width: 100%; height: 100%; }
.node i {
  position: absolute; right: -6px; bottom: -4px; width: 22px; height: 22px; border-radius: 50%;
  background: var(--good); color: #fff; font-size: 13px; font-style: normal; line-height: 22px; border: 2px solid #fff;
}
.node.done { background: #e9f5e3; color: var(--good); }
.node.current { background: var(--accent); color: #fff; animation: pulse 1.2s ease-in-out infinite; }
.node.locked { background: #cdbba0; color: #7a6a58; border-color: #e6d8c0; box-shadow: 0 4px 0 rgba(0, 0, 0, .25); }
.node.bonus { background: #ffd24a; border-color: #fff3c4; font-size: 24px; }
.node.boss { width: 70px; height: 70px; background: #c0392b; border-color: #ffb3a7; font-size: 32px; }
.node.boss.locked, .node.bonus.locked { filter: grayscale(.7) brightness(.85); }
.node-label {
  position: absolute; transform: translateX(-50%);
  padding: 2px 10px; border-radius: 99px; background: rgba(0, 0, 0, .55); color: #fff;
  font-size: 12.5px; font-weight: 700; white-space: nowrap; pointer-events: none;
}
.node-label.boss { background: #8e1f16; }
@keyframes pulse { 50% { transform: translate(-50%, -50%) scale(1.12); } }

[hidden] { display: none !important; }
