/* Мобильная версия: телефон, планшет, узкие окна.
   Раскладка одна и та же, меняются размеры, отступы и порядок блоков. */

/* Крупные пальцы: увеличиваем зоны нажатия. Идёт первым, чтобы на телефоне
   действовали более точные размеры ниже. */
@media (pointer: coarse) {
  .btn { min-height: 48px; }
  .chip { padding: 10px 15px; }
  .friend-choices .btn { min-height: 46px; }
  .key { min-height: 44px; }
  .dpad { width: 64px; height: 64px; }
  .phone-soft { height: 28px; }
}

@media (max-width: 720px) {
  :root {
    --radius-l: 18px;
  }

  html, body {
    overflow: hidden;
  }

  .app {
    height: 100dvh;
  }

  .scene {
    height: 100dvh;
  }

  .sound-toggle {
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
  }
  .sound-toggle svg { width: 16px; height: 16px; }

  /* ---------- Обложка ---------- */

  .cover {
    align-items: flex-end;
    padding: 20px 18px 26px;
  }
  .cover h1 { font-size: clamp(38px, 12vw, 56px); }
  .cover-part { font-size: 16px; margin-bottom: 16px; }
  .cover-lead { font-size: 15.5px; margin-bottom: 20px; }
  .cover-actions { max-width: none; gap: 9px; }
  .cover-actions .btn { min-height: 48px; font-size: 15px; }
  .cover-note { font-size: 11.5px; margin-top: 18px; }
  .cover-nudge { flex-direction: column; align-items: flex-start; gap: 10px; }
  .cover-nudge .btn { margin-left: 0; }

  /* ---------- Вступление и справка ---------- */

  .intro { padding: 16px; align-items: flex-start; }
  .intro-card { padding: 20px 18px; border-radius: 18px; }
  .intro-card h2 { font-size: 24px; }
  .chip { padding: 8px 13px; font-size: 13.5px; }
  .btn { min-height: 48px; font-size: 15px; }

  .doc, .journal, .ending { padding: 46px 16px 22px; }
  .doc-inner, .journal-inner { max-width: none; }
  .doc h2, .journal h2 { font-size: 26px; }
  .doc-step { grid-template-columns: 32px 1fr; gap: 12px; padding: 14px; }
  .stats-bar { grid-template-columns: 120px 1fr 34px; font-size: 13px; }
  .ending-row { grid-template-columns: 1fr; gap: 3px; }
  .ending-row b { font-size: 15px; }
  .ending-actions .btn { flex: 1 1 100%; }

  /* ---------- Сцена «Старый друг» ---------- */

  .friend { padding: 16px 14px 22px; justify-content: flex-end; }
  .friend-line {
    padding: 16px 18px;
    font-size: 19px;
    border-radius: 16px;
    min-height: 64px;
  }
  .friend-choices { gap: 8px; }
  .friend-choices .btn {
    flex: 1 1 calc(50% - 8px);
    min-height: 44px;
    padding: 9px 12px;
    font-size: 14px;
  }
  .friend-progress { margin-top: 18px; }

  /* ---------- Телефон ---------- */

  .phone-stage {
    padding: 8px 8px 12px;
    gap: 8px;
    justify-content: flex-start;
    overflow: hidden;
  }
  .phone {
    width: min(252px, 72vw);
    padding: 11px 11px 14px;
    border-radius: 24px 24px 32px 32px / 22px 22px 42px 42px;
    flex: 0 0 auto;
  }
  .lcd { min-height: 168px; max-height: 190px; font-size: 12.5px; padding: 8px 10px; }
  .lcd-bar { font-size: 9.5px; margin-bottom: 4px; }
  .phone-brand { font-size: 9px; letter-spacing: 0.26em; margin-bottom: 6px; }
  .phone-nav { margin: 8px 2px 7px; gap: 7px; }
  .dpad { width: 56px; height: 56px; }
  .dpad-center { width: 24px; height: 24px; font-size: 8.5px; }
  .dpad-arrow { font-size: 11px; }
  .phone-soft { height: 24px; font-size: 9.5px; }
  .keypad { gap: 5px; }
  .key { min-height: 38px; border-radius: 9px 9px 12px 12px; padding: 6px 2px 5px; }
  .key b { font-size: 14px; }
  .key span { font-size: 7px; min-height: 9px; }
  .contact-list {
    flex: 1 1 auto;
    max-height: none;
    min-height: 110px;
    padding: 6px;
  }
  .contact-row { padding: 9px 10px; gap: 10px; }
  .contact-about { display: none; }
  .contact-letter { width: 30px; height: 30px; font-size: 14px; }
  .contact-name { font-size: 14px; }
  .contact-role { font-size: 11.5px; }
  .phone-hint { font-size: 11px; flex: 0 0 auto; line-height: 1.35; }

  .ritual { padding: 14px; }
  .ritual-card { padding: 22px 18px; border-radius: 18px; }
  .ritual-card h2 { font-size: 22px; }
  .ritual-card ul { font-size: 14px; }
  .ritual-actions .btn { flex: 1 1 100%; }

  /* ---------- Чат ---------- */

  .chat-shell { width: 100vw; height: 100dvh; border-radius: 0; border: 0; }
  .chat-head { padding: 10px 44px 10px 12px; gap: 9px; }
  .chat-back { width: 32px; height: 32px; }
  .chat-avatar { width: 34px; height: 34px; font-size: 14px; }
  .chat-name { font-size: 14px; }
  .chat-role { font-size: 11px; }
  .chat-status { display: none; }
  .chat-finish { font-size: 12px; padding: 7px 11px; }
  .chat-body { padding: 14px 12px 6px; gap: 8px; }
  .msg { max-width: 90%; }
  .msg-body { font-size: 14.5px; padding: 10px 13px; }
  .chat-chips {
    padding: 8px 12px 0;
    -webkit-mask-image: linear-gradient(90deg, #000 0%, #000 88%, transparent 100%);
    mask-image: linear-gradient(90deg, #000 0%, #000 88%, transparent 100%);
  }
  .chat-chip { font-size: 12.5px; padding: 7px 12px; }
  .chat-input { padding: 10px 12px 6px; gap: 8px; }
  .chat-field { padding: 11px 14px; font-size: 16px; }
  .chat-send { width: 42px; height: 42px; }
  .chat-foot { font-size: 10.5px; padding: 4px 12px 10px; }
  .chat-summary { padding: 14px; }
  .chat-summary-row { grid-template-columns: 1fr; gap: 2px; }
  .chat-summary-row span { font-size: 10.5px; }
  .chat-summary-row b { font-size: 14px; }
}

@media (max-width: 720px) and (orientation: landscape) {
  .friend-line { font-size: 17px; }
  .phone-stage { flex-direction: row; align-items: center; justify-content: center; }
  .phone { width: 220px; }
  .lcd { min-height: 150px; max-height: 170px; font-size: 12px; }
  .contact-list { max-height: 46vh; width: 46vw; }
}

/* Не даём тексту выделяться при быстрых касаниях, но в поле ввода — можно. */
@media (max-width: 720px) {
  .btn, .chip, .key, .contact-row, .chat-chip, .phone-soft, .friend-line {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }
  .chat-field, .input, .textarea { user-select: text; -webkit-user-select: text; }
}

/* Безопасные зоны на телефонах с вырезом. */
@supports (padding: max(0px)) {
  @media (max-width: 720px) {
    .chat-input { padding-bottom: max(6px, env(safe-area-inset-bottom)); }
    .chat-foot { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
    .cover { padding-bottom: max(26px, env(safe-area-inset-bottom)); }
  }
}
