/*
 * HumanProse before/after compare (hp-compare.js).
 *
 * The stage is one grid of rows; each row holds the draft cell and the
 * rewrite cell in the same grid area, so a row is as tall as its longer
 * side. The draft lies on ruled paper; the rewrite is ivory and clipped at
 * the divider. The divider and its brass grip move with a transform only.
 * No important flags, logical properties for the page chrome, physical
 * left/right only where the clip and the divider need the screen.
 */

body.hp-ui .hp-cmp-stage {
    --hp-cmp-x: 50%;
    --hp-cmp-nudge: 0px;
    --hp-cmp-draft: color-mix(in srgb, var(--hx-paper-2) 62%, var(--hx-surface));
    --hp-cmp-final: var(--hx-surface);
    --hp-cmp-ruling: color-mix(in srgb, var(--hx-royal) 7%, transparent);
    --hp-cmp-lh: 1.85;
    --hp-cmp-pad: clamp(18px, 3.4vw, 40px);
    --hp-cmp-final-size: 1.32rem;
    position: relative;
    isolation: isolate;
    overflow: clip;
    border: 1px solid var(--hx-line);
    border-radius: 20px;
    background: var(--hp-cmp-draft);
    color: var(--hx-ink);
    touch-action: pan-y;
    -webkit-user-select: none;
    user-select: none;
    cursor: col-resize;
    -webkit-tap-highlight-color: transparent;
}
body.hp-ui .hp-cmp-stage.is-workspace { --hp-cmp-final-size: 1.42rem; border-radius: 18px; }
body.hp-ui .hp-cmp-stage.is-empty { cursor: default; }
html[data-hp-theme="dark"] body.hp-ui .hp-cmp-stage {
    --hp-cmp-draft: var(--hx-paper);
    --hp-cmp-final: color-mix(in srgb, var(--hx-surface-2) 75%, var(--hx-surface));
    --hp-cmp-ruling: color-mix(in srgb, var(--hx-quill) 8%, transparent);
}

body.hp-ui .hp-cmp-sheet { display: grid; grid-template-columns: minmax(0, 1fr); }
body.hp-ui .hp-cmp-row { display: grid; grid-template-columns: minmax(0, 1fr); }
body.hp-ui .hp-cmp-cell {
    grid-area: 1 / 1;
    min-width: 0;
    padding: 8px var(--hp-cmp-pad);
    overflow-wrap: anywhere;
}
body.hp-ui .hp-cmp-row:last-child .hp-cmp-cell { padding-bottom: 30px; }
body.hp-ui .hp-cmp-p { margin: 0; white-space: pre-wrap; }
body.hp-ui .hp-cmp-p + .hp-cmp-p { margin-top: .85em; }
body.hp-ui .hp-cmp-row:not(.hp-cmp-head) + .hp-cmp-row .hp-cmp-cell { padding-top: 14px; }

/* The draft: plain type on ruled paper, the lines falling under each line of text. */
body.hp-ui .hp-cmp-cell.is-before {
    font: 400 .98rem/var(--hp-cmp-lh) var(--hx-f-body);
    color: var(--hx-ink-2);
    background-image: repeating-linear-gradient(180deg, transparent 0 calc(var(--hp-cmp-lh) * 1em - 1px), var(--hp-cmp-ruling) calc(var(--hp-cmp-lh) * 1em - 1px) calc(var(--hp-cmp-lh) * 1em));
    background-origin: content-box;
    background-position: 0 -.38em;
}
body.hp-ui .hp-cmp-cell.is-before[dir="rtl"] {
    --hp-cmp-lh: 1.95;
    font-family: "HP Arabic", "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
    font-size: 1.04rem;
}

/*
 * The rewrite: typeset on one sheet of ivory (a single layer, moved by
 * transform, so rows never show a seam), its text clipped at the divider.
 */
body.hp-ui .hp-cmp-paper {
    position: absolute;
    z-index: 1;
    top: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    background: var(--hp-cmp-final);
    transform: translateX(var(--hp-cmp-x));
    pointer-events: none;
}
body.hp-ui .hp-cmp-stage[dir="rtl"] .hp-cmp-paper { transform: translateX(calc(var(--hp-cmp-x) - 100%)); }
body.hp-ui .hp-cmp-paper[hidden] { display: none; }
body.hp-ui .hp-cmp-cell.is-after {
    z-index: 2;
    font: 400 var(--hp-cmp-final-size)/1.5 var(--hx-f-display);
    color: var(--hx-ink);
    clip-path: inset(0 0 0 var(--hp-cmp-x));
}
body.hp-ui .hp-cmp-stage[dir="rtl"] .hp-cmp-cell.is-after { clip-path: inset(0 calc(100% - var(--hp-cmp-x)) 0 0); }
body.hp-ui .hp-cmp-cell.is-after[dir="rtl"] {
    font-family: "HP Arabic Display", "HP Arabic", serif;
    font-size: calc(var(--hp-cmp-final-size) * .92);
    line-height: 1.85;
}

/* Labels: each one belongs to its own paper, so the divider covers it naturally. */
body.hp-ui .hp-cmp-head .hp-cmp-cell {
    display: flex;
    align-items: center;
    padding-top: 16px;
    padding-bottom: 6px;
    font: inherit;
    background-image: none;
}
body.hp-ui .hp-cmp-head .hp-cmp-cell.is-after { justify-content: flex-end; }
body.hp-ui .hp-cmp-tag {
    display: inline-flex;
    align-items: baseline;
    gap: 10px;
    min-width: 0;
    white-space: nowrap;
}
body.hp-ui .hp-cmp-name {
    font: 800 .68rem/1.2 var(--hx-f-body);
    letter-spacing: .16em;
    text-transform: uppercase;
    color: var(--hx-ink-3);
}
body.hp-ui .hp-cmp-head .is-after .hp-cmp-name { color: var(--hx-quill-ink); }
body.hp-ui .hp-cmp-name::before {
    content: "";
    display: inline-block;
    width: 6px;
    height: 6px;
    margin-inline-end: 8px;
    vertical-align: .12em;
    border-radius: 50%;
    border: 1px solid currentColor;
}
body.hp-ui .hp-cmp-head .is-after .hp-cmp-name::before { border: 0; border-radius: 1px; background: var(--hx-quill); transform: rotate(45deg); }
body.hp-ui .hp-cmp-count {
    font: 500 .74rem/1.2 var(--hx-f-body);
    color: var(--hx-ink-3);
    font-variant-numeric: tabular-nums;
}
html[lang="ar"] body.hp-ui .hp-cmp-name { letter-spacing: 0; font-size: .8rem; text-transform: none; }

/* The labels fade as the divider closes over them. */
body.hp-ui .hp-cmp-head .hp-cmp-tag { transition: opacity .25s ease; }
body.hp-ui .hp-cmp-stage.is-near-start .hp-cmp-head .is-before .hp-cmp-tag,
body.hp-ui .hp-cmp-stage.is-near-end .hp-cmp-head .is-after .hp-cmp-tag { opacity: 0; }

/* The divider: a brass rule the width of the stage's own box, moved by transform. */
body.hp-ui .hp-cmp-rule {
    position: absolute;
    z-index: 3;
    top: 0;
    bottom: 0;
    left: -50%;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    pointer-events: none;
    transform: translateX(var(--hp-cmp-x));
}
body.hp-ui .hp-cmp-rule[hidden] { display: none; }
body.hp-ui .hp-cmp-rule::before {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: calc(50% - 1px);
    width: 2px;
    background: linear-gradient(180deg, color-mix(in srgb, var(--hx-quill) 30%, transparent), var(--hx-quill) 40px, var(--hx-quill) calc(100% - 40px), color-mix(in srgb, var(--hx-quill) 30%, transparent));
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--hx-quill) 9%, transparent), 0 0 22px color-mix(in srgb, var(--hx-quill) 32%, transparent);
}
body.hp-ui .hp-cmp-grip {
    position: sticky;
    top: 104px;
    bottom: 96px;
    display: grid;
    place-items: center;
    width: 46px;
    height: 46px;
    margin-block: auto;
    border-radius: 50%;
    pointer-events: auto;
    translate: var(--hp-cmp-nudge) 0;
    background:
        radial-gradient(circle at 50% 30%, color-mix(in srgb, #fff 55%, var(--hx-surface)), var(--hx-surface) 62%);
    border: 1px solid color-mix(in srgb, var(--hx-quill) 72%, var(--hx-line));
    box-shadow:
        0 0 0 4px color-mix(in srgb, var(--hx-surface) 70%, transparent),
        0 10px 22px -10px rgba(8, 26, 19, .55),
        inset 0 -2px 0 color-mix(in srgb, var(--hx-quill) 20%, transparent);
    color: var(--hx-quill-ink);
    cursor: grab;
    touch-action: none;
    transition: scale .18s var(--hx-ease), box-shadow .2s ease;
}
html[data-hp-theme="dark"] body.hp-ui .hp-cmp-grip {
    background: radial-gradient(circle at 50% 30%, var(--hx-surface-2), var(--hx-surface) 70%);
    color: var(--hx-quill);
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--hx-paper) 60%, transparent), 0 12px 24px -10px rgba(0, 0, 0, .8), inset 0 -2px 0 color-mix(in srgb, var(--hx-quill) 22%, transparent);
}
body.hp-ui .hp-cmp-grip svg { width: 44px; height: 44px; overflow: visible; }
body.hp-ui .hp-cmp-chev { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
body.hp-ui .hp-cmp-pivot { fill: var(--hx-quill); }
body.hp-ui .hp-cmp-grip:hover { scale: 1.05; }
body.hp-ui .hp-cmp-stage.is-dragging { cursor: grabbing; }
body.hp-ui .hp-cmp-stage.is-dragging .hp-cmp-grip { scale: 1.1; cursor: grabbing; }
body.hp-ui .hp-cmp-grip:focus-visible { outline: 2px solid var(--hx-focus); outline-offset: 4px; }

body.hp-ui .hp-cmp-empty { margin: 0; padding: 48px 24px; text-align: center; color: var(--hx-ink-3); font-size: .95rem; }
body.hp-ui .hp-cmp-sr {
    position: absolute; width: 1px; height: 1px; overflow: hidden;
    clip-path: inset(50%); white-space: nowrap;
}

@media (max-width: 640px) {
    body.hp-ui .hp-cmp-stage { --hp-cmp-final-size: 1.16rem; --hp-cmp-pad: 16px; border-radius: 16px; }
    /* Two labels do not fit side by side: the draft's on the first line, the rewrite's on the second. */
    body.hp-ui .hp-cmp-head .hp-cmp-cell.is-before { align-items: flex-start; padding-bottom: 32px; }
    body.hp-ui .hp-cmp-head .hp-cmp-cell.is-after { align-items: flex-end; }
    body.hp-ui .hp-cmp-stage.is-workspace { --hp-cmp-final-size: 1.2rem; }
    body.hp-ui .hp-cmp-cell.is-before { font-size: .94rem; }
    body.hp-ui .hp-cmp-grip { width: 42px; height: 42px; }
    body.hp-ui .hp-cmp-tag { gap: 6px; }
    body.hp-ui .hp-cmp-count { font-size: .7rem; }
}

/* ---------- The workspace: a "Compare" view beside "Review changes" ---------- */
body.hp-ui .hp-cmp-switch { display: flex; align-items: center; margin-top: 12px; }
body.hp-ui .hp-cmp-switch[hidden] { display: none; }
body.hp-ui .hp-cmp-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 34px;
    padding: 0 14px 0 11px;
    border: 1px solid var(--hx-line-2);
    border-radius: 999px;
    background: var(--hx-surface);
    color: var(--hx-ink);
    font: 700 .75rem/1 var(--hx-f-body);
    cursor: pointer;
    transition: border-color .2s ease, background-color .2s ease, color .2s ease;
}
body.hp-ui .hp-cmp-toggle svg { width: 17px; height: 17px; --hp-icon-accent: var(--hx-quill); }
body.hp-ui .hp-cmp-toggle:hover { border-color: var(--hx-royal); color: var(--hx-royal-ink); }
body.hp-ui .hp-cmp-toggle[aria-pressed="true"] {
    background: var(--hx-ink);
    border-color: var(--hx-ink);
    color: var(--hx-paper);
}
body.hp-ui .hp-cmp-toggle[aria-pressed="true"] svg { --hp-icon-accent: var(--hx-cream); }
html[data-hp-theme="dark"] body.hp-ui .hp-cmp-toggle { background: var(--hx-surface-2); }
html[data-hp-theme="dark"] body.hp-ui .hp-cmp-toggle[aria-pressed="true"] { background: var(--hx-quill); border-color: var(--hx-quill); color: #14231c; }
body.hp-ui .hp-cmp-toggle:focus-visible { outline: 2px solid var(--hx-focus); outline-offset: 3px; }

body.hp-ui .hp-cmp-panel { margin: 18px 20px 4px; }
body.hp-ui .hp-cmp-panel[hidden] { display: none; }
@media (min-width: 640px) {
    body.hp-ui .hp-cmp-panel { margin: 22px 28px 6px; }
}
body.hp-ui .hp-cmp-caption {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 6px 16px;
    margin: 0 0 12px;
    color: var(--hx-ink-3);
    font-size: .8rem;
    line-height: 1.4;
}
@media (hover: none) { body.hp-ui .hp-cmp-keys { display: none; } }
body.hp-ui .hp-cmp-caption kbd {
    display: inline-block;
    min-width: 1.6em;
    padding: 1px 6px;
    border: 1px solid var(--hx-line-2);
    border-bottom-width: 2px;
    border-radius: 6px;
    background: var(--hx-surface);
    font: 600 .72rem/1.4 var(--hx-f-mono);
    color: var(--hx-ink-2);
    text-align: center;
}

/* ---------- The document page: "Before and after" ---------- */
body.hp-ui .hp-cmp-card {
    margin: 22px 0;
    padding: 22px 20px 20px;
    border: 1px solid var(--hx-line);
    border-radius: 24px;
    background: var(--hx-surface);
    box-shadow: var(--hx-shadow);
}
@media (min-width: 640px) { body.hp-ui .hp-cmp-card { padding: 28px 28px 24px; } }
body.hp-ui .hp-cmp-card-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 14px 24px;
    margin-bottom: 18px;
}
body.hp-ui .hp-cmp-kicker {
    margin: 0 0 6px;
    color: var(--hx-quill-ink);
    font: 700 .7rem/1.3 var(--hx-f-body);
    letter-spacing: .16em;
    text-transform: uppercase;
}
html[lang="ar"] body.hp-ui .hp-cmp-kicker { font-size: .8rem; letter-spacing: 0; }
body.hp-ui .hp-cmp-title { margin: 0; font-size: clamp(1.7rem, 3vw, 2.25rem); color: var(--hx-ink); }
body.hp-ui .hp-cmp-title em { font-style: italic; color: var(--hx-quill-ink); }
html[data-hp-theme="dark"] body.hp-ui .hp-cmp-title em { color: var(--hx-quill); }
body.hp-ui .hp-cmp-lede { margin: 8px 0 0; max-width: 52ch; color: var(--hx-ink-3); font-size: .9rem; line-height: 1.55; }
body.hp-ui .hp-cmp-pair {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}
body.hp-ui .hp-cmp-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 32px;
    padding: 0 13px;
    border-radius: 999px;
    background: var(--hx-surface-2);
    border: 1px solid var(--hx-line);
    color: var(--hx-ink-2);
    font: 700 .78rem/1.2 var(--hx-f-body);
}
body.hp-ui .hp-cmp-chip.is-after { background: var(--hx-quill-soft); border-color: color-mix(in srgb, var(--hx-quill) 35%, transparent); color: var(--hx-quill-ink); }
body.hp-ui .hp-cmp-vs { display: inline-flex; color: var(--hx-quill); }
body.hp-ui .hp-cmp-vs svg { width: 18px; height: 18px; --hp-icon-accent: var(--hx-quill); }
[dir="rtl"] body.hp-ui .hp-cmp-vs svg { transform: scaleX(-1); }
body.hp-ui .hp-cmp-reset {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 32px;
    padding: 0 12px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--hx-royal-ink);
    font: 700 .78rem/1 var(--hx-f-body);
    text-decoration: underline;
    text-decoration-color: color-mix(in srgb, currentColor 35%, transparent);
    text-underline-offset: .25em;
    cursor: pointer;
}
body.hp-ui .hp-cmp-reset[hidden] { display: none; }
body.hp-ui .hp-cmp-reset:hover { text-decoration-color: currentColor; }
body.hp-ui .hp-cmp-reset:focus-visible { outline: 2px solid var(--hx-focus); outline-offset: 2px; }

/* A long text opens folded: the stage is clipped (not scrolled), the grip stays in the visible part. */
body.hp-ui .hp-cmp-frame { position: relative; }
body.hp-ui .hp-cmp-frame.is-folded { max-height: 34rem; overflow-y: clip; overflow-x: visible; }
body.hp-ui .hp-cmp-frame.is-folded .hp-cmp-rule { bottom: auto; height: 34rem; }
body.hp-ui .hp-cmp-frame.is-folded::after {
    content: "";
    position: absolute;
    z-index: 3;
    inset: auto 1px 0;
    height: 120px;
    border-radius: 0 0 20px 20px;
    pointer-events: none;
    background: linear-gradient(180deg, transparent, var(--hx-surface) 92%);
}
body.hp-ui .hp-cmp-more {
    display: flex;
    justify-content: center;
    margin-top: 12px;
}
body.hp-ui .hp-cmp-more[hidden] { display: none; }
body.hp-ui .hp-cmp-more button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 36px;
    padding: 0 16px;
    border: 1px solid var(--hx-line-2);
    border-radius: 999px;
    background: var(--hx-surface);
    color: var(--hx-ink);
    font: 700 .8rem/1 var(--hx-f-body);
    cursor: pointer;
}
body.hp-ui .hp-cmp-more button:hover { border-color: var(--hx-royal); color: var(--hx-royal-ink); }
body.hp-ui .hp-cmp-more svg { width: 16px; height: 16px; transition: transform .2s var(--hx-ease); }
body.hp-ui .hp-cmp-more button[aria-expanded="true"] svg { transform: rotate(180deg); }
body.hp-ui .hp-cmp-more button:focus-visible { outline: 2px solid var(--hx-focus); outline-offset: 3px; }

/* A version opened from the timeline arrives with a brief brass glow. */
body.hp-ui .hp-cmp-card.is-arriving { box-shadow: var(--hx-shadow), 0 0 0 2px color-mix(in srgb, var(--hx-quill) 55%, transparent); }
body.hp-ui .hp-cmp-card { transition: box-shadow .6s ease; }

@media (prefers-reduced-motion: reduce) {
    body.hp-ui .hp-cmp-grip,
    body.hp-ui .hp-cmp-head .hp-cmp-tag,
    body.hp-ui .hp-cmp-card,
    body.hp-ui .hp-cmp-more svg { transition: none; }
    body.hp-ui .hp-cmp-grip:hover,
    body.hp-ui .hp-cmp-stage.is-dragging .hp-cmp-grip { scale: none; }
}

@media print {
    body.hp-ui .hp-cmp-card, body.hp-ui .hp-cmp-panel, body.hp-ui .hp-cmp-switch { display: none; }
}
