/* Мобильная адаптация «Инцидент: игра Хакадемии».
   Подключается после стилей бандла и срабатывает только на узких экранах
   (портрет телефона) и на низких широких экранах (телефон в ландшафте).
   Десктопную вёрстку не меняет. */

@media (max-width: 820px), ((max-width: 950px) and (max-height: 500px)) {

  /* --- каркас: разрешаем вертикальный скролл страницы --- */
  html, body {
    min-width: 0;
    min-height: 0;
    overflow: visible;
    overflow-x: hidden;
  }

  body {
    min-height: 100svh;
    /* место под закреплённую кнопку «закончить ход» */
    padding-bottom: 84px;
  }

  .app-shell {
    height: auto;
    min-height: 100svh;
    grid-template-rows: auto minmax(0, 1fr);
  }

  /* --- шапка: две строки вместо трёх колонок --- */
  .topbar {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 6px 12px;
    padding: 10px 12px;
  }

  .topbar h1 {
    font-size: 16px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .turn-status {
    grid-column: 1;
    grid-row: 2;
    gap: 12px;
  }

  #reset-button {
    grid-column: 2;
    grid-row: 1 / span 2;
    align-self: center;
  }

  /* --- рабочая область: стол сверху, панель снизу --- */
  .workspace {
    display: block;
    min-height: 0;
  }

  .table-wrap {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    height: 48svh;
    min-height: 300px;
  }

  .table-caption {
    bottom: 10px;
    left: 12px;
    right: 12px;
  }

  /* подсказка «наведите на карту…» не про телефон */
  #table-hint {
    visibility: hidden;
  }

  .match-tooltip {
    max-width: min(240px, 70vw);
  }

  /* --- панель карт: естественная высота, свой скролл только у списка --- */
  .inspector {
    display: block;
    min-height: 0;
  }

  .card-detail {
    padding: 16px 14px 14px;
    overflow: visible;
  }

  .card-text {
    font-size: 15px;
  }

  .open-cards {
    padding: 12px 8px 8px;
    overflow: visible;
  }

  .card-list {
    max-height: 48svh;
  }

  .card-list-item {
    padding: 10px 9px;
  }

  .card-list-copy {
    font-size: 13px;
  }

  .inspector-footer {
    padding: 10px 10px 12px;
  }

  /* --- кнопка «закончить ход»: закреплена внизу экрана --- */
  .end-turn {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: max(12px, env(safe-area-inset-bottom));
    min-width: 0;
    min-height: 52px;
  }

  /* --- уведомления --- */
  .notice {
    max-width: calc(100vw - 24px);
    width: max-content;
    top: 64px;
  }

  /* --- диалоги (правила и развязка) --- */
  .dialog {
    padding: 20px 14px;
  }

  .dialog h2 {
    font-size: 24px;
  }

  .dialog--intro,
  .dialog--final {
    width: calc(100vw - 16px);
    max-height: calc(100svh - 16px);
  }

  .rule-setup {
    grid-template-columns: 1fr 1fr;
  }

  .class-key {
    grid-template-columns: repeat(3, 1fr);
  }

  .class-key canvas {
    width: 64px;
    height: 64px;
  }

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

  .action-key {
    gap: 8px;
  }

  .rule-action-circle {
    width: 92px;
    height: 92px;
    font-size: 10px;
  }

  .rule-action-circle--small {
    width: 84px;
    height: 84px;
  }

  .match-example {
    flex-wrap: wrap;
  }

  .turn-steps {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .turn-steps li {
    min-height: 0;
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr);
    align-items: baseline;
    column-gap: 8px;
    padding: 10px 12px;
  }

  .turn-steps li:before {
    margin-bottom: 0;
  }

  .turn-steps b,
  .turn-steps span {
    grid-column: 2;
  }

  .rule-notes {
    grid-template-columns: 1fr;
  }

  .rule-notes section {
    min-height: 0;
  }

  .glossary dl {
    grid-template-columns: 1fr;
  }

  /* --- финальный экран --- */
  .score-line strong {
    font-size: 48px;
  }

  .rank {
    font-size: 22px;
  }

  .score-scale {
    grid-template-columns: 1fr 1fr;
  }

  .debrief-list {
    grid-template-columns: 1fr;
  }
}

/* Ландшафт телефона: как на десктопе — экран без скролла страницы,
   стол слева, панель справа, но всё компактнее */
@media (max-width: 950px) and (max-height: 500px) {
  html, body {
    overflow: hidden;
  }

  body {
    padding-bottom: 0;
  }

  .app-shell {
    height: 100svh;
    min-height: 0;
  }

  .topbar {
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 12px;
    padding: 6px 12px;
  }

  .turn-status,
  #reset-button {
    grid-column: auto;
    grid-row: auto;
  }

  .workspace {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(280px, 38vw);
    min-height: 0;
  }

  .table-wrap {
    border-right: 1px solid var(--line);
    border-bottom: 0;
    height: auto;
    min-height: 0;
  }

  .inspector {
    display: grid;
    grid-template-rows: minmax(140px, auto) minmax(0, 1fr) auto;
    min-height: 0;
  }

  .card-detail {
    padding: 12px 12px 10px;
    overflow: auto;
  }

  .open-cards {
    padding: 10px 8px 6px;
    overflow: hidden;
  }

  .card-list {
    max-height: calc(100% - 28px);
  }

  .end-turn {
    position: absolute;
    left: auto;
    right: 12px;
    bottom: 12px;
    min-width: 0;
    min-height: 44px;
    padding: 8px 14px;
    font-size: 15px;
  }
}

/* Портрет: стол шире экрана с горизонтальной прокруткой,
   чтобы все шесть карт ряда были видны целиком */
@media (max-width: 820px) and (min-height: 501px) {
  .workspace {
    min-width: 0;
    max-width: 100%;
  }

  .table-wrap {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
  }

  #table {
    width: 760px;
    height: 100%;
  }

  .table-caption {
    position: sticky;
    left: 12px;
    right: auto;
    width: calc(100vw - 24px);
  }
}
