/* Клетки — Telegram Mini App. Мобильный first, тёмная база, поле со своим контрастным арт-стилем. */
:root {
  --bg: var(--tg-theme-bg-color, #14151a);
  --bg2: var(--tg-theme-secondary-bg-color, #1c1e26);
  --text: var(--tg-theme-text-color, #f2f3f7);
  --hint: var(--tg-theme-hint-color, #8b8f9a);
  --accent: var(--tg-theme-button-color, #4c8bf5);
  --accent-text: var(--tg-theme-button-text-color, #fff);
  --danger: #e5484d;
  --ok: #46b96a;
  --panel: #22242e;
  --line: rgba(255,255,255,.08);
  --cell: #2a2d39;
  --cell-lit: #343849;
  --black-p: radial-gradient(circle at 34% 30%, #4a4d5e, #17181f 72%);
  --white-p: radial-gradient(circle at 34% 30%, #ffffff, #c7cad6 78%);
  --radius: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; max-width: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  position: fixed; inset: 0;
  overflow: hidden;
  overscroll-behavior: none;
  user-select: none;
}
#app { height: 100%; position: relative; overflow: hidden; width: 100%; }

/* ── Экраны ── */
.screen {
  position: absolute; inset: 0;
  display: none; flex-direction: column; align-items: center;
  padding: max(16px, env(safe-area-inset-top)) 14px calc(16px + env(safe-area-inset-bottom));
  animation: fade .25s ease;
  overflow-y: auto;
}
.screen.active { display: flex; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ── Меню ── */
.logo { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; width: 72px; height: 72px; margin: 8vh auto 0; }
.logo-cell { border-radius: 8px; }
.logo-cell.b { background: var(--black-p); }
.logo-cell.w { background: var(--white-p); }
.title { font-size: 40px; font-weight: 800; letter-spacing: .5px; margin: 18px 0 4px; }
.subtitle { color: var(--hint); margin: 0 0 22px; font-size: 15px; text-align: center; }

.online { display: inline-flex; align-items: center; gap: 7px; color: var(--hint); font-size: 13px; margin-bottom: 14px; }
.online-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 7px var(--ok); animation: blink 2s infinite; }
.online b { color: var(--text); font-weight: 700; }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

.rating-pill { background: var(--panel); border-radius: 20px; padding: 8px 20px; font-size: 15px; color: var(--hint); margin-bottom: 16px; }
.rating-pill b { color: var(--accent); font-size: 20px; font-weight: 800; }

.stats-row { display: flex; gap: 10px; margin-bottom: 22px; width: 100%; max-width: 300px; }
.stat { background: var(--panel); border-radius: 14px; padding: 12px 14px; min-width: 62px; text-align: center; flex: 1; }
.stat b { display: block; font-size: 22px; font-weight: 800; }
.stat span { font-size: 12px; color: var(--hint); }

.menu-buttons { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 360px; }

.btn {
  appearance: none; border: none; border-radius: 14px;
  padding: 16px; font-size: 17px; font-weight: 600;
  background: var(--panel); color: var(--text);
  cursor: pointer; transition: transform .08s ease, filter .15s ease, opacity .15s;
}
.btn:active { transform: scale(.97); filter: brightness(1.15); }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-ghost { background: transparent; border: 1px solid var(--line); color: var(--hint); }
.btn-danger { background: transparent; border: 1px solid var(--danger); color: var(--danger); }
.btn-sm { padding: 10px 16px; font-size: 15px; }
.btn:disabled { opacity: .5; pointer-events: none; }

.screen-title { font-size: 24px; font-weight: 800; margin: 8vh 0 6px; text-align: center; }
.hint { color: var(--hint); font-size: 14px; text-align: center; margin: 0 0 20px; line-height: 1.45; }
.back { position: absolute; top: max(16px, env(safe-area-inset-top)); left: 14px; background: none; border: none; color: var(--accent); font-size: 16px; padding: 8px; cursor: pointer; }

/* ── Поиск ── */
.search-anim { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; width: 84px; height: 84px; margin: 16vh auto 24px; }
.search-anim span { border-radius: 10px; background: var(--panel); animation: pulse 1.2s infinite ease-in-out; }
.search-anim span:nth-child(1){ animation-delay: 0s; background: var(--black-p);}
.search-anim span:nth-child(2){ animation-delay: .15s; background: var(--white-p);}
.search-anim span:nth-child(3){ animation-delay: .45s; background: var(--white-p);}
.search-anim span:nth-child(4){ animation-delay: .3s; background: var(--black-p);}
@keyframes pulse { 0%,100%{ transform: scale(.8); opacity:.5;} 50%{ transform: scale(1); opacity:1;} }

/* ── Скоребар ── */
.scorebar { display: flex; align-items: center; justify-content: space-between; width: 100%; max-width: 440px; margin: 6px auto 8px; gap: 8px; }
.side { display: flex; align-items: center; gap: 8px; background: var(--panel); border-radius: 12px; padding: 8px 12px; flex: 1; transition: box-shadow .2s, transform .2s; }
.side-white { flex-direction: row; justify-content: flex-end; }
.side.turn { box-shadow: 0 0 0 2px var(--accent); }
.dot { width: 20px; height: 20px; border-radius: 50%; flex: none; }
.dot-black { background: var(--black-p); }
.dot-white { background: var(--white-p); }
.side-name { font-size: 13px; color: var(--hint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 88px; }
.side-score { font-size: 22px; font-weight: 800; min-width: 26px; text-align: center; }
.vs { font-size: 11px; color: var(--hint); text-transform: uppercase; letter-spacing: 1px; }

.turn-timer { width: 100%; max-width: 440px; height: 3px; background: var(--line); border-radius: 3px; overflow: hidden; margin: 0 auto 12px; }
.turn-timer i { display: block; height: 100%; width: 100%; background: var(--accent); transform-origin: left; }
.turn-timer i.run { transition: transform linear; transform: scaleX(0); }

/* ── Поле ── */
.board-wrap { position: relative; width: 100%; max-width: min(440px, calc(100dvh - 210px)); margin: 0 auto; }
.board {
  display: grid; gap: 4px; width: 100%; aspect-ratio: 1 / 1;
  background: var(--bg2); padding: 6px; border-radius: 14px;
}
.tile {
  position: relative; background: var(--cell); border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
}
.tile.movable { cursor: pointer; }
.tile.target { background: var(--cell-lit); cursor: pointer; }
.tile.target::after { content: ""; width: 42%; height: 42%; border-radius: 50%; opacity: .6; transition: transform .12s; }
.tile.target.for-black::after { background: var(--black-p); }
.tile.target.for-white::after { background: var(--white-p); }
/* Прыжок-захват (ход на 2 клетки через врага) — заметный красный ореол + пульс */
.tile.capture { box-shadow: 0 0 0 2px var(--danger) inset; }
.tile.capture::after { width: 54%; height: 54%; opacity: .9; box-shadow: 0 0 0 3px rgba(229,72,77,.55); animation: pulseT 1s infinite ease-in-out; }
@keyframes pulseT { 0%,100% { transform: scale(.86); } 50% { transform: scale(1.06); } }
.tile.lastfrom { outline: 2px dashed rgba(255,255,255,.18); outline-offset: -3px; }
.tile.lastto { box-shadow: 0 0 0 2px var(--accent) inset; }

.piece {
  width: 82%; height: 82%; border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0,0,0,.35);
  transition: background .28s ease, transform .18s ease;
  animation: pop .22s ease;
}
@keyframes pop { from { transform: scale(.2); } to { transform: scale(1); } }
.piece.black { background: var(--black-p); }
.piece.white { background: var(--white-p); }
.tile.selected { background: var(--cell-lit); }
.tile.selected .piece { transform: scale(1.06); box-shadow: 0 0 0 3px var(--accent), 0 2px 6px rgba(0,0,0,.4); }
.piece.flip { animation: flip .34s ease; }
@keyframes flip { 0%{ transform: rotateY(0);} 50%{ transform: rotateY(90deg) scale(.9);} 100%{ transform: rotateY(0);} }

.board-msg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.55); border-radius: 14px; font-size: 15px; text-align: center; padding: 20px; }

.game-actions { display: flex; align-items: center; justify-content: space-between; width: 100%; max-width: 440px; margin: 16px auto 0; gap: 8px; flex-wrap: wrap; }
.you-are { font-size: 13px; color: var(--hint); }
#q-controls { display: flex; gap: 8px; }

/* ── Переключатель игр в меню ── */
.game-tabs { display: flex; gap: 6px; margin-bottom: 14px; background: var(--panel); padding: 4px; border-radius: 14px; }
.gtab { appearance: none; border: none; background: transparent; color: var(--hint); font-size: 14px; font-weight: 600; padding: 8px 16px; border-radius: 10px; cursor: pointer; transition: background .15s; }
.gtab.active { background: var(--accent); color: var(--accent-text); }

/* ── Коридор: поле 9×9 с жёлобами под стенки ── */
.dot-red { background: radial-gradient(circle at 34% 30%, #ff7a6b, #b02a1c 75%); }
.dot-yellow { background: radial-gradient(circle at 34% 30%, #ffe083, #d9a521 78%); }
.qboard {
  display: grid; width: 100%; aspect-ratio: 1 / 1; background: var(--bg2); padding: 2.5%; border-radius: 14px;
  grid-template-columns: repeat(8, 1fr 0.32fr) 1fr;
  grid-template-rows: repeat(8, 1fr 0.32fr) 1fr;
  touch-action: none; /* чтобы протяжка стенки не скроллила страницу */
}
.qcell { background: var(--cell); border-radius: 5px; display: flex; align-items: center; justify-content: center; position: relative; }
.qcell.goal { box-shadow: inset 0 0 0 2px rgba(76,139,245,.22); }
.qcell.target { background: var(--cell-lit); cursor: pointer; }
.qcell.target::after { content: ""; width: 42%; height: 42%; border-radius: 50%; background: var(--accent); opacity: .55; }
.qcell.lastto { box-shadow: 0 0 0 2px var(--accent) inset; }
.qpawn { width: 76%; height: 76%; border-radius: 50%; box-shadow: 0 2px 4px rgba(0,0,0,.4); animation: pop .2s ease; }
.qpawn.p0 { background: var(--black-p); }
.qpawn.p1 { background: var(--white-p); }
.qpawn.me { box-shadow: 0 0 0 3px var(--accent), 0 2px 5px rgba(0,0,0,.45); }
.qwall { border-radius: 3px; width: 100%; height: 100%; z-index: 2; animation: pop .18s ease; }
.qwall.p0 { background: linear-gradient(#4a4d5e, #15161c); box-shadow: 0 0 0 1px rgba(255,255,255,.28), 0 1px 3px rgba(0,0,0,.6); }
.qwall.p1 { background: linear-gradient(#ffffff, #cdd0da); box-shadow: 0 1px 3px rgba(0,0,0,.5); }
.qhint { font-size: 12px; color: var(--hint); }
#q-confirm { display: flex; gap: 8px; }
.qslot { background: rgba(255,255,255,.06); border-radius: 2px; width: 100%; height: 100%; z-index: 3; cursor: pointer; transition: background .1s; }
.qslot:hover { background: rgba(76,139,245,.45); }
.qwall.preview { opacity: .62; outline: 2px dashed var(--accent); outline-offset: -1px; z-index: 4; }
.qghost { border-radius: 3px; width: 100%; height: 100%; background: rgba(244,201,78,.16); cursor: pointer; z-index: 3; transition: background .1s; }
.qghost:active, .qghost.hot { background: rgba(244,201,78,.55); }

/* ── Лидерборд ── */
.top-list { list-style: none; padding: 0; margin: 0; width: 100%; max-width: 420px; }
.top-list li { display: flex; align-items: center; gap: 12px; background: var(--panel); border-radius: 12px; padding: 12px 14px; margin-bottom: 8px; }
.top-list .rank { font-weight: 800; width: 28px; text-align: center; font-size: 16px; }
.top-list .pname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-list .pw { font-weight: 800; color: var(--ok); }
.top-list .pw small { color: var(--hint); font-weight: 500; margin-left: 2px; }
.top-list li.me { box-shadow: 0 0 0 1.5px var(--accent); }
.top-list li.top-sep { background: transparent; justify-content: center; color: var(--hint); letter-spacing: 5px; padding: 2px 0; margin-bottom: 4px; }
.top-list li.clickable { cursor: pointer; }
.top-list li.clickable:active { filter: brightness(1.15); transform: scale(.99); }
.odot { width: 9px; height: 9px; border-radius: 50%; background: var(--hint); flex: none; opacity: .45; }
.odot.on { background: var(--ok); box-shadow: 0 0 6px var(--ok); opacity: 1; }
.top-list .call { background: var(--accent); color: var(--accent-text); font-size: 13px; font-weight: 700; padding: 6px 12px; border-radius: 10px; flex: none; }
.me-rank { margin-top: 14px; color: var(--hint); font-size: 14px; text-align: center; }

/* ── Оверлеи ── */
.overlay { position: absolute; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; padding: 24px; z-index: 20; animation: fade .2s; backdrop-filter: blur(2px); }
.modal { background: var(--bg2); border-radius: 20px; padding: 28px 22px; width: 100%; max-width: 360px; text-align: center; }
.modal-emoji { font-size: 54px; line-height: 1; margin-bottom: 8px; }
.modal h2 { margin: 6px 0 6px; font-size: 24px; }
.ov-score { font-size: 30px; font-weight: 800; margin: 6px 0 4px; }
.ov-rating { font-size: 16px; font-weight: 700; margin: 2px 0 6px; }
.ov-rating.up { color: var(--ok); }
.ov-rating.down { color: var(--danger); }
.modal .menu-buttons { margin-top: 18px; }
.modal-rules { text-align: left; max-width: 400px; }
.rules { padding-left: 20px; margin: 8px 0 18px; line-height: 1.5; font-size: 15px; color: var(--text); }
.rules li { margin-bottom: 8px; }
.rules b { color: var(--accent); }

/* ── Мелочи ── */
.hidden { display: none !important; }
.toast { position: absolute; bottom: calc(20px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); background: rgba(0,0,0,.85); color: #fff; padding: 10px 18px; border-radius: 20px; font-size: 14px; z-index: 30; animation: fade .2s; max-width: 86%; text-align: center; }
.conn { position: absolute; top: max(10px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); background: var(--danger); color: #fff; padding: 5px 14px; border-radius: 14px; font-size: 12px; z-index: 30; }
