/* ============================================================
   reading.css — High-contrast liquid glass reading surface
   Article typography, table of contents, code blocks & print
   ============================================================ */

/* --- Reading progress indicator (fixed at page top) --- */
.reading-progress-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 3px;
    z-index: 1000;
    background: transparent;
    pointer-events: none;
}

.reading-progress-fill {
    height: 100%;
    width: 0%;
    background: var(--sky-glow, var(--accent));
    box-shadow: 0 0 8px var(--sky-glow, var(--accent));
    transition: width 0.1s cubic-bezier(0.16, 1, 0.3, 1);
}

@media (prefers-reduced-motion: reduce) {
    .reading-progress-fill {
        transition: none;
    }
}

/* --- Layout --- */
.reading-wrapper {
    width: 100%;
    max-width: 1240px;
    margin: 0 auto;
    padding: 96px 24px 80px;
}

.reading-top-nav {
    margin-bottom: 24px;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.92rem;
    font-weight: 500;
    color: var(--text-secondary);
    transition: color 0.2s ease, transform 0.2s ease;
}

.back-link:hover {
    color: var(--accent);
    transform: translateX(-3px);
}

.reading-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 260px;
    gap: 40px;
    align-items: start;
}

.reading-shell {
    max-width: 880px;
    width: 100%;
}

@media (max-width: 1100px) {
    .reading-layout {
        grid-template-columns: minmax(0, 1fr);
        justify-content: center;
    }
    .reading-shell {
        max-width: 100%;
    }
    .reading-toc-rail {
        display: none !important;
    }
}

/* --- Reading Shell (High contrast glass surface) --- */
.reading-shell {
    background: rgba(255, 255, 255, 0.92) !important;
    backdrop-filter: blur(24px) saturate(190%);
    -webkit-backdrop-filter: blur(24px) saturate(190%);
    border: 1px solid var(--glass-border-strong);
    border-radius: var(--radius-lg);
    box-shadow: 0 24px 64px -16px rgba(15, 23, 42, 0.12), var(--liquid-inner-glow);
    padding: clamp(28px, 5vw, 56px);
    overflow: hidden;
}

[data-theme="dark"] .reading-shell {
    background: rgba(16, 20, 30, 0.84) !important;
    box-shadow: 0 28px 72px -16px rgba(0, 0, 0, 0.55), var(--liquid-inner-glow);
}

/* Cover Image */
.reading-cover-wrap {
    margin: calc(clamp(28px, 5vw, 56px) * -1) calc(clamp(28px, 5vw, 56px) * -1) 32px;
    overflow: hidden;
    max-height: 420px;
}

.reading-cover {
    width: 100%;
    height: 100%;
    max-height: 420px;
    object-fit: cover;
    display: block;
}

/* Header */
.reading-header {
    margin-bottom: 36px;
    border-bottom: 1px solid var(--divider);
    padding-bottom: 28px;
}

.reading-title {
    font-size: clamp(2rem, 4vw, 2.75rem);
    font-weight: 700;
    line-height: 1.25;
    letter-spacing: -0.03em;
    color: var(--text-primary);
    margin-bottom: 16px;
    text-wrap: balance;
}

.reading-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    font-size: 0.92rem;
    color: var(--text-tertiary);
    margin-bottom: 16px;
    font-variant-numeric: tabular-nums;
}

.reading-meta .meta-separator {
    opacity: 0.5;
}

.reading-time-badge {
    color: var(--accent);
    font-weight: 600;
}

.reading-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

/* --- Table of Contents (Desktop Sticky Rail) --- */
.reading-toc-rail {
    position: sticky;
    top: 96px;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
    scrollbar-width: thin;
}

.toc-sticky-box {
    padding: 20px 22px;
    border-radius: var(--radius-md);
    background: var(--liquid-bg);
}

.toc-rail-title {
    font-size: 0.82rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-tertiary);
    margin-bottom: 14px;
}

.toc-list,
.toc-sublist {
    list-style: none;
    padding-left: 0;
    margin: 0;
}

.toc-sublist {
    padding-left: 14px;
    margin-top: 6px;
}

.toc-item {
    margin-bottom: 8px;
    font-size: 0.88rem;
    line-height: 1.4;
}

.toc-item a {
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.2s ease;
    display: block;
    border-left: 2px solid transparent;
    padding-left: 8px;
}

.toc-item a:hover {
    color: var(--accent);
    border-left-color: var(--accent-dim);
}

.toc-item a.active {
    color: var(--accent);
    font-weight: 600;
    border-left-color: var(--sky-glow, var(--accent));
}

/* Mobile Collapsible TOC */
.toc-mobile-card {
    margin-bottom: 32px;
    padding: 16px 20px;
    border-radius: var(--radius-md);
    background: var(--liquid-bg);
}

.toc-mobile-summary {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
    cursor: pointer;
    user-select: none;
}

.toc-mobile-nav {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--divider);
}

/* --- Reading Body Typography --- */
.reading-body {
    font-size: 1.125rem;
    line-height: 1.78;
    color: var(--text-primary);
    letter-spacing: 0.008em;
}

.reading-body > * + * {
    margin-top: 1.6em;
}

.reading-body h1,
.reading-body h2,
.reading-body h3,
.reading-body h4,
.reading-body h5,
.reading-body h6 {
    color: var(--text-primary);
    scroll-margin-top: 88px;
    position: relative;
    font-weight: 700;
}

.reading-body h1 { font-size: 2.1rem; margin-top: 2em; }
.reading-body h2 { font-size: 1.75rem; margin-top: 1.8em; border-bottom: 1px solid var(--divider); padding-bottom: 0.3em; }
.reading-body h3 { font-size: 1.35rem; margin-top: 1.6em; }
.reading-body h4 { font-size: 1.15rem; margin-top: 1.4em; }

.heading-anchor-link {
    opacity: 0;
    margin-left: 8px;
    color: var(--accent);
    text-decoration: none;
    font-weight: 400;
    transition: opacity 0.2s ease;
}

.reading-body h1:hover .heading-anchor-link,
.reading-body h2:hover .heading-anchor-link,
.reading-body h3:hover .heading-anchor-link,
.reading-body h4:hover .heading-anchor-link,
.heading-anchor-link:focus {
    opacity: 1;
}

.reading-body p {
    color: var(--text-primary);
    margin: 0;
}

.reading-body a {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 3px;
    transition: color 0.2s ease;
}

.reading-body a:hover {
    color: var(--accent-hover);
}

.reading-body blockquote {
    padding: 16px 24px;
    margin: 1.8em 0;
    border-left: 4px solid var(--sky-glow, var(--accent));
    background: var(--liquid-bg);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    font-style: italic;
    color: var(--text-secondary);
}

.reading-body ul,
.reading-body ol {
    padding-left: 1.6em;
    margin: 1.2em 0;
}

.reading-body li {
    margin-bottom: 0.5em;
}

.reading-body li::marker {
    color: var(--accent);
}

.reading-body hr {
    border: none;
    height: 1px;
    background: var(--divider);
    margin: 2.5em 0;
}

/* --- Code Blocks --- */
.code-block {
    position: relative;
    margin: 1.8em 0;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: #0d1117;
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
}

.code-block-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.04);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 0.78rem;
    font-weight: 600;
    color: #8b949e;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.code-copy-btn {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: var(--radius-sm);
    color: #c9d1d9;
    font-size: 0.75rem;
    padding: 3px 10px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.code-copy-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border-color: rgba(255, 255, 255, 0.3);
}

.code-block pre {
    margin: 0;
    padding: 16px 20px;
    overflow-x: auto;
    font-family: var(--font-mono, 'Maple Mono', monospace);
    font-size: 0.92rem;
    line-height: 1.6;
    color: #e6edf3;
    outline: none;
    font-feature-settings: "liga" 1, "calt" 1;
}

.code-block pre:focus-visible {
    outline: 2px solid var(--accent);
}

/* Inline Code */
.reading-body :not(pre) > code {
    background: var(--liquid-pill-bg, rgba(120, 130, 150, 0.15));
    color: var(--accent);
    padding: 2px 7px;
    border-radius: 6px;
    font-size: 0.88em;
    font-family: var(--font-mono, 'Maple Mono', monospace);
    border: 1px solid var(--glass-border);
    font-feature-settings: "liga" 1, "calt" 1;
}

/* --- Tables --- */
.table-wrapper {
    overflow-x: auto;
    margin: 2em 0;
    border-radius: var(--radius-md);
    border: 1px solid var(--glass-border-strong, rgba(255, 255, 255, 0.18));
    background: var(--liquid-bg, rgba(255, 255, 255, 0.5));
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.05);
    scrollbar-width: thin;
}

.table-wrapper::-webkit-scrollbar {
    height: 6px;
}

.table-wrapper::-webkit-scrollbar-track {
    background: transparent;
}

.table-wrapper::-webkit-scrollbar-thumb {
    background: var(--divider, rgba(120, 130, 150, 0.3));
    border-radius: 4px;
}

.table-wrapper:focus-visible {
    outline: 2px solid var(--accent);
}

.reading-body table {
    width: 100%;
    min-width: 780px; /* Prevents columns from wrapping into vertical characters */
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.92rem;
    line-height: 1.55;
    text-align: left;
}

.reading-body th {
    background: var(--glass-surface-strong, rgba(240, 244, 250, 0.95));
    font-weight: 600;
    color: var(--text-primary);
    padding: 12px 16px;
    border-bottom: 2px solid var(--glass-border-strong, rgba(120, 130, 150, 0.25));
    white-space: nowrap;
    letter-spacing: 0.02em;
}

[data-theme="dark"] .reading-body th {
    background: rgba(30, 41, 59, 0.88);
}

.reading-body td {
    padding: 10px 16px;
    border-bottom: 1px solid var(--divider, rgba(120, 130, 150, 0.12));
    color: var(--text-secondary);
    vertical-align: middle;
}

/* Numeric & metrics columns: tabular numbers formatted in Maple Mono */
.reading-body td:nth-child(n+2):nth-child(-n+7) {
    font-variant-numeric: tabular-nums;
    font-family: var(--font-mono, 'Maple Mono', monospace);
    font-size: 0.88rem;
    white-space: nowrap;
}

.reading-body tr:last-child td {
    border-bottom: none;
}

/* Subtle Zebra Striping */
.reading-body tbody tr:nth-child(even) {
    background: rgba(120, 140, 180, 0.035);
}

[data-theme="dark"] .reading-body tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.02);
}

/* Hover effect */
.reading-body tbody tr:hover {
    background: rgba(56, 189, 248, 0.06);
    transition: background 0.15s ease;
}

/* Math container alignment */
.katex-display {
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0.8em 0;
    margin: 1.2em 0 !important;
    scrollbar-width: thin;
}

.katex {
    font-size: 1.05em;
    text-rendering: auto;
}

/* --- Images --- */
.reading-body img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-md);
    cursor: zoom-in;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    display: block;
    margin: 1.8em auto;
}

.reading-body img:hover {
    transform: scale(1.01);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.15);
}

/* --- Footnotes --- */
.reading-body .footnote {
    margin-top: 3em;
    padding-top: 1.5em;
    border-top: 1px solid var(--divider);
    font-size: 0.90rem;
    color: var(--text-secondary);
}

.reading-body .footnote ol {
    padding-left: 1.4em;
}

.reading-body .footnote-backref {
    text-decoration: none;
    margin-left: 6px;
    color: var(--accent);
}

/* --- Feedback Bar (Reactions & Sharing) --- */
.reading-feedback-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-top: 48px;
    padding-top: 24px;
    border-top: 1px solid var(--divider);
}

.reaction-btn-group {
    display: flex;
    align-items: center;
    gap: 12px;
}

.reaction-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 18px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: 9999px;
    transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.reaction-btn .reaction-icon {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), fill 0.2s ease;
}

.reaction-btn.reacted {
    color: #f43f5e;
    border-color: rgba(244, 63, 94, 0.4);
    background: rgba(244, 63, 94, 0.1);
}

.reaction-btn.reacted .reaction-icon {
    fill: #f43f5e;
    transform: scale(1.15);
    animation: heart-pop 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes heart-pop {
    0% { transform: scale(1); }
    50% { transform: scale(1.35); }
    100% { transform: scale(1.15); }
}

.reaction-count {
    font-variant-numeric: tabular-nums;
}

/* --- Comments Section --- */
.reading-comments {
    margin-top: 48px;
    padding-top: 32px;
    border-top: 1px solid var(--divider);
}

.comments-title {
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.015em;
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.comments-count-badge {
    font-size: 0.85rem;
    padding: 2px 10px;
    border-radius: 9999px;
    background: var(--glass-surface-subtle);
    border: 1px solid var(--glass-border);
    color: var(--text-secondary);
}

.comments-list {
    display: flex;
    flex-direction: column;
    gap: 18px;
    margin-bottom: 36px;
}

.comment-card {
    padding: 18px 22px;
    border-radius: var(--radius-md);
    background: var(--glass-surface-subtle);
    border: 1px solid var(--glass-border);
    transition: border-color 0.2s ease;
}

.comment-card.is-reply {
    margin-left: 28px;
    border-left: 3px solid var(--accent);
}

.comment-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.comment-author-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.comment-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--glass-surface-strong);
    border: 1px solid var(--glass-border);
}

.comment-author-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.comment-admin-badge {
    font-size: 0.72rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    background: var(--accent);
    color: #fff;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.comment-date {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.comment-content {
    font-size: 0.94rem;
    line-height: 1.65;
    color: var(--text-primary);
    word-break: break-word;
}

.comment-content p:last-child {
    margin-bottom: 0;
}

.comment-actions {
    margin-top: 8px;
    display: flex;
    justify-content: flex-end;
}

.comment-reply-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: color 0.15s ease, background 0.15s ease;
}

.comment-reply-btn:hover {
    color: var(--accent);
    background: var(--glass-surface-subtle);
}

/* Comment Form */
.comment-form-panel {
    padding: 24px;
    border-radius: var(--radius-md);
    background: var(--glass-surface-strong);
    border: 1px solid var(--glass-border);
}

.comment-form-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 16px;
}

.comment-reply-indicator {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    margin-bottom: 12px;
    border-radius: 6px;
    background: rgba(96, 165, 250, 0.12);
    border: 1px solid rgba(96, 165, 250, 0.25);
    font-size: 0.85rem;
    color: var(--accent);
}

.comment-reply-cancel {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.8rem;
}

.comment-form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin-bottom: 14px;
}

@media (max-width: 600px) {
    .comment-form-grid {
        grid-template-columns: 1fr;
    }
}

.comment-input-wrap label {
    display: block;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.comment-input-wrap .glass-input {
    width: 100%;
}

.comment-textarea-wrap {
    margin-bottom: 14px;
}

.comment-textarea-wrap label {
    display: block;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.comment-textarea {
    width: 100%;
    min-height: 100px;
    resize: vertical;
    font-family: inherit;
    font-size: 0.92rem;
}

.comment-form-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.comment-form-note {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.comment-form-msg {
    margin-top: 10px;
    font-size: 0.85rem;
    padding: 8px 12px;
    border-radius: 6px;
    display: none;
}

.comment-form-msg.error {
    display: block;
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid rgba(239, 68, 68, 0.25);
    color: #ef4444;
}

.comment-form-msg.success {
    display: block;
    background: rgba(16, 185, 129, 0.12);
    border: 1px solid rgba(16, 185, 129, 0.25);
    color: #10b981;
}

/* --- Print Styles --- */
@media print {
    body {
        background: #fff !important;
        color: #000 !important;
    }
    body::before,
    body::after,
    .navbar,
    .footer,
    .reading-progress-container,
    .reading-top-nav,
    .reading-toc-rail,
    .toc-mobile-card,
    .code-copy-btn {
        display: none !important;
    }
    .reading-wrapper {
        padding: 0 !important;
        max-width: 100% !important;
    }
    .reading-layout {
        display: block !important;
    }
    .reading-shell {
        box-shadow: none !important;
        border: none !important;
        padding: 0 !important;
        background: transparent !important;
    }
    .code-block {
        background: #f6f8fa !important;
        border: 1px solid #d0d7de !important;
        color: #000 !important;
        page-break-inside: avoid;
    }
    .code-block pre {
        color: #000 !important;
    }
}
