/**
 * header.css (v4.2 — Task 2: Standardized Editorial Navigation System)
 * Desktop Header (>= 1080px): 80px height (68px on scroll), centered nav links, outline sign in.
 * Mobile Header & Drawer (< 1080px): 60px header, width min(88vw, 380px), 100dvh, serif rows.
 */

.skip-link {
  position: absolute; left: 1rem; top: -4rem; z-index: var(--z-toast, 1070);
  padding: 0.6rem 1rem; background: var(--walnut, #2B1D14); color: var(--paper, #FAF7F0);
  border-radius: var(--radius-ui, 6px); font-weight: 600; text-decoration: none;
  transition: top 0.2s ease; border: 1px solid var(--brass, #A9792B);
}
.skip-link:focus { top: 1rem; }

/* ---------- Announcement Bar (Optional) ---------- */
.announce { 
  background: #23160D; 
  color: #D1BFA5; 
  font-size: var(--text-sm, 0.875rem); 
  border-bottom: 1px solid rgba(169, 121, 43, 0.25);
}
.announce[hidden] { display: none; }
.announce__inner { display: flex; align-items: center; gap: 0.75rem; min-height: 38px; }
.announce__text { flex: 1 1 auto; min-width: 0; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 0.85rem; }
.announce__text a { margin-left: 0.5rem; color: #E5C383; text-underline-offset: 0.3em; }
.announce__close {
  flex: none; width: 38px; height: 38px; margin-right: -0.5rem;
  display: inline-flex; align-items: center; justify-content: center;
  background: none; border: 0; color: inherit; font-size: 1.25rem; cursor: pointer;
}

/* ---------- Header Wrapper (Sticky / Fixed) ---------- */
.site-header-wrapper {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  z-index: var(--z-nav, 1040);
}

body {
  padding-top: var(--site-header-height, 80px);
}

@media (max-width: 1079.98px) {
  body {
    padding-top: var(--site-header-height, 60px);
  }
}

/* ---------- Header Surface (Heritage Walnut with Woodgrain) ---------- */
.site-header {
  position: relative;
  width: 100%;
  background: rgba(43, 29, 20, 0.98);
  background-image: var(--wood-grain, none);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(169, 121, 43, 0.3);
  box-shadow: 0 4px 18px -4px rgba(20, 12, 8, 0.45);
  padding-top: env(safe-area-inset-top, 0px);
  transition: min-height 0.2s ease, height 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}

.site-header.is-scrolled,
.site-header.scrolled {
  background: rgba(35, 22, 13, 0.99);
  box-shadow: 0 6px 24px -2px rgba(15, 9, 6, 0.65);
}

.site-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: var(--container-max, 1200px);
  margin-inline: auto;
  padding-inline: max(var(--gutter), env(safe-area-inset-left)) max(var(--gutter), env(safe-area-inset-right));
  min-height: 80px;
  height: 80px;
  box-sizing: border-box;
  transition: min-height 0.2s ease, height 0.2s ease;
}

.site-header.is-scrolled .site-header__inner,
.site-header.scrolled .site-header__inner {
  min-height: 68px;
  height: 68px;
}

@media (max-width: 1079.98px) {
  .site-header__inner {
    min-height: 60px;
    height: 60px;
  }
  .site-header.is-scrolled .site-header__inner,
  .site-header.scrolled .site-header__inner {
    min-height: 60px;
    height: 60px;
  }
}

/* ---------- Brand Logo ---------- */
.brand {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  color: var(--paper, #FAF7F0);
  text-decoration: none;
  line-height: 1;
}

.brand__logo-img {
  height: 56px;
  width: auto;
  max-width: 220px;
  object-fit: contain;
  display: block;
}

@media (max-width: 1079.98px) {
  .brand__logo-img {
    height: 42px;
    max-width: 160px;
  }
}

/* ---------- Desktop Primary Navigation (>= 1080px) ---------- */
.primary-nav {
  display: none;
}

@media (min-width: 1080px) {
  .primary-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1 1 auto;
    margin-inline: 1rem;
  }
}

.primary-nav__list {
  display: flex;
  align-items: center;
  gap: 28px;
  margin: 0;
  padding: 0;
  list-style: none;
}

@media (min-width: 1080px) and (max-width: 1200px) {
  .primary-nav__list {
    gap: 16px;
  }
}

.primary-nav__link {
  position: relative;
  display: inline-flex;
  align-items: center;
  padding-block: 10px;
  color: rgba(241, 230, 207, 0.82);
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  text-decoration: none;
  text-transform: none;
  white-space: nowrap;
  transition: color 180ms ease;
}

.primary-nav__link::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0px;
  height: 2px;
  background-color: var(--brass, #A9792B);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 180ms cubic-bezier(0.2, 0.7, 0.2, 1);
}

.primary-nav__link[aria-current="page"] {
  color: #FAF7F0;
  font-weight: 600;
}

.primary-nav__link[aria-current="page"]::after {
  transform: scaleX(1);
  bottom: 2px;
}

@media (hover: hover) and (pointer: fine) {
  .primary-nav__link:hover {
    color: #FAF7F0;
  }
  .primary-nav__link:hover::after {
    transform: scaleX(1);
  }
}

.primary-nav__link:focus-visible {
  outline: 2px solid var(--parchment, #F1E6CF);
  outline-offset: 4px;
  border-radius: 4px;
}

/* ---------- Header Actions: Sign In / Account ---------- */
.header-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Desktop Sign in / My Library Outline Button */
.header-signin-btn {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  height: 40px;
  padding-inline: 1rem;
  color: #FAF7F0;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  border: 1px solid rgba(241, 230, 207, 0.4);
  border-radius: 8px;
  background: transparent;
  transition: background-color 180ms ease, border-color 180ms ease, color 180ms ease;
  white-space: nowrap;
}

.header-signin-btn svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

@media (min-width: 1080px) {
  .header-signin-btn {
    display: inline-flex;
  }
}

@media (hover: hover) and (pointer: fine) {
  .header-signin-btn:hover {
    background-color: rgba(241, 230, 207, 0.1);
    border-color: rgba(241, 230, 207, 0.7);
    color: #FFFFFF;
  }
}

.header-signin-btn:focus-visible {
  outline: 2px solid var(--parchment, #F1E6CF);
  outline-offset: 2px;
}

/* User Menu & Dropdown */
.header-user-menu {
  position: relative;
  display: none;
}
@media (min-width: 1080px) {
  .header-user-menu {
    display: inline-block;
  }
}

.header-user-btn {
  cursor: pointer;
  appearance: none;
}
.header-user-btn .user-menu-chevron {
  transition: transform 180ms ease;
  width: 12px;
  height: 12px;
  opacity: 0.8;
}
.header-user-btn[aria-expanded="true"] .user-menu-chevron {
  transform: rotate(180deg);
}

.header-user-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 190px;
  background: #231710;
  border: 1px solid rgba(169, 121, 43, 0.45);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  padding: 6px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.header-user-dropdown[hidden] {
  display: none !important;
}

.user-dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  color: #FAF7F0;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  border-radius: 6px;
  transition: background-color 150ms ease, color 150ms ease;
  width: 100%;
  border: none;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
@media (hover: hover) and (pointer: fine) {
  .user-dropdown-item:hover {
    background-color: rgba(241, 230, 207, 0.12);
    color: #FFFFFF;
  }
}
.user-dropdown-item:focus-visible {
  outline: 2px solid var(--parchment, #F1E6CF);
  outline-offset: -2px;
}
.user-dropdown-divider {
  height: 1px;
  background: rgba(169, 121, 43, 0.25);
  margin: 4px 6px;
}
.user-dropdown-logout {
  color: #E57373;
}
@media (hover: hover) and (pointer: fine) {
  .user-dropdown-logout:hover {
    background-color: rgba(229, 115, 115, 0.15);
    color: #FFCDD2;
  }
}

/* Mobile Drawer Reader Links */
.drawer__reader-links {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}
.drawer__profile-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 8px;
  border: 1px solid rgba(241, 230, 207, 0.25);
  color: #FAF7F0;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  transition: background-color 180ms ease, border-color 180ms ease;
}
.drawer__logout-form {
  margin: 0;
  padding: 0;
  width: 100%;
}
.drawer__logout-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  width: 100%;
  padding: 0 16px;
  border-radius: 8px;
  border: 1px solid rgba(229, 115, 115, 0.35);
  background: transparent;
  color: #E57373;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 180ms ease, color 180ms ease;
}

/* ---------- Mobile Hamburger Button (< 1080px) ---------- */
.menu-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  background: rgba(255, 255, 255, 0.04);
  color: #FAF7F0;
  border: 1px solid rgba(169, 121, 43, 0.35);
  border-radius: 8px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 150ms ease, background-color 150ms ease, transform 150ms ease;
}

.menu-btn svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  pointer-events: none;
}

.menu-btn .icon-close { display: none; }
.menu-btn[aria-expanded="true"] .icon-open { display: none; }
.menu-btn[aria-expanded="true"] .icon-close { display: inline; }

@media (hover: hover) and (pointer: fine) {
  .menu-btn:hover {
    border-color: var(--brass, #A9792B);
    background: rgba(169, 121, 43, 0.2);
  }
}

.menu-btn:focus-visible {
  outline: 2px solid var(--brass, #A9792B);
  outline-offset: 2px;
}

@media (min-width: 1080px) {
  .menu-btn {
    display: none !important;
  }
  .drawer {
    display: none !important;
  }
}

/* ==========================================================================
   Mobile Slide-in Drawer (< 1080px, width min(88vw, 380px), 100dvh)
   ========================================================================== */
.drawer {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal, 1060);
  visibility: hidden;
  pointer-events: none;
  transition: visibility 0s linear 0.26s;
}

.drawer[hidden] {
  display: none !important;
}

.drawer.is-open {
  visibility: visible;
  pointer-events: auto;
  transition-delay: 0s;
}

.drawer__scrim {
  position: absolute;
  inset: 0;
  background: rgba(35, 22, 13, 0.55);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 260ms ease;
}

.drawer.is-open .drawer__scrim {
  opacity: 1;
  pointer-events: auto;
}

.drawer__panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(88vw, 380px);
  height: 100dvh;
  background-color: #2B1D14;
  background-image: var(--wood-grain, none);
  border-left: 1px solid rgba(169, 121, 43, 0.35);
  box-shadow: -10px 0 35px rgba(0, 0, 0, 0.55);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 260ms cubic-bezier(0.2, 0.7, 0.2, 1);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: env(safe-area-inset-bottom, 16px);
  box-sizing: border-box;
}

.drawer.is-open .drawer__panel {
  transform: translateX(0);
}

.drawer__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid rgba(169, 121, 43, 0.2);
}

.drawer__close-btn {
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: #FAF7F0;
  border: 1px solid rgba(169, 121, 43, 0.35);
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 150ms ease, border-color 150ms ease;
}

.drawer__close-btn:hover {
  background: rgba(169, 121, 43, 0.2);
  border-color: var(--brass, #A9792B);
}

.drawer__close-btn:focus-visible {
  outline: 2px solid var(--brass, #A9792B);
  outline-offset: 2px;
}

.drawer__nav {
  flex: 1 1 auto;
  padding-block: 0.5rem;
}

.drawer__nav-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.drawer__item {
  border-bottom: 1px solid rgba(169, 121, 43, 0.12);
}

.drawer__link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding-inline: 1.5rem;
  font-family: var(--font-serif);
  font-size: 1.45rem;
  font-weight: 500;
  color: rgba(241, 230, 207, 0.88);
  text-decoration: none;
  transition: color 150ms ease, background-color 150ms ease;
}

.drawer__link:hover,
.drawer__link:focus-visible {
  color: #FFFFFF;
  background-color: rgba(169, 121, 43, 0.12);
}

.drawer__link.active {
  color: var(--accent, #E5C383);
  font-weight: 600;
}

.drawer__active-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--brass, #A9792B);
}

/* Bottom Account & Socials */
.drawer__account-block {
  padding: 1.5rem;
  border-top: 1px solid rgba(169, 121, 43, 0.25);
  background-color: rgba(15, 9, 6, 0.2);
}

.btn-drawer-account {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  width: 100%;
  min-height: 48px;
  padding: 0.75rem 1rem;
  background-color: var(--cta, #6E2B25);
  color: #FAF7F0 !important;
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  font-weight: 600;
  border-radius: 8px;
  text-decoration: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  transition: background-color 150ms ease;
}

.btn-drawer-account:hover {
  background-color: var(--cta-hover, #56211C);
}

.drawer__logout-link {
  display: block;
  text-align: center;
  margin-top: 0.75rem;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  color: var(--muted, #D1BFA5);
  text-decoration: underline;
}

.drawer__socials {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 1.25rem;
}

.drawer__social-link {
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #D1BFA5;
  border: 1px solid rgba(169, 121, 43, 0.35);
  border-radius: 50%;
  text-decoration: none;
  transition: color 150ms ease, border-color 150ms ease, transform 150ms ease;
}

.drawer__social-link:hover {
  color: #FAF7F0;
  border-color: var(--brass, #A9792B);
  transform: scale(1.05);
}
