/* === M4D Base (mobile-first) === */
:root {
  --bg: #0b1022;
  --bg2: #0f172a;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --card: #0d1224;
  --card2: #0a1020;
  --accent: #60a5fa;
  --accent-2: #34d399;
  --ring: rgba(96, 165, 250, .45);
  --border: rgba(255, 255, 255, .08);
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --radius: 18px;
  --safeTop: env(safe-area-inset-top, 0px);
}

* {
  box-sizing: border-box
}

html,
body {
  height: auto;
  min-height: 100%;
  margin: 0;
  color: var(--text);
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%);
  background-attachment: scroll;
  overflow-x: clip;
  -webkit-text-size-adjust: 100%;
}

img,
svg,
video,
canvas,
iframe {
  max-width: 100%;
  height: auto
}

/* Prevent any rogue element from forcing page-wide horizontal scroll */
:where(.page, main, section) {
  max-width: 100%
}

/* Containers */
.container {
  max-width: min(1100px, calc(100% - 24px));
  margin-inline: auto;
  padding: 16px 12px
}

/* Fluid grids */
.grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr))
}

@media (max-width:420px) {
  .grid {
    grid-template-columns: 1fr
  }
}

/* Cards */
.card {
  display: block;
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  padding: 18px;
  background: linear-gradient(180deg, var(--card), var(--card2));
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  text-decoration: none;
  color: var(--text);
  min-height: clamp(100px, 20vw, 140px);
}

.card h3 {
  margin: 0 0 6px;
  font-size: 18px;
  letter-spacing: .2px
}

.card p {
  margin: 0;
  color: var(--muted);
  font-size: 14px
}

/* Tables: keep page from scrolling horizontally, but allow table itself to scroll when needed */
table {
  width: 100%;
  border-collapse: collapse
}

@media (max-width: 768px) {
  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch
  }
}

/* Header safe-area padding if a page uses a sticky header */
.m4d-header {
  padding-top: var(--safeTop)
}



/* === HEADER SPACING OVERRIDE (safe, CSS-only) === */
:root {
  --m4d-head-h-desktop: 48px;
  --m4d-head-h-mobile: 44px;
  --m4d-pad-x: 14px;
  --m4d-gap: 10px;
}

/* Index-style header (.header-bleed) */
.header-bleed .header-content {
  max-width: 1200px;
  margin: 0 auto !important;
  padding: 8px var(--m4d-pad-x) !important;
  min-height: var(--m4d-head-h-desktop) !important;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--m4d-gap);
}

.header-bleed .ticker .header-content {
  padding: 6px var(--m4d-pad-x) !important;
  min-height: 30px !important
}

.header-bleed .brand .logo {
  width: 18px !important;
  height: 18px !important;
  border-radius: 6px !important
}

/* Generic header pattern (header .inner + nav.primary + .hamburger) */
header .inner {
  max-width: 1100px;
  margin: 0 auto !important;
  padding: 8px var(--m4d-pad-x) !important;
  min-height: var(--m4d-head-h-desktop) !important;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--m4d-gap);
}

nav.primary {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: nowrap
}

nav.primary a {
  padding: 6px 8px !important;
  border-radius: 10px !important;
  font-size: 13px !important
}

/* Legacy inline header container (header > .container[style=...]) */
header>.container {
  max-width: 1100px;
  margin: 0 auto !important;
  padding: 8px var(--m4d-pad-x) !important;
  min-height: var(--m4d-head-h-desktop) !important;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--m4d-gap);
}

/* Mobile: keep burger, hide desktop nav */
@media (max-width:860px) {

  header .inner,
  .header-bleed .header-content,
  header>.container {
    min-height: var(--m4d-head-h-mobile) !important;
  }
}

/* Reduce gap after header */
header+ :is(main, .container, section) {
  margin-top: 8px !important;
}

/* --- Neutralize any spacer growth and keep a tiny, consistent gap --- */
.m4d-spacer {
  display: block !important;
  height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
}

.m4d-header+ :is(main, .container, section, div) {
  margin-top: clamp(8px, 2vw, 16px) !important;
}

/* Header bar stays clamped, but allow drawer to render outside */
.m4d-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  overflow: visible;
}

.m4d-header .m4d-top {
  height: clamp(var(--m4d-head-h-mobile, 56px), 8vw, var(--m4d-head-h-desktop, 64px)) !important;
  min-height: clamp(var(--m4d-head-h-mobile, 56px), 8vw, var(--m4d-head-h-desktop, 64px)) !important;
  display: flex;
  align-items: center;
  overflow: hidden;
  /* clamp content, not the drawer */
}

/* Mobile drawer sits just below the bar and animates open/close */
#m4d-drawer {
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  max-height: 75vh;
  overflow: auto;
  z-index: 1001;

  /* hidden state */
  transform: translateY(-8px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: transform .18s ease, opacity .18s ease, visibility 0s linear .18s;
}

/* visible state toggled by data attribute on the header */
.m4d-header[data-open="1"] #m4d-drawer {
  transform: translateY(0);
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition-delay: 0s;
}

/* Desktop: inline again */
@media (min-width: 860px) {
  #m4d-drawer {
    position: static;
    max-height: none;
    overflow: visible;
    transform: none;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  .m4d-header {
    overflow: visible;
  }
}