/* Top navigation: sticky header, "Copy for AI", menu sheet. Owner: nav builder.
   Wide (1100+): three columns on the page frame. Brand sits in the left rail, links and
   Copy for AI in the centre column, Join the beta in the right rail.
   Narrower: brand left, Copy for AI, Join the beta and a menu button right. */

html { scroll-padding-top: calc(var(--l-topbar-h) + 16px); }

.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  /* opaque so content never shows through; the two column hairlines are redrawn here */
  background:
    linear-gradient(var(--l-hair-color), var(--l-hair-color)) calc(var(--rail-w) - 1px) 0 / 1px 100% no-repeat,
    linear-gradient(var(--l-hair-color), var(--l-hair-color)) calc(100% - var(--rail-w)) 0 / 1px 100% no-repeat,
    var(--paper);
  border-bottom-color: var(--line);
  transition: border-color var(--dur) var(--ease-out);
}
.topbar.is-scrolled { border-bottom-color: var(--l-hair-color); }

.topbar .brand { grid-column: 1; }
.nav-mid { grid-column: 2; display: flex; align-items: center; justify-content: center; gap: 24px; min-width: 0; }
.nav-end { grid-column: 3; display: flex; align-items: center; justify-content: center; gap: 8px; }

.nav-links { display: flex; align-items: center; gap: 4px; margin: 0; padding: 0; list-style: none; }
.nav-link {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 12px;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
  transition: color var(--dur-fast) var(--ease-out);
}
.nav-link::after {
  content: '';
  position: absolute;
  left: 12px; right: 12px; bottom: 3px;
  height: 1px;
  background: var(--ink);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform var(--dur) var(--ease-out);
}
.nav-link:hover { color: var(--ink); }
.nav-link:hover::after, .nav-link.is-active::after, .nav-link[aria-current]::after { transform: scaleX(1); }
.nav-link.is-active, .nav-link[aria-current] { color: var(--ink); }

/* ---------- White glass (secondary): Copy for AI and the menu button ---------- */
.nav-glass {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background:
    radial-gradient(100% 100% at 65% 85%, var(--white), transparent),
    linear-gradient(145deg, var(--white), var(--tile-2));
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  color: var(--ink);
  white-space: nowrap;
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
}
@media (hover: hover) { .nav-glass:hover { border-color: var(--muted-2); } }
.nav-glass:active { transform: scale(.97); }
.nav-px { width: 20px; height: 20px; margin-inline: -3px; flex-shrink: 0; }

/* Copy for AI: two faces share one cell, so the label swap never shifts the layout */
.nav-copy { display: inline-grid; padding: 0 14px; }
.nav-copy-face { grid-area: 1 / 1; display: inline-flex; align-items: center; justify-content: center; gap: 8px; transition: opacity var(--dur-fast) var(--ease-out); }
.nav-copy-done { opacity: 0; }
.nav-copy[data-state='done'] .nav-copy-idle { opacity: 0; }
.nav-copy[data-state='done'] .nav-copy-done { opacity: 1; }
.nav-copy .px-icon { margin-inline: -3px; }

/* Join the beta: smoked glass, header size */
.topbar .button.cta-glass.nav-join { min-height: 36px; padding: 0 16px; border-radius: 10px; font-size: 13px; font-weight: 600; line-height: 1; letter-spacing: 0; white-space: nowrap; }
.nav-sheet .button.cta-glass { min-height: 48px; padding: 0 24px; font-size: 14px; white-space: nowrap; }

.nav-menu { display: none; width: 40px; min-height: 40px; padding: 0; }
.nav-menu .nav-px-close { display: none; }
.nav-menu[aria-expanded='true'] .nav-px-open { display: none; }
.nav-menu[aria-expanded='true'] .nav-px-close { display: block; }

/* ---------- Menu sheet ---------- */
.nav-sheet {
  position: fixed;
  top: var(--l-topbar-h);
  left: 0; right: 0;
  height: calc(100vh - var(--l-topbar-h));
  height: calc(100dvh - var(--l-topbar-h));
  overflow-y: auto;
  padding: 8px max(16px, var(--rail-w)) 32px;
  background: var(--paper);
  border-top: 1px solid var(--line);
  animation: nav-sheet-in var(--dur) var(--ease-out);
}
@keyframes nav-sheet-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
.nav-sheet-links { display: block; margin: 0; padding: 0; list-style: none; }
.nav-sheet-links li { border-bottom: 1px solid var(--line); }
.nav-sheet-link {
  display: flex; align-items: center; justify-content: space-between;
  min-height: 64px;
  font-family: var(--font-body);   /* title role (design-system pass) */
  font-size: 20px;
  font-weight: var(--fw-title);
  color: var(--ink);
  text-decoration: none;
}
.nav-sheet-actions { display: grid; gap: 12px; margin-top: 32px; }
.nav-sheet-actions .nav-glass, .nav-sheet-actions .cta-glass { width: 100%; min-height: 48px; font-size: 14px; }
.nav-sheet-note { margin-top: 16px; font-size: 13px; color: var(--muted); text-align: center; }

/* ---------- Copy fallback: select the text by hand ---------- */
.nav-fallback {
  position: fixed;
  top: calc(var(--l-topbar-h) + 8px);
  right: 16px;
  z-index: calc(var(--z-header) + 1);
  width: min(380px, calc(100vw - 32px));
  padding: 16px;
  background: var(--paper);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
}
.nav-fallback p { font-size: 13px; line-height: 1.5; color: var(--ink-2); }
.nav-fallback textarea {
  display: block; width: 100%; height: 140px; margin: 12px 0;
  padding: 10px; resize: none;
  border: 1px solid var(--line-strong); border-radius: 8px;
  background: var(--tile-2); color: var(--ink);
  font-family: var(--font-body); font-size: 12px; line-height: 1.5;
}
.nav-fallback-close { display: block; margin-left: auto; min-height: 32px; padding: 0 12px; border: 0; background: none; font-size: 13px; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }

html.nav-locked { overflow: hidden; }

/* ---------- Narrower than the three-column frame ---------- */
@media (max-width: 1099px) {
  .topbar { display: flex; align-items: center; gap: 8px; padding-inline: max(16px, var(--rail-w)); background: var(--paper); }
  .topbar .brand { justify-self: auto; margin-right: auto; }
  .nav-mid { margin-left: auto; }
  .nav-links { display: none; }
  .nav-end { gap: 8px; }
  .nav-menu { display: inline-flex; }
}
@media (max-width: 639px) {
  .nav-mid { display: none; }
  .topbar .button.cta-glass.nav-join { padding: 0 14px; }
}
@media (min-width: 1100px) {
  .nav-sheet { display: none !important; }
}

@media (prefers-reduced-motion: reduce) {
  .nav-sheet { animation: none; }
  .nav-link::after, .nav-glass, .nav-copy-face { transition: none; }
}
html[data-motion='paused'] .nav-sheet { animation: none; }

/* one CTA while the sheet is open */
.topbar:has(.nav-menu[aria-expanded='true']) .nav-end .nav-join { display: none; }
