/* Phone-only viewport and keyboard layout; desktop keeps its existing styling. */
@media (max-width: 600px), (max-width: 1024px) and (max-height: 600px) and (hover: none) and (pointer: coarse) {
  html,
  body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  body {
    position: fixed;
    inset: 0;
  }

  .app-shell {
    position: fixed;
    top: var(--phone-viewport-top, 0px);
    right: 0;
    left: 0;
    height: 100dvh;
    height: var(--phone-viewport-height, 100dvh);
    min-height: 0;
    padding-right: env(safe-area-inset-right, 0px);
    padding-left: env(safe-area-inset-left, 0px);
    background: var(--bg);
    touch-action: manipulation;
  }

  .sidebar {
    padding-top: calc(8px + env(safe-area-inset-top, 0px));
    background: var(--bg);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .chat-panel {
    grid-template-rows: minmax(0, 1fr) auto auto auto;
  }

  .messages {
    grid-row: 1;
    min-width: 0;
    overflow-x: hidden;
    overflow-y: auto;
    scrollbar-gutter: auto;
  }

  .message,
  .bubble {
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .history-storage-status {
    grid-row: 2;
  }

  .composer {
    grid-row: 3;
    padding-bottom: 8px;
  }

  .composer-shell {
    transform: none;
  }

  #messageInput,
  #languageSearch,
  #chatSearchInput {
    /* iPhone focus zoom is triggered by editable text smaller than 16px. */
    font-size: max(16px, 1em);
  }

  #messageInput {
    min-height: calc(2.9em + 10px);
    max-height: min(172px, calc(var(--phone-viewport-height, 100dvh) * 0.25));
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .privacy-note {
    grid-row: 4;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  }

  .phone-input-active .privacy-note,
  .phone-keyboard-open .privacy-note {
    display: none;
  }

  .phone-input-active:not(.phone-keyboard-open) .composer {
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  }

  .top-actions,
  .language-menu {
    position: static;
  }

  .top-actions {
    align-self: center;
  }

  .language-panel {
    position: absolute;
    top: calc(100% + 8px);
    right: 10px;
    left: 10px;
    max-height: max(100px, calc(var(--phone-viewport-height, 100dvh) - 140px - env(safe-area-inset-top, 0px)));
  }

  .language-list,
  .history-panel {
    max-height: max(80px, calc(var(--phone-viewport-height, 100dvh) - 230px - env(safe-area-inset-top, 0px)));
  }

  .source-menu {
    max-height: max(80px, calc(var(--phone-viewport-height, 100dvh) - 250px - env(safe-area-inset-top, 0px)));
  }
}
