/* =============================================
   TELEGRAM WEB APP – CHECKERS GAME STYLES
   ============================================= */

:root {
  --tg-bg: #17212b;
  --tg-secondary-bg: #232e3c;
  --tg-text: #f5f5f5;
  --tg-hint: #708499;
  --tg-link: #5288c1;
  --tg-button: #5288c1;
  --tg-button-text: #ffffff;
  --tg-accent: #5288c1;
  --tg-destructive: #e53935;
  --tg-success: #43a047;
  --tg-card: #1e2c3a;
  --tg-border: rgba(255, 255, 255, 0.07);

  --cell-light: #e8cfa7;
  --cell-dark: #5d4037;

  --piece-red: #e53935;
  --piece-red-dark: #b71c1c;
  --piece-black: #263238;
  --piece-black-dark: #000a12;
  --piece-crown: #ffd740;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-xl: 24px;

  --shadow-card: 0 2px 12px rgba(0, 0, 0, 0.35);
  --shadow-piece: 0 3px 8px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--tg-bg);
  color: var(--tg-text);
  font-size: 14px;
  line-height: 1.5;
}

/* ── SCREENS ──────────────────────────────── */
.screen {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  flex-direction: column;
  overflow: hidden;
  background: var(--tg-bg);
}

.screen.active {
  display: flex;
  animation: screenIn 0.2s ease;
}

@keyframes screenIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ── HEADER ───────────────────────────────── */
.tg-header {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background: var(--tg-secondary-bg);
  border-bottom: 1px solid var(--tg-border);
  gap: 10px;
  flex-shrink: 0;
  min-height: 56px;
}

.tg-header-title {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}

.tg-avatar {
  width: 36px;
  height: 36px;
  background: var(--tg-accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.tg-title {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.2;
}

.tg-subtitle {
  font-size: 12px;
  color: var(--tg-hint);
}

.back-btn {
  background: none;
  border: none;
  color: var(--tg-accent);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  padding: 0 6px 0 0;
  font-weight: 300;
}

/* ── LOBBY ────────────────────────────────── */
.lobby-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.hero-board-preview {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  width: 180px;
  height: 180px;
  align-self: center;
  opacity: 0.75;
  flex-shrink: 0;
}

.preview-cell {
  aspect-ratio: 1;
}

.preview-cell.light {
  background: var(--cell-light);
}

.preview-cell.dark {
  background: var(--cell-dark);
}

.lobby-card {
  background: var(--tg-secondary-bg);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-card);
}

.lobby-heading {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 6px;
}

.lobby-desc {
  font-size: 13px;
  color: var(--tg-hint);
  margin-bottom: 16px;
  line-height: 1.6;
}

.btn-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ── BUTTONS ──────────────────────────────── */
.tg-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 13px 16px;
  border-radius: var(--radius-md);
  border: none;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}

.tg-btn:active {
  transform: scale(0.97);
  opacity: 0.85;
}

.tg-btn-primary {
  background: var(--tg-button);
  color: var(--tg-button-text);
}

.tg-btn-secondary {
  background: var(--tg-card);
  color: var(--tg-accent);
  border: 1.5px solid var(--tg-border);
}

.tg-btn-ghost {
  background: transparent;
  color: var(--tg-hint);
}

.btn-icon {
  font-size: 17px;
}

/* ── STATS ────────────────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.stat-card {
  background: var(--tg-secondary-bg);
  border-radius: var(--radius-md);
  padding: 12px 8px;
  text-align: center;
}

.stat-val {
  font-size: 22px;
  font-weight: 700;
  color: var(--tg-accent);
}

.stat-lbl {
  font-size: 11px;
  color: var(--tg-hint);
  margin-top: 2px;
}

/* ── FORM / JOIN ──────────────────────────── */
.form-body {
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-desc {
  color: var(--tg-hint);
  font-size: 13px;
  line-height: 1.6;
}

.tg-input {
  width: 100%;
  padding: 13px 14px;
  background: var(--tg-secondary-bg);
  border: 1.5px solid var(--tg-border);
  border-radius: var(--radius-md);
  color: var(--tg-text);
  font-family: inherit;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-align: center;
  text-transform: uppercase;
  outline: none;
  transition: border-color 0.2s;
}

.tg-input:focus {
  border-color: var(--tg-accent);
}

.tg-input::placeholder {
  letter-spacing: 0.05em;
  color: var(--tg-hint);
  font-weight: 400;
  font-size: 14px;
}

.error-msg {
  color: var(--tg-destructive);
  font-size: 13px;
  text-align: center;
  min-height: 18px;
}

/* ── WAITING ──────────────────────────────── */
.waiting-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 20px;
  gap: 18px;
}

.spinner-ring {
  width: 52px;
  height: 52px;
  border: 4px solid var(--tg-border);
  border-top-color: var(--tg-accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.waiting-text {
  color: var(--tg-hint);
  font-size: 14px;
}

.room-code-display {
  background: var(--tg-secondary-bg);
  border: 2px solid var(--tg-accent);
  border-radius: var(--radius-md);
  padding: 12px 28px;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 0.25em;
  color: var(--tg-accent);
  text-transform: uppercase;
}

/* ── GAME SCREEN ──────────────────────────── */
#screen-game {
  display: flex;
  flex-direction: column;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--tg-secondary-bg);
  border-bottom: 1px solid var(--tg-border);
  flex-shrink: 0;
  min-height: 58px;
}

.player-info {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.player-black {
  flex-direction: row-reverse;
}

.player-piece {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: var(--shadow-piece);
}

.red-piece {
  background: radial-gradient(circle at 35% 35%, #ef9a9a, var(--piece-red) 60%, var(--piece-red-dark));
}

.black-piece {
  background: radial-gradient(circle at 35% 35%, #546e7a, var(--piece-black) 60%, var(--piece-black-dark));
}

.player-details {
  min-width: 0;
}

.player-name {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 90px;
}

.player-captures {
  font-size: 11px;
  color: var(--tg-hint);
}

.game-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
  padding: 0 8px;
}

.timer-display {
  font-size: 14px;
  font-weight: 700;
  color: var(--tg-text);
  font-variant-numeric: tabular-nums;
}

.menu-btn {
  background: none;
  border: none;
  color: var(--tg-hint);
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

.turn-indicator {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--tg-success);
  opacity: 0;
  flex-shrink: 0;
  transition: opacity 0.25s;
}

.turn-indicator.active {
  opacity: 1;
  animation: pulse 1.2s ease infinite;
}

@keyframes pulse {

  0%,
  100% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.5);
  }
}

/* ── BOARD ────────────────────────────────── */
.board-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--tg-bg);
  /* No overflow:hidden here — let it fill */
  padding: 8px;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.55), 0 0 0 3px var(--tg-secondary-bg);
  /* Size: fit in viewport minus header (~58px) and footer (~46px) and header (~56px) */
  width: min(calc(100vw - 16px), calc(100vh - 180px));
  height: min(calc(100vw - 16px), calc(100vh - 180px));
  flex-shrink: 0;
}

.cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: default;
  transition: background 0.1s;
  /* Force equal sizing */
  width: 100%;
  height: 100%;
}

.cell.light {
  background: var(--cell-light);
}

.cell.dark {
  background: var(--cell-dark);
}

.cell.selected {
  background: #ffd740 !important;
}

.cell.valid-move {
  background: rgba(82, 200, 82, 0.4) !important;
  cursor: pointer;
}

.cell.capture-move {
  background: rgba(229, 57, 53, 0.35) !important;
  cursor: pointer;
}

/* Dot indicator for valid moves */
.cell.valid-move::after,
.cell.capture-move::after {
  content: '';
  position: absolute;
  width: 30%;
  height: 30%;
  border-radius: 50%;
  pointer-events: none;
}

.cell.valid-move::after {
  background: rgba(82, 200, 82, 0.8);
}

.cell.capture-move::after {
  background: rgba(229, 57, 53, 0.8);
}

.cell.last-move-from {
  box-shadow: inset 0 0 0 2px rgba(255, 215, 64, 0.45);
}

.cell.last-move-to {
  box-shadow: inset 0 0 0 2px rgba(255, 215, 64, 0.9);
}

/* ── PIECES ───────────────────────────────── */
.piece {
  width: 78%;
  height: 78%;
  border-radius: 50%;
  cursor: pointer;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-piece), inset 0 -3px 5px rgba(0, 0, 0, 0.3);
  transition: transform 0.12s, box-shadow 0.12s;
  z-index: 1;
}

.piece:active {
  transform: scale(0.92);
}

.piece.selected {
  transform: scale(1.13);
  box-shadow: 0 5px 16px rgba(0, 0, 0, 0.6), 0 0 0 3px #ffd740;
}

.piece-red {
  background: radial-gradient(circle at 38% 35%, #ef9a9a 0%, var(--piece-red) 55%, var(--piece-red-dark) 100%);
  border: 2px solid rgba(255, 255, 255, 0.15);
}

.piece-black {
  background: radial-gradient(circle at 38% 35%, #78909c 0%, var(--piece-black) 55%, var(--piece-black-dark) 100%);
  border: 2px solid rgba(255, 255, 255, 0.08);
}

.piece.king::after {
  content: '♛';
  position: absolute;
  font-size: 50%;
  color: var(--piece-crown);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
  line-height: 1;
  pointer-events: none;
}

/* ── GAME FOOTER ──────────────────────────── */
.game-footer {
  padding: 10px 16px 14px;
  background: var(--tg-secondary-bg);
  border-top: 1px solid var(--tg-border);
  flex-shrink: 0;
}

.status-bar {
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  color: var(--tg-text);
  min-height: 20px;
}

/* ── BOTTOM SHEET ─────────────────────────── */
.game-menu-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 100;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  animation: fadeIn 0.18s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.game-menu-sheet {
  background: var(--tg-secondary-bg);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: 10px 16px 36px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: slideUp 0.2s ease;
}

@keyframes slideUp {
  from {
    transform: translateY(50px);
  }

  to {
    transform: translateY(0);
  }
}

.sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--tg-hint);
  border-radius: 2px;
  margin: 0 auto 12px;
  opacity: 0.5;
}

.sheet-title {
  font-size: 15px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 4px;
}

.sheet-btn {
  width: 100%;
  padding: 14px;
  background: var(--tg-card);
  border: 1px solid var(--tg-border);
  border-radius: var(--radius-md);
  color: var(--tg-text);
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  text-align: center;
  cursor: pointer;
  transition: opacity 0.15s;
}

.sheet-btn:active {
  opacity: 0.7;
}

.sheet-btn-cancel {
  color: var(--tg-hint);
  background: transparent;
  border-color: transparent;
}

/* ── RESULT ───────────────────────────────── */
.result-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 20px;
  gap: 16px;
  text-align: center;
  overflow-y: auto;
}

.result-icon {
  font-size: 60px;
  animation: bounceIn 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

@keyframes bounceIn {
  0% {
    transform: scale(0) rotate(-20deg);
    opacity: 0;
  }

  60% {
    transform: scale(1.2) rotate(5deg);
    opacity: 1;
  }

  100% {
    transform: scale(1) rotate(0);
  }
}

.result-title {
  font-size: 26px;
  font-weight: 800;
}

.result-subtitle {
  font-size: 13px;
  color: var(--tg-hint);
}

.result-scores {
  display: flex;
  gap: 20px;
  background: var(--tg-secondary-bg);
  border-radius: var(--radius-lg);
  padding: 14px 24px;
}

.score-box {
  text-align: center;
}

.score-val {
  font-size: 26px;
  font-weight: 800;
  color: var(--tg-accent);
}

.score-lbl {
  font-size: 11px;
  color: var(--tg-hint);
  margin-top: 2px;
}

/* ── TOAST ────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: rgba(20, 30, 40, 0.95);
  color: #fff;
  padding: 9px 18px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 200;
  white-space: nowrap;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  max-width: calc(100vw - 32px);
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── PIECE ANIMATIONS ─────────────────────── */
@keyframes pieceDrop {
  0% {
    transform: scale(0.5) translateY(-6px);
    opacity: 0;
  }

  70% {
    transform: scale(1.08) translateY(1px);
    opacity: 1;
  }

  100% {
    transform: scale(1) translateY(0);
  }
}

.piece.dropping {
  animation: pieceDrop 0.26s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes kingFlash {

  0%,
  100% {
    box-shadow: var(--shadow-piece);
  }

  50% {
    box-shadow: 0 0 0 6px rgba(255, 215, 64, 0.5), var(--shadow-piece);
  }
}

.piece.king-promoted {
  animation: kingFlash 0.5s ease;
}

/* ── SCROLLBAR ────────────────────────────── */
::-webkit-scrollbar {
  width: 3px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--tg-border);
  border-radius: 2px;
}