/* Shared reader layout — normal reader (Views/Reader/Index) and exclusive reader (Views/Explore/ExclusiveReader).
   Reading preferences are CSS variables on <html>, set by wwwroot/js/reader-shell.js before first paint:
     --rd-fs  font size     --rd-lh  line height     --rd-ff  font family     --rd-w  column width
   html.rd-paper = "Giấy" (sepia) reading surface; dark mode is the site-wide .dark class. */

:root {
    --rd-fs: 18px;
    --rd-lh: 1.85;
    --rd-ff: Nunito, ui-sans-serif, system-ui, sans-serif;
    --rd-w: 40rem;
    --rd-text: #292524;
    --rd-muted: #78716c;
}
.dark { --rd-text: #e7e5e4; --rd-muted: #a8a29e; }

/* The site nav scrolls away on reader pages; the reader top bar is the sticky one */
html.rd-page nav[aria-label="Điều hướng chính"] { position: relative; }

/* ── Paper (sepia) surface ── */
html.rd-paper:not(.dark) { --rd-text: #3b2f22; --rd-muted: #7a6650; }
html.rd-paper:not(.dark) body { background-color: #f4ecdb; }
html.rd-paper:not(.dark) #excl-backdrop { display: none; }
html.rd-paper:not(.dark) #rd-topbar { background-color: rgb(244 236 219 / 0.88); }

/* ── Reading column ── */
.rd-col { width: 100%; max-width: var(--rd-w); margin-inline: auto; }

/* ── Story text ── */
#reader-content .paragraph-content,
#ir-content {
    font-size: var(--rd-fs);
    line-height: var(--rd-lh);
    font-family: var(--rd-ff);
    color: var(--rd-text);
    overflow-wrap: break-word;
}
#reader-content .paragraph-content > * + * { margin-top: 1em; }
#reader-content .paragraph-content p { margin-bottom: 0; }
.rd-para + .rd-para { margin-top: 1em; }
.rd-intro { font-family: var(--rd-ff); color: var(--rd-muted); }

/* Paragraph currently read aloud */
.tts-reading { background-color: rgba(255, 145, 0, 0.08); box-shadow: 0 0 0 0.375rem rgba(255, 145, 0, 0.08); border-radius: 0.25rem; transition: background-color 0.3s ease, box-shadow 0.3s ease; }
.dark .tts-reading { background-color: rgba(255, 145, 0, 0.12); box-shadow: 0 0 0 0.375rem rgba(255, 145, 0, 0.12); }

/* ── Paragraph actions (love / comment) ──
   A "paragraph" is often a whole chapter (authors paste the chapter as one block), so the actions are sticky:
   they follow the viewport while their block is on screen instead of sitting at its top or bottom.
   Wide screens with a mouse: sticky in the right gutter, faint until the block is hovered / focused.
   Touch & narrow screens: hidden until the text is tapped (reader-shell.js toggles .is-active), then a
   floating pill sticks to the bottom of the screen. */
.rd-para { position: relative; }
.rd-para-actions-inner { display: flex; align-items: center; gap: 0.25rem; }
.rd-para-btn {
    display: inline-flex; align-items: center; gap: 0.25rem;
    min-width: 2.25rem; min-height: 2.25rem; padding: 0 0.5rem; border-radius: 9999px;
    font-size: 0.75rem; font-weight: 600; font-family: ui-sans-serif, system-ui, sans-serif;
    color: var(--rd-muted); transition: color 0.15s, background-color 0.15s;
}
.rd-para-btn:hover { background-color: rgb(120 113 108 / 0.1); }
.rd-para-btn[data-kind="love"]:hover { color: #f43f5e; }
.rd-para-btn[data-kind="comment"]:hover { color: var(--color-tno); }
.rd-para-btn svg { width: 1rem; height: 1rem; flex-shrink: 0; }

/* Default: tap mode */
.rd-para-actions {
    display: none; justify-content: center; pointer-events: none;
    position: sticky; z-index: 30; margin-top: 0.75rem;
    bottom: calc(1rem + var(--reader-nav-h, 0px) + env(safe-area-inset-bottom, 0px));
}
.rd-para.is-active .rd-para-actions { display: flex; }
html.reader-dock-is-open .rd-para-actions { bottom: calc(0.5rem + var(--reader-dock-h, 0px) + var(--reader-nav-h, 0px)); }
.rd-para-actions .rd-para-actions-inner {
    pointer-events: auto; padding: 0.25rem; border-radius: 9999px;
    background: rgb(255 255 255 / 0.95); box-shadow: 0 6px 20px rgb(0 0 0 / 0.12); outline: 1px solid rgb(231 229 228);
    -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}
.dark .rd-para-actions .rd-para-actions-inner { background: rgb(28 25 23 / 0.95); outline-color: rgb(68 64 60 / 0.6); }

/* Wide screens with a mouse: sticky column in the right gutter */
@media (hover: hover) and (min-width: 1024px) {
    .rd-para-actions,
    .rd-para.is-active .rd-para-actions {
        display: block; position: absolute; top: 0; bottom: 0; left: 100%; margin: 0 0 0 0.5rem;
        pointer-events: none;
    }
    .rd-para-actions .rd-para-actions-inner {
        position: sticky; top: 5rem; flex-direction: column; gap: 0;
        padding: 0; background: none; box-shadow: none; outline: none; -webkit-backdrop-filter: none; backdrop-filter: none;
        opacity: 0.35; transition: opacity 0.2s;
    }
    .dark .rd-para-actions .rd-para-actions-inner { background: none; }
    .rd-para-btn { flex-direction: column; gap: 0; min-height: 0; padding: 0.25rem; font-size: 0.6875rem; }
    .rd-para:hover .rd-para-actions-inner,
    .rd-para:focus-within .rd-para-actions-inner { opacity: 1; }
}

/* ── Top bar ── */
#rd-topbar {
    position: sticky; top: 0; z-index: 45;
    background-color: rgb(255 251 245 / 0.85);
    -webkit-backdrop-filter: blur(16px) saturate(160%);
    backdrop-filter: blur(16px) saturate(160%);
    border-bottom: 1px solid rgb(120 113 108 / 0.15);
    transition: transform 0.3s ease;
}
.dark #rd-topbar { background-color: rgb(12 10 9 / 0.85); border-bottom-color: rgb(68 64 60 / 0.6); }
#rd-topbar.is-hidden { transform: translateY(-100%); }
.rd-icon-btn {
    position: relative; display: inline-flex; align-items: center; justify-content: center;
    width: 2.25rem; height: 2.25rem; flex-shrink: 0; border-radius: 9999px;
    color: var(--rd-muted); transition: color 0.15s, background-color 0.15s;
}
.rd-icon-btn:hover { color: var(--color-tno); background-color: rgb(120 113 108 / 0.1); }
.rd-icon-btn:focus-visible { outline: 2px solid var(--color-tno); outline-offset: 2px; }
.rd-icon-btn svg { width: 1.25rem; height: 1.25rem; }
.rd-count {
    position: absolute; top: 0.0625rem; right: 0.0625rem; min-width: 1rem; height: 1rem; padding: 0 0.25rem;
    border-radius: 9999px; background: var(--color-tno); color: #1c1917;
    font-size: 0.625rem; font-weight: 700; line-height: 1rem; text-align: center;
}

/* ── Slide-in panels (chapter list, exclusive comments) ── */
.rd-panel { transition: transform 0.35s cubic-bezier(.4, 0, .2, 1); }
.rd-panel[data-side="left"]:not(.is-open) { transform: translateX(-100%); }
.rd-panel[data-side="right"]:not(.is-open) { transform: translateX(100%); }
.rd-panel:not(.is-open) { visibility: hidden; transition: transform 0.35s cubic-bezier(.4, 0, .2, 1), visibility 0s linear 0.35s; }
.rd-backdrop { opacity: 0; pointer-events: none; transition: opacity 0.3s; }
.rd-backdrop.is-open { opacity: 1; pointer-events: auto; }

/* ── Settings option buttons ── */
.rd-opt {
    flex: 1; border-radius: 0.75rem; padding: 0.5rem 0.25rem;
    font-size: 0.8125rem; font-weight: 600; color: #57534e;
    box-shadow: inset 0 0 0 1px rgb(214 211 209); transition: box-shadow 0.15s, color 0.15s, background-color 0.15s;
}
.dark .rd-opt { color: #d6d3d1; box-shadow: inset 0 0 0 1px rgb(68 64 60); }
.rd-opt:hover { color: var(--color-tno); }
.rd-opt[aria-pressed="true"] { color: var(--color-tno); box-shadow: inset 0 0 0 2px var(--color-tno); background-color: rgb(255 145 0 / 0.06); }

@media (prefers-reduced-motion: reduce) {
    #rd-topbar, .rd-panel, .rd-backdrop, .rd-para-actions-inner { transition: none; }
}
@media print {
    #rd-topbar, .rd-para-actions { display: none; }
}

/* Selection stays enabled for select-to-speak / dictionary tools (copying is blocked in the views' JS) */
#reader-content { -webkit-user-select: text; user-select: text; }
