/* ========== CSS CUSTOM PROPERTIES ========== */
:root {
    color-scheme: light dark;

    --color-bg: #FAFAFA;
    --color-text: #000000;
    --color-text-hover: #333333;
    --color-link: #000000;
    --color-border: #e0e0e0;
    --color-blockquote-border: #ccc;
    --color-accent: #b17ada;
    --color-selection: rgba(177, 122, 218, 0.2);
    --color-preview-bg: #f0f0f0;
    --color-text-muted: #666;
    --color-text-faint: #999;
    --color-text-dim: #888;
    --color-subtitle: #444;
    --color-shadow: rgba(0, 0, 0, 0.15);
}

/* Dark mode — auto-detect from system preference */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --color-bg: #1a1a1a;
        --color-text: #e0e0e0;
        --color-text-hover: #ffffff;
        --color-link: #e0e0e0;
        --color-border: #333;
        --color-blockquote-border: #555;
        --color-accent: #b17ada;
        --color-selection: rgba(177, 122, 218, 0.3);
        --color-preview-bg: #2a2a2a;
        --color-text-muted: #aaa;
        --color-text-faint: #888;
        --color-text-dim: #999;
        --color-subtitle: #bbb;
        --color-shadow: rgba(0, 0, 0, 0.4);
    }
}

/* Dark mode — manual override via toggle */
[data-theme="dark"] {
    --color-bg: #1a1a1a;
    --color-text: #e0e0e0;
    --color-text-hover: #ffffff;
    --color-link: #e0e0e0;
    --color-border: #333;
    --color-blockquote-border: #555;
    --color-accent: #b17ada;
    --color-selection: rgba(177, 122, 218, 0.3);
    --color-preview-bg: #2a2a2a;
    --color-text-muted: #aaa;
    --color-text-faint: #888;
    --color-text-dim: #999;
    --color-subtitle: #bbb;
    --color-shadow: rgba(0, 0, 0, 0.4);
}

/* Sans font override */
[data-font="sans"] body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
}

[data-font="sans"] .sidebar-toggle,
[data-font="sans"] .bilingual-label {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
}

/* ========== BASE STYLES ========== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 16px;
    line-height: 1.6;
    color: var(--color-text);
    background-color: var(--color-bg);
}

/* ========== TYPOGRAPHY ========== */
h1 {
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 36px;
    font-weight: normal;
    margin: 20px 0;
}

h2 {
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 24px;
    font-weight: normal;
    margin-top: 40px;
    margin-bottom: 15px;
}

h3 {
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 20px;
    font-weight: normal;
    margin-top: 30px;
    margin-bottom: 10px;
}

p {
    margin-bottom: 15px;
}

a {
    color: var(--color-link);
    text-decoration: underline;
}

a:hover {
    color: var(--color-text-hover);
    text-decoration: none;
}

em {
    font-style: italic;
}

strong {
    font-weight: bold;
}

blockquote {
    margin: 20px 0;
    padding-left: 20px;
    border-left: 3px solid var(--color-blockquote-border);
    font-style: italic;
}

ul, ol {
    margin-bottom: 15px;
    padding-left: 30px;
}

li {
    margin-bottom: 5px;
}

/* When text is selected, use IFP purple */
::selection {
    background-color: var(--color-selection);
}

/* ========== LAYOUT ========== */
.container {
    max-width: 700px;
    margin: 0 auto;
    padding: 40px;
}

/* ========== MAIN PAGE STYLES ========== */

/* Header section with photo and name */
.header {
    display: flex;
    align-items: flex-end;
    gap: 20px;
    margin-bottom: 40px;
}

.header h1 {
    margin: 0;
}

.header h2 {
    margin-top: 60px;
}

.profile-photo {
    width: 120px;
    height: 120px;
    border-radius: 6px;
    object-fit: cover;
}

/* Bio section */
.bio {
    margin-bottom: 40px;
}

/* Contact bar */
.contact-bar {
    display: flex;
    justify-content: center;
    gap: 25px;
    margin: 30px 0;
    padding: 15px 0;
    border-top: 1px solid var(--color-border);
    border-bottom: 1px solid var(--color-border);
    font-size: 15px;
}

.contact-bar a {
    text-decoration: none;
}

.contact-bar a:hover {
    text-decoration: underline;
}

/* IFP link with smooth transition */
.ifp-link {
    transition: color 0s ease;
}

.ifp-link:hover {
    color: var(--color-accent);
}

/* Publication-style sections */
.publication-list h2 {
    margin-top: 40px;
}

.publication-list p {
    margin-bottom: 10px;
    padding-left: 25px;
    text-indent: -25px;
}

/* Media mentions section - normal indent */
#media-mentions p {
    padding-left: 0;
    text-indent: 0;
}

/* ========== IMAGE PREVIEW ========== */
.image-preview {
    position: fixed;
    right: 40px;
    top: 50%;
    transform: translateY(-50%);
    width: 300px;
    max-width: 25vw;
    opacity: 0;
    transition: opacity 0s ease;
    pointer-events: none;
    z-index: 1000;
}

.image-preview.visible {
    opacity: 1;
}

.image-preview-container {
    position: relative;
    width: 100%;
    min-height: 300px;
    max-height: 500px;
    border-radius: 8px;
    overflow: hidden;
    background-color: var(--color-preview-bg);
    box-shadow: 0 4px 12px var(--color-shadow);
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-preview img {
    max-width: 100%;
    max-height: 500px;
    width: auto;
    height: auto;
    object-fit: contain;
    opacity: 0;
    transition: opacity 0s ease;
}

.image-preview img.loaded {
    opacity: 1;
}

.image-preview.icon-preview {
    width: 110px;
    max-width: 110px;
}

.image-preview.icon-preview .image-preview-container {
    min-height: 0;
    max-height: none;
    background-color: transparent;
    box-shadow: none;
}

.image-preview.icon-preview img {
    max-width: 96px;
    max-height: 96px;
}

.media-mosaic {
    position: fixed;
    top: 140px;
    width: 236px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    opacity: 0;
    pointer-events: none;
    z-index: 1000;
}

.media-mosaic.visible {
    opacity: 1;
}

.media-mosaic-tile {
    width: 72px;
    height: 72px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.media-mosaic-tile img {
    max-width: 64px;
    max-height: 64px;
    width: auto;
    height: auto;
    object-fit: contain;
}

html[data-theme="dark"] .media-mosaic-tile {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.16);
}

html[data-theme="dark"] .media-mosaic-tile.invert-on-dark img {
    filter: invert(1) brightness(0.9);
}

@media (prefers-color-scheme: dark) {
    html:not([data-theme="light"]) .media-mosaic-tile {
        background: rgba(255, 255, 255, 0.08);
        border: 1px solid rgba(255, 255, 255, 0.16);
    }

    html:not([data-theme="light"]) .media-mosaic-tile.invert-on-dark img {
        filter: invert(1) brightness(0.9);
    }

}

/* ========== SIDEBAR NAVIGATION ========== */
.page-wrapper {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    position: fixed;
    left: max(20px, calc((100vw - 700px) / 4 - 80px));
    top: 0;
    width: 160px;
    height: 100%;
    padding: 50px 20px 40px;
    font-size: 15px;
    display: flex;
    flex-direction: column;
}

.sidebar-name {
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 16px;
    margin-bottom: 20px;
}

.sidebar-name a {
    text-decoration: none;
    color: var(--color-text);
}

.sidebar-name a:hover {
    text-decoration: underline;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sidebar-nav a {
    text-decoration: none;
    color: var(--color-text-muted);
}

.sidebar-nav a:hover {
    color: var(--color-text);
}

.sidebar-nav a.active {
    color: var(--color-text);
}

/* Sidebar toggles */
.sidebar-toggles {
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar-toggle {
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    color: var(--color-text-faint);
    padding: 2px 0;
    display: flex;
    gap: 4px;
    align-items: center;
    text-align: left;
}

.sidebar-toggle:hover {
    color: var(--color-text-muted);
}

.sidebar-toggle-separator {
    color: var(--color-text-faint);
}

.mobile-sticky-nav {
    display: none;
}

/* ========== SECTION REVEAL (JS ENHANCEMENT) ========== */
.js-reveal-enabled .reveal-heading,
.js-reveal-enabled .reveal-content {
    opacity: 0;
    transform: translateY(6px);
    transition: opacity 420ms ease, transform 420ms ease;
    will-change: opacity, transform;
}

.js-reveal-enabled .reveal-heading.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.js-reveal-enabled .reveal-content {
    transition-delay: calc(80ms + var(--reveal-delay, 0ms));
}

.js-reveal-enabled .reveal-content.is-visible {
    opacity: 1;
    transform: translateY(0);
}

@media (prefers-reduced-motion: reduce) {
    .js-reveal-enabled .reveal-heading,
    .js-reveal-enabled .reveal-content {
        opacity: 1;
        transform: none;
        transition: none;
    }
}

/* Center content in viewport; sidebar lives in left margin area */
.page-wrapper .container {
    margin-left: auto;
    margin-right: auto;
}

/* On mid-size screens, fall back to offset layout to avoid sidebar overlap */
@media (min-width: 769px) and (max-width: 1100px) {
    .sidebar {
        left: 0;
        padding-left: 20px;
        padding-right: 16px;
        width: 150px;
    }

    .page-wrapper .container {
        margin-left: 160px;
        margin-right: 16px;
    }
}

/* ========== MISCELLANY PAGE ========== */

/* Painting gallery — thumbnail grid */
.gallery-wrapper {
    position: relative;
    margin: 20px 0 10px 0;
}

.gallery-wrapper.collapsed .gallery-grid {
    max-height: 430px;
    overflow: hidden;
    -webkit-mask-image: linear-gradient(to bottom, black 70%, transparent 100%);
    mask-image: linear-gradient(to bottom, black 70%, transparent 100%);
}

.gallery-toggle {
    display: block;
    margin: 12px auto 40px auto;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-text-muted);
    font-size: 14px;
    font-family: inherit;
    padding: 0;
}

.gallery-toggle:hover {
    color: var(--color-text);
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
}

.gallery-grid-item {
    cursor: pointer;
    overflow: hidden;
    border-radius: 4px;
    position: relative;
    background: var(--color-border);
    aspect-ratio: 1 / 1;
}

.gallery-grid-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    aspect-ratio: 1 / 1;
    transition: transform 0.2s ease;
}

.gallery-grid-item:hover img {
    transform: scale(1.03);
}

.gallery-grid-item:focus-visible {
    outline: 2px solid var(--color-link);
    outline-offset: 2px;
}

/* Lightbox overlay */
.lightbox {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.92);
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

.lightbox.active {
    display: flex;
}

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

.lightbox-caption {
    color: #ccc;
    font-size: 14px;
    font-style: italic;
    margin-top: 12px;
    text-align: center;
    padding: 0 20px;
}

.lightbox-counter {
    color: #888;
    font-size: 13px;
    margin-top: 6px;
}

.lightbox-close {
    position: absolute;
    top: 16px;
    right: 20px;
    background: none;
    border: none;
    color: #ccc;
    font-size: 28px;
    cursor: pointer;
    padding: 8px;
    line-height: 1;
    z-index: 1001;
}

.lightbox-close:hover {
    color: #fff;
}

.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: #ccc;
    font-size: 32px;
    cursor: pointer;
    padding: 16px;
    z-index: 1001;
}

.lightbox-nav:hover {
    color: #fff;
}

.lightbox-prev {
    left: 12px;
}

.lightbox-next {
    right: 12px;
}

/* Blockquotes for "Words I like" */
blockquote cite {
    display: block;
    margin-top: 6px;
    font-style: normal;
    font-size: 14px;
    color: var(--color-text-muted);
}

blockquote + blockquote {
    margin-top: 30px;
}

/* Readings list */
.readings-list {
    list-style: disc;
    padding-left: 25px;
    margin-bottom: 15px;
}

.readings-list li {
    margin-bottom: 8px;
}

.readings-list a {
    color: var(--color-link);
}

/* Expandable quotes */
.quote-content.collapsed {
    position: relative;
}

.quote-content.collapsed::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3em;
    background: linear-gradient(transparent, var(--color-bg));
    pointer-events: none;
}

.quote-toggle {
    display: inline-block;
    font-style: normal;
    font-size: 14px;
    color: var(--color-text-muted);
    text-decoration: none;
    margin-top: 6px;
    margin-bottom: 6px;
}

.quote-toggle:hover {
    text-decoration: underline;
}

/* Bilingual side-by-side quotes */
.bilingual-columns {
    display: flex;
    gap: 30px;
}

.bilingual-col {
    flex: 1;
    min-width: 0;
}

.bilingual-col p {
    margin-bottom: 0;
}

.bilingual-label {
    font-style: normal;
    font-size: 13px;
    color: var(--color-text-faint);
    margin-bottom: 8px !important;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
    text-transform: lowercase;
}

/* Wide quote — extends right for bilingual poems with longer lines */
.wide-quote {
    margin-right: -120px;
}

/* ========== BLOG POST STYLES ========== */
.back-link {
    margin-bottom: 40px;
}

.post-header {
    margin-bottom: 40px;
}

.post-date {
    color: var(--color-text-muted);
    font-size: 14px;
    margin-top: 10px;
}

.post-subtitle {
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 18px;
    font-weight: normal;
    color: var(--color-subtitle);
    font-style: italic;
    margin-top: 8px;
}

.post-content {
    line-height: 1.7;
}

.post-image {
    margin: 30px 0;
    text-align: center;
}

.post-image img {
    max-width: 65%;
    height: auto;
}

.post-image-caption {
    font-size: 13px;
    color: var(--color-text-dim);
    margin-top: 8px;
    font-style: italic;
}

.post-content .see-also {
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid var(--color-border);
}

.post-content .see-also h2 {
    font-size: 18px;
    margin-top: 0;
}

/* Wiki-style notice */
.post-notice {
    font-size: 13px;
    color: var(--color-text-dim);
    font-style: italic;
    margin-bottom: 20px;
}

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
    .container {
        padding: 20px;
    }

    h1 {
        font-size: 28px;
    }

    h2 {
        font-size: 20px;
        margin-top: 40px;
    }

    h3 {
        font-size: 18px;
    }

    body {
        font-size: 15px;
    }

    .links a {
        display: inline-block;
        margin-bottom: 5px;
    }

    /* Hide image preview on mobile */
    .image-preview,
    .media-mosaic {
        display: none;
    }

    /* Stack bilingual columns on mobile */
    .bilingual-columns {
        flex-direction: column;
        gap: 20px;
    }

    .wide-quote {
        margin-right: 0;
    }

    /* Gallery grid: 2 columns on mobile */
    .gallery-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .gallery-wrapper.collapsed .gallery-grid {
        max-height: none;
        -webkit-mask-image: none;
        mask-image: none;
    }

    .gallery-wrapper.collapsed .gallery-grid-item:nth-child(n+7) {
        display: none;
    }

    .gallery-wrapper.collapsed .gallery-grid-item:nth-child(5),
    .gallery-wrapper.collapsed .gallery-grid-item:nth-child(6) {
        opacity: 0.3;
    }

    /* Lightbox touch targets */
    .lightbox-nav {
        padding: 20px;
        min-width: 44px;
        min-height: 44px;
    }

    .lightbox-close {
        min-width: 44px;
        min-height: 44px;
    }

    .sidebar-nav a {
        padding: 8px 4px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
    }

    .contact-bar a {
        padding: 8px 4px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
    }

    /* Sidebar becomes top bar on mobile */
    .sidebar {
        position: static;
        width: 100%;
        height: auto;
        padding: 12px 20px 8px 20px;
        display: block;
    }

    body.has-mobile-sticky-nav .page-wrapper {
        padding-top: calc(env(safe-area-inset-top) + 64px);
    }

    .mobile-sticky-nav {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1100;
        display: flex;
        align-items: center;
        gap: 16px;
        padding: calc(env(safe-area-inset-top) + 8px) 20px 8px;
        background: var(--color-bg);
        border-bottom: 1px solid var(--color-border);
    }

    .mobile-sticky-nav .sidebar-name {
        margin: 0;
        white-space: nowrap;
    }

    .mobile-sticky-nav .sidebar-nav {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 12px;
        min-width: 0;
        align-items: center;
    }

    .mobile-sticky-nav .sidebar-nav a {
        padding: 8px 4px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
    }

    .sidebar-name,
    .sidebar-nav {
        display: none;
    }    

    .sidebar-toggles {
        margin: 0;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 12px;
        min-width: 0;
    }

    .sidebar-toggle {
        min-height: 44px;
        padding: 8px 0;
        display: inline-flex;
        align-items: center;
    }

    .page-wrapper {
        flex-direction: column;
    }

    .page-wrapper .container {
        margin-left: auto;
        margin-right: auto;
    }
}

@media (max-width: 1200px) {
    /* Adjust image preview size for smaller screens */
    .image-preview {
        width: 250px;
        right: 20px;
    }

    .media-mosaic {
        width: 200px;
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }

    .media-mosaic-tile {
        width: 60px;
        height: 60px;
    }

    .media-mosaic-tile img {
        max-width: 52px;
        max-height: 52px;
    }
}
