/* ============================================================
   MEGA MENU — desktop mega-panels, mobile drawer, ⌘K palette.
   Paired with assets/js/util/megamenu.js. Uses design tokens.
   ============================================================ */

/* ---------- Top bar ---------- */
.mm-header { overflow: visible; }
.mm-bar { display: flex; align-items: center; gap: var(--sp-4); width: 100%; }
.mm-nav { display: flex; align-items: center; gap: var(--sp-1); margin-left: var(--sp-5); }
.mm-actions { margin-left: auto; display: flex; align-items: center; gap: var(--sp-2); }

.mm-trigger {
  display: inline-flex; align-items: center; gap: 6px;
  background: none; border: 0; cursor: pointer;
  color: var(--text-soft); font: inherit; font-size: var(--fs-sm); font-weight: 600;
  padding: 8px 12px; border-radius: var(--r-pill);
  transition: color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.mm-trigger:hover, .mm-trigger[aria-expanded="true"] { color: var(--text); background: rgba(255,255,255,.06); }
.mm-trigger.accent { color: var(--gold); }
.mm-trigger.accent:hover, .mm-trigger.accent[aria-expanded="true"] { color: var(--gold); background: rgba(255,221,0,.1); }
.mm-chev { width: 7px; height: 7px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg) translateY(-1px); transition: transform var(--dur) var(--ease); opacity: .7; }
.mm-trigger[aria-expanded="true"] .mm-chev { transform: rotate(-135deg) translateY(-1px); }

/* ---------- Bar actions ---------- */
.mm-live {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: var(--font-mono); font-size: var(--fs-xs); font-weight: 700; letter-spacing: .08em;
  color: #fff; background: var(--ember); padding: 5px 11px; border-radius: var(--r-pill);
  text-transform: uppercase; box-shadow: 0 0 0 0 rgba(255,90,31,.6); animation: mm-pulse 2s infinite;
}
.mm-live-dot { width: 8px; height: 8px; border-radius: 50%; background: #fff; }
@keyframes mm-pulse { 0% { box-shadow: 0 0 0 0 rgba(255,90,31,.55); } 70% { box-shadow: 0 0 0 9px rgba(255,90,31,0); } 100% { box-shadow: 0 0 0 0 rgba(255,90,31,0); } }

.mm-search {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  background: rgba(255,255,255,.05); border: 1px solid var(--border); color: var(--text-soft);
  border-radius: var(--r-pill); padding: 7px 12px; font: inherit; font-size: var(--fs-sm);
  transition: border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.mm-search:hover { border-color: var(--accent); color: var(--text); }
.mm-search-ic { font-size: 1.05rem; line-height: 1; }
.mm-kbd { font-family: var(--font-mono); font-size: 0.66rem; border: 1px solid var(--border); border-radius: 5px; padding: 1px 6px; color: var(--text-soft); }

.mm-burger { display: none; background: none; border: 0; cursor: pointer; width: 42px; height: 42px; flex-direction: column; gap: 5px; align-items: center; justify-content: center; }
.mm-burger span { width: 22px; height: 2px; background: var(--text); border-radius: 2px; transition: transform var(--dur) var(--ease), opacity var(--dur) var(--ease); }
body.mm-drawer-open .mm-burger span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
body.mm-drawer-open .mm-burger span:nth-child(2) { opacity: 0; }
body.mm-drawer-open .mm-burger span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ---------- Desktop mega panels ---------- */
.mm-panels { position: fixed; left: 0; right: 0; top: var(--header-h); z-index: 99; pointer-events: none; }
.mm-panel {
  position: absolute; left: 0; right: 0; top: 0;
  background: color-mix(in srgb, var(--bg-elev) 96%, transparent);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border); box-shadow: var(--shadow-md);
  opacity: 0; visibility: hidden; transform: translateY(-10px); pointer-events: none;
  transition: opacity .22s var(--ease), transform .22s var(--ease), visibility .22s;
}
.mm-header[data-panel="watch"] #mm-panel-watch,
.mm-header[data-panel="liberate"] #mm-panel-liberate,
.mm-header[data-panel="read"] #mm-panel-read,
.mm-header[data-panel="connect"] #mm-panel-connect {
  opacity: 1; visibility: visible; transform: none; pointer-events: auto;
}
.mm-panel-inner { display: grid; grid-template-columns: 1.5fr 1fr; gap: var(--sp-6); padding: var(--sp-5) var(--sp-4); }
.mm-links { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-2); align-content: start; }

.mm-item {
  display: flex; align-items: flex-start; gap: var(--sp-3);
  padding: var(--sp-3); border-radius: var(--r-md); border: 1px solid transparent;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.mm-item:hover { background: var(--bg-card); border-color: var(--border); transform: translateY(-2px); }
.mm-item.current { border-color: var(--accent); background: var(--bg-card); }
.mm-ic { font-size: 1.3rem; line-height: 1.2; flex-shrink: 0; width: 1.6em; text-align: center; }
.mm-it-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.mm-it-label { font-weight: 700; font-size: var(--fs-sm); color: var(--text); }
.mm-it-desc { font-size: var(--fs-xs); color: var(--text-soft); line-height: 1.4; }
.mm-item.is-live.now .mm-ic { color: var(--ember); animation: mm-blink 1.4s infinite; }
@keyframes mm-blink { 50% { opacity: .35; } }

/* ---------- Feature tiles (right column) ---------- */
.mm-extra { display: grid; gap: var(--sp-3); align-content: start; }
.mm-feature {
  display: flex; flex-direction: column; gap: 6px;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: var(--sp-4); transition: border-color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.mm-feature:hover { border-color: var(--accent); transform: translateY(-2px); }
.mm-feat-kicker { font-family: var(--font-mono); font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .12em; color: var(--accent); }
.mm-feature strong { font-size: var(--fs-md); line-height: 1.2; }
.mm-feat-text { font-size: var(--fs-xs); color: var(--text-soft); line-height: 1.5; }
.mm-feat-cta { font-size: var(--fs-sm); font-weight: 700; color: var(--gold); margin-top: 2px; }

.mm-latest { padding: 0; overflow: hidden; }
.mm-latest .mm-feat-kicker { padding: var(--sp-3) var(--sp-4) 0; }
.mm-latest-body { display: flex; flex-direction: column; }
.mm-latest-body img { width: 100%; aspect-ratio: 16/9; object-fit: cover; margin-top: 8px; }
.mm-latest-title { font-weight: 700; font-size: var(--fs-sm); padding: var(--sp-3) var(--sp-4); line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.mm-essay-list { display: grid; gap: 6px; }
.mm-essay { display: flex; justify-content: space-between; gap: var(--sp-2); padding: 8px 10px; border-radius: var(--r-sm); transition: background var(--dur) var(--ease); }
.mm-essay:hover { background: var(--bg-elev); }
.mm-essay-title { font-size: var(--fs-sm); font-weight: 600; }
.mm-essay-meta { font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--text-soft); white-space: nowrap; }

.mm-reach-num { font-family: var(--font-mono); font-size: var(--fs-2xl); font-weight: 800; background: var(--grad-brand); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.mm-reach-lbl { font-size: var(--fs-xs); color: var(--text-soft); }
.mm-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: var(--sp-2); }
.mm-chip { font-family: var(--font-mono); font-size: var(--fs-xs); padding: 3px 10px; border-radius: var(--r-pill); border: 1px solid var(--border); color: var(--text-soft); transition: all var(--dur) var(--ease); }
.mm-chip:hover { border-color: var(--accent); color: var(--text); }

.mm-skel { color: var(--text-soft); font-size: var(--fs-xs); opacity: .7; }

/* ---------- Mobile drawer ---------- */
.mm-drawer {
  position: fixed; inset: 0; z-index: 200; background: var(--bg);
  display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform .3s var(--ease); visibility: hidden;
}
body.mm-drawer-open .mm-drawer { transform: none; visibility: visible; }
body.mm-drawer-open { overflow: hidden; }
.mmd-top { display: flex; align-items: center; justify-content: space-between; height: var(--header-h); border-bottom: 1px solid var(--border); }
.mmd-close { background: none; border: 0; color: var(--text); font-size: 2rem; line-height: 1; cursor: pointer; }
.mmd-scroll { flex: 1; overflow-y: auto; padding: var(--sp-4) var(--sp-4) var(--sp-8); display: flex; flex-direction: column; gap: var(--sp-4); }
.mmd-search { width: 100%; justify-content: center; }
.mmd-live { align-self: flex-start; }
.mmd-group { display: flex; flex-direction: column; gap: 4px; }
.mmd-h { font-family: var(--font-mono); font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .15em; color: var(--text-soft); margin: var(--sp-2) 0 4px; }
.mmd-h.accent { color: var(--gold); }
.mmd-items { display: grid; gap: 4px; }
.mmd-items .mm-item { background: var(--bg-card); border: 1px solid var(--border); }
.mmd-foot { display: flex; flex-direction: column; gap: var(--sp-3); margin-top: var(--sp-4); padding-top: var(--sp-4); border-top: 1px solid var(--border); }
.mmd-foot .btn { width: 100%; }
.mmd-socials { display: flex; flex-wrap: wrap; gap: var(--sp-2); justify-content: center; }
.mmd-social { font-size: var(--fs-sm); color: var(--text-soft); padding: 6px 12px; border: 1px solid var(--border); border-radius: var(--r-pill); }

/* ---------- Command palette ---------- */
.mm-palette { position: fixed; inset: 0; z-index: 300; background: rgba(0,0,0,.6); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); display: none; align-items: flex-start; justify-content: center; padding: 12vh var(--sp-4) var(--sp-4); }
.mm-palette.open { display: flex; }
.mmp-box { width: min(620px, 100%); background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-md); overflow: hidden; animation: mm-rise .18s var(--ease); }
@keyframes mm-rise { from { transform: translateY(10px); opacity: 0; } }
.mmp-input { width: 100%; padding: var(--sp-4) var(--sp-5); background: none; border: 0; border-bottom: 1px solid var(--border); color: var(--text); font: inherit; font-size: var(--fs-md); }
.mmp-input:focus { outline: none; }
.mmp-results { list-style: none; margin: 0; padding: var(--sp-2); max-height: 50vh; overflow-y: auto; }
.mmp-item { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-radius: var(--r-md); cursor: pointer; }
.mmp-item.sel, .mmp-item:hover { background: var(--bg-card); }
.mmp-label { font-weight: 600; font-size: var(--fs-sm); }
.mmp-group { font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--text-soft); }
.mmp-empty { padding: var(--sp-4); color: var(--text-soft); font-size: var(--fs-sm); text-align: center; }
.mmp-hint { display: flex; gap: var(--sp-4); padding: var(--sp-2) var(--sp-5); border-top: 1px solid var(--border); font-size: var(--fs-xs); color: var(--text-soft); }
.mmp-hint kbd { font-family: var(--font-mono); border: 1px solid var(--border); border-radius: 4px; padding: 0 5px; margin-right: 3px; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .mm-nav { display: none; }
  .mm-panels { display: none; }
  .mm-search .mm-kbd { display: none; }
  .mm-search-ic { font-size: 1.2rem; }
  .mm-search { padding: 8px 10px; }
  .mm-join { display: none; }
  #theme-toggle { display: none; }
  .mm-burger { display: flex; }
}
@media (min-width: 901px) {
  .mm-drawer { display: none; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .mm-live { animation: none; }
  .mm-item.is-live.now .mm-ic { animation: none; }
  .mm-panel, .mm-drawer, .mmp-box { transition: none; animation: none; }
}
