:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f1f1f4);
  --text: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #8a8a8f);
  --accent: var(--tg-theme-button-color, #2481cc);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #e53935);
  --light: #f0d9b5;
  --dark: #b58863;
  --size: min(calc(100vw - 16px), 480px);
  --sq: calc(var(--size) / 8);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
#app { max-width: 520px; margin: 0 auto; padding: 8px 8px 24px; }
[hidden] { display: none !important; }
h1 { margin: 0; font-size: 22px; }
.hint { color: var(--hint); font-size: 13px; }

button {
  font: inherit; border: 0; border-radius: 10px; padding: 10px 14px; cursor: pointer;
  background: var(--accent); color: var(--accent-text); font-weight: 600;
}
button.secondary { background: var(--bg2); color: var(--text); }
button.danger { background: var(--bg2); color: var(--danger); }
button:disabled { opacity: .5; cursor: default; }

/* ---------- лобби ---------- */
.lobby-head { display: flex; gap: 12px; align-items: center; padding: 8px 4px 16px; }
.logo { width: 52px; height: 52px; border-radius: 14px; background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center; font-size: 32px; }
.card { background: var(--bg2); border-radius: 14px; padding: 14px; margin-bottom: 12px; }
.card-title { font-weight: 700; margin-bottom: 4px; }
.color-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.color-btn { display: flex; flex-direction: column; align-items: center; gap: 2px; background: var(--bg); color: var(--text); padding: 12px 6px; }
.color-btn .piece { font-size: 30px; line-height: 1; }
.color-btn .piece.r { font-weight: 800; color: var(--accent); }

.games-list { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.game-item { display: flex; justify-content: space-between; align-items: center; gap: 8px; text-align: left;
  background: var(--bg); color: var(--text); font-weight: 500; }
.game-item .sub { color: var(--hint); font-size: 13px; font-weight: 400; }
.badge { font-size: 12px; padding: 3px 8px; border-radius: 99px; background: var(--bg2); color: var(--hint); white-space: nowrap; }
.badge.turn { background: var(--accent); color: var(--accent-text); }

.author { display: block; text-align: center; color: var(--hint); font-size: 13px; padding: 8px 0 4px; text-decoration: none; }
.author[href] b { color: var(--accent); }

/* ---------- доска ---------- */
.board-wrap { position: relative; display: flex; justify-content: center; }
.board { width: var(--size); height: var(--size); display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr)); grid-template-rows: repeat(8, minmax(0, 1fr));
  border-radius: 6px; overflow: hidden; box-shadow: 0 2px 10px rgba(0,0,0,.18); user-select: none; }
.sq { position: relative; display: grid; place-items: center; min-width: 0; min-height: 0; overflow: hidden; }
.sq.light { background: var(--light); }
.sq.dark { background: var(--dark); }
.sq.last::before { content: ""; position: absolute; inset: 0; background: rgba(255, 213, 0, .38); }
.sq.selected::before { content: ""; position: absolute; inset: 0; background: rgba(20, 120, 255, .38); }
.sq.check::before { content: ""; position: absolute; inset: 0;
  background: radial-gradient(circle, rgba(255,0,0,.85) 0%, rgba(255,0,0,.35) 55%, transparent 75%); }
.sq.target::after { content: ""; position: absolute; width: 30%; height: 30%; border-radius: 50%; background: rgba(0,0,0,.22); }
.sq.capture::after { content: ""; position: absolute; inset: 4%; border-radius: 50%; border: calc(var(--sq) * .08) solid rgba(0,0,0,.22); }

.piece { position: relative; z-index: 1; font-size: calc(var(--sq) * .8); line-height: 1;
  font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", "DejaVu Sans", "Arial Unicode MS", serif; }
.piece.w { color: #fff; text-shadow: 0 0 1px #000, 0 0 1px #000, 0 1px 2px rgba(0,0,0,.6); }
.piece.b { color: #1b1b1b; text-shadow: 0 1px 1px rgba(255,255,255,.25); }

.coord { position: absolute; font-size: calc(var(--sq) * .2); font-weight: 700; z-index: 2; pointer-events: none; }
.coord.rank { top: 2px; left: 3px; }
.coord.file { bottom: 1px; right: 3px; }
.sq.light .coord { color: var(--dark); }
.sq.dark .coord { color: var(--light); }

/* Котёнок сидит на верхнем краю доски (виден только избранным) */
.kitten-box {
  position: absolute; z-index: 3; pointer-events: none;
  right: calc((100% - var(--size)) / 2 + 10px); bottom: calc(100% - 5px);
}
.kitten {
  display: block; height: 72px;
  filter: drop-shadow(0 3px 4px rgba(0,0,0,.35));
  transform-origin: bottom center; animation: kitten-breathe 3.2s ease-in-out infinite;
}
@keyframes kitten-breathe { 50% { transform: scale(1.035) translateY(-1px); } }

/* Облачко как в комиксе */
.bubble {
  position: absolute; right: calc(100% + 10px); top: -14px; white-space: nowrap;
  background: #fff; color: #111; border: 2.5px solid #111; border-radius: 18px;
  padding: 6px 12px; box-shadow: 3px 3px 0 #111;
  font: 900 14px/1.1 "Comic Sans MS", "Chalkboard SE", "Comic Neue", "Marker Felt", sans-serif;
  text-transform: uppercase; letter-spacing: .02em;
  transform: rotate(-4deg); transform-origin: right bottom;
  animation: bubble-pop .45s cubic-bezier(.2, 1.6, .4, 1) both, bubble-shake 4s ease-in-out 1s infinite;
}
/* хвостик облачка, направленный на котёнка */
.bubble::before, .bubble::after { content: ""; position: absolute; border-style: solid; }
.bubble::before { right: -15px; bottom: 4px; border-width: 9px 0 9px 15px; border-color: transparent transparent transparent #111; }
.bubble::after { right: -10px; bottom: 7px; border-width: 6px 0 6px 10px; border-color: transparent transparent transparent #fff; }
@keyframes bubble-pop { from { transform: rotate(-4deg) scale(0); } to { transform: rotate(-4deg) scale(1); } }
@keyframes bubble-shake {
  0%, 88%, 100% { transform: rotate(-4deg); }
  91% { transform: rotate(-8deg) scale(1.06); }
  94% { transform: rotate(0deg) scale(1.06); }
  97% { transform: rotate(-6deg); }
}

body.has-kitten #top-player { padding-right: 64px; }
body.has-kitten #game { padding-top: 50px; }

/* ---------- игроки и статус ---------- */
.player { display: flex; align-items: center; gap: 8px; padding: 8px 4px; min-height: 40px; }
.player .dot { width: 14px; height: 14px; border-radius: 50%; border: 1px solid #888; flex: none; }
.player .dot.white { background: #fff; }
.player .dot.black { background: #222; }
.player .pinfo { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.player .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Где сейчас соперник */
.presence { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--hint); line-height: 1.3; }
.presence .pdot { width: 8px; height: 8px; border-radius: 50%; background: #a0a0a6; flex: none; }
.presence.visible .pdot, .presence.choosing .pdot { background: #2ecc71; }
.presence.hidden .pdot { background: #f0a500; }
.presence.choosing { color: #27ae60; font-weight: 600; }
.presence.choosing .pdot { animation: presence-pulse 1.2s ease-in-out infinite; }
@keyframes presence-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(46, 204, 113, .6); }
  50% { box-shadow: 0 0 0 5px rgba(46, 204, 113, 0); }
}
.thinking i { font-style: normal; animation: thinking-dot 1.2s infinite; opacity: .2; }
.thinking i:nth-child(2) { animation-delay: .2s; }
.thinking i:nth-child(3) { animation-delay: .4s; }
@keyframes thinking-dot { 30% { opacity: 1; } 60%, 100% { opacity: .2; } }
.player .turn { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--accent); color: var(--accent-text); }

.status { text-align: center; font-weight: 700; font-size: 17px; padding: 6px 0 10px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 12px; }
.actions button { flex: 1 1 140px; }

.moves { background: var(--bg2); border-radius: 12px; padding: 10px 12px; font-family: ui-monospace, Menlo, monospace;
  font-size: 14px; display: grid; grid-template-columns: 36px 1fr 1fr; row-gap: 2px; max-height: 180px; overflow-y: auto; }
.moves .n { color: var(--hint); }
.moves:empty { display: none; }

/* ---------- модалка превращения ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; z-index: 10; }
.modal-box { background: var(--bg); border-radius: 16px; padding: 16px; width: min(320px, 90vw); text-align: center; }
.promo-choices { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 10px; }
.promo-choices button { background: var(--light); padding: 6px 0; }
.promo-choices .piece { font-size: 44px; }

.screen-msg { text-align: center; padding: 60px 20px; color: var(--hint); }
