/* Header bar with lightweight sticky behavior. */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--header-bg);
  border-bottom: 1px solid var(--line);
  transition:
    background-color 260ms ease,
    border-color 260ms ease;
}

/* Inner header layout keeps content aligned with the main container width. */
.header-inner {
  max-width: 720px;
  margin: 0 auto;
  padding: 0.85rem 1.2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* Right-aligned header actions (menu + theme icon). */
.header-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  margin-left: auto;
  flex-wrap: wrap;
}

/* Brand image in the top-left corner. */
.brand {
  display: inline-flex;
  align-items: center;
  margin: 0;
  text-decoration: none;
}

.brand img {
  width: 40px;
  height: 40px;
  border-radius: 0.5rem;
  display: block;
}

/* Dropdown list container for top-level menu groups. */
.menu {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Each dropdown uses <details> so it works with no JavaScript. */
.menu details {
  position: relative;
}

/* Top-level dropdown trigger styling. */
.menu summary {
  list-style: none;
  cursor: pointer;
  padding: 0.25rem 0.1rem;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font-size: 0.9rem;
  transition:
    color 180ms ease,
    opacity 180ms ease,
    transform 180ms ease;
}

/* Add a small arrow icon and animate it when the dropdown opens. */
.menu summary::after {
  content: "▾";
  margin-left: 0.45rem;
  display: inline-block;
  transition: transform 180ms ease;
}

/* Hide default browser disclosure marker for custom summary appearance. */
.menu summary::-webkit-details-marker {
  display: none;
}

/* Subtle visual cue on hover/focus for better interactivity feedback. */
.menu summary:hover,
.menu summary:focus-visible {
  opacity: 0.72;
  transform: translateY(-1px);
}

/* Rotate the custom arrow while the dropdown is expanded. */
.menu details[open] summary::after {
  transform: rotate(180deg);
}

/* Dropdown panel appears below its trigger. */
.dropdown-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 0.35rem);
  min-width: 200px;
  margin: 0;
  padding: 0.5rem;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 0.5rem;
  box-shadow: 0 8px 18px var(--panel-shadow);
  transform-origin: top right;
  transition:
    background-color 260ms ease,
    border-color 260ms ease,
    box-shadow 260ms ease;
}

/* Animate dropdown panel when it appears. */
.menu details[open] .dropdown-panel {
  animation: dropdown-in 180ms ease;
}

@keyframes dropdown-in {
  from {
    opacity: 0;
    transform: translateY(-6px) scale(0.98);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Links inside dropdown panels. */
.dropdown-panel a {
  display: block;
  padding: 0.35rem 0.4rem;
  color: var(--text);
  text-decoration: none;
  border-radius: 0.35rem;
  transition:
    color 260ms ease,
    background-color 180ms ease;
}

/* Hover/focus affordance for dropdown links. */
.dropdown-panel a:hover,
.dropdown-panel a:focus-visible {
  background: var(--link-hover);
}

/* Theme selector control in the top header. */
.theme-control {
  display: inline-flex;
  align-items: center;
}

.theme-toggle {
  width: 1.8rem;
  height: 1.8rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 1.15rem;
  opacity: 0.82;
  padding: 0;
  transition:
    color 260ms ease,
    opacity 160ms ease,
    transform 180ms ease;
}

/* Keep theme icon sizing consistent across sun/moon states. */
.theme-toggle svg {
  width: 1.05rem;
  height: 1.05rem;
  display: block;
}

.theme-toggle:hover,
.theme-toggle:focus-visible {
  opacity: 1;
  transform: translateY(-1px) scale(1.05);
}

/* Mobile adjustments for header and dropdown alignment. */
@media (max-width: 768px) {
  .header-inner {
    margin: 0 1rem;
    padding: 0.75rem 0;
  }

  .dropdown-panel {
    right: auto;
    left: 0;
    transform-origin: top left;
  }
}

@media (prefers-reduced-motion: reduce) {
  .menu summary,
  .menu summary::after {
    transition: none;
  }

  .site-header,
  .dropdown-panel,
  .dropdown-panel a,
  .theme-toggle {
    transition: none;
  }

  .menu details[open] .dropdown-panel {
    animation: none;
  }
}
