/* «Призрачная пятёрка»: верхняя панель, экраны-страницы, поле и карточки. */

:root {
  --bg: #EEF1F7;
  --bg-2: #E4E9F2;
  --surface: #FFFFFF;
  --surface-2: #F4F6FB;
  --ink: #151B2A;
  --muted: #5B6578;
  --rule: #D8DEEA;
  --board: #C8D0DE;
  --cell: #F1F3F7;
  --cell-hover: #DFE5EF;
  --wall: #394155;
  --wall-2: #5A637B;
  --wall-ink: #FFFFFF;
  --burn: #F2A33A;
  --alert: #B4321F;
  --ok: #0E9466;
  --go: #0E9D5E; --go-2: #19B46E; --go-ink: #FFFFFF;
  --no: #C8453A;
  --brand: #3A56DE;
  --brand-2: #6E4BE0;
  --brand-ink: #FFFFFF;
  --shadow: 0 1px 2px rgb(21 27 42 / .06), 0 8px 24px -12px rgb(21 27 42 / .18);
  --shadow-lg: 0 2px 6px rgb(21 27 42 / .08), 0 24px 48px -24px rgb(21 27 42 / .32);
  /* На светлой доске фишки глубокие: светлая заливка на светлых клетках не читается. */
  --c-cobalt: #2740BE; --c-indigo: #4B2DB8; --c-sky: #0A63AC; --c-teal: #076C7B;
  --c-emerald: #0A7A53; --c-lime: #4C760C; --c-amber: #A96C00; --c-orange: #B4530E;
  --c-coral: #C43D34; --c-crimson: #96102F; --c-rose: #A61D60; --c-plum: #76228C;
  --c-violet: #6E2FB0; --c-graphite: #566078;
  /* «Белый» — самый контрастный к доске: в светлой теме он тёмно-графитовый. */
  --c-lemon: #8F7600; --c-snow: #242C3C;
  --p1: var(--c-cobalt);
  --p2: var(--c-coral);
  --r-sm: 10px;
  --r: 14px;
  --r-lg: 20px;
  --display: "Unbounded", "Golos Text", system-ui, sans-serif;
  --wordmark: "Space Grotesk", "Unbounded", system-ui, sans-serif;
  --body: "Golos Text", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0C1017; --bg-2: #0F131B; --surface: #161C28; --surface-2: #1C2331;
    --ink: #E7EBF3; --muted: #94A0B6; --rule: #2A3346;
    --board: #232B3E; --cell: #171D29; --cell-hover: #222B3C;
    --wall: #080B11; --wall-2: #2A3245; --wall-ink: #E5E9F1;
    --burn: #F5A742; --alert: #FF8A7A; --ok: #34D399;
    --go: #2FC484; --go-2: #52D79B; --go-ink: #04140B; --no: #FF8070;
    --brand: #6C84FF; --brand-2: #9B7BFF; --brand-ink: #0B0F17;
    --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 12px 32px -16px rgb(0 0 0 / .7);
    --shadow-lg: 0 2px 8px rgb(0 0 0 / .5), 0 28px 56px -28px rgb(0 0 0 / .8);
    --c-cobalt: #6D86FF; --c-indigo: #9A86FF; --c-sky: #4FB4F5; --c-teal: #3CC8DB;
    --c-emerald: #34D399; --c-lime: #A8D43F; --c-amber: #F5B83D; --c-orange: #FF9A4D;
    --c-coral: #FF6E62; --c-crimson: #FF5E7D; --c-rose: #FF6FB0; --c-plum: #DD8CF0;
    --c-violet: #B98CFF; --c-graphite: #98A3B8;
    --c-lemon: #FFE04D; --c-snow: #FFFFFF;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0C1017; --bg-2: #0F131B; --surface: #161C28; --surface-2: #1C2331;
  --ink: #E7EBF3; --muted: #94A0B6; --rule: #2A3346;
  --board: #232B3E; --cell: #171D29; --cell-hover: #222B3C;
  --wall: #080B11; --wall-2: #2A3245; --wall-ink: #E5E9F1;
  --burn: #F5A742; --alert: #FF8A7A; --ok: #34D399;
  --go: #2FC484; --go-2: #52D79B; --go-ink: #04140B; --no: #FF8070;
  --brand: #6C84FF; --brand-2: #9B7BFF; --brand-ink: #0B0F17;
  --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 12px 32px -16px rgb(0 0 0 / .7);
  --shadow-lg: 0 2px 8px rgb(0 0 0 / .5), 0 28px 56px -28px rgb(0 0 0 / .8);
    --c-cobalt: #6D86FF; --c-indigo: #9A86FF; --c-sky: #4FB4F5; --c-teal: #3CC8DB;
  --c-emerald: #34D399; --c-lime: #A8D43F; --c-amber: #F5B83D; --c-orange: #FF9A4D;
  --c-coral: #FF6E62; --c-crimson: #FF5E7D; --c-rose: #FF6FB0; --c-plum: #DD8CF0;
  --c-violet: #B98CFF; --c-graphite: #98A3B8;
  --c-lemon: #FFE04D; --c-snow: #FFFFFF;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  background-image: radial-gradient(90rem 50rem at 50% -20rem, color-mix(in srgb, var(--brand) 12%, transparent), transparent 70%);
  color: var(--ink); font-family: var(--body); font-size: 15px; line-height: 1.5;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}
button, input { font-family: inherit; font-size: inherit; color: inherit; }
h1, h2, h3 { margin: 0; }
[hidden] { display: none !important; }

/* ---------- Верхняя панель ---------- */

.appbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--rule);
  padding-top: env(safe-area-inset-top, 0px);
}
.bar-in {
  max-width: 1180px; margin: 0 auto; display: flex; align-items: center; gap: 12px 20px;
  padding: 10px max(16px, env(safe-area-inset-left, 0px)) 10px max(16px, env(safe-area-inset-right, 0px));
}
.brand {
  display: flex; align-items: center; gap: 9px; border: 0; background: none; padding: 0; cursor: pointer;
  font-family: var(--wordmark); font-weight: 700; font-size: 18px; letter-spacing: -0.02em; white-space: nowrap;
  color: var(--ink);
}
.brand .mark {
  width: 22px; height: 22px; border-radius: 7px; flex: none;
  background: linear-gradient(140deg, var(--p1), var(--p2));
  box-shadow: inset 0 1px 0 rgb(255 255 255 / .3);
}
.tabs { display: flex; gap: 2px; margin-inline: auto; background: var(--surface-2); border: 1px solid var(--rule); border-radius: 999px; padding: 3px; }
.tab {
  position: relative; border: 0; background: none; cursor: pointer; color: var(--muted);
  padding: 7px 15px; border-radius: 999px; font-size: 14px; font-weight: 500; white-space: nowrap;
  transition: color .15s, background .15s;
}
.tab:hover { color: var(--ink); }
.tab[aria-current="page"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }
.nbadge {
  display: inline-block; min-width: 17px; height: 17px; margin-left: 6px; padding: 0 4px;
  border-radius: 999px; background: var(--p2); color: #fff;
  font-size: 11px; font-weight: 600; line-height: 17px; text-align: center; vertical-align: 1px;
}
.who { display: flex; align-items: baseline; gap: 10px; font-size: 13.5px; color: var(--muted); min-width: 0; }
.who b { color: var(--ink); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 14ch; }

@media (max-width: 860px) {
  .bar-in { padding-block: 8px; gap: 8px; }
  /* На телефоне шапка не липнет: иначе она закрывает верх доски. Навигация и так внизу. */
  .appbar { position: static; backdrop-filter: none; -webkit-backdrop-filter: none; background: var(--bg); }
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; margin: 0; border-radius: 0;
    border: 0; border-top: 1px solid var(--rule); padding: 6px 8px;
    padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
    background: color-mix(in srgb, var(--bg) 92%, transparent);
    backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
    justify-content: space-around;
  }
  .tab { flex: 1 1 0; padding: 9px 6px; font-size: 13px; text-align: center; }
  .main { padding-bottom: 84px; }
}
@media (max-width: 420px) {
  .who b { display: none; }
}

/* ---------- Экраны ---------- */

.main {
  max-width: 1180px; margin: 0 auto;
  padding: 22px max(16px, env(safe-area-inset-left, 0px)) 56px max(16px, env(safe-area-inset-right, 0px));
}
.screen { display: flex; flex-direction: column; gap: 18px; animation: fade .18s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }
.screen-head { display: flex; flex-direction: column; gap: 4px; }
.screen-head h2 { font-family: var(--display); font-weight: 500; font-size: clamp(21px, 3.4vw, 27px); letter-spacing: -0.01em; }
.screen-head .sub { margin: 0; color: var(--muted); }
.cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 340px); gap: 18px; align-items: start; }
.cols .col { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
@media (max-width: 900px) { .cols { grid-template-columns: minmax(0, 1fr); } }

.card {
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-lg);
  padding: 18px; display: flex; flex-direction: column; gap: 14px; min-width: 0;
  box-shadow: var(--shadow);
}
.card-title {
  font-family: var(--mono); font-weight: 500; font-size: 11px;
  letter-spacing: .12em; text-transform: uppercase; color: var(--muted);
}
.note { margin: 0; font-size: 14px; color: var(--muted); }
.note.err { color: var(--alert); }
.small { font-size: 13px; color: var(--muted); margin: 0; }
.small.ok { color: var(--ok); }
.small.err { color: var(--alert); }
.fhint { margin: 0; font-size: 12.5px; color: var(--muted); }
.fhint.err { color: var(--alert); }

/* ---------- Кнопки ---------- */

.btn {
  border-radius: 999px; padding: 11px 20px; font-size: 15px; font-weight: 600; cursor: pointer;
  border: 1px solid transparent; transition: filter .15s, transform .08s, background .15s;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap;
}
.btn:active:not(:disabled) { transform: scale(.98); }
.btn:focus-visible, .chip:focus-visible, .tab:focus-visible, .linkbtn:focus-visible,
.seg button:focus-visible, .swatch:focus-visible, .shp:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 2px;
}
.btn.primary { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: var(--brand-ink); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.07); }
.btn.ghost { background: var(--surface); color: var(--ink); border-color: var(--rule); }
.btn.ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .4; cursor: default; }
.chip {
  border: 1px solid var(--rule); background: var(--surface); color: var(--ink);
  border-radius: 999px; padding: 7px 14px; font-size: 13px; font-weight: 500; cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.chip:hover:not(:disabled) { background: var(--surface-2); }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip.go { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: var(--brand-ink); border-color: transparent; }
.chip.warn { color: var(--alert); }
.chip:disabled { opacity: .4; cursor: default; }
.linkbtn {
  border: 0; background: none; padding: 0; color: var(--ink); text-decoration: underline;
  text-underline-offset: 3px; text-decoration-color: color-mix(in srgb, var(--ink) 35%, transparent);
  cursor: pointer; font-size: 13.5px;
}
.linkbtn:hover { color: var(--brand); }

/* ---------- Поля ввода ---------- */

.authform { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label { font-size: 13px; font-weight: 600; color: var(--muted); }
input:not([type="range"]) {
  display: block; width: 100%; flex: none; min-width: 0;
  padding: 11px 14px; border-radius: var(--r); border: 1px solid var(--rule);
  background: var(--surface-2); color: var(--ink); font-size: 15px; line-height: 1.3;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
input::placeholder { color: color-mix(in srgb, var(--muted) 75%, transparent); }
input:not([type="range"]):hover { border-color: color-mix(in srgb, var(--muted) 45%, var(--rule)); }
input:not([type="range"]):focus { outline: 0; border-color: var(--brand); background: var(--surface); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 22%, transparent); }
.field-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.field-row input { flex: 1 1 180px; width: auto; }
.codein { font-family: var(--mono); letter-spacing: .3em; font-size: 18px; text-align: center; }
.codein-sm { font-family: var(--mono); letter-spacing: .12em; text-transform: uppercase; }
.rowform { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.rowform.grow { flex: 1 1 200px; }
.rowform input { flex: 1 1 160px; width: auto; }
.formfoot { margin: 0; font-size: 13.5px; color: var(--muted); }

/* ---------- Вход ---------- */

.screen-auth { align-items: center; gap: 26px; padding-top: max(24px, 8vh); }
.hero { display: flex; flex-direction: column; gap: 8px; align-items: center; text-align: center; }
.hero h1 {
  font-family: var(--wordmark); font-weight: 700; font-size: clamp(38px, 9vw, 60px);
  letter-spacing: -0.035em; color: var(--ink);
}
.auth-card { width: 100%; max-width: 420px; gap: 16px; padding: 22px; border-radius: var(--r-lg); box-shadow: var(--shadow-lg); }
.auth-card .card-title { font-family: var(--display); font-size: 19px; letter-spacing: -0.01em; text-transform: none; color: var(--ink); font-weight: 500; }
.seg.wide { display: grid; grid-template-columns: 1fr 1fr; }
.seg.wide button { padding: 9px 10px; font-size: 14px; }

/* ---------- Экран игры ---------- */

.playbar {
  display: flex; gap: 8px 12px; align-items: center; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--rule); border-radius: 999px;
  padding: 8px 10px 8px 16px; box-shadow: var(--shadow);
}
.playbar .btn, .playbar .chip { margin-left: auto; }
.playbar .chip + .chip, .playbar .chip + .btn, .playbar .btn + .chip { margin-left: 0; }
.gb-code { font-size: 14px; display: inline-flex; align-items: center; gap: 8px; }
.gb-code b { font-family: var(--mono); font-weight: 500; letter-spacing: .14em; }
.gb-note { flex-basis: 100%; font-size: 12.5px; color: var(--muted); word-break: break-all; padding-inline: 6px; }
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.live-dot.on { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }

/* Слева журнал, в центре поле, справа ход и игроки: ничего не надо прокручивать. */
.playgrid {
  display: grid; grid-template-columns: minmax(0, 250px) minmax(0, 620px) minmax(0, 310px);
  gap: 18px; align-items: start; justify-content: center;
}
.playlog { display: flex; flex-direction: column; gap: 12px; min-width: 0; position: sticky; top: 78px; }
.playlog .log { max-height: min(60vh, 520px); }
@media (max-width: 1180px) {
  .playgrid { grid-template-columns: minmax(0, 620px) minmax(0, 310px); }
  .playlog { grid-column: 1 / -1; order: 3; position: static; }
}
@media (max-width: 980px) {
  .playgrid { grid-template-columns: minmax(0, 1fr); }
  .playmain { order: 1; }
  .playside { order: 2; }
  .playlog { order: 3; }
}

/* Настройки партии и оформления живут за кнопкой «три точки». */
/* Настройки живут под полем: раскрытие не сдвигает доску. */
.drawer {
  margin-top: 4px;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px;
  animation: fade .16s ease-out;
}
/* Кнопка и сам ящик стоят рядом, внизу экрана. */
.drawer-toggle {
  display: flex; align-items: center; gap: 9px; cursor: pointer; align-self: start;
  padding: 9px 16px 9px 12px; border-radius: 999px; font-size: 13.5px; font-weight: 500;
  border: 1px solid var(--rule); background: var(--surface); color: var(--muted);
  transition: color .15s, background .15s;
}
.drawer-toggle:hover { color: var(--ink); background: var(--surface-2); }
.drawer-toggle[aria-expanded="true"] { color: var(--ink); border-color: color-mix(in srgb, var(--ink) 35%, var(--rule)); }
.drawer-toggle .dots3 { font-size: 16px; line-height: 1; }
.drawer-toggle:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* Перемотка ходов. */
.rewind { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.rewind .chip { padding: 5px 11px; font-size: 13px; }
.rewind-at {
  font-family: var(--mono); font-size: 12px; color: var(--muted); min-width: 56px; text-align: center;
  font-variant-numeric: tabular-nums;
}
.board.past { filter: saturate(.75); }
.board.past::after {
  content: ""; position: absolute; inset: 0; border-radius: var(--r); pointer-events: none;
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--muted) 55%, transparent);
}
@media (max-width: 560px) { .playbar { border-radius: var(--r); padding: 10px 12px; } }
.playmain { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.playside { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

.status { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; min-height: 34px; }
.round {
  font-family: var(--mono); font-size: 11px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); padding: 4px 10px; border: 1px solid var(--rule); border-radius: 999px;
  font-variant-numeric: tabular-nums; white-space: nowrap; background: var(--surface);
}
/* Часы хода: полоска внутри чипа показывает остаток. */
.clock {
  position: relative; overflow: hidden; display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--mono); font-size: 12px; font-weight: 500; font-variant-numeric: tabular-nums;
  padding: 4px 10px; border-radius: 999px; white-space: nowrap; min-width: 62px;
  background: var(--surface); border: 1px solid color-mix(in srgb, var(--brand) 40%, var(--rule)); color: var(--ink);
}
.clock .bar {
  position: absolute; left: 0; top: 0; bottom: 0; width: 100%;
  background: color-mix(in srgb, var(--brand) 22%, transparent);
  transition: width .25s linear;
}
.clock b { position: relative; font-weight: 600; }
.clock::before {
  content: "ход"; position: relative; font-size: 10px; letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted);
}
.clock.bank::before { content: "запас"; }
.clock.bank { border-color: var(--rule); opacity: .75; }
.clock.bank .bar { background: color-mix(in srgb, var(--muted) 18%, transparent); }
.clock.bank.active { opacity: 1; border-color: color-mix(in srgb, var(--burn) 55%, var(--rule)); }
.clock.bank.active .bar { background: color-mix(in srgb, var(--burn) 26%, transparent); }
.clock.spent { opacity: .5; }
.clock.low {
  border-color: color-mix(in srgb, var(--alert) 55%, var(--rule)); color: var(--alert);
  animation: blink 1s steps(2, end) infinite;
}
.clock.low .bar { background: color-mix(in srgb, var(--alert) 22%, transparent); }
@keyframes blink { 50% { opacity: .5; } }
#statusText { font-weight: 500; min-width: 0; }
#statusText.win1 { color: var(--p1); font-weight: 600; }
#statusText.win2 { color: var(--p2); font-weight: 600; }
.msg { margin: 0; font-size: 13.5px; color: var(--alert); }

.tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tools .label { font-size: 13px; color: var(--muted); }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.actions .btn.primary { flex: 1 1 220px; padding-block: 13px; }
/* Пауза перед ходом: «Подтвердить» и «Отмена» стоят в одну строку и не переносятся. */
.actions.pair { flex-wrap: nowrap; }
.actions.pair .btn { flex: 1 1 0; min-width: 0; padding-block: 13px; padding-inline: 10px; }
.actions.pair .btn.go { flex-grow: 1.6; }
.btn.go {
  background: linear-gradient(135deg, var(--go-2), var(--go));
  color: var(--go-ink); border-color: transparent;
  box-shadow: 0 6px 18px -10px color-mix(in srgb, var(--go) 70%, transparent);
}
.btn.go:hover:not(:disabled) { filter: brightness(1.06); }
.btn.no {
  background: color-mix(in srgb, var(--no) 13%, var(--surface));
  color: color-mix(in srgb, var(--no) 85%, var(--ink));
  border-color: color-mix(in srgb, var(--no) 32%, transparent);
}
.btn.no:hover:not(:disabled) { background: color-mix(in srgb, var(--no) 20%, var(--surface)); }

/* ---------- Поле ---------- */

.board-wrap { position: relative; width: 100%; }
.board {
  position: relative;
  display: grid; gap: 2px; padding: 6px; background: var(--board);
  border-radius: var(--r); aspect-ratio: 1; width: 100%;
  box-shadow: var(--shadow);
}
.cell {
  appearance: none; border: 0; padding: 0; margin: 0; min-width: 0; min-height: 0;
  background: var(--cell); border-radius: 3px; position: relative; cursor: default;
}
.board.live .cell.ok { cursor: pointer; }
.board.live .cell.ok.empty:hover { background: var(--cell-hover); }
.cell:focus-visible { outline: 2px solid var(--ink); outline-offset: -2px; z-index: 3; }
.cell.last::after {
  content: ""; position: absolute; inset: 0; border-radius: 3px;
  box-shadow: inset 0 0 0 2px var(--muted); pointer-events: none;
}
.cell.frag::before, .cell.selected::before {
  content: ""; position: absolute; inset: 2px; border-radius: 4px; pointer-events: none;
  border: 1.5px dashed var(--muted);
}
.cell.selected::before { border-color: var(--ink); }
/* Якорь: сплошная рамка цветом игрока — его не сбить выстрелом. */
.cell.anchored { background: color-mix(in srgb, var(--ac) 14%, var(--cell)); }
.cell.anchored.a1 { --ac: var(--p1); }
.cell.anchored.a2 { --ac: var(--p2); }
.cell.anchored::after {
  content: ""; position: absolute; inset: 0; border-radius: 3px; pointer-events: none;
  box-shadow: inset 0 0 0 2px var(--ac);
}
.cell.wall { background: repeating-linear-gradient(45deg, var(--wall) 0 3px, var(--wall-2) 3px 6px); }
/* Стена доживает последний раунд: она вот-вот разрушится. */
.cell.wall.crumbling { opacity: .5; }
.cell.burn { animation: burn .8s ease-out; }
.cell.win-p1 { background: color-mix(in srgb, var(--p1) 30%, var(--cell)); }
.cell.win-p2 { background: color-mix(in srgb, var(--p2) 30%, var(--cell)); }
.cell.win-p1 .stone, .cell.win-p2 .stone { animation: winpulse 1.3s ease-in-out infinite; }

/* Фишки: один элемент, форму задаёт класс sh-* */
.stone { position: absolute; inset: 14%; pointer-events: none; background: var(--pc); }
.stone.p1 { --pc: var(--p1); }
.stone.p2 { --pc: var(--p2); }
.sh-circle { border-radius: 50%; background: radial-gradient(circle at 34% 30%, rgb(255 255 255 / .38), transparent 58%), var(--pc); }
.sh-ring { inset: 12%; border-radius: 50%; background: radial-gradient(circle closest-side, transparent 50%, var(--pc) 53%); }
.sh-square { inset: 18%; border-radius: 16%; background: linear-gradient(145deg, rgb(255 255 255 / .3), transparent 55%), var(--pc); }
.sh-diamond { inset: 8%; clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); }
.sh-cross { inset: 15%; clip-path: polygon(20% 0, 50% 30%, 80% 0, 100% 20%, 70% 50%, 100% 80%, 80% 100%, 50% 70%, 20% 100%, 0 80%, 30% 50%, 0 20%); }
.sh-star { inset: 6%; clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); }
.sh-triangle { inset: 10%; clip-path: polygon(50% 2%, 98% 92%, 2% 92%); }
.sh-hex { inset: 10%; clip-path: polygon(50% 1%, 94% 26%, 94% 74%, 50% 99%, 6% 74%, 6% 26%); }
.sh-pentagon { inset: 10%; clip-path: polygon(50% 1%, 99% 37%, 80% 97%, 20% 97%, 1% 37%); }
.sh-bolt { inset: 8%; clip-path: polygon(44% 0, 90% 0, 58% 38%, 88% 38%, 26% 100%, 44% 54%, 12% 54%); }
.sh-moon { inset: 12%; border-radius: 50%; background: radial-gradient(circle at 74% 28%, transparent 52%, var(--pc) 53%); }
.sh-flower {
  inset: 9%; background:
    radial-gradient(circle at 50% 21%, var(--pc) 25%, transparent 26%),
    radial-gradient(circle at 79% 50%, var(--pc) 25%, transparent 26%),
    radial-gradient(circle at 50% 79%, var(--pc) 25%, transparent 26%),
    radial-gradient(circle at 21% 50%, var(--pc) 25%, transparent 26%),
    radial-gradient(circle at 50% 50%, var(--pc) 27%, transparent 28%);
}
.stone.worn { opacity: .75; }
.stone.fragile { opacity: .45; }
.stone.ghost { opacity: .4; animation: breathe 1.1s ease-in-out infinite; }
.stone.pop { animation: pop .38s cubic-bezier(.3, 1.6, .5, 1); }
.stone.vanish { animation: vanish .7s ease-in forwards; }

.badge {
  position: absolute; top: 1px; right: 2px; z-index: 1; pointer-events: none;
  font-family: var(--mono); font-weight: 500; font-size: clamp(7px, 1.15vw, 10px); line-height: 1;
  color: var(--ink); font-variant-numeric: tabular-nums;
}
.cell.wall .badge { color: var(--wall-ink); }
.aim {
  position: absolute; inset: 10%; border: 2px solid var(--ink); border-radius: 50%; z-index: 2; pointer-events: none;
  background:
    linear-gradient(var(--ink), var(--ink)) center / 2px 60% no-repeat,
    linear-gradient(var(--ink), var(--ink)) center / 60% 2px no-repeat;
  animation: breathe 1.1s ease-in-out infinite;
}

@keyframes pop { from { transform: scale(.3); } to { transform: scale(1); } }
@keyframes vanish { 0% { opacity: .6; transform: scale(1); } 100% { opacity: 0; transform: scale(.4); filter: blur(3px); } }
@keyframes breathe { 50% { opacity: .55; } }
@keyframes burn { 0% { box-shadow: inset 0 0 0 40px var(--burn); } 100% { box-shadow: inset 0 0 0 0 transparent; } }
@keyframes winpulse { 50% { transform: scale(.82); } }

.cover {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-radius: var(--r); padding: 20px; z-index: 5;
}
.cover-inner { display: flex; flex-direction: column; gap: 14px; align-items: center; width: 100%; max-width: 380px; }
.cover h2 { font-family: var(--display); font-weight: 500; font-size: 20px; text-wrap: balance; }
.cover p { margin: 0; color: var(--muted); }
.cover .btn.ghost { background: var(--surface); }
.bigcode {
  font-family: var(--mono); font-weight: 500; font-size: clamp(30px, 8vw, 46px); letter-spacing: .18em;
  background: linear-gradient(135deg, var(--p1), var(--p2)); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.linkrow { display: flex; gap: 8px; width: 100%; flex-wrap: wrap; }
.linkrow input { flex: 1 1 180px; width: auto; font-family: var(--mono); font-size: 12px; }
.linkrow .btn { flex: 0 0 auto; }

/* ---------- Карточки игроков, журнал ---------- */

/* Карточки игроков стоят в строку над полем: имя и счёт сверху, запасы — строкой ниже. */
.players { display: flex; gap: 10px; margin-bottom: 10px; }
.players .pcard { flex: 1 1 0; flex-wrap: wrap; padding: 9px 11px; gap: 7px 8px; }
.players .pcard .dots { margin-left: auto; }
.players .pcard .bits { flex-basis: 100%; margin-left: 0; gap: 10px; }
.pcard {
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r);
  padding: 10px 13px; display: flex; align-items: center; gap: 9px; min-width: 0;
  transition: box-shadow .2s, border-color .2s;
}
.pcard .nm { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1 1 auto; min-width: 2.5em; }
.pcard .elo {
  font-family: var(--mono); font-size: 11px; font-weight: 600; color: var(--pc);
  padding: 2px 7px; border-radius: 999px; flex: none;
  background: color-mix(in srgb, var(--pc) 13%, transparent);
  border: 1px solid color-mix(in srgb, var(--pc) 30%, transparent);
}
.pcard .done { color: var(--ok); font-size: 13px; flex: none; }
.pcard .bits { margin-left: auto; display: flex; gap: 9px; align-items: center; flex: none; }
.pcard .bit { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); }
.pcard .bit.off { opacity: .45; }
.pcard .bit svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.pcard .bit b { font-family: var(--mono); font-size: 11.5px; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
/* Счёт партии: заполненный кружок — выигранный раунд. */
.dots { display: inline-flex; gap: 5px; align-items: center; flex: none; }
.dots i {
  width: 9px; height: 9px; border-radius: 50%; display: block;
  background: color-mix(in srgb, var(--pc) 16%, transparent);
  box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--pc) 45%, transparent);
}
.dots i.on { background: var(--pc); box-shadow: none; }
.dots.p1 { --pc: var(--p1); }
.dots.p2 { --pc: var(--p2); }
.pcard .dots { margin-left: 10px; }
/* Первая тройка таблицы лидеров: тонкий ободок и подкрашенный рейтинг. */
.pcard.medal { border-color: color-mix(in srgb, var(--medal) 55%, var(--rule)); }
.pcard.medal .elo {
  color: var(--medal); border-color: color-mix(in srgb, var(--medal) 45%, transparent);
  background: color-mix(in srgb, var(--medal) 14%, transparent);
}
.pcard.m1 { --medal: #E8B33A; }
.pcard.m2 { --medal: #B9C2D0; }
.pcard.m3 { --medal: #C8803F; }
.pcard.p1 { --pc: var(--p1); }
.pcard.p2 { --pc: var(--p2); }
.pcard.active { border-color: color-mix(in srgb, var(--pc) 55%, var(--rule)); box-shadow: inset 0 0 0 1px var(--pc), 0 0 0 4px color-mix(in srgb, var(--pc) 14%, transparent); }
.ico { position: relative; width: 16px; height: 16px; flex: none; display: inline-block; }

.log { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 7px; max-height: 240px; overflow-y: auto; }
.log li { display: flex; gap: 10px; font-size: 13.5px; align-items: baseline; }
.log b { font-family: var(--mono); font-weight: 500; font-size: 11px; color: var(--muted); min-width: 30px; font-variant-numeric: tabular-nums; flex: none; }
.log li.burn span { color: color-mix(in srgb, var(--burn) 70%, var(--ink)); }
.log li.win span { font-weight: 600; }
/* Свёрнутая карточка: заголовок кликабелен, стрелка показывает состояние */
.fold > summary { cursor: pointer; list-style: none; display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.fold > summary .brief {
  flex: 1 1 100%; font-family: var(--body); font-size: 12.5px; letter-spacing: 0;
  text-transform: none; color: var(--muted); font-weight: 400; order: 3;
}
.fold[open] > summary .brief { display: none; }
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary::after {
  content: ""; width: 7px; height: 7px; flex: none; margin-right: 3px;
  border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted);
  transform: rotate(45deg) translate(-2px, -2px); transition: transform .15s;
}
.fold[open] > summary::after { transform: rotate(225deg) translate(-2px, -2px); }
.fold > summary:focus-visible { outline: 2px solid var(--brand); outline-offset: 3px; border-radius: 4px; }
.fold[open] > summary { margin-bottom: 14px; }

/* Окно «Как играть» */
.sheet {
  border: 1px solid var(--rule); border-radius: var(--r-lg); background: var(--surface); color: var(--ink);
  padding: 24px; max-width: 540px; width: calc(100% - 32px);
  box-shadow: var(--shadow-lg);
}
.sheet::backdrop { background: rgb(6 9 14 / .6); backdrop-filter: blur(4px); }
.sheet h2 { font-family: var(--display); font-weight: 500; font-size: 21px; margin-bottom: 16px; }
.sheet .rules { margin-bottom: 20px; }
.sheet .rules p { font-size: 14px; }

.rules { display: flex; flex-direction: column; gap: 10px; }
.rules p { margin: 0; font-size: 13.5px; color: var(--muted); }
.rules strong { color: var(--ink); font-weight: 600; }

/* ---------- Настройки правил ---------- */

.setting { display: flex; flex-direction: column; gap: 4px; }
.setting .row { display: flex; justify-content: space-between; align-items: center; gap: 8px 12px; flex-wrap: wrap; }
.setting .row > span { font-size: 14px; font-weight: 500; }
.setting .hint { font-size: 12.5px; color: var(--muted); margin: 0; }
.setting.dim { opacity: .45; }
.seg { display: inline-flex; border: 1px solid var(--rule); border-radius: 999px; padding: 3px; background: var(--surface-2); flex-wrap: wrap; }
.seg button {
  border: 0; background: transparent; color: var(--muted); padding: 6px 12px; border-radius: 999px;
  font-size: 13px; font-weight: 500; cursor: pointer; font-variant-numeric: tabular-nums;
  transition: background .15s, color .15s;
}
.seg button:hover:not(:disabled):not([aria-pressed="true"]) { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }
.seg button:disabled { cursor: default; }
.rules-card .setting + .setting,
.fold .setting + .setting { border-top: 1px solid var(--rule); padding-top: 12px; }
.fold .setting { gap: 10px; }
.fold .look + .look { margin-top: 12px; padding-top: 12px; }
/* В чужой партии правила менять нельзя: вместо переключателей короткая строка. */
.rules-card.locked .setting { display: none; }
.rules-card.locked #rulesNote { font-size: 14px; color: var(--ink); }

/* ---------- Списки друзей и партий ---------- */

.glist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.glist li {
  display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap;
  padding: 11px 14px; border-radius: var(--r); background: var(--surface-2); border: 1px solid transparent;
}
.glist li.invite { border-color: color-mix(in srgb, var(--brand) 45%, var(--rule)); background: color-mix(in srgb, var(--brand) 8%, var(--surface-2)); }
.gi { display: flex; flex-direction: column; min-width: 0; flex: 1 1 160px; }
.gi b { font-weight: 600; font-size: 14.5px; }
.gi span { font-size: 12.5px; color: var(--muted); }
.gi .when { font-size: 11.5px; color: color-mix(in srgb, var(--muted) 80%, transparent); margin-top: 1px; }
.btns { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; flex: none; }
.empty-list { font-size: 13.5px; color: var(--muted); margin: 0; }

/* ---------- Внешний вид ---------- */

.look { display: flex; flex-direction: column; gap: 10px; }
.look + .look { border-top: 1px solid var(--rule); padding-top: 14px; margin-top: 14px; }
.look-name { font-size: 14px; font-weight: 600; }
.swatches, .shapes { display: flex; flex-wrap: wrap; gap: 9px; }
.swatch {
  width: 30px; height: 30px; border-radius: 50%; border: 0; padding: 0; cursor: pointer;
  background: var(--sw); transition: transform .12s;
}
.swatch:hover:not(:disabled) { transform: scale(1.08); }
/* Цвет, который мы советуем к выбранной палитре. */
.swatch.rec { box-shadow: 0 0 0 2px var(--surface), 0 0 0 3px color-mix(in srgb, var(--ink) 28%, transparent); }
.swatch[aria-pressed="true"] { outline: 2px solid var(--ink); outline-offset: 3px; }
.swatch:disabled { opacity: .2; cursor: default; }
.shp {
  position: relative; width: 38px; height: 38px; border-radius: var(--r-sm); padding: 0; cursor: pointer;
  border: 1px solid var(--rule); background: var(--surface-2); transition: border-color .15s, box-shadow .15s;
}
.shp[aria-pressed="true"] { box-shadow: inset 0 0 0 2px var(--ink); border-color: var(--ink); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Подписи осей ---------- */
.board-frame {
  display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto;
  gap: 4px; width: 100%;
}
.ranks, .files {
  display: grid; font-family: var(--mono); font-size: 10px; color: var(--muted);
  font-variant-numeric: tabular-nums; user-select: none;
}
.ranks { grid-column: 1; grid-row: 1; padding: 6px 0; }
.ranks span { display: grid; place-items: center; }
.files { grid-column: 2; grid-row: 2; padding: 0 6px; }
.files span { display: grid; place-items: center; }
.board-box { grid-column: 2; grid-row: 1; position: relative; min-width: 0; }

/* ---------- След от сбитой фишки ---------- */
.cell.scar::before {
  content: ""; position: absolute; inset: 24%; border-radius: 50%; pointer-events: none;
  border: 1.5px dashed var(--sc); opacity: .85;
}
.cell.scar.s1 { --sc: var(--p1); }
.cell.scar.s2 { --sc: var(--p2); }

/* ---------- Навыки игрока ---------- */
.skills { display: flex; flex-wrap: wrap; gap: 5px; min-width: 0; }
.skill {
  display: inline-flex; align-items: baseline; gap: 5px; padding: 3px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 500; white-space: nowrap; max-width: 100%; overflow: hidden;
  background: color-mix(in srgb, var(--pc) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--pc) 35%, transparent); color: var(--ink);
}
.skill b { font-family: var(--mono); font-weight: 600; font-variant-numeric: tabular-nums; color: var(--pc); }
.skill.off { opacity: .4; }
.rank {
  font-family: var(--mono); font-size: 11px; font-weight: 500; color: var(--muted);
  padding: 2px 7px; border: 1px solid var(--rule); border-radius: 999px; flex: none;
}

/* ---------- Таблица лидеров ---------- */
.lead { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; counter-reset: place; }
.lead li {
  display: grid; grid-template-columns: 2.2em minmax(0, 1fr) auto auto; gap: 12px; align-items: center;
  padding: 10px 14px; border-radius: var(--r); background: var(--surface-2); border: 1px solid transparent;
}
.lead li.me { border-color: color-mix(in srgb, var(--brand) 50%, var(--rule)); background: color-mix(in srgb, var(--brand) 9%, var(--surface-2)); }
.lead .place { font-family: var(--mono); font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.lead li:nth-child(1) .place, .lead li:nth-child(2) .place, .lead li:nth-child(3) .place { color: var(--brand); font-weight: 600; }
.lead .who-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lead .score { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.lead .elo { font-family: var(--display); font-size: 17px; font-weight: 500; font-variant-numeric: tabular-nums; }
@media (max-width: 520px) {
  .lead li { grid-template-columns: 2em minmax(0, 1fr) auto; }
  .lead .score { grid-column: 2 / -1; }
}

/* ---------- Журнал: ники цветом игрока ---------- */
.log .nm { font-weight: 600; color: var(--pc); }
.log .nm.n1 { --pc: var(--p1); }
.log .nm.n2 { --pc: var(--p2); }
.log .pos { font-family: var(--mono); font-size: 12px; }
.log .ev-anchor, .log .ev-unanchor, .log .ev-anchorMove { color: var(--brand); }
.log .ev-hit { color: var(--alert); }
.log .ev-cap { color: var(--ok); }
.log .ev-burn, .log .ev-cool, .log .ev-wallGone { color: color-mix(in srgb, var(--burn) 70%, var(--ink)); }
.log .ev-pass, .log .ev-miss, .log .ev-vanish { color: var(--muted); }
.log li { flex-wrap: wrap; }
.log li > span { display: flex; flex-wrap: wrap; gap: 4px; }
.log .ev { display: inline; }

/* ---------- Куда идёт ход ---------- */
/* Клетки, доступные для якоря или его сдвига. */
.cell.target::after {
  content: ""; position: absolute; inset: 40%; border-radius: 50%; pointer-events: none;
  background: var(--ink); opacity: .22; animation: breathe 1.4s ease-in-out infinite;
}
.cell.from { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--ink) 45%, transparent); opacity: .7; }
.cell.from .stone { animation: breathe 1.4s ease-in-out infinite; }
/* Отправленный ход: виден только вам, пока соперник выбирает. */
.cell.pending::before {
  content: ""; position: absolute; inset: 1px; border-radius: 4px; pointer-events: none;
  border: 1.5px dashed var(--brand);
}
.cell.pending { background: color-mix(in srgb, var(--brand) 10%, var(--cell)); }
.badge.mark { font-size: clamp(9px, 1.5vw, 13px); color: var(--ink); opacity: .85; }
.aim.soft { border-color: var(--brand); opacity: .75; }

/* Якорь, отмеченный к возврату в запас. */
.cell.leaving { opacity: .55; }
.cell.leaving::before {
  content: ""; position: absolute; inset: 2px; border-radius: 4px; pointer-events: none;
  border: 1.5px dashed var(--brand);
}

/* ---------- Итог партии ---------- */
.cover.finish { backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px); background: color-mix(in srgb, var(--bg) 62%, transparent); }
.result {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 14px;
  padding: 26px 30px; border-radius: var(--r-lg); max-width: 420px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border: 1px solid var(--rule); box-shadow: var(--shadow-lg);
  animation: rise .5s cubic-bezier(.2, 1.3, .35, 1) both;
}
.result.w1 { --pc: var(--p1); }
.result.w2 { --pc: var(--p2); }
.result.won { border-color: color-mix(in srgb, var(--pc) 55%, var(--rule)); }
.result.won::before {
  content: ""; position: absolute; inset: -2px; border-radius: inherit; pointer-events: none;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--pc) 60%, transparent), 0 0 40px -6px color-mix(in srgb, var(--pc) 55%, transparent);
  animation: halo 2.2s ease-in-out infinite;
}
.result h2 {
  font-family: var(--display); font-weight: 500; font-size: clamp(19px, 3.6vw, 25px);
  text-align: center; text-wrap: balance; margin: 0;
}
.result.won h2 { color: var(--pc); }
.result.lost h2 { color: var(--muted); }
.result .tally {
  margin: 0; display: flex; align-items: center; gap: 12px;
  font-family: var(--mono); font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums;
}
.result .sub-result { font-size: 13.5px; text-align: center; text-wrap: balance; }
.result .btn { min-width: 190px; }

/* Искры разлетаются из центра карточки. */
.sparks { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
.sparks i {
  position: absolute; left: 50%; top: 46%; width: 8px; height: 8px; margin: -4px 0 0 -4px;
  border-radius: 2px; background: var(--pc, var(--brand)); opacity: 0;
  animation: spark 1.1s ease-out var(--t, 0s) 2 both;
}
@keyframes spark {
  0% { opacity: 0; transform: rotate(var(--a)) translateY(0) scale(.5); }
  12% { opacity: 1; }
  100% { opacity: 0; transform: rotate(var(--a)) translateY(calc(var(--d) * -1)) scale(.25); }
}
@keyframes rise { from { opacity: 0; transform: translateY(22px) scale(.9); } }
@keyframes halo { 50% { opacity: .45; } }

/* ---------- Подсветка клетки и её координат ---------- */
.xline, .yline {
  position: absolute; pointer-events: none; z-index: 1; border-radius: 4px;
  background: color-mix(in srgb, var(--ink) 7%, transparent);
}
.xline { left: 6px; right: 6px; }
.yline { top: 6px; bottom: 6px; }
.cellring {
  position: absolute; pointer-events: none; z-index: 2; border-radius: 4px;
  box-shadow: inset 0 0 0 2px var(--brand);
  background: color-mix(in srgb, var(--brand) 16%, transparent);
  animation: breathe 1.2s ease-in-out infinite;
}
.ranks span.on, .files span.on { color: var(--ink); font-weight: 700; }
.log .pos {
  cursor: default; border-bottom: 1px dotted color-mix(in srgb, var(--muted) 55%, transparent);
}
.log .pos:hover { color: var(--brand); border-bottom-color: var(--brand); }

/* ---------- Звук в шапке ---------- */
.vol { display: inline-flex; align-items: center; gap: 8px; }
.iconbtn {
  display: grid; place-items: center; width: 34px; height: 34px; flex: none; cursor: pointer;
  border: 1px solid var(--rule); border-radius: 50%; background: var(--surface); color: var(--ink);
  transition: background .15s, border-color .15s;
}
.iconbtn:hover { background: var(--surface-2); }
.iconbtn svg { width: 19px; height: 19px; }
.iconbtn .horn { fill: currentColor; }
.iconbtn .wave, .iconbtn .cross { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.iconbtn .cross { display: none; }
.iconbtn[aria-pressed="false"] { color: var(--muted); border-color: var(--rule); }
.iconbtn[aria-pressed="false"] .wave { display: none; }
.iconbtn[aria-pressed="false"] .cross { display: block; }
/* Ползунок рисуем сами: общий стиль полей сжимал дорожку отступами. */
.vol-range {
  -webkit-appearance: none; appearance: none;
  width: 94px; height: 16px; padding: 0; margin: 0; border: 0; background: none; cursor: pointer;
}
.vol-range:focus { outline: none; }
.vol-range:focus-visible { outline: 2px solid var(--brand); outline-offset: 3px; border-radius: 999px; }
.vol-range::-webkit-slider-runnable-track {
  height: 4px; border-radius: 999px;
  background: linear-gradient(to right, var(--brand) 0 var(--fill, 70%), var(--rule) var(--fill, 70%) 100%);
}
.vol-range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 14px; height: 14px; margin-top: -5px;
  border-radius: 50%; background: var(--brand); border: 2px solid var(--surface);
  box-shadow: 0 1px 3px rgb(0 0 0 / .35);
}
.vol-range::-moz-range-track { height: 4px; border-radius: 999px; background: var(--rule); }
.vol-range::-moz-range-progress { height: 4px; border-radius: 999px; background: var(--brand); }
.vol-range::-moz-range-thumb {
  width: 14px; height: 14px; border: 2px solid var(--surface); border-radius: 50%;
  background: var(--brand); box-shadow: 0 1px 3px rgb(0 0 0 / .35);
}
@media (max-width: 1040px) { .vol-range { display: none; } }

/* ---------- Палитры ---------- */
.palettes { display: flex; flex-wrap: wrap; gap: 8px; }
.pal {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  padding: 6px 12px 6px 7px; border-radius: 999px; font-size: 13px; font-weight: 500;
  border: 1px solid var(--rule); background: var(--surface-2); color: var(--ink);
}
.pal i { width: 18px; height: 18px; border-radius: 50%; background: linear-gradient(135deg, var(--a), var(--b)); flex: none; }
.pal[aria-pressed="true"] { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); font-weight: 600; }
.pal:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ---------- Цветовые гаммы ---------- */
:root[data-palette="forest"] { --brand: #1E8F5E; --brand-2: #45A86F; --board: #C4D5C8; }
:root[data-palette="sunset"] { --brand: #CF5F2C; --brand-2: #DE893A; --board: #DFCDC2; }
:root[data-palette="violet"] { --brand: #6A3FD0; --brand-2: #9B4FD8; --board: #CDC6E2; }
:root[data-palette="mono"] { --brand: #44506A; --brand-2: #6B7791; --board: #C7CBD5; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"])[data-palette="forest"] { --brand: #35C98A; --brand-2: #7BE0AE; --brand-ink: #06120C; --board: #1D2B23; --cell: #141D18; --cell-hover: #1E2C25; }
  :root:not([data-theme="light"])[data-palette="sunset"] { --brand: #FF8A4C; --brand-2: #FFB169; --brand-ink: #1A0C04; --board: #2E2219; --cell: #1E160F; --cell-hover: #2A1F16; }
  :root:not([data-theme="light"])[data-palette="violet"] { --brand: #9B7BFF; --brand-2: #C58CFF; --brand-ink: #0D0719; --board: #241E36; --cell: #181329; --cell-hover: #231C3A; }
  :root:not([data-theme="light"])[data-palette="mono"] { --brand: #8A97B5; --brand-2: #B4BFD6; --brand-ink: #0B0F17; --board: #232833; --cell: #171B23; --cell-hover: #222733; }
}
:root[data-theme="dark"][data-palette="forest"] { --brand: #35C98A; --brand-2: #7BE0AE; --brand-ink: #06120C; --board: #1D2B23; --cell: #141D18; --cell-hover: #1E2C25; }
:root[data-theme="dark"][data-palette="sunset"] { --brand: #FF8A4C; --brand-2: #FFB169; --brand-ink: #1A0C04; --board: #2E2219; --cell: #1E160F; --cell-hover: #2A1F16; }
:root[data-theme="dark"][data-palette="violet"] { --brand: #9B7BFF; --brand-2: #C58CFF; --brand-ink: #0D0719; --board: #241E36; --cell: #181329; --cell-hover: #231C3A; }
:root[data-theme="dark"][data-palette="mono"] { --brand: #8A97B5; --brand-2: #B4BFD6; --brand-ink: #0B0F17; --board: #232833; --cell: #171B23; --cell-hover: #222733; }

/* ---------- Меню действий по правому клику ---------- */
.cellmenu {
  position: fixed; z-index: 40; min-width: 210px; padding: 6px;
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r);
  box-shadow: var(--shadow-lg); display: flex; flex-direction: column; gap: 2px;
  animation: popin .12s ease-out;
}
.cellmenu .mhead {
  padding: 6px 10px 7px; font-family: var(--mono); font-size: 11px; letter-spacing: .1em;
  text-transform: uppercase; color: var(--muted); border-bottom: 1px solid var(--rule); margin-bottom: 4px;
}
.cellmenu button {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%;
  padding: 9px 10px; border: 0; border-radius: var(--r-sm); background: none; color: var(--ink);
  font-size: 14px; text-align: left; cursor: pointer;
}
.cellmenu button:hover { background: var(--surface-2); }
.cellmenu button:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }
.cellmenu button.on { color: var(--brand); font-weight: 600; }
.cellmenu .minfo {
  display: flex; justify-content: space-between; gap: 12px; padding: 5px 10px;
  font-size: 12.5px; color: var(--muted);
}
.cellmenu .minfo + button { margin-top: 4px; border-top: 1px solid var(--rule); border-radius: 0 0 var(--r-sm) var(--r-sm); padding-top: 10px; }
.cellmenu button small { color: var(--muted); font-size: 12px; }
/* Памятка про якорь: та же раскладка, но только для чтения. */
.celltip {
  position: fixed; z-index: 45; min-width: 240px; max-width: 320px; padding: 6px;
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r);
  box-shadow: var(--shadow-lg); display: flex; flex-direction: column; gap: 2px;
  pointer-events: none; animation: popin .12s ease-out;
}
.celltip .mhead {
  padding: 6px 10px 7px; font-family: var(--mono); font-size: 11px; letter-spacing: .1em;
  text-transform: uppercase; color: var(--muted); border-bottom: 1px solid var(--rule); margin-bottom: 4px;
}
.celltip .minfo { display: flex; justify-content: space-between; gap: 14px; padding: 5px 10px; font-size: 12.5px; }
.celltip .minfo span { font-weight: 600; flex: none; }
.celltip .minfo small { color: var(--muted); font-size: 12px; text-align: right; }

@keyframes popin { from { opacity: 0; transform: scale(.94); } }

/* ---------- Телефон: играть одной рукой ---------- */
@media (max-width: 860px) {
  .main { padding-top: 12px; }
  .who { gap: 6px; }
  .who .linkbtn { display: none; }
  .help span, .hist span { display: none; }
  .help::after { content: "?"; font-size: 15px; font-weight: 700; line-height: 1; }
  .hist::after { content: "↺"; font-size: 16px; line-height: 1; }
  .help, .hist { width: 34px; height: 34px; padding: 0; display: grid; place-items: center; border-radius: 50%; }
  .brand { font-size: 16px; }
  .brand .mark { width: 20px; height: 20px; }

  /* Состояние хода и часы всегда на виду. */
  .status {
    position: sticky; top: 0; z-index: 12; margin: 0 -4px; padding: 6px 4px;
    background: color-mix(in srgb, var(--bg) 92%, transparent);
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  }
  /* Кнопка хода не уезжает за экран. */
  .actions {
    position: sticky; bottom: calc(66px + env(safe-area-inset-bottom, 0px)); z-index: 11;
    padding: 6px 0;
  }
  .actions .btn.primary { box-shadow: var(--shadow-lg); }

  /* Карточки игроков компактнее: чипы в строку, мельче шрифт. */
  .players { gap: 8px; }
  .pcard { padding: 10px; gap: 2px; }
  .pname { font-size: 14px; }
  .pwins { font-size: 22px; }
  .pwins small { font-size: 11px; }
  .skills { gap: 4px; }
  .skill { padding: 2px 7px; font-size: 11.5px; }
  .rank { font-size: 10px; padding: 1px 6px; }
  .playgrid { gap: 14px; }
  .playside { gap: 10px; }
  .tools { gap: 6px; }
  .tools .chip { padding: 6px 11px; font-size: 12.5px; }
  .playbar { padding: 8px 10px; gap: 6px; }
  .playbar .seg button { padding: 6px 9px; font-size: 12px; }
}
@media (max-width: 860px) {
  .only-wide { display: none; }
  .playbar .btn { padding: 8px 14px; font-size: 13px; }
}
@media (max-width: 420px) {
  .gb-code { font-size: 13px; }
  .who .chip { padding: 0; }
}

/* ---------- Страница правил ---------- */
.doc { gap: 10px; }
.doc p { margin: 0; font-size: 14px; line-height: 1.6; color: var(--muted); }
.doc p b { color: var(--ink); font-weight: 600; }
.doc p span { color: var(--ink); }
.help[aria-pressed="true"], .hist[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }

/* Фишка приезжает из прежней клетки: видно, как сработал магнит. */
.stone.slide { animation: slide .38s cubic-bezier(.25, .9, .3, 1) both; }
@keyframes slide {
  from { transform: translate(calc(var(--dx, 0) * 102%), calc(var(--dy, 0) * 102%)); }
  to { transform: translate(0, 0); }
}

/* ---------- Карточка игрока: полоски для запасов, метки для редкого ---------- */
.pcard { gap: 7px; }
.pcard .headline { display: flex; align-items: center; gap: 8px; min-width: 0; }
.pcard .headline .nm { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pcard .headline .score {
  margin-left: auto; font-family: var(--display); font-weight: 500; font-size: 21px; line-height: 1;
  color: var(--pc); font-variant-numeric: tabular-nums;
}
.pcard .sub { font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gauge {
  display: grid; grid-template-columns: 58px minmax(0, 1fr) auto; align-items: center; gap: 8px;
  font-size: 11.5px; color: var(--muted);
}
.gauge .track { height: 5px; border-radius: 999px; background: var(--rule); overflow: hidden; }
.gauge .track span { display: block; height: 100%; background: var(--pc); border-radius: 999px; transition: width .3s; }
.gauge .dots { display: flex; gap: 4px; align-items: center; }
.gauge .dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--pc); }
.gauge .dots i.off { background: var(--rule); }
.gauge b {
  font-family: var(--mono); font-size: 11px; font-weight: 600; color: var(--ink);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.gauge.low b { color: var(--alert); }
.tags { display: flex; gap: 5px; flex-wrap: wrap; }
.tag {
  display: inline-flex; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; white-space: nowrap;
  background: color-mix(in srgb, var(--pc) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--pc) 32%, transparent); color: var(--ink);
}
.tag.go { background: color-mix(in srgb, var(--ok) 18%, transparent); border-color: color-mix(in srgb, var(--ok) 45%, transparent); }

/* Пока идёт отсчёт перед ходом, намерение мигает на доске. */
.cell.intent { background: color-mix(in srgb, var(--brand) 14%, var(--cell)); }
.cell.intent::before {
  content: ""; position: absolute; inset: 1px; border-radius: 4px; pointer-events: none;
  border: 2px dashed var(--brand); animation: blink 1s steps(2, end) infinite;
}
.cell.intent .stone.ghost { opacity: .6; animation: blink 1.1s ease-in-out infinite; }
.cell.intent .aim { animation: blink 1s steps(2, end) infinite; }
