:root {
  --bg: #0d120e;
  --bg2: #151d17;
  --panel: #1a221c;
  --panel2: #222c25;
  --line: #34433a;
  --text: #ece6d6;
  --muted: #9aa597;
  --gold: #e8b931;
  --gold2: #b8860b;
  --red: #ff5d5d;
  --green: #5ee37a;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif; overflow: hidden; overscroll-behavior: none; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
#app { position: fixed; inset: 0; }
.screen { position: absolute; inset: 0; display: none; }
.screen.active { display: flex; flex-direction: column; }
.hidden { display: none !important; }

button { font: inherit; color: inherit; cursor: pointer; }
.btn { border: 1px solid var(--line); background: var(--panel2); padding: 12px 16px; border-radius: 12px; font-weight: 700; font-size: 15px; transition: transform .08s, filter .15s; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; }
.btn.gold { background: linear-gradient(180deg, #f3cd52, #c9930f); color: #1d1503; border-color: #f7d56e; box-shadow: 0 4px 0 #7a5806, 0 8px 22px rgba(232,185,49,.25); }
.btn.gold:active { box-shadow: 0 2px 0 #7a5806; transform: translateY(2px); }
.btn.big { padding: 16px; font-size: 17px; }
.btn.small { padding: 8px 12px; font-size: 13px; }
.btn.ghost { background: transparent; }

/* ---------- меню ---------- */
#scr-menu { background: radial-gradient(ellipse at 50% 20%, #1f3324 0%, var(--bg) 65%); overflow-y: auto; }
.menu-wrap { width: 100%; max-width: 420px; margin: 0 auto; padding: 28px 18px calc(24px + var(--safe-b)); display: flex; flex-direction: column; gap: 22px; min-height: 100%; }
.logo { text-align: center; margin-top: 4vh; }
.logo-tower { font-size: 64px; filter: drop-shadow(0 6px 18px rgba(232,185,49,.35)); animation: bob 3s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-6px); } }
.logo h1 { font-family: Cinzel, serif; font-weight: 900; font-size: 44px; line-height: .95; margin: 8px 0 6px; letter-spacing: 1px; background: linear-gradient(180deg, #fff3c4, var(--gold) 55%, var(--gold2)); -webkit-background-clip: text; background-clip: text; color: transparent; text-shadow: 0 2px 0 rgba(0,0,0,.2); }
.logo .tag { margin: 0; color: var(--muted); letter-spacing: 3px; text-transform: uppercase; font-size: 12px; }
.menu-card { background: rgba(26,34,28,.85); border: 1px solid var(--line); border-radius: 18px; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
input { font: inherit; color: var(--text); background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; font-size: 16px; outline: none; width: 100%; }
input:focus { border-color: var(--gold2); }
.join-row { display: flex; gap: 8px; }
#inp-code { text-transform: uppercase; letter-spacing: 4px; text-align: center; font-weight: 800; }
.rules { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; color: var(--muted); font-size: 14px; }
.rules li { padding-left: 18px; position: relative; }
.rules li::before { content: '◆'; position: absolute; left: 0; color: var(--gold2); font-size: 10px; top: 4px; }
.rules b { color: var(--text); }
.conn { text-align: center; color: var(--muted); font-size: 12px; margin-top: auto; }

/* ---------- лобби ---------- */
#scr-lobby { background: radial-gradient(ellipse at 50% 0%, #1f3324 0%, var(--bg) 60%); overflow-y: auto; }
.lobby-wrap { width: 100%; max-width: 440px; margin: 0 auto; padding: 16px 16px calc(20px + var(--safe-b)); display: flex; flex-direction: column; gap: 14px; }
.lobby-head { display: flex; align-items: center; justify-content: space-between; }
.room-code { font-size: 14px; color: var(--muted); }
.room-code b { font-family: Cinzel, serif; color: var(--gold); font-size: 24px; letter-spacing: 3px; margin-left: 6px; }
.lobby-count { color: var(--muted); font-size: 13px; text-align: center; }
.plist { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.plist li { display: flex; align-items: center; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.plist .dot { width: 14px; height: 14px; border-radius: 50%; box-shadow: 0 0 10px currentColor; flex: none; }
.plist .nm { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plist .crown { font-size: 14px; }
.plist .kick { background: none; border: none; color: var(--muted); font-size: 18px; padding: 0 4px; }
.plist li.empty { opacity: .35; border-style: dashed; justify-content: center; font-size: 13px; }
.host-tools { display: grid; gap: 10px; }
.wait-host { text-align: center; color: var(--muted); font-size: 14px; padding: 10px; }
.wait-host.small { font-size: 13px; padding: 6px 0 0; }

/* ---------- игра ---------- */
#scr-game { background: var(--bg); }
#hud { padding: 8px 10px 6px; background: linear-gradient(180deg, #121a14, rgba(18,26,20,.92)); border-bottom: 1px solid var(--line); flex: none; z-index: 2; }
.hud-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.wave { display: flex; flex-direction: column; }
.wave span { font-family: Cinzel, serif; font-weight: 900; font-size: 18px; color: var(--gold); }
.wave small, .gold-box small { color: var(--muted); font-size: 11px; }
.gold-box { display: flex; flex-direction: column; align-items: flex-end; }
.gold-box span { font-weight: 800; font-size: 20px; }
.gold-box span::before { content: '🪙 '; font-size: 16px; }
.hpbar { position: relative; height: 16px; margin-top: 6px; background: #2a1414; border-radius: 8px; overflow: hidden; border: 1px solid #4a2424; }
.hpfill { position: absolute; inset: 0 auto 0 0; width: 100%; background: linear-gradient(180deg, #7ef08f, #2fae4a); transition: width .2s linear, background .3s; }
.hpbar span { position: absolute; inset: 0; text-align: center; font-size: 11px; font-weight: 800; line-height: 15px; text-shadow: 0 1px 2px #000; }
.chips { display: flex; gap: 6px; overflow-x: auto; margin-top: 6px; scrollbar-width: none; padding-bottom: 1px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; display: flex; flex-direction: column; gap: 3px; min-width: 64px; max-width: 92px; padding: 4px 7px; background: var(--panel); border: 1px solid var(--line); border-radius: 9px; font-size: 11px; }
.chip.me { border-color: var(--gold2); }
.chip.dead { opacity: .4; }
.chip .cn { display: flex; align-items: center; gap: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.chip .cd { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.chip .cb { height: 4px; background: #2a1414; border-radius: 2px; overflow: hidden; }
.chip .cb i { display: block; height: 100%; background: var(--green); }

#stage { position: relative; flex: 1 1 auto; min-height: 0; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.cam-btn { position: absolute; left: 10px; bottom: 10px; width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: rgba(26,34,28,.85); font-size: 20px; }
.abil { position: absolute; right: 10px; bottom: 10px; display: flex; flex-direction: column; gap: 10px; }
.ab { position: relative; width: 58px; height: 58px; border-radius: 50%; border: 2px solid var(--gold2); background: radial-gradient(circle at 35% 30%, #3a4a3e, #19221b); font-size: 26px; display: grid; place-items: center; box-shadow: 0 4px 14px rgba(0,0,0,.5); overflow: hidden; }
.ab .cdv { position: absolute; inset: 0; background: conic-gradient(rgba(0,0,0,.65) var(--p, 0%), transparent 0); display: grid; place-items: center; font-size: 14px; font-weight: 800; }
.ab.locked { border-color: var(--line); filter: grayscale(.6); }
.ab .price { position: absolute; bottom: 4px; left: 0; right: 0; font-size: 10px; font-weight: 800; text-align: center; color: var(--gold); text-shadow: 0 1px 2px #000; }
.ab.ready { animation: glow 1.4s ease-in-out infinite; }
@keyframes glow { 50% { box-shadow: 0 0 18px rgba(232,185,49,.7); } }
#toasts { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; width: 92%; }
.toast { background: rgba(10,14,11,.88); border: 1px solid var(--line); padding: 6px 12px; border-radius: 10px; font-size: 12px; font-weight: 600; animation: tin .25s ease-out, tout .4s ease-in 2.6s forwards; text-align: center; }
.toast.bad { border-color: #8a2a2a; color: #ffb3b3; }
.toast.big { font-family: Cinzel, serif; font-size: 18px; color: var(--gold); padding: 8px 18px; }
@keyframes tin { from { opacity: 0; transform: translateY(-8px); } }
@keyframes tout { to { opacity: 0; transform: translateY(-6px); } }
.dead-banner { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: rgba(10,14,11,.85); border: 1px solid #8a2a2a; padding: 12px 18px; border-radius: 14px; text-align: center; display: none; pointer-events: none; }
.dead-banner.show { display: block; }
.dead-banner b { font-family: Cinzel, serif; color: var(--red); font-size: 22px; display: block; }

#panel { flex: none; height: 41%; max-height: 360px; min-height: 230px; background: var(--panel); border-top: 1px solid var(--line); display: flex; flex-direction: column; padding-bottom: var(--safe-b); }
.tabs { display: flex; flex: none; }
.tab { flex: 1; background: none; border: none; border-bottom: 2px solid transparent; padding: 10px; font-weight: 700; color: var(--muted); font-size: 14px; }
.tab.active { color: var(--gold); border-color: var(--gold); }
.tabbody { flex: 1; overflow-y: auto; padding: 8px 10px 12px; -webkit-overflow-scrolling: touch; }
.stats { font-size: 11px; color: var(--muted); margin-bottom: 8px; line-height: 1.5; }
.stats b { color: var(--text); }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.card { min-width: 0; display: grid; grid-template-columns: 28px minmax(0, 1fr); grid-template-rows: auto auto auto; gap: 0 8px; align-items: center; text-align: left; background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 7px 9px; transition: transform .08s, border-color .15s; }
.card:active { transform: scale(.97); }
.card .ic { grid-row: span 3; font-size: 22px; text-align: center; }
.card .t { font-size: 13px; font-weight: 700; display: flex; justify-content: space-between; gap: 4px; white-space: nowrap; }
.card .t > span:first-child { overflow: hidden; text-overflow: ellipsis; }
.card .t small { color: var(--muted); font-weight: 600; flex: none; }
.card .d { font-size: 10.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .c { font-size: 13px; font-weight: 800; color: var(--gold); margin-top: 1px; }
.card.na { opacity: .5; }
.card.na .c { color: #b58a5a; }
.card.max .c { color: var(--green); }
.card.flash { border-color: var(--gold); }
.tgt-label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.tgt-row { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 8px; scrollbar-width: none; }
.tgt-row::-webkit-scrollbar { display: none; }
.tgt { flex: none; padding: 6px 10px; border-radius: 9px; border: 1px solid var(--line); background: var(--panel2); font-size: 12px; font-weight: 600; display: flex; align-items: center; gap: 5px; }
.tgt.active { border-color: var(--gold); color: var(--gold); }
.tgt .cd { width: 8px; height: 8px; border-radius: 50%; }
.hint { font-size: 11px; color: var(--muted); margin: 10px 2px 0; }

/* ---------- итоги ---------- */
.overlay { position: absolute; inset: 0; background: rgba(5,8,6,.78); display: grid; place-items: center; z-index: 10; padding: 16px; backdrop-filter: blur(3px); }
.over-card { width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--gold2); border-radius: 18px; padding: 18px; box-shadow: 0 20px 60px rgba(0,0,0,.6); max-height: 92%; overflow-y: auto; }
.over-card h2 { font-family: Cinzel, serif; text-align: center; color: var(--gold); margin: 0 0 14px; font-size: 24px; }
.results { list-style: none; padding: 0; margin: 0 0 16px; display: grid; gap: 6px; }
.results li { display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 8px; background: var(--panel2); border-radius: 12px; padding: 9px 12px; border: 1px solid var(--line); }
.results li.me { border-color: var(--gold2); }
.results .pl { font-size: 20px; text-align: center; font-weight: 800; color: var(--muted); }
.results .rn { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.results .rn small { display: block; color: var(--muted); font-weight: 500; font-size: 11px; }
.results .rw { font-size: 12px; color: var(--muted); text-align: right; }
.results .rw b { color: var(--text); font-size: 15px; display: block; }
.over-btns { display: grid; gap: 8px; }

.err { position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%); background: #3a1515; border: 1px solid #8a2a2a; color: #ffd0d0; padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 20; max-width: 90%; text-align: center; }

/* ---------- магия / графика ---------- */
.grid.one { grid-template-columns: minmax(0, 1fr); }
@media (min-width: 560px) { .grid.one { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.spell { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; align-items: center; gap: 4px 10px; text-align: left; background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 9px 10px; position: relative; overflow: hidden; }
.spell::before { content: ''; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--sc, #888); }
.spell .si { font-size: 26px; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; background: radial-gradient(circle, color-mix(in srgb, var(--sc) 35%, transparent), transparent 70%); }
.spell .sn { font-weight: 800; font-size: 14px; }
.spell .sn small { color: var(--muted); font-weight: 600; margin-left: 4px; }
.spell .sd { font-size: 11px; color: var(--muted); grid-column: 2; line-height: 1.35; }
.spell .sb { grid-row: span 2; grid-column: 3; font-weight: 800; font-size: 13px; color: #1d1503; background: linear-gradient(180deg, #f3cd52, #c9930f); border-radius: 10px; padding: 8px 10px; white-space: nowrap; }
.spell.na .sb { background: #3a3a33; color: #b58a5a; }
.spell.max .sb { background: transparent; color: var(--green); }
.spell.owned { border-color: color-mix(in srgb, var(--sc) 55%, var(--line)); }
.spell:active { transform: scale(.98); }
.gfx-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 13px; color: var(--muted); }
.seg { display: flex; background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button { background: none; border: none; padding: 6px 10px; border-radius: 7px; font-size: 12px; font-weight: 700; color: var(--muted); }
.seg button.on { background: var(--panel2); color: var(--gold); box-shadow: inset 0 0 0 1px var(--gold2); }
.fnum { position: absolute; left: 0; top: 0; font-weight: 900; font-size: 14px; pointer-events: none; text-shadow: 0 2px 3px rgba(0,0,0,.8); white-space: nowrap; z-index: 3; }
.ab { width: 52px; height: 52px; font-size: 23px; }
.abil { gap: 8px; }
