/*
 * Быки и Коровы — интерфейс пошаговой дуэли.
 * Наследует гамму alfa 1.2 (серая шапка, синий primary, зелёный «бык», охра «корова»),
 * mobile-first, светлая и тёмная темы, без внешних шрифтов и библиотек.
 */

/* ================================================================ tokens */
:root {
  color-scheme: light dark;

  --bg: #eef0f3;
  --surface: #ffffff;
  --surface-2: #f6f7f9;
  --border: #dde1e6;
  --text: #1e2832;
  --muted: #6b7785;
  --header-bg: #d7e9f6;
  --header-text: #17324d;
  --header-border: #c2daee;

  --primary: #2d6ca2;
  --primary-hover: #245a88;
  --primary-soft: #e2edf7;
  --on-primary: #ffffff;

  --bull: #2f8a3e;
  --bull-soft: #ddf0e1;
  --cow: #c2850f;
  --cow-soft: #fbefd3;
  --miss: #c9ced5;
  --danger: #c0392b;
  --danger-soft: #f8e1de;
  --ok: #2f8a3e;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 6px 20px rgba(16, 24, 40, .06);
  --shadow-up: 0 -6px 24px rgba(16, 24, 40, .10);

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;

  --header-h: 52px;
  --tabbar-h: 58px;
  --content-w: 1040px;
  --gutter: 16px;
  --tap: 44px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151a;
    --surface: #1a2027;
    --surface-2: #212932;
    --border: #2d3742;
    --text: #e5e9ee;
    --muted: #92a0ae;
    --header-bg: #1b2b3d;
    --header-text: #e3eef8;
    --header-border: #243a52;

    --primary: #4a8fd1;
    --primary-hover: #5d9edb;
    --primary-soft: #1b3248;

    --bull: #4cb860;
    --bull-soft: #1b3423;
    --cow: #e0a53b;
    --cow-soft: #3a2e15;
    --miss: #3b4652;
    --danger: #e5594b;
    --danger-soft: #3b1f1c;
    --ok: #4cb860;

    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    --shadow-up: 0 -6px 24px rgba(0, 0, 0, .35);
  }
}

/* ================================================================ base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0; }
a { color: var(--primary); }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 55%, transparent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: var(--mono); }
.center { text-align: center; }
.stack { display: grid; gap: var(--gutter); }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.row--between { justify-content: space-between; }
.row--end { justify-content: flex-end; }
.row--center { justify-content: center; }
.grow { flex: 1 1 auto; min-width: 0; }
.loading { color: var(--muted); padding: 3rem 0; text-align: center; }

/* ================================================================ header */
.header {
  position: sticky;
  top: 0;
  z-index: 20;
  height: calc(var(--header-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(var(--gutter), env(safe-area-inset-right)) 0 max(var(--gutter), env(safe-area-inset-left));
  background: var(--header-bg);
  color: var(--header-text);
  border-bottom: 1px solid var(--header-border);
  display: flex;
  align-items: center;
  gap: .75rem;
}
.header__title {
  color: inherit;
  text-decoration: none;
  font-size: 1.15rem;
  white-space: nowrap;
}
.header__title b { font-weight: 700; }
.header__ver { font-size: .75rem; opacity: .6; margin-left: .35rem; }
.header__help {
  display: none;
  width: 32px; height: 32px; border-radius: 50%;
  place-items: center; flex: none;
  color: var(--header-text); text-decoration: none; font-weight: 800;
  border: 1.5px solid color-mix(in srgb, var(--header-text) 35%, transparent);
}
body.in-game .header__help { display: grid; }
.header__me {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: .5rem;
  min-width: 0;
  font-size: .9rem;
}
.header__nick { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40vw; }
.conn { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); flex: none; }
.conn--off { background: var(--danger); animation: blink 1.2s infinite; }

/* ================================================================ tab bar */
body { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
}
.tabbar__inner {
  height: var(--tabbar-h);
  max-width: 480px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}
.tabbar a {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted);
  text-decoration: none;
  font-size: .72rem;
  font-weight: 600;
  -webkit-tap-highlight-color: transparent;
}
.tabbar a:hover { color: var(--text); }
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a[aria-current="page"] { color: var(--primary); }
.tabbar a[aria-current="page"] svg { stroke-width: 2.2; }
.tabbar a[aria-current="page"]::before {
  content: ""; position: absolute; top: 0; left: 32%; right: 32%;
  height: 3px; border-radius: 0 0 3px 3px; background: var(--primary);
}
/* Во время партии меню скрыто: внизу панель с клавиатурой, а уйти из игры всё равно нельзя */
body.in-game { padding-bottom: 0; }
body.in-game .tabbar { display: none; }

/* ================================================================ layout */
.main {
  width: 100%;
  max-width: var(--content-w);
  margin: 0 auto;
  padding: var(--gutter) max(var(--gutter), env(safe-area-inset-right)) calc(var(--gutter) * 2) max(var(--gutter), env(safe-area-inset-left));
}

/* ================================================================ primitives */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--gutter);
}
.card--flat { box-shadow: none; }
.card__title { display: flex; align-items: baseline; justify-content: space-between; gap: .5rem; margin-bottom: .75rem; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  min-height: var(--tap);
  padding: 0 1.1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn--primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn--primary:hover { background: var(--primary-hover); }
.btn--danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
.btn--danger:hover { background: var(--danger-soft); }
.btn--danger-fill { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn--ghost { background: transparent; border-color: transparent; }
.btn--ghost:hover { background: var(--surface-2); }
.btn--sm { min-height: 36px; padding: 0 .8rem; font-size: .9rem; }
.btn--block { width: 100%; }

.input {
  min-height: var(--tap);
  padding: 0 .8rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  min-width: 0;
}
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .1rem .55rem;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}
.chip--free { background: var(--bull-soft); color: var(--bull); }
.chip--busy { background: var(--cow-soft); color: var(--cow); }
.chip--offline { background: var(--danger-soft); color: var(--danger); }
.chip--turn { background: var(--primary); color: var(--on-primary); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; }

.avatar {
  --hue: 210;
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: .95rem;
  color: hsl(var(--hue) 55% 30%);
  background: hsl(var(--hue) 60% 88%);
  position: relative;
}
@media (prefers-color-scheme: dark) {
  .avatar { color: hsl(var(--hue) 70% 82%); background: hsl(var(--hue) 35% 26%); }
}
.avatar--sm { width: 32px; height: 32px; font-size: .8rem; }
.avatar--lg { width: 56px; height: 56px; font-size: 1.2rem; }
.avatar__status {
  position: absolute; right: -1px; bottom: -1px;
  width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid var(--surface);
  background: var(--ok);
}
.avatar__status--off { background: var(--miss); }

/* ================================================================ digits: tiles, pips */
.tiles { display: inline-flex; gap: 4px; }
.tile {
  width: 30px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font: 700 1.05rem var(--mono);
  color: var(--text);
}
.tile--lg { width: 44px; height: 52px; font-size: 1.5rem; border-radius: 10px; }
.tile--hidden { color: var(--muted); background: repeating-linear-gradient(45deg, var(--surface-2), var(--surface-2) 4px, var(--surface) 4px, var(--surface) 8px); }
.tile--bull { background: var(--bull-soft); border-color: var(--bull); color: var(--bull); }
.tile--cow { background: var(--cow-soft); border-color: var(--cow); color: var(--cow); }
.tile--out { color: var(--muted); text-decoration: line-through; opacity: .55; }
.tile--in { border-color: var(--bull); box-shadow: inset 0 -3px 0 var(--bull); }

.pips { display: inline-flex; gap: 4px; align-items: center; }
.pip { width: 12px; height: 12px; border-radius: 50%; background: transparent; border: 2px solid var(--miss); }
.pip--bull { background: var(--bull); border-color: var(--bull); }
.pip--cow { background: var(--cow); border-color: var(--cow); }
.score { display: inline-flex; align-items: center; gap: .5rem; }
.score__text { font: 600 .85rem var(--mono); color: var(--muted); min-width: 4.2em; }
.score__text b:first-child { color: var(--bull); }
.score__text b:last-child { color: var(--cow); }

/* ================================================================ lobby */
.hero { display: grid; gap: .5rem; }
.hero h1 { font-size: 1.7rem; }
.rules summary { cursor: pointer; color: var(--primary); font-weight: 600; min-height: var(--tap); display: flex; align-items: center; }
.rules ul { margin: .25rem 0 0; padding-left: 1.2rem; display: grid; gap: .35rem; }
.legend { display: inline-flex; gap: .75rem; flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: .3rem; }

.profile { display: flex; gap: .9rem; align-items: center; flex-wrap: wrap; }
.profile form { display: flex; gap: .5rem; flex: 1 1 180px; min-width: 0; }
.profile .input { flex: 1 1 auto; }
.stats { display: flex; gap: 1.25rem; flex-wrap: wrap; }
.stat { display: grid; }
.stat b { font-size: 1.15rem; }
.stat span { font-size: .78rem; color: var(--muted); }

.rooms { display: grid; gap: var(--gutter); grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.room { display: grid; gap: .75rem; align-content: space-between; text-decoration: none; color: inherit; transition: border-color .15s, transform .15s; }
.room:hover { border-color: var(--primary); transform: translateY(-2px); }
.room__online { display: inline-flex; align-items: center; gap: .35rem; color: var(--ok); font-weight: 600; font-size: .9rem; }
.room__online--zero { color: var(--muted); }

/* ================================================================ room */
.pagehead { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.pagehead h2 { margin-right: auto; }
.players { list-style: none; margin: 0; padding: 0; }
.player {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .7rem 0;
  border-top: 1px solid var(--border);
}
.player:first-child { border-top: 0; }
.player__name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player__meta { font-size: .82rem; color: var(--muted); }
.player--me { background: linear-gradient(90deg, var(--primary-soft), transparent); margin: 0 calc(var(--gutter) * -1); padding-left: var(--gutter); padding-right: var(--gutter); }
.empty { text-align: center; color: var(--muted); padding: 1.5rem .5rem; display: grid; gap: .5rem; justify-items: center; }

/* ================================================================ game: duel strip */
.game { display: grid; gap: var(--gutter); }
/* Партия на весь экран: панель действий прижата к низу, даже когда ходов мало */
.game--play {
  display: flex;
  flex-direction: column;
  min-height: calc(100dvh - var(--header-h) - env(safe-area-inset-top) - var(--gutter) * 3);
}
.game--play > .dock { margin-top: auto; }
.duel {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: .5rem;
}
.duel__vs { font-weight: 800; color: var(--muted); font-size: .85rem; letter-spacing: .08em; }
.fighter {
  display: flex;
  align-items: center;
  gap: .6rem;
  min-width: 0;
  padding: .6rem .7rem;
  border-radius: var(--radius);
  background: var(--surface);
  border: 2px solid var(--border);
  transition: border-color .2s, box-shadow .2s;
}
.fighter--opp { flex-direction: row-reverse; text-align: right; }
.fighter--active { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft); }
.fighter__info { min-width: 0; display: grid; gap: .15rem; }
.fighter__name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fighter__sub { font-size: .78rem; color: var(--muted); display: flex; gap: .35rem; align-items: center; flex-wrap: wrap; }
.fighter--opp .fighter__sub { justify-content: flex-end; }
.misses { display: inline-flex; gap: 3px; }
.misses i { width: 7px; height: 7px; border-radius: 50%; background: var(--miss); }
.misses i.on { background: var(--danger); }

/* ================================================================ game: boards */
.tabs { display: none; }
.boards { display: grid; gap: var(--gutter); grid-template-columns: 1fr 1fr; align-items: start; }
.board { padding: 0; overflow: hidden; }
.board__head {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  padding: .8rem var(--gutter);
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.board__head h3 { display: flex; align-items: center; gap: .5rem; }
.board__secret { display: flex; align-items: center; gap: .6rem; }
.board__secret .small { color: var(--muted); }
.moves { list-style: none; margin: 0; padding: .25rem 0; }
.move {
  display: grid;
  grid-template-columns: 2.2rem auto 1fr;
  align-items: center;
  gap: .6rem;
  padding: .45rem var(--gutter);
}
.move + .move { border-top: 1px dashed var(--border); }
.move__seq { font: .8rem var(--mono); color: var(--muted); }
.move__score { justify-self: end; }
.move--win { background: var(--bull-soft); }
.move--timeout .move__score { font-size: .85rem; color: var(--muted); font-style: italic; }
.move--new { animation: flash 1.6s ease-out; }
.moves__empty { padding: 1.25rem var(--gutter); color: var(--muted); text-align: center; font-size: .9rem; }

/* ================================================================ game: action dock */
.dock {
  position: sticky;
  bottom: 0;
  z-index: 15;
  margin: 0 auto;
  width: 100%;
  max-width: 560px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: var(--shadow-up);
  padding: .8rem var(--gutter) calc(.8rem + env(safe-area-inset-bottom));
  display: grid;
  gap: .7rem;
}
.dock--idle { position: static; box-shadow: var(--shadow); }
@media (min-width: 760px) {
  .dock { bottom: 12px; border-radius: var(--radius); }
}
.turn { display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.turn__label { font-weight: 800; font-size: 1.05rem; display: flex; align-items: center; gap: .5rem; }
.turn__label--me { color: var(--primary); }
.turn__label--wait { color: var(--muted); }
.timer { font: 700 1rem var(--mono); font-variant-numeric: tabular-nums; }
.timer--low { color: var(--danger); animation: pulse 1s infinite; }
.timer-bar { height: 5px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.timer-bar > span { display: block; height: 100%; background: var(--primary); transition: width .25s linear; }
.timer-bar--low > span { background: var(--danger); }

.slots { display: flex; gap: .5rem; justify-content: center; }
.slot {
  width: 52px;
  height: 60px;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--surface-2);
  display: grid;
  place-items: center;
  font: 800 1.7rem var(--mono);
}
.slot--filled { border-color: var(--primary); background: var(--primary-soft); color: var(--text); animation: pop .15s ease-out; }
.slot--next { border-color: var(--primary); border-style: dashed; }
.slots--error .slot { border-color: var(--danger); animation: shake .3s; }

.keypad { display: grid; grid-template-columns: repeat(5, 1fr); gap: .45rem; }
.key {
  min-height: 52px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  font: 700 1.35rem var(--mono);
  cursor: pointer;
  position: relative;
  user-select: none;
  touch-action: manipulation;
  transition: background .1s, transform .05s;
}
.key:hover { background: var(--surface-2); }
.key:active { transform: scale(.96); }
.key:disabled { opacity: .35; cursor: default; transform: none; }
.key--out { color: var(--muted); text-decoration: line-through; background: var(--surface-2); }
.key--in { border-color: var(--bull); color: var(--bull); box-shadow: inset 0 -3px 0 var(--bull); }
.keypad--notes .key { border-style: dashed; }
.keybar { display: grid; grid-template-columns: auto auto 1fr; gap: .45rem; }
.keybar .btn { min-height: 48px; }
.note-hint { font-size: .8rem; color: var(--muted); text-align: center; }
.last { display: flex; align-items: center; justify-content: center; gap: .75rem; flex-wrap: wrap; font-size: .9rem; color: var(--muted); }

/* ================================================================ game: phases */
.phase { display: grid; gap: 1rem; justify-items: center; text-align: center; padding: 1.5rem var(--gutter); }
.phase .timer-bar { width: min(320px, 100%); }
.spinner { width: 46px; height: 46px; border-radius: 50%; border: 4px solid var(--primary-soft); border-top-color: var(--primary); animation: spin 1s linear infinite; }
.ready { display: inline-flex; align-items: center; gap: .4rem; font-weight: 600; }
.ready--yes { color: var(--ok); }
.ready--no { color: var(--muted); }

.result { display: grid; gap: .9rem; justify-items: center; text-align: center; padding: 1.75rem var(--gutter); }
.result__title { font-size: 2rem; font-weight: 800; }
.result--win .result__title { color: var(--bull); }
.result--lose .result__title { color: var(--danger); }
.result__secrets { display: flex; gap: 1.5rem; flex-wrap: wrap; justify-content: center; }
.result__secrets > div { display: grid; gap: .35rem; justify-items: center; }

/* ================================================================ modal & toasts */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(10, 14, 20, .5);
  display: flex; align-items: center; justify-content: center;
  padding: var(--gutter);
  animation: fade .15s ease-out;
}
.modal {
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 420px;
  padding: 1.25rem;
  display: grid;
  gap: 1rem;
  animation: rise .2s ease-out;
}
.modal__actions { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }

.toasts {
  position: fixed; z-index: 60;
  top: calc(var(--header-h) + env(safe-area-inset-top) + 8px);
  right: 12px;
  display: grid; gap: 8px;
  width: min(360px, calc(100vw - 24px));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  padding: .7rem .9rem;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  box-shadow: var(--shadow);
  font-weight: 600;
  font-size: .92rem;
  cursor: pointer;
  animation: rise .2s ease-out;
}
.toast--success { border-left-color: var(--ok); }
.toast--error { border-left-color: var(--danger); }

/* ================================================================ animations */
@keyframes flash { from { background: var(--primary-soft); } to { background: transparent; } }
@keyframes pop { from { transform: scale(.85); } to { transform: scale(1); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
@keyframes pulse { 50% { opacity: .55; } }
@keyframes blink { 50% { opacity: .3; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

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

/* ================================================================ mobile */
@media (max-width: 759px) {
  :root { --gutter: 12px; }
  h1, .hero h1 { font-size: 1.4rem; }
  .header__ver { display: none; }
  .main { padding-bottom: var(--gutter); }

  .duel { gap: .35rem; }
  .fighter { padding: .45rem .5rem; gap: .45rem; }
  .fighter .avatar { width: 32px; height: 32px; font-size: .8rem; }
  .fighter__name { font-size: .9rem; }

  .tabs {
    display: grid; grid-template-columns: 1fr 1fr;
    background: var(--surface-2); border: 1px solid var(--border);
    border-radius: 12px; padding: 4px; gap: 4px;
  }
  .tab {
    min-height: 40px; border: 0; border-radius: 9px; background: transparent;
    font-weight: 700; color: var(--muted); cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  }
  .tab--active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
  .tab__badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: .72rem; display: grid; place-items: center; }

  .boards { grid-template-columns: 1fr; }
  .board__head h3 { display: none; }
  .board__head { justify-content: flex-end; }
  .game--play { min-height: calc(100dvh - var(--header-h) - env(safe-area-inset-top) - var(--gutter)); }
  .boards[data-tab="me"] .board--opp,
  .boards[data-tab="opp"] .board--me { display: none; }

  .dock {
    border-radius: var(--radius) var(--radius) 0 0;
    margin: 0 calc(var(--gutter) * -1) calc(var(--gutter) * -1);
    width: auto;
    max-width: none;
    border-left: 0; border-right: 0; border-bottom: 0;
  }
  .dock--idle { margin: 0; border: 1px solid var(--border); border-radius: var(--radius); }
  .key { min-height: 50px; }
  .slot { width: 48px; height: 56px; }

  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal { max-width: none; border-radius: var(--radius) var(--radius) 0 0; padding-bottom: calc(1.25rem + env(safe-area-inset-bottom)); }

  .toasts { left: 12px; right: 12px; width: auto; }
}

@media (max-width: 380px) {
  .fighter__sub .chip { display: none; }
  .tile { width: 26px; height: 32px; font-size: .95rem; }
  .move { gap: .4rem; }
  .pip { width: 10px; height: 10px; }
}

/* ================================================================ accounts, help, profile */

.name { display: inline-flex; align-items: center; gap: .35rem; min-width: 0; max-width: 100%; }
.name__text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge-reg {
  flex: none; width: 17px; height: 17px; border-radius: 50%;
  display: inline-grid; place-items: center;
  background: var(--primary); color: var(--on-primary); font-size: .65rem; font-weight: 800;
}
.chip--guest { background: transparent; border: 1px dashed var(--border); color: var(--muted); font-weight: 500; padding: 0 .45rem; }
.avatar--guest { background: transparent; border: 2px dashed hsl(var(--hue) 40% 60%); }

.gbtn { min-height: 44px; display: flex; align-items: center; }
.signin { display: grid; gap: .6rem; padding: .9rem; border-radius: var(--radius-sm); background: var(--primary-soft); }
.signin p { font-size: .9rem; }

.prose { display: grid; gap: .8rem; line-height: 1.6; }
.prose h2 { margin-top: .5rem; }
.prose ul, .prose ol { margin: 0; padding-left: 1.3rem; display: grid; gap: .35rem; }
.prose code { font: .9em var(--mono); background: var(--surface-2); padding: .1rem .35rem; border-radius: 5px; }
.prose table { border-collapse: collapse; width: 100%; font-size: .92rem; }
.prose th, .prose td { border-bottom: 1px solid var(--border); padding: .45rem .5rem; text-align: left; }
.prose th { color: var(--muted); font-weight: 600; }
.prose .formula { font: 1rem var(--mono); background: var(--surface-2); padding: .7rem .9rem; border-radius: var(--radius-sm); overflow-x: auto; }
.help-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.help-list a {
  display: grid; gap: .15rem; padding: .8rem var(--gutter); text-decoration: none; color: inherit;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface);
}
.help-list a:hover { border-color: var(--primary); }
.help-list b { color: var(--primary); }
.crumbs { display: flex; gap: .4rem; align-items: center; font-size: .9rem; color: var(--muted); }

.chart { width: 100%; height: 140px; display: block; }
.chart__line { fill: none; stroke: var(--primary); stroke-width: 2.5; }
.chart__area { fill: var(--primary-soft); opacity: .7; }
.chart__dot { fill: var(--primary); }
.history { list-style: none; margin: 0; padding: 0; }
.history li + li { border-top: 1px solid var(--border); }
.history a {
  display: grid; grid-template-columns: auto 1fr auto; gap: .2rem .75rem; align-items: center;
  padding: .7rem 0; text-decoration: none; color: inherit;
}
.history__res { font-weight: 800; font-size: .8rem; border-radius: 6px; padding: .15rem .5rem; text-align: center; min-width: 5.5rem; }
.history__res--won { background: var(--bull-soft); color: var(--bull); }
.history__res--lost { background: var(--danger-soft); color: var(--danger); }
.history__res--draw { background: var(--surface-2); color: var(--muted); }
.history__meta { font-size: .8rem; color: var(--muted); grid-column: 2; }
.delta { font: 700 .95rem var(--mono); grid-row: span 2; }
.delta--up { color: var(--bull); }
.delta--down { color: var(--danger); }

@media (max-width: 759px) {
  .header__nick { max-width: 28vw; }
  .history__res { min-width: 4.5rem; }
}

/* ---------- строка игрока на главной */
.userbar { display: flex; align-items: center; gap: .65rem; padding: .55rem var(--gutter); }
.userbar__info { display: flex; align-items: baseline; gap: .6rem; min-width: 0; flex: 1 1 auto; flex-wrap: nowrap; font-weight: 600; overflow: hidden; }
.userbar__info .name { flex: 0 1 auto; }
.userbar__stat { white-space: nowrap; }
@media (max-width: 380px) { .userbar__rank { display: none; } }
.userbar__edit { flex: none; font-size: .9rem; font-weight: 600; white-space: nowrap; min-height: var(--tap); display: inline-flex; align-items: center; }
