/* =========================================
   Base + stacking order
   ========================================= */
html, body { margin: 0; padding: 0; }
* { box-sizing: border-box; }

:root { --header-h: 50px; }

.site-header {
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: var(--shadow-1);
  position: sticky;
  top: 0;
  z-index: 2000; /* below drawer/backdrop */
  height: var(--header-h);
}

/* 3-column header layout at all sizes */
.header-row {
  display: grid;
  grid-template-columns: 44px 1fr 44px; /* [menu] [title] [theme] */
  align-items: center;
  gap: 8px;
  padding: 2px 12px;
  height: var(--header-h);
}

/* Centered page title, consistent typography */
.site-title {
  display: block;
  margin: 0;
  padding: 0 8px;
  text-align: center;
  font-family: 'Oswald', 'Oswald Narrow', 'Arial Narrow', Arial, sans-serif;
  font-weight: 600;
  font-size: 1.3rem;
  line-height: 1.25;
  color: var(--color-muted);
  letter-spacing: .2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* =========================================
   Menu button / hamburger
   ========================================= */
.menu-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 10px;
  color: var(--color-text) !important; /* force icon color in all themes */
}

/* Make the hamburger bars follow the current text color */
.menu-btn svg rect,
.menu-btn svg path {
  fill: currentColor !important;
}

.menu-btn:hover {
  background: var(--header-hover-bg);
}

/* =========================================
   Theme toggle (icon-only, mobile-safe)
   ========================================= */
.theme-toggle {
  background: none;
  border: 1px solid transparent;
  cursor: pointer;
  padding: 6px;
  border-radius: 10px;
  color: var(--color-muted);
  justify-self: end;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
}

.theme-toggle svg {
  width: 22px;
  height: 22px;
  display: block;
}

/* Visibility logic */
.theme-toggle .ico { display: none; }

/* Fallback for first paint (before JS sets data-theme) */
.theme-toggle:not([data-theme]) .ico-sun { display: block; }

/* Normal icon switching */
.theme-toggle[data-theme="light"]  .ico-sun   { display: block; }
.theme-toggle[data-theme="dark"]   .ico-moon  { display: block; }
.theme-toggle[data-theme="modern"] .ico-spark { display: block; }

.theme-toggle:hover {
  background: var(--header-hover-bg);
}
.theme-toggle:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* =========================================
   Drawer (panel) — sits ABOVE everything
   ========================================= */
.nav-drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: -320px;                   /* off-screen */
  width: 320px;
  background: var(--color-surface);
  transition: left .28s ease-in-out;
  z-index: 10001;                 /* higher than backdrop */
  overflow-y: auto;
  box-shadow: var(--shadow-2);
  pointer-events: auto;           /* ensure clicks are accepted */
}
.nav-drawer.open { left: 0; }

.nav-content {
  padding: 20px;
  position: relative;
}

/* Close button inside drawer */
.close-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  width: 36px;
  height: 36px;
  line-height: 36px;
  text-align: center;
  border-radius: 8px;
  color: var(--color-text);
}
.close-btn:hover {
  background: var(--header-hover-bg);
}

/* =========================================
   Menu list
   ========================================= */
.nav-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.nav-list li {
  margin-bottom: 8px;
}
.nav-list a {
  color: var(--color-text);
  text-decoration: none;
  display: block;
  padding: 10px 12px;
  border-radius: 8px;
  transition: background-color 0.2s ease, color 0.2s ease;
}

/* 🔶 Forced dropdown highlight (desktop + mobile)
   - Use !important to beat any older gray-background rules
*/
.nav-list a:hover,
.nav-list a:focus,
.nav-list a:active {
  background: var(--nav-item-hover-bg) !important;   /* orange */
  color: var(--nav-item-hover-text) !important;      /* black text */
}

/* Reduce default gray tap highlight on mobile */
.nav-list a,
.menu-btn,
.theme-toggle,
.close-btn {
  -webkit-tap-highlight-color: transparent;
}

/* =========================================
   Backdrop — real element, BELOW drawer
   ========================================= */
.nav-backdrop {
  position: fixed;
  inset: 0;
  background: var(--nav-backdrop-bg);
  opacity: 0;
  pointer-events: none;          /* disabled until shown */
  transition: opacity .28s ease;
  z-index: 10000;                /* below drawer (10001), above content/header */
}
.nav-backdrop.show {
  opacity: 1;
  pointer-events: auto;          /* captures click to close */
}

/* =========================================
   Small-screen refinements
   ========================================= */
@media (max-width: 768px) {
  .nav-drawer { width: 80vw; }
}

@media (max-width: 420px) {
  .header-row {
    padding: 8px 10px;
    gap: 6px;
  }
  .site-title {
    font-size: 1.05rem;
  }
  .theme-toggle {
    width: 40px;
    height: 40px;
  }
  .theme-toggle svg {
    width: 20px;
    height: 20px;
  }
}
