/* ──────────────────────────────────────────────────────────────────────
   The site header and footer (idea 4, 2026-10-18).
   Markup: navHTML() / checkoutNavHTML() / siteFooterHTML() in
   scripts/genre-pages.mjs (generated into every page). Behaviour:
   js/site-nav.js. Builds on .nav, .nav-link, .nav-search, .nav-user,
   .nav-dropdown and .lp-footer in css/style.css.
   ────────────────────────────────────────────────────────────────────── */

/* ── Desktop row ─────────────────────────────────────────────── */
/* body is a flex column (style.css): never let the header shrink. */
.shell, .shell-chapters-bar { flex-shrink: 0; }
.shell .shell-links { display: flex; align-items: center; gap: 2px; margin-left: 12px; }
.shell .nav-link { display: inline-flex; align-items: center; gap: 5px; line-height: 1.4; }
.shell .nav-link[hidden] { display: none; }
.shell .nav-link.active { color: var(--text); background: var(--surface-hi); }
.shell-browse { position: relative; }
.shell-browse-btn { font: inherit; font-size: .9rem; font-weight: 500; color: var(--text-2); }
.shell-chev { flex: none; opacity: .7; transition: transform .15s; }
[aria-expanded="true"] > .shell-chev { transform: rotate(180deg); }

/* Small popovers: the Browse menu and the avatar menu. */
.shell-pop[hidden], .nav-dropdown[hidden] { display: none !important; }
.shell-browse-menu {
  position: absolute; top: calc(100% + 8px); left: 0; z-index: 210;
  min-width: 190px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  box-shadow: 0 12px 32px rgba(0,0,0,.5);
  display: flex; flex-direction: column;
}
.shell-pop-item {
  display: block; padding: 9px 12px; border-radius: var(--r-sm);
  color: var(--text-2); font-size: .9rem;
}
.shell-pop-item:hover, .shell-pop-item:focus-visible { background: var(--surface-hi); color: var(--text); }
.shell-pop-item.active, .shell-pop-item[aria-current="page"] { color: var(--accent); }
a.nav-dropdown-item { text-decoration: none; }
.nav-dropdown-item:focus-visible { background: var(--surface-hi); color: var(--text); outline-offset: -2px; }
.nav-dropdown-item[aria-current="page"] { color: var(--accent); }
.nav-dropdown-item[aria-current="page"] svg { color: var(--accent); }
.nav-dropdown-meta a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.nav-dropdown { padding-bottom: 6px; }

/* Account side: the width is reserved so painting the signed-in state
   (js/site-nav.js, auth.js) never moves the search box; blank until the
   state is known so a reader never sees "Log in" flash. */
.shell-auth { min-width: 206px; justify-content: flex-end; gap: 8px; }
.shell-auth:not([data-state]) > * { visibility: hidden; }
.shell-auth .btn-sm { white-space: nowrap; }
.shell .nav-user { color: var(--text-2); }
.shell .nav-user-name { max-width: 150px; }

/* Icon buttons (phone): search, menu, sheet close. */
.shell-icon {
  display: none; align-items: center; justify-content: center; flex: none;
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--border); background: transparent; color: var(--text);
  transition: background .15s, border-color .15s;
}
.shell-icon:hover { background: var(--surface-hi); }
.shell-search-close { display: none; }

/* Narrow desktops and landscape tablets: give the search box less room
   so the row never overflows before the phone layout takes over. */
@media (min-width: 901px) and (max-width: 1180px) {
  .shell { gap: 10px; }
  .shell .nav-search { width: min(240px, 20vw); }
  .shell .nav-search kbd { display: none; }
  .shell-auth { min-width: 188px; }
  .shell .nav-user-name { max-width: 96px; }
}

/* ── Phones and portrait tablets ─────────────────────────────── */
@media (max-width: 900px) {
  .shell { gap: 8px; padding: 0 12px; }
  .shell .shell-links, .shell .nav-search { display: none; }
  .shell .shell-icon { display: inline-flex; }
  .shell-auth { min-width: 72px; gap: 6px; justify-content: center; }
  .shell-auth .shell-signup, .shell .nav-user-name, .shell .nav-user .shell-chev { display: none; }
  .shell .nav-user { padding: 4px; border-radius: 50%; }
  .shell .nav-user .nav-avatar { width: 32px; height: 32px; font-size: .85rem; }
  .shell .shell-auth .btn-sm { padding: 8px 14px; font-size: .85rem; }

  /* Full-width search over the header row. */
  .shell.is-searching .nav-search {
    display: flex; position: absolute; left: 12px; right: 12px; top: 50%; transform: translateY(-50%);
    width: auto; height: 42px; z-index: 3; background: var(--surface); border-color: var(--accent-dim);
  }
  .shell.is-searching .nav-search kbd { display: none; }
  .shell.is-searching .nav-search input { font-size: 1rem; }
  .shell.is-searching .shell-search-close {
    display: inline-flex; flex: none; padding: 6px 2px 6px 8px;
    color: var(--text-2); font-size: .88rem; font-weight: 500;
  }
  .shell.is-searching > :not(.nav-search) { visibility: hidden; }
}
@media (max-width: 380px) {
  .shell { gap: 6px; padding: 0 10px; }
  .shell .nav-logo { font-size: 1.05rem; }
  .shell .nav-logo svg { width: 24px; height: 24px; }
  .shell-icon { width: 38px; height: 38px; }
  .shell .shell-auth .btn-sm { padding: 7px 10px; }
  .shell-auth { min-width: 62px; }
}

/* ── Phone menu sheet ────────────────────────────────────────── */
html.shell-locked, html.shell-locked body { overflow: hidden; }
.shell-backdrop {
  position: fixed; inset: 0; z-index: 189;
  background: rgba(0,0,0,.55); opacity: 0; transition: opacity .2s;
}
.shell-backdrop.is-open { opacity: 1; }
.shell-backdrop[hidden], .shell-sheet[hidden] { display: none; }
.shell-sheet {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 190;
  width: min(360px, 88vw); display: flex; flex-direction: column;
  background: var(--bg); border-left: 1px solid var(--border);
  box-shadow: -18px 0 40px rgba(0,0,0,.5);
  transform: translateX(100%); transition: transform .22s ease;
  padding-bottom: env(safe-area-inset-bottom);
}
.shell-sheet.is-open { transform: none; }
@media (prefers-reduced-motion: reduce) { .shell-sheet, .shell-backdrop { transition: none; } }
.shell-sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  height: var(--nav-h); padding: 0 12px 0 20px; flex: none;
  border-bottom: 1px solid var(--border);
}
.shell-sheet-title { font-family: var(--font-display); font-weight: 700; font-size: 1.15rem; color: var(--text); }
.shell-sheet .shell-icon { display: inline-flex; }
.shell-sheet-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 16px 12px 24px; }
.shell-sheet-acct { display: flex; flex-direction: column; gap: 10px; padding: 0 8px 16px; margin-bottom: 8px; border-bottom: 1px solid var(--border); }
.shell-sheet-btn { justify-content: center; width: 100%; min-height: 46px; }
.shell-sheet-user { display: flex; align-items: center; gap: 12px; padding: 4px 0; }
.shell-sheet-acct .nav-dropdown-meta { padding: 0; }
.shell-sheet-acct .shell-sheet-main { margin: 4px -8px 0; }
.shell-sheet ul { list-style: none; margin: 0; padding: 0; }
.shell-sheet-main a, .shell-sheet-main button {
  display: flex; align-items: center; gap: 12px; width: 100%;
  min-height: 48px; padding: 0 12px; border-radius: var(--r-sm);
  color: var(--text); font-size: 1.05rem; font-weight: 500; text-align: left;
}
.shell-sheet-main svg { color: var(--text-3); flex: none; }
.shell-sheet-main a:hover, .shell-sheet-main button:hover { background: var(--surface); }
.shell-sheet-main a.active, .shell-sheet-main a[aria-current="page"] { background: var(--surface-hi); box-shadow: inset 3px 0 0 var(--accent); }
.shell-sheet-main li[hidden] { display: none; }
.shell-sheet-h { margin: 18px 12px 4px; font-size: .7rem; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--text-3); }
.shell-sheet-minor { display: flex; gap: 4px; margin-top: 18px !important; padding-top: 14px !important; border-top: 1px solid var(--border); }
.shell-sheet-minor a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 12px; color: var(--text-2); font-size: .95rem; border-radius: var(--r-sm); }
.shell-sheet-minor a[aria-current="page"] { color: var(--accent); }

/* ── Focused header (/subscribe, /welcome, /oauth-callback) ──── */
.shell--focused .shell-back {
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 999px;
  color: var(--text-2); font-size: .88rem; font-weight: 500; white-space: nowrap;
}
.shell--focused .shell-back:hover { color: var(--text); background: var(--surface-hi); }
@media (max-width: 380px) { .shell--focused .shell-back { padding: 0 10px; font-size: .8rem; } }

/* ── Sticky neighbours ───────────────────────────────────────── */
/* Book pages: one sticky bar at a time. The site header scrolls away and
   the section tab bar (.bp2-tabs, sticky top:0) takes the top edge, so the
   two never overlap. */
body:has(.bp2-tabs) .shell { position: relative; }

/* Player (book.html): the chapter list's entry point is a labelled
   "Chapters" button under the header, not the header's ☰ (that is the
   site menu now). Only where the list is a drawer. */
.shell-chapters-bar { display: none; }
@media (max-width: 768px) {
  .shell-chapters-bar {
    display: flex; align-items: center; gap: 10px;
    position: sticky; top: var(--nav-h); z-index: 99;
    height: 44px; padding: 0 12px;
    background: rgba(23,19,16,.92); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
  }
  .shell-chapters-bar .sidebar-toggle { display: inline-flex; align-items: center; gap: 8px; }
  /* The sticky bar is the one way in on phones; the book header's own
     Chapters button would be a second copy of it. */
  #hero-chapters-btn { display: none; }
  /* The drawer and its overlay open below both bars. */
  body:has(.shell-chapters-bar) .sidebar,
  body:has(.shell-chapters-bar) .sidebar-overlay { top: calc(var(--nav-h) + 44px); }
}

/* ── Footer ──────────────────────────────────────────────────── */
/* .lp-footer (style.css) on every standard page; the grid fits the four
   columns most pages carry and the homepage's six. */
.lp-footer-grid { grid-template-columns: minmax(220px, 1.4fr) repeat(auto-fit, minmax(140px, 1fr)); }
@media (max-width: 1100px) { .lp-footer-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 640px) { .lp-footer-grid { grid-template-columns: 1fr 1fr; } }
.lp-footer a[aria-current="page"] { color: var(--text); }
.lp-footer { flex-shrink: 0; }
.lp-footer--slim { padding-top: 0; margin-top: auto; background: transparent; }
.lp-footer--slim .lp-footer-bar { margin-top: 0; border-top: 0; }
body.player-active .lp-footer { display: none; }
/* Book pages on phones: the floating Listen button (book-page.css,
   .bp2-tabs.show-cta) must not cover the footer's last row. */
@media (max-width: 639px) { body:has(.bp2-tabs.show-cta) .lp-footer { padding-bottom: 90px; } }

/* Avatar status line and its one action inside the phone menu sheet. */
.shell-sheet-acct .nav-menu-status { padding: 0; margin: 2px 0 10px; }
.shell-sheet-acct .nav-menu-action { margin: 0 0 12px; }

/* Phones: the avatar sits left of the ☰ button, so a menu right-aligned to
   the avatar ran off the left edge at 320px. Line it up with the header's
   right edge instead (☰ width + gap). */
@media (max-width: 900px) { .shell .nav-dropdown { right: -48px; } }
@media (max-width: 380px) { .shell .nav-dropdown { right: -44px; } }
