/* ── Top navbar ── */
#navbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 4.5rem;
  background: var(--surface-raised);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}

#navbar-inner {
  height: 100%;
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

#logo a { display: inline-flex; align-items: center; }

.brand-lockup {
  --brand-mark-height: 2.75rem;
  --brand-word-size: 1.55rem;
  --brand-gap: 0.42rem;
  display: inline-flex;
  align-items: center;
  gap: var(--brand-gap);
  white-space: nowrap;
}

.brand-lockup img {
  display: block;
  width: auto;
  height: var(--brand-mark-height);
  flex: 0 0 auto;
}

.brand-wordmark {
  color: var(--text-strong);
  font-family: 'Quicksand', 'Avenir Next', sans-serif;
  font-size: var(--brand-word-size);
  font-weight: 600;
  letter-spacing: -0.07em;
  line-height: 1;
}

.nav-link {
  font-family: 'Inter', -apple-system, sans-serif;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: color 0.15s;
}
.nav-link:hover { color: var(--secondary); }
.nav-link.active { color: var(--navy); font-weight: 700; }

#account-menu {
  position: relative;
  margin-left: auto;
  flex-shrink: 0;
}

#account-menu summary {
  position: relative;
  list-style: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.55rem;
  height: 2.3rem;
  padding: 0;
  border: 1.5px solid var(--border);
  border-radius: 16px 16px 16px 9px;
  background: var(--surface-raised);
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  box-shadow: 0 2px 8px var(--shadow-soft);
  transform: rotate(-2deg);
  transition: color 0.15s, transform 0.15s, background 0.15s, box-shadow 0.15s;
}

#account-menu summary::-webkit-details-marker { display: none; }
#account-menu summary::after {
  content: "";
  position: absolute;
  left: -0.16rem;
  bottom: 0.18rem;
  width: 0.5rem;
  height: 0.5rem;
  border-left: 1.5px solid var(--border);
  border-top: 1.5px solid var(--border);
  border-top-left-radius: 0.35rem;
  background: inherit;
  transform: rotate(-35deg);
}

#account-menu summary:hover,
#account-menu[open] summary {
  color: var(--secondary);
  background: var(--surface);
  box-shadow: 0 6px 18px var(--shadow-hover);
}

#account-menu summary:hover { transform: translateY(-1px) rotate(-2deg); }

#account-menu-panel {
  position: absolute;
  top: calc(100% + 0.55rem);
  right: 0;
  min-width: 11rem;
  padding: 0.45rem;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 16px 40px var(--shadow-raised);
}

#account-menu-panel form { margin: 0; }

.menu-item {
  display: block;
  width: 100%;
  padding: 0.65rem 0.75rem;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--muted);
  font-family: 'Inter', -apple-system, sans-serif;
  font-size: 0.85rem;
  font-weight: 500;
  line-height: 1.2;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.menu-item:hover,
.menu-item.active {
  color: var(--navy);
  background: var(--surface);
}

.menu-button { color: var(--secondary); }

.menu-item-cta {
  margin-top: 0.3rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  color: var(--blue);
  font-weight: 700;
}
.menu-item-cta:hover { color: var(--blue); }

/* ── Footer ── */
footer {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.45rem;
  text-align: center;
  padding: 2rem;
  font-size: 0.8rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
}
footer a { color: inherit; text-decoration: underline; }
.github-link { display: inline-flex; align-items: center; gap: 0.35rem; }
.github-link svg { flex: 0 0 auto; display: block; }

/* ── Bottom tab bar (mobile, signed-in only) ── */
#tab-bar { display: none; }

@media (max-width: 600px) {
  #navbar { height: 3.5rem; }
  #navbar-inner { padding: 0 1rem; }
  .nav-link { display: none; }

  #account-menu summary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 46px;
    height: 44px;
  }

  #tab-bar {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: calc(4rem + env(safe-area-inset-bottom));
    background: var(--surface-raised);
    border-top: 1px solid var(--border);
    z-index: 100;
    padding-bottom: env(safe-area-inset-bottom);
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
  }

  .tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: 4rem;
    color: var(--muted);
    text-decoration: none;
    font-family: 'Inter', -apple-system, sans-serif;
    font-size: 0.65rem;
    font-weight: 500;
    background: none;
    border: none;
    cursor: pointer;
    transition: color 0.15s;
  }
  .tab:hover { color: var(--secondary); }
  .tab.active { color: var(--navy); }

  /* Only signed-in pages render #tab-bar — scope the body offset to it so
     public pages (no tab bar) don't get a phantom gap at the bottom. */
  body:has(#tab-bar) { padding-bottom: calc(4rem + env(safe-area-inset-bottom)); }

  /* A page reachable while signed in (Story, Privacy, Terms, Guide) can
     render both a footer and the tab bar on mobile — the tab bar already
     covers navigation there, so hide the footer instead of stacking both. */
  body:has(#tab-bar) footer { display: none; }
}
