/* SIMORGH mobile — button-controlled paper sections.
   Load AFTER the desktop/main SIMORGH CSS.

   The existing JavaScript controls the state by adding/removing .is-open.
   Hover and focus no longer open a paper on mobile.
*/
@media (hover: none), (pointer: coarse), (max-width: 720px) {
  body.template-homepage {
    margin: 0;
  }

  #main-content {
    --mobile-half: clamp(9rem, 39vw, 12rem);
    --mobile-gutter: clamp(1.25rem, 5vw, 2.5rem);

    height: auto;
    min-height: 0;
    overflow: clip;
    perspective: none;
  }


  /* ================================================================
     HERO
     ================================================================ */

  #hero.home-section--hero {
    position: relative;
    inset: auto;

    transform: none;

    width: min(100%, 42rem);
    max-width: none;
    max-height: none;

    margin: 0 auto;
    padding: 2rem var(--mobile-gutter) 1.5rem;
  }

  #hero > .home-section__content {
    height: auto;
    padding: 0;
  }

  #hero h2 {
    font-size: clamp(1.1rem, 4.5vw, 1.5rem);
    line-height: 1.5;
  }

  #hero p {
    line-height: 1.6;
  }

  #hero .swarm-playground,
  #hero .swarm-playground__canvas {
    max-height: none;
  }

  #hero .swarm-playground__stage {
    height: auto;
    min-height: 0;
    gap: .75rem;
  }

  #hero .swarm-playground__canvas {
    width: 100%;
    height: auto;
  }

  #hero .swarm-playground__controls {
    gap: .65rem;
    align-items: center;
  }

  #hero .swarm-playground__controls button {
    min-height: 44px;
    padding: .75rem 1rem;
    font-size: 1rem;
    touch-action: manipulation;
  }

  #hero .swarm-playground__status,
  #hero .swarm-playground__timer {
    flex: 1 1 100%;
    text-align: center;
    line-height: 1.5;
  }


  /* ================================================================
     MOBILE PAPERS
     ================================================================ */

  /*
   * Keep the same diagonal mobile geometry in both states.
   * Opening is now controlled only by the .is-open class.
   */
  #main-content > .home-section:not(.home-section--hero) {
    position: relative;
    inset: auto;

    width: 100%;
    height: auto;
    min-height: calc(2 * var(--mobile-half));

    margin: calc(-1 * var(--mobile-half)) 0 0;
    padding: 0;

    border: 0;
    border-radius: 0;

    transform: none;
    box-shadow: none;
    transition: none;
    will-change: auto;

    z-index: 2;
    overflow: hidden;
    cursor: auto;
  }

  #main-content > #intro {
    margin-top: 0;
  }

  #main-content > :is(#intro, #log) {
    clip-path: polygon(
      0 0,
      100% var(--mobile-half),
      100% calc(100% - var(--mobile-half)),
      0 100%
    );

    --mobile-angle: 16deg;
  }

  #main-content > :is(#swarm, #me) {
    clip-path: polygon(
      100% 0,
      100% 100%,
      0 calc(100% - var(--mobile-half)),
      0 var(--mobile-half)
    );

    --mobile-angle: -16deg;
  }


  /* ================================================================
     OPEN / CLOSE BUTTONS
     ================================================================ */

  /*
   * OPEN is a little translucent tab sitting in the free part of the
   * diagonal strip. It rotates with the visual angle of that strip.
   */
  #main-content > .home-section:not(.home-section--hero)
  > .btn-open-home-section-content,
  #main-content > .home-section:not(.home-section--hero)
  > .btn-close-home-section-content {
    position: absolute;
    z-index: 20;

    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .45em;

    min-height: 44px;
    box-sizing: border-box;

    border: 1px solid rgb(0 0 0 / .18);
    border-radius: 999px;

    font: inherit;
    font-size: .78rem;
    font-weight: 700;
    letter-spacing: .08em;
    line-height: 1;
    text-transform: uppercase;
    text-decoration: none;

    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  #main-content > .home-section:not(.home-section--hero)
  > .btn-open-home-section-content {
    top: 50%;
    right: 4%;

    padding: .72rem .95rem;

    color: #182c61;
    background: #fff5dc;
    box-shadow:
      0 5px 18px rgb(0 0 0 / .10),
      inset 0 1px 0 rgb(255 255 255 / .55);

    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);

    transform:
      translateY(-50%)
      rotate(var(--mobile-angle));

    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  /*
   * For right-leaning papers the heading occupies the right-hand side,
   * so put the OPEN tab on the left.
   */
  #main-content > :is(#swarm, #me)
  > .btn-open-home-section-content {
    left: 4%;
    right: auto;
  }

  #main-content > .home-section:not(.home-section--hero)
  > .btn-open-home-section-content::after {
    content: "↗";
    display: inline-block;
    font-size: 1.05em;
    transition: transform 160ms ease;
  }

  #main-content > .home-section:not(.home-section--hero)
  > .btn-open-home-section-content:active::after {
    transform: translate(.12rem, -.12rem);
  }

  /*
   * CLOSE is hidden while the paper is parked.
   * It appears only after .is-open is added by the existing JS.
   */
  #main-content > .home-section:not(.home-section--hero)
  > .btn-close-home-section-content {
    top: calc(var(--mobile-half) + .65rem);
    right: var(--mobile-gutter);

    padding: .72rem 1rem;

    color: white;
    background: #182c61;
    box-shadow: 0 6px 20px rgb(0 0 0 / .16);

    opacity: 0;
    visibility: hidden;
    pointer-events: none;
  }

  #main-content > .home-section:not(.home-section--hero)
  > .btn-close-home-section-content::before {
    content: "×";
    font-size: 1.25em;
    font-weight: 400;
    line-height: .7;
  }

  #main-content > .home-section:not(.home-section--hero).is-open
  > .btn-open-home-section-content {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
  }

  #main-content > .home-section:not(.home-section--hero).is-open
  > .btn-close-home-section-content {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  #main-content > .home-section:not(.home-section--hero)
  > :is(.btn-open-home-section-content, .btn-close-home-section-content):focus-visible {
    outline: 3px solid currentColor;
    outline-offset: 3px;
  }


  /* ================================================================
     PAPER CONTENT — OPEN STATE
     ================================================================ */

  #main-content > .home-section:not(.home-section--hero)
  .home-section-content {
    position: relative;
    inset: auto;

    width: min(100%, 46rem);
    height: auto;

    margin: 0 auto;
    padding:
      calc(var(--mobile-half) + 1.5rem)
      var(--mobile-gutter);

    overflow: visible;

    font-size: 1rem;
    line-height: 1.7;
    overflow-wrap: anywhere;
  }

  #main-content > .home-section:not(.home-section--hero)
  .block-heading_block {
    position: relative;
    inset: auto;

    width: auto;
    margin: 0 0 1.25rem;

    text-align: left;

    transform: none;
    transition: none;
    will-change: auto;
  }

  #main-content > .home-section:not(.home-section--hero) h2 {
    font-size: clamp(1rem, 3.7vw, 1.35rem);
    line-height: 1.55;
  }

  #main-content > .home-section:not(.home-section--hero)
  .home-section-content > :not(.block-heading_block) {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;

    transform: none;
    transition: none;
  }

  #main-content .home-section-content p:empty {
    display: none;
  }

  #main-content .home-section-content figure {
    margin: 1.5rem 0;
  }

  #main-content .home-section-content a {
    text-underline-offset: .2em;
  }


  /* ================================================================
     RESTING / CLOSED STATE
     ================================================================ */

  /*
   * Closed papers collapse visually back into the diagonal strip.
   * No :hover or :focus-within selectors are used anymore.
   */
  #main-content > .home-section:not(.home-section--hero):not(.is-open)
  .home-section-content {
    width: 100%;
    height: calc(2 * var(--mobile-half));
    padding: 0;
  }

  #main-content > .home-section:not(.home-section--hero):not(.is-open)
  .block-heading_block {
    position: absolute;

    top: 50%;
    left: 4%;
    right: auto;
    bottom: auto;

    width: 62%;
    margin: 0;
    padding: .5rem;
    box-sizing: border-box;

    transform:
      translateY(-50%)
      rotate(var(--mobile-angle));

    text-align: center;
  }

  #main-content > :is(#swarm, #me):not(.is-open)
  .block-heading_block {
    left: auto;
    right: 4%;
  }

  #main-content > .home-section:not(.home-section--hero):not(.is-open)
  h2 {
    font-size: clamp(.85rem, 3.3vw, 1.1rem);
    line-height: 1.5;
  }

  /*
   * Hide the body while closed without display:none, preserving the
   * document structure and preventing it from affecting the strip height.
   */
  #main-content > .home-section:not(.home-section--hero):not(.is-open)
  .home-section-content > :not(.block-heading_block) {
    position: absolute;

    width: 1px;
    height: 1px;

    padding: 0;
    margin: -1px;

    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;

    opacity: 0;
    pointer-events: none;
  }

  #main-content > .home-section:not(.home-section--hero).is-open
  .home-section-content > :not(.block-heading_block) {
    position: static;

    width: auto;
    height: auto;

    clip-path: none;
    white-space: normal;
  }


  /* Hoopoe effect only needs to run visibly while its paper is open. */
  #main-content > #swarm:not(.is-open)
  > #home-section-effect-canvas-hoopoe {
    visibility: hidden;
  }


  /* ================================================================
     FOOTER
     ================================================================ */

  body.template-homepage > footer {
    padding: 1.5rem var(--mobile-gutter, 1.25rem);
    text-align: center;
    line-height: 1.6;
    overflow-wrap: anywhere;
  }
}


/* Accessibility: remove button micro-animation when requested. */
@media (prefers-reduced-motion: reduce) {
  .btn-open-home-section-content::after {
    transition: none;
  }
}

/* BLOG ENTRY — appended only; original mobile home CSS remains above.
   Load this complete file after simorgh_com.css on blog pages too. */
@media (max-width: 720px) {
  body.template-blogpage { font-size: 1rem; line-height: 1.75; }
  body.template-blogpage > header {
    width: calc(100% - 2rem);
    gap: .85rem;
    padding: 1.5rem 0 .75rem;
  }
  body.template-blogpage > header img { width: 2.75rem; height: 2.75rem; }
  body.template-blogpage > header h1 {
    min-width: 0;
    font-size: clamp(.85rem, 3.3vw, 1.1rem);
  }
  body.template-blogpage > aside {
    width: calc(100% - 2rem);
    margin-bottom: 1.5rem;
  }
  body.template-blogpage > aside nav p { gap: .5rem; padding-bottom: .75rem; }
  body.template-blogpage > aside a { padding-inline: .85rem; }
  body.template-blogpage > #main {
    width: calc(100% - 1.5rem);
    margin-bottom: 2rem;
    padding: 2rem clamp(1rem, 5vw, 2rem);
    box-shadow: 0 8px 24px #182c610c;
  }
  body.template-blogpage > #main::after { width: 1.5rem; height: 1.5rem; }
  body.template-blogpage #main > h1 {
    font-size: clamp(1.4rem, 6vw, 2rem);
    line-height: 1.45;
  }
  body.template-blogpage #main .meta { margin-bottom: 1.5rem; font-size: .8rem; }
  body.template-blogpage #main .intro {
    padding: 1rem;
    margin-bottom: 2rem;
    font-size: 1.05rem;
  }
  body.template-blogpage #main h2 { font-size: 1.1rem; }
  body.template-blogpage #main h3 { font-size: 1.075rem; }
  body.template-blogpage #main :is(blockquote, pre) { padding: 1rem; }
  body.template-blogpage #main img:is(.left, .right) {
    float: none;
    display: block;
    max-width: 100%;
    margin: 1.5rem auto;
  }
  body.template-blogpage #main :is(th, td) { padding: .6rem .75rem; }
  body.template-blogpage > footer {
    width: calc(100% - 2rem);
    padding-bottom: 2rem;
  }
}


/* Same tilework at a finer scale on the existing mobile paper layout. */
@media (hover: none), (pointer: coarse), (max-width: 720px) {
  body.template-blogpage { background-size: 112px 112px; }
  #main-content > #intro { --section-pattern-size: 132px; }
  #main-content > #swarm { --section-pattern-size: 120px; }
  #main-content > #log { --section-pattern-size: 138px; }
  #main-content > #me { --section-pattern-size: 144px; }
  #hero.home-section--hero { box-shadow: inset 0 -3px 0 var(--tile-gold); }
  #main-content > .home-section:not(.home-section--hero) > :is(.btn-open-home-section-content, .btn-close-home-section-content) {
    color: var(--tile-ivory);
    background: var(--tile-lapis);
    border-color: var(--tile-gold);
    border-radius: .15rem;
    box-shadow: 0 0 0 2px var(--tile-lapis), 0 0 0 3px var(--tile-gold);
  }
}
@media (max-width: 720px) {
  body.template-blogpage > #main {
    box-shadow: 0 0 0 3px var(--tile-turquoise), 0 0 0 5px var(--tile-lapis), 0 0 0 6px var(--tile-gold);
  }
}

/* CSS-ONLY CORRECTION: the original alternating diagonal strips remain.
   Uses the original controller's .is-open; no markup or JS changes. */
@media (hover: none), (pointer: coarse), (max-width: 720px) {
  body.template-homepage #main-content {
    --mobile-half: clamp(7rem, 32vw, 10rem);
    --mobile-gutter: clamp(1.25rem, 5vw, 2rem);
  }
  body.template-homepage #hero.home-section--hero { width: min(100%, 42rem); box-shadow: none; padding: 2rem var(--mobile-gutter); }
  body.template-homepage #hero h2 { font-size: 1.15rem; }
  body.template-homepage #hero .swarm-playground__controls button { min-height: 44px; font-size: .9375rem; }
  body.template-homepage #main-content > .home-section:not(.home-section--hero) {
    /* A little more usable thickness inside each original diagonal band. */
    min-height: calc(2 * var(--mobile-half) + 4rem);
    box-shadow: inset 3px 0 #183c83;
  }
  body.template-homepage #main-content > .home-section:not(.home-section--hero):not(.is-open) .home-section-content { height: calc(2 * var(--mobile-half) + 4rem); }
  body.template-homepage #main-content > .home-section:not(.home-section--hero):not(.is-open) .block-heading_block:first-child {
    inset: auto;
    top: 50%;
    left: 4%;
    width: 62%;
    padding: .4rem;
    transform: translateY(-50%) rotate(var(--mobile-angle));
  }
  body.template-homepage #main-content > .home-section:not(.home-section--hero):is(#swarm,#me):not(.is-open) .block-heading_block:first-child { left: auto; right: 4%; }
  body.template-homepage #main-content > .home-section:not(.home-section--hero):not(.is-open) h2 { font-size: clamp(.875rem, 3.3vw, 1.1rem); line-height: 1.55; }
  body.template-homepage #main-content > .home-section:not(.home-section--hero) > .btn-open-home-section-content {
    inset: auto;
    top: 50%;
    right: 4%;
    transform: translateY(-50%) rotate(var(--mobile-angle));
  }
  body.template-homepage #main-content > .home-section:not(.home-section--hero):is(#swarm,#me) > .btn-open-home-section-content { right: auto; left: 4%; }
  body.template-homepage #main-content > .home-section:not(.home-section--hero).is-open {
    /* Retain the clipped diagonal ends, but keep all reading below the cut. */
    background: #f8f7ee;
    box-shadow: inset 3px 0 #183c83;
    overflow: clip;
    display: flow-root;
  }
  body.template-homepage #main-content > .home-section:not(.home-section--hero).is-open > .btn-close-home-section-content {
    inset: auto;
    position: sticky;
    float: right;
    top: 1rem;
    margin: calc(var(--mobile-half) + .75rem) var(--mobile-gutter) 0 0;
    transform: none;
    background: #183c83;
    color: #fff;
  }
  body.template-homepage #main-content > .home-section:not(.home-section--hero).is-open .home-section-content {
    width: min(100%, 46rem);
    padding: calc(var(--mobile-half) + 5rem) var(--mobile-gutter) calc(var(--mobile-half) + 2rem);
    margin: auto;
    background: transparent;
    box-shadow: none;
  }
  body.template-homepage #main-content > .home-section:not(.home-section--hero).is-open .block-heading_block {
    position: static;
    inset: auto;
    width: auto;
    margin: 0 0 1.25rem;
    transform: none;
    text-align: left;
  }
  body.template-homepage #main-content > .home-section:not(.home-section--hero).is-open h2 { font-size: 1.2rem; line-height: 1.55; }
  body.template-homepage #main-content > .home-section:not(.home-section--hero).is-open .home-section-content > :not(:first-child) {
    position: static;
    width: auto;
    height: auto;
    margin: 0;
    clip-path: none;
    white-space: normal;
    transform: none;
  }
}
