/* Тема берётся из Telegram (--tg-theme-*), палитра доски фиксированная. */

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--tg-theme-bg-color, #f4f4f5);
  color: var(--tg-theme-text-color, #222);
  user-select: none;
  -webkit-user-select: none;
}

.hidden { display: none !important; }
.muted { color: var(--tg-theme-hint-color, #888); }
.small { font-size: 13px; }

.screen {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
}

.big-icon { font-size: 56px; line-height: 1; }

h2 { margin: 0; font-size: 22px; }

.btn {
  border: none;
  border-radius: 12px;
  padding: 14px 22px;
  font-size: 16px;
  width: 100%;
  max-width: 320px;
  background: var(--tg-theme-secondary-bg-color, #e7e7e9);
  color: var(--tg-theme-text-color, #222);
  cursor: pointer;
}
.btn.primary {
  background: var(--tg-theme-button-color, #2ea6ff);
  color: var(--tg-theme-button-text-color, #fff);
}
.btn.danger { color: #e53935; }
.btn.mini {
  width: auto;
  padding: 8px 14px;
  font-size: 14px;
  border-radius: 10px;
}
.btn:active { opacity: .75; }

.field {
  display: flex;
  gap: 8px;
  width: 100%;
  max-width: 320px;
}
.field input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--tg-theme-hint-color, #bbb);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 16px;
  background: var(--tg-theme-secondary-bg-color, #fff);
  color: var(--tg-theme-text-color, #222);
  outline: none;
}
.field .btn { width: auto; }

.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 320px;
  color: var(--tg-theme-hint-color, #888);
  font-size: 13px;
}
.divider::before, .divider::after {
  content: "";
  height: 1px;
  flex: 1;
  background: var(--tg-theme-hint-color, #bbb);
  opacity: .4;
}

.invites {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 320px;
}
.invite-btn { animation: pulse 2s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.03); }
}

.spinner {
  width: 34px; height: 34px;
  border: 3px solid var(--tg-theme-hint-color, #bbb);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- игровой экран --- */

#screen-game {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  gap: 6px;
}

.player-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 6px;
  min-height: 26px;
  font-size: 15px;
}
.pname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.captured { color: var(--tg-theme-hint-color, #888); font-size: 13px; }
.turn-flag {
  margin-left: auto;
  font-size: 12px;
  padding: 2px 10px;
  border-radius: 20px;
  background: var(--tg-theme-button-color, #2ea6ff);
  color: var(--tg-theme-button-text-color, #fff);
  visibility: hidden;
}
.turn-flag.on { visibility: visible; }

.dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--tg-theme-hint-color, #bbb);
  flex: none;
}
.dot.online { background: #43a047; }

#board-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
}
#board {
  width: min(100vw - 12px, 100dvh - 170px);
  max-width: 560px;
  aspect-ratio: 1;
  border-radius: 10px;
  box-shadow: 0 2px 14px rgba(0,0,0,.25);
  touch-action: manipulation;
}

#controls {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 6px;
}
#conn { margin-left: auto; }

#banner {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 6px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--tg-theme-secondary-bg-color, #e7e7e9);
  font-size: 14px;
}
#banner-text { flex: 1; }
#banner-buttons { display: flex; gap: 6px; }
#banner-buttons.hidden { display: none; }

/* --- модалка результата --- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 24px;
}
.modal-box {
  background: var(--tg-theme-bg-color, #fff);
  border-radius: 18px;
  padding: 24px;
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: rgba(20,20,20,.9);
  color: #fff;
  padding: 10px 18px;
  border-radius: 12px;
  font-size: 14px;
  z-index: 60;
  max-width: 90vw;
  text-align: center;
}

/* --- видеозвонки --- */

.btn-row {
  display: flex;
  gap: 8px;
  width: 100%;
  max-width: 320px;
}
.btn-row .btn { flex: 1; width: auto; }

.cbtn {
  width: 46px;
  height: 46px;
  border: none;
  border-radius: 50%;
  font-size: 19px;
  background: rgba(255,255,255,.18);
  color: #fff;
  cursor: pointer;
  backdrop-filter: blur(4px);
}
.cbtn.danger { background: #e53935; }
.cbtn.ok { background: #43a047; }
.cbtn.off { background: rgba(229,57,53,.85); }
.cbtn:active { opacity: .75; }

#board-wrap { position: relative; }

#pip {
  position: fixed;           /* координаты ставит JS: окно можно таскать по экрану */
  width: 124px;
  z-index: 45;
  border-radius: 14px;
  overflow: hidden;
  background: #111;
  box-shadow: 0 4px 18px rgba(0,0,0,.45);
  display: flex;
  flex-direction: column;
  touch-action: none;        /* жест перетаскивания не отдаём браузеру */
  cursor: grab;
}
#pip-remote {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  background: #111;
  display: block;
}
#pip-local {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 34%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,.5);
  background: #222;
}
#pip.pip-big {
  position: fixed;
  top: 50%;
  left: 50%;
  right: auto;
  transform: translate(-50%, -50%);
  width: min(90vw, 420px);
  z-index: 55;
}
#pip-status, #pip-badges {
  position: absolute;
  left: 0; right: 0;
  bottom: 52px;
  padding: 3px 6px;
  font-size: 11px;
  color: #fff;
  background: rgba(0,0,0,.45);
  text-align: center;
}
#pip-controls {
  display: flex;
  justify-content: space-around;
  gap: 4px;
  padding: 6px;
  background: rgba(0,0,0,.6);
}
#pip-controls .cbtn { width: 36px; height: 36px; font-size: 15px; }
#pip.waiting #pip-local { display: none; }

#call-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 6px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--tg-theme-button-color, #2ea6ff);
  color: var(--tg-theme-button-text-color, #fff);
  font-size: 14px;
  animation: pulse 1.6s ease-in-out infinite;
}
#call-banner-text { flex: 1; }
#call-banner .btn { background: rgba(255,255,255,.92); color: #222; }

/* полноэкранный звонок */

#screen-call {
  position: fixed;
  inset: 0;
  background: #101014;
  z-index: 40;
  overflow: hidden;
}
#call-remote {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #101014;
}
#call-local {
  position: absolute;
  right: 12px;
  bottom: calc(96px + env(safe-area-inset-bottom));
  width: 28vw;
  max-width: 132px;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.5);
  background: #222;
  z-index: 42;
}
#call-top {
  position: absolute;
  top: calc(14px + env(safe-area-inset-top));
  left: 0; right: 0;
  text-align: center;
  color: #fff;
  z-index: 42;
  text-shadow: 0 1px 6px rgba(0,0,0,.7);
}
#call-name { font-size: 22px; font-weight: 600; }
#call-status { font-size: 14px; opacity: .85; margin-top: 4px; }
#call-badges { font-size: 12px; opacity: .85; margin-top: 4px; }
#call-controls {
  position: absolute;
  left: 0; right: 0;
  bottom: calc(22px + env(safe-area-inset-bottom));
  display: flex;
  justify-content: center;
  gap: 18px;
  z-index: 42;
}
#call-controls .cbtn { width: 56px; height: 56px; font-size: 22px; }
