/* Mobile controls: one aligned action row and a full-width search row. */
@media (max-width: 800px), (pointer: coarse) {
  .header .vr-header-search input,
  .vr-search-field input { font-size: 16px; }
}

@media (max-width: 800px) {
  .header .header-inner {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px 8px;
    padding: 10px max(16px, env(safe-area-inset-right, 0px))
      12px max(16px, env(safe-area-inset-left, 0px));
  }
  .header .brand { min-width: 0; gap: 8px; }
  .header .brand b { width: 32px; height: 32px; flex: 0 0 32px; font-size: 24px; }
  .header .brand span {
    font-size: clamp(15px, 4.2vw, 18px);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .header .header-actions { gap: 4px; margin: 0; flex-shrink: 0; }
  .header .header-actions .icon-button,
  .header .header-actions #account {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    min-height: 44px;
    flex: 0 0 44px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel);
    color: var(--text);
  }
  .header .header-actions #theme { font-size: 23px; line-height: 1; }
  .header .header-actions #account { position: relative; font-size: 0; }
  .header .header-actions #account:before {
    content: "";
    position: absolute;
    inset: 0;
    margin: auto;
    display: block;
    width: 20px;
    height: 20px;
    background: currentColor;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.7'%3E%3Cpath d='M20 21v-3a5 5 0 0 0-5-5H9a5 5 0 0 0-5 5v3M16 5a4 4 0 1 1-8 0 4 4 0 0 1 8 0'/%3E%3C/svg%3E") center/contain no-repeat;
  }
  .header .header-actions .wallet-pill,
  .header .header-actions #dashboard-link { display: none; }
  .header .rg-badge { top: 1px; right: 1px; }
  .header .vr-header-search {
    grid-column: 1 / -1;
    order: 3;
    min-width: 0;
    min-height: 46px;
    height: 46px;
    margin: 0 !important;
    padding: 0 13px;
    border-radius: 14px;
    background: var(--bg);
  }
  .header .vr-header-search input { min-height: 44px; margin: 0; }
  .header .vr-header-search > svg { flex: 0 0 18px; width: 18px; height: 18px; }
  .header .rg-search-results {
    width: 100%;
    max-height: max(80px, calc(var(--vr-visual-height, 100dvh) - var(--header-height, 123px) - 96px));
    overscroll-behavior: contain;
  }
  .header .rg-notification-menu {
    max-height: max(80px, calc(var(--vr-visual-height, 100dvh) - var(--header-height, 123px) - 96px));
    overscroll-behavior: contain;
  }
  /* Preserve the compact chapter header and staff navigation. */
  .vr-reading .header .vr-header-search,
  .admin-mode .header .vr-header-search { display: none !important; }
  .admin-mode .header .header-inner { display: flex; }
}

@media (max-width: 700px) {
  body:not(.admin-mode) { padding-bottom: calc(84px + env(safe-area-inset-bottom, 0px)); }
  body:not(.admin-mode) .vr-bottom-nav {
    display: flex;
    position: fixed;
    top: auto;
    bottom: var(--vr-visual-inset, 0px);
    left: 0;
    right: 0;
    height: calc(68px + env(safe-area-inset-bottom, 0px));
    padding: 6px max(8px, env(safe-area-inset-right, 0px))
      calc(6px + env(safe-area-inset-bottom, 0px))
      max(8px, env(safe-area-inset-left, 0px));
    transform: none;
    backface-visibility: hidden;
    transition: none;
    opacity: 1;
    pointer-events: auto;
  }
  .vr-bottom-nav a { min-width: 0; min-height: 48px; font-size: 10px; gap: 4px; }
  body:not(.admin-mode).vr-chrome-hidden .vr-bottom-nav {
    transform: none;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
  }
}
