/* Edge Journal — dedicated small-screen navigation and article refinement */

/* Desktop/tablet-large: keep the original sidebar, hide the mobile header. */
.journal-mobile-header {
  display: none;
}

@media (max-width: 820px) {
  html.journal-menu-open,
  html.journal-menu-open body {
    overflow: hidden !important;
  }

  body.article-page,
  body.edge-journal-page,
  body.posts-index-page,
  body.tools-index-page,
  body.tool-page {
    background: #05070a !important;
  }

  /* The desktop sidebar is not repurposed on small screens: it disappears completely. */
  body.article-page .left-sidebar,
  body.edge-journal-page .left-sidebar,
  body.posts-index-page .left-sidebar,
  body.tools-index-page .left-sidebar,
  body.tool-page .left-sidebar {
    display: none !important;
  }

  /* Real mobile header */
  .journal-mobile-header {
    --journal-mobile-h: 74px;
    display: block;
    position: sticky;
    top: 0;
    z-index: 1000;
    width: 100%;
    padding-top: var(--edge-safe-top, 0px);
    background: rgba(5, 8, 12, .92);
    border-bottom: 1px solid rgba(153, 174, 204, .14);
    backdrop-filter: blur(18px) saturate(1.15);
    -webkit-backdrop-filter: blur(18px) saturate(1.15);
  }

  .journal-mobile-header__bar {
    min-height: var(--journal-mobile-h);
    padding: 0 max(16px, var(--edge-safe-right, 0px)) 0 max(16px, var(--edge-safe-left, 0px));
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
  }

  .journal-mobile-header__brand {
    min-width: 0;
    display: inline-flex;
    align-items: center;
    gap: 12px;
    text-decoration: none !important;
  }

  .journal-mobile-header__brand img {
    display: block;
    width: 72px;
    height: 40px;
    object-fit: contain;
    object-position: left center;
    flex: 0 0 auto;
  }

  .journal-mobile-header__identity {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0;
    min-width: 0;
    line-height: .88;
  }

  .journal-mobile-header__identity strong,
  .journal-mobile-header__identity em {
    display: block;
    margin: 0;
    font-style: normal;
    font-family: var(--base-font-family, system-ui, sans-serif);
    font-size: .74rem;
    font-weight: 800;
    letter-spacing: .12em;
  }

  .journal-mobile-header__identity strong {
    color: #f4f7fb;
  }

  .journal-mobile-header__identity em {
    color: #5b9cff;
  }

  .journal-mobile-header__toggle {
    position: relative;
    flex: 0 0 46px;
    width: 46px;
    height: 46px;
    min-width: 46px;
    min-height: 46px;
    margin: 0;
    padding: 0;
    display: grid;
    place-items: center;
    border: 1px solid rgba(157, 177, 204, .16);
    border-radius: 0;
    background: rgba(255,255,255,.025);
    color: #eef3f9;
  }

  .journal-mobile-header__toggle span {
    position: absolute;
    width: 22px;
    height: 2px;
    background: currentColor;
    transition: transform .22s ease, opacity .18s ease, top .22s ease;
  }

  .journal-mobile-header__toggle span:nth-child(1) { transform: translateY(-7px); }
  .journal-mobile-header__toggle span:nth-child(2) { transform: translateY(0); }
  .journal-mobile-header__toggle span:nth-child(3) { transform: translateY(7px); }

  .journal-mobile-header.is-menu-open .journal-mobile-header__toggle span:nth-child(1) {
    transform: rotate(45deg);
  }
  .journal-mobile-header.is-menu-open .journal-mobile-header__toggle span:nth-child(2) {
    opacity: 0;
  }
  .journal-mobile-header.is-menu-open .journal-mobile-header__toggle span:nth-child(3) {
    transform: rotate(-45deg);
  }

  /* Drawer */
  .journal-mobile-menu {
    position: fixed;
    top: 0;
    right: 0;
    z-index: 1003;
    width: min(88vw, 390px);
    height: 100vh;
    height: 100dvh;
    padding: max(20px, var(--edge-safe-top, 0px)) max(20px, var(--edge-safe-right, 0px)) max(24px, var(--edge-safe-bottom, 0px)) 20px;
    display: flex;
    flex-direction: column;
    background: #080d14;
    border-left: 1px solid rgba(153, 174, 204, .16);
    box-shadow: -24px 0 70px rgba(0,0,0,.5);
    transform: translate3d(102%, 0, 0);
    visibility: hidden;
    transition: transform .28s cubic-bezier(.2,.8,.2,1), visibility .28s;
  }

  .journal-mobile-header.is-menu-open .journal-mobile-menu {
    transform: translate3d(0,0,0);
    visibility: visible;
  }

  .journal-mobile-menu__top {
    min-height: 54px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid rgba(153, 174, 204, .13);
    color: #7d8a9b;
    font-size: .68rem;
    font-weight: 800;
    letter-spacing: .18em;
  }

  .journal-mobile-menu__close {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: #f4f7fb;
    font-size: 2rem;
    font-weight: 300;
    line-height: 1;
  }

  .journal-mobile-menu__nav {
    display: flex;
    flex-direction: column;
    margin-top: 20px;
  }

  .journal-mobile-menu__nav a {
    min-height: 62px;
    padding: 0 2px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    border-bottom: 1px solid rgba(153, 174, 204, .1);
    color: #c0c9d6;
    text-decoration: none !important;
    font-size: 1.08rem;
    font-weight: 650;
    letter-spacing: -.02em;
  }

  .journal-mobile-menu__nav a > span:last-child {
    color: #536174;
    font-size: .9rem;
  }

  .journal-mobile-menu__nav a.is-active {
    color: #ffffff;
  }

  .journal-mobile-menu__nav a.is-active::before {
    content: '';
    width: 3px;
    height: 22px;
    margin-right: 9px;
    background: #5b9cff;
  }

  .journal-mobile-menu__nav a.is-active > span:first-of-type {
    margin-right: auto;
  }

  .journal-mobile-menu__footer {
    margin-top: auto;
    padding-top: 20px;
    border-top: 1px solid rgba(153, 174, 204, .12);
    display: grid;
    gap: 7px;
    color: #697688;
    font-size: .72rem;
    line-height: 1.45;
  }

  .journal-mobile-menu__footer a {
    color: #98a5b6;
    text-decoration: none;
  }

  .journal-mobile-menu__backdrop {
    position: fixed;
    inset: 0;
    z-index: 1002;
    display: block;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: rgba(0,0,0,.64);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity .25s ease, visibility .25s ease;
  }

  .journal-mobile-header.is-menu-open .journal-mobile-menu__backdrop {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  /* Once the sidebar is gone, the content owns the full viewport width. */
  body.article-page .main-container,
  body.edge-journal-page .main-container,
  body.posts-index-page .main-container,
  body.tools-index-page .main-container,
  body.tool-page .main-container {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding-top: 0 !important;
    grid-template-columns: minmax(0,1fr) !important;
  }

  body.article-page main.main,
  body.edge-journal-page main.main,
  body.posts-index-page main.main,
  body.tools-index-page main.main,
  body.tool-page main.main {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
  }

  /* Article refinement */
  body.article-page main.main {
    padding: 14px 14px 52px !important;
  }

  body.article-page .main-article {
    width: 100% !important;
    margin: 0 !important;
  }

  body.article-page .article-header {
    margin: 0 !important;
    padding: 0 0 20px !important;
  }

  body.article-page .article-image,
  body.article-page .article-image img,
  body.article-page .article-header .article-image,
  body.article-page .article-header .article-image img,
  body.article-page .article-header > figure,
  body.article-page .article-header > figure img {
    width: 100% !important;
    max-width: 100% !important;
  }

  body.article-page .article-header > figure,
  body.article-page .article-image {
    margin: 0 0 18px !important;
  }

  body.article-page .article-header img {
    aspect-ratio: 16 / 9 !important;
    object-fit: cover !important;
  }

  body.article-page .article-category {
    margin: 0 0 14px !important;
  }

  body.article-page .article-category a {
    display: inline-flex !important;
    align-items: center !important;
    min-height: 28px !important;
    padding: 0 10px !important;
    font-size: .62rem !important;
    letter-spacing: .16em !important;
  }

  body.article-page .article-title {
    margin: 0 !important;
    max-width: 12ch !important;
    font-size: clamp(2.08rem, 9.8vw, 3rem) !important;
    line-height: .97 !important;
    letter-spacing: -.055em !important;
  }

  body.article-page .article-subtitle {
    margin-top: 16px !important;
    max-width: 100% !important;
    font-size: .96rem !important;
    line-height: 1.58 !important;
  }

  body.article-page .article-details,
  body.article-page .article-time {
    margin-top: 14px !important;
    font-size: .69rem !important;
    line-height: 1.45 !important;
  }

  body.article-page .article-content {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding-top: 18px !important;
    font-size: 1rem !important;
    line-height: 1.72 !important;
  }

  body.article-page .article-content > p:first-of-type {
    font-size: 1.08rem !important;
    line-height: 1.65 !important;
  }
}

/* Very narrow phones: simplify the brand but keep the header intentional. */
@media (max-width: 380px) {
  .journal-mobile-header__bar {
    padding-left: max(12px, var(--edge-safe-left, 0px));
    padding-right: max(12px, var(--edge-safe-right, 0px));
    gap: 10px;
  }

  .journal-mobile-header__brand {
    gap: 8px;
  }

  .journal-mobile-header__brand img {
    width: 62px;
    height: 36px;
  }

  .journal-mobile-header__identity strong,
  .journal-mobile-header__identity em {
    font-size: .64rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .journal-mobile-menu,
  .journal-mobile-menu__backdrop,
  .journal-mobile-header__toggle span {
    transition: none !important;
  }
}
