/* Tuotu Astro-projektista: src/styles/mobile/toc.css (bin/sync-astro.py). */
/* Mobile round (Tapio, 2026-09-25): The table of contents on phones: collapsed, floating at the bottom of the screen.
   Loaded after wp.css (src/layouts/Site.astro). Phone and tablet rules only: desktop stays as it is.
   Toc.astro renders the list twice: in the page (.wp-toc > .wrap, desktop and tablets, wp.css) and in
   .wp-toc-dock, a <details> that is a bar fixed to the bottom of phone screens and opens the list upwards
   ("minimized by default and floating in the bottom of the screen on mobile"). The dock sits inside the
   section, so wp.css's .wp-toc rules (list, numbers, chevron) reach it too; the rules here only change
   what differs, with selectors that outrank wp.css's. */

/* The dock (Toc.astro .wp-toc-dock) exists only on phones. */
.wp-toc-dock {
  display: none;
}

@media (max-width: 767px) {
  /* The in-page list leaves the page on phones; the section stays as the 1 px rule
     between the post's header and its first band... */
  .wp-toc > .wrap {
    display: none;
  }

  .landing-section.landing-section--rails.wp-toc {
    border-bottom: 0;
  }

  /* 26.11.2026: the band kept the 48 px paddings of spacing-system.css (important declarations in the layer
     mobile-spacing-system) and left a 97 px empty strip under the header. Same layer, more specific. */
  @layer mobile-spacing-system {
    html body main .landing-section.landing-section--rails.wp-toc {
      padding-block: 0 !important;
    }
  }

  /* ...unless that band draws its own accent line (wp.css, "A text section's accent line"). */
  .landing-section.landing-section--rails.wp-toc:has(+ .landing-section--rails:not(.is-untitled)) {
    border-top: 0;
  }

  /* The bar, fixed to the bottom of the screen, with the list opening upwards from it. */
  .wp-toc .wp-toc-dock {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 40; /* under the header (50) and the cookie banner */
    display: block;
    transition:
      transform 0.25s ease,
      visibility 0.25s;
  }

  /* Out of the way over the footer (Toc.astro's script). */
  .wp-toc .wp-toc-dock.is-away:not([open]) {
    visibility: hidden;
    transform: translateY(100%);
  }

  .wp-toc .wp-toc-dock > summary.wp-toc-dock-bar {
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    gap: 1rem;
    min-height: 3.5rem;
    padding: 0.5rem 1rem calc(0.5rem + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    background: var(--gh-header, #000);
    color: var(--gh-text);
    font-size: 1rem;
    font-weight: 400;
    letter-spacing: 0;
    -webkit-tap-highlight-color: transparent;
  }

  /* While the list is open, a drag on the bar doesn't scroll the page behind it. */
  .wp-toc .wp-toc-dock[open] > summary.wp-toc-dock-bar {
    touch-action: none;
  }

  /* wp.css's chevron: up while folded (the list opens upwards), down while open. */
  .wp-toc .wp-toc-dock:not([open]) > summary.wp-toc-dock-bar::after {
    margin-top: 0.3rem;
    transform: rotate(-135deg);
  }

  .wp-toc .wp-toc-dock[open] > summary.wp-toc-dock-bar::after {
    margin-top: -0.3rem;
    transform: rotate(45deg);
  }

  .wp-toc-dock-text {
    display: grid;
    flex: 1;
    min-width: 0;
    gap: 0.125rem;
  }

  .wp-toc-dock-title {
    color: var(--gh-subtle);
    font-family: 'Mona Sans', var(--font);
    font-size: 0.8125rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    line-height: 1.2;
  }

  .wp-toc-dock-current {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    min-width: 0;
    color: #fff;
    font-size: 0.9375rem;
    font-weight: 600;
    line-height: 1.3;
  }

  .wp-toc-dock-num {
    flex-shrink: 0;
    color: var(--gh-subtle);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.75rem;
    font-weight: 400;
  }

  .wp-toc-dock-num:empty {
    display: none;
  }

  .wp-toc-dock-label {
    overflow: hidden;
    min-width: 0;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* The page dims behind the open list; a tap on it closes the list. */
  .wp-toc-dock-scrim {
    position: fixed;
    inset: 0;
    z-index: 0;
    background: rgb(0 0 0 / 0.6);
    touch-action: none;
  }

  .wp-toc-dock-sheet {
    position: absolute;
    right: 0;
    bottom: 100%;
    left: 0;
    z-index: 1;
    max-height: min(70vh, calc(100vh - var(--topbar, 148px) - 4.5rem));
    max-height: min(70dvh, calc(100dvh - var(--topbar, 148px) - 4.5rem));
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 0.75rem 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    background: var(--gh-header, #000);
  }

  /* The list as wp.css draws the in-page one on phones, in one column. */
  .wp-toc .wp-toc-dock .wp-toc-list {
    columns: 1;
    padding: 0;
  }

  .wp-toc .wp-toc-dock a {
    grid-template-columns: 2.1rem minmax(0, 1fr);
    min-height: 2.75rem;
    font-size: 1rem;
  }

  .wp-toc .wp-toc-dock .wp-toc-chapter ol {
    padding-left: 2.1rem;
  }

  .wp-toc .wp-toc-dock .wp-toc-chapter ol a {
    grid-template-columns: minmax(0, 1fr);
    min-height: 2.5rem;
  }

  .wp-toc.is-numbered .wp-toc-dock .wp-toc-chapter > a {
    grid-template-columns: minmax(0, 1fr);
  }

  .wp-toc.is-numbered .wp-toc-dock .wp-toc-chapter ol {
    padding-left: 1.25rem;
  }

  /* Where the reader is (Toc.astro's script). */
  .wp-toc .wp-toc-dock a[aria-current] {
    background: color-mix(in srgb, var(--gh-text) 8%, transparent);
    color: #fff;
  }

  .wp-toc .wp-toc-dock a[aria-current]::before {
    color: var(--gh-accent);
  }
}

/* Without JavaScript the bar never moves away: the footer's last line stays clear of it. */
@media (max-width: 767px) and (scripting: none) {
  body:has(.wp-toc-dock) .site-footer {
    padding-bottom: calc(3.5rem + env(safe-area-inset-bottom, 0px));
  }
}

@media (max-width: 767px) and (prefers-reduced-motion: reduce) {
  .wp-toc .wp-toc-dock,
  .wp-toc .wp-toc-dock > summary.wp-toc-dock-bar::after {
    transition: none;
  }
}

@media print {
  .wp-toc-dock {
    display: none !important;
  }
}
