/* Reading-mode styles. Two concerns:
   (1) .rp-markdown — readable typography for rendered lesson markdown. Used BOTH on the in-cabinet
       content page (/content) and inside the reader. Before this file the class had no rules at all,
       so lesson text fell back to UA defaults (no paragraph rhythm, cramped lists).
   (2) .rp-reader — the chrome-free reader shell: full-viewport background per color scheme, a
       centered reading column, a slim top bar, and a native <details> settings popover. Color and
       base font-size are driven by CSS variables keyed off the data-reader-scheme / data-reader-size
       attributes that ReaderPage sets (and reader.js persists). */

/* ---- (1) Shared markdown typography ---- */
.rp-markdown { line-height: 1.65; }
.rp-markdown > :first-child { margin-top: 0; }
.rp-markdown > :last-child { margin-bottom: 0; }
.rp-markdown p { margin: 0 0 1em; }
.rp-markdown h1, .rp-markdown h2, .rp-markdown h3, .rp-markdown h4 {
    line-height: 1.25; margin: 1.6em 0 0.6em; font-weight: 650;
}
.rp-markdown ul, .rp-markdown ol { margin: 0 0 1em; padding-left: 1.5em; }
.rp-markdown li { margin: 0.25em 0; }
.rp-markdown blockquote {
    margin: 0 0 1em; padding: 0.25em 0 0.25em 1em;
    border-left: 3px solid var(--slate-300, #cbd5e1); color: var(--slate-500, #64748b);
}
.rp-markdown code {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em;
    background: var(--slate-100, #f1f5f9); padding: 0.1em 0.35em; border-radius: 4px;
}
.rp-markdown pre { overflow-x: auto; background: var(--slate-100, #f1f5f9); padding: 0.8em 1em; border-radius: 8px; }
.rp-markdown pre code { background: none; padding: 0; }
.rp-markdown img { max-width: 100%; height: auto; border-radius: 8px; }
.rp-markdown a { color: var(--brand-primary, #1d73b3); }

/* ---- (2) Reader shell ---- */
.rp-reader {
    --reader-bg: #ffffff; --reader-fg: #1a1a1a; --reader-muted: #6b6b6b;
    --reader-card: rgba(0, 0, 0, 0.04); --reader-accent: #1d73b3; --reader-font: 18px;
    /* Opaque surfaces for the floating pill / segment track (the translucent --reader-card
       reads muddy over the reading column). Scheme-specific so the pill follows the READING theme. */
    --reader-surface: #ffffff; --reader-border: #e7e3dc; --reader-sec: #f3f1ed;
    position: fixed; inset: 0; overflow-y: auto; z-index: 1;
    background: var(--reader-bg); color: var(--reader-fg);
    font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.rp-reader[data-reader-scheme="sepia"] {
    --reader-bg: #f4ecd8; --reader-fg: #5b4636; --reader-muted: #8a7a64;
    --reader-card: rgba(91, 70, 54, 0.07); --reader-accent: #9a6a3a;
    --reader-surface: #fbf4e6; --reader-border: #e2d4b8; --reader-sec: #efe3cb;
}
.rp-reader[data-reader-scheme="dark"] {
    --reader-bg: #1a1a1a; --reader-fg: #d6d6d6; --reader-muted: #9a9a9a;
    --reader-card: rgba(255, 255, 255, 0.06); --reader-accent: #4ea3e0;
    --reader-surface: #201e1b; --reader-border: #322e28; --reader-sec: #2a2723;
}
.rp-reader[data-reader-size="0"] { --reader-font: 16px; }
.rp-reader[data-reader-size="1"] { --reader-font: 18px; }
.rp-reader[data-reader-size="2"] { --reader-font: 20px; }
.rp-reader[data-reader-size="3"] { --reader-font: 23px; }
.rp-reader[data-reader-size="4"] { --reader-font: 26px; }

.rp-reader .rp-markdown,
.rp-reader .rp-markdown :is(p, li, blockquote) { color: var(--reader-fg); }
.rp-reader .rp-markdown code,
.rp-reader .rp-markdown pre { background: var(--reader-card); }
.rp-reader .rp-markdown a { color: var(--reader-accent); }

.rp-reader-bar {
    position: sticky; top: 0; z-index: 4; display: flex; align-items: center; gap: 14px;
    padding: 0 20px; height: 60px; background: var(--reader-surface); color: var(--reader-fg);
    border-bottom: 1px solid var(--reader-border);
    background: color-mix(in srgb, var(--reader-surface) 90%, transparent);
    backdrop-filter: blur(8px);
}
.rp-reader-exit {
    display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0;
    color: var(--reader-muted); text-decoration: none; font-size: 0.9rem; font-weight: 500;
}
.rp-reader-exit:hover { color: var(--reader-fg); }
.rp-reader-bar-sep { width: 1px; height: 20px; background: var(--reader-border); flex-shrink: 0; }
.rp-reader-bar-title {
    font-size: 0.9rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    min-width: 0;
}
.rp-reader-bar-subtitle { font-size: 0.8rem; color: var(--reader-muted); flex-shrink: 0; }
.rp-reader-bar-spacer { flex: 1; }
.rp-reader-panel-label {
    font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em;
    color: var(--reader-muted); margin-bottom: -4px;
}
@media (max-width: 600px) {
    .rp-reader-bar { padding: 0 12px; gap: 8px; }
    .rp-reader-bar-sep, .rp-reader-bar-subtitle { display: none; }
}
.rp-reader-settings { position: relative; }
.rp-reader-aa {
    list-style: none; cursor: pointer; font-weight: 600; padding: 7px 13px;
    background: var(--reader-surface); color: var(--reader-fg);
    border: 1px solid var(--reader-border); border-radius: 8px; user-select: none;
}
/* `list-style: none` hides the disclosure triangle in Firefox; WebKit/Blink need this too. */
.rp-reader-aa::-webkit-details-marker { display: none; }

.rp-reader-progress {
    position: sticky; top: 0; left: 0; height: 3px; z-index: 3;
    background: var(--reader-accent);
    transform: scaleX(var(--reader-progress, 0)); transform-origin: left center;
    transition: transform 0.08s linear;
}

.rp-reader-settings[open] .rp-reader-panel { display: flex; }
.rp-reader-panel {
    display: none; position: absolute; right: 0; top: calc(100% + 8px); z-index: 5;
    flex-direction: column; gap: 12px; padding: 16px; min-width: 236px;
    background: var(--reader-surface); color: var(--reader-fg);
    border: 1px solid var(--reader-border); border-radius: 12px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
}
.rp-reader-fonts { display: flex; gap: 10px; align-items: center; }
.rp-reader-schemes { display: flex; gap: 8px; }
.rp-reader-font {
    width: 44px; cursor: pointer; padding: 9px 0; font-size: 1rem; font-weight: 600;
    background: var(--reader-surface); color: var(--reader-fg);
    border: 1px solid var(--reader-border); border-radius: 8px;
}
.rp-reader-font-label { flex: 1; text-align: center; font-size: 0.82rem; color: var(--reader-muted); }
.rp-reader-swatch {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px;
    padding: 8px 4px; cursor: pointer; font: inherit;
    background: transparent; border: 1.5px solid var(--reader-border); border-radius: 8px;
}
.rp-reader-swatch-dot {
    width: 26px; height: 26px; border-radius: 50%; display: inline-flex;
    align-items: center; justify-content: center; font-size: 0.75rem; font-weight: 600;
}
.rp-reader-swatch-name { font-size: 0.7rem; color: var(--reader-muted); }
.rp-reader-swatch.rp-scheme-light .rp-reader-swatch-dot { background: #ffffff; color: #1c1a17; border: 1px solid #d0d0d0; }
.rp-reader-swatch.rp-scheme-sepia .rp-reader-swatch-dot { background: #fbf4e6; color: #3b3020; border: 1px solid #e2d4b8; }
.rp-reader-swatch.rp-scheme-dark .rp-reader-swatch-dot { background: #201e1b; color: #e8e4de; border: 1px solid #322e28; }
.rp-reader-fullscreen {
    cursor: pointer; padding: 9px 0; background: var(--reader-surface); color: var(--reader-fg);
    border: 1px solid var(--reader-border); border-radius: 8px; font-size: 0.9rem;
}

.rp-reader-font:disabled { opacity: 0.4; cursor: default; }
.rp-reader-swatch.is-active { border-color: var(--reader-accent); }
.rp-reader-opt {
    flex: 1; cursor: pointer; padding: 8px 6px; font-size: 0.9rem;
    background: var(--reader-card); color: var(--reader-fg); border: 0; border-radius: 8px;
}
.rp-reader-opt.is-active { outline: 2px solid var(--reader-accent); outline-offset: 1px; font-weight: 650; }
.rp-reader-opts { display: flex; gap: 8px; }

.rp-reader-doc {
    max-width: var(--reader-measure, 34em);
    margin: 0 auto; padding: 32px 20px 96px;
    font-size: var(--reader-font);
    font-family: var(--reader-doc-font, inherit);
}
/* The narration pill is `position:fixed` and reserves no layout space on its own, so the last
   content block can render underneath it — bump the doc's bottom padding whenever a player is
   present (ReaderDocument toggles `.rp-reader--with-player` off the audio manifest). Mobile gets
   extra room because the pill wraps to two rows there (segments row + controls row) plus the
   safe-area inset. */
.rp-reader--with-player .rp-reader-doc { padding-bottom: 170px; }
/* When the prev/next lesson nav follows the doc, the pill must clear the NAV, not the doc — else
   the fixed pill sits exactly over the «Следующий →» links at bottom-of-scroll (hit-test-verified).
   With :has() support the doc drops back to its base padding so the reserve isn't doubled; without
   it both rules apply (harmless extra gap, links still clickable). */
.rp-reader--with-player .rp-reader-doc:has(~ .rp-reader-nav) { padding-bottom: 96px; }
.rp-reader--with-player .rp-reader-nav { margin-bottom: 150px; }
.rp-reader[data-reader-width="narrow"] { --reader-measure: 30em; }
.rp-reader[data-reader-width="medium"] { --reader-measure: 34em; }
.rp-reader[data-reader-width="wide"]   { --reader-measure: 40em; }
.rp-reader[data-reader-font-family="serif"] { --reader-doc-font: Georgia, "Noto Serif", "Times New Roman", serif; }
.rp-reader-title { font-size: 1.6em; line-height: 1.2; margin: 0 0 1em; font-weight: 700; }
.rp-reader-block { margin: 0 0 1.8em; }
.rp-reader-video { position: relative; width: 100%; padding-top: 56.25%; }
.rp-reader-video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; border-radius: 8px; }
.rp-reader-file {
    display: flex; align-items: center; gap: 12px; text-decoration: none;
    padding: 14px 16px; background: var(--reader-card); border-radius: 10px; color: var(--reader-fg);
}
.rp-reader-file-name { font-weight: 600; }
.rp-reader-file-size { color: var(--reader-muted); font-size: 0.85em; }
.rp-reader-file-cta { margin-left: auto; color: var(--reader-accent); font-weight: 600; }
/* Формула-мини-волна Task 4: .rp-formula's base card (bp.css) uses the cabinet's var(--card)/var(--border) —
   re-tint to the reader's own palette so it follows the light/sepia/dark scheme swap. KaTeX renders formula
   text in currentColor, which already tracks --reader-fg, so no separate text-color rule is needed. */
.rp-reader .rp-formula { background: var(--reader-card); border-color: var(--reader-border); }
.rp-reader-hw { padding: 16px; background: var(--reader-card); border-radius: 12px; }
.rp-reader-hw-label { font-weight: 650; margin-bottom: 8px; }
.rp-reader-hw-cta {
    display: inline-block; margin-top: 12px; padding: 8px 16px; border-radius: 8px;
    background: var(--reader-accent); color: #fff; text-decoration: none; font-weight: 600;
}

.rp-reader-nav {
    max-width: var(--reader-measure, 34em); margin: 2.4em auto 0;
    display: flex; gap: 12px; justify-content: space-between;
    border-top: 1px solid var(--reader-card); padding-top: 1.4em;
}
.rp-reader-nav-link {
    flex: 1; display: flex; flex-direction: column; gap: 2px; text-decoration: none;
    padding: 12px 14px; border-radius: 10px; background: var(--reader-card); color: var(--reader-fg);
}
.rp-reader-nav-link.next { text-align: right; }
.rp-reader-nav-link.is-disabled { opacity: 0.5; pointer-events: none; }
.rp-reader-nav-dir { font-size: 0.8em; color: var(--reader-muted); }
.rp-reader-nav-title { font-weight: 600; }

/* Tap-to-jump: only blocks with narration get a pointer cursor + hover affordance. */
.rp-reader-block.is-jumpable { cursor: pointer; }

/* ---- Audio narration pill (desktop: floating bottom-center; mobile: full-width bottom bar) ---- */
.rp-reader-pill-wrap {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
    display: flex; justify-content: center; padding: 0 24px 20px; pointer-events: none;
}
.rp-reader-pill {
    pointer-events: auto; display: flex; align-items: center; gap: 14px;
    height: 64px; padding: 0 18px 0 14px; min-width: 420px; max-width: 640px;
    background: var(--reader-surface); color: var(--reader-fg);
    border: 1px solid var(--reader-border); border-radius: 999px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
}
.rp-reader-pill-btn, .rp-reader-pill-play {
    display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
    border: 0; cursor: pointer; border-radius: 50%; line-height: 1;
}
.rp-reader-pill-btn {
    width: 40px; height: 40px; background: transparent; color: var(--reader-fg); font-size: 1rem;
    transition: background 0.15s;
}
.rp-reader-pill-btn:hover { background: var(--reader-sec); }
.rp-reader-pill-play {
    width: 46px; height: 46px; background: var(--reader-accent); color: #fff; font-size: 0.95rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
.rp-reader-pill-info { flex: 1; min-width: 0; }
.rp-reader-pill-titles { display: flex; align-items: baseline; gap: 8px; }
.rp-reader-pill-label { font-size: 0.78rem; font-weight: 600; }
.rp-reader-pill-block { font-size: 0.72rem; color: var(--reader-muted); white-space: nowrap; }
.rp-reader-pill-track {
    display: flex; gap: 2px; height: 4px; margin-top: 6px; border-radius: 999px; overflow: hidden;
}
.rp-reader-pill-seg {
    flex: 1; height: 100%; border-radius: 999px; background: var(--reader-sec); overflow: hidden;
}
.rp-reader-pill-seg-fill { height: 100%; background: var(--reader-accent); transition: width 0.3s; }
.rp-reader-pill-time {
    font-size: 0.72rem; color: var(--reader-muted); flex-shrink: 0;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.rp-reader-pill-rate {
    flex-shrink: 0; background: var(--reader-surface); color: var(--reader-fg);
    border: 1px solid var(--reader-border); border-radius: 8px;
    padding: 4px 6px; font-size: 0.8rem; cursor: pointer;
}

@media (max-width: 600px) {
    .rp-reader-pill-wrap { padding: 0; }
    .rp-reader-pill {
        width: 100%; min-width: 0; max-width: none; height: auto;
        flex-wrap: wrap; align-items: center; gap: 8px 10px;
        padding: 10px 14px calc(14px + env(safe-area-inset-bottom, 0px));
        border-radius: 0; border-width: 1px 0 0;
        background: color-mix(in srgb, var(--reader-surface) 94%, transparent);
        backdrop-filter: blur(10px);
    }
    /* .rp-reader-pill-track is a DOM child of .rp-reader-pill-info, not a direct child of
       .rp-reader-pill — so `order`/`flex-basis` on the track were no-ops against the pill's flex
       formatting context (those properties only apply to genuine flex items of the container
       they sit directly inside). `display: contents` removes -info's own box without touching
       the DOM, promoting its children (-titles, -track) to real flex items of .rp-reader-pill so
       their order/flex-basis actually take effect. Segments row spans full width on top; controls
       + info below. */
    .rp-reader-pill-info { display: contents; }
    .rp-reader-pill-track { order: -1; flex-basis: 100%; margin-top: 0; }
    .rp-reader-pill-titles { order: 1; flex: 1 1 auto; min-width: 0; }
    .rp-reader-pill-btn, .rp-reader-pill-play { order: 2; }
    .rp-reader-pill-time, .rp-reader-pill-rate { order: 3; }

    /* Two-row pill (segments + wrapped controls) needs more reserved space than desktop's
       floating single row, plus the safe-area inset already padded into the pill itself. */
    .rp-reader--with-player .rp-reader-doc { padding-bottom: calc(210px + env(safe-area-inset-bottom, 0px)); }
    .rp-reader--with-player .rp-reader-doc:has(~ .rp-reader-nav) { padding-bottom: 96px; }
    .rp-reader--with-player .rp-reader-nav { margin-bottom: calc(190px + env(safe-area-inset-bottom, 0px)); }
}

/* Highlight the block currently being narrated */
.rp-reader-block.is-speaking {
    background: color-mix(in srgb, var(--reader-accent) 12%, transparent);
    border-radius: 8px;
    transition: background 0.25s;
}
