/* ================================
   CSS Variables & Reset
   ================================ */

:root {
    /* Force light mode — prevents browsers from auto-darkening */
    color-scheme: light only;

    /* Colors */
    --color-bg: #FAFAFA;
    --color-text: #1A1A1A;
    --color-accent: #8B0000;
    --color-overlay: rgba(0, 0, 0, 0.92);
    
    /* Typography */
    --font-display: 'Libre Baskerville', serif;
    --font-body: 'Hanken Grotesk', sans-serif;
    
    /* Spacing */
    --spacing-xs: 0.5rem;
    --spacing-sm: 1rem;
    --spacing-md: 1.5rem;
    --spacing-lg: 2rem;
    --spacing-xl: 3rem;
    --spacing-2xl: 4rem;
    
    /* Layout */
    --max-width: 1400px;
    --header-height: 70px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    scrollbar-gutter: stable both-edges;
    background-color: var(--color-bg);
}

body {
    font-family: var(--font-body);
    background-color: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Prevents scrolling during theme transitions — required for iOS Safari
   which ignores overflow:hidden on child elements */
html.scroll-locked,
html.scroll-locked body {
    overflow: hidden;
    touch-action: none;
    overscroll-behavior: none;
}

/* Prevents background scrolling when overlay is open — uses position:fixed
   technique instead of touch-action:none so pinch-to-zoom still works */
html.overlay-scroll-locked body {
    position: fixed;
    width: 100%;
    overflow: hidden;
}

/* ================================
   Header
   ================================ */

.site-header {
    position: relative;
    height: var(--header-height);
    background-color: var(--color-bg);
    z-index: 100;
    /* Start invisible — JS adds .revealed after fonts load to trigger fade+slide */
    opacity: 0;
    transform: translateY(-8px);
    transition: opacity 0.5s ease, transform 0.5s ease;
}

.site-header.revealed {
    opacity: 1;
    transform: translateY(0);
}

.header-content {
    max-width: var(--max-width);
    margin: 0 auto;
    height: 100%;
    padding: 0 var(--spacing-md);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.wordmark {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--color-text);
    text-decoration: none;
    letter-spacing: 0.01em;
}

/* Desktop Navigation */
.desktop-nav {
    display: none;
    gap: var(--spacing-lg);
}

.nav-link {
    font-size: 1.09rem;
    color: var(--color-text);
    text-decoration: none;
    transition: color 0.3s ease;
}

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

/* Mobile Menu Toggle */
.mobile-menu-toggle {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-end; /* Right-align 24px icon within 40px touch target */
    width: 40px;
    height: 40px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    z-index: 300; /* Sits above mobile-menu overlay (z-index: 200) */
    position: relative;
}

.hamburger-icon {
    position: relative;
    width: 24px;
    height: 2px;
    background-color: var(--color-text);
    transition: background-color 0.3s ease;
}

.hamburger-icon::before,
.hamburger-icon::after {
    content: '';
    position: absolute;
    left: 0;
    width: 24px;
    height: 2px;
    background-color: var(--color-text);
    transition: transform 0.3s ease, top 0.3s ease;
}

.hamburger-icon::before {
    top: -7px;
}

.hamburger-icon::after {
    top: 7px;
}

/* Hamburger → X morph */
.mobile-menu-toggle.is-open .hamburger-icon {
    background-color: transparent;
}

.mobile-menu-toggle.is-open .hamburger-icon::before {
    top: 0;
    transform: rotate(45deg);
}

.mobile-menu-toggle.is-open .hamburger-icon::after {
    top: 0;
    transform: rotate(-45deg);
}

/* Mobile Menu Overlay */
.mobile-menu {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--color-bg);
    z-index: 200;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.mobile-menu.active {
    opacity: 1;
    visibility: visible;
}

.mobile-nav {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xl);
    align-items: center;
}

.mobile-nav-link {
    font-family: var(--font-body);
    font-size: 1.5rem;
    font-weight: 400;
    color: var(--color-text);
    text-decoration: none;
    transition: color 0.3s ease;
}

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

/* ================================
   Sticky Theme Indicator
   ================================ */

.sticky-theme-indicator {
    position: fixed;
    /* Clear the status bar on notched iPhones, fall back to a comfortable offset */
    top: max(0.75rem, calc(env(safe-area-inset-top, 0px) + 0.25rem));
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    z-index: 90;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
    /* Pill shape — echoes "View next theme" button language */
    background: rgba(250, 250, 250, 0.75);
    border-radius: 999px;
    padding: 0.5rem 1.25rem;
    white-space: nowrap;
}

.sticky-theme-indicator.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.sticky-theme-indicator .theme-text {
    font-family: var(--font-display);
    font-size: 0.8rem;
    font-weight: 600;
    text-align: center;
    display: block;
    color: var(--color-text);
    letter-spacing: 0.01em;
}

/* ================================
   Main Content
   ================================ */

.main-content {
    padding: var(--spacing-xl) var(--spacing-md);
    max-width: var(--max-width);
    margin-left: auto;
    margin-right: auto;
}

/* ================================
   Theme Section
   ================================ */

.theme-section {
    display: flex;
    flex-direction: column;
}

.theme-subheader {
    font-family: var(--font-body);
    font-size: 1.035rem;
    font-weight: 400;
    text-align: center;
    color: var(--color-text);
    margin-bottom: var(--spacing-sm);
    letter-spacing: 0.02em;
    /* Start invisible — JS adds .revealed to trigger fade+slide (same direction as header) */
    opacity: 0;
    transform: translateY(-12px);
    transition: opacity 0.7s ease, transform 0.7s ease;
}

.theme-subheader.revealed {
    opacity: 1;
    transform: translateY(0);
}

.theme-headline {
    font-family: var(--font-display);
    /* Fluid type: scales from 2.5rem at 320px to 4.375rem at 1440px */
    font-size: clamp(2.5rem, 1.5rem + 3.125vw, 4.375rem);
    font-weight: 400;
    text-align: center;
    margin-bottom: var(--spacing-xl);
    line-height: 1.4;
    max-width: 90vw;
    margin-left: auto;
    margin-right: auto;
    text-wrap: balance;
    -webkit-text-stroke: 0.5px var(--color-text);
}

/* "We " prefix — regular weight */
.theme-prefix {
    white-space: nowrap;
    font-weight: 400;
}

/* The changing word — uniform 400, same as prefix */
.theme-word-animated {
    font-weight: 400;
}

.theme-period {
    font-weight: 400;
    visibility: hidden; /* JS reveals after typing completes */
}

/* Cursor hidden — animation itself is the signal */
.typing-cursor {
    display: none;
}

/* Character spans for typing animation — pre-rendered invisible,
   then revealed sequentially via .revealed class.
   Opacity transition creates soft materialisation without layout shift. */
.theme-word-animated > span,
.theme-prefix > span {
    display: inline;
    opacity: 0;
    transition: opacity 0.05s ease;
}

.theme-word-animated > span.revealed,
.theme-prefix > span.revealed {
    opacity: 1;
}


/* ================================
   Masonry Grid — true column masonry
   ================================ */

.masonry-grid {
    position: relative;
    margin-bottom: var(--spacing-2xl);
}

.masonry-item {
    position: absolute;
    overflow: hidden;
    cursor: pointer;
    border-radius: 4px;
    pointer-events: none; /* Enabled by JS after fade-in — prevents clicks on invisible images */
}

/* Transparent overlay to prevent right-click image saving */
.masonry-item::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: transparent;
    z-index: 1;
}

/* The ::after shield stays active on all devices including touch —
   pinch-to-zoom still works because it's a browser-level gesture
   that operates on the viewport, not individual elements. */

.masonry-item:hover img {
    transform: scale(1.02);
}

.masonry-item:hover .masonry-item-overlay {
    opacity: 1;
}

.masonry-item img {
    width: 100%;
    height: auto;
    display: block;
    transition: transform 0.4s ease;
    border-radius: 4px;
    /* Mobile image save prevention */
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-user-drag: none;
    pointer-events: none;
}

/* Hover metadata overlay — spans full thumbnail, gradient always proportional to image */
.masonry-item-overlay {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: flex-end;
    padding: 10px 10px 8px;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.8) 100%);
    color: #fff;
    font-family: var(--font-body);
    font-size: 0.9375rem;
    font-weight: 400;
    letter-spacing: 0.02em;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 2;
    border-radius: 4px;
    pointer-events: none;
}

/* Disable hover overlay on touch devices — no hover state to trigger it */
@media (hover: none) and (pointer: coarse) {
    .masonry-item-overlay {
        display: none;
    }
}

/* ================================
   Theme Navigation
   ================================ */

.theme-navigation {
    display: none; /* Hidden until JS reveals after typing + images complete */
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-sm);
    margin-top: var(--spacing-xl);
}

.navigation-buttons {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    width: 100%;
    max-width: 400px;
}

/* Wrapper around button + hint — gives hint text a positioning context */
.button-wrapper {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 38px;
}

/* Previous theme link - subtle, below main button */
.nav-previous-link {
    font-family: var(--font-body);
    font-size: 0.9rem;
    color: #555;
    text-decoration: none;
    cursor: pointer;
    transition: color 0.2s ease;
}

.nav-previous-link:hover {
    color: var(--color-text);
    text-decoration: underline;
}

.theme-button {
    font-family: var(--font-body);
    font-size: 1.05rem;
    padding: 0.875rem 2.25rem;
    background-color: var(--color-text);
    border: none;
    color: #fff;
    cursor: pointer;
    border-radius: 999px;
    text-align: center;
    box-shadow: none;
    transition: background-color 0.25s ease, transform 0.15s ease;
    white-space: nowrap;
    width: auto;
    max-width: none;
}

.theme-button:hover {
    background-color: #333;
}

.theme-button:active {
    transform: scale(0.98);
    background-color: #444;
}

/* Hint text - appears below button on hover, inside .button-wrapper */
.nav-hint-text {
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    font-family: var(--font-body);
    font-size: 0.875rem;
    color: #888;
    text-align: center;
    opacity: 0;
    transition: opacity 0.25s ease;
    margin-top: var(--spacing-xs);
    pointer-events: none;
    white-space: nowrap;
}

.button-wrapper:hover .nav-hint-text {
    opacity: 1;
}

/* ================================
   Image Overlay
   ================================ */

.image-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--color-overlay);
    z-index: 300;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    padding: var(--spacing-md);
}

.image-overlay.active {
    opacity: 1;
    visibility: visible;
}

.overlay-close {
    position: absolute;
    top: calc(var(--spacing-md) + env(safe-area-inset-top, 0px));
    right: var(--spacing-md);
    font-size: 2.125rem;
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    /* 44×44px touch target — meets accessibility minimum */
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    /* Dark outline ensures visibility on any image — same principle as macOS cursor */
    text-shadow:
        -1px -1px 2px rgba(0, 0, 0, 0.7),
         1px -1px 2px rgba(0, 0, 0, 0.7),
        -1px  1px 2px rgba(0, 0, 0, 0.7),
         1px  1px 2px rgba(0, 0, 0, 0.7);
    transition: opacity 0.2s ease;
}

.overlay-close:hover {
    opacity: 0.7;
}

/* Carousel Navigation — side arrows removed, bottom bar is universal */
.overlay-nav-prev,
.overlay-nav-next {
    display: none;
}

.overlay-nav.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.overlay-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    max-width: 100%;
    max-height: 100%;
    position: relative;
    padding-bottom: 100px; /* space for the fixed bottom bar */
}

/* Transparent shield over overlay image — suppresses both the browser's
   generic right-click menu (desktop) and long-press save (mobile).
   Close button, nav arrows, and bottom bar are siblings/fixed-position,
   so they sit above this shield and remain interactive. */
.overlay-content::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 100px; /* matches padding-bottom, stops above the info bar */
    z-index: 2;
}

.overlay-image {
    max-width: 100%;
    max-height: 72vh;
    max-height: 72svh;
    object-fit: contain;
    display: block;
    transition: opacity 0.2s ease;
    /* Belt-and-suspenders: CSS protection for mobile + fallback */
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-user-drag: none;
    pointer-events: none;
}

.overlay-image.transitioning {
    opacity: 0;
}

/* Bottom info + controls bar — fixed, universal */
.overlay-info {
    position: fixed;
    bottom: var(--spacing-lg);
    left: 0;
    right: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-sm);
    /* Ensure caption stays above Chrome iOS bottom toolbar */
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

.overlay-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-lg);
}

.image-caption {
    color: var(--color-bg);
    font-size: 0.875rem;
    text-align: center;
    text-wrap: balance;
    opacity: 0.9;
    padding: 0 var(--spacing-lg);
}

.image-counter {
    color: var(--color-bg);
    font-size: 0.8rem;
    opacity: 0.6;
    font-family: var(--font-body);
    min-width: 48px;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: translateY(2.5px);
}

/* Mobile nav arrows — shown in bottom bar on all sizes */
.overlay-nav-prev-mobile,
.overlay-nav-next-mobile {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--color-bg);
    font-size: 2.25rem;
    cursor: pointer;
    padding: var(--spacing-xs) var(--spacing-sm);
    opacity: 0.8;
    transition: opacity 0.2s ease;
    line-height: 1;
}

.overlay-nav-prev-mobile:hover,
.overlay-nav-next-mobile:hover {
    opacity: 1;
}

.overlay-nav-prev-mobile.hidden,
.overlay-nav-next-mobile.hidden {
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
}

/* Mobile overlay adjustments */
@media (max-width: 767px) {
    .image-overlay {
        padding: var(--spacing-sm);
    }

    .overlay-close {
        top: var(--spacing-sm);
        right: var(--spacing-sm);
    }

    .overlay-image {
        max-height: calc(100vh - 200px);
        max-height: calc(100svh - 200px);
    }
}

/* ================================
   Tablet & Desktop Breakpoints
   ================================ */

@media (min-width: 768px) {
    .main-content {
        padding: var(--spacing-2xl) var(--spacing-xl);
    }

    .theme-subheader {
        font-size: 1.29rem;
        margin-bottom: var(--spacing-md);
    }

    .sticky-theme-indicator .theme-text {
        font-size: 0.85rem;
    }
}

@media (min-width: 1024px) {
    .mobile-menu-toggle {
        display: none;
    }

    .desktop-nav {
        display: flex;
    }

    .theme-subheader {
        font-size: 1.44rem;
    }

    .navigation-prompt {
        font-size: 1.5rem;
    }

    .theme-button {
        font-size: 1.25rem;
    }
}

/* ================================
   Footer
   ================================ */

.site-footer {
    padding: var(--spacing-2xl) var(--spacing-md) var(--spacing-xl);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}

.site-footer.visible {
    opacity: 1;
    pointer-events: auto;
}

.footer-content {
    max-width: var(--max-width);
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-sm);
}

.footer-nav {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.footer-link {
    font-family: var(--font-body);
    font-size: 0.9rem;
    color: var(--color-text);
    text-decoration: none;
    transition: color 0.2s ease;
}

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

.footer-divider {
    color: rgba(26, 26, 26, 0.25);
    font-size: 0.85rem;
    user-select: none;
}

.footer-icon-link {
    display: flex;
    align-items: center;
    color: var(--color-text);
    transition: color 0.2s ease;
}

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

.footer-copyright {
    font-family: var(--font-body);
    font-size: 0.8rem;
    color: #888;
}

/* ================================
   Animations
   ================================ */

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

.fade-in {
    animation: fadeIn 0.6s ease forwards;
}

.fade-out {
    animation: fadeOut 0.4s ease forwards;
}

/* ================================
   About & Archive Pages
   ================================ */

/* Shared layout for text-heavy pages */
.page-content {
    padding: calc(var(--spacing-xl) + 1rem) var(--spacing-md) var(--spacing-2xl);
    max-width: 580px;
    margin: 0 auto;
}

/* Choreographed entrance — elements start hidden, JS reveals sequentially */
.entrance-hidden {
    opacity: 0;
    transform: translateY(-8px);
}

.entrance-visible {
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.5s ease, transform 0.5s ease;
}

/* Page heading */
.page-heading {
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 600;
    color: var(--color-text);
    line-height: 1.3;
    margin-bottom: 2rem;
}

.page-heading em {
    font-style: italic;
}

.prose p {
    font-family: var(--font-body);
    font-size: 1.22rem;
    line-height: 1.75;
    color: var(--color-text);
    margin-bottom: 1.5rem;
}

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

.prose a {
    color: var(--color-text);
    text-decoration: underline;
    text-decoration-color: rgba(26, 26, 26, 0.35);
    text-underline-offset: 3px;
    transition: text-decoration-color 0.2s ease;
}

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

/* Accordion group — boxed card style */
.accordion-group {
    margin-top: 2.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.accordion {
    border: 1px solid rgba(26, 26, 26, 0.12);
    border-radius: 8px;
    transition: border-color 0.25s ease;
}

.accordion:hover {
    border-color: rgba(26, 26, 26, 0.25);
}

.accordion.open {
    border-color: rgba(26, 26, 26, 0.2);
}

.accordion-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 1.125rem 1.25rem;
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
    font-family: var(--font-display);
    font-size: 1.0625rem;
    font-weight: 600;
    color: var(--color-text);
    line-height: 1.4;
    transition: color 0.2s ease;
}

.accordion-trigger:hover {
    color: #555;
}

.accordion-icon {
    font-size: 1.25rem;
    font-weight: 300;
    font-family: var(--font-body);
    color: #999;
    flex-shrink: 0;
    margin-left: 1rem;
    transition: transform 0.3s ease;
    line-height: 1;
}

.accordion-trigger[aria-expanded="true"] .accordion-icon {
    transform: rotate(45deg);
}

/* Smooth expand/collapse via CSS grid rows */
.accordion-body {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows 0.3s ease;
}

.accordion.open .accordion-body {
    grid-template-rows: 1fr;
}

.accordion-panel {
    overflow: hidden;
}

.accordion-panel p {
    padding: 0 1.25rem;
}

.accordion-panel p:first-child {
    margin-top: 0;
}

.accordion-panel p:last-child {
    margin-bottom: 1.25rem;
}

/* Active nav link — dot indicator */
.nav-link-active {
    position: relative;
}

.nav-link-active::after {
    content: '';
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%);
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background-color: var(--color-text);
}

/* Archive CTA — pill button matching Home page "View next theme" */
.archive-cta.theme-button {
    display: block;
    margin: 2.5rem auto 0;
    text-decoration: none;
    color: #fff;
    width: fit-content;
}

/* Scroll-direction sticky nav for text pages — hidden on scroll-down, shown on scroll-up */
.page-about .site-header,
.page-archive .site-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    transition: opacity 0.5s ease, transform 0.5s ease;
}

.page-about .site-header.nav-hidden,
.page-archive .site-header.nav-hidden {
    transform: translateY(-100%);
    opacity: 0;
    pointer-events: none;
}

/* Offset page content for fixed header */
.page-about .page-content,
.page-archive .page-content {
    padding-top: calc(var(--header-height) + var(--spacing-xl) + 1rem);
}

/* On text pages, footer visibility is controlled by JS entrance sequence */
.page-about .site-footer,
.page-archive .site-footer {
    transition: opacity 0.5s ease;
}

/* Tablet+ adjustments for text pages */
@media (min-width: 768px) {
    .page-content {
        padding-top: calc(var(--spacing-2xl) + 1rem);
        padding-bottom: var(--spacing-2xl);
    }

    .page-about .page-content,
    .page-archive .page-content {
        padding-top: calc(var(--header-height) + var(--spacing-2xl) + 1rem);
    }

    .page-heading {
        font-size: 2.25rem;
    }

    .prose p {
        font-size: 1.29rem;
        line-height: 1.8;
    }

    .accordion-trigger {
        font-size: 1.125rem;
    }
}

/* ================================
   Print Protection
   ================================ */

@media print {
    .masonry-grid,
    .image-overlay {
        display: none !important;
    }
}
