/* app.css — общие компоненты «Сянци: Путь Мастера». Подключать после tokens.css:
 *   <link rel="stylesheet" href="/css/tokens.css"><link rel="stylesheet" href="/css/app.css">
 *
 * Каркас:     body > main.page (ширина --page-max; body.is-wide → --page-max-wide), .appbar (шапка), .bottom-nav
 * Кнопки:     .btn + --primary | --secondary | --ghost | --danger | --jade | --gold | --tonal ; размеры --sm | --lg ; --block ; --icon (круглая 44px)
 * Карточки:   .card (+ --pad-lg, --interactive, --hero), .card__head/.card__title/.card__sub, .tile (крупная кнопка-карточка хаба)
 * Списки:     .list > .list-item (.list-item__lead / __main / __title / __sub / __trail), a.list-item — кликабельная строка
 * Мелочи:     .chip (+ --win/--loss/--draw/--gold/--sky/--jade), .badge, .avatar (ui.avatar()), .progress > .progress__fill (--value:0..1)
 *             .seg (сегмент-переключатель из <button aria-pressed>), .choice (радио-карточки), .switch (<label class=switch><input type=checkbox><span></span></label>)
 *             .stat-grid > .stat (.stat__value/.stat__label), .kbd, .divider, .section-title, .seal (иероглиф-печать)
 * Формы:      .field > label + .input/.select/.textarea + .field__hint ; .form-row
 * Таблицы:    .table-wrap > table.table
 * Состояния:  .empty, .skeleton, .spinner, .fullscreen-msg
 * Оверлеи:    .modal-backdrop > .modal(.modal--sheet), .toast-stack > .toast (делает ui.js)
 * Утилиты:    .row .col .wrap .grow .gap-1..5 .center .between .muted .small .mt-*, .sr-only, .hidden, .num (табличные цифры)
 */

*, *::before, *::after { box-sizing: border-box; }
html, body { overflow-x: hidden; }
body {
  min-height: 100vh; min-height: 100dvh;
  background-color: var(--bg);
  background-image:
    radial-gradient(circle at 20% 0%, var(--bg-pattern) 0 2px, transparent 3px),
    radial-gradient(circle at 70% 50%, var(--bg-pattern) 0 1.5px, transparent 2.5px);
  background-size: 28px 28px, 36px 36px;
}
img, svg { display: block; max-width: 100%; }
svg.ico { display: inline-block; flex: none; vertical-align: middle; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; font-weight: 800; letter-spacing: -.01em; }
p { margin: 0; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--r-sm); }
::selection { background: var(--primary-soft); }

/* ---------- каркас ---------- */
.page {
  width: 100%; max-width: var(--page-max); margin: 0 auto;
  padding: var(--sp-4) max(var(--sp-4), env(safe-area-inset-right)) calc(var(--sp-6) + env(safe-area-inset-bottom)) max(var(--sp-4), env(safe-area-inset-left));
}
body.is-wide .page { max-width: var(--page-max-wide); }
body.has-bottom-nav .page { padding-bottom: calc(88px + env(safe-area-inset-bottom)); }
.stack > * + * { margin-top: var(--sp-4); }
.stack-lg > * + * { margin-top: var(--sp-5); }

.appbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: var(--sp-2);
  min-height: 56px; padding: var(--sp-2) max(var(--sp-3), env(safe-area-inset-right)) var(--sp-2) max(var(--sp-3), env(safe-area-inset-left));
  padding-top: calc(var(--sp-2) + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(14px); backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
}
.appbar > * { max-width: var(--page-max); }
.appbar__title { flex: 1; min-width: 0; font-size: var(--fs-lg); font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-left: var(--sp-2); }
.appbar__actions { display: flex; gap: var(--sp-1); }
.in-tg .appbar { padding-top: var(--sp-2); }

.bottom-nav {
  position: fixed; left: 50%; bottom: 0; transform: translateX(-50%); z-index: 40;
  width: 100%; max-width: var(--page-max);
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px max(var(--sp-2), env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(var(--sp-2), env(safe-area-inset-left));
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.5) blur(16px); backdrop-filter: saturate(1.5) blur(16px);
  border-top: 1px solid var(--border);
}
@media (min-width: 600px) { .bottom-nav { bottom: var(--sp-3); border: 1px solid var(--border); border-radius: var(--r-xl); box-shadow: var(--shadow-3); width: calc(100% - 32px); max-width: 480px; padding-bottom: 6px; } }
.bottom-nav__item {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 52px; border-radius: var(--r-md);
  color: var(--ink-3); font-size: 11.5px; font-weight: 700; text-decoration: none !important;
  transition: color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.bottom-nav__item .ico { transition: transform var(--dur) var(--ease-bounce); }
.bottom-nav__item.is-active { color: var(--primary); }
.bottom-nav__item.is-active .ico { transform: translateY(-1px) scale(1.08); }
.bottom-nav__item:active { background: var(--surface-2); }

/* ---------- типографика ---------- */
.h1 { font-size: var(--fs-2xl); font-weight: 900; }
.h2 { font-size: var(--fs-xl); font-weight: 800; }
.h3 { font-size: var(--fs-lg); font-weight: 800; }
.section-title {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2);
  margin: var(--sp-5) 0 var(--sp-3); font-size: var(--fs-md); font-weight: 800; color: var(--ink);
}
.section-title a, .section-title .link { font-size: var(--fs-sm); font-weight: 700; }
.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); }
.small { font-size: var(--fs-sm); }
.xsmall { font-size: var(--fs-xs); }
.num { font-variant-numeric: tabular-nums; }
.brush { font-family: var(--font-brush); font-weight: 400; }
.kbd { font-family: var(--font-mono); font-size: .88em; padding: 1px 6px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); }
.divider { height: 1px; background: var(--border); border: 0; margin: var(--sp-4) 0; }

/* ---------- кнопки ---------- */
.btn {
  --btn-bg: var(--surface); --btn-fg: var(--ink); --btn-bd: var(--border); --btn-sh: var(--shadow-1);
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: 44px; padding: 0 var(--sp-4);
  border: 1px solid var(--btn-bd); border-radius: var(--r-md);
  background: var(--btn-bg); color: var(--btn-fg); box-shadow: var(--btn-sh);
  font-family: var(--font-ui); font-size: var(--fs-md); font-weight: 800; line-height: 1.1; letter-spacing: .005em;
  cursor: pointer; user-select: none; -webkit-user-select: none; text-decoration: none !important; white-space: nowrap;
  transition: transform 120ms var(--ease), background var(--dur) var(--ease), box-shadow var(--dur) var(--ease), opacity var(--dur);
}
.btn:hover { filter: brightness(1.03); }
.btn:active { transform: scale(.97); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .45; pointer-events: none; }
.btn--primary {
  --btn-bg: linear-gradient(180deg, color-mix(in srgb, var(--primary) 88%, #fff) 0%, var(--primary) 55%, var(--primary-hover) 100%);
  --btn-fg: var(--on-accent); --btn-bd: transparent;
  --btn-sh: 0 1px 0 rgba(255,255,255,.25) inset, 0 -2px 0 rgba(0,0,0,.12) inset, 0 4px 12px color-mix(in srgb, var(--primary) 35%, transparent);
}
.btn--jade {
  --btn-bg: linear-gradient(180deg, color-mix(in srgb, var(--jade) 85%, #fff), var(--jade));
  --btn-fg: var(--on-accent); --btn-bd: transparent;
  --btn-sh: 0 1px 0 rgba(255,255,255,.25) inset, 0 -2px 0 rgba(0,0,0,.12) inset, 0 4px 12px color-mix(in srgb, var(--jade) 30%, transparent);
}
.btn--gold {
  --btn-bg: linear-gradient(180deg, color-mix(in srgb, var(--gold) 80%, #fff), var(--gold));
  --btn-fg: #2b1c05; --btn-bd: transparent;
  --btn-sh: 0 1px 0 rgba(255,255,255,.35) inset, 0 -2px 0 rgba(0,0,0,.1) inset, 0 4px 12px color-mix(in srgb, var(--gold) 30%, transparent);
}
.btn--secondary { --btn-bg: var(--surface); }
.btn--tonal { --btn-bg: var(--primary-soft); --btn-fg: var(--primary); --btn-bd: transparent; --btn-sh: none; }
.btn--ghost { --btn-bg: transparent; --btn-bd: transparent; --btn-sh: none; }
.btn--ghost:hover { --btn-bg: var(--surface-2); }
.btn--danger { --btn-bg: var(--danger); --btn-fg: var(--on-accent); --btn-bd: transparent; --btn-sh: 0 4px 12px color-mix(in srgb, var(--danger) 30%, transparent); }
.btn--sm { min-height: 36px; padding: 0 var(--sp-3); font-size: var(--fs-sm); border-radius: var(--r-sm); }
.btn--lg { min-height: 56px; padding: 0 var(--sp-5); font-size: var(--fs-lg); border-radius: var(--r-lg); }
.btn--block { display: flex; width: 100%; }
.btn--icon { width: 44px; min-width: 44px; padding: 0; border-radius: 50%; }
.btn--icon.btn--sm { width: 36px; min-width: 36px; }
.btn.is-loading { color: transparent !important; pointer-events: none; }
.btn.is-loading::after {
  content: ''; position: absolute; width: 20px; height: 20px; border-radius: 50%;
  border: 2.5px solid var(--btn-fg); border-right-color: transparent; animation: spin .7s linear infinite;
}
.btn-row { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 0; }

/* ---------- карточки ---------- */
.card {
  position: relative; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: var(--sp-4); box-shadow: var(--shadow-1);
}
.card--pad-lg { padding: var(--sp-5); }
.card--flush { padding: 0; overflow: hidden; }
.card--interactive { cursor: pointer; transition: transform 140ms var(--ease), box-shadow var(--dur) var(--ease); color: inherit; text-decoration: none !important; display: block; }
.card--interactive:hover { box-shadow: var(--shadow-2); }
.card--interactive:active { transform: scale(.985); }
.card__head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); margin-bottom: var(--sp-3); }
.card__title { font-size: var(--fs-lg); font-weight: 800; }
.card__sub { color: var(--ink-2); font-size: var(--fs-sm); }
.card--hero {
  color: #fff8ec; border: 0; overflow: hidden; isolation: isolate;
  background:
    radial-gradient(120% 90% at 100% 0%, rgba(255,210,140,.35), transparent 55%),
    linear-gradient(145deg, #c23a2a 0%, #9f2a1e 55%, #7a1f16 100%);
  box-shadow: 0 10px 30px rgba(140,30,20,.3), 0 1px 0 rgba(255,255,255,.15) inset;
}
.card--hero .muted { color: rgba(255,245,230,.78); }

/* крупная карточка-действие хаба */
.tile {
  position: relative; display: flex; align-items: center; gap: var(--sp-3);
  min-height: 76px; padding: var(--sp-3) var(--sp-4); width: 100%; text-align: left;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-1);
  color: var(--ink); text-decoration: none !important; cursor: pointer; overflow: hidden;
  transition: transform 140ms var(--ease), box-shadow var(--dur) var(--ease);
}
.tile:hover { box-shadow: var(--shadow-2); }
.tile:active { transform: scale(.98); }
.tile__icon {
  --tint: var(--primary); flex: none; display: grid; place-items: center; width: 48px; height: 48px; border-radius: 15px;
  color: var(--tint); background: color-mix(in srgb, var(--tint) 14%, var(--surface));
}
.tile__main { flex: 1; min-width: 0; }
.tile__title { display: block; font-weight: 800; font-size: var(--fs-md); line-height: 1.25; }
.tile__sub { display: block; color: var(--ink-2); font-size: var(--fs-sm); line-height: 1.3; margin-top: 2px; }
.tile__chev { color: var(--ink-3); flex: none; }
.tile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
.tile-grid .tile { flex-direction: column; align-items: flex-start; min-height: 128px; padding: var(--sp-4); }
.tile-grid .tile__chev { display: none; }

/* ---------- списки ---------- */
.list { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; box-shadow: var(--shadow-1); }
.list-item { display: flex; align-items: center; gap: var(--sp-3); min-height: 60px; padding: var(--sp-2) var(--sp-4); color: inherit; text-decoration: none !important; }
.list-item + .list-item { border-top: 1px solid var(--border); }
a.list-item, button.list-item { cursor: pointer; background: none; border-left: 0; border-right: 0; border-bottom: 0; width: 100%; text-align: left; font: inherit; transition: background var(--dur); }
a.list-item:active, button.list-item:active { background: var(--surface-2); }
@media (hover: hover) { a.list-item:hover, button.list-item:hover { background: color-mix(in srgb, var(--surface-2) 60%, transparent); } }
.list-item__lead { flex: none; }
.list-item__main { flex: 1; min-width: 0; }
.list-item__title { display: block; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item__sub { display: block; color: var(--ink-2); font-size: var(--fs-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item__trail { flex: none; display: flex; align-items: center; gap: var(--sp-2); color: var(--ink-3); font-size: var(--fs-sm); }

/* ---------- чипы, бейджи, аватары ---------- */
.chip {
  --c: var(--ink-2); display: inline-flex; align-items: center; gap: 4px; height: 26px; padding: 0 10px;
  border-radius: var(--r-pill); font-size: var(--fs-xs); font-weight: 800; letter-spacing: .01em; white-space: nowrap;
  color: var(--c); background: color-mix(in srgb, var(--c) 13%, transparent);
}
.chip .ico { width: 14px; height: 14px; }
.chip--win, .chip--jade { --c: var(--win); }
.chip--loss { --c: var(--loss); }
.chip--draw, .chip--sky { --c: var(--draw); }
.chip--gold { --c: var(--gold); }
.chip--live { --c: var(--warn); }
.chip--red { --c: var(--piece-red); }
.chip--black { --c: var(--ink); }
.badge { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: var(--r-pill); background: var(--primary); color: var(--on-accent); font-size: 11px; font-weight: 900; }
.avatar {
  --size: 40px; flex: none; display: inline-grid; place-items: center; width: var(--size); height: var(--size); border-radius: 50%;
  background: color-mix(in srgb, var(--av, var(--primary)) 18%, var(--surface)); color: var(--av, var(--primary));
  font-weight: 900; font-size: calc(var(--size) * .4); line-height: 1; user-select: none;
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 3px color-mix(in srgb, var(--av, var(--primary)) 30%, transparent);
}
.avatar--emoji { font-size: calc(var(--size) * .56); background: var(--surface-2); }
.seal {
  display: inline-grid; place-items: center; width: 56px; height: 56px; border-radius: 14px;
  font-family: var(--font-piece); font-weight: 900; font-size: 32px; line-height: 1;
  color: #fff6e6; background: linear-gradient(145deg, #c9402f, #8f2419);
  box-shadow: 0 1px 0 rgba(255,255,255,.25) inset, 0 6px 16px rgba(143,36,25,.3);
  transform: rotate(-4deg);
}

/* ---------- прогресс ---------- */
.progress { --value: 0; position: relative; height: 10px; border-radius: var(--r-pill); background: var(--surface-3); overflow: hidden; }
.progress__fill {
  position: absolute; inset: 0 auto 0 0; width: calc(var(--value) * 100%); min-width: 10px; border-radius: inherit;
  background: linear-gradient(90deg, var(--gold), color-mix(in srgb, var(--gold) 70%, #fff));
  box-shadow: 0 0 10px color-mix(in srgb, var(--gold) 50%, transparent);
  transition: width 900ms var(--ease);
}
.progress--jade .progress__fill { background: linear-gradient(90deg, var(--jade), color-mix(in srgb, var(--jade) 65%, #fff)); box-shadow: none; }

/* ---------- сегменты и выбор ---------- */
.seg { display: flex; padding: 4px; gap: 4px; border-radius: var(--r-md); background: var(--surface-2); border: 1px solid var(--border); }
.seg > button {
  flex: 1; min-height: 40px; border: 0; border-radius: 10px; background: transparent; color: var(--ink-2);
  font-weight: 800; font-size: var(--fs-sm); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), box-shadow var(--dur);
}
.seg > button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }

.choice-list { display: grid; gap: var(--sp-2); }
.choice {
  display: flex; align-items: center; gap: var(--sp-3); width: 100%; min-height: 64px; padding: var(--sp-3);
  border: 2px solid var(--border); border-radius: var(--r-md); background: var(--surface); cursor: pointer; text-align: left;
  transition: border-color var(--dur), background var(--dur), transform 120ms var(--ease);
}
.choice:active { transform: scale(.985); }
.choice[aria-checked="true"], .choice[aria-pressed="true"] { border-color: var(--primary); background: color-mix(in srgb, var(--primary-soft) 55%, var(--surface)); }
.choice__icon { flex: none; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; background: var(--surface-2); font-family: var(--font-piece); font-weight: 900; font-size: 22px; }
.choice__main { flex: 1; min-width: 0; }
.choice__title { font-weight: 800; display: flex; align-items: center; gap: var(--sp-2); }
.choice__sub { color: var(--ink-2); font-size: var(--fs-sm); line-height: 1.3; }
.choice__check { flex: none; width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--border); display: grid; place-items: center; color: transparent; transition: all var(--dur); }
.choice[aria-checked="true"] .choice__check { background: var(--primary); border-color: var(--primary); color: var(--on-accent); }

.switch { position: relative; display: inline-flex; align-items: center; gap: var(--sp-3); cursor: pointer; min-height: 44px; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch > span:first-of-type { flex: none; position: relative; width: 48px; height: 28px; border-radius: var(--r-pill); background: var(--surface-3); transition: background var(--dur); }
.switch > span:first-of-type::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-1); transition: transform var(--dur) var(--ease-bounce); }
.switch input:checked + span { background: var(--jade); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { box-shadow: var(--focus); }

/* ---------- статистика ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: var(--sp-2); }
.stat { padding: var(--sp-3); border-radius: var(--r-md); background: var(--surface-2); text-align: center; }
.stat__value { font-size: var(--fs-xl); font-weight: 900; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat__label { font-size: var(--fs-xs); color: var(--ink-2); font-weight: 700; margin-top: 2px; }

/* ---------- формы ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--sp-4); }
.field > label, .label { font-size: var(--fs-sm); font-weight: 800; color: var(--ink-2); }
.field__hint { font-size: var(--fs-xs); color: var(--ink-3); }
.field__error { font-size: var(--fs-xs); color: var(--danger); font-weight: 700; }
.input, .select, .textarea {
  width: 100%; min-height: 48px; padding: 10px 14px; border-radius: var(--r-md);
  border: 1.5px solid var(--border); background: var(--surface); color: var(--ink);
  font: inherit; font-size: var(--fs-md); transition: border-color var(--dur), box-shadow var(--dur);
}
.textarea { min-height: 96px; resize: vertical; line-height: 1.45; }
.select { appearance: none; -webkit-appearance: none; padding-right: 40px;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%), linear-gradient(135deg, var(--ink-3) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%; background-size: 6px 6px; background-repeat: no-repeat; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus); }
.input::placeholder, .textarea::placeholder { color: var(--ink-3); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
@media (max-width: 420px) { .form-row { grid-template-columns: 1fr; } }

/* ---------- таблицы ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.table th { position: sticky; top: 0; background: var(--surface-2); color: var(--ink-2); font-weight: 800; font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .04em; text-align: left; }
.table th, .table td { padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 50%, transparent); }
.table .t-right { text-align: right; }

/* ---------- состояния ---------- */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--sp-2); padding: var(--sp-6) var(--sp-4); color: var(--ink-2); }
.empty__icon { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); color: var(--ink-3); margin-bottom: var(--sp-2); }
.empty__title { font-weight: 800; color: var(--ink); font-size: var(--fs-lg); }
.empty__text { max-width: 320px; font-size: var(--fs-sm); }
.skeleton { position: relative; overflow: hidden; background: var(--surface-2); border-radius: var(--r-md); color: transparent !important; min-height: 16px; }
.skeleton::after { content: ''; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--surface) 60%, transparent), transparent); animation: shimmer 1.3s infinite; }
@keyframes shimmer { to { transform: translateX(100%); } }
.spinner { --size: 28px; display: inline-block; width: var(--size); height: var(--size); border-radius: 50%; border: 3px solid var(--surface-3); border-top-color: var(--primary); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.page-loader { display: grid; place-items: center; min-height: 50vh; }

.fullscreen-msg { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: var(--sp-5); background: var(--bg); }
.fullscreen-msg__card { max-width: 400px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: var(--sp-3); }
.fullscreen-msg__card .seal { width: 84px; height: 84px; font-size: 48px; border-radius: 22px; margin-bottom: var(--sp-3); }
.fullscreen-msg__card h1 { font-size: var(--fs-xl); }
.fullscreen-msg__card p { color: var(--ink-2); }
.fullscreen-msg__actions { width: 100%; margin-top: var(--sp-3); display: grid; gap: var(--sp-2); }

/* ---------- модалки ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: var(--sp-4);
  background: rgba(20,12,6,.0); transition: background 220ms var(--ease);
}
.modal-backdrop.is-open { background: rgba(20,12,6,.45); }
.modal {
  width: 100%; max-width: 420px; max-height: calc(100dvh - 32px); overflow: auto; overscroll-behavior: contain;
  background: var(--surface); border-radius: var(--r-xl); box-shadow: var(--shadow-3); padding: var(--sp-4) var(--sp-5) var(--sp-5);
  opacity: 0; transform: translateY(12px) scale(.97); transition: opacity 220ms var(--ease), transform 260ms var(--ease-bounce);
}
.modal-backdrop.is-open .modal { opacity: 1; transform: none; }
.modal-backdrop.is-closing .modal { opacity: 0; transform: translateY(8px) scale(.98); transition-duration: 160ms; }
.modal__head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); margin: 0 calc(var(--sp-2) * -1) var(--sp-2) 0; min-height: 44px; }
.modal__title { font-size: var(--fs-lg); font-weight: 900; }
.modal__text { color: var(--ink-2); }
.modal__actions { display: flex; gap: var(--sp-2); margin-top: var(--sp-5); }
.modal__actions > .btn { flex: 1; }
.modal__grip { width: 40px; height: 5px; border-radius: 3px; background: var(--surface-3); margin: 0 auto var(--sp-2); }
@media (max-width: 599px) {
  .modal-backdrop.is-sheet { place-items: end stretch; padding: 0; }
  .modal--sheet {
    max-width: none; border-radius: var(--r-xl) var(--r-xl) 0 0; max-height: 92dvh;
    padding-bottom: calc(var(--sp-5) + env(safe-area-inset-bottom)); transform: translateY(100%);
    transition: transform 300ms var(--ease), opacity 200ms;
  }
  .modal-backdrop.is-closing .modal--sheet { transform: translateY(100%); }
}
@media (min-width: 600px) { .modal__grip { display: none; } }
body.has-modal { overflow: hidden; }

/* ---------- тосты ---------- */
.toast-stack {
  position: fixed; z-index: 100; left: 50%; transform: translateX(-50%);
  top: calc(var(--sp-3) + env(safe-area-inset-top)); width: min(420px, calc(100% - 24px));
  display: flex; flex-direction: column; gap: var(--sp-2); pointer-events: none;
}
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: var(--sp-2); padding: 12px 16px;
  border-radius: var(--r-md); background: var(--ink); color: var(--bg); font-weight: 700; font-size: var(--fs-sm);
  box-shadow: var(--shadow-3); opacity: 0; transform: translateY(-12px) scale(.96);
  transition: opacity 200ms var(--ease), transform 260ms var(--ease-bounce);
}
.toast.is-in { opacity: 1; transform: none; }
.toast.is-out { opacity: 0; transform: translateY(-8px); }
.toast--success .ico { color: var(--jade); }
.toast--error .ico { color: var(--primary); }
.toast--warn .ico { color: var(--gold); }
[data-theme="dark"] .toast--success .ico, .toast--success .ico { filter: saturate(1.2); }

/* ---------- утилиты ---------- */
.row { display: flex; align-items: center; gap: var(--sp-3); }
.col { display: flex; flex-direction: column; gap: var(--sp-2); }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.between { justify-content: space-between; }
.center { text-align: center; }
.gap-1 { gap: var(--sp-1); } .gap-2 { gap: var(--sp-2); } .gap-3 { gap: var(--sp-3); } .gap-4 { gap: var(--sp-4); } .gap-5 { gap: var(--sp-5); }
.mt-1 { margin-top: var(--sp-1); } .mt-2 { margin-top: var(--sp-2); } .mt-3 { margin-top: var(--sp-3); } .mt-4 { margin-top: var(--sp-4); } .mt-5 { margin-top: var(--sp-5); }
.hidden, [hidden] { display: none !important; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

@keyframes fade-up { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.appear > * { animation: fade-up 420ms var(--ease) both; }
.appear > *:nth-child(2) { animation-delay: 50ms; } .appear > *:nth-child(3) { animation-delay: 100ms; }
.appear > *:nth-child(4) { animation-delay: 150ms; } .appear > *:nth-child(5) { animation-delay: 200ms; }
.appear > *:nth-child(6) { animation-delay: 250ms; } .appear > *:nth-child(n+7) { animation-delay: 300ms; }

/* ====================================================================
   Доска (board.js). Все размеры — в единицах SVG, цвета — из токенов.
   ==================================================================== */
.xq-board { position: relative; width: 100%; max-width: 100%; margin: 0 auto; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.xq-board.is-static { touch-action: auto; }
.xq-board svg { width: 100%; height: auto; overflow: visible; }
.xq-board .xq-grid { stroke: var(--board-line); stroke-linecap: round; }
.xq-board .xq-coord { fill: var(--board-line); opacity: .62; font-family: var(--font-ui); font-weight: 800; font-size: 15px; }
.xq-board .xq-river { fill: var(--board-river-text); font-family: var(--font-brush); font-size: 44px; opacity: .88; }
.xq-piece { cursor: default; will-change: transform; }
.xq-board.is-interactive .xq-piece.is-mine { cursor: grab; }
.xq-piece .xq-lift { transition: transform 160ms var(--ease-bounce); }
.xq-piece.is-selected .xq-lift { transform: translateY(-5px) scale(1.07); }
.xq-piece.is-dragging { cursor: grabbing; }
.xq-piece.is-dragging .xq-lift { transform: translateY(-4px) scale(1.16); transition: none; }
.xq-piece.is-selected .xq-shadow { transform: translate(2px, 8px) scale(1.04); opacity: .75; }
.xq-piece .xq-shadow { transition: transform 160ms var(--ease), opacity 160ms; }
.xq-piece.is-captured { pointer-events: none; }
.xq-board:not(.has-labels) .xq-label { display: none; }
.xq-glyph { font-family: var(--font-piece); font-weight: 900; font-size: 44px; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.xq-piece.is-red .xq-glyph { fill: var(--piece-red); }
.xq-piece.is-black .xq-glyph { fill: var(--piece-black); }
.xq-piece.is-red .xq-ring { stroke: var(--piece-red); }
.xq-piece.is-black .xq-ring { stroke: var(--piece-black); }
.xq-label { font-family: var(--font-ui); font-weight: 900; font-size: 12px; text-anchor: middle; letter-spacing: -.02em; pointer-events: none; }
.xq-piece.is-red .xq-label { fill: var(--piece-red); }
.xq-piece.is-black .xq-label { fill: var(--piece-black); }
.xq-glyph-g { transition: transform 160ms var(--ease); }
.xq-board.has-labels .xq-glyph-g { transform: translateY(-7px) scale(.7); }

.xq-move-dot { fill: var(--hl-move); pointer-events: none; animation: xq-pop 180ms var(--ease-bounce) both; }
.xq-move-ring { fill: none; stroke: var(--hl-capture); stroke-width: 5; pointer-events: none; animation: xq-pop 200ms var(--ease-bounce) both; }
@keyframes xq-pop { from { transform: scale(.3); opacity: 0; } }
.xq-last { fill: var(--hl-last); }
.xq-last-from { fill: var(--hl-last); stroke: color-mix(in srgb, var(--gold) 80%, #000); stroke-width: 2.5; stroke-dasharray: 5 5; opacity: .9; }
.xq-last-corners { fill: none; stroke: color-mix(in srgb, var(--gold) 85%, #000); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.xq-hl-target { fill: none; stroke: var(--hl-select); stroke-width: 5; }
.xq-hl-hint { fill: none; stroke: var(--hl-hint); stroke-width: 5; animation: xq-hint 1.1s ease-in-out infinite; }
@keyframes xq-hint { 50% { stroke-width: 9; opacity: .55; } }
.xq-check-glow { animation: xq-check 1.15s ease-in-out infinite; transform-box: fill-box; transform-origin: center; pointer-events: none; }
@keyframes xq-check { 0%, 100% { opacity: .55; transform: scale(.92); } 50% { opacity: 1; transform: scale(1.12); } }
.xq-drop-hover { fill: none; stroke: var(--hl-select); stroke-width: 4; opacity: .9; }
.xq-arrow { stroke-width: 11; stroke-linecap: round; opacity: .82; pointer-events: none; }
.xq-arrow--good { stroke: var(--jade); fill: var(--jade); }
.xq-arrow--bad { stroke: var(--primary); fill: var(--primary); }
.xq-arrow--info { stroke: var(--sky); fill: var(--sky); }
.xq-mark-dot { fill: var(--jade); opacity: .85; }
.xq-mark-cross { stroke: var(--primary); stroke-width: 7; stroke-linecap: round; }
.xq-mark-ring { fill: none; stroke: var(--gold); stroke-width: 5; }
.xq-mark-label-bg { fill: var(--sky); }
.xq-mark-label { fill: #fff; font-family: var(--font-ui); font-weight: 900; font-size: 22px; text-anchor: middle; dominant-baseline: central; }

.xq-diagram { margin: var(--sp-4) auto; max-width: 420px; }
.xq-diagram figcaption, .xq-diagram__caption { text-align: center; color: var(--ink-2); font-size: var(--fs-sm); margin-top: var(--sp-2); }

@media (prefers-reduced-motion: reduce) {
  .xq-check-glow, .xq-hl-hint { animation: none; }
  .xq-piece .xq-lift, .xq-piece .xq-shadow { transition: none; }
}

/* ====================================================================
   Общие игровые элементы: фишка, строка партии
   ==================================================================== */
.mini-piece {
  --size: 44px; --pc: var(--piece-red);
  position: relative; flex: none; display: inline-grid; place-items: center; width: var(--size); height: var(--size); border-radius: 50%;
  font-family: var(--font-piece); font-weight: 900; font-size: calc(var(--size) * .5); line-height: 1; color: var(--pc);
  background: radial-gradient(circle at 42% 34%, color-mix(in srgb, var(--piece-face) 60%, #fff), var(--piece-face) 62%, color-mix(in srgb, var(--piece-face) 80%, var(--piece-rim)));
  box-shadow: 0 calc(var(--size) * .06) 0 color-mix(in srgb, var(--piece-rim) 80%, #3a1d05), 0 calc(var(--size) * .12) calc(var(--size) * .22) var(--piece-shadow), inset 0 0 0 1.5px var(--piece-rim);
}
.mini-piece::after { content: ''; position: absolute; inset: calc(var(--size) * .1); border-radius: 50%; border: 1.5px solid var(--pc); opacity: .8; }
.mini-piece--black { --pc: var(--piece-black); }

.game-row__badge { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; color: var(--c, var(--ink-3)); background: color-mix(in srgb, var(--c, var(--ink-3)) 14%, var(--surface)); }
.game-row--win { --c: var(--win); } .game-row--loss { --c: var(--loss); } .game-row--draw { --c: var(--draw); } .game-row--live { --c: var(--warn); }
.delta { font-weight: 900; font-variant-numeric: tabular-nums; font-size: var(--fs-xs); padding: 2px 6px; border-radius: 6px; }
.delta.is-up { color: var(--win); background: var(--jade-soft); }
.delta.is-down { color: var(--loss); background: var(--primary-soft); }
.level-dots { display: inline-flex; gap: 3px; margin-left: 2px; }
.level-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--surface-3); }
.level-dots i.on { background: var(--primary); }
.color-dot { width: 16px; height: 16px; border-radius: 50%; box-shadow: inset 0 0 0 2px var(--piece-rim); }
.color-dot--red { background: var(--piece-red); }
.color-dot--black { background: var(--piece-black); }
.modal--wide { max-width: 480px; }

/* ====================================================================
   Главная (index.html)
   ==================================================================== */
.home > * + * { margin-top: var(--sp-4); }
.home > .section-title { margin-top: var(--sp-5); margin-bottom: 0; }
.home > .section-title + * { margin-top: var(--sp-3); }
.home-hello { display: flex; align-items: center; gap: var(--sp-3); padding-top: calc(var(--sp-2) + env(safe-area-inset-top)); }
.in-tg .home-hello { padding-top: var(--sp-2); }
.home-hello__avatar { text-decoration: none !important; border-radius: 50%; }
.home-hello__hi { color: var(--ink-2); font-weight: 700; font-size: var(--fs-sm); line-height: 1.2; }
.home-hello__name { font-size: var(--fs-2xl); font-weight: 900; line-height: 1.1; letter-spacing: -.02em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.home-hello__rating {
  display: flex; flex-direction: column; align-items: center; justify-content: center; min-width: 64px; min-height: 52px; padding: 4px 10px;
  border-radius: var(--r-md); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-1);
  color: var(--ink-2); font-size: 11px; font-weight: 800; line-height: 1.1; text-decoration: none !important;
}
.home-hello__rating-num { color: var(--ink); font-size: var(--fs-lg); font-weight: 900; }

.level-card { display: flex; align-items: center; gap: var(--sp-4); padding: var(--sp-4); }
.level-card__seal {
  flex: none; width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center;
  font-family: var(--font-piece); font-weight: 900; font-size: 34px; color: #5a3a06;
  background: radial-gradient(circle at 40% 32%, #fff3cf, var(--gold) 70%, color-mix(in srgb, var(--gold) 70%, #5a3a06));
  box-shadow: 0 4px 0 color-mix(in srgb, var(--gold) 60%, #3a2604), 0 8px 18px color-mix(in srgb, var(--gold) 40%, transparent), inset 0 0 0 3px rgba(255,255,255,.35);
}
.level-card__kicker { font-size: var(--fs-xs); font-weight: 800; color: var(--ink-3); text-transform: uppercase; letter-spacing: .08em; }
.level-card__title { font-size: var(--fs-xl); font-weight: 900; line-height: 1.1; }
.level-card__xp { display: flex; justify-content: space-between; gap: var(--sp-2); margin-top: 6px; font-size: var(--fs-xs); color: var(--ink-2); font-weight: 700; }

.resume {
  display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-3) var(--sp-3) var(--sp-4);
  border-radius: var(--r-lg); background: var(--warn-soft); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent);
  color: var(--ink); text-decoration: none !important;
}
.resume b { display: block; }
.resume__sub { display: block; font-size: var(--fs-sm); color: var(--ink-2); }
.resume__pulse { flex: none; width: 12px; height: 12px; border-radius: 50%; background: var(--warn); box-shadow: 0 0 0 0 var(--warn); animation: pulse-ring 1.6s infinite; }
@keyframes pulse-ring { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--warn) 60%, transparent); } 100% { box-shadow: 0 0 0 12px transparent; } }

.play-hero {
  position: relative; display: flex; width: 100%; min-height: 176px; padding: var(--sp-5); border: 0; border-radius: var(--r-xl);
  text-align: left; cursor: pointer; overflow: hidden; isolation: isolate; color: #fff8ec;
  background:
    radial-gradient(90% 120% at 100% 100%, rgba(255,200,120,.35), transparent 60%),
    radial-gradient(60% 80% at 0% 0%, rgba(255,255,255,.12), transparent 60%),
    linear-gradient(150deg, #cf4330 0%, #a82b1f 50%, #7c1d14 100%);
  box-shadow: 0 14px 34px rgba(150,35,20,.32), 0 2px 0 rgba(255,255,255,.18) inset, 0 -3px 0 rgba(0,0,0,.14) inset;
  transition: transform 140ms var(--ease), box-shadow var(--dur);
}
.play-hero::before {  /* сетка доски водяным знаком */
  content: ''; position: absolute; inset: -20px -20px -20px 45%; z-index: -1; opacity: .16;
  background-image: linear-gradient(rgba(255,240,220,.9) 1.5px, transparent 1.5px), linear-gradient(90deg, rgba(255,240,220,.9) 1.5px, transparent 1.5px);
  background-size: 34px 34px; transform: rotate(-12deg);
  -webkit-mask-image: radial-gradient(circle at 60% 50%, #000 30%, transparent 75%); mask-image: radial-gradient(circle at 60% 50%, #000 30%, transparent 75%);
}
.play-hero:active { transform: scale(.985); }
.play-hero__text { position: relative; z-index: 1; display: flex; flex-direction: column; gap: 4px; max-width: 64%; }
.play-hero__kicker { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-xs); font-weight: 800; text-transform: uppercase; letter-spacing: .08em; color: rgba(255,240,220,.85); }
.play-hero__title { font-size: 38px; font-weight: 900; line-height: 1; letter-spacing: -.02em; text-shadow: 0 2px 0 rgba(0,0,0,.12); }
.play-hero__sub { font-size: var(--fs-sm); color: rgba(255,240,225,.85); font-weight: 600; line-height: 1.3; }
.play-hero__cta {
  margin-top: var(--sp-3); align-self: flex-start; display: inline-flex; align-items: center; gap: 4px; min-height: 40px; padding: 0 14px 0 16px;
  border-radius: var(--r-pill); background: #fff8ec; color: #9f2a1e; font-weight: 900; font-size: var(--fs-sm);
  box-shadow: 0 4px 12px rgba(60,10,5,.25);
}
.play-hero__art { position: absolute; right: 14px; top: 50%; width: 140px; height: 150px; transform: translateY(-50%); }
.play-hero__art .mini-piece { position: absolute; }
.play-hero__art .mini-piece:nth-child(1) { right: 10px; top: 36px; transform: rotate(-8deg); }
.play-hero__art .mini-piece:nth-child(2) { right: 74px; top: 2px; transform: rotate(10deg); }
.play-hero__art .mini-piece:nth-child(3) { right: 78px; bottom: 6px; transform: rotate(-14deg); }
@media (hover: hover) { .play-hero:hover .play-hero__art .mini-piece:nth-child(1) { transform: rotate(-2deg) translateY(-3px); } }
.play-hero__art .mini-piece { transition: transform 300ms var(--ease-bounce); }
.tile.is-busy { opacity: .6; pointer-events: none; }
.library-seal { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; color: var(--gold); background: var(--gold-soft); }
.home-foot { display: flex; align-items: center; justify-content: center; gap: 4px; color: var(--ink-3); font-size: var(--fs-xs); font-weight: 700; margin-top: var(--sp-5) !important; text-align: center; }
@media (max-width: 360px) { .play-hero__art { opacity: .5; right: -10px; } .play-hero__text { max-width: 80%; } }
.confetti { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 95; pointer-events: none; }

/* ====================================================================
   Партия (play.html) и реплей (replay.html)
   ==================================================================== */
.game-body { overscroll-behavior: none; }
.game { width: 100%; max-width: var(--page-max); margin: 0 auto; padding: 0 max(var(--sp-3), env(safe-area-inset-right)) calc(var(--sp-3) + env(safe-area-inset-bottom)) max(var(--sp-3), env(safe-area-inset-left)); }
.game-top { display: flex; align-items: center; gap: var(--sp-2); min-height: 52px; padding-top: env(safe-area-inset-top); }
.in-tg .game-top { padding-top: 0; }
.game-top__title { flex: 1; min-width: 0; padding: 0 var(--sp-1); }
.game-top__back[hidden] + .game-top__title { padding-left: var(--sp-1); }
.game-top__main { font-weight: 900; font-size: var(--fs-md); line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.game-top__sub { font-size: var(--fs-sm); font-weight: 700; color: var(--ink-2); line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: color var(--dur); }
.game-top__sub.is-alert { color: var(--danger); }
.net-dot { flex: none; width: 10px; height: 10px; margin: 0 var(--sp-2); border-radius: 50%; background: var(--jade); box-shadow: 0 0 0 3px color-mix(in srgb, var(--jade) 20%, transparent); transition: background var(--dur); }
.net-dot.is-off { background: var(--warn); animation: pulse-ring 1.2s infinite; }

.game-layout { display: flex; flex-direction: column; gap: var(--sp-2); }
.game-board-col { display: flex; flex-direction: column; gap: 6px; }
.board-wrap {
  position: relative; margin: 0 auto;
  width: min(100%, calc((var(--tg-viewport-stable-height, 100dvh) - 292px) * .857));
  min-width: 280px;
}
/* колонка minmax(0,1fr): иначе auto-колонка растягивается по длинному тексту карточки, и та уезжает вправо за край */
.board-overlay { position: absolute; inset: 0; z-index: 5; display: grid; grid-template-columns: minmax(0, 1fr); place-items: center; overflow-y: auto; padding: var(--sp-3); border-radius: 22px; background: color-mix(in srgb, var(--bg) 55%, transparent); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); animation: fade-up 300ms var(--ease); }

/* игроки */
.player {
  display: flex; align-items: center; gap: var(--sp-3); min-height: 54px; padding: 6px 8px 6px 6px;
  border-radius: var(--r-lg); border: 1.5px solid transparent; transition: background var(--dur), border-color var(--dur), box-shadow var(--dur);
}
.player.is-active { background: var(--surface); border-color: color-mix(in srgb, var(--gold) 55%, var(--border)); box-shadow: var(--shadow-1); }
.player__avatar { position: relative; flex: none; }
.avatar--ai { --av: var(--sky); }
.player__color { position: absolute; right: -3px; bottom: -3px; width: 16px; height: 16px; border-radius: 50%; border: 2.5px solid var(--bg); }
.player.is-active .player__color { border-color: var(--surface); }
.player__color--red { background: var(--piece-red); }
.player__color--black { background: var(--piece-black); }
[data-theme="dark"] .player__color--black { background: #6b5e52; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .player__color--black { background: #6b5e52; } }
.player__main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.player__name { font-weight: 800; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 6px; }
.player__nm { min-width: 0; overflow: hidden; text-overflow: ellipsis; }   /* длинное имя сокращается, чип «ты» остаётся целым */
.player__you { flex: none; font-size: 10.5px; font-weight: 900; text-transform: uppercase; letter-spacing: .06em; color: var(--primary); background: var(--primary-soft); padding: 1px 6px; border-radius: 6px; }
.player__meta { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; font-size: var(--fs-xs); color: var(--ink-2); font-weight: 700; line-height: 1.3; }
.player__status { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.player__status.is-thinking { color: var(--sky); }
.player__status.is-offline { color: var(--ink-3); }
.online-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--jade); }
.is-offline .online-dot { background: var(--ink-3); }
.dots { display: inline-flex; gap: 2px; margin-left: 1px; }
.dots i { width: 4px; height: 4px; border-radius: 50%; background: currentColor; animation: dot-bounce 1s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: .15s; } .dots i:nth-child(3) { animation-delay: .3s; }
@keyframes dot-bounce { 0%, 60%, 100% { transform: none; opacity: .5; } 30% { transform: translateY(-3px); opacity: 1; } }
.player__caps { display: inline-flex; align-items: center; gap: 1px; min-width: 0; overflow: hidden; }
.cap { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; font-family: var(--font-piece); font-weight: 900; font-size: 11px; line-height: 1; background: var(--piece-face); box-shadow: inset 0 0 0 1px var(--piece-rim); }
.cap--red { color: var(--piece-red); } .cap--black { color: var(--piece-black); }
.cap + .cap { margin-left: -4px; }
.cap-more { margin-left: 3px; font-size: 11px; color: var(--ink-3); }
.clock {
  flex: none; display: inline-flex; align-items: center; gap: 5px; min-width: 76px; justify-content: center; height: 36px; padding: 0 10px;
  border-radius: var(--r-md); background: var(--surface-2); color: var(--ink-2); font-weight: 800; font-size: var(--fs-md);
  transition: background var(--dur), color var(--dur);
}
.clock.is-running { background: var(--ink); color: var(--bg); }
.clock.is-running .ico { animation: spin 4s linear infinite; }

/* ходы */
.moves { overflow-x: auto; overflow-y: hidden; scrollbar-width: none; -webkit-overflow-scrolling: touch; min-height: 40px; mask-image: linear-gradient(90deg, transparent 0, #000 14px, #000 calc(100% - 14px), transparent); -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 14px, #000 calc(100% - 14px), transparent); }
.moves::-webkit-scrollbar { display: none; }
.moves__empty { display: flex; align-items: center; justify-content: center; min-height: 40px; color: var(--ink-3); font-size: var(--fs-sm); font-weight: 700; }
.moves__list { display: flex; gap: 6px; margin: 0; padding: 4px 14px; list-style: none; white-space: nowrap; }
.moves__pair { display: inline-flex; align-items: center; gap: 4px; padding: 3px 4px 3px 8px; border-radius: var(--r-md); background: var(--surface); border: 1px solid var(--border); }
.moves__n { color: var(--ink-3); font-size: var(--fs-xs); font-weight: 800; font-variant-numeric: tabular-nums; }
.moves__m { font-size: var(--fs-sm); font-weight: 700; padding: 3px 7px; border-radius: 8px; }
.moves__m--red { color: var(--piece-red); }
[data-theme="dark"] .moves__m--red { color: var(--primary); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .moves__m--red { color: var(--primary); } }
.moves__m.is-last { background: color-mix(in srgb, var(--gold) 22%, transparent); }
button.moves__m { border: 0; background: none; cursor: pointer; font: inherit; font-size: var(--fs-sm); font-weight: 700; min-height: 32px; }
button.moves__m.is-current { background: var(--ink); color: var(--bg); }

/* панель действий */
.actions { display: flex; justify-content: space-between; gap: 2px; padding: 4px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-1); }
.act {
  flex: 1 1 0; min-width: 0; min-height: 56px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 0; border-radius: var(--r-md); background: transparent; color: var(--ink); cursor: pointer; padding: 4px 2px;
  transition: background var(--dur), color var(--dur), transform 120ms var(--ease);
}
.act:active { transform: scale(.94); background: var(--surface-2); }
.act:disabled { opacity: .35; pointer-events: none; }
.act[aria-pressed="true"] { color: var(--primary); background: var(--primary-soft); }
.act__ic { position: relative; display: grid; place-items: center; }
.act__badge { position: absolute; top: -6px; right: -12px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; display: grid; place-items: center; background: var(--gold); color: #2b1c05; font-size: 11px; font-weight: 900; box-shadow: 0 0 0 2px var(--surface); }
.act__label { font-size: 11px; font-weight: 800; letter-spacing: -.01em; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.act--danger { color: var(--danger); }
/* узкие телефоны (360 и уже): подписи мельче, чтобы 6 кнопок помещались целиком */
@media (max-width: 374px) {
  .actions { gap: 0; padding: 3px; }
  .act { padding: 4px 0; }
  .act__label { font-size: 10px; letter-spacing: -.02em; }
}
.actions.is-final { gap: var(--sp-2); padding: 6px; flex-wrap: nowrap; }
.actions.is-final > .btn:not(.btn--icon) { flex: 1; }

/* ожидание соперника */
.wait-card { width: min(100%, 330px); padding: var(--sp-4); border-radius: var(--r-xl); background: var(--surface); box-shadow: var(--shadow-3); text-align: center; display: flex; flex-direction: column; gap: var(--sp-3); align-items: center; }
.wait-card h2 { font-size: var(--fs-xl); font-weight: 900; }
.wait-card .btn { white-space: normal; padding-inline: var(--sp-3); } /* на узкой доске «Отправить приглашение» с иконкой не влезает в строку */
.wait-card__art { display: flex; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-1); }
.wait-card__vs { font-weight: 900; color: var(--ink-3); font-size: var(--fs-sm); text-transform: uppercase; }
.wait-card__q { width: 58px; height: 58px; border-radius: 50%; display: grid; place-items: center; border: 2.5px dashed var(--ink-3); color: var(--ink-3); font-size: 26px; font-weight: 900; animation: wait-q 1.8s ease-in-out infinite; }
@keyframes wait-q { 50% { transform: scale(1.08) rotate(8deg); border-color: var(--primary); color: var(--primary); } }

/* финал */
.modal--finale { max-width: 380px; text-align: center; padding-top: var(--sp-5); overflow: visible; }
.modal--finale .modal__head { display: none; }
.finale { display: flex; flex-direction: column; align-items: center; gap: var(--sp-2); }
.finale__seal {
  width: 92px; height: 92px; border-radius: 50%; display: grid; place-items: center; margin-top: -64px; margin-bottom: var(--sp-2);
  font-family: var(--font-brush); font-size: 56px; line-height: 1; color: #fff8ec;
  background: radial-gradient(circle at 38% 30%, color-mix(in srgb, var(--fc) 70%, #fff), var(--fc) 65%, color-mix(in srgb, var(--fc) 70%, #000));
  box-shadow: 0 0 0 6px var(--surface), 0 10px 28px color-mix(in srgb, var(--fc) 45%, transparent);
  animation: seal-in 600ms var(--ease-bounce) both;
}
@keyframes seal-in { from { transform: scale(.3) rotate(-30deg); opacity: 0; } }
.finale--win { --fc: var(--gold); } .finale--loss { --fc: var(--sky); } .finale--draw { --fc: var(--jade); } .finale--spect, .finale--abandoned { --fc: var(--ink-2); }
.finale__title { font-size: var(--fs-2xl); font-weight: 900; letter-spacing: -.02em; }
.finale--win .finale__title { color: color-mix(in srgb, var(--gold) 70%, var(--ink)); }
.finale__reason { font-weight: 800; color: var(--ink-2); font-size: var(--fs-sm); text-transform: uppercase; letter-spacing: .06em; }
.finale__sub { color: var(--ink-2); font-size: var(--fs-sm); max-width: 300px; }
.finale__stats { display: flex; justify-content: center; gap: var(--sp-2); width: 100%; margin-top: var(--sp-2); }
.finale__stats:empty { display: none; }
.finale__stat { flex: 1; max-width: 110px; padding: var(--sp-2) var(--sp-1); border-radius: var(--r-md); background: var(--surface-2); display: flex; flex-direction: column; animation: fade-up 400ms var(--ease) both; }
.finale__stat:nth-child(2) { animation-delay: 120ms; } .finale__stat:nth-child(3) { animation-delay: 240ms; }
.finale__stat b { font-size: var(--fs-xl); font-weight: 900; line-height: 1.1; }
.finale__stat span { font-size: var(--fs-xs); color: var(--ink-2); font-weight: 700; }
.finale__stat--xp b { color: color-mix(in srgb, var(--gold) 75%, var(--ink)); }
.finale__stat.is-up b { color: var(--win); } .finale__stat.is-down b { color: var(--loss); }
.finale__badges { width: 100%; text-align: left; display: flex; flex-direction: column; gap: 6px; margin-top: var(--sp-2); }
.badge-new { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-2) var(--sp-3); border-radius: var(--r-md); background: var(--gold-soft); animation: fade-up 400ms 300ms var(--ease) both; }
.badge-new__ic { font-size: 26px; line-height: 1; }
.badge-new b { display: block; font-size: var(--fs-sm); } .badge-new small { display: block; color: var(--ink-2); font-size: var(--fs-xs); line-height: 1.3; }
.finale__level { width: 100%; text-align: left; margin-top: var(--sp-2); }
.finale__level:empty { display: none; }
.finale__lvglyph { flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-family: var(--font-piece); font-weight: 900; font-size: 20px; color: #5a3a06; background: radial-gradient(circle at 40% 32%, #fff3cf, var(--gold) 75%); }
.finale__foot { display: flex; justify-content: center; gap: var(--sp-2); margin-top: var(--sp-3); }
.modal--finale .modal__actions { margin-top: var(--sp-4); }

/* компьютер: две колонки */
@media (min-width: 900px) {
  .game { max-width: 1060px; }
  .game-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: var(--sp-5); align-items: start; }
  .board-wrap { width: min(100%, calc((100dvh - 200px) * .857)); }
  .game-side { position: sticky; top: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-3); }
  .moves { max-height: calc(100dvh - 260px); min-height: 200px; overflow-y: auto; overflow-x: hidden; mask-image: none; -webkit-mask-image: none; padding: var(--sp-2); border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--border); }
  .moves__list { flex-direction: column; padding: 0; gap: 2px; white-space: normal; }
  .moves__pair { display: grid; grid-template-columns: 34px 1fr 1fr; border: 0; background: none; padding: 2px 4px; }
  .moves__pair:nth-child(odd) { background: var(--surface-2); }
  .actions { flex-wrap: wrap; }
  .act { flex: 1 1 30%; }
}
.game-side { display: flex; flex-direction: column; gap: var(--sp-2); }

/* реплей */
.replay-head { display: none; gap: 6px; flex-wrap: wrap; justify-content: center; }
.replay-sub-result--win { color: var(--win); } .replay-sub-result--loss { color: var(--loss); } .replay-sub-result--draw { color: var(--draw); }
.replay-caption { display: flex; align-items: center; gap: var(--sp-2); min-height: 36px; padding: 0 var(--sp-2); font-weight: 800; }
.replay-caption__n { color: var(--ink-3); font-variant-numeric: tabular-nums; }
.replay-caption__m { font-size: var(--fs-lg); font-weight: 900; }
.replay-caption__of { margin-left: auto; }
.replay-controls { display: flex; flex-direction: column; gap: 4px; padding: 4px var(--sp-3) var(--sp-2); }
.replay-buttons { display: flex; align-items: center; justify-content: space-between; }
.replay-play { width: 52px; min-width: 52px; min-height: 52px; }
.replay-speed { min-width: 64px; min-height: 40px; padding: 0 8px; font-size: var(--fs-xs); font-weight: 800; white-space: nowrap; }
.replay .seg--speed { display: none; }
.seg--speed > button { flex: 1 1 auto; min-height: 36px; font-size: var(--fs-xs); white-space: nowrap; padding: 0 8px; }
.replay-slider { --p: 0; width: 100%; height: 32px; margin: 0; background: transparent; -webkit-appearance: none; appearance: none; cursor: pointer; }
.replay-slider::-webkit-slider-runnable-track { height: 8px; border-radius: 4px; background: linear-gradient(90deg, var(--primary) calc(var(--p) * 100%), var(--surface-3) calc(var(--p) * 100%)); }
.replay-slider::-moz-range-track { height: 8px; border-radius: 4px; background: var(--surface-3); }
.replay-slider::-moz-range-progress { height: 8px; border-radius: 4px; background: var(--primary); }
.replay-slider::-webkit-slider-thumb { -webkit-appearance: none; width: 26px; height: 26px; margin-top: -9px; border-radius: 50%; background: var(--surface); border: 3px solid var(--primary); box-shadow: var(--shadow-2); }
.replay-slider::-moz-range-thumb { width: 22px; height: 22px; border-radius: 50%; background: var(--surface); border: 3px solid var(--primary); box-shadow: var(--shadow-2); }
.replay-slider:focus-visible { box-shadow: none; }
.replay-slider:focus-visible::-webkit-slider-thumb { box-shadow: var(--focus); }
/* телефон: доска забирает то, что осталось от шапки, чипов, игроков, подписи и пульта (~385px) — пульт всегда на экране, лента ходов может уйти под низ */
.replay .board-wrap { width: min(100%, calc((var(--tg-viewport-stable-height, 100dvh) - 385px) * .857)); min-width: 260px; }
.replay .player { min-height: 44px; padding-top: 2px; padding-bottom: 2px; }
@media (min-width: 900px) {
  .replay .board-wrap { width: min(100%, calc((100dvh - 190px) * .857)); }
  .moves--replay { max-height: calc(100dvh - 400px); }
  .replay .seg--speed, .replay-head { display: flex; }
  .replay-sub-result { display: none; }
  .replay-speed { display: none; }
}

/* ====================================================================
   Вход (login.html)
   ==================================================================== */
.login { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--sp-5); padding: var(--sp-5) var(--sp-4) calc(var(--sp-5) + env(safe-area-inset-bottom)); }
.login__card { width: min(100%, 400px); padding: var(--sp-6) var(--sp-5) var(--sp-5); border-radius: var(--r-xl); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-3); text-align: center; display: flex; flex-direction: column; align-items: center; gap: var(--sp-3); animation: fade-up 500ms var(--ease) both; }
.login__art { position: relative; width: 170px; height: 96px; margin-bottom: var(--sp-2); }
.login__art .mini-piece { position: absolute; }
.login__art .mini-piece:nth-child(1) { left: 6px; top: 22px; transform: rotate(-14deg); }
.login__art .mini-piece:nth-child(2) { left: 47px; top: 0; z-index: 1; animation: login-bob 2.4s ease-in-out infinite; }
.login__art .mini-piece:nth-child(3) { right: 6px; top: 34px; transform: rotate(12deg); }
@keyframes login-bob { 50% { transform: translateY(-6px); } }
.login__title { font-size: var(--fs-xl); font-weight: 900; }
.login__text { max-width: 320px; }
.login__status { width: 100%; min-height: 48px; display: grid; gap: var(--sp-2); place-items: center; margin-top: var(--sp-2); }
.login__check { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; background: var(--jade); color: var(--on-accent); box-shadow: 0 8px 20px color-mix(in srgb, var(--jade) 40%, transparent); animation: seal-in 500ms var(--ease-bounce) both; }
.login__card.is-error .login__art .mini-piece:nth-child(2) { animation: none; transform: rotate(18deg) translateY(6px); filter: grayscale(.4); }
.login__foot { font-family: var(--font-brush); font-size: var(--fs-xl); color: var(--ink-3); opacity: .6; letter-spacing: .2em; }
.login__hint { display: inline-flex; align-items: center; gap: 8px; padding: 10px 14px; border-radius: var(--r-md); background: var(--sky-soft); color: var(--sky); font-weight: 700; font-size: var(--fs-sm); }
.xq-sel { fill: color-mix(in srgb, var(--hl-select) 45%, transparent); stroke: var(--hl-select); stroke-width: 3.5; }
.xq-label { paint-order: stroke; stroke: var(--piece-face); stroke-width: 3px; stroke-linejoin: round; }
.game-row .list-item__trail { font-size: var(--fs-xs); gap: 4px; }

/* ---------- «Связь с автором» (owner-kit: public/js/owner-kit.js + support.js) ---------- */
:root {
  --okit-accent-host: var(--primary); --okit-on-accent-host: var(--on-accent);
  --okit-text-host: var(--ink); --okit-muted-host: var(--ink-2);
  --okit-bg-host: var(--bg); --okit-surface-host: var(--surface);
}
.support-foot { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 2px var(--sp-2); margin-top: var(--sp-4) !important; }
.support-foot__btn { border: 0; background: none; font: inherit; font-size: var(--fs-sm); font-weight: 700; color: var(--ink-3); padding: var(--sp-2) var(--sp-2); min-height: 40px; cursor: pointer; border-radius: var(--r-pill); }
.support-foot__btn:active { background: var(--surface-2); }
.support-foot__dot { color: var(--ink-3); opacity: .6; }
