/* ============================================================
   tw-mobile-nav.css - mobile navigation for theme ws-theme-2
   Loaded via wp_enqueue_style('tw-mobile-nav', ...).
   Printed AFTER css/main.css. Desktop navigation (.tw-nav) NOT touched.
   ============================================================ */

/* --- 1. Burger: visible on mobile, neutralise baked-in .sf-hidden --- */
@media (max-width: 1023.98px) {
  .tw-burger.sf-hidden { display: inline-flex !important; }
}
@media (min-width: 1024px) {
  .tw-burger.sf-hidden { display: none !important; }   /* keep Tailwind lg:hidden */
}

.tw-burger {
  /* Bar geometry is defined once and reused, so the cross can never drift
     out of centre again.
     NOTE: the button is display:inline-flex with flex-direction:column, and in a
     flex container vertical margins DO NOT collapse. The step between bar centres
     is therefore (height + 2 x gap) = 2 + 10 = 12px - not 7px as it would be in
     normal block flow. That is why the open-state shift equals --tw-bar-pitch. */
  --tw-bar-h: 2px;
  --tw-bar-gap: 5px;
  --tw-bar-pitch: calc(var(--tw-bar-h) + var(--tw-bar-gap) * 2);   /* 12px */

  align-items: center;
  justify-content: center;
  flex-direction: column;
  width: 40px;
  height: 40px;
  padding: 0;
  background: transparent;
  border: 0;
  cursor: pointer;
}

/* --- 2. Burger bars (three <span>, inserted server-side) --- */
.tw-burger span {
  display: block;
  width: 22px;                                   /* all three bars are the same length */
  height: var(--tw-bar-h);
  background: #F5F5F0;
  margin: var(--tw-bar-gap) 0;
  transition: transform .25s ease, opacity .25s ease;
  transform-origin: center center;
}

/* Open state: bars 1 and 3 shift by exactly one pitch, so both rotated bars
   pass through the centre of the middle bar -> symmetric cross. */
.tw-burger.open span:nth-child(1) { transform: translateY(var(--tw-bar-pitch)) rotate(45deg); }
.tw-burger.open span:nth-child(2) { opacity: 0; }
.tw-burger.open span:nth-child(3) { transform: translateY(calc(-1 * var(--tw-bar-pitch))) rotate(-45deg); }

/* --- 3. Panel: states, height cap, own scrolling, opaque background --- */
.tw-mobile-panel {
  /* offset = distance from the viewport top to the panel top (header bar height).
     CSS fallback below; JS refines it from the real bar row on load/resize/open. */
  --tw-header-offset: 67px;

  display: none;

  /* (1)+(2) the menu uses exactly the space under the header, never beyond the viewport */
  max-height: calc(100vh - var(--tw-header-offset));    /* fallback for older browsers */
  max-height: calc(100dvh - var(--tw-header-offset));   /* modern dynamic viewport height */

  /* (1) the panel scrolls itself instead of pushing the page */
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;

  /* (3) opaque background matching the header / site colour (coal2 = rgb(11 12 14)) */
  background-color: #0B0C0E;

  scrollbar-width: thin;
}

@media (max-width: 1023.98px) {
  .tw-mobile-panel.sf-hidden        { display: none !important; }
  .tw-mobile-panel.sf-hidden.open   { display: block !important; }
}
@media (min-width: 1024px) {
  .tw-mobile-panel.sf-hidden,
  .tw-mobile-panel.sf-hidden.open   { display: none !important; }
}

/* (4) while the menu is open the page behind must not scroll.
   NOTE: deliberately NO touch-action:none on html/body - a touch-action on an
   ancestor intersects with the panel's own value and would block the panel
   from being swiped. Page locking is done with overflow only. */
html.tw-nav-open {
  overflow: hidden;
  overscroll-behavior: none;
}
html.tw-nav-open body {
  overflow: hidden;
}
/* the panel keeps its own scrolling and absorbs the gesture chain */
html.tw-nav-open .tw-mobile-panel {
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

/* --- 4. Panel content (WordPress menu markup, injected server-side) --- */
.tw-mobile-panel ul               { list-style: none; margin: 0; padding: 0; }
.tw-mobile-panel a                { text-decoration: none; }
.tw-mobile-panel .sub-menu        { padding-left: 16px; }
.tw-mobile-panel .sub-menu a span { font-size: 13.5px; color: rgba(245,245,240,.7); }

/* --- 5. Safety net: if JS did not load, never show a dead button --- */
html:not(.tw-nav-ready) .tw-burger.sf-hidden { display: none !important; }
html.tw-nav-ready .tw-burger.sf-hidden        { display: inline-flex !important; }
@media (min-width: 1024px) {
  html.tw-nav-ready .tw-burger.sf-hidden      { display: none !important; }
}
