/* ============================================
   ARTICLE ENHANCEMENTS
   Leo G. Ferrara - leogferrara.com
   ============================================ */

:root {
    --ink: #1a1918;
    --paper: #f6f5f1;
    --graphite: #6e6d6a;
    --accent: #c9a227;
    --rule: rgba(26,25,24,0.1);
}

[data-theme="dark"] {
    --ink: #f6f5f1;
    --paper: #0a0a09;
    --graphite: #9e9d9a;
    --rule: rgba(246,245,241,0.1);
}

/* ============================================
   1. READING PROGRESS BAR
   ============================================ */
.reading-progress {
    position: fixed;
    top: 0;
    left: 0;
    width: 0;
    height: 2px;
    background: var(--accent);
    z-index: 9999;
    transition: width 0.1s linear;
}

/* ============================================
   2. READING TIME & META ENHANCEMENTS
   ============================================ */
.article-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
    font-size: 0.7rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--graphite);
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--rule);
}

.reading-time {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.reading-time::before {
    content: "◔";
    font-size: 0.9em;
}

/* ============================================
   3. TABLE OF CONTENTS (Floating)
   ============================================ */
.toc-container {
    position: fixed;
    left: 2rem;
    top: 50%;
    transform: translateY(-50%);
    max-width: 200px;
    z-index: 100;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.toc-container.visible {
    opacity: 1;
}

.toc-title {
    font-size: 0.6rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--graphite);
    margin-bottom: 1rem;
}

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

.toc-list li {
    margin-bottom: 0.5rem;
}

.toc-list a {
    font-size: 0.75rem;
    color: var(--graphite);
    text-decoration: none;
    transition: color 0.2s, padding-left 0.2s;
    display: block;
    padding-left: 0;
    line-height: 1.4;
}

.toc-list a:hover,
.toc-list a.active {
    color: var(--ink);
    padding-left: 0.5rem;
}

.toc-list a.active::before {
    content: "—";
    margin-right: 0.5rem;
    color: var(--accent);
}

/* Hide TOC on smaller screens */
@media (max-width: 1400px) {
    .toc-container {
        display: none;
    }
}

/* ============================================
   4. SHARE BUTTONS
   ============================================ */
.share-buttons {
    display: flex;
    gap: 1rem;
    margin-top: 3rem;
    padding-top: 2rem;
    border-top: 1px solid var(--rule);
}

.share-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1rem;
    font-size: 0.7rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    text-decoration: none;
    color: var(--graphite);
    border: 1px solid var(--rule);
    background: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.share-btn:hover {
    color: var(--ink);
    border-color: var(--ink);
}

.share-btn.copied {
    color: var(--accent);
    border-color: var(--accent);
}

.share-btn svg {
    width: 14px;
    height: 14px;
    fill: currentColor;
}

/* ============================================
   5. NEWSLETTER SIGNUP
   ============================================ */
.newsletter-box {
    background: var(--paper);
    border: 1px solid var(--rule);
    padding: 2.5rem;
    margin: 4rem 0;
    text-align: center;
}

[data-theme="dark"] .newsletter-box {
    background: rgba(255,255,255,0.02);
}

.newsletter-title {
    font-family: var(--serif, Georgia, serif);
    font-size: 1.3rem;
    font-weight: 400;
    margin-bottom: 0.5rem;
}

.newsletter-desc {
    font-size: 0.85rem;
    color: var(--graphite);
    margin-bottom: 1.5rem;
    max-width: 400px;
    margin-left: auto;
    margin-right: auto;
}

.newsletter-form {
    display: flex;
    gap: 0.5rem;
    max-width: 400px;
    margin: 0 auto;
}

.newsletter-input {
    flex: 1;
    padding: 0.8rem 1rem;
    font-size: 0.85rem;
    border: 1px solid var(--rule);
    background: var(--paper);
    color: var(--ink);
    font-family: inherit;
}

.newsletter-input:focus {
    outline: none;
    border-color: var(--accent);
}

.newsletter-submit {
    padding: 0.8rem 1.5rem;
    font-size: 0.7rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    border: 1px solid var(--ink);
    background: var(--ink);
    color: var(--paper);
    cursor: pointer;
    transition: all 0.2s ease;
}

.newsletter-submit:hover {
    background: transparent;
    color: var(--ink);
}

@media (max-width: 500px) {
    .newsletter-form {
        flex-direction: column;
    }
}

/* ============================================
   6. RELATED ARTICLES
   ============================================ */
.related-articles {
    margin-top: 4rem;
    padding-top: 3rem;
    border-top: 1px solid var(--rule);
}

.related-title {
    font-size: 0.65rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--graphite);
    margin-bottom: 1.5rem;
}

.related-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 2rem;
}

.related-card {
    text-decoration: none;
    color: inherit;
    display: block;
    transition: transform 0.2s ease;
}

.related-card:hover {
    transform: translateY(-2px);
}

.related-card-image {
    width: 100%;
    height: 140px;
    object-fit: cover;
    margin-bottom: 1rem;
    filter: grayscale(100%);
    transition: filter 0.3s ease;
}

.related-card:hover .related-card-image {
    filter: grayscale(0%);
}

.related-card-title {
    font-family: var(--serif, Georgia, serif);
    font-size: 1rem;
    font-weight: 400;
    margin-bottom: 0.3rem;
    line-height: 1.3;
}

.related-card-meta {
    font-size: 0.65rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--graphite);
}

/* ============================================
   7. BACK TO TOP BUTTON
   ============================================ */
.back-to-top {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--paper);
    border: 1px solid var(--rule);
    color: var(--ink);
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 100;
}

.back-to-top.visible {
    opacity: 1;
    visibility: visible;
}

.back-to-top:hover {
    background: var(--ink);
    color: var(--paper);
    border-color: var(--ink);
}

.back-to-top svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

/* ============================================
   8. PRINT STYLES
   ============================================ */
@media print {
    .reading-progress,
    .toc-container,
    .share-buttons,
    .newsletter-box,
    .back-to-top,
    nav,
    .related-articles {
        display: none !important;
    }
    
    body {
        font-size: 12pt;
        line-height: 1.5;
        color: #000;
        background: #fff;
    }
    
    article {
        max-width: 100%;
        margin: 0;
        padding: 0;
    }
    
    h1 {
        font-size: 24pt;
        page-break-after: avoid;
    }
    
    h2 {
        font-size: 18pt;
        page-break-after: avoid;
    }
    
    p {
        orphans: 3;
        widows: 3;
    }
    
    a {
        text-decoration: none;
        color: #000;
    }
    
    a[href^="http"]:after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        color: #666;
    }
    
    blockquote {
        border-left: 2pt solid #ccc;
        margin-left: 0;
        padding-left: 1em;
    }
}

/* ============================================
   9. CODE SYNTAX HIGHLIGHTING (Basic)
   ============================================ */
pre {
    background: rgba(0,0,0,0.03);
    padding: 1.5rem;
    overflow-x: auto;
    font-size: 0.85rem;
    line-height: 1.5;
    border-radius: 2px;
}

[data-theme="dark"] pre {
    background: rgba(255,255,255,0.05);
}

code {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.9em;
}

:not(pre) > code {
    background: rgba(0,0,0,0.04);
    padding: 0.15em 0.4em;
    border-radius: 2px;
}

[data-theme="dark"] :not(pre) > code {
    background: rgba(255,255,255,0.08);
}

/* Syntax colors */
.token.comment { color: var(--graphite); font-style: italic; }
.token.keyword { color: #0066cc; }
.token.string { color: #008800; }
.token.number { color: #cc6600; }
.token.function { color: #6600cc; }

[data-theme="dark"] .token.keyword { color: #6699ff; }
[data-theme="dark"] .token.string { color: #66cc66; }
[data-theme="dark"] .token.number { color: #ffaa66; }
[data-theme="dark"] .token.function { color: #cc99ff; }

/* ============================================
   10. SCROLL DEPTH INDICATOR
   ============================================ */
.scroll-depth {
    position: fixed;
    bottom: 2rem;
    left: 2rem;
    padding: 0.5rem 0.8rem;
    font-size: 0.65rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    background: var(--paper);
    border: 1px solid var(--rule);
    color: var(--graphite);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 50;
}

.scroll-depth.visible {
    opacity: 1;
    visibility: visible;
}

@media (max-width: 768px) {
    .scroll-depth {
        display: none;
    }
}

/* ============================================
   11. FOOTNOTE POPUP
   ============================================ */
.footnote-popup {
    position: fixed;
    max-width: 300px;
    padding: 1rem;
    font-size: 0.8rem;
    line-height: 1.5;
    background: var(--paper);
    border: 1px solid var(--rule);
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
    color: var(--graphite);
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    z-index: 1000;
    pointer-events: none;
}

.footnote-popup.visible {
    opacity: 1;
    visibility: visible;
}

[data-theme="dark"] .footnote-popup {
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

/* ============================================
   12. LIGHTBOX
   ============================================ */
.lightbox {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.95);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 9999;
    cursor: zoom-out;
}

.lightbox.visible {
    opacity: 1;
    visibility: visible;
}

.lightbox-close {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: white;
    font-size: 2rem;
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.lightbox-close:hover {
    opacity: 1;
}

.lightbox-img {
    max-width: 90vw;
    max-height: 80vh;
    object-fit: contain;
}

.lightbox-caption {
    margin-top: 1rem;
    color: rgba(255,255,255,0.7);
    font-size: 0.85rem;
    text-align: center;
}

/* ============================================
   13. COPY CODE BUTTON
   ============================================ */
.copy-code-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    padding: 0.3rem 0.6rem;
    font-size: 0.6rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    background: var(--paper);
    border: 1px solid var(--rule);
    color: var(--graphite);
    cursor: pointer;
    opacity: 0;
    transition: all 0.2s ease;
}

pre:hover .copy-code-btn {
    opacity: 1;
}

.copy-code-btn:hover {
    color: var(--ink);
    border-color: var(--ink);
}

.copy-code-btn.copied {
    color: var(--accent);
    border-color: var(--accent);
}

/* ============================================
   14. SELECTION SHARE
   ============================================ */
.selection-share {
    position: absolute;
    display: flex;
    gap: 0.25rem;
    padding: 0.3rem;
    background: var(--ink);
    border-radius: 4px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(5px);
    transition: all 0.2s ease;
    z-index: 100;
}

.selection-share.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.selection-share::after {
    content: '';
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 6px solid var(--ink);
}

.selection-share-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: none;
    border: none;
    color: var(--paper);
    cursor: pointer;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.selection-share-btn:hover {
    opacity: 1;
}

/* ============================================
   15. SIDENOTES (Tufte-style)
   ============================================ */
.sidenote {
    float: right;
    clear: right;
    width: 200px;
    margin-right: -240px;
    margin-top: 0.3rem;
    margin-bottom: 1rem;
    font-size: 0.75rem;
    line-height: 1.5;
    color: var(--graphite);
}

.sidenote::before {
    content: attr(data-sidenote) ". ";
    font-weight: 500;
}

@media (max-width: 1200px) {
    .sidenote {
        display: none;
    }
}

/* ============================================
   16. PAGE TRANSITIONS
   ============================================ */
.page-transition {
    position: fixed;
    inset: 0;
    background: var(--paper);
    z-index: 9999;
    pointer-events: none;
    opacity: 1;
    transition: opacity 0.3s ease;
}

body.page-loaded .page-transition {
    opacity: 0;
}

body.page-leaving {
    opacity: 0;
    transition: opacity 0.3s ease;
}

/* ============================================
   17. CURSOR TRAIL
   ============================================ */
.cursor-trail {
    position: fixed;
    width: 6px;
    height: 6px;
    background: var(--accent);
    border-radius: 50%;
    pointer-events: none;
    z-index: 9998;
    mix-blend-mode: difference;
}

@media (hover: none) {
    .cursor-trail {
        display: none;
    }
}

/* ============================================
   18. MOBILE BOTTOM NAV
   ============================================ */
.mobile-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-around;
    background: var(--paper);
    border-top: 1px solid var(--rule);
    padding: 0.5rem 0;
    padding-bottom: calc(0.5rem + env(safe-area-inset-bottom));
    z-index: 1000;
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.2rem;
    padding: 0.5rem 1rem;
    text-decoration: none;
    color: var(--graphite);
    font-size: 0.55rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    transition: color 0.2s;
}

.bottom-nav-item.active,
.bottom-nav-item:hover {
    color: var(--ink);
}

.bottom-nav-item svg {
    fill: currentColor;
}

/* Adjust body padding for bottom nav */
@media (max-width: 768px) {
    body {
        padding-bottom: 70px;
    }
}

/* ============================================
   19. PULL TO REFRESH
   ============================================ */
.pull-refresh {
    position: fixed;
    top: -50px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--paper);
    border: 1px solid var(--rule);
    border-radius: 50%;
    opacity: 0;
    transition: transform 0.2s;
    z-index: 1001;
}

.pull-refresh-icon {
    font-size: 1.2rem;
    color: var(--graphite);
    transition: transform 0.3s;
}

.pull-refresh.ready .pull-refresh-icon {
    color: var(--accent);
    transform: rotate(180deg);
}

.pull-refresh.refreshing .pull-refresh-icon {
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============================================
   20. READING TIME IN META
   ============================================ */
.reading-time::before {
    content: "◔ ";
    opacity: 0.6;
}

/* ============================================
   21. ENHANCED LINK HOVER
   ============================================ */
article a:not(.share-btn):not(.related-card) {
    text-decoration: none;
    background-image: linear-gradient(var(--accent), var(--accent));
    background-size: 100% 1px;
    background-position: 0 100%;
    background-repeat: no-repeat;
    transition: background-size 0.3s ease;
}

article a:not(.share-btn):not(.related-card):hover {
    background-size: 100% 100%;
    color: var(--paper);
}

[data-theme="dark"] article a:not(.share-btn):not(.related-card):hover {
    color: var(--ink);
}

/* ============================================
   PRINT STYLES
   ============================================ */
@media print {
    /* Hide non-essential elements */
    nav,
    .reading-progress,
    .back-link,
    .cursor,
    .frame-left,
    .mobile-menu,
    .menu-toggle,
    .scroll-depth,
    .share-popup,
    .comments-section,
    footer {
        display: none !important;
    }
    
    /* Reset page */
    body {
        background: white !important;
        color: black !important;
        font-size: 12pt;
        line-height: 1.6;
    }
    
    article {
        max-width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
    }
    
    h1 {
        font-size: 24pt;
        page-break-after: avoid;
    }
    
    h2 {
        font-size: 16pt;
        page-break-after: avoid;
    }
    
    p {
        orphans: 3;
        widows: 3;
    }
    
    /* Show URLs for links */
    a[href^="http"]:after {
        content: " (" attr(href) ")";
        font-size: 9pt;
        color: #666;
    }
    
    /* Page breaks */
    .content {
        page-break-before: avoid;
    }
    
    /* Images */
    img {
        max-width: 100% !important;
        page-break-inside: avoid;
    }
}

/* ============================================
   LAZY LOADING STYLES
   ============================================ */
img[data-src] {
    opacity: 0;
    transition: opacity 0.3s ease;
}

img[data-src].loaded {
    opacity: 1;
}

.img-placeholder {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

@media (prefers-color-scheme: dark) {
    .img-placeholder {
        background: linear-gradient(90deg, #2a2a2a 25%, #3a3a3a 50%, #2a2a2a 75%);
        background-size: 200% 100%;
    }
}

/* ============================================
   SEARCH TRIGGER HINT
   ============================================ */
.search-hint {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    font-family: var(--mono);
    font-size: 0.65rem;
    letter-spacing: 0.1em;
    color: var(--silver);
    background: var(--paper);
    padding: 0.5rem 1rem;
    border-radius: 4px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease;
    pointer-events: none;
}

.search-hint.visible {
    opacity: 1;
    transform: translateY(0);
}

.search-hint kbd {
    background: rgba(0,0,0,0.1);
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    margin-left: 0.25rem;
}
