:root {
  --bg: #0c0a14; --panel: rgba(18, 14, 30, 0.82); --panel2: rgba(32, 25, 52, 0.9); --line: rgba(231, 185, 85, 0.22);
  --gold: #e7b955; --gold2: #ffd98a; --violet: #a874ff; --text: #efe7d6; --mute: #a69cb8; --red: #ff6b6b; --green: #7cffb2; --blue: #7fd8ff;
  --r: 14px; --sideW: 340px;
  font-family: Manrope, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; overscroll-behavior: none; }
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2, h3 { font-family: 'Cormorant Garamond', Georgia, serif; letter-spacing: .02em; margin: 0 0 .4em; }
h1 { font-size: 34px; color: var(--gold2); }
h2 { font-size: 24px; color: var(--gold); }
h3 { font-size: 18px; color: var(--mute); margin-top: 14px; }
.sub { color: var(--mute); font-size: 13px; }

#stage { position: fixed; inset: 0; z-index: 0; }
#stage canvas { display: block; width: 100%; height: 100%; touch-action: none; }

#top { position: fixed; top: 0; left: 0; right: 0; height: 52px; padding: 0 12px; padding-top: env(safe-area-inset-top); display: flex; align-items: center; justify-content: space-between; z-index: 20;
  background: linear-gradient(180deg, rgba(12,10,20,.92), rgba(12,10,20,0)); pointer-events: none; }
#top > * { pointer-events: auto; }
#logo { background: none; border: 0; display: flex; align-items: center; gap: 8px; padding: 6px; }
#logo .mark { font-size: 26px; color: var(--gold); text-shadow: 0 0 12px rgba(231,185,85,.6); }
#logo .name { font-family: 'Cormorant Garamond', serif; font-weight: 700; font-size: 21px; color: var(--gold2); }
#top .right { display: flex; gap: 8px; align-items: center; }
.icon { background: rgba(255,255,255,.06); border: 1px solid var(--line); border-radius: 10px; width: 38px; height: 38px; }
.userchip { display: flex; gap: 8px; align-items: center; background: var(--panel2); border: 1px solid var(--line); border-radius: 20px; padding: 6px 12px; }
.userchip span { color: var(--gold); font-weight: 700; font-size: 13px; }

.btn { background: linear-gradient(180deg, #f0c768, #c8902f); color: #1b1206; border: 0; border-radius: 11px; padding: 10px 16px; font-weight: 700; box-shadow: 0 2px 10px rgba(231,185,85,.25); transition: transform .1s, filter .2s; }
.btn:hover { filter: brightness(1.08); } .btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: rgba(255,255,255,.06); color: var(--text); border: 1px solid var(--line); box-shadow: none; font-weight: 600; }
.btn.danger { color: #ffb0b0; }
.btn.small { padding: 7px 12px; font-size: 13px; }
.btn.glow { box-shadow: 0 0 18px rgba(231,185,85,.5); }
select, input { font: inherit; background: rgba(0,0,0,.35); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
input:focus, select:focus { outline: 2px solid rgba(231,185,85,.5); }

/* ---------- панели ---------- */
#view { position: fixed; z-index: 10; left: 16px; top: 62px; bottom: 16px; width: 420px; pointer-events: none; }
.panel { pointer-events: auto; max-height: 100%; overflow-y: auto; background: var(--panel); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--line); border-radius: var(--r); padding: 18px; box-shadow: 0 20px 60px rgba(0,0,0,.5); scrollbar-width: thin; }
.panel section { margin-top: 18px; padding-top: 14px; border-top: 1px solid rgba(255,255,255,.06); }
.hero p { margin: 0 0 8px; color: #d8cfe6; line-height: 1.45; }
.stats { font-size: 12px; color: var(--mute); }
.lvls { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.lvl { background: linear-gradient(160deg, rgba(168,116,255,.22), rgba(231,185,85,.1)); border: 1px solid var(--line); border-radius: 12px; padding: 12px 8px; text-align: left; display: flex; flex-direction: column; gap: 4px; transition: transform .15s, border-color .2s; }
.lvl:hover { transform: translateY(-2px); border-color: var(--gold); }
.lvl b { color: var(--gold2); } .lvl small { color: var(--mute); font-size: 11.5px; line-height: 1.3; }
.seg { display: inline-flex; background: rgba(0,0,0,.3); border: 1px solid var(--line); border-radius: 11px; padding: 3px; gap: 3px; }
.seg button { background: none; border: 0; border-radius: 8px; padding: 7px 12px; font-size: 13px; color: var(--mute); }
.seg button.on { background: var(--panel2); color: var(--gold2); box-shadow: inset 0 0 0 1px var(--line); }
.create { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; align-items: center; }
.create .btn { grid-column: 1 / -1; }
.chk { display: flex; gap: 6px; align-items: center; font-size: 14px; color: var(--mute); }
.list { display: flex; flex-direction: column; gap: 6px; }
.row { display: flex; align-items: center; gap: 10px; background: rgba(255,255,255,.04); border: 1px solid rgba(255,255,255,.06); border-radius: 11px; padding: 10px 12px; }
.row.click { cursor: pointer; } .row.click:hover { border-color: var(--line); }
.row .grow { flex: 1; min-width: 0; }
.rt { color: var(--gold); font-size: 12px; margin-left: 6px; font-weight: 700; }
.on { color: var(--green); margin-left: 6px; font-size: 11px; } .offl { color: var(--mute); margin-left: 6px; font-size: 11px; }
.tag { font-size: 10px; letter-spacing: .1em; background: var(--red); color: #fff; padding: 2px 6px; border-radius: 5px; margin-right: 6px; font-weight: 700; animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .55; } }
.watch { color: var(--gold); font-size: 13px; white-space: nowrap; }
.empty { color: var(--mute); font-size: 14px; padding: 10px 2px; }
.links { display: flex; flex-wrap: wrap; gap: 8px; }
.cta p { color: var(--mute); margin: 0 0 10px; }
.back { background: none; border: 0; color: var(--gold); padding: 0 0 8px; font-size: 15px; }
.big { font-size: 22px; color: var(--gold2); font-weight: 700; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
table.top { width: 100%; border-collapse: collapse; }
table.top td, table.top th { padding: 8px 6px; text-align: left; border-bottom: 1px solid rgba(255,255,255,.06); }
table.top tr.click { cursor: pointer; } table.top tr.click:hover td { background: rgba(255,255,255,.04); }
.plain { padding-left: 18px; line-height: 1.5; color: #d8cfe6; } .plain li { margin-bottom: 6px; }
.rgrid { display: grid; gap: 12px; }
.rcard { background: rgba(255,255,255,.04); border: 1px solid rgba(255,255,255,.07); border-radius: 12px; padding: 12px; }
.rhead { display: flex; align-items: center; gap: 10px; } .rhead h3 { margin: 0; color: var(--gold2); font-size: 22px; }
.meta { color: var(--gold); font-size: 12px; margin-top: 4px; }
body[data-view=rules] #view, body[data-view=top] #view, body[data-view=u] #view { width: 560px; }

/* ---------- карточка фигуры и заклинания ---------- */
.glyph { font-size: 34px; line-height: 1; width: 46px; height: 46px; display: grid; place-items: center; border-radius: 12px; background: radial-gradient(circle at 40% 30%, #fff8e6, #c9b48a); color: #2a1d0c; }
.glyph.b { background: radial-gradient(circle at 40% 30%, #5b4b7a, #1b1526); color: #e9dcff; }
.spell { display: grid; grid-template-columns: 38px 1fr auto; gap: 10px; align-items: center; padding: 10px; margin-top: 8px; border-radius: 12px; background: rgba(255,255,255,.03); border: 1px solid rgba(255,255,255,.06); opacity: .6; }
.spell.on { opacity: 1; border-color: rgba(127,216,255,.3); background: linear-gradient(120deg, rgba(127,216,255,.1), rgba(255,255,255,.02)); }
.spell.ult.on { border-color: rgba(255,207,74,.45); background: linear-gradient(120deg, rgba(255,207,74,.14), rgba(255,255,255,.02)); }
.sicon { font-size: 24px; width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px; background: rgba(0,0,0,.3); }
.stext b { display: block; font-size: 15px; } .stext small { color: var(--mute); font-size: 12.5px; line-height: 1.35; display: block; margin-top: 2px; }
.sstate { font-size: 12px; text-align: right; }
.lock, .cd { color: var(--mute); white-space: nowrap; } .ready { color: var(--gold); }
.btn.cast { padding: 8px 12px; font-size: 13px; background: linear-gradient(180deg, #c99bff, #7d4ae0); color: #fff; box-shadow: 0 0 14px rgba(168,116,255,.55); }
.spell.ult .btn.cast { background: linear-gradient(180deg, #ffe08a, #e0a02a); color: #261a02; box-shadow: 0 0 16px rgba(255,207,74,.6); }

/* ---------- HUD партии ---------- */
body:not([data-view=home]):not([data-view=rules]):not([data-view=top]):not([data-view=u]) #view { display: none; }
.hud .pbar { position: fixed; z-index: 12; left: 16px; display: flex; align-items: center; gap: 12px; background: var(--panel); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; min-width: 300px; max-width: calc(100vw - var(--sideW) - 48px); }
.hud .pbar.top { top: 62px; } .hud .pbar.bottom { bottom: 16px; }
.who { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; }
.who b { overflow: hidden; text-overflow: ellipsis; }
.who.active b { color: var(--gold2); }
.who.active .dot { box-shadow: 0 0 0 3px rgba(231,185,85,.35), 0 0 12px var(--gold); }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; } .dot.w { background: #f3ead6; } .dot.b { background: #2a2238; border: 1px solid #6b5a8a; }
.off { font-size: 11px; color: var(--mute); } .thinking { font-size: 12px; color: var(--violet); animation: pulse 1s infinite; }
.dead { font-size: 16px; color: var(--mute); letter-spacing: -2px; white-space: nowrap; overflow: hidden; max-width: 140px; }
.clock { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 20px; background: rgba(0,0,0,.4); padding: 4px 10px; border-radius: 8px; min-width: 70px; text-align: center; }
.clock.run { color: var(--gold2); box-shadow: inset 0 0 0 1px var(--gold); } .clock.low { color: var(--red); }
.hud .side { position: fixed; z-index: 12; right: 0; top: 52px; bottom: 0; width: var(--sideW); padding: 12px; display: flex; flex-direction: column; gap: 6px; background: var(--panel); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-left: 1px solid var(--line); }
.side .info { display: flex; gap: 10px; color: var(--mute); font-size: 13px; flex-wrap: wrap; }
.side .btns { margin: 4px 0; } .side .btns .btn { flex: 1 1 auto; }
.log { flex: 1; overflow-y: auto; margin: 0; padding: 0 0 0 30px; font-size: 13px; line-height: 1.7; color: #d6cce6; scrollbar-width: thin; }
.log li.b { color: #b7a8d6; }
.card-sheet { position: fixed; z-index: 14; right: calc(var(--sideW) + 16px); top: 62px; width: 360px; max-height: calc(100dvh - 80px); overflow-y: auto; background: var(--panel2); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--line); border-radius: var(--r); padding: 14px; transform: translateX(30px); opacity: 0; pointer-events: none; transition: .25s; box-shadow: 0 20px 50px rgba(0,0,0,.5); }
.card-sheet.show { transform: none; opacity: 1; pointer-events: auto; }
.card-head { display: grid; grid-template-columns: 46px 1fr 30px; gap: 12px; align-items: center; }
.card-head b { font-size: 18px; } .kills { font-size: 13px; color: var(--mute); margin-top: 2px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.souls { color: var(--blue); letter-spacing: 1px; }
.chip { font-size: 11px; padding: 2px 7px; border-radius: 6px; background: rgba(255,255,255,.08); } .chip.stun { color: #ffe680; } .chip.sh { color: var(--blue); }
.x { background: none; border: 0; color: var(--mute); font-size: 18px; }
.hint { position: fixed; z-index: 13; left: calc((100vw - var(--sideW)) / 2); top: 62px; transform: translate(-50%, -10px); opacity: 0; transition: .25s; pointer-events: none;
  background: rgba(10,8,18,.85); border: 1px solid var(--line); border-radius: 20px; padding: 7px 14px; font-size: 14px; display: flex; gap: 10px; align-items: center; white-space: nowrap; }
.hint.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.hud.compact .side, .hud.compact .card-sheet, .hud.compact .hint { display: none; }
.hud.compact .pbar { min-width: 0; padding: 6px 10px; font-size: 13px; left: auto; right: 16px; max-width: 360px; }
.hud.compact .pbar.top { top: 62px; } .hud.compact .pbar.bottom { bottom: 16px; }
.hud.compact .dead { display: none; }
body[data-view=g] #stage, body[data-view=bot] #stage, body[data-view=hotseat] #stage { right: var(--sideW); }

/* ---------- окна ---------- */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(5,3,10,.6); display: grid; place-items: center; padding: 16px; opacity: 0; transition: opacity .2s; }
.modal.show { opacity: 1; }
.mbox { background: var(--panel2); border: 1px solid var(--line); border-radius: 18px; padding: 22px; width: min(420px, 100%); box-shadow: 0 30px 80px rgba(0,0,0,.6); }
.choose { display: flex; flex-direction: column; gap: 10px; text-align: center; }
.choose .opts { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.choose .opts .btn { flex: 1 1 120px; font-size: 16px; padding: 12px; }
.modal.end .mbox { border-color: var(--gold); box-shadow: 0 0 60px rgba(231,185,85,.3); }
.modal.end h2 { font-size: 34px; }
.auth { display: flex; flex-direction: column; gap: 10px; } .auth .seg { align-self: center; }
.err { color: var(--red); min-height: 18px; font-size: 14px; }
#toasts { position: fixed; z-index: 60; left: 50%; bottom: 90px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: min(92vw, 480px); }
.toast { background: var(--panel2); border: 1px solid var(--gold); border-radius: 12px; padding: 10px 16px; font-size: 14px; opacity: 0; transform: translateY(10px); transition: .3s; pointer-events: auto; text-align: center; }
.toast.show { opacity: 1; transform: none; } .toast.click { cursor: pointer; }
#conn { position: fixed; z-index: 70; top: 56px; left: 50%; transform: translateX(-50%); background: #5a1f2a; color: #fff; padding: 6px 14px; border-radius: 10px; font-size: 13px; display: none; }
#conn.show { display: block; }

/* ---------- телефоны ---------- */
@media (max-width: 820px) {
  :root { --sideW: 0px; }
  h1 { font-size: 28px; }
  #logo .name { font-size: 18px; }
  body[data-view=home] #stage { bottom: auto; height: 44dvh; }
  #view { left: 0; right: 0; width: auto !important; top: 44dvh; bottom: 0; }
  body:not([data-view=home]) #view { top: 52px; }
  .panel { border-radius: 18px 18px 0 0; height: 100%; max-height: none; padding: 16px 14px 40px; }
  body[data-view=g] #stage, body[data-view=bot] #stage, body[data-view=hotseat] #stage { right: 0; top: 96px; bottom: 112px; }
  .hud .pbar { left: 8px; right: 8px; min-width: 0; max-width: none; padding: 6px 10px; }
  .hud .pbar.top { top: 52px; } .hud .pbar.bottom { bottom: calc(8px + env(safe-area-inset-bottom)); }
  .clock { font-size: 17px; min-width: 60px; }
  .hud .side { top: auto; bottom: calc(60px + env(safe-area-inset-bottom)); left: 8px; right: 8px; width: auto; height: auto; padding: 0; background: none; border: 0; backdrop-filter: none; -webkit-backdrop-filter: none; }
  .side .info { display: none; } .side .log { display: none; }
  .side .btns { margin: 0; flex-wrap: nowrap; overflow-x: auto; } .side .btns .btn { flex: 0 0 auto; padding: 8px 10px; font-size: 13px; }
  .card-sheet { left: 0; right: 0; top: auto; bottom: 0; width: auto; max-height: 62dvh; border-radius: 18px 18px 0 0; transform: translateY(100%); padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  .card-sheet.show { transform: none; }
  .hint { left: 50%; top: auto; bottom: calc(108px + env(safe-area-inset-bottom)); font-size: 13px; }
  .hud.compact .pbar { left: 8px; right: auto; max-width: 70vw; }
  .hud.compact .pbar.top { top: 52px; } .hud.compact .pbar.bottom { bottom: auto; top: calc(44dvh - 44px); }
  .create { grid-template-columns: 1fr 1fr; }
  .lvls { grid-template-columns: 1fr 1fr 1fr; }
  #toasts { bottom: 130px; }
}
@media (min-width: 821px) {
  body[data-view=home] #stage, body[data-view=rules] #stage, body[data-view=top] #stage, body[data-view=u] #stage { left: 440px; }
  body[data-view=rules] #stage, body[data-view=top] #stage, body[data-view=u] #stage { left: 580px; }
}
