/* Mobile shell (phones only, < 768px): compact top bar, bottom tab bar and a
   full-screen search. Built by assets/js/mobile-shell.js. Desktop is untouched:
   everything here sits inside the media query, and the shell's own elements are
   hidden at md and up. */

#na-tabbar, #na-m-search, #na-actionbar, .na-m-only { display: none; }

@media (max-width: 767.98px) {
   .na-m-hide { display: none !important; }
   .na-m-only { display: inline-flex; }

   body.na-shell { padding-bottom: calc(74px + env(safe-area-inset-bottom, 0px)); }

   /* ── Bottom tab bar ─────────────────────────────────────────────────── */
   #na-tabbar {
      position: fixed; left: 0; right: 0; bottom: 0; z-index: 150;
      display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
      height: calc(64px + env(safe-area-inset-bottom, 0px));
      padding: 4px 8px env(safe-area-inset-bottom, 0px);
      background: rgba(12, 12, 15, 0.97);
      -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
      border-top: 1px solid rgba(255, 255, 255, 0.08);
   }
   #na-tabbar a, #na-tabbar button {
      border: 0; background: transparent; padding: 0; font-family: inherit;
      display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
      font-size: 10.5px; font-weight: 700; color: #a1a1aa; text-decoration: none;
      -webkit-tap-highlight-color: transparent;
   }
   #na-tabbar a .material-symbols-outlined, #na-tabbar button .material-symbols-outlined { font-size: 24px; }
   #na-tabbar a[aria-current="page"] { color: #c084fc; }
   #na-tabbar a[aria-current="page"] .material-symbols-outlined { font-variation-settings: 'FILL' 1; }

   /* ── Full-screen search ─────────────────────────────────────────────── */
   #na-m-search {
      position: fixed; inset: 0; z-index: 400; flex-direction: column;
      background: #09090b; color: #fafafa; overflow-y: auto;
   }
   #na-m-search.is-open { display: flex; }
   #na-m-search .na-ms-head {
      position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 4px;
      padding: 10px 12px 10px 6px; background: #09090b; border-bottom: 1px solid rgba(255, 255, 255, 0.06);
   }
   #na-m-search .na-ms-slot { flex: 1; min-width: 0; }
   #na-m-search .na-ms-slot input {
      height: 46px; border-radius: 12px !important;
      border-color: rgba(168, 85, 247, 0.55) !important; background: #141417 !important;
   }
   /* nav-search.js's dropdown stays out of the overlay: results render inline. */
   #na-m-search [data-search-panel] { display: none !important; }
   #na-m-search .na-ms-slot > div { position: relative; }
   #na-m-search .na-ms-slot input { font-size: 16px !important; padding-right: 44px !important; }
   #na-m-search .na-ms-clear {
      position: absolute; right: 4px; top: 50%; width: 38px; height: 38px; margin-top: -19px;
      display: inline-flex; align-items: center; justify-content: center; border: 0; background: transparent; color: #71717a;
   }
   #na-m-search .na-ms-clear[hidden] { display: none; }
   #na-m-search .na-ms-clear .material-symbols-outlined { font-size: 19px; }
   #na-m-search.has-query .na-ms-body { padding-bottom: 96px; }
   #na-m-search [data-ms-results] { display: flex; flex-direction: column; gap: 18px; }
   #na-m-search [data-ms-results][hidden] { display: none; }
   #na-m-search .na-ms-empty { margin: 0; font-size: 13px; color: #71717a; }
   #na-m-search .na-ms-hit {
      min-height: 64px; padding: 8px 0; display: flex; align-items: center; gap: 12px;
      color: #fafafa; text-decoration: none; border-top: 1px solid rgba(255, 255, 255, 0.05);
   }
   #na-m-search .na-ms-hit:first-of-type { border-top: 0; }
   #na-m-search .na-ms-cover { width: 40px; height: 58px; flex-shrink: 0; border-radius: 5px; overflow: hidden; background: #1c1730; }
   #na-m-search .na-ms-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
   #na-m-search .na-ms-hit-text { min-width: 0; flex: 1; }
   #na-m-search .na-ms-hit-title {
      display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
      font-size: 14px; font-weight: 700; line-height: 1.3;
   }
   #na-m-search .na-ms-hit-meta { display: block; margin-top: 2px; font-size: 12px; color: #71717a; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
   #na-m-search mark { background: transparent; color: #c084fc; }
   #na-m-search .na-ms-author { min-height: 48px; display: flex; align-items: center; gap: 12px; color: #fafafa; text-decoration: none; font-size: 14px; font-weight: 600; }
   #na-m-search .na-ms-author-icon {
      width: 36px; height: 36px; flex-shrink: 0; border-radius: 999px; background: #27272a; color: #a1a1aa;
      display: inline-flex; align-items: center; justify-content: center;
   }
   #na-m-search .na-ms-author-icon .material-symbols-outlined { font-size: 19px; }
   #na-m-search .na-ms-dim { color: #71717a; font-weight: 500; }
   #na-m-search .na-ms-labelrow { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
   #na-m-search .na-ms-labelrow .na-ms-label { margin: 0; }
   #na-m-search .na-ms-clearall { min-height: 36px; padding: 0 4px; border: 0; background: transparent; color: #c084fc; font-size: 11px; font-weight: 800; }
   #na-m-search button.na-ms-chip { background: #18181b; }
   #na-m-search .na-ms-chip.na-ms-genre { border-radius: 8px; color: #a1a1aa; }
   #na-m-search .na-ms-all {
      position: fixed; left: 16px; right: 16px; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); z-index: 3; height: 50px;
      display: flex; align-items: center; justify-content: center; gap: 6px; padding: 0 14px; border-radius: 12px;
      background: #18181b; border: 1px solid rgba(255, 255, 255, 0.1); color: #e4e4e7; font-size: 13px; font-weight: 800; text-decoration: none;
      box-shadow: 0 -12px 24px #09090b;
   }
   #na-m-search .na-ms-all[hidden] { display: none; }
   #na-m-search .na-ms-all > span:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
   #na-m-search .na-ms-all .material-symbols-outlined { font-size: 18px; }
   #na-m-search .na-ms-body { padding: 18px 16px 32px; display: flex; flex-direction: column; gap: 22px; }
   #na-m-search .na-ms-label {
      margin: 0 0 10px; font-size: 10.5px; font-weight: 900; letter-spacing: 0.2em;
      text-transform: uppercase; color: #71717a;
   }
   #na-m-search .na-ms-chips { display: flex; flex-wrap: wrap; gap: 6px; }
   #na-m-search .na-ms-chip {
      display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 12px;
      border-radius: 999px; border: 1px solid rgba(255, 255, 255, 0.1); background: #111114;
      font-size: 12.5px; font-weight: 600; color: #d4d4d8; text-decoration: none;
   }
   #na-m-search .na-ms-chip .material-symbols-outlined { font-size: 16px; color: #71717a; }
   #na-m-search .na-ms-request {
      display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 0 14px;
      border-radius: 12px; border: 1px solid rgba(168, 85, 247, 0.3); background: rgba(168, 85, 247, 0.08);
      color: #e9d5ff; font-size: 13.5px; font-weight: 700; text-decoration: none;
   }
   .na-ms-iconbtn {
      width: 44px; height: 44px; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
      border: 0; background: transparent; color: #a1a1aa; border-radius: 10px;
   }
   body.na-search-open { overflow: hidden; }

   /* ── Pinned action bar (novel page, replaces the tab bar) ───────────── */
   #na-actionbar {
      position: fixed; left: 0; right: 0; bottom: 0; z-index: 150;
      display: grid; grid-template-columns: 52px minmax(0, 1fr); gap: 10px;
      padding: 10px 16px calc(12px + env(safe-area-inset-bottom, 0px));
      background: rgba(12, 12, 15, 0.97);
      -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
      border-top: 1px solid rgba(255, 255, 255, 0.08);
   }
   #na-actionbar .na-ab-list {
      height: 52px; border-radius: 12px; border: 1px solid rgba(255, 255, 255, 0.12);
      background: #18181b; color: #d8b4fe; display: inline-flex; align-items: center; justify-content: center;
   }
   #na-actionbar .na-ab-read {
      height: 52px; border-radius: 12px; background: #a855f7; color: #fff; text-decoration: none;
      display: flex; align-items: center; justify-content: center; gap: 8px; min-width: 0;
      font-size: 12px; font-weight: 900; letter-spacing: 0.14em; text-transform: uppercase;
   }
   #na-actionbar .na-ab-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
   body.na-has-actionbar { padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px)); }

   /* ── Scale pass: one type floor, 44px thumb targets, even icons ──────── */
   /* Text floor: the 8–10px micro labels used across the site read too small
      on a phone. Bumped per Tailwind size class, so desktop keeps its sizes. */
   .text-\[8px\], .text-\[9px\] { font-size: 10.5px !important; }
   .text-\[10px\] { font-size: 11px !important; }
   #na-tabbar a, #na-tabbar button { font-size: 11px; }
   #na-m-search .na-ms-label { font-size: 11px; }
   #na-m-search .na-ms-chip { height: 40px; padding: 0 14px; }

   /* Header: search · chat · bell · login in one centred row, every icon a
      44px box with a 24px glyph so they line up evenly. */
   .na-m-actions { display: flex !important; align-items: center !important; gap: 2px !important; }
   .na-m-actions > a:not(.na-m-hide), .na-m-actions > button:not([data-auth-open]):not(.na-m-hide) {
      width: 44px !important; height: 44px !important; padding: 0 !important; margin: 0 !important;
      display: inline-flex !important; align-items: center !important; justify-content: center !important;
      transform: none !important; color: #a1a1aa;
   }
   .na-m-actions .material-symbols-outlined { font-size: 24px !important; line-height: 1 !important; }
   .na-m-actions svg { width: 24px !important; height: 24px !important; }
   .na-m-actions [data-alert-toggle] { position: relative; }
   .na-m-actions [data-alert-toggle] .na-alert-dot { top: 10px !important; right: 10px !important; }
   .na-m-actions button[data-auth-open] {
      height: 40px !important; min-width: 60px !important; padding: 0 10px !important; margin-left: 4px !important;
      display: inline-flex !important; align-items: center !important; justify-content: center !important;
   }
   /* Signed in: a round person icon (or the avatar picture) instead of a name. */
   .na-m-actions button[data-auth-open].na-m-user,
   .na-m-actions button[data-auth-open].na-m-avatar {
      width: 40px !important; min-width: 40px !important; max-width: 40px !important; padding: 0 !important;
      border-radius: 999px !important; overflow: hidden;
   }
   .na-m-actions button[data-auth-open].na-m-user {
      font-size: 0 !important; background: #27272a !important; border: 1px solid rgba(168, 85, 247, 0.5) !important;
   }
   .na-m-actions button[data-auth-open].na-m-user > * { display: none !important; }
   .na-m-actions button[data-auth-open].na-m-user::before {
      content: "person"; font-family: 'Material Symbols Outlined'; font-size: 24px; line-height: 1;
      font-variation-settings: 'FILL' 1; color: #d8b4fe; -webkit-font-feature-settings: 'liga'; font-feature-settings: 'liga';
   }
   nav:not(#na-tabbar) a[href="/"]:first-child { display: inline-flex; align-items: center; min-height: 44px; }
   #apply-banner { height: 24px !important; font-size: 11px !important; }

   /* Footer links: tall enough to hit. */
   footer nav a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 6px; }

   /* Dialogs that every shell page can open (login, request, alerts). */
   #na-auth-close, #na-request-close { width: 44px !important; height: 44px !important; }
   #na-tab-login, #na-tab-register { min-height: 40px; }
   #na-auth-pw-toggle { width: 40px !important; height: 40px !important; }
   #na-auth-modal a, #na-auth-modal button[type="button"]:not(#na-auth-close):not(#na-auth-pw-toggle) { min-height: 36px; }
   #na-request-cancel, #na-request-submit { min-height: 44px; }
   #na-alert-mark-read, #na-alert-clear-all { min-height: 36px; }

   /* Shared pagination (the library filter sheet is styled in libary.html). */
   #library-prev-page, #library-next-page, #library-page-numbers button { min-height: 44px; min-width: 44px; }

   /* Novel page: rating, read-more, genre chips, comment actions, header icons. */
   #novel-genre-report-btn, #novel-flag-btn { width: 40px !important; height: 40px !important; }
   #novel-rate-btn { min-height: 34px; }
   #novel-author { display: inline-flex; align-items: center; min-height: 32px; }
   #novel-desc-toggle { min-height: 36px; }
   #novel-genres a, #novel-genres span { min-height: 32px; display: inline-flex; align-items: center; }
   #novel-comments-list button { min-height: 36px; }
   #novel-comments-list .material-symbols-outlined { font-size: 17px !important; }
   #novel-chapter-sort, #novel-chapter-filter { min-height: 40px; }
   #novel-source-row button { min-height: 36px; }
   #novel-chapter-showall { min-height: 48px; }
   #novel-chapter-list .na-like-btn { min-height: 36px; min-width: 36px; justify-content: center; }
   #novel-chapter-list .material-symbols-outlined { font-size: 16px !important; }

   /* Home: chapter rows, the All tab, the sign-up button. */
   #home-latest-updates article a[href*="/reader"] { min-height: 40px; }
   main h2 + div > button, main .flex.p-1 > button { min-height: 36px; }
   #home-continue-action { min-height: 40px; }

   /* Profile: section "View all" links. */
   a[href="/my-library"].items-center { min-height: 36px; }

   /* My Library: the per-cover buttons are touch targets now. */
   .lib-remove-btn, .lib-folder-btn, .lib-status-btn { width: 34px !important; height: 34px !important; }
   .lib-remove-btn { top: 2.75rem !important; }
   .lib-folder-btn { top: 5.25rem !important; }
   .lib-status-btn { top: 7.75rem !important; }

   /* Profile */
   #profile-bio-edit-btn { width: 36px !important; height: 36px !important; }

   /* Keyboard-shortcut hints mean nothing on a phone. */
   .kbd, .na-keys-hint { display: none !important; }
}

/* Narrow phones (≤ 380px, e.g. 360-wide Androids / iPhone SE): one notch
   smaller so search · chat · bell · login still fit on one even row. */
@media (max-width: 380px) {
   .na-m-actions > a:not(.na-m-hide), .na-m-actions > button:not([data-auth-open]):not(.na-m-hide) {
      width: 40px !important; height: 40px !important;
   }
   .na-m-actions .material-symbols-outlined { font-size: 22px !important; }
   .na-m-actions svg { width: 22px !important; height: 22px !important; }
   .na-m-actions button[data-auth-open] { min-width: 56px !important; padding: 0 8px !important; }
   nav:not(#na-tabbar) a[href="/"]:first-child > span { font-size: 16px !important; }   /* the logo, not the Home tab */
}
