/* Цвета — из темы Telegram (переменные --tg-theme-* ставит telegram-web-app.js), с запасными значениями */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f1f3f6);
  --text: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --link: var(--tg-theme-link-color, #2481cc);
  --btn: var(--tg-theme-button-color, #2481cc);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #e5484d);
  --sq-light: #eeeed2;
  --sq-dark: #769656;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: var(--tg-theme-bg-color, #17212b);
    --bg2: var(--tg-theme-secondary-bg-color, #232e3c);
    --text: var(--tg-theme-text-color, #f5f5f5);
    --hint: var(--tg-theme-hint-color, #7d8b99);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
body { min-height: 100vh; overscroll-behavior: none; }
a { color: var(--link); text-decoration: none; cursor: pointer; }
button { font: inherit; color: inherit; border: 0; cursor: pointer; }

.screen { max-width: 520px; margin: 0 auto; padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); }
.screen.center { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 90vh; text-align: center; gap: 10px; }
.screen.text p { color: var(--text); }
h1 { font-size: 26px; margin: 4px 0 18px; text-align: center; }
h2 { font-size: 21px; margin: 6px 0 14px; }
h3 { font-size: 14px; text-transform: uppercase; letter-spacing: .04em; color: var(--hint); margin: 18px 0 8px; font-weight: 600; }
.muted { color: var(--hint); }
.logo { font-size: 72px; text-align: center; line-height: 1; margin-top: 18px; }
.logo.small { font-size: 52px; }
.pulse { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.12); opacity: .7; } }

.home .menu { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.home .muted { text-align: center; min-height: 1.4em; }
.links { text-align: center; margin-top: 18px; font-size: 14px; }

button.big { display: block; width: 100%; padding: 15px 16px; border-radius: var(--radius); background: var(--bg2);
  font-size: 17px; font-weight: 600; text-align: center; margin: 6px 0; transition: transform .08s; }
button.big:active { transform: scale(.98); }
button.big.primary { background: var(--btn); color: var(--btn-text); margin-top: 22px; }
.home button.big { background: var(--btn); color: var(--btn-text); }
.home button.big.secondary { background: var(--bg2); color: var(--text); }
button.link { background: none; color: var(--link); padding: 12px; }
.banner { display: block; width: 100%; padding: 12px 14px; margin: 0 0 12px; border-radius: var(--radius);
  background: color-mix(in srgb, var(--btn) 15%, var(--bg)); color: var(--text); text-align: center; }

.opts { display: flex; flex-wrap: wrap; gap: 8px; }
.opts.col { flex-direction: column; }
.opt { padding: 11px 14px; border-radius: 10px; background: var(--bg2); flex: 1 1 auto; text-align: left; }
.opts:not(.col) .opt { text-align: center; }
.opt.on { background: var(--btn); color: var(--btn-text); }

/* партия */
.screen.game { padding-top: 8px; }
.pbar { display: flex; align-items: center; justify-content: space-between; padding: 6px 2px; gap: 8px; }
.pbar .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clock { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 18px; padding: 4px 10px; border-radius: 8px;
  background: var(--bg2); min-width: 64px; text-align: center; }
.clock:empty { display: none; }
.clock.run { background: var(--btn); color: var(--btn-text); }
.clock.run.low { background: var(--danger); color: #fff; }
.board-wrap { position: relative; width: 100%; aspect-ratio: 1; touch-action: none; }
#board { width: 100%; height: 100%; }
.cm-chessboard.default .board .square.white { fill: var(--sq-light); }
.cm-chessboard.default .board .square.black { fill: var(--sq-dark); }
.cm-chessboard.default .coordinates .coordinate.black { fill: var(--sq-light); }
.cm-chessboard.default .coordinates .coordinate.white { fill: var(--sq-dark); }
.status { text-align: center; min-height: 1.5em; margin: 8px 0 4px; color: var(--hint); }
.status.mine { color: var(--text); font-weight: 600; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; align-items: center; margin-top: 8px; }
.actions button { padding: 10px 12px; border-radius: 10px; background: var(--bg2); font-size: 15px; flex: 1 1 40%; }
.actions .muted { flex: 0 0 auto; }
.reactions { display: flex; justify-content: center; gap: 10px; margin-top: 10px; }
.reactions button { font-size: 24px; background: var(--bg2); border-radius: 50%; width: 46px; height: 46px; }
.offer { display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap; padding: 8px;
  border-radius: 10px; background: var(--bg2); margin: 6px 0; }
.offer button { padding: 7px 12px; border-radius: 8px; background: var(--btn); color: var(--btn-text); }
.offer button + button { background: var(--bg); color: var(--text); }
#react-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.react { position: absolute; font-size: 54px; left: 50%; animation: floatup 2.2s ease-out forwards; }
.react.theirs { top: 10%; }
.react.mine { bottom: 10%; }
@keyframes floatup { 0% { transform: translate(-50%, 20px) scale(.6); opacity: 0; }
  15% { transform: translate(-50%, 0) scale(1.1); opacity: 1; } 100% { transform: translate(-50%, -60px) scale(1); opacity: 0; } }

/* окна поверх */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: flex; align-items: center; justify-content: center;
  padding: 16px; z-index: 50; animation: fade .2s; }
.modal .card { background: var(--bg); color: var(--text); border-radius: 18px; padding: 20px 18px; width: 100%; max-width: 400px; text-align: center; }
.modal .card h2 { margin-top: 0; }
.modal .card button.big.primary { margin-top: 12px; }
.card.result.win h2 { color: #2fa84f; }
@keyframes fade { from { opacity: 0; } }

/* мои партии */
.row { display: flex; width: 100%; align-items: center; gap: 12px; padding: 12px; border-radius: var(--radius);
  background: var(--bg2); margin-bottom: 8px; text-align: left; }
.row .ic { font-size: 22px; width: 28px; text-align: center; }
.row .grow { flex: 1; min-width: 0; }
.row .side { width: 14px; height: 14px; border-radius: 50%; border: 1px solid var(--hint); }
.row .side.w { background: #fff; }
.row .side.b { background: #222; }

.spinner { width: 36px; height: 36px; border: 3px solid var(--bg2); border-top-color: var(--btn); border-radius: 50%;
  animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

#toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: rgba(30, 30, 30, .92); color: #fff; padding: 10px 16px; border-radius: 12px; opacity: 0; transition: .25s;
  pointer-events: none; z-index: 100; max-width: 90vw; text-align: center; font-size: 15px; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#offline-bar { display: none; position: fixed; top: 0; left: 0; right: 0; background: var(--danger); color: #fff;
  text-align: center; font-size: 13px; padding: 3px; z-index: 90; }
body.offline #offline-bar { display: block; }
