/* ==================================================================
   rd-nar — audio narration player for the reader
   Sticky bottom bar with an expandable panel. Drives both uploaded
   audio files and browser-synthesised narration ("Narrate with Oryx").
   Themed for dark (default), sepia, and light reading modes.
   ================================================================== */

.rd-nar {
    position: fixed;
    left: 50%;
    transform: translateX(-50%) translateY(0);
    bottom: 18px;
    width: min(720px, calc(100% - 28px));
    z-index: 40;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    display: flex;
    flex-direction: column;
    background: rgba(20, 22, 34, .82);
    backdrop-filter: blur(20px) saturate(1.2);
    -webkit-backdrop-filter: blur(20px) saturate(1.2);
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: var(--r-card);
    box-shadow: 0 10px 40px rgba(0, 0, 0, .45);
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    animation: rd-nar-slide-in .38s cubic-bezier(.2,.8,.2,1) .2s forwards;
    transition:
        transform .28s cubic-bezier(.2,.8,.2,1),
        opacity   .2s,
        width     .28s cubic-bezier(.2,.8,.2,1),
        border-radius .28s;
}
@keyframes rd-nar-slide-in {
    from { opacity: 0; transform: translateX(-50%) translateY(20px); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0);    }
}
.rd-nar[hidden] {
    display: flex;
    opacity: 0;
    transform: translateX(-50%) translateY(28px);
    pointer-events: none;
    animation: none;
}
.rd-nar[data-ready="1"] {
    opacity: 1;
    pointer-events: auto;
}

/* ---- Bar row ---- */
.rd-nar-bar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
}
.rd-nar-left,
.rd-nar-right {
    display: flex;
    align-items: center;
    min-width: 0;
    gap: 10px;
}
.rd-nar-right { justify-content: flex-end; }
.rd-nar-center {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 0 0 auto;
    min-width: 280px;
    max-width: 360px;
}

/* ---- Left: cover + title ---- */
.rd-nar-cover {
    width: 36px;
    height: 36px;
    border-radius: var(--r-card);
    background: linear-gradient(135deg, #ddb1f9 0%, #6366f1 100%);
    background-size: cover;
    background-position: center;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(139, 92, 246, .25);
}
.rd-nar-cover svg { opacity: .9; }
.rd-nar-title {
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.rd-nar-title strong {
    font-size: 13px;
    font-weight: 600;
    color: #e8e8f0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.rd-nar-title small {
    font-size: 11px;
    color: rgba(232, 232, 240, .55);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ---- Center: play + thin progress ---- */
.rd-nar-play {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 0;
    background: linear-gradient(135deg, #c79bff, #ddb1f9);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(139, 92, 246, .35);
    transition: transform .12s cubic-bezier(.2,.8,.2,1);
    flex-shrink: 0;
}
.rd-nar-play:hover { transform: scale(1.04); }
.rd-nar-play:active { transform: scale(.94); }
.rd-nar-play .ico-pause { display: none; }
.rd-nar[data-playing="1"] .rd-nar-play .ico-play { display: none; }
.rd-nar[data-playing="1"] .rd-nar-play .ico-pause { display: inline; }

.rd-nar-seek {
    position: relative;
    flex: 1 1 auto;
    height: 20px;
    display: flex;
    align-items: center;
    cursor: pointer;
}
.rd-nar-seek-track {
    position: relative;
    width: 100%;
    height: 3px;
    background: rgba(255, 255, 255, .1);
    border-radius: var(--r-pill);
    overflow: visible;
    transition: height .2s;
}
.rd-nar-seek:hover .rd-nar-seek-track { height: 5px; }
.rd-nar-seek-fill {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, #c79bff, #ddb1f9);
    border-radius: var(--r-pill);
    transition: width 120ms linear;
    pointer-events: none;
}
.rd-nar-seek-handle {
    position: absolute;
    top: 50%;
    left: 0;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #fff;
    transform: translate(-50%, -50%) scale(0);
    box-shadow: 0 2px 8px rgba(0, 0, 0, .4);
    transition: transform .18s cubic-bezier(.2,.8,.2,1);
    pointer-events: none;
}
.rd-nar-seek:hover .rd-nar-seek-handle,
.rd-nar[data-expanded="1"] .rd-nar-seek-handle { transform: translate(-50%, -50%) scale(1); }
.rd-nar-seek-input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    margin: 0;
}

/* ---- Right: speed + expand + close ---- */
.rd-nar-speed {
    background: rgba(255, 255, 255, .06);
    border: 1px solid rgba(255, 255, 255, .1);
    color: #e8e8f0;
    border-radius: var(--r-card);
    padding: 5px 9px;
    font-size: 12px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    cursor: pointer;
    transition: background .15s, color .15s;
}
.rd-nar-speed:hover { background: rgba(255, 255, 255, .12); }

.rd-nar-btn {
    width: 30px;
    height: 30px;
    border-radius: var(--r-pill);
    background: transparent;
    border: 0;
    color: rgba(232, 232, 240, .65);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background .15s, color .15s, transform .2s;
}
.rd-nar-btn:hover { background: rgba(255, 255, 255, .08); color: #e8e8f0; }
.rd-nar[data-expanded="1"] .rd-nar-expand { transform: rotate(180deg); }

/* ---- Expandable panel ---- */
.rd-nar-panel {
    max-height: 0;
    overflow: hidden;
    border-top: 1px solid transparent;
    transition:
        max-height .34s cubic-bezier(.2,.8,.2,1),
        border-color .2s,
        padding .28s cubic-bezier(.2,.8,.2,1);
    padding: 0 16px;
}
.rd-nar[data-expanded="1"] .rd-nar-panel {
    max-height: 320px;
    border-top-color: rgba(255, 255, 255, .06);
    padding: 14px 16px 16px;
}

.rd-nar-wave {
    position: relative;
    width: 100%;
    height: 42px;
    overflow: hidden;
}
.rd-nar-wave svg { width: 100%; height: 100%; display: block; }
.rd-nar-wave-bar {
    fill: rgba(255, 255, 255, .14);
    transition: fill .1s;
}
.rd-nar-wave-bar.on { fill: #c79bff; }

.rd-nar-times {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    font-variant-numeric: tabular-nums;
    color: rgba(232, 232, 240, .55);
    margin-top: 6px;
}

.rd-nar-sources {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    flex-wrap: wrap;
}
.rd-nar-src {
    flex: 1 1 auto;
    min-width: 120px;
    background: rgba(255, 255, 255, .04);
    border: 1px solid rgba(255, 255, 255, .08);
    color: rgba(232, 232, 240, .8);
    padding: 8px 12px;
    border-radius: var(--r-card);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background .15s, border-color .15s, color .15s;
}
.rd-nar-src:hover { background: rgba(255, 255, 255, .07); }
.rd-nar-src[aria-pressed="true"] {
    background: rgba(139, 92, 246, .14);
    border-color: rgba(139, 92, 246, .45);
    color: #e8e8f0;
}
.rd-nar-src svg { color: #c79bff; flex-shrink: 0; }
.rd-nar-src small { display: block; color: rgba(232, 232, 240, .5); font-weight: 400; }

/* Studio source — premium-feel sheen + inline generation status.
   The status span is data-status driven; empty/idle renders nothing. */
.rd-nar-src-studio {
    background: linear-gradient(135deg, rgba(139, 92, 246, .10), rgba(244, 114, 182, .08));
    border-color: rgba(244, 114, 182, .25);
}
.rd-nar-src-studio:hover {
    background: linear-gradient(135deg, rgba(139, 92, 246, .16), rgba(244, 114, 182, .12));
}
.rd-nar-studio-status {
    margin-left: auto;
    font-size: 11px;
    font-weight: 500;
    color: rgba(232, 232, 240, .55);
    padding: 2px 8px;
    border-radius: var(--r-pill);
    background: rgba(255, 255, 255, .06);
    white-space: nowrap;
}
.rd-nar-studio-status[data-status="idle"],
.rd-nar-studio-status:empty { display: none; }
.rd-nar-studio-status[data-status="generating"] {
    color: #f9a8d4;
    background: rgba(244, 114, 182, .15);
    animation: rd-nar-pulse 1.4s ease-in-out infinite;
}
.rd-nar-studio-status[data-status="ready"]  { display: none; }
.rd-nar-studio-status[data-status="error"]  { color: #FFA8B2; background: rgba(239, 68, 68, .18); }
@keyframes rd-nar-pulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: .55; }
}

/* ---- Reopen pill (shown when closed) ---- */
.rd-nar-reopen {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: linear-gradient(135deg, #c79bff, #ddb1f9);
    border: 0;
    color: #fff;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 24px rgba(139, 92, 246, .35);
    z-index: 39;
    transition: transform .18s;
}
.rd-nar-reopen.visible { display: flex; }
.rd-nar-reopen:hover { transform: scale(1.05); }
.rd-nar-reopen:active { transform: scale(.94); }

/* ---- Sentence highlight (Oryx TTS) ---- */
.rd-nar-sent {
    transition: background-color .25s cubic-bezier(.2,.8,.2,1), color .25s;
    border-radius: var(--r-card);
    padding: 1px 0;
}
.rd-nar-sent-active {
    background-color: rgba(139, 92, 246, .14);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, .14);
}
body.rd-theme-sepia .rd-nar-sent-active { background-color: rgba(139, 92, 246, .13); box-shadow: 0 0 0 3px rgba(139, 92, 246, .13); }
body.rd-theme-light .rd-nar-sent-active { background-color: rgba(124, 58, 237, .10); box-shadow: 0 0 0 3px rgba(124, 58, 237, .10); }

/* ---- Focus mode: minimise ----
   In focus mode the bar fades + slides down, but stays reachable by
   hovering near the bottom of the screen. */
body.rd-focus .rd-nar {
    opacity: 0;
    transform: translateX(-50%) translateY(80%);
    pointer-events: none;
    transition: opacity var(--dur-slow) var(--ease-out), transform var(--dur-slow) var(--ease-out);
}
body.rd-focus .rd-nar:hover,
body.rd-focus .rd-nar[data-expanded="1"] {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
    pointer-events: auto;
}

/* ---- Sepia theme ---- */
body.rd-theme-sepia .rd-nar {
    background: color-mix(in srgb, #f3e9d2 92%, transparent);
    border-color: rgba(74, 58, 34, .14);
    box-shadow: 0 10px 30px rgba(74, 58, 34, .18);
}
body.rd-theme-sepia .rd-nar-title strong { color: #2b200f; }
body.rd-theme-sepia .rd-nar-title small  { color: rgba(74, 58, 34, .6); }
body.rd-theme-sepia .rd-nar-seek-track { background: rgba(74, 58, 34, .14); }
body.rd-theme-sepia .rd-nar-seek-handle { background: #3b2e1b; box-shadow: 0 2px 8px rgba(74, 58, 34, .3); }
body.rd-theme-sepia .rd-nar-btn { color: rgba(74, 58, 34, .65); }
body.rd-theme-sepia .rd-nar-btn:hover { background: rgba(74, 58, 34, .08); color: #2b200f; }
body.rd-theme-sepia .rd-nar-speed {
    background: rgba(74, 58, 34, .06);
    border-color: rgba(74, 58, 34, .14);
    color: #3b2e1b;
}
body.rd-theme-sepia .rd-nar-speed:hover { background: rgba(74, 58, 34, .11); }
body.rd-theme-sepia .rd-nar-panel { border-top-color: rgba(74, 58, 34, .1); }
body.rd-theme-sepia .rd-nar-times { color: rgba(74, 58, 34, .55); }
body.rd-theme-sepia .rd-nar-src {
    background: rgba(74, 58, 34, .04);
    border-color: rgba(74, 58, 34, .12);
    color: #3b2e1b;
}
body.rd-theme-sepia .rd-nar-src small { color: rgba(74, 58, 34, .55); }
body.rd-theme-sepia .rd-nar-src[aria-pressed="true"] {
    background: rgba(139, 92, 246, .12);
    border-color: rgba(139, 92, 246, .4);
}
body.rd-theme-sepia .rd-nar-wave-bar { fill: rgba(74, 58, 34, .2); }

/* ---- Voice-style selector (Oryx only) ---- */
.rd-nar-styles {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    flex-wrap: wrap;
}
.rd-nar-styles-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: rgba(232, 232, 240, .5);
    margin-right: 2px;
}
.rd-nar-style {
    background: rgba(255, 255, 255, .04);
    border: 1px solid rgba(255, 255, 255, .08);
    color: rgba(232, 232, 240, .75);
    padding: 5px 10px;
    border-radius: var(--r-pill);
    font-size: 11.5px;
    font-weight: 500;
    cursor: pointer;
    transition: background .15s, border-color .15s, color .15s;
}
.rd-nar-style:hover { background: rgba(255, 255, 255, .08); color: #e8e8f0; }
.rd-nar-style[aria-pressed="true"] {
    background: rgba(139, 92, 246, .18);
    border-color: rgba(139, 92, 246, .5);
    color: #fff;
}
body.rd-theme-sepia .rd-nar-styles-label { color: rgba(74, 58, 34, .55); }
body.rd-theme-sepia .rd-nar-style {
    background: rgba(74, 58, 34, .05);
    border-color: rgba(74, 58, 34, .14);
    color: rgba(74, 58, 34, .7);
}
body.rd-theme-sepia .rd-nar-style:hover { background: rgba(74, 58, 34, .1); color: #2b200f; }
body.rd-theme-sepia .rd-nar-style[aria-pressed="true"] {
    background: rgba(139, 92, 246, .14);
    border-color: rgba(139, 92, 246, .4);
    color: #2b200f;
}
body.rd-theme-light .rd-nar-styles-label { color: rgba(31, 33, 50, .5); }
body.rd-theme-light .rd-nar-style {
    background: rgba(31, 33, 50, .04);
    border-color: rgba(31, 33, 50, .08);
    color: rgba(31, 33, 50, .7);
}
body.rd-theme-light .rd-nar-style:hover { background: rgba(31, 33, 50, .08); color: #1d1f35; }
body.rd-theme-light .rd-nar-style[aria-pressed="true"] {
    background: rgba(124, 58, 237, .1);
    border-color: rgba(124, 58, 237, .4);
    color: #1d1f35;
}

/* ---- Light theme ---- */
body.rd-theme-light .rd-nar {
    background: color-mix(in srgb, #ffffff 94%, transparent);
    border-color: rgba(31, 33, 50, .08);
    box-shadow: 0 6px 24px rgba(31, 33, 50, .08), 0 1px 2px rgba(31, 33, 50, .04);
}
body.rd-theme-light .rd-nar-title strong { color: #1d1f35; }
body.rd-theme-light .rd-nar-title small  { color: rgba(31, 33, 50, .55); }
body.rd-theme-light .rd-nar-seek-track { background: rgba(31, 33, 50, .08); }
body.rd-theme-light .rd-nar-seek-handle { background: #1d1f35; }
body.rd-theme-light .rd-nar-btn { color: rgba(31, 33, 50, .6); }
body.rd-theme-light .rd-nar-btn:hover { background: rgba(31, 33, 50, .06); color: #1d1f35; }
body.rd-theme-light .rd-nar-speed {
    background: rgba(31, 33, 50, .04);
    border-color: rgba(31, 33, 50, .08);
    color: #1d1f35;
}
body.rd-theme-light .rd-nar-speed:hover { background: rgba(31, 33, 50, .08); }
body.rd-theme-light .rd-nar-panel { border-top-color: rgba(31, 33, 50, .06); }
body.rd-theme-light .rd-nar-times { color: rgba(31, 33, 50, .5); }
body.rd-theme-light .rd-nar-src {
    background: rgba(31, 33, 50, .03);
    border-color: rgba(31, 33, 50, .08);
    color: #1d1f35;
}
body.rd-theme-light .rd-nar-src small { color: rgba(31, 33, 50, .55); }
body.rd-theme-light .rd-nar-src[aria-pressed="true"] {
    background: rgba(124, 58, 237, .08);
    border-color: rgba(124, 58, 237, .4);
}
body.rd-theme-light .rd-nar-wave-bar { fill: rgba(31, 33, 50, .15); }

/* ---- Responsive ---- */
@media (max-width: 720px) {
    .rd-nar { bottom: 14px; width: calc(100% - 20px); }
    .rd-nar-bar { grid-template-columns: auto 1fr auto; gap: 10px; padding: 8px 10px; }
    .rd-nar-left { min-width: 0; }
    .rd-nar-cover { width: 32px; height: 32px; }
    .rd-nar-title { display: none; }
    .rd-nar-center { min-width: 0; max-width: unset; }
    .rd-nar-play { width: 34px; height: 34px; }
    .rd-nar-speed { padding: 4px 7px; font-size: 11px; }
    .rd-nar-btn { width: 28px; height: 28px; }
    .rd-nar[data-expanded="1"] .rd-nar-title { display: flex; flex-basis: 100%; }
    .rd-nar-sources { flex-direction: column; }
}

/* When bottom-nav is present (pages that include bottom-nav.php) the
   player needs to clear it. Reader never shows bottom-nav, but this
   keeps the bar safe if the reader ever nests inside one. */
body.has-bottom-nav .rd-nar { bottom: 82px; }
@media (max-width: 720px) {
    body.has-bottom-nav .rd-nar { bottom: 76px; }
}
