/* ════════════════════════════════════════════════════════════════
   responsive.css — адаптивные стили по брейкпоинтам
   Содержание:
   1. ≤1400px — общий макет
   2. ≤1080px — секции, игровой стол
   3. ≤768px  — мобильная версия
   4. ≤485px  — компактная мобильная
   ════════════════════════════════════════════════════════════════ */

/* ── 1. ≤1400px: общий макет ── */

@media (max-width: 1400px) {
  body {
    position: relative;
    display: block;
  }
  .content-wrap {
    flex-direction: column;
    position: relative;
    width: 100%;
    margin: 0px;
    transform: translateX(0);
  }

  .section {
    width: auto;
  }

}

/* ── 2. ≤1080px: секции и игровой стол ── */

@media (max-width: 1080px) {
  .section {
    width: auto;
    min-width: 0;
    max-width: 100%;
    margin: 12px;
  }

  .body-wrap {
    width: 100%;
  }

  .left-section-tables-wrap {
    padding: 0 10px;
  }

  .history-shell {
    --history-shell-pad-x: 10px;
    padding: 0px;
  }

  #history {
    --history-rail-width: 10px;
  }

  /* ── 2.1 Игровой стол ── */

  .mahjong-table {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 0;
    margin: 0 auto;
    padding: 32px 20px;
    gap: 20px;
    border-bottom: 1px solid #ebeef0;
  }

  .mahjong-table__turns,
  .mahjong-table__turn-defs {
    display: none;
  }

  .player.west { order: 1; }
  .player.north { order: 2; }
  .mahjong-table__board { order: 3; }
  .player.south { order: 4; }
  .player.east { order: 5; }

  .mahjong-table__board {
    width: min(250px, 72vw);
    height: min(250px, 72vw);
  }

  .mahjong-table__felt {
    padding: 6px;
  }

  .mahjong-table__wall--north .mahjong-table__wall-row,
  .mahjong-table__wall--south .mahjong-table__wall-row {
    flex-wrap: nowrap;
    justify-content: center;
  }

  .settings-table-tile {
    --settings-tile-w: 9px;
    --settings-tile-h: 12px;
  }

  .settings-table-tile .hand-tile-face,
  .settings-table-tile .hand-tile-label {
    transform: none;
  }

  .playerNames .player.west,
  .playerNames .player.north,
  .playerNames .player.south,
  .playerNames .player.east,
  .playerNames .mahjong-table__board {
    order: unset;
  }
}

/* ── 3. ≤768px: мобильная версия ── */

@media (max-width: 768px) {
  /* ── 3.1 Базовый макет ── */

  html,
  body {
    overflow-x: hidden;
    max-width: 100%;
  }

  body {
    position: relative;
    display: block;
    min-height: 100dvh;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  body,
  .body-wrap,
  .content-wrap,
  .section,
  .left-section-tables-wrap,
  .history-shell,
  .round-cards,
  .score-cards {
    max-width: 100%;
    box-sizing: border-box;
    overflow-x: hidden;
  }

  .body-wrap {
    width: 100%;
    display: block;
    padding-bottom: calc(112px + env(safe-area-inset-bottom, 0px));
    box-sizing: border-box;
  }

  .content-wrap {
    flex-direction: column;
    width: 100%;
  }

  .section {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    margin: 8px 0;
    padding: 12px;
    box-sizing: border-box;
    overflow-wrap: anywhere;
  }

  .left-section-tables-wrap {
    padding: 0 4px;
    max-width: 100%;
    overflow-x: hidden;
    overflow: visible;
    height: auto !important;
    min-height: 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    gap: 12px;
  }

  #roundTable,
  #scoreSummary,
  #scoreTable,
  .round-cards,
  .score-cards {
    overflow: visible;
    max-height: none;
    min-height: 0;
    height: auto;
    flex: 0 0 auto;
    width: 100%;
  }

  .history-round-body {
    min-height: 300px;
  }

  .history-timeline-rail {
    padding: 0px 11px;
  }

  #roundTable {
    order: 1;
  }

  .calculateRound-wrap {
    order: 2;
  }

  #scoreSummary {
    order: 3;
    margin-top: 0;
  }

  .round-cards__grid,
  .score-cards__grid {
    margin: 0 0 8px;
    padding: 0;
    min-height: auto;
  }

  .round-card,
  .score-card {
    min-height: auto;
  }

  .history-shell {
    --history-shell-pad-x: 4px;
  }

  #history {
    --history-rail-width: 4px;
  }

  .roundWind-wrap {
    height: auto;
    min-height: 52px;
    padding: 8px 14px 14px;
  }

  .input-group {
    gap: 8px;
    margin: 0px;
    width: 100%;
  }

  /* ── 3.2 Кнопка расчёта раунда ── */

  .calculateRound-wrap {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    margin: 0;
    position: relative;
    z-index: 2;
  }

  .calculateRound-wrap > button.calculateRound {
    width: 100%;
    max-width: none;
    min-height: 44px;
    margin-top: 0;
  }

  .calculateRound-secondary {
    display: none;
  }

  .voice-score-button {
    display: none !important;
  }

  .calculateRound-wrap button:not(.voice-score-button) {
    width: 100%;
    max-width: none;
  }

  /* ── 3.3 Заголовки и меню ── */

  .section h2,
  .playerNames h2 {
    font-size: 1.2em;
  }

  .menu-stack {
    position: fixed;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    top: auto;
    right: 10px;
    left: 10px;
    transform: none;
    z-index: 10001;
  }

  .menu-wrap {
    width: auto;
    max-width: 100%;
    box-sizing: border-box;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 8px 10px;
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    justify-content: space-between;
    align-items: center;
    gap: 4px;
    border-radius: 50px;
    transition: none;
    overflow: hidden;
  }

  .menu-wrap:hover {
    width: 100%;
  }

  .hamburger::before, 
  .reload-button::before, 
  .save-button::before, 
  .load-button::before, 
  .server-games-button::before, 
  .rules-button::before {
    display: none;    
  }

  .menu-right-fixed {
    display: none;
  }

  .hamburger,
  .reload-button,
  .save-button,
  .load-button,
  .server-games-button,
  .rules-button,
  .theme-button {
    margin: 0 !important;
    left: 0 !important;
    flex: 1 1 0;
    min-width: 0;
    max-width: 44px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .reload-icon,
  .save-icon,
  .load-icon,
  .server-games-icon,
  .rules-icon,
  .theme-icon {
    position: static;
    top: auto;
    right: auto;
    left: auto;
    transform: none;
    width: 100%;
    height: 100%;
  }

  .theme-icon-svg {
    width: 24px;
    height: 24px;
    min-width: 24px;
    min-height: 24px;
  }

  .menu-wrap:hover .hamburger,
  .menu-wrap:hover .reload-button,
  .menu-wrap:hover .save-button,
  .menu-wrap:hover .load-button,
  .menu-wrap:hover .server-games-button,
  .menu-wrap:hover .rules-button,
  .menu-wrap:hover .theme-button {
    width: 44px;
    min-width: 44px;
    max-width: 44px;
  }

  .hamburger {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .menu-item-label {
    display: none;
  }

  /* ── 3.4 Round cards ── */

  #roundTable {
    overflow: visible;
  }

  .round-cards__grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    padding: 10px;
    align-content: start;
  }

  #roundTable.round-cards {
    --round-card-tags-height: 29px;
  }

  .round-card {
    gap: 0;
    padding: 0;
    border-radius: 12px;
    min-height: 0 !important;
    height: auto !important;
    max-height: 163px !important;
    overflow: hidden !important;
  }

  .round-card__header,
  .round-card__body,
  .round-card__score,
  .round-card__mahjong {
    padding: 3px 5px !important;
    margin: 0 !important;
  }

  .round-card__header {
    padding-bottom: 3px !important;
  }

  .round-card__body {
    padding-top: 0 !important;
    gap: 3px !important;
  }

  .round-card__title-row {
    gap: 3px;
    min-height: var(--round-card-tags-height);
    align-items: stretch;
  }

  .round-card__name,
  .round-card__name--compact {
    font-size: 9px !important;
    line-height: 1.05 !important;
    white-space: normal !important;
    overflow-wrap: anywhere;
    word-break: break-word;
    text-overflow: clip;
  }

  .round-card--compact-mobile .round-card__title-row {
    align-items: stretch;
  }

  .round-card--compact-mobile .round-card__tags {
    gap: 2px;
    min-height: 0;
    overflow: hidden;
  }

  .round-card--compact-mobile .round-card__tag {
    font-size: 8px !important;
    padding: 1px 4px !important;
    line-height: 1.1 !important;
    white-space: normal !important;
    text-align: center;
  }

  .round-card__tags {
    gap: 2px;
    min-height: 0;
    overflow: hidden;
  }

  .round-card__tag {
    font-size: 8px !important;
    padding: 1px 4px !important;
    line-height: 1.1 !important;
    white-space: normal !important;
    text-align: center;
  }

  .round-card__wind {
    font-size: 9px !important;
    min-width: 14px !important;
  }

  .round-card__score input[type="number"] {
    min-height: 22px !important;
    font-size: 11px !important;
    padding: 1px 3px !important;
  }

  .round-card__score-toolbar {
    gap: 2px !important;
    padding: 2px 0 0 !important;
    margin-top: 4px !important;
    justify-content: center;
  }

  .round-card__score-tool {
    min-height: 16px !important;
    padding: 2px 3px !important;
    font-size: 8px !important;
  }

  .round-card__score-tool--number {
    display: none;
  }

  .round-card__mahjong,
  .round-card__mahjong-btn,
  .round-card--compact-mobile .round-card__mahjong,
  .round-card--compact-mobile .round-card__mahjong-btn {
    display: none !important;
  }

  /* ── 3.5 Score cards ── */

  .score-cards__grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .score-card {
    min-height: 78px !important;
    border-radius: 12px;
    height: auto !important;
    max-height: 104px !important;
    overflow: hidden !important;
  }

  .score-card__head {
    min-height: 24px !important;
    padding: 3px 5px 4px !important;
  }

  .score-card__body {
    padding: 3px 5px 4px !important;
  }

  .score-card__value {
    font-size: 12px !important;
  }

  .score-card__name {
    font-size: 8px !important;
  }

  /* ── 3.6 История ── */

  #history .history-round-title {
    max-width: 140px;
  }

  .history-player-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    margin: 0 0 10px;
  }

  .history-player-card {
    padding: 0;
    min-height: 0 !important;
    border-radius: 12px;
    height: auto !important;
    max-height: 96px !important;
    overflow: hidden !important;
  }

  .history-player-card__head,
  .history-player-card__stats {
    padding: 3px 5px !important;
  }

  .history-player-card__head {
    gap: 3px;
  }

  .history-player-card__name {
    font-size: 8px !important;
    line-height: 1.05 !important;
  }

  .history-player-card__wind {
    min-width: 14px !important;
    font-size: 9px !important;
  }

  .history-player-card__stats {
    gap: 3px;
  }

  .history-player-card__stat {
    gap: 2px;
  }

  .history-player-card__label {
    font-size: 6px !important;
    letter-spacing: 0.02em;
  }

  .history-player-card__value {
    font-size: 8px !important;
  }

  .history-player-card .score-delta {
    min-width: 20px !important;
    width: 20px !important;
    padding: 1px 2px !important;
    font-size: 7px !important;
  }

  .history-player-card .score-delta {
    min-width: 42px;
    width: 42px;
    font-size: 11px;
    padding: 3px 4px;
  }

  .round-card__mahjong-btn {
    width: 100%;
  }

  

  /* ── 3.7 Маджонг-индикаторы ── */

  

  

  

  .score-card__value {
    font-size: 22px;
  }

  /* ── 3.8 История: контейнер и группы ── */

  #history {
    max-height: 40vh;
  }

  .round-group {
    margin-bottom: 15px;
  }

  #historyScore {
    padding: 12px;
  }

  #historyScore .input-group {
    margin-bottom: 60px;
  }

  .input-group button {
    font-size: 12px;
    padding: 8px 12px;
    min-width: auto;
  }

  #history {
    --history-section-pad-x: 10px;
    --history-group-gap: 22px;
  }

  #history .round-group.appear {
    margin: 0 0 0 calc(-1 * var(--history-timeline-inset));
  }

  /* ── 3.9 Модальные окна ── */

  .modal {
    padding: 12px;
    align-items: center;
  }

  .modal-content {
    width: min(92vw, 460px);
    max-width: 460px;
    padding: 16px;
    border-radius: 18px;
    max-height: calc(100vh - 24px - env(safe-area-inset-bottom, 0px));
  }

  .modal-content--hand-calculator {
    width: min(96vw, 1280px);
    max-width: none;
    padding: 14px;
    border-radius: 18px;
    height: calc(100dvh - 24px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    max-height: calc(100dvh - 24px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  }

  .modal-content--edit-history {
    width: min(94vw, 720px);
    max-width: none;
  }

  .edit-history-form {
    grid-template-columns: 1fr;
  }

  .modal-actions--hand-calculator {
    flex-direction: column-reverse;
    align-items: stretch;
    gap: 8px;
  }

  .modal-actions--hand-calculator button {
    width: 100%;
    max-width: none;
    min-width: 0;
  }

  .modal-content--chart {
    width: min(96vw, 900px);
    max-width: none;
  }

  .modal-title {
    font-size: 1.15em;
    margin-bottom: 12px;
  }

  .modal-text {
    font-size: 18px;
    padding: 16px 14px;
    gap: 14px;
  }

  .modal-text i {
    width: 62px;
    height: 62px;
    border-radius: 50%;
    font-size: 26px;
  }

  #modalOverlayInfo .modal-actions button,
  #modalOverlayQuestion .modal-actions button {
    min-width: 88px;
    min-height: 38px;
    padding: 9px 18px;
    font-size: 15px;
  }

  .modal-chart-wrap canvas {
    max-height: 45vh;
  }

  .modal-actions {
    margin-top: 14px;
    gap: 8px;
  }

  .modal-actions button {
    width: auto;
    min-width: 80px;
    max-width: 120px;
    padding: 7px 14px;
    font-size: 13px;
  }

  .modal-actions--split {
    flex-direction: row;
  }

  .modal-actions--split button {
    max-width: 120px;
  }

  /* ── 3.10 Toast и калькулятор ── */

  .toast-notification {
    bottom: calc(78px + env(safe-area-inset-bottom, 0px));
    left: 50%;
    max-width: calc(100vw - 24px);
    white-space: normal;
    text-align: center;
  }

  .calc-buttons {
    grid-template-columns: repeat(3, 40px);
  }

  .calc-buttons button {
    min-width: 35px;
    padding: 8px;
  }

  .toast-notification {
    font-size: 12px;
  }

  /* ── 3.11 Панель ввода имён ── */

  .playerNames {
    --panel-edge: 12px;
    --panel-menu-space: 0px;
    --mobile-menu-clearance: calc(112px + env(safe-area-inset-bottom, 0px));
    --panel-height: calc(100dvh - var(--panel-edge) - var(--mobile-menu-clearance));
    top: var(--panel-edge);
    left: var(--panel-edge);
    right: var(--panel-edge);
    width: auto;
    max-width: none;
  }

  .playerNames__curtain {
    overflow: hidden;
  }

  .playerNames__content {
    min-height: 0;
    height: 100%;
    align-items: stretch;
    justify-content: flex-start;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px 12px 16px;
    gap: 10px;
  }

  .playerNames h2 {
    flex: 0 0 auto;
    margin-bottom: 0;
    padding: 6px 10px;
  }

  .playerNames .mahjong-table__board {
    display: none !important;
  }

  .playerNames .mahjong-table {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    flex: 0 0 auto;
    width: 100%;
    max-width: 100%;
    min-height: unset;
    margin: 0;
    padding: 0;
    gap: 10px;
    border-bottom: none;
    grid-template-columns: none;
    grid-template-rows: none;
    grid-template-areas: none;
    overflow: visible;
  }

  .playerNames .player {
    width: 100%;
    max-width: none;
    min-width: 0;
    grid-area: auto;
    order: 0;
  }

  .playerNames .player.west,
  .playerNames .player.north,
  .playerNames .player.south,
  .playerNames .player.east {
    grid-area: auto;
    order: 0;
  }

  .playerNames .mahjong-table label {
    font-size: 11px;
    margin-bottom: 4px;
    padding: 4px 8px;
  }

  .playerNames .mahjong-table input[type="text"] {
    width: 100%;
    max-width: none;
    min-width: 0;
    box-sizing: border-box;
    display: block;
    font-size: 16px;
    padding: 8px 10px;
    background-color: var(--color-input-bg, #fff);
    color: var(--color-input-text, #333);
    border: 2px solid #51481e96;
  }

  .playerNames__actions {
    width: 100%;
    max-width: none;
    flex: 0 0 auto;
    margin: 4px 0 0;
    padding: 0;
    gap: 8px;
  }

  .playerNames__actions-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .playerNames__start {
    min-height: 44px;
    font-size: 15px;
  }

  .playerNames__actions-grid button {
    min-height: 40px;
    padding: 8px 6px;
    font-size: 12px;
  }

  .playerNames__actions-grid button i {
    margin-right: 4px;
  }

  /* ── 3.12 Инпуты и selects ── */

  input[type="text"]:not(.playerNames input),
  input[type="number"],
  select:not(.app-select__native) {
    padding: 10px;
    font-size: 14px;
  }

  .app-select--header-wind .app-select__trigger {
    font-size: 1.05em;
    padding: 0;
    border: none;
    background: transparent;
    box-shadow: none;
  }

  .app-select--wind .app-select__trigger {
    min-height: 40px;
    padding: 6px 10px;
    font-size: 18px;
  }

  input[type="text"]:not(.playerNames input) {
    width: auto;
  }

  .playerNames .mahjong-table input[type="text"] {
    width: 100%;
    max-width: none;
  }

  /* ── 3.13 Ветер раунда ── */

  .roundWind-wrap p {
    font-size: 16px;
    flex-wrap: wrap;
    width: 100%;
    max-width: 100%;
  }

  .roundWind-title__label {
    flex-wrap: wrap;
    justify-content: center;
    max-width: 100%;
  }

  .roundWind-title__text {
    white-space: normal;
    text-align: center;
  }
}

/* ── 4. ≤485px: компактная мобильная ── */

@media (max-width: 485px) {
  .round-cards__grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .score-cards__grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .history-player-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    margin: 0 0 10px;
  }

  #history .history-round-title {
    max-width: 140px;
  }

  /* ── 4.1 Модальные окна ── */

  .modal {
    padding: 8px;
  }

  .modal-content {
    width: min(94vw, 420px);
    padding: 14px;
  }

  .modal-content--hand-calculator {
    width: min(98vw, 1280px);
    padding: 12px;
    height: calc(100dvh - 16px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    max-height: calc(100dvh - 16px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  }

  .modal-content--dialog:has(.score-explanation) {
    width: min(94vw, 520px);
  }

  .score-explanation {
    gap: 12px;
  }

  .score-winner {
    padding: 12px;
  }

  .score-row {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto minmax(46px, 46px);
    gap: 6px 8px;
    padding: 9px 10px;
  }

  .score-row__players {
    gap: 6px;
  }

  .score-row__formula {
    flex-wrap: wrap;
    row-gap: 4px;
  }

  /* ── 4.2 Select ветра ── */

  .app-select--wind .app-select__trigger {
    padding: 0 8px;
    min-height: 36px;
    background-color: transparent;
    border: none;
    box-shadow: none;
    font-weight: 600;
    font-size: 20px;
  }

  .app-select.is-round-wind .app-select__trigger {
    box-shadow: none;
  }

  /* ── 4.3 Компактные секции и индикаторы ── */

  .section {
    margin: 5px 0px;
    padding: 5px;
  }

  

  

  

  .input-group button {
    font-size: 11px;
    padding: 6px 10px;
  }

  

  .score-delta {
    min-width: 35px;
    padding: 2px 6px;
    font-size: 11px;
  }

  .history-player-card .score-delta {
    min-width: 48px;
    width: 48px;
    padding: 2px 6px;
    font-size: 11px;
  }

  

  

  /* ── 4.4 Меню ── */

  .menu-wrap {
    padding: 6px 12px;
    gap: 2px;
  }

  .menu-wrap:hover .hamburger,
  .menu-wrap:hover .reload-button,
  .menu-wrap:hover .save-button,
  .menu-wrap:hover .load-button,
  .menu-wrap:hover .server-games-button,
  .menu-wrap:hover .rules-button,
  .menu-wrap:hover .theme-button {
    width: 34px;
    min-width: 0;
    max-width: 40px;
    height: 34px;
  }

  .hamburger,
  .reload-button,
  .save-button,
  .load-button,
  .server-games-button,
  .rules-button,
  .theme-button {
    width: 34px;
    min-width: 0;
    max-width: 40px;
    height: 34px;
    font-size: 22px;
  }

  .reload-icon,
  .save-icon,
  .load-icon,
  .server-games-icon,
  .theme-icon {
    width: 34px;
    height: 34px;
  }

  .theme-icon-svg {
    width: 20px;
    height: 20px;
    min-width: 20px;
    min-height: 20px;
  }

  /* ── 4.5 Панель ввода имён ── */

  .playerNames {
    --panel-edge: 8px;
    --mobile-menu-clearance: calc(76px + env(safe-area-inset-bottom, 0px));
  }

  .playerNames__content {
    padding: 10px 10px 12px;
    gap: 8px;
  }

  .playerNames .mahjong-table {
    gap: 8px;
  }

  .playerNames__actions-grid button {
    font-size: 11px;
    min-height: 38px;
    padding: 7px 4px;
  }

  .playerNames__actions-grid button i {
    margin-right: 2px;
  }
}
