/* In-game HUD in the same glass style as Telegram's own buttons, so they read as one interface. */
:root {
  --tg-top: 0px;
  --tg-bar: 0px;
  --glass: rgba(18, 16, 26, .58);
  --glass-line: rgba(255, 255, 255, .1);
  --glass-shadow: 0 4px 16px rgba(0, 0, 0, .35);
}
#hud .frame, #hud .mini-btn, #hud .belt-btn {
  background: var(--glass);
  border: 1px solid var(--glass-line);
  box-shadow: var(--glass-shadow);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

/* Hero pill */
#hero-box { border-radius: 24px; padding: 5px 12px 5px 5px; gap: 9px; width: min(46vw, 230px); align-items: center; }
#portrait { width: 36px; height: 36px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .2); background: radial-gradient(circle at 50% 35%, #4a5a8a, #161a2a); }
#portrait img, #portrait img.photo { border-radius: 50%; }
#lvl-badge {
  right: -5px; bottom: -5px; min-width: 17px; height: 17px; line-height: 15px; font-size: 10px; font-weight: 800;
  border-radius: 9px; border: 1px solid rgba(0, 0, 0, .55); box-shadow: none;
}
#hud .bar { border: 0; border-radius: 6px; background: rgba(0, 0, 0, .45); margin-top: 3px; }
#hud .bar .fill, #hud .bar .ghost { border-radius: 6px; }
#hud .bar .fill::after { border-radius: 6px 6px 0 0; }
#hud .hero-info .bar:first-of-type { margin-top: 0; }
#hud .bar.hp { height: 12px; }
#hud .bar.hp span { font-size: 8px; line-height: 12px; }
#hud .bar.mp { height: 7px; }
#hud .bar.mp span { display: none; }
#hud .bar.xp { height: 3px; }
#hud .bar.run { height: 4px; }
#hud .bar.run span { display: none; }

/* Map card + round pause / bag */
#map-box { border-radius: 16px; padding: 5px; width: 94px; }
#minimap { border: 0; border-radius: 11px; background: rgba(0, 0, 0, .35); }
.map-info { padding: 0 2px; }
#hud .mini-btn {
  width: 38px; height: 38px; border-radius: 50%; gap: 4px;
  right: calc(110px + var(--sa-r)); top: calc(8px + var(--sa-t));
}
#hud .mini-btn i { width: 4px; height: 13px; background: #fff; border-radius: 2px; box-shadow: none; }
#hud .belt-btn { border-radius: 50%; }

/* ---------- Fullscreen Telegram: cards wrap around Telegram's own buttons ----------
   Telegram draws "Close" (top-left) and "v ..." (top-right) inside a strip of height --tg-bar.
   The hero card and the map card start in that strip, so each native button sits inside our card. */
:root { --tg-l: 0px; --tg-r: 0px; }
#tg-wrap-l { display: none; }
body.tg-bar #hero-box {
  top: calc(var(--tg-top) + 2px); left: calc(var(--tg-l) + 8px); transform: none;
  padding-top: calc(var(--tg-bar) + 2px); border-radius: 22px; width: min(52vw, 220px);
}
body.tg-bar #map-box {
  top: calc(var(--tg-top) + 2px); right: calc(var(--tg-r) + 8px);
  padding: calc(var(--tg-bar) + 2px) 6px 6px; border-radius: 22px; width: 102px;
}
body.tg-bar #minimap { width: 90px; height: 90px; }
/* Pause shares the hero card's top row with "Close", at the card's right end. */
body.tg-bar #hud .mini-btn {
  left: calc(var(--tg-l) + 8px + min(52vw, 220px) - 46px); right: auto;
  top: calc(var(--tg-top) + 2px + (var(--tg-bar) - 38px) / 2);
}
body.tg-bar #boss-bar { top: calc(var(--sa-t) + 70px); }
body.tg-bar #toasts { top: calc(var(--sa-t) + 110px); }

/* Wide screens: the hero pill takes the centre of the strip; a small card wraps "Close" and holds pause. */
@media (min-width: 600px) {
  body.tg-bar #hero-box {
    left: 50%; transform: translateX(-50%); padding-top: 5px;
    top: calc(var(--tg-top) + max(2px, (var(--tg-bar) - 48px) / 2));
    width: min(34vw, 300px);
  }
  body.tg-bar #tg-wrap-l {
    display: block; position: absolute; pointer-events: none;
    top: calc(var(--tg-top) + 2px); left: calc(var(--tg-l) + 8px);
    width: 128px; height: calc(var(--tg-bar) + 48px); border-radius: 22px;
  }
  body.tg-bar #hud .mini-btn { left: calc(var(--tg-l) + 72px); top: calc(var(--tg-top) + var(--tg-bar) + 2px); }
  body.tg-bar #boss-bar { top: calc(var(--tg-top) + var(--tg-bar) + 12px); }
  body.tg-bar #toasts { top: calc(var(--tg-top) + var(--tg-bar) + 50px); }
}

/* ---------- Title: 3D hero by the fire instead of the pixel sprite ---------- */
#title-screen { justify-content: space-between; padding: calc(28px + var(--sa-t)) 16px calc(54px + var(--sa-b)); }
#title-screen { background: linear-gradient(rgba(6, 5, 12, .75), rgba(6, 5, 12, 0) 26%, rgba(6, 5, 12, 0) 52%, rgba(6, 5, 12, .9) 74%); }
#title-screen .title-hero { display: none; }
body.cover #title-screen { justify-content: center; }

/* Fortress defence is switched off for now (code kept): hide its entry points. */
#hub-fort, #leaders [data-b="fort"] { display: none !important; }

/* ---------- Hero select: header / 3D stage / name / compact panel, no scrolling ---------- */
#select-screen {
  --cc: #7a5cd6;
  justify-content: flex-start; align-items: stretch; gap: 0; overflow: hidden; touch-action: none;
  padding: calc(8px + var(--sa-t)) 12px calc(10px + var(--sa-b));
  background: linear-gradient(rgba(5, 3, 8, .7), rgba(5, 3, 8, 0) 16%, rgba(5, 3, 8, 0) 46%, rgba(5, 3, 8, .85) 62%, rgba(5, 3, 8, .96));
}
.sel-head { position: relative; display: flex; align-items: center; justify-content: center; min-height: 44px; flex: none; }
#select-screen .sel-back { position: absolute; left: 0; top: 2px; width: 40px; height: 40px; border-radius: 50%; background: var(--glass); border: 1px solid var(--glass-line); color: #fff; font-size: 18px; }
#select-screen .sel-title { margin: 0; font-size: 22px; }
body.tg-bar #select-screen .sel-head { margin-top: 0; }
.sel-stage { position: relative; flex: 1 1 auto; min-height: 120px; }
.sel-arrow { position: absolute; top: 50%; transform: translateY(-50%); width: 44px; height: 44px; border-radius: 50%;
  background: var(--glass); border: 1px solid var(--glass-line); color: #fff; font-size: 30px; line-height: 1; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
#sel-prev { left: 0; }
#sel-next { right: 0; }
.sel-arrow:active { transform: translateY(-50%) scale(.9); }
.sel-name { flex: none; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 0 8px; }
.sel-name b { font-size: 30px; font-weight: 900; color: #fff; line-height: 1; text-shadow: 0 3px 0 rgba(0, 0, 0, .6), 0 0 22px color-mix(in srgb, var(--cc) 60%, transparent); }
.sel-name span { font-size: 12px; font-weight: 800; letter-spacing: 1.2px; text-transform: uppercase; color: var(--cc); }
.sel-dots { display: flex; gap: 8px; margin-top: 6px; }
.sel-dots i { width: 8px; height: 8px; border-radius: 4px; background: rgba(255, 255, 255, .25); transition: width .2s, background .2s; cursor: pointer; }
.sel-dots i.on { width: 22px; background: var(--cc); }
#select-screen .sel-panel {
  flex: none; width: min(100%, 440px); margin: 0 auto; max-height: none; overflow: visible; touch-action: auto;
  padding: 12px; display: flex; flex-direction: column; gap: 8px; text-align: left;
  background: var(--glass); border: 1px solid var(--glass-line); border-radius: 22px; box-shadow: var(--glass-shadow);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
#sel-info { display: flex; flex-direction: column; gap: 7px; }
#select-screen .sel-desc { font-size: 12.5px; line-height: 1.3; margin: 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
#select-screen .sel-bars { gap: 3px 12px; font-size: 12px; }
#select-screen .sel-attack { font-size: 11.5px; padding: 5px 8px; border-radius: 10px; }
#select-screen .sel-skills { gap: 5px; }
#select-screen .sk { gap: 8px; }
#select-screen .sk img { width: 32px; height: 32px; }
#select-screen .sk b { font-size: 13px; }
#select-screen .sk p { font-size: 11.5px; margin: 1px 0 0; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
#select-screen #sel-go { height: 52px; border-radius: 16px; font-size: 18px; margin-top: 2px; }
/* Short screens: drop the secondary text so everything still fits without scrolling. */
@media (max-height: 720px) {
  #select-screen .sel-desc, #select-screen .sk p { display: none; }
  .sel-name b { font-size: 26px; }
}
@media (max-height: 600px) {
  #select-screen .sel-attack { display: none; }
  #select-screen .sel-skills { flex-direction: row; }
  #select-screen .sk { flex: 1; }
  .sel-name { padding-bottom: 4px; }
  #select-screen #sel-go { height: 44px; }
}
/* Landscape: panel on the right, heroes on the left. */
@media (min-aspect-ratio: 4/3) and (max-height: 600px) {
  #select-screen { display: grid; grid-template-columns: 1fr min(46vw, 400px); grid-template-rows: auto 1fr auto; column-gap: 14px; }
  .sel-head { grid-column: 1; }
  .sel-stage { grid-column: 1; grid-row: 2; }
  .sel-name { grid-column: 1; grid-row: 3; }
  #select-screen .sel-panel { grid-column: 2; grid-row: 1 / 4; align-self: center; width: 100%; }
}

/* ---------- Forge hints ---------- */
.fg-intro { display: flex; gap: 10px; align-items: flex-start; background: rgba(255, 210, 120, .07); border: 1px solid rgba(255, 210, 120, .25); border-radius: 12px; padding: 8px 10px; margin-bottom: 10px; }
.fg-intro > b { font-size: 22px; line-height: 1; margin-top: 2px; }
.fg-intro strong { display: block; font-size: 13px; color: #ffd86a; }
.fg-intro p { margin: 2px 0 0; font-size: 11.5px; line-height: 1.35; color: #d8cbb4; }
.fg-sec { font-size: 11px; font-weight: 800; letter-spacing: .8px; text-transform: uppercase; color: var(--muted); margin: 4px 0 5px; }
.forge-grid .slot { position: relative; }
.fg-ok { position: absolute; left: 2px; top: 1px; font-style: normal; font-size: 11px; font-weight: 900; color: #5ee37a; text-shadow: 0 1px 0 #000; }
.fg-rec { position: absolute; left: 50%; bottom: -6px; transform: translateX(-50%); font-style: normal; font-size: 8px; font-weight: 800; text-transform: uppercase; background: #5ee37a; color: #0a2a10; border-radius: 6px; padding: 0 4px; white-space: nowrap; }
.fg-gain { position: absolute; left: 0; right: 0; bottom: 1px; font-style: normal; font-size: 9.5px; font-weight: 800; text-align: center; color: #ffcf8a; text-shadow: 0 1px 0 #000, 0 0 3px #000; white-space: nowrap; }
.fg-power { display: flex; flex-wrap: wrap; gap: 4px 12px; justify-content: center; margin-top: 8px; padding: 6px 8px; border-radius: 10px; background: rgba(94, 227, 122, .08); font-size: 12px; }
.fg-power small { width: 100%; text-align: center; color: var(--muted); font-size: 10.5px; }
.fg-power em { font-style: normal; color: var(--muted); }
.fg-power strong { color: #5ee37a; }
.fg-power.muted { background: rgba(255, 255, 255, .04); color: var(--muted); font-size: 11px; }
.cost small { color: var(--muted); font-weight: 600; font-size: 12px; align-self: center; }
.fg-lack { text-align: center; color: #ff8a7a; font-size: 12px; font-weight: 700; margin: -2px 0 8px; }
.fg-lack small { display: block; color: var(--muted); font-weight: 500; font-size: 10.5px; margin-top: 2px; }
.fg-now { font-size: 12px; color: var(--muted); text-align: center; margin: -2px 0 8px; }

/* ---------- Bag hints ---------- */
.inv-hint { font-size: 11.5px; line-height: 1.35; color: #d8cbb4; background: rgba(255, 210, 120, .07); border: 1px solid rgba(255, 210, 120, .22); border-radius: 10px; padding: 6px 9px; margin: -2px 0 8px; }
.inv-legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 10.5px; color: var(--muted); margin: 2px 0 6px; }
.inv-legend b { font-style: normal; margin-right: 3px; }
.lg-up { color: #5ee37a; }
.lg-no { color: #ff6a6a; }
.lg-r { display: inline-block; width: 10px; height: 10px; border-radius: 3px; vertical-align: -1px; border: 2px solid #5aa9ff; }
#stat-list .st { cursor: pointer; border-radius: 6px; }
#stat-list .st:active { background: rgba(255, 255, 255, .08); }
.slot.nofit img { filter: grayscale(.8) brightness(.6); }
.slot .nf { position: absolute; right: 3px; top: 1px; font-style: normal; font-size: 12px; font-weight: 900; color: #ff6a6a; text-shadow: 0 1px 0 #000; }
.slot.eq .eq-plus { position: absolute; right: 3px; top: 1px; font-style: normal; font-size: 12px; color: #5ee37a; text-shadow: 0 1px 0 #000; animation: hubPulse 1.6s ease-in-out infinite; }
.slot.eq { position: relative; }
#inv-junk small { color: var(--gold); font-weight: 800; }
.inv-tools .chip:disabled { opacity: .45; }
.tt-hint { font-size: 11px; color: var(--muted); text-align: center; margin: 6px 0 2px; line-height: 1.35; }
.tt-btns .btn small { display: block; font-size: 10px; opacity: .8; font-weight: 600; }

/* ---------- Stash hints ---------- */
.stash-tools { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 8px; }
.stash-tools .chip { font-size: 12px; padding: 8px 6px; }
.stash-tools .chip:disabled { opacity: .45; }
.stash-h small { font-weight: 500; color: var(--muted); font-size: 11px; }
.stash-warn { color: #ffb070; font-size: 11.5px; font-weight: 700; margin: -2px 0 6px; }
.stash-warn:empty { display: none; }
.stash-grid .slot { position: relative; }
.st-arrow { position: absolute; left: 2px; bottom: 0; font-style: normal; font-size: 11px; color: #ffd86a; text-shadow: 0 1px 0 #000; opacity: .85; }
#stash .stash-panel { max-height: calc(100vh - 24px - var(--sa-t) - var(--sa-b)); overflow-y: auto; overscroll-behavior: contain; }
#stash #stash-box { max-height: none; overflow: visible; }
#stash .stash-grid { gap: 4px; }

/* ---------- Leaderboard hints ---------- */
#lb-intro .fg-intro { margin: 8px 0 8px; }
.lb-mycard { display: flex; gap: 10px; align-items: center; padding: 8px 10px; margin-bottom: 8px; border-radius: 12px; background: rgba(255, 210, 90, .1); border: 1px solid rgba(255, 210, 90, .4); }
.lb-place { display: flex; flex-direction: column; align-items: center; min-width: 52px; }
.lb-place b { font-size: 24px; font-weight: 900; color: #ffd86a; line-height: 1; }
.lb-place span { font-size: 10.5px; color: var(--muted); }
.lb-mytext strong { font-size: 13px; color: #fff; }
.lb-mytext p { margin: 2px 0 0; font-size: 12px; font-weight: 700; color: #5ee37a; }
.lb-mytext small { display: block; margin-top: 3px; font-size: 11px; line-height: 1.3; color: var(--muted); }
.lb-row .lb-name small { display: block; font-size: 10.5px; font-weight: 600; opacity: .9; }
.lb-you { font-style: normal; font-size: 10px; font-weight: 800; background: #ffd86a; color: #2a1a05; border-radius: 6px; padding: 0 5px; vertical-align: 1px; }

/* HD test: cinematic vignette over the 3D view. */
body.hd #game3d { filter: saturate(1.08); }
body.hd #hud::before { content: ''; position: fixed; inset: 0; pointer-events: none; background: radial-gradient(ellipse at 50% 45%, rgba(0,0,0,0) 55%, rgba(0,0,0,.55) 100%); }

.map-info .fps { position: absolute; top: 6px; left: 8px; font-size: 9px; line-height: 1; padding: 2px 4px; border-radius: 4px; background: rgba(0,0,0,.45); opacity: .85; font-variant-numeric: tabular-nums; pointer-events: none; }
.map-info .fps.low { color: #ff8a7a; opacity: 1; }
/* The map canvas is turned with the 3D camera and changes its aspect: fit it, never stretch. */
#minimap, #bigmap-cv { object-fit: contain; }
