/* Layout is selected by viewport size, not by browser/user-agent detection. */
@media (max-width: 760px), (max-width: 1100px) and (max-height: 500px) {
  :root {
    --mobile-header: 56px;
    --mobile-bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  }
  html,
  body {
    width: 100%;
    height: var(--app-height, 100dvh);
    overflow: hidden;
    overscroll-behavior: none;
  }
  header {
    height: var(--mobile-header);
    padding: 0 max(12px, env(safe-area-inset-left)) 0
      max(12px, env(safe-area-inset-right));
    gap: 8px;
  }
  .brand {
    gap: 7px;
    min-width: 0;
  }
  .brand strong {
    font-size: 23px;
  }
  .brand [data-icon] .icon {
    width: 24px;
    height: 24px;
  }
  header nav {
    display: none;
  }
  .connection {
    margin-left: auto;
    max-width: 110px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 6px 8px;
    font-size: 10px;
  }
  #settings {
    width: 36px;
    height: 40px;
    flex-shrink: 0;
  }
  main {
    height: calc(var(--app-height, 100dvh) - var(--mobile-header));
    width: 100%;
    overflow: hidden;
  }
  #map,
  .has-sidebar #map {
    width: 100%;
    height: 100%;
    touch-action: none;
  }
  .top-left {
    top: 8px;
    left: max(8px, env(safe-area-inset-left));
  }
  .top-left .square {
    width: 44px;
    height: 44px;
  }
  .date-pill,
  .has-sidebar .date-pill {
    top: 8px;
    right: max(8px, env(safe-area-inset-right));
    width: calc(100% - 72px);
    max-width: 300px;
    min-width: 0;
    height: 52px;
    padding: 6px 8px;
    gap: 6px;
    border-radius: 14px;
  }
  .date-pill #date {
    font-size: 14px;
    min-width: 0;
    white-space: normal;
    line-height: 18px;
  }
  .date-pill > button:first-child,
  .date-pill > button:last-child {
    width: 36px;
    height: 40px;
    flex-shrink: 0;
    padding: 6px;
  }
  .jump-widget-caption {
    font-size: 10px;
    line-height: 12px;
  }
  .bottom-left {
    bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    left: max(8px, env(safe-area-inset-left));
    gap: 6px;
  }
  .dock {
    padding: 8px;
    gap: 6px;
  }
  .dock button {
    width: 44px;
    height: 44px;
  }
  .bottom-left > .square {
    width: 44px;
    height: 44px;
    border-radius: 12px;
  }
  .bottom-right,
  .has-sidebar .bottom-right {
    right: max(8px, env(safe-area-inset-right));
    bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  }
  #country {
    width: 44px;
    height: 44px;
    padding: 4px;
  }
  .bottom-right #country .flag {
    width: 34px;
    height: 25px;
  }
  .panel,
  .right,
  #left[data-panel="jump"],
  #left[data-panel="search"],
  .has-sidebar #right {
    left: 8px;
    right: 8px;
    top: auto;
    bottom: var(--mobile-bottom);
    height: calc(100% - var(--mobile-bottom) - 72px);
    max-height: calc(100% - 72px);
    width: auto;
    max-width: none;
    min-width: 0;
    border-radius: 16px;
    padding-left: 0;
    z-index: 4;
  }
  .panel-head,
  .has-sidebar #right .panel-head {
    padding: 12px 16px;
    min-height: 52px;
    height: auto;
    gap: 8px;
  }
  .panel-head h2 {
    font-size: 18px;
    line-height: 24px;
    min-width: 0;
    overflow-wrap: anywhere;
  }
  .panel-head button {
    width: 36px;
    height: 36px;
    padding: 8px;
    flex-shrink: 0;
  }
  .panel-body,
  .has-sidebar #right .panel-body {
    padding: 14px 16px;
    min-height: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }
  .panel-foot,
  .has-sidebar #right .panel-foot {
    padding: 10px 12px;
    flex-shrink: 0;
  }
  .panel p {
    font-size: 16px;
  }
  .panel .muted {
    font-size: 14px;
  }
  .has-sidebar #right {
    padding-left: 44px;
  }
  .has-sidebar #right .panel-head {
    padding-left: 8px;
  }
  #sidebar-tabs {
    left: 12px;
    right: auto;
    top: 80px;
    width: 40px;
    z-index: 5;
    gap: 6px;
  }
  #sidebar-tabs button {
    width: 36px;
    height: 40px;
    padding: 8px;
  }
  .composer {
    gap: 6px;
  }
  .composer textarea {
    font-size: 16px !important;
    min-height: 44px;
    max-height: 112px;
    resize: none;
    padding: 10px;
    line-height: 24px;
  }
  .composer button {
    width: 44px;
    height: 44px;
    padding: 10px;
  }
  .composer-field {
    padding-right: 4px;
  }
  .composer-field button {
    width: 32px;
    height: 44px;
    padding: 6px;
  }
  .chat-card {
    padding: 12px;
    gap: 12px;
    min-height: 76px;
  }
  .chat-card .preview {
    max-width: 100%;
    word-break: break-word;
  }
  .chat-card .grow {
    min-width: 0;
  }
  .chat-card .flag {
    width: 34px;
    height: 34px;
  }
  #new-chat {
    width: 100%;
    min-height: 68px;
  }
  .action .actions {
    opacity: 1;
  }
  .action .actions button {
    padding: 8px;
    min-height: 36px;
  }
  .speaker-options select {
    width: 100%;
    min-width: 0;
  }
  .speaker-options > .row {
    flex-wrap: wrap;
  }
  .advisor-suggestions {
    gap: 6px;
    margin-bottom: 10px;
  }
  .advisor-suggestions button {
    font-size: 12px;
    padding: 5px 10px;
  }
  #left[data-panel="menu"] {
    top: 60px;
    bottom: var(--mobile-bottom);
    height: auto;
    max-height: none;
    width: min(320px, calc(100% - 16px));
    left: 8px;
    right: auto;
  }
  #left[data-panel="search"] {
    height: min(380px, calc(100% - var(--mobile-bottom) - 72px));
  }
  #left[data-panel="jump"] .panel-head {
    min-height: 68px;
  }
  #left[data-panel="jump"] .panel-body {
    padding: 20px 16px;
    text-align: center;
  }
  #auto-jump {
    font-size: 16px;
    width: 100%;
    padding: 10px 12px;
    line-height: 22px;
  }
  .timeline {
    gap: 20px;
    padding: 20px 0;
  }
  .timeline .now {
    width: 76px;
    height: 76px;
  }
  .jump-settings input {
    min-width: 0;
  }
  .jump-settings > .row {
    flex-wrap: wrap;
  }
  .jump-settings #custom-date {
    flex: 1;
  }
  .jump-settings #custom-jump {
    height: 44px;
  }
  dialog {
    width: calc(100% - 16px);
    max-width: calc(100% - 16px);
    max-height: calc(var(--app-height, 100dvh) - 24px);
    border-radius: 16px;
    padding: 0;
    margin: auto;
  }
  .modal-head {
    padding: 12px 16px;
  }
  .modal-head button {
    width: 36px;
    height: 36px;
    padding: 8px;
  }
  .modal-body {
    padding: 14px 16px;
    max-height: calc(var(--app-height, 100dvh) - 160px);
    overflow: auto;
  }
  .modal-foot {
    padding: 12px 16px;
  }
  input,
  select,
  textarea {
    font-size: 16px !important;
    max-width: 100%;
  }
  .row {
    min-width: 0;
  }
  .row > * {
    min-width: 0;
  }
  select {
    min-height: 44px;
  }
  .search-results button {
    min-height: 48px;
  }
  .country-picker button {
    min-height: 52px;
  }
  #playback,
  #generating {
    left: 8px;
    right: 8px;
    transform: none;
    min-width: 0;
    max-width: none;
    width: auto;
    bottom: var(--mobile-bottom);
    padding: 12px 14px;
    z-index: 6;
  }
  #playback > div:last-child {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
  }
  #playback button,
  #generating button {
    min-height: 44px;
    font-size: 13px;
    padding: 8px 10px;
    margin: 0;
  }
  #generation-status {
    font-size: 14px;
  }
  #notice {
    top: 68px;
    left: 8px;
    right: 8px;
    transform: none;
    max-width: none;
    padding: 12px 16px;
    font-size: 14px;
  }
  #map-tip {
    max-width: calc(100% - 16px);
  }
  .map-zoom {
    display: none;
  }
  .keyboard-open .panel,
  .keyboard-open .has-sidebar #right {
    top: 4px;
    bottom: 4px;
    height: calc(100% - 8px);
    max-height: none;
  }
  .keyboard-open #sidebar-tabs {
    top: 12px;
  }
  .keyboard-open .bottom-left,
  .keyboard-open .bottom-right,
  .keyboard-open .date-pill,
  .keyboard-open .top-left {
    visibility: hidden;
  }
}
@media (max-width: 1100px) and (max-height: 500px) {
  :root {
    --mobile-header: 44px;
    --mobile-bottom: 58px;
  }
  header {
    height: 44px;
  }
  .dock {
    padding: 4px;
  }
  .dock button {
    height: 40px;
    width: 40px;
  }
  .panel,
  .right,
  .has-sidebar #right {
    top: 60px;
    bottom: var(--mobile-bottom);
    height: auto;
  }
  .panel-head {
    padding: 6px 12px;
    min-height: 40px;
  }
  .date-pill {
    height: 44px;
    top: 4px;
  }
  .top-left {
    top: 4px;
  }
  .panel-foot {
    padding: 6px 10px;
  }
  #sidebar-tabs {
    top: 68px;
  }
  #left[data-panel="menu"] {
    top: 52px;
  }
  .panel-body {
    padding: 8px 12px;
  }
}
