:root {
  --bg: #0b0d10;
  --line: #2d2a22;
  --gold: #d6b25e;
  --gold2: #8c6d2f;
  --text: #e8e2d0;
  --muted: #8e8a7e;
  --radiant: #6fd36a;
  --dire: #e2503a;
  --serif: Georgia, "Times New Roman", serif;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 14px/1.3 -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
#app { height: var(--tg-viewport-stable-height, 100vh); max-width: 520px; margin: 0 auto; position: relative; overflow: hidden; }
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; }
.hidden { display: none !important; }

/* ——— карта уровней ——— */
#menu {
  overflow-y: auto; padding: 0 12px 28px;
  background:
    radial-gradient(120% 50% at 0% 0%, rgba(111, 211, 106, .13), transparent 60%),
    radial-gradient(120% 50% at 100% 100%, rgba(226, 80, 58, .14), transparent 60%),
    var(--bg);
}
.brand { text-align: center; padding: 24px 0 8px; position: relative; }
.lang {
  position: absolute; top: 12px; right: 0; height: 30px; min-width: 44px; padding: 0 10px; border-radius: 15px;
  border: 1px solid var(--gold2); background: #1b1e25; color: #f0e2b8; font-weight: 700; font-size: 12px; letter-spacing: .08em;
}
.lang:active { transform: scale(.94); }
.logo {
  width: 58px; height: 58px; margin: 0 auto; border-radius: 50%;
  background: linear-gradient(135deg, var(--radiant) 0 48%, #111 48% 52%, var(--dire) 52% 100%);
  border: 3px solid var(--gold); box-shadow: 0 0 24px rgba(214, 178, 94, .35), inset 0 0 12px rgba(0, 0, 0, .6);
}
.brand h1 {
  margin: 10px 0 2px; font-family: var(--serif); font-size: 27px; letter-spacing: .06em; text-transform: uppercase;
  color: #e9c979; background: linear-gradient(#f7e3a6, #b8872f); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.brand p { margin: 0; color: var(--muted); font-size: 11px; letter-spacing: .16em; text-transform: uppercase; }

.act { margin: 14px 0; border: 1px solid var(--line); border-radius: 10px; background: linear-gradient(180deg, #171a20, #101216); overflow: hidden; position: relative; }
.act::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 2px; background: linear-gradient(90deg, transparent, var(--act), transparent); }
.act-head { display: flex; align-items: baseline; gap: 8px; padding: 11px 12px 4px; }
.act-num { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .14em; }
.act-head b { font-family: var(--serif); font-size: 16px; color: #f0e2b8; font-weight: 400; }
.act-stars { margin-left: auto; font-size: 12px; color: var(--gold); }
.levels { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; padding: 10px 10px 12px; }
.lvl {
  position: relative; aspect-ratio: 1; border-radius: 8px; border: 1px solid #3a3428; padding: 0;
  background: linear-gradient(180deg, #272b34, #1a1d23);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.lvl .num { font-size: 17px; font-weight: 700; }
.lvl .stars { font-size: 10px; color: #4f4a3f; letter-spacing: 1px; }
.lvl.done .stars { color: var(--gold); }
.lvl.boss { border-color: var(--gold2); box-shadow: inset 0 0 14px rgba(214, 178, 94, .18); }
.lvl .tag {
  position: absolute; top: -7px; left: 50%; transform: translateX(-50%); font-size: 8px; padding: 1px 4px; border-radius: 4px;
  background: var(--gold2); color: #140f05; text-transform: uppercase; font-weight: 800; white-space: nowrap; letter-spacing: .04em;
}
.lvl.locked { opacity: .4; }
.lvl.next { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold), 0 0 14px rgba(214, 178, 94, .35); }
.lvl:not(.locked):active { transform: scale(.95); }

.roster { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 18px; }
.roster-title { grid-column: 1 / -1; font-family: var(--serif); text-transform: uppercase; letter-spacing: .12em; color: var(--muted); font-size: 12px; text-align: center; }
.rh { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 9px 4px; border: 1px solid var(--line); border-radius: 8px; background: #13151a; font-size: 12px; }

.orb {
  font-style: normal; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  background: var(--c); background: radial-gradient(circle at 35% 30%, #fff8 0, transparent 45%), var(--c);
  color: #15110a; font-weight: 800; font-size: 17px; border: 2px solid #6b5b43; box-shadow: inset 0 -4px 8px rgba(0, 0, 0, .35);
}
.locked .orb { filter: grayscale(1) brightness(.6); }
small { color: var(--muted); font-size: 11px; }

/* ——— бой ——— */
#play { background: var(--bg); }
.hud { display: flex; align-items: center; gap: 6px; padding: 6px 8px; background: linear-gradient(180deg, #1c1f26, #121419); border-bottom: 1px solid var(--gold2); }
.icon { min-width: 36px; height: 32px; padding: 0 6px; border-radius: 6px; border: 1px solid #3a3428; background: #20242c; font-weight: 700; }
.stat { display: flex; align-items: center; gap: 5px; padding: 5px 8px; border-radius: 6px; background: #0e1014; border: 1px solid #2a2720; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat.gold i { width: 12px; height: 12px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #fff3b0, #e0a92e 60%, #8a6212); }
.stat.lives i { width: 11px; height: 13px; background: var(--radiant); clip-path: polygon(50% 0, 100% 40%, 50% 100%, 0 40%); }
body[data-side="dire"] .stat.lives i { background: var(--dire); }
.stat.lives.hurt { animation: hurt .4s; }
@keyframes hurt { 30% { background: #5a1510; border-color: var(--dire); } }
.stat.wave { font-weight: 400; color: var(--muted); margin-left: auto; font-size: 12px; }
.stat.wave b { color: var(--text); }

.field { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; position: relative; overflow: hidden; }
#cv { display: block; border-radius: 4px; box-shadow: 0 0 0 1px #2d2a22, 0 8px 28px rgba(0, 0, 0, .6); touch-action: none; }
.banner {
  position: absolute; top: 16%; left: 0; right: 0; text-align: center; pointer-events: none; opacity: 0;
  padding: 10px 0; background: linear-gradient(90deg, transparent, rgba(8, 8, 10, .85) 25%, rgba(8, 8, 10, .85) 75%, transparent);
}
.banner b { display: block; font-family: var(--serif); font-weight: 400; font-size: 21px; color: #f4dd9a; letter-spacing: .06em; text-transform: uppercase; }
.banner span { font-size: 12px; color: #cfc7b0; }
.banner.on { animation: ban 2.6s ease forwards; }
@keyframes ban { 0% { opacity: 0; transform: translateY(-8px); } 12% { opacity: 1; transform: none; } 75% { opacity: 1; } 100% { opacity: 0; } }
.paused-mark { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0, 0, 0, .45); font-family: var(--serif); font-size: 24px; letter-spacing: .2em; color: #f4dd9a; pointer-events: none; }

.panel { min-height: 148px; padding: 8px 10px calc(10px + env(safe-area-inset-bottom)); background: linear-gradient(180deg, #171a20, #0e1014); border-top: 1px solid var(--gold2); }
.p-head { display: flex; align-items: center; gap: 9px; margin-bottom: 7px; min-height: 30px; }
.p-head b { font-family: var(--serif); font-weight: 400; font-size: 16px; color: #f0e2b8; }
.p-head .lv { color: var(--gold); font-size: 12px; }
.p-head .orb { width: 30px; height: 30px; font-size: 15px; }
.x { margin-left: auto; width: 30px; height: 30px; border-radius: 6px; border: 1px solid #3a3428; background: #20242c; }
.hero-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
.hcard { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 7px 1px 6px; border-radius: 8px; border: 1px solid #3a3428; background: #1d2027; font-size: 10.5px; white-space: nowrap; }
.hcard .orb { width: 30px; height: 30px; font-size: 15px; }
.hcard small { color: var(--gold); font-size: 10.5px; }
.hcard.locked small { color: var(--muted); }
.hcard:disabled { opacity: .42; }
.hcard:not(:disabled):active { transform: scale(.94); }

.hint { color: var(--muted); font-size: 12px; text-align: center; margin: 8px 0 12px; }
.btn {
  width: 100%; height: 48px; border-radius: 8px; border: 1px solid var(--gold2);
  background: linear-gradient(180deg, #3d5f2b, #213619); color: #eef7dc; font-size: 16px; font-weight: 700; letter-spacing: .03em;
}
body[data-side="dire"] .btn.call { background: linear-gradient(180deg, #6e2c21, #3b1611); color: #ffe6db; }
.btn:disabled { opacity: .5; }
.btn:not(:disabled):active { filter: brightness(1.2); }
.btn small { font-weight: 400; color: inherit; opacity: .85; font-size: 12px; margin-left: 6px; }
.t-stats { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.t-stats b { color: var(--text); }
.t-desc { font-size: 12px; color: #b3ac9a; margin: 5px 0 9px; }
.t-actions { display: grid; grid-template-columns: 1.7fr 1fr; gap: 6px; }
.btn.up { height: 42px; font-size: 14px; background: linear-gradient(180deg, #5b4a1f, #362b10); color: #ffe9b0; }
.btn.sell { height: 42px; font-size: 13px; background: linear-gradient(180deg, #33302a, #211e18); border-color: #4a4030; color: #d9ccaa; }

/* ——— окна ——— */
.modal { position: absolute; inset: 0; background: rgba(0, 0, 0, .62); display: grid; place-items: center; z-index: 10; }
.card { width: min(86%, 340px); padding: 22px 16px 14px; border-radius: 12px; border: 1px solid var(--gold2); background: linear-gradient(180deg, #1d2027, #111317); text-align: center; box-shadow: 0 20px 60px rgba(0, 0, 0, .7); }
.card h2 { margin: 0 0 6px; font-family: var(--serif); font-weight: 400; text-transform: uppercase; letter-spacing: .07em; color: #f4dd9a; }
.card h2.bad { color: #ff8a70; }
.big-stars { font-size: 40px; color: var(--gold); letter-spacing: 6px; margin: 2px 0; }
.big-stars .dim { color: #3a362d; }
.card p { color: #b3ac9a; margin: 6px 0 16px; font-size: 13px; }
.card .row { display: grid; gap: 7px; }
.card .btn.ghost { background: #1d2027; border-color: #3a3428; color: var(--text); height: 42px; font-size: 14px; }

/* ——— портреты ——— */
.orb { position: relative; overflow: hidden; }
.orb img { position: absolute; left: 0; top: 0; width: 100%; height: 100%; transform: scale(1.5) translateY(14%); pointer-events: none; }
.orb em { position: absolute; inset: 0; display: grid; place-items: center; font-style: normal; font-size: 14px; background: rgba(0, 0, 0, .45); }
.rh .orb { width: 46px; height: 46px; }
.rh.foe .orb { background: radial-gradient(circle at 50% 40%, #3b2a30, #17121a); border-color: #5a2a24; }
.rh.foe .orb img { transform: scale(1.2) translateY(4%); }
.rh small { text-align: center; }
#bestiary { margin-top: 12px; }

/* ——— способности ——— */
.ults { display: flex; gap: 8px; padding: 6px 10px; min-height: 58px; background: #0e1014; border-top: 1px solid #2a2720; overflow-x: auto; align-items: center; }
.ults:empty { display: none; }
.ult {
  position: relative; flex: 0 0 auto; width: 46px; height: 46px; padding: 0; border-radius: 50%; overflow: hidden;
  border: 2px solid #4a4030; background: radial-gradient(circle at 50% 35%, #2c3038, #15171c);
}
.ult img { position: absolute; left: 0; top: 0; width: 100%; height: 100%; transform: scale(1.45) translateY(14%); pointer-events: none; }
.ult::after { content: ""; position: absolute; inset: 0; background: conic-gradient(rgba(0, 0, 0, .72) calc(var(--p, 0) * 360deg), transparent 0); pointer-events: none; }
.ult .cd { position: absolute; inset: 0; display: grid; place-items: center; z-index: 1; font-weight: 800; font-size: 15px; color: #fff; text-shadow: 0 1px 3px #000; }
.ult.ready { border-color: #f3cf6a; box-shadow: 0 0 12px rgba(243, 207, 106, .55); animation: ready 1.6s ease-in-out infinite; }
.ult.off { filter: grayscale(1) brightness(.55); }
.ult:active { transform: scale(.92); }
@keyframes ready { 50% { box-shadow: 0 0 18px rgba(243, 207, 106, .9); } }
.ab { color: #f3cf6a; }
.t-desc .ab { font-weight: 700; }

/* ——— карточки нового героя/врага ——— */
.intro-item { display: flex; gap: 12px; align-items: center; text-align: left; margin: 10px 0; }
.intro-item > img { flex: 0 0 auto; width: 72px; height: 72px; border-radius: 12px; background: radial-gradient(circle at 50% 40%, #2c3a2c, #121614); border: 1px solid var(--gold2); }
.intro-item.foe > img { background: radial-gradient(circle at 50% 40%, #3b2a30, #17121a); border-color: #6a2f26; }
.intro-item small { color: var(--gold); text-transform: uppercase; letter-spacing: .1em; font-size: 10px; }
.intro-item b { display: block; font-family: var(--serif); font-weight: 400; font-size: 16px; color: #f0e2b8; }
.intro-item p { margin: 3px 0 0; font-size: 12px; color: #b3ac9a; }
.intro-item p.ab { color: #f3cf6a; }
.card { max-height: 88%; overflow-y: auto; }

/* ——— обучение и «Как играть» ——— */
.tut-ring {
  position: absolute; z-index: 8; pointer-events: none; border-radius: 10px; border: 2px solid #f3cf6a;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, .3), 0 0 16px rgba(243, 207, 106, .8); animation: tut 1.2s ease-in-out infinite;
}
@keyframes tut { 50% { border-color: #fff3c0; box-shadow: 0 0 0 9999px rgba(0, 0, 0, .3), 0 0 26px rgba(243, 207, 106, 1); } }
.tut-tip {
  position: absolute; z-index: 9; pointer-events: none; padding: 10px 12px 6px; border-radius: 10px; border: 1px solid var(--gold);
  background: linear-gradient(180deg, #262a33, #16181d); box-shadow: 0 10px 30px rgba(0, 0, 0, .6); text-align: center;
}
.tut-tip p { margin: 0 0 4px; font-size: 13.5px; line-height: 1.35; color: #f0e2b8; }
.tut-skip { pointer-events: auto; border: 0; background: none; color: var(--muted); font-size: 11px; text-decoration: underline; padding: 4px 8px; }
.lang.help { left: 0; right: auto; letter-spacing: .02em; }

/* ——— «Позвать друга», «Отзыв», «Поделиться» ——— */
.brand-actions { display: flex; gap: 8px; justify-content: center; margin-top: 12px; }
.pill { height: 32px; padding: 0 14px; border-radius: 16px; border: 1px solid var(--gold2); background: #1b1e25; color: #f0e2b8; font-size: 12.5px; font-weight: 600; }
.pill:active { transform: scale(.95); }
.card .btn.share { background: linear-gradient(180deg, #2f5a78, #1a3346); border-color: #4c86ad; color: #e3f2ff; height: 42px; font-size: 14px; }
.card .btn.small { height: 36px; font-size: 12.5px; color: var(--muted); }
.rules { text-align: left; margin: 8px 0 14px; padding-left: 20px; color: #b3ac9a; font-size: 13px; }
.rules li { margin: 7px 0; }
.rules b { color: #f0e2b8; font-weight: 600; }
