/*
 * Single article polish (loaded only on posts, body.ap-on).
 * Calmer reading layout: readable line length, a toolbar that no longer follows the page,
 * a sidebar that always fits the screen, a lighter hero on phones and a sharper cover on desktop.
 */

/* ---------- hero ---------- */
body.ap-on .ap-hero > .relative.z-10.max-w-7xl { padding-bottom: 2.75rem; }
body.ap-on .article-favorite-action { margin-top: 1.1rem; }

@media (min-width: 1024px) {
  body.ap-on .ap-hero > .relative.z-10.max-w-7xl { padding-top: 2rem; padding-bottom: 3rem; }
  body.ap-on .ap-hero .grid { align-items: center; gap: 3.5rem; }
  body.ap-on .ap-hero h1.article-hero-title { font-size: clamp(1.6rem, 2.1vw, 2.05rem); line-height: 1.7; }
  body.ap-on .ap-hero .lg\:col-span-7,
  body.ap-on .ap-hero .lg\:col-span-5 { grid-column: span 6 / span 6; }
  body.ap-on .ap-hero .article-hero-media {
    max-width: 600px;
    margin-inline-start: auto;
    border-radius: 1.5rem;
    background: #fff;
    box-shadow: 0 40px 80px -36px rgba(0, 0, 0, .7), 0 0 0 1px rgba(255, 255, 255, .14);
  }
  body.ap-on .ap-hero .article-hero-media::before { display: none; }
  body.ap-on .ap-hero .article-hero-media img { object-fit: cover; }
}

@media (max-width: 767px) {
  /* the breadcrumb already names the category */
  body.ap-on .ap-hero .lg\:col-span-7 > .inline-flex:first-child { display: none; }
  body.ap-on .ap-hero nav[aria-label] { margin-bottom: .9rem; }
  body.ap-on .ap-hero > .relative.z-10.max-w-7xl { padding-top: 1.25rem; padding-bottom: 1.5rem; }
  body.ap-on .ap-hero h1.article-hero-title { margin-bottom: .75rem; }
  body.ap-on .ap-hero .grid { gap: 1.1rem; }
  body.ap-on .ap-hero .text-sm.text-white\/80 { gap: .35rem 1rem; font-size: .8rem; }
  body.ap-on .article-favorite-action { margin-top: .75rem; }
  body.ap-on .ap-hero .article-hero-media { border-radius: 1.1rem; }
}

/* ---------- reading toolbar: small, in place, not following the page ---------- */
body.ap-on .reader-section { padding-top: 1.5rem; padding-bottom: 1.5rem; }
body.ap-on .reader-tools {
  position: static;
  justify-content: flex-start;
  width: fit-content;
  max-width: 100%;
  margin-bottom: 1.25rem;
  padding: .35rem;
  border-radius: 1rem;
  background: #fff;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  box-shadow: 0 10px 30px -24px rgba(4, 34, 59, .35);
}
body.ap-on .reader-tools > div:first-child { display: none; }
body.ap-on .reader-tools > div:last-child { gap: .3rem; width: auto; }
body.ap-on .reader-tool-btn { height: 2.25rem; min-width: 2.25rem; padding-inline: .6rem; border-color: transparent; background: transparent; flex: none; }
body.ap-on .reader-tool-btn:hover { background: var(--tint); }
body.ap-on .reader-tool-btn.is-wide { min-width: 0; }
body.ap-on.reading-focus .reader-tools { position: sticky; top: 0; }

@media (max-width: 767px) {
  body.ap-on .reader-tools { width: 100%; padding: .3rem; flex-direction: row; }
  body.ap-on .reader-tools > div:last-child { width: 100%; justify-content: space-between; }
  body.ap-on .reader-print-btn { display: none; }
  body.ap-on .reader-tool-btn { min-height: 44px; min-width: 44px; flex: 1; }
  body.ap-on .reader-tool-btn.is-wide { flex: 1.4; }
}

/* ---------- reading column: comfortable line length on desktop ---------- */
@media (min-width: 1024px) {
  body.ap-on .article-content[data-font-step="0"] { font-size: 1.0625rem; }
  body.ap-on .article-content[data-font-step="-1"] { font-size: 1rem; }
  body.ap-on .article-content[data-font-step="1"] { font-size: 1.125rem; }
  body.ap-on .article-content[data-font-step="2"] { font-size: 1.1875rem; }
}
body.ap-on .article-content h2 { scroll-margin-top: 6rem; }
body.ap-on .article-content :is(h3, h4, [id]) { scroll-margin-top: 6rem; }
@media (max-width: 767px) {
  body.ap-on .article-content :is(h2, h3, h4, [id]) { scroll-margin-top: 5.25rem; }
}

/* ---------- sidebar: always fits the screen; the contents list scrolls inside ---------- */
@media (min-width: 1024px) {
  body.ap-on .article-aside {
    top: 5.5rem;
    max-height: calc(100vh - 6.5rem);
    max-height: calc(100dvh - 6.5rem);
    gap: .75rem;
  }
  body.ap-on .article-aside > .article-aside-card { flex: none; }
  body.ap-on .article-aside > .article-aside-card:first-child {
    flex: 0 1 auto;
    min-height: 9rem;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding-bottom: .75rem;
  }
  body.ap-on .article-aside > .article-aside-card:first-child > h2 { flex: none; margin-bottom: .6rem; }
  body.ap-on #readerToc {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    margin-inline: -.35rem;
    padding-inline: .35rem;
  }
  body.ap-on #readerToc a { flex: none; min-height: 2rem; padding-block: .35rem; font-size: .82rem; line-height: 1.7; }
  body.ap-on .article-aside .promo-side { padding: 1rem; }
  body.ap-on .article-aside .promo-side > img,
  body.ap-on .article-aside .promo-side > p { display: none; }
  body.ap-on .article-aside .promo-side > h3 { margin-top: .25rem; font-size: 1rem; line-height: 1.8; }
  body.ap-on .article-aside .promo-side > .inline-flex:first-child { margin-bottom: .5rem; }
  body.ap-on .article-aside .promo-side .btn { padding-block: .6rem; }
}

/* ---------- tables: two-column tables fit the phone, no sideways scroll ---------- */
body.ap-on .rich-content table:not(:has(tr > :nth-child(3))) { min-width: 0; }
body.ap-on .mobile-table-hint.ap-fit { display: none; }

/* ---------- after the article ---------- */
body.ap-on .article-editorial-note-wrap {
  padding-block: 0 2.5rem;
  background: var(--surface, #f5f9fd);
  box-shadow: 0 0 0 100vmax var(--surface, #f5f9fd);
  clip-path: inset(0 -100vmax);
}
body.ap-on .related-section .sec-num { display: none; }

/* support button: icon only on articles so it never sits on the text */
@media (min-width: 1024px) {
  body.ap-on .mts-widget .mts-launcher { width: 54px; height: 54px; padding: 0; gap: 0; justify-content: center; border-radius: 999px; }
  body.ap-on .mts-widget .mts-launcher > span { display: none; }
}

/* ---------- floating contents button + sheet (phones and tablets) ---------- */
.ap-toc-fab, .ap-toc-sheet, .ap-toc-backdrop { display: none; }
.ap-toc-sheet[hidden] { display: none !important; }
@media (max-width: 1023px) {
  .ap-toc-fab {
    position: fixed;
    left: 14px;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 78px);
    z-index: 60;
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    height: 44px;
    padding: 0 .95rem 0 .8rem;
    border: 1px solid rgba(1, 103, 173, .18);
    border-radius: 999px;
    background: rgba(255, 255, 255, .96);
    color: var(--brand, #0167ad);
    font: inherit;
    font-size: .8rem;
    font-weight: 800;
    box-shadow: 0 12px 30px -14px rgba(4, 34, 59, .45);
    opacity: 0;
    transform: translateY(12px);
    pointer-events: none;
    transition: opacity .25s ease, transform .25s ease;
  }
  .ap-toc-fab.is-shown { opacity: 1; transform: none; pointer-events: auto; }
  .ap-toc-fab svg { width: 18px; height: 18px; }
  .ap-toc-backdrop {
    position: fixed; inset: 0; z-index: 95; display: block;
    background: rgba(4, 20, 36, .42);
    opacity: 0; pointer-events: none; transition: opacity .25s ease;
  }
  .ap-toc-sheet {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 96; display: flex; flex-direction: column;
    max-height: 72vh; max-height: 72dvh;
    padding: .5rem 1rem calc(env(safe-area-inset-bottom, 0px) + 1rem);
    border-radius: 1.25rem 1.25rem 0 0;
    background: #fff;
    box-shadow: 0 -20px 50px -20px rgba(4, 34, 59, .4);
    transform: translateY(105%);
    transition: transform .3s cubic-bezier(.2, .8, .2, 1);
  }
  .ap-toc-open .ap-toc-backdrop { opacity: 1; pointer-events: auto; }
  .ap-toc-open .ap-toc-sheet { transform: none; }
  .ap-toc-sheet-head { display: flex; align-items: center; justify-content: space-between; padding: .6rem .25rem .75rem; border-bottom: 1px solid var(--line, #e5e7eb); }
  .ap-toc-sheet-head::before { content: ""; position: absolute; top: .45rem; left: 50%; width: 40px; height: 4px; margin-left: -20px; border-radius: 4px; background: #d6dde6; }
  .ap-toc-sheet-head strong { font-size: .95rem; }
  .ap-toc-close { width: 44px; height: 44px; border: 0; border-radius: 999px; background: transparent; color: var(--muted, #64748b); font-size: 1.5rem; line-height: 1; }
  .ap-toc-list { overflow-y: auto; overscroll-behavior: contain; padding-top: .35rem; }
  .ap-toc-list a { display: flex; align-items: center; min-height: 44px; padding: .45rem .75rem; border-radius: .75rem; border-right: 3px solid transparent; color: var(--ink, #0c1b2b); font-size: .88rem; line-height: 1.8; }
  .ap-toc-list a.is-active { background: var(--tint, #eaf4fb); color: var(--brand, #0167ad); border-right-color: var(--brand, #0167ad); font-weight: 700; }
  body.reading-focus .ap-toc-fab { display: none; }
  body:has(#drawer.open) .ap-toc-fab { visibility: hidden; }
}
@media (prefers-reduced-motion: reduce) {
  .ap-toc-fab, .ap-toc-sheet, .ap-toc-backdrop { transition: none; }
}
