/* Шахматы VK Mini App — классическая тема: тёплое дерево, латунь, приглушённая зелень.
   Консервативный стиль (в отличие от футуристичных шашек). Тема единая тёмная. */
:root {
    --font: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --radius: 16px;

    --bg-0: #2a2019;
    --bg-1: #14100b;
    --text: #efe7d6;
    --text-dim: #a89880;

    /* латунь вместо неонового золота */
    --brass-1: #e6cd94;
    --brass-2: #b58f3c;
    --brass-3: #856616;

    /* классическая зелёная кнопка */
    --green-1: #4e8560;
    --green-2: #33613f;

    --panel: rgba(58, 45, 33, .5);
    --panel-2: rgba(70, 55, 40, .7);
    --panel-border: rgba(184, 152, 100, .26);
    --panel-soft: 0 4px 14px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .05);

    --sq-light: #f0dfc0;
    --sq-dark: #8a6a47;
    --frame: linear-gradient(160deg, #5c422f, #3a281b 55%, #4d3826);

    --pw: #f7f1e3;
    --pw-edge: #6a583a;
    --pb: #221c14;
    --pb-hi: rgba(255, 255, 255, .28);

    --sel: rgba(150, 160, 90, .85);
    --hint: rgba(120, 130, 75, .7);
    --cap: rgba(170, 80, 55, .8);
    --chk: rgba(180, 66, 52, .5);
}

* {
    box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent;
    /* Игровое поле: без выделения текста/каллаута — иначе тап/свайп по доске триггерит
       системное выделение или контекстное меню (требования Яндекс Игр п. 1.6.1.8/1.6.2.7). */
    -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
html, body { min-height: 100%; overscroll-behavior-y: none; }
body {
    font-family: var(--font);
    color: var(--text);
    font-size: 15px; line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    overscroll-behavior: none;
    touch-action: pan-x pan-y;
    background:
        radial-gradient(115% 65% at 50% -8%, rgba(150, 115, 65, .22), transparent 60%),
        radial-gradient(90% 60% at 50% 118%, rgba(90, 65, 40, .18), transparent 60%),
        linear-gradient(180deg, var(--bg-0), var(--bg-1) 72%);
    background-attachment: fixed;
}
.hidden { display: none !important; }
#app { min-height: 100dvh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.screen {
    flex: 1; display: flex; flex-direction: column;
    padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
    overflow-y: auto; overflow-x: hidden; scrollbar-width: thin;
}

/* --- Меню --- */
/* safe center: центрирует, если влезает; при переполнении прижимает к верху (не обрезает, скроллится) */
#screen-menu { align-items: center; justify-content: safe center; gap: 8px; }
.menu-title {
    font-size: 48px; font-weight: 800; letter-spacing: 1px;
    background: linear-gradient(180deg, var(--brass-1) 20%, var(--brass-2) 62%, var(--brass-3));
    -webkit-background-clip: text; background-clip: text; color: transparent;
    filter: drop-shadow(0 2px 6px rgba(0, 0, 0, .4));
}
.menu-subtitle {
    font-size: 12px; font-weight: 700; letter-spacing: 2.4px; text-transform: uppercase;
    color: var(--text-dim); margin: -2px 0 24px; text-align: center;
}

.menu-actions { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px; }
.mode-card {
    display: flex; align-items: center; gap: 14px; text-align: left;
    font-family: var(--font); color: var(--text); cursor: pointer;
    background: var(--panel); border: 1.5px solid var(--panel-border); border-radius: 18px;
    padding: 15px 16px; box-shadow: var(--panel-soft);
    transition: transform .07s ease, border-color .15s ease;
}
.mode-card:active { transform: scale(.98); }
.mode-card:disabled { opacity: .5; cursor: default; }
.mode-card[aria-busy="true"] { opacity: .72; cursor: wait; }
.mode-card-primary {
    border-color: rgba(120, 155, 110, .55);
    background: linear-gradient(165deg, rgba(58, 88, 62, .5), rgba(50, 40, 28, .55));
    box-shadow: 0 6px 18px rgba(0, 0, 0, .4), inset 0 1px 0 rgba(255, 255, 255, .06);
}
.continue-card {
    border-color: rgba(200, 165, 90, .72);
    background: linear-gradient(165deg, rgba(105, 78, 34, .5), rgba(50, 40, 28, .6));
}
@media (max-height: 900px) {
    #screen-menu.has-continue { gap: 4px; }
    #screen-menu.has-continue .menu-title { font-size: 34px; }
    #screen-menu.has-continue .menu-subtitle { margin: -2px 0 8px; }
    #screen-menu.has-continue .menu-actions { gap: 8px; }
    #screen-menu.has-continue .mode-card { padding: 9px 14px; }
    #screen-menu.has-continue .mode-icon { width: 42px; height: 42px; }
    #screen-menu.has-continue .difficulty { margin-top: 9px; }
    #screen-menu.has-continue .difficulty-label { margin-bottom: 6px; }
    #screen-menu.has-continue .level-list { gap: 5px; }
    #screen-menu.has-continue .level-item { padding: 5px 12px; }
    #screen-menu.has-continue .menu-stats { margin-top: 8px; }
    #screen-menu.has-continue .rules-link { margin-top: 7px; }
}
.mode-icon {
    flex: none; width: 52px; height: 52px; border-radius: 14px;
    background: rgba(20, 14, 8, .55); border: 1px solid var(--panel-border);
    display: flex; align-items: center; justify-content: center;
}
.mode-glyph { font-size: 30px; line-height: 1; color: var(--pw); filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .5)); font-variant-emoji: text; }
.mode-glyph.w { color: var(--pw); }
.mode-glyph.over { margin-left: -12px; color: #4a3a28; }
.mode-name { display: block; font-size: 17px; font-weight: 800; }
.mode-sub { display: block; font-size: 12.5px; color: var(--text-dim); margin-top: 2px; }

/* Статистика в меню */
.menu-stats {
    display: flex; align-items: stretch; gap: 4px; margin-top: 22px;
    background: var(--panel); border: 1.5px solid var(--panel-border); border-radius: 14px;
    padding: 12px 8px; box-shadow: var(--panel-soft);
}
.stat-item { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.stat-item b { font-size: 22px; font-weight: 800; color: var(--brass-1); }
.stat-item span { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .5px; }
.stat-sep { width: 1px; background: var(--panel-border); }

.rules-link {
    margin-top: 20px; background: none; border: none; cursor: pointer;
    color: var(--text-dim); font-family: var(--font); font-size: 14px; font-weight: 600; text-decoration: underline;
}

.btn {
    font-family: var(--font); font-size: 16px; font-weight: 700;
    border: none; border-radius: var(--radius); padding: 15px 18px;
    cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px;
    transition: transform .06s ease, opacity .15s ease;
    color: var(--text);
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary {
    background: linear-gradient(180deg, var(--green-1), var(--green-2));
    box-shadow: 0 4px 14px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .18);
    color: #fff;
}
.btn-secondary { background: var(--panel-2); border: 1.5px solid var(--panel-border); box-shadow: var(--panel-soft); }
.btn-ghost { background: transparent; color: var(--text-dim); }
.badge { font-size: 11px; font-weight: 700; background: rgba(184, 152, 100, .18); color: var(--text-dim); padding: 2px 8px; border-radius: 999px; }

/* --- Сложность / цвет фигур --- */
.difficulty { margin-top: 22px; width: 100%; max-width: 380px; text-align: center; }
.difficulty-label { font-size: 12px; font-weight: 700; letter-spacing: 1.6px; text-transform: uppercase; color: var(--text-dim); margin-bottom: 10px; }
.level-list { display: flex; flex-direction: column; gap: 8px; }
.level-item {
    display: flex; align-items: center; gap: 12px; text-align: left;
    background: var(--panel); border: 1.5px solid var(--panel-border); border-radius: 14px;
    padding: 10px 14px; cursor: pointer; font-family: var(--font); color: var(--text);
    transition: border-color .15s ease;
}
.level-item .level-ico { font-size: 20px; width: 28px; text-align: center; }
.level-text { flex: 1; display: flex; flex-direction: column; }
.level-text b { font-size: 15px; font-weight: 800; }
.level-text i { font-style: normal; font-size: 12px; color: var(--text-dim); }
.level-check { color: var(--brass-1); font-weight: 800; font-size: 17px; opacity: 0; transition: opacity .15s ease; }
.level-item.active {
    border-color: rgba(184, 152, 100, .7);
    box-shadow: 0 4px 12px rgba(0, 0, 0, .3), inset 0 1px 0 rgba(255, 255, 255, .05);
}
.level-item.active .level-check { opacity: 1; }

.seg { display: inline-flex; background: var(--panel); border: 1.5px solid var(--panel-border); border-radius: 14px; padding: 4px; gap: 4px; box-shadow: var(--panel-soft); }
.side-btn { border: none; background: transparent; color: var(--text-dim); font-family: var(--font); font-weight: 700; font-size: 14px; padding: 9px 22px; border-radius: 10px; cursor: pointer; }
.side-btn.active { background: linear-gradient(180deg, var(--green-1), var(--green-2)); color: #fff; box-shadow: inset 0 1px 0 rgba(255, 255, 255, .18); }

/* --- Игра --- */
.game-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.icon-btn {
    width: 42px; height: 42px; border-radius: 13px; cursor: pointer;
    border: 1.5px solid var(--panel-border); background: var(--panel); color: var(--text);
    font-size: 22px; display: flex; align-items: center; justify-content: center;
    box-shadow: var(--panel-soft);
}
.status {
    flex: 1; text-align: center; font-weight: 800; font-size: 14px; letter-spacing: .4px;
    background: var(--panel); border: 1.5px solid var(--panel-border); border-radius: 999px;
    padding: 9px 14px; box-shadow: var(--panel-soft);
}
.status.check { color: #f0a090; border-color: rgba(170, 80, 55, .5); }

/* Панель соперника над доской */
.opp-bar {
    display: flex; align-items: center; gap: 12px;
    max-width: min(88vw, 454px); width: 100%; margin: 0 auto 12px;
    background: var(--panel); border: 1.5px solid var(--panel-border); border-radius: 16px;
    padding: 8px 14px; box-shadow: var(--panel-soft);
    transition: border-color .2s ease, box-shadow .2s ease;
}
.opp-ava {
    flex: none; width: 40px; height: 40px; border-radius: 50%;
    background: rgba(20, 14, 8, .55); border: 1.5px solid var(--panel-border);
    display: flex; align-items: center; justify-content: center; font-size: 22px;
}
.opp-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.opp-name { font-size: 15px; font-weight: 800; }
.opp-sub { font-size: 12px; color: var(--text-dim); }
.opp-turn { flex: none; }
.turn-dot { display: block; width: 10px; height: 10px; border-radius: 50%; background: #5a4a38; transition: background .2s ease, box-shadow .2s ease; }
.opp-bar.thinking { border-color: rgba(200, 165, 90, .6); box-shadow: 0 4px 14px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .05); }
.opp-bar.thinking .turn-dot { background: var(--brass-1); box-shadow: 0 0 8px rgba(200, 165, 90, .8); animation: dotPulse 1s ease-in-out infinite; }
@keyframes dotPulse { 0%,100% { opacity: .5; } 50% { opacity: 1; } }

.board-wrap { display: flex; justify-content: center; }
.board-frame {
    padding: 8px; border-radius: 18px;
    background: var(--frame);
    box-shadow: 0 14px 36px rgba(0, 0, 0, .55), inset 0 1px 0 rgba(255, 255, 255, .08), inset 0 0 0 1.5px rgba(184, 152, 100, .3);
}
.board {
    /* Ограничение И по высоте: иначе на десктопном/ландшафтном фрейме доска высокая
       и нижние кнопки уезжают за экран (замечание модерации). Запас считает шапку,
       панель соперника, взятые фигуры, СТРОКУ ЧАСОВ/НОТАЦИИ и кнопки — при добавлении
       новых блоков под доской его нужно увеличивать, иначе низ обрежется в VK-фрейме. */
    width: min(88vw, 440px, calc(100dvh - 356px)); aspect-ratio: 1;
    position: relative; display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr);
    border-radius: 10px; overflow: hidden;
    touch-action: manipulation;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .3);
}
.sq { position: relative; display: flex; align-items: center; justify-content: center; cursor: pointer; user-select: none; }
.sq.light { background: var(--sq-light); }
.sq.dark { background: var(--sq-dark); }
.sq.last::before { content: ''; position: absolute; inset: 0; background: rgba(190, 175, 90, .35); }
.sq.check::before { content: ''; position: absolute; inset: 0; background: var(--chk); }

/* Координаты по краям доски */
.coord { position: absolute; font-size: 9px; font-weight: 800; opacity: .6; pointer-events: none; user-select: none; z-index: 1; }
.coord-rank { top: 2px; left: 3px; }
.coord-file { bottom: 1px; right: 3px; }
.sq.light .coord { color: #9a7a4e; }
.sq.dark .coord { color: #e6d3b0; }

/* Исчезновение съеденной фигуры (взятие на проходе) */
.pc.capfade { position: absolute; z-index: 3; animation: capFade .4s ease-out forwards; pointer-events: none; }
@keyframes capFade { 0% { opacity: 1; transform: scale(1); } 100% { opacity: 0; transform: scale(.4); } }

/* Фигуры-глифы: размер от клетки (доска = min(88vw,440px)) */
/* font-variant-emoji: text — вместе с U+FE0E в глифах не даёт iOS 16.4+ показать
   пешку ♟ как эмодзи (иначе белые пешки чёрные, см. GLYPH в app.js). */
.pc { font-size: min(9.2vw, 46px); line-height: 1; z-index: 1; position: relative; filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .45)); font-variant-emoji: text; }
.pc.w { color: var(--pw);
    text-shadow: -1px -1px 0 var(--pw-edge), 1px -1px 0 var(--pw-edge), -1px 1px 0 var(--pw-edge), 1px 1px 0 var(--pw-edge), 0 -1px 0 var(--pw-edge), 0 1px 0 var(--pw-edge), -1px 0 0 var(--pw-edge), 1px 0 0 var(--pw-edge); }
.pc.b { color: var(--pb);
    text-shadow: -1px -1px 0 var(--pb-hi), 1px -1px 0 var(--pb-hi), -1px 1px 0 var(--pb-hi), 1px 1px 0 var(--pb-hi); }

.sq.sel::after { content: ''; position: absolute; inset: 0; box-shadow: inset 0 0 0 3px var(--sel), inset 0 0 14px rgba(150, 160, 90, .4); z-index: 2; }
.sq.hint::after { content: ''; position: absolute; width: 30%; height: 30%; border-radius: 50%; background: var(--hint); box-shadow: 0 0 6px rgba(120, 130, 75, .6); z-index: 2; }
.sq.hint.cap::after { width: 82%; height: 82%; background: transparent; box-shadow: inset 0 0 0 3px var(--cap); border-radius: 50%; }
/* Лучший ход (кнопка «Подсказка») */
.sq.hint-best::after {
    content: ''; position: absolute; inset: 2px; z-index: 3; border-radius: 8px;
    box-shadow: inset 0 0 0 4px #ffe27a, 0 0 18px rgba(255, 226, 122, .9);
    background: rgba(255, 226, 122, .18);
    animation: bestPulse .65s ease-in-out infinite;
}
.sq.hint-to::after {
    box-shadow: inset 0 0 0 4px #74e39a, 0 0 20px rgba(70, 220, 130, .95);
    background: rgba(70, 220, 130, .22);
}
.hint-step {
    position: absolute; top: 4px; right: 4px; z-index: 5;
    width: 22px; height: 22px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    background: #ffe27a; color: #261b0e; border: 2px solid #fff6c8;
    font-size: 12px; font-weight: 900; line-height: 1;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .55);
    pointer-events: none;
}
.hint-to .hint-step { background: #74e39a; border-color: #caffdc; }
.hint-arrow {
    position: absolute; z-index: 4; height: 6px; border-radius: 999px;
    transform-origin: 0 50%; pointer-events: none;
    background: linear-gradient(90deg, #ffe27a, #74e39a);
    box-shadow: 0 1px 5px rgba(0, 0, 0, .7), 0 0 10px rgba(116, 227, 154, .8);
    animation: arrowIn .28s ease-out both;
}
.hint-arrow::after {
    content: ''; position: absolute; right: -2px; top: 50%; transform: translateY(-50%);
    border-left: 13px solid #74e39a; border-top: 9px solid transparent; border-bottom: 9px solid transparent;
}
@keyframes arrowIn { from { opacity: 0; scale: .55 1; } to { opacity: 1; scale: 1; } }
@keyframes bestPulse { 0%,100% { opacity: .72; } 50% { opacity: 1; } }

/* --- Панель под доской --- */
.under-board { max-width: min(88vw, 454px); width: 100%; margin: 14px auto 0; display: flex; flex-direction: column; gap: 10px; }
.captured-panel {
    display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap;
    background: var(--panel); border: 1.5px solid var(--panel-border); border-radius: 14px;
    padding: 9px 14px; min-height: 44px; box-shadow: var(--panel-soft);
}
.captured-label { font-size: 12px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase; color: var(--text-dim); }
.captured { display: inline-flex; align-items: center; gap: 1px; flex-wrap: wrap; font-size: 21px; }
.cap-pc.w { color: var(--pw); text-shadow: 0 0 2px rgba(0, 0, 0, .5); }
.cap-pc.b { color: #3a3024; text-shadow: 0 0 2px rgba(255, 255, 255, .3); }
.cap-adv {
    font-size: 14px; font-weight: 800; margin-left: 6px; font-family: var(--font);
    background: linear-gradient(180deg, var(--brass-1), var(--brass-2));
    -webkit-background-clip: text; background-clip: text; color: transparent;
}

/* Часы: считают время, потраченное каждой стороной. Моноширинные цифры — чтобы
   строка не дёргалась при смене секунд. */
.clock {
    flex: none; font-size: 13px; font-weight: 700; letter-spacing: .5px;
    font-variant-numeric: tabular-nums; color: var(--text-dim);
    background: rgba(0, 0, 0, .22); border-radius: 8px; padding: 3px 8px;
}
.clock.active { color: var(--brass-1); }

/* Время игрока + лента его ходов в нотации; лента скроллится вбок. */
.movebar {
    display: flex; align-items: center; gap: 10px; min-width: 0;
    background: var(--panel); border: 1.5px solid var(--panel-border); border-radius: 12px;
    padding: 7px 10px; min-height: 40px;
}
.clock-label { font-size: 11px; color: var(--text-dim); white-space: nowrap; }
@media (max-width: 420px) { .clock-label { font-size: 10px; } }
.moves {
    display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0;
    overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
    font-size: 13px; color: var(--text-dim);
}
.moves::-webkit-scrollbar { display: none; }
.mv { flex: none; white-space: nowrap; }
.mv-no { color: rgba(255, 255, 255, .3); margin-right: 4px; }
.mv-san { font-weight: 600; color: var(--text); }
.mv.last .mv-san { color: var(--brass-1); }

.actions-row { display: flex; gap: 10px; }
.btn-panel {
    flex: 1; position: relative; padding: 12px 10px; font-size: 14px;
    background: var(--panel-2); border: 1.5px solid var(--panel-border); box-shadow: var(--panel-soft);
}
.count-badge {
    position: absolute; top: -7px; right: -6px; min-width: 20px; height: 20px; border-radius: 999px;
    background: linear-gradient(180deg, #b58f3c, #856616); color: #fff;
    font-size: 12px; font-weight: 800; display: flex; align-items: center; justify-content: center; padding: 0 5px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, .4);
}

/* Эмодзи-реакции (PvP) */
.react-row { display: flex; justify-content: center; gap: 10px; }
.react-btn {
    width: 46px; height: 46px; border-radius: 50%; font-size: 22px; cursor: pointer;
    background: var(--panel-2); border: 1.5px solid var(--panel-border); box-shadow: var(--panel-soft);
    display: flex; align-items: center; justify-content: center;
    transition: transform .07s ease;
}
.react-btn:active { transform: scale(.9); }
.react-float {
    position: fixed; left: 50%; z-index: 70; pointer-events: none;
    font-size: 54px; transform: translateX(-50%);
    filter: drop-shadow(0 4px 12px rgba(0, 0, 0, .5));
}
.react-float.mine { bottom: 20%; }
.react-float.opp { top: 16%; }
.react-float.pop { animation: reactPop 1.7s ease-out forwards; }
@keyframes reactPop {
    0% { opacity: 0; transform: translateX(-50%) scale(.4); }
    12% { opacity: 1; transform: translateX(-50%) scale(1.15); }
    22% { transform: translateX(-50%) scale(1); }
    75% { opacity: 1; }
    100% { opacity: 0; transform: translateX(-50%) translateY(-40px) scale(.9); }
}

/* --- Комната PvP --- */
.room-body { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; }
.room-illus {
    font-size: 60px; margin-bottom: 4px;
    filter: drop-shadow(0 6px 16px rgba(0, 0, 0, .4));
    animation: roomFloat 2.6s ease-in-out infinite;
}
@keyframes roomFloat { 0%,100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-8px) rotate(4deg); } }
.room-code-label { color: var(--text-dim); font-size: 13px; font-weight: 700; letter-spacing: 1.4px; text-transform: uppercase; }
.room-code {
    font-size: 44px; font-weight: 800; letter-spacing: 10px; cursor: pointer;
    background: linear-gradient(180deg, var(--brass-1), var(--brass-2));
    -webkit-background-clip: text; background-clip: text; color: transparent;
    filter: drop-shadow(0 2px 8px rgba(0, 0, 0, .4));
    border: none; font-family: var(--font); padding: 4px 12px;
    transition: transform .07s ease;
}
.room-code:active { transform: scale(.96); }
.room-hint { color: var(--text-dim); font-size: 12.5px; margin-top: -6px; }
.room-status { color: var(--text-dim); font-size: 14px; display: flex; align-items: center; gap: 9px; margin-top: 4px; }
.room-spinner {
    width: 15px; height: 15px; border-radius: 50%;
    border: 2px solid rgba(184, 152, 100, .3); border-top-color: var(--brass-1);
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.room-body .btn-primary { min-width: 240px; }

/* Кнопки шеринга на финальном оверлее */
.share-row { display: flex; gap: 10px; }
.share-row .btn { flex: 1; padding: 12px 10px; font-size: 15px; }

/* --- Оверлеи --- */
.overlay { position: fixed; inset: 0; background: rgba(10, 7, 4, .72); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.overlay-card {
    background: linear-gradient(170deg, rgba(66, 50, 34, .97), rgba(28, 20, 12, .98));
    border: 1.5px solid var(--panel-border);
    border-radius: 22px; padding: 28px 24px; width: 100%; max-width: 330px; text-align: center;
    display: flex; flex-direction: column; gap: 12px;
    box-shadow: 0 18px 60px rgba(0, 0, 0, .6);
}
.overlay-emoji { font-size: 56px; filter: drop-shadow(0 4px 10px rgba(0, 0, 0, .4)); }
.overlay-title {
    font-size: 26px; font-weight: 800; margin-bottom: 6px;
    background: linear-gradient(180deg, var(--brass-1), var(--brass-2));
    -webkit-background-clip: text; background-clip: text; color: transparent;
}
.overlay-score { font-size: 14px; color: var(--text-dim); font-weight: 700; margin-top: -6px; }

/* Кнопка «Сдаться» в PvP */
.resign-btn {
    align-self: center; margin-top: 4px; padding: 8px 20px; cursor: pointer;
    background: none; border: 1px solid var(--panel-border); border-radius: 999px;
    color: var(--text-dim); font-family: var(--font); font-size: 13px; font-weight: 700;
}
.resign-btn:active { transform: scale(.97); }

.promo-row { display: flex; justify-content: center; gap: 10px; }
.promo-btn {
    width: 60px; height: 60px; border-radius: 14px; cursor: pointer;
    border: 1.5px solid var(--panel-border); background: var(--panel-2); color: var(--pw);
    font-size: 34px; line-height: 1; display: flex; align-items: center; justify-content: center;
    box-shadow: var(--panel-soft); font-variant-emoji: text;
    text-shadow: -1px -1px 0 var(--pw-edge), 1px -1px 0 var(--pw-edge), -1px 1px 0 var(--pw-edge), 1px 1px 0 var(--pw-edge);
}
.promo-btn:active { transform: scale(.96); }

.rules-card { text-align: left; max-width: 360px; }
.rules-card .overlay-title { text-align: center; }
.rules-list { margin: 4px 0; padding-left: 20px; display: flex; flex-direction: column; gap: 10px; color: var(--text-dim); font-size: 14px; line-height: 1.4; }

/* --- Toast --- */
.toast {
    position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
    background: rgba(30, 22, 14, .96); color: var(--text);
    border: 1px solid var(--panel-border);
    padding: 10px 18px; border-radius: 999px; font-weight: 600; font-size: 14px; z-index: 60;
    box-shadow: 0 4px 16px rgba(0, 0, 0, .5);
}

/* ================= Невысокий фрейм: компактное меню =================
   VK-фрейм часто ниже 700px, а полное меню занимает ~800px — «Цвет фигур» уезжал
   за нижний край, и его нельзя было выбрать. Ужимаем отступы и заголовок, чтобы
   меню помещалось целиком. Состав элементов и логика не меняются. */
@media (max-height: 800px) {
    .screen { padding: max(10px, env(safe-area-inset-top)) 16px max(10px, env(safe-area-inset-bottom)); }
    #screen-menu { gap: 4px; }
    .menu-title { font-size: 32px; }
    .menu-subtitle { margin: -2px 0 8px; }
    .menu-actions { gap: 8px; }
    .mode-card { padding: 10px 14px; }
    .mode-icon { width: 44px; height: 44px; }
    .difficulty { margin-top: 10px; }
    .difficulty-label { margin-bottom: 6px; }
    .level-list { gap: 6px; }
    .level-item { padding: 6px 14px; }
    .rules-link { margin-top: 10px; }
}
/* Совсем низкий фрейм — прячем декоративный подзаголовок. */
@media (max-height: 650px) {
    .menu-title { font-size: 26px; }
    .menu-subtitle { display: none; }
    .mode-icon { width: 38px; height: 38px; }
    .mode-glyph { font-size: 24px; }
    .level-item { padding: 5px 12px; }
}
/* Экстремально низкий фрейм (ландшафт телефона, узкое окно VK). */
@media (max-height: 560px) {
    .menu-title { font-size: 22px; }
    .mode-card { padding: 8px 12px; }
    .mode-icon { width: 34px; height: 34px; }
    .mode-glyph { font-size: 20px; }
    .level-item { padding: 4px 12px; }
    .difficulty { margin-top: 8px; }
    .rules-link { margin-top: 6px; }
}

/* ================= Десктоп: раскладка в три колонки =================
   VK на десктопе даёт широкий, но НЕВЫСОКИЙ фрейм: вертикальная мобильная колонка
   в него не помещается и низ обрезался. Раскладываем как настольный клиент:
   слева соперник, по центру доска, справа взятые + часы/нотация + управление.
   Брейкпоинт 900: реальный VK-фрейм на десктопе ~993px, при пороге 1024 он не
   попадал в эту раскладку и получал мобильную колонку. Доска ужимается по 44vw,
   поэтому три колонки помещаются и на 900. Мобильная раскладка не трогается. */
@media (min-width: 900px) {
    #screen-game {
        display: grid;
        grid-template-columns: minmax(200px, 280px) auto minmax(200px, 300px);
        grid-template-rows: auto 1fr;
        grid-template-areas:
            "header header header"
            "left   board  right";
        align-content: center; justify-content: center;
        column-gap: 32px; row-gap: 18px;
        max-width: 1180px; margin: 0 auto; width: 100%;
    }
    #screen-game > .game-header { grid-area: header; }

    #screen-game > .opp-bar {
        grid-area: left; align-self: start; margin: 0; max-width: none;
        gap: 8px; padding: 8px 10px;
    }
    #screen-game > .opp-bar .opp-ava { width: 36px; height: 36px; font-size: 20px; }
    #screen-game > .opp-bar .opp-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    #screen-game > .opp-bar .clock { padding: 3px 6px; }
    #screen-game > .opp-bar .turn-dot { width: 8px; height: 8px; }

    #screen-game > .board-wrap { grid-area: board; align-self: center; }
    /* Панели ушли вбок — вертикальный запас больше не нужен, ограничиваем доску
       высотой фрейма и шириной центральной колонки. */
    #screen-game > .board-wrap .board { width: min(66vh, 44vw, 560px); }

    #screen-game > .under-board {
        grid-area: right; align-self: start; margin: 0; max-width: none;
    }
    #screen-game > .under-board .actions-row { flex-direction: column; }
}

/* ================= Product pass: daily challenge, tutorial and result ================= */
.daily-card {
    width: 100%; max-width: 380px; min-height: 64px; margin-bottom: 4px; padding: 10px 14px;
    display: flex; align-items: center; gap: 12px; cursor: pointer; text-align: left;
    color: var(--text); font-family: var(--font); border: 1.5px solid rgba(200, 165, 90, .55);
    border-radius: 16px; background: linear-gradient(155deg, rgba(102, 74, 32, .65), rgba(48, 38, 27, .72));
    box-shadow: var(--panel-soft); transition: transform .08s ease, border-color .15s ease;
}
.daily-card:active { transform: scale(.985); }
.daily-card.done { border-color: rgba(91, 153, 105, .7); background: linear-gradient(155deg, rgba(48, 93, 60, .62), rgba(45, 37, 27, .72)); }
.daily-icon, .mode-icon {
    flex: none; width: 44px; height: 44px; border-radius: 12px;
    background: rgba(20, 14, 8, .48); border: 1px solid var(--panel-border); display: grid; place-items: center;
}
.mode-icon { width: 52px; height: 52px; border-radius: 14px; }
.daily-icon svg, .mode-icon svg { width: 25px; height: 25px; fill: none; stroke: var(--brass-1); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.daily-copy { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.daily-copy b { font-size: 15px; font-weight: 800; }
.daily-copy i { font-size: 12px; font-style: normal; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.streak-chip { min-width: 48px; height: 34px; padding: 0 9px; border-radius: 11px; display: flex; align-items: center; justify-content: center; gap: 3px; background: rgba(15, 10, 6, .48); color: var(--brass-1); font-variant-numeric: tabular-nums; }
.streak-chip b { font-size: 17px; }
.menu-links { display: flex; gap: 22px; }
.menu-links .rules-link { min-height: 44px; margin-top: 8px; padding: 8px 2px; }
.icon-btn { width: 44px; height: 44px; }
.icon-btn svg, .button-icon, .opp-ava svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.button-icon { flex: none; width: 20px; height: 20px; }
#sound-btn .sound-off { display: none; }
#sound-btn.muted .sound-on { display: none; }
#sound-btn.muted .sound-off { display: block; }
.opp-ava svg { color: var(--brass-1); }
.lesson-banner {
    width: 100%; max-width: min(88vw, 454px); margin: 0 auto 10px; min-height: 48px;
    display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 14px;
    border: 1.5px solid rgba(200, 165, 90, .62); background: rgba(55, 42, 28, .94);
    color: var(--text); font-size: 13px; font-weight: 700; box-shadow: var(--panel-soft);
}
.lesson-step { flex: none; min-width: 38px; height: 28px; display: grid; place-items: center; border-radius: 9px; background: var(--brass-2); color: #1d140b; font-size: 12px; font-weight: 900; }
.result-mark { width: 58px; height: 58px; margin: 0 auto; display: grid; place-items: center; color: var(--brass-1); }
.result-mark svg { width: 56px; height: 56px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; filter: drop-shadow(0 4px 10px rgba(0, 0, 0, .4)); }
.result-mark.lose { color: #c8b7a1; transform: rotate(180deg); }
.result-mark.draw { color: #9ec5e8; transform: rotate(90deg); }
.result-stats { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--panel-border); border-radius: 14px; overflow: hidden; background: rgba(15, 10, 6, .25); }
.result-stats > div { padding: 9px 5px; display: flex; flex-direction: column; gap: 1px; }
.result-stats > div + div { border-left: 1px solid var(--panel-border); }
.result-stats b { color: var(--brass-1); font-size: 18px; font-variant-numeric: tabular-nums; }
.result-stats span { color: var(--text-dim); font-size: 10px; letter-spacing: .5px; text-transform: uppercase; }
.next-goal { display: flex; flex-direction: column; gap: 4px; text-align: left; padding: 10px 12px; border-radius: 12px; background: rgba(15, 10, 6, .25); }
.next-goal > span { color: var(--text-dim); font-size: 10px; letter-spacing: .6px; text-transform: uppercase; }
.next-goal > b { font-size: 13px; }
.goal-track { height: 5px; border-radius: 5px; overflow: hidden; background: rgba(255,255,255,.1); }
.goal-track i { display: block; height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, var(--green-1), var(--brass-1)); transition: width .35s ease; }
.onboarding-card p { color: var(--text-dim); font-size: 14px; line-height: 1.5; }
.onboarding-board { width: 88px; height: 88px; margin: 0 auto; display: grid; grid-template-columns: repeat(2,1fr); border: 5px solid #4d3826; border-radius: 12px; overflow: hidden; transform: rotate(-4deg); box-shadow: 0 10px 24px rgba(0,0,0,.4); }
.onboarding-board span:nth-child(1), .onboarding-board span:nth-child(4) { background: var(--sq-light); }
.onboarding-board span:nth-child(2), .onboarding-board span:nth-child(3) { background: var(--sq-dark); }

@media (min-width: 900px) {
    #screen-game > .lesson-banner { position: fixed; top: max(72px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 15; max-width: 430px; }
}
@media (max-width: 420px) {
    .daily-card { min-height: 58px; padding: 8px 11px; }
    .daily-icon { width: 40px; height: 40px; }
    .overlay { align-items: safe center; overflow-y: auto; padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom)); }
    .overlay-card { padding: 20px 17px; max-height: calc(100dvh - 24px); overflow-y: auto; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
button:focus-visible, .sq:focus-visible { outline: 3px solid #8fc6ff; outline-offset: 3px; }
