/* ─── Topbar ─── */
.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  height: var(--topbar-h);
  background: var(--topbar);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  border-bottom: 1px solid var(--border);
}

.topbar__inner {
  display: flex;
  align-items: center;
  height: var(--topbar-h);
  gap: var(--sp-2);
}

/* ─── Logo ─── */
.logo {
  display: flex;
  align-items: center;
  gap: 2px;
  text-decoration: none;
  flex-shrink: 0;
  margin-right: var(--sp-8);
}

.logo__mark {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 22px;
  color: var(--accent);
  line-height: 1;
}

.logo__text {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.08em;
  color: var(--text-heading);
  line-height: 1;
}

/* ─── Logo Terminal Prompt ─── */
.logo__chevron {
  color: var(--accent);
  flex-shrink: 0;
  margin-right: -6px;
}

.logo__cursor {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
  margin-right: 6px;
  animation: cursorBlink 1s step-end infinite;
}

@keyframes cursorBlink {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0; }
}

/* ─── Nav ─── */
.nav {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  flex: 1;
}

.nav__item {
  position: relative;
}

.nav__link {
  display: flex;
  align-items: center;
  padding: var(--sp-2) var(--sp-3);
  font-family: var(--font-sans);
  font-size: 13.5px;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  border-radius: var(--radius);
  transition: color var(--t), background var(--t);
  white-space: nowrap;
}

.nav__link:hover {
  color: var(--text);
  background: var(--chip-hover);
}

/* Current page indicator */
.nav__link--current {
  color: var(--accent);
}

.nav__letter {
  display: inline-block;
  animation: letterBounce 3s ease-in-out infinite;
}

@keyframes letterBounce {
  0%, 100% { transform: translateY(0); }
  8% { transform: translateY(-1.5px); }
  16% { transform: translateY(0); }
}

/* ─── Mega Menu ─── */
.mega {
  position: absolute;
  top: calc(100% + var(--sp-2));
  left: 0;
  width: 560px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: var(--sp-5);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition:
    opacity var(--t-ui) var(--ease),
    transform var(--t-ui) var(--ease),
    visibility var(--t-ui);
  pointer-events: none;
}

/* Invisible bridge so mouse can travel from link to dropdown */
.mega::before {
  content: '';
  position: absolute;
  top: calc(-1 * var(--sp-2) - 4px);
  left: 0;
  right: 0;
  height: calc(var(--sp-2) + 4px);
}

.nav__item:hover > .mega,
.nav__item.mega-open > .mega {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  pointer-events: auto;
}

.mega__inner {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: var(--sp-5);
}

/* ─── Mega Columns ─── */
.megaCol__label {
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted-2);
  margin-bottom: var(--sp-3);
}

.megaCol__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}

.megaCol--cta {
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  min-width: 80px;
}

/* ─── Mega Post Link ─── */
.megaPost {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2);
  text-decoration: none;
  border-radius: var(--radius);
  transition: background var(--t);
}

.megaPost:hover {
  background: var(--chip-hover);
}

.megaPost__img {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  flex-shrink: 0;
  background: var(--surface-2);
}

.megaPost__img--empty {
  display: block;
}

.megaPost__title {
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* View All CTA */
.mega__viewAll {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--accent);
  text-decoration: none;
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius);
  transition: background var(--t), color var(--t);
  white-space: nowrap;
}

.mega__viewAll:hover {
  background: var(--accent-subtle);
  color: var(--accent-hover);
}

.mega__viewAll svg {
  transition: transform var(--t);
}

.mega__viewAll:hover svg {
  transform: translateX(2px);
}

/* ─── Topbar Actions ─── */
.topbar__actions {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  margin-left: auto;
}

.topbar__btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: var(--radius);
  cursor: pointer;
  transition: color var(--t), background var(--t);
}

.topbar__btn:hover {
  color: var(--text);
  background: var(--chip-hover);
}

/* Search trigger button */
.topbar__search {
  width: auto;
  gap: var(--sp-2);
  padding: 0 var(--sp-3);
  height: 32px;
  border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--border));
  background: var(--surface);
  border-radius: var(--radius);
}

.topbar__search:hover {
  border-color: var(--border);
  background: var(--surface-2);
}

.topbar__search-text {
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--muted-2);
}

.kbd {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  color: var(--muted-2);
  background: var(--chip);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1px 5px;
  line-height: 1.4;
}

/* Theme toggle icons */
#themeToggle {
  position: relative;
}

#themeToggle svg {
  stroke: var(--accent);
  fill: none;
  position: absolute;
  top: 50%;
  left: 50%;
  opacity: 0;
  transform: translate(-50%, -50%) rotate(-90deg);
  transition: opacity 300ms var(--ease), transform 500ms var(--ease);
}

/* Dark mode: show sun, hide moon */
html[data-theme="dark"] #themeToggle .theme-icon-sun,
html:not([data-theme="light"]) #themeToggle .theme-icon-sun {
  opacity: 1;
  transform: translate(-50%, -50%) rotate(0deg);
}

html[data-theme="dark"] #themeToggle .theme-icon-moon,
html:not([data-theme="light"]) #themeToggle .theme-icon-moon {
  opacity: 0;
  transform: translate(-50%, -50%) rotate(90deg);
}

/* Light mode: show moon, hide sun */
html[data-theme="light"] #themeToggle .theme-icon-moon {
  opacity: 1;
  transform: translate(-50%, -50%) rotate(0deg);
}

html[data-theme="light"] #themeToggle .theme-icon-sun {
  opacity: 0;
  transform: translate(-50%, -50%) rotate(-90deg);
}

/* ─── Command Palette / Search Modal ─── */
.searchModal {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: min(20vh, 160px);
}

.searchModal[hidden] {
  display: none;
}

.searchModal__backdrop {
  position: absolute;
  inset: 0;
  background: var(--overlay);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fadeIn var(--t-modal) var(--ease);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.searchModal__container {
  position: relative;
  width: 100%;
  max-width: 580px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow), 0 0 0 1px var(--border-subtle);
  overflow: hidden;
  animation: modalIn var(--t-modal) var(--ease);
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: scale(0.97) translateY(-8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.searchModal__header {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
}

.searchModal__icon {
  flex-shrink: 0;
  color: var(--muted);
}

.searchModal__input {
  flex: 1;
  border: none;
  background: none;
  font-family: var(--font-sans);
  font-size: 15px;
  color: var(--text);
  outline: none;
}

.searchModal__input::placeholder {
  color: var(--muted-2);
}

.searchModal__esc {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  color: var(--muted-2);
  background: var(--chip);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px 6px;
  flex-shrink: 0;
}

.searchModal__body {
  padding: var(--sp-3) var(--sp-2);
  max-height: 400px;
  overflow-y: auto;
}

.searchModal__section {
  padding: var(--sp-2) var(--sp-3);
}

.searchModal__section[hidden] {
  display: none;
}

.searchModal__label {
  display: block;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted-2);
  padding: var(--sp-2) var(--sp-2);
  margin-bottom: var(--sp-1);
}

.searchModal__link {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  font-family: var(--font-sans);
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
  text-decoration: none;
  border-radius: var(--radius);
  transition: background var(--t);
}

.searchModal__link:hover,
.searchModal__link.focused {
  background: var(--chip-hover);
}

.searchModal__link svg {
  color: var(--muted);
  flex-shrink: 0;
}

/* Search result items */
.searchResult {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  text-decoration: none;
  border-radius: var(--radius);
  transition: background var(--t);
}

.searchResult:hover,
.searchResult.focused {
  background: var(--chip-hover);
}

.searchResult__type {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-subtle);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.searchResult__title {
  font-family: var(--font-sans);
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.searchModal__empty,
.searchModal__loading {
  padding: var(--sp-8) var(--sp-3);
  text-align: center;
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--muted);
}

/* ─── Mobile Drawer ─── */
.drawer__overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-overlay);
  background: var(--overlay);
  opacity: 0;
  visibility: hidden;
  transition:
    opacity var(--t-ui) var(--ease),
    visibility var(--t-ui);
}

.drawer__overlay.open {
  opacity: 1;
  visibility: visible;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: calc(var(--z-overlay) + 1);
  width: 300px;
  max-width: 85vw;
  background: var(--surface);
  border-left: 1px solid var(--border);
  transform: translateX(100%);
  transition: transform var(--t-ui) var(--ease);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.admin-bar .drawer {
  top: 32px;
}

@media (max-width: 782px) {
  .admin-bar .drawer {
    top: 46px;
  }
}

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

.drawer__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
}

.drawer__nav {
  display: flex;
  flex-direction: column;
  padding: var(--sp-3);
  gap: var(--sp-1);
}

.drawer__link {
  display: flex;
  align-items: center;
  padding: var(--sp-3) var(--sp-4);
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  text-decoration: none;
  border-radius: var(--radius);
  transition: background var(--t);
}

.drawer__link:hover {
  background: var(--chip-hover);
}

.drawer__link.nav__link--current {
  color: var(--accent);
}

.drawer__link.nav__link--current .nav__letter {
  display: inline-block;
  animation: letterBounce 3s ease-in-out infinite;
}

/* ─── Drawer collapsible sections ─── */
.drawer__section {
  border: none;
}

.drawer__section summary {
  list-style: none;
  cursor: pointer;
}

.drawer__section summary::-webkit-details-marker {
  display: none;
}

.drawer__toggle {
  justify-content: space-between;
}

.drawer__toggle::after {
  content: '';
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform 200ms var(--ease);
  flex-shrink: 0;
  margin-left: auto;
}

.drawer__section[open] > .drawer__toggle::after {
  transform: rotate(45deg);
}

.drawer__sectionBody {
  padding: var(--sp-1) var(--sp-3) var(--sp-3) var(--sp-5);
}

.drawer__postGroup {
  margin-bottom: var(--sp-3);
}

.drawer__postGroup:last-of-type {
  margin-bottom: var(--sp-2);
}

.drawer__postLabel {
  display: block;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: var(--sp-1) var(--sp-2);
  margin-bottom: var(--sp-1);
}

.drawer__post {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 6px var(--sp-2);
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: background var(--t);
}

.drawer__post:hover {
  background: var(--chip-hover);
}

.drawer__postImg {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  flex-shrink: 0;
  background: var(--surface-2);
}

.drawer__postImg--empty {
  display: block;
}

.drawer__postTitle {
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-clamp: 2;
  overflow: hidden;
}

.drawer__viewAll {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  padding: var(--sp-1) var(--sp-2);
  border-radius: var(--radius-sm);
  transition: background var(--t), color var(--t);
}

.drawer__viewAll:hover {
  background: var(--accent-subtle);
  color: var(--accent-hover);
}

.drawer__viewAll svg {
  transition: transform var(--t);
}

.drawer__viewAll:hover svg {
  transform: translateX(2px);
}

/* ─── Mobile Hamburger (hidden on desktop) ─── */
.topbar__hamburger {
  display: none;
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
  .nav { display: none; }
  .topbar__search-text { display: none; }
  .kbd { display: none; }
  .topbar__hamburger { display: flex; }

  .topbar__search {
    border: none;
    background: transparent;
    width: 32px;
    padding: 0;
  }

  .searchModal__container {
    margin: 0 var(--sp-4);
    max-width: none;
  }
}
