/* ==========================================================================
   Reading comfort on the long reads (round 7, look track)
   resources/views/look/partials/reading.blade.php, public/js/hp-reading.js

   A text size control (four steps) above the article and a thin brass line
   under the site header that fills as the article is read.

   The size scales the reading column with `zoom`: its text, line height and
   everything inside it together, so headings, notes and tables keep their
   proportions and a column sized in ch keeps its measure in characters. The
   rest of the page stays as it is. The steps are the ones of
   App\Services\Look\Inks::TEXT_SIZES.
   ========================================================================== */

/* ---------- The size, before the first paint ----------
   A signed-in writer's size is on the control from the server; :has() lets the
   column follow it before any script runs. Columns of the pages that include
   the control are listed; another page's column is marked by the script. */
body:has(.hp-read[data-size="smaller"]) :is(.hpg-prose, .hpx-sample, .hpx-study, .hpi-road-steps, .hcm-sheet, .hcm-stories, [data-hp-read-col]) { zoom: .9; }
body:has(.hp-read[data-size="larger"]) :is(.hpg-prose, .hpx-sample, .hpx-study, .hpi-road-steps, .hcm-sheet, .hcm-stories, [data-hp-read-col]) { zoom: 1.15; }
body:has(.hp-read[data-size="largest"]) :is(.hpg-prose, .hpx-sample, .hpx-study, .hpi-road-steps, .hcm-sheet, .hcm-stories, [data-hp-read-col]) { zoom: 1.3; }

/* ---------- The control ---------- */
body.hp-ui .hp-read {
    display: flex; align-items: center; justify-content: flex-end; gap: 10px;
    margin-block: clamp(22px, 3vw, 32px) 0;
}
body.hp-ui .hp-read.is-measure { font-size: 1.09rem; max-width: 68ch; margin-inline: auto; }
/* The measure grows with the column, so the control stays at the column's end. */
body.hp-ui .hp-read.is-measure[data-size="smaller"] { max-width: calc(68ch * .9); }
body.hp-ui .hp-read.is-measure[data-size="larger"] { max-width: calc(68ch * 1.15); }
body.hp-ui .hp-read.is-measure[data-size="largest"] { max-width: calc(68ch * 1.3); }
body.hp-ui .hp-read.is-wide { width: 100%; }
/* Without the script the buttons would do nothing: the row keeps its place, empty. */
body.hp-ui .hp-read:not(.is-ready) .hp-read-tools { visibility: hidden; }

body.hp-ui .hp-read-tools {
    display: inline-flex; align-items: center; gap: 2px;
    padding: 3px 10px 3px 4px; padding-inline: 12px 6px;
    border: 1px solid var(--hx-line-2); border-radius: 999px;
    background: var(--hx-surface);
    box-shadow: 0 6px 16px -14px rgba(20, 35, 28, .5);
    font: 600 .8rem/1 var(--hx-f-body);
}
body.hp-ui .hp-read-label {
    margin-inline-end: 6px; color: var(--hx-ink-3);
    font-size: .74rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; white-space: nowrap;
}
html[lang="ar"] body.hp-ui .hp-read-label { font-size: .8rem; letter-spacing: 0; text-transform: none; }

body.hp-ui .hp-read-btn {
    position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 1px;
    min-width: 38px; height: 34px; padding: 0 8px; margin: 0;
    border: 1px solid transparent; border-radius: 999px;
    background: transparent; color: var(--hx-ink);
    font-family: var(--hx-f-display); line-height: 1; cursor: pointer;
    transition: background-color .16s ease, border-color .16s ease, color .16s ease;
}
body.hp-ui .hp-read-btn:hover { background: var(--hx-surface-2); }
body.hp-ui .hp-read-btn:focus-visible { outline: 2px solid var(--hx-focus); outline-offset: 2px; }
body.hp-ui .hp-read-btn[aria-disabled="true"] { color: var(--hx-ink-3); cursor: default; opacity: .55; }
body.hp-ui .hp-read-btn[aria-disabled="true"]:hover { background: transparent; }
body.hp-ui .hp-read-btn[aria-pressed="true"] { border-color: var(--hx-quill); background: var(--hx-quill-soft); color: var(--hx-quill-ink); }
body.hp-ui .hp-read-a { font-size: 1.12rem; font-weight: 500; }
body.hp-ui .hp-read-a.is-small { font-size: .9rem; }
body.hp-ui .hp-read-a.is-large { font-size: 1.32rem; }
body.hp-ui .hp-read-a { display: block; line-height: .8; }
body.hp-ui .hp-read-sign { display: block; font-family: var(--hx-f-body); font-size: .86rem; font-weight: 700; line-height: 1; }
/* The letters A and the signs stay Latin and left to right in Arabic. */
body.hp-ui .hp-read-btn { direction: ltr; }

/* Four pips: where the size is among the four steps. */
body.hp-ui .hp-read-pips { display: inline-flex; gap: 3px; margin-inline-start: 6px; }
body.hp-ui .hp-read-pips i { width: 5px; height: 5px; border-radius: 50%; background: var(--hx-line-2); transition: background-color .16s ease; }
body.hp-ui .hp-read[data-size="smaller"] .hp-read-pips i:nth-child(-n+1),
body.hp-ui .hp-read[data-size="normal"] .hp-read-pips i:nth-child(-n+2),
body.hp-ui .hp-read[data-size="larger"] .hp-read-pips i:nth-child(-n+3),
body.hp-ui .hp-read[data-size="largest"] .hp-read-pips i { background: var(--hx-quill); }

body.hp-ui .hp-read-sr {
    position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
    clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- Where the control sits on each long read ---------- */
body.hp-ui.hp-guides .hp-read + .hpg-lang-note { margin-top: 18px; }
body.hp-ui.hp-guides .hp-read ~ .hpg-toc { margin-top: 22px; }
body.hp-ui.hp-guides .hp-read + .hpg-prose { margin-top: 26px; }
body.hp-ui.hp-legal .hpl-main > .hp-read { margin-top: 0; margin-bottom: 18px; }
body.hp-ui.hp-legal .hpl-main > .hp-read + .hpl-prose { margin-top: 0; }
body.hp-ui.hp-examples .hpx-page > .hp-read { margin-block: 28px -12px; }
/* Wide screens: on the row of the example's buttons, whose end is empty. */
@media (min-width: 1100px) {
    body.hp-ui.hp-examples .hpx-actions + .hp-read { margin-block: -43px 0; }
}
body.hp-ui.hpi-guide .hp-read { max-width: 1160px; margin-inline: auto; margin-block: 30px -8px; }
body.hp-ui.hp-community .hp-read.is-wide { max-width: 1120px; margin-inline: auto; }
body.hp-ui.hp-community .hp-read + .hcm-letter-page { margin-top: 22px; }
body.hp-ui.hp-community .hcm-section-head + .hp-read { margin-block: -6px 18px; }

/* ---------- Reading progress ----------
   Fixed under the floating header (the script places it below the header's
   bar and follows its width); only transform changes while scrolling. */
body.hp-ui .hp-read-progress {
    position: fixed; top: 0; left: 0; z-index: 59;
    width: 100%; height: 2px; border-radius: 2px; overflow: hidden;
    background: color-mix(in srgb, var(--hx-quill) 18%, transparent);
    pointer-events: none;
    transform: translate3d(0, -10px, 0);
}
body.hp-ui .hp-read-progress[hidden] { display: none; }
body.hp-ui .hp-read-fill {
    display: block; width: 100%; height: 100%;
    background: linear-gradient(90deg, color-mix(in srgb, var(--hx-quill) 70%, var(--hx-cream)), var(--hx-quill));
    transform: scaleX(0); transform-origin: 0 50%;
    will-change: transform;
}
[dir="rtl"] body.hp-ui .hp-read-fill { transform-origin: 100% 50%; background: linear-gradient(270deg, color-mix(in srgb, var(--hx-quill) 70%, var(--hx-cream)), var(--hx-quill)); }
html[data-hp-theme="dark"] body.hp-ui .hp-read-fill { background: var(--hx-quill); }

@media (max-width: 560px) {
    body.hp-ui .hp-read-label { display: none; }
    body.hp-ui .hp-read-tools { padding-inline: 4px 8px; }
}
@media (prefers-reduced-motion: reduce) {
    body.hp-ui :is(.hp-read-btn, .hp-read-pips i) { transition: none; }
}
@media print {
    html body.hp-ui :is(.hp-read, .hp-read-progress) { display: none; }
    html body:has(.hp-read) :is(.hpg-prose, .hpx-sample, .hpx-study, .hpi-road-steps, .hcm-sheet, .hcm-stories, [data-hp-read-col]) { zoom: 1; }
}
