/* ==========================================================================
   Design Tokens - Mapped from Figma
   ========================================================================== */

:root {
    /* Colors */
    --color-background: #ffffff;
    --color-text-primary: #000000;
    --color-accent: #009DFF;
    --color-tldr: #7499ff;

    /* Typography - Font Families */
    --font-heading: 'Inter Tight', sans-serif;
    --font-body: 'Inter', sans-serif;

    /* Typography - Sizes */
    --text-heading-1: clamp(24px, 5vw, 32px);
    --text-heading-2: clamp(20px, 4vw, 24px);
    --text-body: 16px;
    --text-caption: 12px;

    /* Typography - Weights */
    --weight-bold: 700;
    --weight-medium: 500;
    --weight-regular: 400;

    /* Typography - Line Heights */
    --leading-heading: 1;
    --leading-body: 1.5;
    /* 24px / 16px */

    /* Typography - Letter Spacing */
    --tracking-body: -0.01em;
    /* -1% */

    /* Spacing Scale */
    --space-xxs: 8px;
    --space-xs: 16px;
    --space-sm: 24px;
    --space-md: 32px;
    --space-lg: 40px;
    --space-xl: 60px;
    --space-xxl: 80px;
    --space-xxxl: 180px;

    /* Layout */
    --container-max: 1040px;
    --content-max: 688px;
    --gutter-desktop: 240px;
    --gutter-tablet: 24px;
    --gutter-mobile: 16px;

    /* Radii */
    --radius-none: 0;
    --radius-sm: 4px;
    --radius-md: 8px;

    /* Shadows */
    --shadow-none: none;
}

/* ==========================================================================
   Base Reset & Typography
   ========================================================================== */

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-body);
    font-weight: var(--weight-regular);
    font-size: var(--text-body);
    line-height: var(--leading-body);
    letter-spacing: var(--tracking-body);
    color: var(--color-text-primary);
    background-color: var(--color-background);
}

h1,
h2,
h3,
h4,
h5,
h6 {
    font-family: var(--font-heading);
    line-height: var(--leading-heading);
    letter-spacing: 0;
}

p {
    margin-bottom: 0;
}

img {
    max-width: 100%;
    height: auto;
    display: block;
}

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

.site-header {
    width: 100%;
    padding: var(--space-sm) var(--gutter-tablet);
    background: rgba(255, 255, 255, 0.3);
}

.header-content {
    max-width: var(--container-max);
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-family: var(--font-heading);
    font-size: 18px;
    font-weight: var(--weight-bold);
    color: var(--color-text-primary);
    text-decoration: none;
}

.logo:hover {
    opacity: 0.7;
}

.nav-links {
    display: flex;
    gap: var(--space-sm);
    list-style: none;
    margin: 0;
    padding: 0;
}

.nav-links a {
    font-family: var(--font-body);
    font-size: 14px;
    color: var(--color-text-primary);
    text-decoration: none;
    transition: opacity 0.2s ease;
}

.nav-links a:hover {
    opacity: 0.6;
}

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

.site-footer {
    width: 100%;
    padding: var(--space-xs) var(--gutter-tablet);
    background: var(--color-background);
    border-top: 1px solid #e5e5e5;
    margin-top: var(--space-xxl);
}

.footer-content {
    max-width: var(--container-max);
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.footer-left p {
    font-family: var(--font-body);
    font-size: 14px;
    color: #666;
    margin: 0;
}

.social-links {
    display: flex;
    gap: var(--space-sm);
    list-style: none;
    margin: 0;
    padding: 0;
}

.social-links a {
    font-family: var(--font-body);
    font-size: 14px;
    color: var(--color-text-primary);
    text-decoration: none;
    transition: opacity 0.2s ease;
}

.social-links a:hover {
    opacity: 0.6;
}

/* ==========================================================================
   Typography Classes
   ========================================================================== */

/* Title / Heading 1: 40px, weight 600 */
.heading-1 {
    font-family: var(--font-heading);
    font-size: 40px;
    font-weight: 600;
    line-height: 1;
    letter-spacing: 0;
}

/* Heading 2: 24px, weight 700 */
.heading-2 {
    font-family: var(--font-heading);
    font-size: 24px;
    font-weight: 700;
    line-height: 1;
    letter-spacing: 0;
}

/* Heading 3: 16px, weight 700 */
.heading-3 {
    font-family: var(--font-heading);
    font-size: 16px;
    font-weight: 700;
    line-height: 1;
    letter-spacing: 0;
}

.section-body .heading-3 {
    margin-bottom: var(--space-xxs);
}

/* Body: 16px, weight 400, line-height 24px, letter-spacing -0.16px */
.body-text {
    font-family: var(--font-body);
    font-size: 16px;
    font-weight: 400;
    line-height: 24px;
    letter-spacing: -0.16px;
}

/* Caption: 12px, weight 400 */
.caption {
    font-family: var(--font-body);
    font-size: 12px;
    font-weight: 400;
    line-height: 1;
    letter-spacing: 0;
}

/* Inline text styles */
.body-text a {
    color: var(--color-accent);
    text-decoration: underline;
    text-underline-offset: 2px;
    transition: opacity 0.2s ease;
}

a {
    color: var(--color-accent);
    text-decoration: underline;
    text-underline-offset: 2px;
    transition: opacity 0.2s ease;
}

.body-text a:hover {
    opacity: 0.7;
}

.body-text strong {
    font-weight: 600;
}

.body-text em {
    font-style: italic;
}

/* ==========================================================================
   Layout System - 6 Column Grid
   ========================================================================== */

.page-wrapper {
    width: 100%;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    padding: 0 var(--gutter-desktop);
}

.article-container {
    width: 100%;
    max-width: var(--container-max);
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: var(--space-lg) 0;
    /* row gap only, columns handle their own spacing */
    padding-top: var(--space-xl);
    padding-bottom: var(--space-xl);
}

/* Default: content spans columns 2-5 (centered 4 columns) */
.article-section {
    grid-column: 2 / 6;
}


/* Sidebar */
.sidebar {
    grid-column: 1 / 2;
}

.sidebar2 {
    grid-column: 6 / 7;
}

.sidebar-list {
    list-style: none;
    font-size: var(--text-caption);
    margin: 0;
    padding: 0;
}

.sidebar-list li {
    margin-bottom: var(--space-xxs);
}

.sidebar-list li a {
    color: var(--color-text-primary);
    text-decoration: none;
    opacity: 0.6;
    transition: 0.2s ease;
}

.sidebar-list li a:hover {
    color: var(--color-accent);
}

/* Breadcrumb */
.breadcrumb {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--font-body);
    font-size: var(--text-caption);
    line-height: 1;
    margin-bottom: var(--space-xs);
}

.breadcrumb a {
    color: var(--color-text-primary);
    text-decoration: none;
    transition: opacity 0.2s ease;
}

.breadcrumb a:hover {
    opacity: 0.6;
}

.breadcrumb-separator {
    opacity: 0.5;
}

.breadcrumb-current {
    color: var(--color-text-primary);
}

/* Full-width: breaks out of content column to span full article grid */
.article-image-full {
    grid-column: 1 / 7;
    width: calc(100% + 50%);
    margin-left: -25%;
    padding: 0;
}

.article-content {
    width: 100%;
}

/* Article content container - holds markdown-loaded content */
#article-content {
    grid-column: 2 / 6;
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

/* Sections inside #article-content should not set their own grid-column */
#article-content .article-section {
    grid-column: unset;
}

.related-section {
    grid-column: 2 / 6;
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}


.not100vh {
    min-height: unset;
}

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

.article-header {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.article-header .heading-1 {
    width: 100%;
}

.article-header .heading-2 {
    width: 100%;
}

/* ==========================================================================
   Article Sections
   ========================================================================== */

.section-content {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.section-content .heading-2 {
    margin-bottom: 0;
}

.section-body {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.section-body p {
    margin: 0;
    margin-bottom: var(--space-sm);
}

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

.section-body ul,
ol {
    margin: 0;
    margin-bottom: var(--space-sm);
}

.section-body ul li,
ol li {
    display: list-item;
    unicode-bidi: isolate;
    list-style-position: inside;
    margin-left: var(--space-xs);
}

.section-body ol li {
    margin-bottom: 0;
}

.section-body ul li p:first-child,
.section-body ol li p:first-child {
    display: inline;
    text-decoration: underline;
    line-height: 36px;
}

.section-body ul li p,
ol li p {
    margin-bottom: var(--space-xxs) !important;
}

/* ==========================================================================
   Article Divider
   ========================================================================== */

.article-divider {
    display: flex;
    justify-content: center;
    align-items: center;
    border: none;
    background: transparent;
    height: auto;
    padding: var(--space-md) 0;
    grid-column: 1 / 7;
}

.article-divider::before {
    content: '';
    display: block;
    width: 264px;
    height: 10px;
    background-image: url('/assets/divider.svg');
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    /* Apply #009DFF color via CSS filter */
    /* This filter converts black to #009DFF */
    filter: invert(44%) sepia(98%) saturate(1500%) hue-rotate(185deg) brightness(102%) contrast(101%);
}

/* ==========================================================================
   Article Images
   ========================================================================== */

.article-image {
    width: 100%;
    margin: 0;
}

/* .article-image-full is defined in Layout System section */

.article-image img,
.article-image-full img {
    width: 100%;
    height: auto;
    /* aspect-ratio: 720 / 425; */
    object-fit: cover;
}

/* Caption styling */
.caption {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: 12px;
    color: #909090;
    /* margin-top: var(--space-xs); */
    line-height: 1.5;
}

/* ==========================================================================
   Responsive - Large Desktop (> 1200px)
   ========================================================================== */

@media (min-width: 1201px) {
    .page-wrapper {
        padding: 0 var(--gutter-desktop);
    }
}

/* ==========================================================================
   Responsive - Desktop (901px - 1200px)
   ========================================================================== */

@media (max-width: 1200px) {
    .page-wrapper {
        padding: 0 clamp(60px, 10vw, 120px);
    }

    /* Grid stays 6 columns, content still centered */
}

/* ==========================================================================
   Responsive - Tablet (481px - 900px)
   ========================================================================== */

@media (max-width: 900px) {
    :root {
        --space-xl: 80px;
    }

    .page-wrapper {
        padding: 0 var(--gutter-tablet);
    }

    .article-container {
        gap: var(--space-sm) 0;
        /* On tablet, content spans full width */
        grid-template-columns: 1fr;
    }

    .article-section {
        grid-column: 1 / -1;
    }

    #article-content {
        grid-column: 1 / -1;
    }

    .article-image-full {
        grid-column: 1 / -1;
    }

    .article-content {
        max-width: 100%;
    }
}

/* ==========================================================================
   Responsive - Mobile (≤ 480px)
   ========================================================================== */

@media (max-width: 480px) {
    :root {
        --space-xl: 60px;
        --space-lg: 32px;
        --space-md: 24px;
    }

    .page-wrapper {
        padding: 0 var(--gutter-mobile);
    }

    .article-container {
        gap: var(--space-sm);
    }

    .article-divider svg {
        width: 200px;
        height: auto;
    }
}

/* ==========================================================================
   Focus States (Accessibility)
   ========================================================================== */

a:focus-visible,
button:focus-visible {
    outline: 2px solid var(--color-text-primary);
    outline-offset: 2px;
}

/* ==========================================================================
   TLDR Toggle Feature
   ========================================================================== */

/* Section with TLDR enabled */
.tldr-section {
    position: relative;
}

/* Button wrapper - positioned in left gutter, aligned with body text */
.tldr-toggle-wrapper {
    position: absolute;
    left: -80px;
    width: 80px;
    display: flex;
    justify-content: flex-end;
    align-items: flex-start;
    z-index: 10;
    height: -webkit-fill-available;
    padding: 0 16px;
}

/* Sticky toggle button - Figma design */
.tldr-toggle-btn {
    position: sticky;
    top: var(--space-xl);
    display: flex;
    align-items: center;
    gap: 0;
    padding: 4px 0px;
    font-family: var(--font-body);
    font-size: 12px;
    font-weight: 400;
    letter-spacing: 0;
    text-transform: uppercase;
    color: white;
    background: #fff;
    border: none;
    cursor: pointer;
    white-space: nowrap;

    /* Hidden by default */
    opacity: 0;
    pointer-events: none;
    transform: translateX(-8px);
    transition:
        opacity 0.25s ease,
        transform 0.25s ease;
    border-bottom: 1px solid var(--color-tldr);
    color: var(--color-tldr);
}


/* Show button on section hover/focus-within */
.tldr-section:hover .tldr-toggle-btn,
.tldr-section:focus-within .tldr-toggle-btn {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(0);
}

/* Button hover/focus state */
.tldr-toggle-btn:hover {
    background: var(--color-tldr);
    color: #fff;
}

/* Tooltip helper text - appears on hover */
.tldr-toggle-btn::after {
    content: attr(data-tooltip);
    position: absolute;
    top: -100%;
    left: -50%;
    margin-top: 4px;
    font-size: 10px;
    font-weight: 400;
    color: #000000;
    text-transform: none;
    letter-spacing: 0;
    white-space: nowrap;
    opacity: 0;
    transform: translateY(16px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    pointer-events: none;
    background: #ffffff;
    padding: 2px;
}

.tldr-toggle-btn:hover::after,
.tldr-toggle-btn:focus-visible::after {
    opacity: 1;
    transform: translateY(0);
}

.tldr-highlight {
    background: rgba(116, 153, 255, 0.12);
    border-radius: 0;
    margin: -12px -16px;
    padding: 12px 16px;
    transition: background 0.2s ease;
}

/* Fade transition for content swap */
.tldr-fading {
    opacity: 0;
    transition: opacity 0.18s ease;
}

.body-text {
    transition: opacity 0.22s ease, background 0.3s ease;
}

/* Micro-feedback message - positioned above body text */
.tldr-feedback {
    position: absolute;
    top: -28px;
    left: 0;
    font-family: var(--font-body);
    font-size: 11px;
    font-weight: 400;
    color: var(--color-tldr);
    opacity: 0;
    transform: translateY(4px);
    transition:
        opacity 0.2s ease,
        transform 0.2s ease;
    pointer-events: none;
}

.tldr-feedback--visible {
    opacity: 1;
    transform: translateY(0);
}

/* ==========================================================================
   TLDR Toggle - Responsive
   ========================================================================== */

/* Tablet: button moves inline above body text */
@media (max-width: 900px) {
    .tldr-toggle-wrapper {
        position: relative;
        left: auto;
        width: auto;
        justify-content: flex-start;
        margin-bottom: var(--space-xs);
    }

    .tldr-toggle-btn {
        position: relative;
        top: auto;
        opacity: 1;
        pointer-events: auto;
        transform: none;
        border-radius: 2px;
    }

    .tldr-toggle-btn::after {
        display: none;
    }

    .tldr-feedback {
        position: relative;
        top: auto;
        margin-bottom: var(--space-xs);
    }

    .tldr-highlight,
    .body-text.tldr-active {
        margin: -8px -12px;
        padding: 8px 12px;
    }
}

/* Mobile: smaller button */
@media (max-width: 480px) {
    .tldr-toggle-btn {
        font-size: 11px;
        padding: 6px 10px;
    }
}

/* ==========================================================================
   TLDR Toggle - Accessibility (Reduced Motion)
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    .tldr-toggle-btn {
        transition: none;
    }

    .body-text,
    .tldr-fading {
        transition: none;
    }

    .tldr-feedback {
        transition: none;
    }

    .tldr-highlight {
        transition: none;
    }
}

/* ==========================================================================
   Writings List Styles
   ========================================================================== */

.writings-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.writing-item {
    padding-bottom: var(--space-md);
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.writing-item:last-child {
    border-bottom: none;
}

.writing-link {
    display: block;
    text-decoration: none;
    color: inherit;
    transition: opacity 0.2s ease;
}

.writing-link:hover {
    opacity: 0.7;
}

.writing-link .heading-3 {
    margin-bottom: 8px;
}

.writing-link .body-text {
    margin: 0;
}

/* ==========================================================================
   Homepage Styles
   ========================================================================== */

/* Gradient Background - scrolls with page, base color controlled by JS */
.home-gradient {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 523px;
    background: linear-gradient(180deg,
            rgba(255, 255, 255, 0.3) 0%,
            #FFFFFF 100%),
        var(--home-base, #E0B2FF);
    pointer-events: none;
    z-index: -1;
}

/* Homepage Container - uses middle 4 columns (688px max) */
.home-container {
    width: 100%;
    max-width: var(--content-max);
    /* 688px */
    margin: 0 auto;
    padding-top: 120px;
    padding-bottom: var(--space-xxl);
    display: flex;
    flex-direction: column;
}

/* Homepage Section - consistent spacing */
.home-section {
    width: 100%;
}

/* Hero Section */
.home-hero {
    margin-bottom: var(--space-lg);
    /* 40px gap to intro */
}

.listings-hero {
    margin-bottom: var(--space-xxxl);
    /* 40px gap to intro */
}

/* Text Blocks - constrained width */
.home-text-block {
    max-width: 100%;
}

.home-text-block p {
    margin: 0;
}

.home-text-block p+p {
    margin-top: 24px;
    /* Paragraph spacing */
}

/* Intro Section */
.home-intro {
    margin-bottom: var(--space-xl);
    /* 60px to philosophy */
}

/* Philosophy Section */
.home-philosophy {
    margin-bottom: var(--space-xl);
    /* 60px to work section */
}

/* Work Section */
.home-work {
    margin-bottom: var(--space-lg);
    /* 40px to divider */
}

.home-work .heading-2 {
    margin-bottom: var(--space-sm);
    /* 24px below heading */
}

/* Project Cards */
.home-project {
    display: block;
    position: relative;
    margin-bottom: var(--space-sm);
    padding: 16px;
    margin-left: -16px;
    margin-right: -16px;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
}

/* Hover overlay using pseudo-element for smooth transition */
.home-project::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: linear-gradient(rgba(255, 255, 255, 0.6),
            rgba(255, 255, 255, 0.6)),
        var(--home-color, #E0B2FF);
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
    z-index: 0;
}

.home-project:hover::before {
    opacity: 1;
}

/* Ensure content is above the overlay */
.home-project>* {
    position: relative;
    z-index: 1;
}

.home-project:last-child {
    margin-bottom: 0;
}

.home-project .heading-3 {
    margin-bottom: 8px;
}

.home-project .body-text {
    margin: 0;
}

/* Homepage Divider */
.home-divider {
    display: flex;
    justify-content: center;
    align-items: center;
    border: none;
    background: transparent;
    height: auto;
    padding: var(--space-md) 0;
    margin: 0;
}

.home-divider::before {
    content: '';
    display: block;
    width: 264px;
    height: 10px;
    /* Use mask to allow dynamic coloring */
    background-color: var(--home-color, #E0B2FF);
    -webkit-mask-image: url('/assets/divider.svg');
    mask-image: url('/assets/divider.svg');
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: center;
    mask-position: center;
    -webkit-mask-size: contain;
    mask-size: contain;
    transition: background-color 0.3s ease;
}

/* Image Placeholder */
.home-image-placeholder {
    width: 100%;
    height: 74px;
    background-color: #d9d9d9;
    margin: var(--space-lg) 0;
}

/* Learning Section */
.home-learning {
    margin-bottom: var(--space-sm);
    /* 24px to grid */
}

/* Apps & Thoughts Grid */
.home-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-sm);
    /* 24px gap between columns */
    margin-bottom: var(--space-lg);
}

.home-grid-column {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    /* 24px between items */
}

.home-grid-item {
    position: relative;
    display: flex;
    flex-direction: column;
    padding: 16px;
    margin-left: -16px;
    margin-right: -16px;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
}

/* Hover overlay using pseudo-element for smooth transition */
.home-grid-item::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: linear-gradient(rgba(255, 255, 255, 0.8),
            rgba(255, 255, 255, 0.8)),
        var(--home-color, #E0B2FF);
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
    z-index: 0;
}

.home-grid-item:hover::before {
    opacity: 1;
}

/* Ensure content is above the overlay */
.home-grid-item>* {
    position: relative;
    z-index: 1;
}

.home-grid-item .caption {
    margin-bottom: 4px;
}

.home-grid-item .heading-3 {
    margin-bottom: 8px;
}

.home-grid-item .body-text {
    margin: 0;
}

/* CTA Section */
.home-cta {
    margin-top: var(--space-lg);
}

.home-cta .heading-2 {
    margin-bottom: var(--space-sm);
}

.home-cta .heading-2:last-child {
    margin-bottom: 0;
}

/* ==========================================================================
   Homepage Responsive
   ========================================================================== */

@media (max-width: 900px) {
    .home-container {
        padding-top: 80px;
    }

    .home-hero .heading-1 {
        font-size: 32px;
    }

    .home-text-block {
        width: 100%;
    }

    .home-grid {
        grid-template-columns: 1fr;
        gap: var(--space-md);
    }

    .home-work .heading-2,
    .home-learning .heading-2,
    .home-cta .heading-2 {
        font-size: 20px;
    }
}

@media (max-width: 480px) {
    .home-container {
        padding-top: 60px;
    }

    .home-hero .heading-1 {
        font-size: 28px;
    }

    .home-gradient {
        height: 400px;
    }
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
    .page-wrapper {
        padding: 0;
    }

    .article-section {
        padding: 0;
    }

    .tldr-toggle-wrapper {
        display: none;
    }
}