/* ==========================================================================
   NAVIGATION.CSS - Ink & Gold header with click-to-open menu
   Desktop (>= 768px): dropdown panel under the Menu button
   Mobile  (<  768px): full-height sheet below the header, scrolls on its own
   All menu classes are ink-menu-* so site.css / forms.css generic rules
   (.section-title, .grid-item, li, button padding...) never reach them.
   ========================================================================== */

:root {
  /* Warm Xuan Rice Paper (宣纸) Palette */
  --ink-paper-bg: #f8f0e3;
  --ink-card-bg: rgba(255, 255, 255, 0.94);
  --ink-card-solid: #ffffff;
  --ink-border-wash: rgba(179, 136, 47, 0.22);
  --ink-border-light: rgba(235, 226, 208, 0.9);

  --ink-dark: #232220;           /* Soft pine soot ink (松烟墨) */
  --ink-mountain-wash: #8c8273;  /* Mountain mist (远山黛) */
  --ink-mist: #e2dac8;           /* Morning fog (晓雾) */

  --ink-gold: #b3882f;           /* Imperial gold (泥金) */
  --ink-gold-light: rgba(179, 136, 47, 0.12);
  --ink-gold-hover: #966e1e;

  --ink-accent-red: #c92a2a;     /* Cinnabar red (朱砂红) */
  --ink-accent-red-light: rgba(201, 42, 42, 0.1);
  --ink-peach-pink: #d9485e;     /* Longevity Peach Pink */

  --panel-shadow: 0 16px 40px rgba(179, 136, 47, 0.15), 0 6px 16px rgba(0, 0, 0, 0.06);

  /* Header-specific */
  --ink-header-bg: rgba(248, 240, 227, 0.86);
  --ink-menu-bg: rgba(255, 252, 245, 0.98);
  --ink-menu-solid: #fffcf5;      /* opaque sheet on phones */
  --ink-header-h: 64px;          /* updated by header.html script */

  /* Fluid typography & scales */
  --font-nav-label: clamp(10px, 0.4vw + 8.5px, 12px);
}

/* Dark Mode: Ink Painting on Midnight Silk (夜山金墨) */
@media (prefers-color-scheme: dark) {
  :root {
    --ink-paper-bg: #121211;
    --ink-card-bg: rgba(26, 25, 23, 0.95);
    --ink-card-solid: #1a1917;
    --ink-border-wash: rgba(229, 203, 143, 0.2);
    --ink-border-light: rgba(50, 47, 42, 0.9);

    --ink-dark: #e8e3d8;
    --ink-mountain-wash: #8f877a;
    --ink-mist: #24221e;

    --ink-gold: #e5cb8f;
    --ink-gold-light: rgba(229, 203, 143, 0.15);
    --ink-gold-hover: #f3dfae;

    --ink-accent-red: #ff5252;
    --ink-accent-red-light: rgba(255, 82, 82, 0.15);
    --ink-peach-pink: #ff6b81;

    --panel-shadow: 0 20px 48px rgba(0, 0, 0, 0.85);

    --ink-header-bg: rgba(18, 18, 17, 0.86);
    --ink-menu-bg: rgba(26, 25, 23, 0.98);
    --ink-menu-solid: #1a1917;
  }
}

/* Never let the page scroll sideways because of the header */
html,
body {
  overflow-x: clip;
}

/* While the mobile menu sheet is open, the page behind it does not scroll */
html.ink-menu-locked,
html.ink-menu-locked body {
  overflow: hidden;
}

/* ==========================================================================
   Header bar
   ========================================================================== */
.ink-site-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  width: 100%;
  background: var(--ink-header-bg);
  border-bottom: 1px solid var(--ink-border-wash);
  backdrop-filter: blur(12px) saturate(140%);
  -webkit-backdrop-filter: blur(12px) saturate(140%);
}

.ink-header-inner {
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  max-width: 1440px;
  margin: 0 auto;
  padding: 6px clamp(12px, 2vw + 6px, 28px);
  box-sizing: border-box;
}

/* --- Brand --------------------------------------------------------------- */
.ink-brand-logo {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  min-width: 0;
  text-decoration: none;
  user-select: none;
}

.ink-brand-img {
  height: clamp(38px, 3vw + 22px, 60px);
  width: auto;
  object-fit: contain;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.08));
}

.ink-brand-fallback {
  flex-direction: column;
  line-height: 1.1;
}

.logo-fallback-main {
  color: var(--ink-gold);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 1.8px;
}

.logo-fallback-sub {
  color: var(--ink-dark);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 2px;
}

/* --- Primary nav --------------------------------------------------------- */
.ink-nav-group {
  display: flex;
  align-items: center;
  gap: clamp(2px, 0.8vw, 10px);
  min-width: 0;
}

.ink-nav-item {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 56px;
  min-height: 46px;
  margin: 0;
  padding: 4px 10px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-dark);
  font: inherit;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  box-sizing: border-box;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.ink-nav-item:hover {
  background: var(--ink-gold-light);
  color: var(--ink-gold);
}

.ink-nav-item:focus-visible,
.ink-nav-signup:focus-visible,
.ink-menu-link:focus-visible,
.ink-menu-btn:focus-visible,
.ink-menu-logout:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(179, 136, 47, 0.35);
}

.ink-nav-item.is-active {
  background: var(--ink-gold-light);
  border-color: var(--ink-border-wash);
  color: var(--ink-gold);
}

.ink-item-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
}

.ink-item-icon svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
}

.ink-item-icon.is-rose svg {
  color: var(--ink-peach-pink);
}

/* Header badges (top-right of the icon) */
.ink-item-icon {
  position: relative;
}

.ink-nav-badge,
.ink-nav-alert {
  position: absolute;
  top: -6px;
  left: calc(100% - 8px);           /* grows to the right, never over the icon */
  box-sizing: border-box;
  height: 16px;
  border-radius: 999px;
  border: 2px solid var(--ink-paper-bg, #fdfaf4);
  font-family: inherit;
  font-size: 10px;
  font-weight: 800;
  line-height: 12px;
  text-align: center;
  color: #ffffff;
  pointer-events: none;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
}

.ink-nav-badge {
  min-width: 16px;
  padding: 0 4px;
  background: var(--ink-gold);
  font-variant-numeric: tabular-nums;
}

.ink-nav-alert {
  width: 16px;
  background: var(--ink-accent-red);
  animation: inkAlertPulse 2s ease-in-out infinite;
}

.ink-nav-badge[hidden],
.ink-nav-alert[hidden] {
  display: none;
}

@keyframes inkAlertPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(168, 50, 38, 0.45); }
  50%      { box-shadow: 0 0 0 4px rgba(168, 50, 38, 0); }
}

@media (prefers-reduced-motion: reduce) {
  .ink-nav-alert { animation: none; }
}

@media (prefers-color-scheme: dark) {
  .ink-nav-badge { color: #1a1916; }   /* light gold needs dark text */
}

/* Screen-reader-only text */
.ink-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.ink-item-label {
  font-size: var(--font-nav-label);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

/* Guest Sign Up pill */
.ink-nav-signup {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--ink-gold);
  color: #ffffff;
  font-size: 12.5px;
  font-weight: 800;
  letter-spacing: 0.3px;
  text-decoration: none;
  white-space: nowrap;
  box-shadow: 0 3px 10px rgba(179, 136, 47, 0.3);
  transition: background 0.2s ease;
}

.ink-nav-signup svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
}

.ink-nav-signup:hover {
  background: var(--ink-gold-hover);
}

/* ==========================================================================
   Menu (button + panel)
   ========================================================================== */
.ink-menu {
  position: relative;
}

.ink-menu-close-icon {
  display: none;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
}

.ink-menu.is-open .ink-menu-toggle {
  background: var(--ink-gold);
  border-color: var(--ink-gold);
  color: #ffffff;
}

.ink-menu.is-open .ink-menu-open-icon {
  display: none;
}

.ink-menu.is-open .ink-menu-close-icon {
  display: block;
}

/* Panel — desktop dropdown */
.ink-menu-panel {
  display: none;
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 1100;
  width: min(460px, calc(100vw - 24px));
  max-height: calc(100vh - var(--ink-header-h) - 24px);
  max-height: calc(100dvh - var(--ink-header-h) - 24px);
  flex-direction: column;
  background: var(--ink-menu-bg);
  border: 1px solid var(--ink-border-wash);
  border-radius: 18px;
  box-shadow: var(--panel-shadow);
  overflow: hidden;
  animation: inkMenuIn 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes inkMenuIn {
  from { opacity: 0; transform: translateY(-6px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}

/* Click mode (JS) */
.ink-site-header.is-js .ink-menu.is-open .ink-menu-panel {
  display: flex;
}

/* No-JS fallback: open while the menu has focus */
.ink-site-header:not(.is-js) .ink-menu:focus-within .ink-menu-panel {
  display: flex;
}

/* Scrolling body of the panel */
.ink-menu-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 14px 14px 6px;
  scrollbar-width: thin;
  scrollbar-color: rgba(179, 136, 47, 0.5) transparent;
}

.ink-menu-scroll::-webkit-scrollbar { width: 10px; }
.ink-menu-scroll::-webkit-scrollbar-track { background: transparent; margin: 10px 0; }
.ink-menu-scroll::-webkit-scrollbar-thumb {
  background: rgba(179, 136, 47, 0.45);
  border: 3px solid transparent;
  border-radius: 999px;
  background-clip: padding-box;
}
.ink-menu-scroll::-webkit-scrollbar-button { display: none; }

/* User header */
.ink-menu-user {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  margin-bottom: 6px;
  border-radius: 14px;
  background: var(--ink-gold-light);
  border: 1px solid var(--ink-border-wash);
}

.ink-menu-avatar {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ink-gold);
  color: #ffffff;
  font-size: 1.05rem;
  font-weight: 900;
}

.ink-menu-user-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.ink-menu-user-name {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--ink-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ink-menu-user-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--ink-mountain-wash);
}

.ink-menu-role {
  font-size: 0.64rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-accent-red);
  background: var(--ink-accent-red-light);
  padding: 1px 6px;
  border-radius: 4px;
}

/* Sections */
.ink-menu-section {
  padding: 10px 0 4px;
}

.ink-menu-section + .ink-menu-section {
  border-top: 1px solid var(--ink-border-wash);
}

.ink-menu-heading {
  margin: 0 4px 8px;
  padding: 0;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-gold);
}

.ink-menu-section.is-admin .ink-menu-heading {
  color: var(--ink-accent-red);
}

.ink-menu-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
}

/* Menu link: icon tile + label + hint */
.ink-menu-link {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 8px;
  border-radius: 12px;
  border: 1px solid transparent;
  text-decoration: none;
  color: var(--ink-dark);
  box-sizing: border-box;
  min-width: 0;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.ink-menu-link:hover {
  background: var(--ink-gold-light);
  border-color: var(--ink-border-wash);
}

.ink-menu-link.is-current {
  background: var(--ink-gold-light);
  border-color: var(--ink-gold);
}

.ink-menu-icon {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(140, 130, 115, 0.12);
  color: var(--ink-dark);
}

.ink-menu-icon svg {
  width: 19px;
  height: 19px;
  stroke: currentColor;
}

.ink-menu-link.is-gold .ink-menu-icon { color: var(--ink-gold); background: var(--ink-gold-light); }
.ink-menu-link.is-rose .ink-menu-icon { color: var(--ink-peach-pink); background: rgba(217, 72, 94, 0.1); }
.ink-menu-link.is-red  .ink-menu-icon { color: var(--ink-accent-red); background: var(--ink-accent-red-light); }

.ink-menu-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.ink-menu-label {
  font-size: 0.86rem;
  font-weight: 700;
  line-height: 1.25;
  color: var(--ink-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ink-menu-hint {
  font-size: 0.7rem;
  line-height: 1.3;
  color: var(--ink-mountain-wash);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Footer (always visible below the scroll area) */
.ink-menu-footer {
  flex-shrink: 0;
  display: flex;
  gap: 8px;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--ink-border-wash);
  background: var(--ink-menu-bg);
}

.ink-menu-logout,
.ink-menu-btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 40px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-decoration: none;
  box-sizing: border-box;
  transition: all 0.2s ease;
}

.ink-menu-logout {
  color: var(--ink-accent-red);
  background: var(--ink-accent-red-light);
  border: 1px solid rgba(201, 42, 42, 0.22);
}

.ink-menu-logout svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
}

.ink-menu-logout:hover {
  background: var(--ink-accent-red);
  color: #ffffff;
}

.ink-menu-btn.is-ghost {
  color: var(--ink-gold);
  border: 1.5px solid var(--ink-gold);
  background: transparent;
}

.ink-menu-btn.is-gold {
  color: #ffffff;
  background: var(--ink-gold);
  border: 1.5px solid var(--ink-gold);
}

.ink-menu-btn.is-gold:hover {
  background: var(--ink-gold-hover);
  border-color: var(--ink-gold-hover);
}

.ink-menu-backdrop {
  display: none;
}

/* Desktop / mobile-only bits */
.ink-menu-section.is-mobile-only {
  display: none;
}

/* ==========================================================================
   Mobile (< 768px)
   ========================================================================== */
@media (max-width: 767px) {
  .ink-header-inner {
    padding: 6px 12px;
    gap: 8px;
  }

  .ink-nav-item {
    min-width: 50px;
    min-height: 44px;
    padding: 4px 6px;
  }

  .ink-nav-item.is-desktop-only {
    display: none;
  }

  .ink-menu-section.is-mobile-only {
    display: block;
  }

  .ink-nav-signup {
    height: 34px;
    padding: 0 12px;
  }

  /* Full-height sheet under the header.
     The header's backdrop-filter makes it the containing block for fixed
     children, so size the sheet from the viewport explicitly instead of
     relying on bottom: 0 (which would stop at the header's edge). */
  .ink-menu-panel {
    position: fixed;
    top: var(--ink-header-h);
    left: 0;
    right: 0;
    bottom: auto;
    width: auto;
    height: calc(100vh - var(--ink-header-h));
    height: calc(100dvh - var(--ink-header-h));
    max-height: none;
    background: var(--ink-menu-solid, #fffcf5);
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    box-shadow: 0 -1px 0 var(--ink-border-wash);
    animation: inkSheetIn 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  }

  @keyframes inkSheetIn {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: none; }
  }

  .ink-menu-scroll {
    padding: 14px 16px 8px;
  }

  .ink-menu-footer {
    padding-left: 16px;
    padding-right: 16px;
  }

  /* One column on phones so labels and hints stay readable */
  .ink-menu-grid {
    grid-template-columns: 1fr;
  }

  .ink-menu-link {
    min-height: 56px;
  }

  .ink-menu-label {
    font-size: 0.92rem;
  }

  .ink-menu-hint {
    font-size: 0.74rem;
  }
}

/* Two columns again on wider phones / small tablets in portrait */
@media (min-width: 480px) and (max-width: 767px) {
  .ink-menu-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Very small phones: icons only in the bar (labels stay for screen readers) */
@media (max-width: 359px) {
  .ink-nav-item .ink-item-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
  .ink-nav-item {
    min-width: 42px;
  }
}

/* ==========================================================================
   Dark mode touch-ups
   ========================================================================== */
@media (prefers-color-scheme: dark) {
  .ink-menu-icon {
    background: rgba(255, 255, 255, 0.06);
  }
  .ink-menu.is-open .ink-menu-toggle,
  .ink-nav-signup,
  .ink-menu-btn.is-gold,
  .ink-menu-avatar {
    color: #1a1916;
  }
  .ink-menu-scroll {
    scrollbar-color: rgba(229, 203, 143, 0.45) transparent;
  }
  .ink-menu-scroll::-webkit-scrollbar-thumb {
    background: rgba(229, 203, 143, 0.4);
    background-clip: padding-box;
  }
}