:root {
  --gold: #ffcf4d;
  --gold-2: #f0a91f;
  --gold-edge: #b8700f;
  --blue: #3d6fe0;
  --blue-2: #2c54b8;
  --blue-edge: #1c3577;
  --ink: #fff8ea;
  --ink-2: rgba(255, 248, 234, 0.66);
  --panel: rgba(16, 24, 44, 0.86);
  --panel-line: rgba(255, 220, 150, 0.22);
  /* безопасные поля: своё у браузера и то, что задаёт Link */
  --safe-t: max(env(safe-area-inset-top, 0px), var(--link-miniapp-safe-area-top, 0px));
  --safe-b: max(env(safe-area-inset-bottom, 0px), var(--link-miniapp-safe-area-bottom, 0px));
  --safe-l: max(env(safe-area-inset-left, 0px), var(--link-miniapp-safe-area-left, 0px));
  --safe-r: max(env(safe-area-inset-right, 0px), var(--link-miniapp-safe-area-right, 0px));
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  background:
    radial-gradient(120% 80% at 50% 38%, #2b4a7a 0%, #1a2b4d 38%, #0d1426 78%, #080c18 100%);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
[hidden] { display: none !important; }

#stage { position: fixed; inset: 0; }
#stage canvas { display: block; width: 100%; height: 100%; outline: none; }

/* ---------- загрузка */
.loading {
  position: fixed; inset: 0; display: grid; place-content: center; justify-items: center; gap: 22px; z-index: 50;
  background: radial-gradient(100% 70% at 50% 40%, #2b4a7a, #0d1426 80%);
  transition: opacity .4s;
}
.loading img { width: 120px; filter: drop-shadow(0 12px 18px rgba(0,0,0,.5)); animation: bob 1.4s ease-in-out infinite; }
.loading .bar { width: 180px; height: 10px; border-radius: 6px; background: rgba(255,255,255,.12); overflow: hidden; }
.loading .bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--gold), var(--gold-2)); border-radius: 6px; transition: width .2s; }
.loading.done { opacity: 0; pointer-events: none; }
@keyframes bob { 50% { transform: translateY(-8px); } }

/* ---------- кнопки */
.btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 12px;
  min-height: 56px; padding: 0 26px; border-radius: 18px;
  font-size: 19px; font-weight: 800; letter-spacing: .2px;
  transition: transform .08s, box-shadow .08s, filter .15s;
}
.btn.big { min-height: 72px; font-size: 21px; width: 100%; justify-content: flex-start; padding: 0 22px; }
.btn img { width: 46px; height: 46px; margin: -6px 0; filter: drop-shadow(0 4px 4px rgba(0,0,0,.35)); }
.btn small { display: block; font-size: 13px; font-weight: 700; opacity: .75; margin-left: auto; }
.btn.gold {
  color: #4a2a00;
  background: linear-gradient(180deg, #ffe58a 0%, var(--gold) 45%, var(--gold-2) 100%);
  box-shadow: 0 6px 0 var(--gold-edge), 0 12px 24px rgba(0,0,0,.35), inset 0 2px 0 rgba(255,255,255,.65);
  text-shadow: 0 1px 0 rgba(255,255,255,.45);
}
.btn.blue {
  color: #fff;
  background: linear-gradient(180deg, #6d97ff 0%, var(--blue) 45%, var(--blue-2) 100%);
  box-shadow: 0 6px 0 var(--blue-edge), 0 12px 24px rgba(0,0,0,.35), inset 0 2px 0 rgba(255,255,255,.35);
  text-shadow: 0 1px 2px rgba(0,0,0,.35);
}
.btn.red {
  color: #fff;
  background: linear-gradient(180deg, #ff8a7a 0%, #e5523f 45%, #c43a2a 100%);
  box-shadow: 0 6px 0 #7e2015, 0 12px 24px rgba(0,0,0,.35), inset 0 2px 0 rgba(255,255,255,.35);
}
.btn:active, .btn.pressed { transform: translateY(5px); box-shadow: 0 1px 0 var(--gold-edge), 0 4px 10px rgba(0,0,0,.3), inset 0 2px 0 rgba(255,255,255,.5); }
.btn.blue:active { box-shadow: 0 1px 0 var(--blue-edge), 0 4px 10px rgba(0,0,0,.3); }
.btn.red:active { box-shadow: 0 1px 0 #7e2015, 0 4px 10px rgba(0,0,0,.3); }
.btn:disabled { filter: grayscale(.8) brightness(.7); cursor: default; }

.chip {
  min-width: 56px; height: 44px; padding: 0 16px; border-radius: 22px; font-weight: 800; font-size: 15px;
  background: rgba(255,255,255,.1); border: 2px solid rgba(255,255,255,.18);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.chip:active { transform: scale(.96); }

/* ---------- экраны */
.screen {
  position: fixed; inset: 0; z-index: 20;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 34px;
  padding: calc(24px + var(--safe-t)) 22px calc(24px + var(--safe-b));
  background: linear-gradient(180deg, rgba(8,12,24,.55) 0%, rgba(8,12,24,.1) 35%, rgba(8,12,24,.15) 60%, rgba(8,12,24,.8) 100%);
  animation: fadeUp .35s ease-out;
}
@keyframes fadeUp { from { transform: translateY(18px); } to { transform: none; } }

.title { text-align: center; position: relative; margin-top: -4vh; }
.title h1 {
  margin: 0; font-size: clamp(54px, 15vw, 96px); font-weight: 900; letter-spacing: 1px; line-height: .95;
  background: linear-gradient(180deg, #fff6d8 0%, #ffd66b 45%, #e39a1a 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 0 #7a4a06) drop-shadow(0 14px 22px rgba(0,0,0,.55));
}
.title .t-sub {
  display: inline-block; margin-top: 10px; padding: 4px 16px; border-radius: 12px;
  font-weight: 900; font-size: 22px; letter-spacing: 6px; color: #10213f;
  background: linear-gradient(180deg, #bfe0ff, #7fb3ff); box-shadow: 0 4px 0 #3a6bc0;
}
.title .t-king { width: 92px; display: block; margin: 0 auto -6px; filter: drop-shadow(0 10px 14px rgba(0,0,0,.5)); }

.menu-buttons { width: min(420px, 100%); display: grid; gap: 20px; }
.menu-foot { display: flex; gap: 12px; }

.panel {
  width: min(460px, 100%);
  background: linear-gradient(180deg, rgba(30,46,82,.96), rgba(15,23,43,.97));
  border: 2px solid var(--panel-line);
  border-radius: 26px; padding: 22px 20px 24px;
  box-shadow: 0 24px 60px rgba(0,0,0,.55), inset 0 1px 0 rgba(255,255,255,.12);
}
.panel h2 { margin: 6px 4px 14px; font-size: 18px; font-weight: 800; color: var(--ink-2); text-transform: uppercase; letter-spacing: 1.4px; }
.panel h2 + * { margin-bottom: 22px; }
.panel .row { display: flex; gap: 14px; margin-top: 8px; }
.panel .row .btn { flex: 1; }

.levels { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.lvl {
  position: relative; padding: 14px 12px 12px; border-radius: 18px; text-align: left;
  background: rgba(255,255,255,.07); border: 2px solid rgba(255,255,255,.12);
  transition: transform .1s, background .15s, border-color .15s;
}
.lvl b { display: block; font-size: 17px; font-weight: 800; }
.lvl small { display: block; margin-top: 3px; color: var(--ink-2); font-size: 13px; font-weight: 600; }
.lvl .stars { color: var(--gold); font-size: 15px; letter-spacing: 2px; margin-bottom: 4px; }
.lvl.on { background: linear-gradient(180deg, rgba(255,207,77,.28), rgba(255,170,30,.16)); border-color: var(--gold); box-shadow: 0 0 0 3px rgba(255,207,77,.18); }
.lvl:active { transform: scale(.97); }

.colors { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.col {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 6px 12px; border-radius: 18px;
  background: rgba(255,255,255,.07); border: 2px solid rgba(255,255,255,.12); font-weight: 800; font-size: 15px;
}
.col img { width: 64px; height: 64px; filter: drop-shadow(0 6px 6px rgba(0,0,0,.4)); }
.col .dice { width: 64px; height: 64px; display: grid; place-items: center; font-size: 40px; font-weight: 900; color: var(--gold); }
.col.on { background: linear-gradient(180deg, rgba(255,207,77,.28), rgba(255,170,30,.16)); border-color: var(--gold); }

/* ---------- интерфейс партии: колонка карточек; середина свободна под доску */
.hud {
  position: fixed; inset: 0; z-index: 10; pointer-events: none;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  /* --hud-top: под шапкой Link; в полноэкранной игре — 0 (капсулу обходит только верхняя карточка) */
  padding: calc(10px + max(var(--safe-t), var(--hud-top, var(--link-top)))) calc(10px + var(--safe-r)) calc(10px + var(--safe-b)) calc(10px + var(--safe-l));
}
/* верхняя карточка уступает место капсуле «⋯ | ⌄» Link */
.hud.capped > #plateTop { align-self: flex-start; width: calc(100% - var(--cap-reserve, 0px)); }
.hud > * { pointer-events: auto; width: min(560px, 100%); }
.hud > .spacer { flex: 1; pointer-events: none; }

.card {
  position: relative; display: flex; align-items: center; gap: 12px; flex: none;
  padding: 8px 12px 8px 8px; border-radius: 22px;
  background: linear-gradient(180deg, rgba(32, 46, 82, .9), rgba(15, 22, 42, .92));
  border: 1.5px solid rgba(255, 255, 255, .09);
  box-shadow: 0 8px 22px rgba(0, 0, 0, .32), inset 0 1px 0 rgba(255, 255, 255, .07);
  transition: border-color .25s, box-shadow .25s;
}
.card.turn { border-color: rgba(255, 207, 77, .6); box-shadow: 0 0 0 3px rgba(255, 207, 77, .12), 0 8px 22px rgba(0, 0, 0, .32); }
.card.check { border-color: rgba(255, 96, 70, .8); box-shadow: 0 0 0 3px rgba(255, 90, 60, .18), 0 8px 22px rgba(0, 0, 0, .32); }
.pic { position: relative; width: 50px; height: 50px; flex: none; }
.pic .ava, .pic .ini {
  position: relative; width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: grid; place-items: center;
  background: radial-gradient(circle at 50% 30%, #6b8fe0, #2a4590 75%); border: 2px solid rgba(255, 255, 255, .25);
  font-weight: 900; font-size: 21px; color: #fff;
}
.pic .ava.piece { object-fit: contain; padding: 5px; }
.pic .ring { position: absolute; inset: -5px; border-radius: 50%; border: 3px solid transparent; transition: border-color .25s; }
.card.turn .ring { border-color: var(--gold); animation: ring 1.8s ease-in-out infinite; }
.card.check .ring { border-color: #ff5a3c; animation: ring 0.9s ease-in-out infinite; }
@keyframes ring { 50% { box-shadow: 0 0 0 4px rgba(255, 207, 77, .18), 0 0 16px rgba(255, 207, 77, .45); } }
.pic .kc {
  position: absolute; right: -5px; bottom: -5px; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  background: linear-gradient(180deg, #fffaf0, #d9cdb2); border: 2px solid #0f1830;
}
.pic .kc.b { background: linear-gradient(180deg, #5a4535, #2a1d14); }
.pic .kc img { width: 18px; height: 18px; }
.who { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.line1 { display: flex; align-items: center; gap: 8px; min-width: 0; }
.card .name { font-size: 17px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.meta { display: flex; align-items: center; gap: 6px; flex: none; font-size: 13px; font-weight: 800; color: var(--ink-2); }
.meta .lv {
  min-width: 22px; height: 20px; padding: 0 6px; border-radius: 10px; display: grid; place-items: center;
  font-size: 12px; color: #4a2a00; background: linear-gradient(180deg, #ffe58a, var(--gold-2));
}
.meta .tr { color: var(--gold); }
.meta .stars { color: var(--gold); letter-spacing: 1px; font-size: 12px; }
.meta .stars i { font-style: normal; color: rgba(255, 255, 255, .22); }
.lg.xs { width: 20px; height: 23px; }
.caps { display: flex; align-items: center; min-height: 20px; }
.caps img { width: 22px; height: 22px; margin-left: -7px; filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .5)); }
.caps img:first-child, .caps img.g { margin-left: 0; }
.caps img.g { margin-left: 3px; }
.caps img.new { animation: capIn .45s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes capIn { from { transform: scale(0) translateY(-8px); } }
.caps .adv { margin-left: 6px; padding: 1px 7px; border-radius: 9px; font-weight: 900; font-size: 12px; color: #4a2a00; background: var(--gold); }
.caps:empty::before { content: attr(data-empty); font-size: 12px; font-weight: 700; color: rgba(255, 255, 255, .28); }

.tag {
  position: absolute; top: -11px; right: 14px; height: 22px; padding: 0 10px; border-radius: 11px;
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 900; letter-spacing: .2px;
  color: #4a2a00; background: linear-gradient(180deg, #ffe58a, var(--gold-2)); box-shadow: 0 3px 8px rgba(0, 0, 0, .35);
  animation: tagIn .25s ease-out;
}
.tag.think { color: #fff; background: linear-gradient(180deg, #6d97ff, #2c54b8); }
.tag.red { color: #fff; background: linear-gradient(180deg, #ff8a6a, #d8361c); }
@keyframes tagIn { from { transform: translateY(6px); opacity: 0; } }
.dots { display: inline-flex; gap: 3px; }
.dots i { width: 4px; height: 4px; border-radius: 50%; background: currentColor; animation: dot 1s infinite; }
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }
@keyframes dot { 30% { transform: translateY(-3px); opacity: 1; } 0%, 60%, 100% { opacity: .5; } }

.moves {
  flex: none; display: flex; align-items: center; gap: 4px; height: 30px; overflow-x: auto; scrollbar-width: none;
  padding: 0 4px; mask-image: linear-gradient(90deg, transparent, #000 14px, #000 calc(100% - 14px), transparent);
}
.moves::-webkit-scrollbar { display: none; }
.moves span { flex: none; font-size: 13px; font-weight: 800; padding: 4px 8px; border-radius: 9px; color: var(--ink-2); }
.moves span.n { padding: 4px 0 4px 6px; color: rgba(255, 255, 255, .35); }
.moves span.last { background: rgba(255, 207, 77, .22); color: var(--ink); }
.moves span.e { display: none; }

.dock {
  flex: none; width: auto !important; max-width: 100%; display: flex; justify-content: center; gap: 4px; padding: 6px;
  border-radius: 24px; background: rgba(12, 18, 34, .78); border: 1px solid rgba(255, 255, 255, .08);
  box-shadow: 0 10px 26px rgba(0, 0, 0, .35); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}
.dk {
  width: 70px; height: 56px; border-radius: 18px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  color: #dce6ff; font-size: 11px; font-weight: 800; transition: background .15s, transform .08s, opacity .2s;
}
.dk svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.dk span { white-space: nowrap; max-width: 66px; overflow: hidden; text-overflow: ellipsis; }
.dk:active { transform: scale(.92); background: rgba(255, 255, 255, .1); }
.dk:disabled { opacity: .32; }
.dk.lit { color: var(--gold); background: rgba(255, 207, 77, .14); }
.dk.danger { color: #ffb0a0; }
.dk .x { display: none; }
.dk.off .x { display: inline; }
.dk.off .w { display: none; }
.dk.off { color: rgba(220, 230, 255, .5); }
@media (hover: hover) { .dk:hover:not(:disabled) { background: rgba(255, 255, 255, .07); } }

/* маленькая круглая кнопка «назад» в таблице лидеров */
.tool {
  display: grid; place-items: center; background: linear-gradient(180deg, #4a6ab0, #2d4785);
  box-shadow: 0 5px 0 #1a2c57, 0 10px 18px rgba(0, 0, 0, .35), inset 0 2px 0 rgba(255, 255, 255, .25);
}
.tool svg { fill: none; stroke: #fff; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.tool:active { transform: translateY(4px); box-shadow: 0 1px 0 #1a2c57, 0 4px 8px rgba(0, 0, 0, .3); }

/* ---------- надпись «Шах!» */
.banner {
  position: fixed; left: 50%; top: 42%; z-index: 30; transform: translate(-50%, -50%);
  font-size: clamp(40px, 11vw, 72px); font-weight: 900; letter-spacing: 1px; pointer-events: none;
  background: linear-gradient(180deg, #fff3cf, #ffb340 60%, #e46a12); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 0 #7a3306) drop-shadow(0 10px 24px rgba(0,0,0,.6));
  animation: pop 1.1s ease-out forwards;
}
.banner.red { background-image: linear-gradient(180deg, #ffe0d6, #ff6a4d 60%, #c22d16); filter: drop-shadow(0 4px 0 #6d1406) drop-shadow(0 10px 24px rgba(0,0,0,.6)); }
@keyframes pop {
  0% { transform: translate(-50%, -50%) scale(.4); }
  18% { transform: translate(-50%, -50%) scale(1.12); }
  30% { transform: translate(-50%, -50%) scale(1); }
  80% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -64%) scale(.96); opacity: 0; }
}

/* ---------- окна */
.modal {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 20px;
  background: rgba(5, 9, 20, .55); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  animation: fadeIn .2s ease-out;
}
@keyframes fadeIn { from { background: rgba(5,9,20,0); } }
.modal .panel { animation: popIn .28s cubic-bezier(.2,1.4,.4,1); text-align: center; }
@keyframes popIn { from { transform: scale(.85) translateY(20px); } }
.modal h3 { margin: 4px 0 6px; font-size: 30px; font-weight: 900; }
.modal p { margin: 0 0 20px; color: var(--ink-2); font-weight: 700; font-size: 16px; }
.modal .stack { display: grid; gap: 16px; margin-top: 6px; }
.modal .stack .btn { width: 100%; }
.modal .result-ico { width: 110px; height: 110px; margin: -70px auto 4px; display: block; filter: drop-shadow(0 12px 16px rgba(0,0,0,.55)); }
.modal .result-ico.lost { transform: rotate(78deg) translateX(18px); }
.modal .toggles { display: flex; gap: 10px; justify-content: center; margin: 4px 0 18px; flex-wrap: wrap; }
.modal .chip.on { background: rgba(255,207,77,.22); border-color: var(--gold); }

.promo { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 8px; }
.promo button {
  aspect-ratio: 1; border-radius: 18px; background: rgba(255,255,255,.08); border: 2px solid rgba(255,255,255,.14);
  display: grid; place-items: center; transition: transform .1s, background .15s;
}
.promo button:hover { background: rgba(255,207,77,.2); border-color: var(--gold); }
.promo button:active { transform: scale(.94); }
.promo img { width: 82%; filter: drop-shadow(0 6px 6px rgba(0,0,0,.45)); }

/* ---------- широкий экран: всё в левой колонке, ходы — нотацией */
@media (min-width: 640px) and (min-aspect-ratio: 4/3) {
  .hud { right: auto; width: calc(clamp(290px, 32vw, 380px) + var(--safe-l)); align-items: stretch; gap: 12px;
    padding: calc(16px + var(--safe-t)) 16px calc(16px + var(--safe-b)) calc(16px + var(--safe-l)); }
  .hud > * { width: 100%; }
  .hud > .spacer { display: none; }
  .moves {
    flex: 1; min-height: 0; height: auto; display: grid; grid-template-columns: 38px 1fr 1fr; align-content: start; gap: 2px 4px;
    overflow-y: auto; padding: 10px; mask-image: none; border-radius: 18px;
    background: rgba(12, 18, 34, .55); border: 1px solid rgba(255, 255, 255, .06);
  }
  .moves span { padding: 5px 8px; }
  .moves span.n { padding: 5px 0; text-align: right; padding-right: 6px; }
  .moves span.e { display: block; }
  .moves:empty { display: block; }
  .dock { width: 100% !important; justify-content: space-between; }
}
@media (max-height: 640px) {
  .pic { width: 40px; height: 40px; }
  .card { padding: 5px 10px 5px 6px; }
  .card .name { font-size: 15px; }
  .dk { height: 48px; }
  .dk span { display: none; }
}

/* ---------- профиль, лиги, таблица лидеров */
:root {
  --link-top: max(var(--link-miniapp-header-height, 0px), calc(var(--link-miniapp-controls-top, 0px) + var(--link-miniapp-controls-height, 0px)));
  --cap-right: calc(var(--link-miniapp-controls-right, 0px) + var(--link-miniapp-controls-width, 0px));
}
.screen { padding-top: calc(24px + max(var(--safe-t), var(--link-top))); }
.btn.green {
  color: #fff;
  background: linear-gradient(180deg, #6fe08a 0%, #2fb457 45%, #1f9444 100%);
  box-shadow: 0 6px 0 #14662d, 0 12px 24px rgba(0,0,0,.35), inset 0 2px 0 rgba(255,255,255,.4);
  text-shadow: 0 1px 2px rgba(0,0,0,.3);
}
.btn.green:active { transform: translateY(5px); box-shadow: 0 1px 0 #14662d, 0 4px 10px rgba(0,0,0,.3); }
.btn .cup { font-size: 30px; width: 46px; text-align: center; }
.menu-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.menu-row .btn { min-height: 64px; padding: 0 12px; font-size: 18px; gap: 6px; }
.menu-row .btn img { width: 40px; height: 40px; }
#menu { gap: 26px; }

.profile {
  width: min(420px, 100%); display: flex; align-items: center; gap: 12px; padding: 10px 14px 10px 10px; text-align: left;
  border-radius: 22px; background: var(--panel); border: 2px solid rgba(255,255,255,.12); box-shadow: 0 10px 26px rgba(0,0,0,.35);
}
.profile:active { transform: scale(.98); }
.pf-ava { position: relative; width: 58px; height: 58px; flex: none; }
.pf-ava img, .pf-ava span, .ava-c {
  width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: grid; place-items: center;
  font-weight: 900; font-size: 24px; color: #fff; background: linear-gradient(180deg, #6d97ff, #2c54b8); border: 3px solid rgba(255,255,255,.85);
}
.pf-ava img[hidden] + span { display: grid; }
.pf-lvl {
  position: absolute; right: -6px; bottom: -4px; min-width: 26px; height: 26px; padding: 0 6px; border-radius: 13px;
  display: grid; place-items: center; font-size: 14px; color: #4a2a00; background: linear-gradient(180deg, #ffe58a, #f0a91f); border: 2px solid #fff;
}
.pf-main { flex: 1; min-width: 0; }
.pf-name { display: block; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 7px; }
.xpbar { position: relative; height: 18px; border-radius: 9px; background: rgba(0,0,0,.35); overflow: hidden; border: 1px solid rgba(255,255,255,.12); }
.xpbar i { position: absolute; inset: 0 auto 0 0; width: 0; background: linear-gradient(180deg, #8ff0a8, #2fb457); border-radius: 9px; transition: width .8s cubic-bezier(.2,.8,.2,1); }
.xpbar span { position: relative; display: block; text-align: center; font-size: 11px; font-weight: 800; line-height: 17px; text-shadow: 0 1px 2px rgba(0,0,0,.6); }
.pf-league { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.pf-tr { font-size: 15px; color: var(--gold); }
.pf-tr::before { content: '🏆 '; font-size: 12px; }

/* значок лиги: щит с фигурой */
.lg { position: relative; display: inline-grid; place-items: center; width: 44px; height: 50px; flex: none; }
.lg::before {
  content: ''; position: absolute; inset: 0;
  clip-path: polygon(50% 0, 100% 14%, 100% 58%, 50% 100%, 0 58%, 0 14%);
  background: var(--lg-bg); box-shadow: inset 0 0 0 3px rgba(255,255,255,.4);
}
.lg::after {
  content: ''; position: absolute; inset: 4px;
  clip-path: polygon(50% 0, 100% 14%, 100% 58%, 50% 100%, 0 58%, 0 14%);
  background: var(--lg-in);
}
.lg img { position: relative; z-index: 1; width: 64%; margin-top: -10%; filter: drop-shadow(0 2px 2px rgba(0,0,0,.5)); }
.lg.sm { width: 28px; height: 32px; }
.lg.xl { width: 96px; height: 110px; }
.lg[data-l=bronze]   { --lg-bg: linear-gradient(180deg, #f3b27a, #9a5a2c); --lg-in: linear-gradient(180deg, #c98150, #7a421c); }
.lg[data-l=silver]   { --lg-bg: linear-gradient(180deg, #ffffff, #9aa6b8); --lg-in: linear-gradient(180deg, #d5dce8, #7d889c); }
.lg[data-l=gold]     { --lg-bg: linear-gradient(180deg, #fff1a6, #d9971b); --lg-in: linear-gradient(180deg, #ffd34d, #b8730f); }
.lg[data-l=platinum] { --lg-bg: linear-gradient(180deg, #c9fff4, #2bb3a0); --lg-in: linear-gradient(180deg, #7fe8d6, #17897a); }
.lg[data-l=diamond]  { --lg-bg: linear-gradient(180deg, #d8d2ff, #5b6cff); --lg-in: linear-gradient(180deg, #9aa8ff, #3a3fc9); }
.lg[data-l=champion] { --lg-bg: linear-gradient(180deg, #ffe08a, #e0412b); --lg-in: linear-gradient(180deg, #ff7a52, #a3170c); }

.lvl .reward { display: flex; gap: 8px; margin-top: 6px; font-size: 13px; font-weight: 800; }
.lvl .reward .up { color: #7dff9a; }
.lvl .reward .down { color: #ff9a8a; }
.lvl.weak { opacity: .7; }
.lvl .weak-note { display: block; margin-top: 4px; font-size: 11px; color: #ffcf9a; font-weight: 700; }
.setup-note { margin: -8px 4px 14px; font-size: 13px; color: var(--ink-2); font-weight: 700; text-align: center; }
.setup-note:empty { display: none; }

.leaders { justify-content: flex-start; gap: 12px; background: linear-gradient(180deg, rgba(8,12,24,.86), rgba(8,12,24,.94)); }
.lb-head { width: min(560px, 100%); display: flex; align-items: center; gap: 12px; }
.lb-head h2 { margin: 0; font-size: 26px; font-weight: 900; }
.tool.small { width: 48px; height: 46px; border-radius: 14px; }
.tool.small svg { width: 24px; height: 24px; }
.tabs { width: min(560px, 100%); display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 5px; border-radius: 18px; background: rgba(255,255,255,.07); }
.tabs button { height: 42px; border-radius: 14px; font-weight: 800; font-size: 15px; color: var(--ink-2); }
.tabs button.on { color: #4a2a00; background: linear-gradient(180deg, #ffe58a, var(--gold-2)); box-shadow: 0 3px 0 var(--gold-edge); }
.lb-note { width: min(560px, 100%); display: flex; align-items: center; gap: 12px; font-weight: 700; color: var(--ink-2); font-size: 14px; min-height: 0; }
.lb-note:empty { display: none; }
.lb-note b { color: var(--ink); font-size: 18px; display: block; }
.lb-list { width: min(560px, 100%); flex: 1; overflow-y: auto; display: grid; align-content: start; gap: 8px; padding: 2px 2px 90px; touch-action: pan-y; }
.lb-row {
  display: flex; align-items: center; gap: 12px; padding: 8px 12px 8px 8px; border-radius: 18px;
  background: rgba(255,255,255,.06); border: 2px solid rgba(255,255,255,.06);
}
.lb-row.me { background: rgba(255,207,77,.16); border-color: var(--gold); }
.lb-row .rk { width: 34px; height: 34px; flex: none; display: grid; place-items: center; font-weight: 900; font-size: 15px; color: var(--ink-2); }
.lb-row .rk.m1, .lb-row .rk.m2, .lb-row .rk.m3 { border-radius: 50%; color: #3a2400; font-size: 16px; box-shadow: inset 0 -3px 0 rgba(0,0,0,.2); }
.lb-row .rk.m1 { background: linear-gradient(180deg, #fff1a6, #e0a21b); }
.lb-row .rk.m2 { background: linear-gradient(180deg, #ffffff, #a9b3c4); }
.lb-row .rk.m3 { background: linear-gradient(180deg, #f6c08f, #b06a33); }
.lb-row .av { width: 44px; height: 44px; flex: none; }
.lb-row .av img, .lb-row .av .ava-c { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; border-width: 2px; font-size: 18px; }
.lb-row .nm { flex: 1; min-width: 0; }
.lb-row .nm b { display: block; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-row .nm small { color: var(--ink-2); font-weight: 700; font-size: 12px; }
.lb-row .pts { font-weight: 900; font-size: 17px; color: var(--gold); white-space: nowrap; }
.lb-me { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(14px + var(--safe-b)); width: min(560px, calc(100% - 44px)); }
.lb-me .lb-row { background: linear-gradient(180deg, rgba(60,48,16,.97), rgba(40,32,10,.97)); border-color: var(--gold); box-shadow: 0 10px 26px rgba(0,0,0,.5); }
.lb-empty { text-align: center; color: var(--ink-2); font-weight: 700; padding: 40px 10px; }

.gate p { margin: 0; font-size: 20px; font-weight: 800; text-align: center; }

/* награда за партию */
.reward-box { display: grid; gap: 12px; margin: 4px 0 18px; }
.rw-trophies { font-size: 44px; font-weight: 900; color: var(--gold); text-shadow: 0 3px 0 #7a4a06; }
.rw-trophies.neg { color: #ff8a7a; text-shadow: 0 3px 0 #6d1406; }
.rw-line { display: flex; align-items: center; justify-content: center; gap: 10px; font-weight: 800; color: var(--ink-2); }
.rw-line .xpbar { flex: 1; max-width: 220px; }
.rw-up { padding: 10px; border-radius: 16px; background: rgba(125,255,154,.12); color: #9dffb4; font-weight: 900; display: flex; align-items: center; justify-content: center; gap: 10px; }
.rw-up.down { background: rgba(255,138,122,.12); color: #ffb0a4; }
.rules p { margin: 0 0 8px; text-align: left; font-size: 14px; color: var(--ink-2); line-height: 1.4; }
.rules { margin-bottom: 12px; }
.lb-note .lg { flex: none; }
.profile { margin-bottom: 4px; }
.rw-trophies.done { animation: bump .35s cubic-bezier(.2, 1.8, .4, 1); }
@keyframes bump { 40% { transform: scale(1.18); } }
.reward-box .rw-up { animation: rwIn .45s 1.3s cubic-bezier(.2, 1.5, .4, 1) both; }
@keyframes rwIn { from { transform: scale(.6); opacity: 0; } }

/* экраны меню прокручиваются, если не влезают (телефон в альбомной), и не заходят под вырез */
.screen:not(.leaders) {
  justify-content: flex-start; overflow-y: auto; touch-action: pan-y; scrollbar-width: none;
  padding-left: calc(22px + var(--safe-l)); padding-right: calc(22px + var(--safe-r));
}
.screen:not(.leaders)::-webkit-scrollbar { display: none; }
.screen:not(.leaders) > :first-child { margin-top: auto; }
.screen:not(.leaders) > :last-child { margin-bottom: auto; }
.leaders { padding-left: calc(22px + var(--safe-l)); padding-right: calc(22px + var(--safe-r)); }
@media (max-height: 500px) and (min-aspect-ratio: 4/3) {
  .screen { gap: 16px; padding-top: calc(12px + max(var(--safe-t), var(--link-top))); }
  .levels { grid-template-columns: repeat(4, 1fr); gap: 8px; }
  .lvl { padding: 10px; }
  .lvl small:not(.weak-note) { display: none; }
  .colors { gap: 8px; }
  .col { padding: 8px; }
  .col img, .col .dice { width: 40px; height: 40px; font-size: 28px; }
  .panel h2 { margin: 2px 4px 8px; font-size: 14px; }
  .panel h2 + * { margin-bottom: 12px; }
}
/* низкий широкий экран (телефон в альбомной): меню в две колонки */
@media (max-height: 500px) and (min-aspect-ratio: 4/3) {
  #menu {
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-content: center; justify-items: center;
    grid-template-areas: "prof btns" "title btns" "foot btns"; column-gap: 32px; row-gap: 10px;
  }
  #menu > * { margin: 0 !important; }
  #menu .profile { grid-area: prof; width: min(400px, 100%); }
  #menu .title { grid-area: title; }
  #menu .title h1 { font-size: 54px; }
  #menu .menu-buttons { grid-area: btns; gap: 12px; }
  #menu .menu-foot { grid-area: foot; }
  #menu .btn.big { min-height: 56px; font-size: 18px; }
  #menu .menu-row .btn { min-height: 52px; }
}

/* ---------- игра с другом */
.btn.violet {
  color: #fff;
  background: linear-gradient(180deg, #b48cff 0%, #8a5cf0 45%, #6c3fd6 100%);
  box-shadow: 0 6px 0 #45238f, 0 12px 24px rgba(0,0,0,.35), inset 0 2px 0 rgba(255,255,255,.4);
  text-shadow: 0 1px 2px rgba(0,0,0,.3);
}
.btn.violet:active { transform: translateY(5px); box-shadow: 0 1px 0 #45238f, 0 4px 10px rgba(0,0,0,.3); }
.btn .duo { position: relative; width: 52px; height: 46px; flex: none; }
.btn .duo img { position: absolute; width: 40px; height: 40px; margin: 0; }
.btn .duo img:first-child { left: -2px; top: -2px; }
.btn .duo img:last-child { right: -4px; bottom: -4px; }
.btn .badge {
  margin-left: auto; min-width: 30px; height: 30px; padding: 0 9px; border-radius: 15px; display: grid; place-items: center;
  font-size: 16px; font-weight: 900; color: #4a2a00; background: linear-gradient(180deg, #ffe58a, var(--gold-2));
  box-shadow: 0 3px 0 var(--gold-edge); text-shadow: none; animation: badgePop .5s cubic-bezier(.2, 1.8, .4, 1);
}
@keyframes badgePop { from { transform: scale(.3); } }
.fr-invite { width: min(560px, 100%); display: grid; gap: 10px; }
.fr-note { margin: 0 4px; text-align: center; font-size: 13px; font-weight: 700; color: var(--ink-2); }
.fr-row { cursor: pointer; text-align: left; width: 100%; color: inherit; }
.fr-row:active { transform: scale(.98); }
.fr-row.turn { background: rgba(255,207,77,.12); border-color: rgba(255,207,77,.55); }
.fr-row .st { flex: none; padding: 5px 10px; border-radius: 12px; font-size: 13px; font-weight: 900; white-space: nowrap; background: rgba(255,255,255,.08); color: var(--ink-2); }
.fr-row .st.go { color: #4a2a00; background: linear-gradient(180deg, #ffe58a, var(--gold-2)); }
.fr-row .st.won { color: #9dffb4; background: rgba(125,255,154,.12); }
.fr-row .st.lost { color: #ffb0a4; background: rgba(255,138,122,.12); }
.fr-row .av .piece { border-radius: 0; object-fit: contain; background: none; border: 0; }
.fr-section { margin: 10px 6px 0; font-size: 13px; font-weight: 900; letter-spacing: .4px; text-transform: uppercase; color: var(--ink-2); }
.duel-invite .who-big { display: grid; justify-items: center; gap: 8px; margin: 4px 0 14px; }
.duel-invite .who-big .av { width: 84px; height: 84px; position: relative; }
.duel-invite .who-big .av img, .duel-invite .who-big .av .ava-c { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; font-size: 34px; }
.duel-invite .who-big .av .kc { position: absolute; right: -6px; bottom: -6px; }
.score { display: inline-flex; gap: 8px; align-items: center; padding: 6px 14px; border-radius: 14px; background: rgba(255,255,255,.07); font-weight: 900; color: var(--ink); margin-bottom: 14px; }
.score b { color: var(--gold); font-size: 20px; }
.meta .sc { color: var(--ink-2); font-weight: 900; }
@media (max-height: 500px) and (min-aspect-ratio: 4/3) {
  #friends .fr-invite { grid-template-columns: auto 1fr; align-items: center; }
  #friends .fr-invite .btn.big { min-height: 54px; width: auto; }
}
.banner.long {
  font-size: clamp(22px, 6vw, 32px); letter-spacing: 0; text-align: center; line-height: 1.15;
  width: min(86vw, 520px); animation: popLong 2.4s ease-out forwards;
}
@keyframes popLong { 0% { opacity: 0; transform: translate(-50%, -50%) scale(.7); } 8% { opacity: 1; transform: translate(-50%, -50%) scale(1.05); } 14% { transform: translate(-50%, -50%) scale(1); } 85% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -50%) scale(1); } }
