/**
 * Мобильная вёрстка — подключать ПОСЛЕДНИМ на каждой странице.
 * Переопределяет дублирующие правила из page-specific CSS.
 */

@media (max-width: 768px) {
  :root {
    --page-inset-x: clamp(10px, 3vw, 20px);
    --header-top-offset: max(10px, env(safe-area-inset-top, 0px));
    --header-height: 52px;
    --content-top: calc(var(--header-top-offset) + var(--header-height) + 12px);

    --site-bg: #121212;
    --site-text: #e0e0e0;
    --site-text-muted: #b0b0b0;
    --site-accent-green: #3b9219;
    --site-accent-green-hover: #46aa1e;
    --site-accent-blue: #64b5f6;
    --site-gold: #ffd77a;
    --site-surface: rgba(26, 26, 30, 0.75);
    --site-surface-card: rgba(10, 10, 14, 0.55);
    --site-border: rgba(255, 255, 255, 0.1);
    --site-glass: rgba(255, 255, 255, 0.03);
  }

  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  body,
  body.shop-body,
  body.profile-body,
  body.game-select-body,
  body.social-page-body,
  body.play-lobby-body {
    background-color: var(--site-bg);
    color: var(--site-text);
  }

  /* ——— Шапка (все варианты страниц) ——— */
  .ios-header,
  body.profile-body .ios-header,
  body.shop-body .ios-header,
  body.game-select-body .ios-header,
  body.social-page-body .ios-header,
  body.play-lobby-body .ios-header,
  .index .ios-header {
    top: var(--header-top-offset) !important;
    left: var(--page-inset-x) !important;
    right: var(--page-inset-x) !important;
    height: var(--header-height) !important;
    padding: 0 clamp(12px, 3.5vw, 18px) !important;
    border-radius: 22px !important;
  }

  .logo-chess-beta {
    font-size: 1.2rem;
    letter-spacing: 0.06em;
  }

  .header-wallet-compact {
    padding: 3px 7px;
    font-size: 0.72rem;
    color: var(--site-gold);
    max-width: 72px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .header-profile-chip {
    padding: 3px !important;
    max-width: none !important;
  }

  .header-profile-chip span[data-header-nick],
  .header-profile-chip .cosmetic-nick-stack {
    display: none !important;
  }

  .btn-auth-login {
    padding: 7px 14px;
    font-size: 0.88rem;
  }

  /* ——— Контент под шапкой ——— */
  .shop-wrap,
  .profile-wrap,
  .friends-wrap,
  .social-wrap,
  body.social-page-body.tops-page--shop .social-wrap,
  .game-select-wrap,
  .play-lobby-wrap {
    padding-top: var(--content-top) !important;
    padding-left: var(--page-inset-x) !important;
    padding-right: var(--page-inset-x) !important;
  }

  .shop-title,
  .tops-title,
  .friends-title {
    font-size: 1.5rem;
  }

  .shop-board,
  .tops-board,
  .profile-board {
    padding: 18px 16px 22px;
    border-radius: 20px;
  }

  .shop-grid {
    grid-template-columns: 1fr;
  }

  /* ——— Выбор игры ——— */
  body.game-select-body {
    min-height: 100dvh;
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .game-select-wrap {
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding-bottom: max(12px, env(safe-area-inset-bottom, 0px)) !important;
  }

  .game-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: clamp(8px, 2.5vw, 14px);
    width: 100%;
  }

  .game-card {
    padding: 4px 2px;
    min-height: 0;
  }

  .game-card-board {
    width: 100%;
    max-width: 100%;
    height: auto;
    aspect-ratio: 1;
    max-height: min(32dvh, 175px);
    margin: 0 auto 6px;
    border-radius: 14px;
    background: rgba(0, 0, 0, 0.35);
  }

  .game-card-board img {
    object-fit: contain;
    object-position: center;
  }

  .game-card-title {
    font-size: clamp(0.92rem, 4vw, 1.35rem);
    margin-bottom: 2px;
  }

  .game-card-playing {
    font-size: clamp(0.62rem, 2.5vw, 0.82rem);
    line-height: 1.2;
  }

  /* ——— Социальные ——— */
  .social-page-title {
    font-size: 1.35rem;
  }

  .social-pill {
    min-height: 44px;
    font-size: 0.8rem;
  }

  .social-row {
    flex-wrap: wrap;
    padding: 12px;
  }

  .social-row-actions {
    width: 100%;
    justify-content: flex-end;
  }

  body.social-page-body.tops-page--shop .tops-row {
    flex-wrap: nowrap;
    align-items: center;
    padding: 12px;
  }

  body.social-page-body.tops-page--shop .tops-row-text {
    flex: 1;
    min-width: 0;
  }

  body.social-page-body.tops-page--shop .tops-row-nick,
  body.social-page-body.tops-page--shop .tops-row-login {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  body.social-page-body.tops-page--shop .tops-value-block {
    flex-shrink: 0;
    text-align: right;
  }

  /* ——— Профиль ——— */
  .nickname-block {
    min-width: 0 !important;
  }

  .profile-nickname-text {
    font-size: 1.3rem;
  }

  .profile-stats-strip {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .profile-stats-strip--banner {
    padding-left: 14px !important;
    padding-right: 14px !important;
  }

  .stat-tile {
    text-align: center;
  }

  .st-lbl,
  .st-val {
    display: block;
    margin-right: 0;
  }

  .profile-board.profile-board--editing .profile-hero-left {
    flex-direction: column;
    align-items: center;
    width: 100%;
  }

  .profile-board.profile-board--editing .nickname-block {
    width: 100%;
    text-align: center;
  }

  .profile-board.profile-board--editing .profile-bg-actions {
    display: flex;
    justify-content: center;
    width: 100%;
  }

  /* ——— Меню профиля: уведомления слева, меню справа ——— */
  #profile-menu-sheet {
    padding-top: calc(var(--content-top) - 8px);
    padding-left: max(6px, env(safe-area-inset-left, 0px));
    padding-right: max(6px, env(safe-area-inset-right, 0px));
    justify-content: flex-end;
  }

  .profile-menu-dialog {
    flex-direction: row !important;
    flex-wrap: nowrap;
    max-width: calc(100vw - 12px);
    overflow: hidden;
  }

  .profile-menu-notifications {
    width: calc(50% - 6px) !important;
    max-width: none;
    flex: 1 1 50%;
    min-width: 0;
    max-height: min(70dvh, calc(100dvh - var(--content-top) - 24px));
  }

  .profile-menu-panel {
    width: calc(50% - 6px) !important;
    flex: 1 1 50%;
    min-width: 0;
  }

  /* ——— Игра ——— */
  .game-container {
    display: flex !important;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: var(--content-top) var(--page-inset-x)
      max(16px, env(safe-area-inset-bottom, 0px)) !important;
    max-width: 100%;
    min-height: auto;
    box-sizing: border-box;
  }

  .game-container .side-panel {
    width: 100%;
    max-width: min(480px, 100%);
  }

  .side-panel {
    flex-direction: column;
    align-items: stretch;
    padding: 12px 14px;
    border-radius: 18px;
    background: var(--site-glass);
  }

  .side-panel .panel-content {
    order: 1;
    width: 100%;
  }

  .left-panel .panel-content {
    order: 1;
  }

  .eaten-figures {
    order: 2;
    width: 100%;
    max-width: none;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-start;
    padding: 8px 0 0;
    margin: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
  }

  .left-panel .eaten-figures,
  .right-panel .eaten-figures {
    border-left: none;
    border-right: none;
    margin: 0;
    padding-left: 0;
    padding-right: 0;
  }

  .board-container {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .game-container #board {
    width: 100% !important;
    max-width: min(100%, 420px);
    margin: 0 auto;
  }

  .game-container #board .square-55d63.white-1e1d7 {
    background-color: #f0d9b5 !important;
  }

  .game-container #board .square-55d63.black-3c85d {
    background-color: #b58863 !important;
  }

<<<<<<< HEAD
=======
  .game-container #board .square-55d63 {
    background-image: none !important;
  }

  .game-container #board img {
    filter: none !important;
    -webkit-filter: none !important;
    mix-blend-mode: normal !important;
    opacity: 1 !important;
  }

>>>>>>> 7a25831 (баги)
  #checkers-board {
    width: min(calc(100vw - 2 * var(--page-inset-x)), 400px) !important;
    max-width: 100%;
    margin: 0 auto;
    display: grid !important;
    grid-template-columns: repeat(8, 1fr) !important;
    grid-template-rows: repeat(8, 1fr) !important;
    aspect-ratio: 1;
  }

  #checkers-board .cell {
    width: 100% !important;
    height: auto !important;
    aspect-ratio: 1;
    min-height: 0;
  }

  #checkers-board .piece {
    width: 76%;
    height: 76%;
    max-width: 44px;
    max-height: 44px;
  }

  #checkers-board .piece.king::after {
    font-size: clamp(14px, 4vw, 22px);
  }

  #checkers-board .cell.light {
    background-color: #ebecd0 !important;
  }

  #checkers-board .cell.dark {
    background-color: #779556 !important;
  }

  .eaten-item-wrapper img {
    width: 28px;
    height: 28px;
    object-fit: contain;
  }

  /* ——— Главная ——— */
  .carousel-container {
    height: min(50vh, 360px);
    min-height: 220px;
  }

  .overlay-button-container {
    top: 55%;
    left: 0;
    right: 0;
    width: 100%;
    transform: none;
    display: flex;
    justify-content: center;
    padding: 0 var(--page-inset-x);
    box-sizing: border-box;
  }

  .main-play-btn {
    display: block;
    margin: 0 auto;
    padding: 16px 28px;
    font-size: 1.2rem;
    max-width: min(100%, 280px);
    background: var(--site-accent-green);
    border-radius: 999px;
  }

  .text-content {
    width: calc(100% - 2 * var(--page-inset-x));
    margin-left: auto;
    margin-right: auto;
    padding: 18px 16px;
    border-radius: 20px;
  }

  .text-content h1 {
    font-size: 1.45rem;
  }

  .text-content h3 {
    color: var(--site-accent-green);
    font-size: 1rem;
  }

  .main-footer {
    flex-direction: column;
    text-align: center;
    padding: 14px;
  }

  .overlay .modal-content,
  .overlay:not(.room-settings-overlay) .modal-content {
    width: min(380px, calc(100vw - 24px)) !important;
    margin: auto;
    padding: 22px 18px;
    box-sizing: border-box;
  }
}

@media (max-width: 380px) {
  .logo-chess-beta {
    font-size: 1rem;
  }

  .game-card-board {
    max-height: min(28dvh, 140px);
  }

  .game-card-title {
    font-size: 0.85rem;
  }
}

@media (hover: none) and (pointer: coarse) {
  .main-play-btn:hover {
    transform: none;
    box-shadow: none;
  }

  .image-content img:hover {
    transform: none;
  }

  button,
  .btn-auth-login,
  .social-pill {
    min-height: 44px;
  }

  body.game-select-body .game-card {
    min-height: 0;
  }

  .auth-field input,
  .social-input {
    font-size: 16px;
  }
}
