/* ========================================
   CSS Variables & Base Styles
   ======================================== */
:root {
    --bg-color: #F5F5F5;
    --card-bg: #D7DEDB;
    --primary-color: #2C3A33;
    --secondary-color: #5A6E65;
    --icon-color: #41514B;

    --card-border: rgba(44, 58, 51, 0.08);
    --card-shadow: 0 4px 12px rgba(44, 58, 51, 0.08),
        0 8px 24px rgba(44, 58, 51, 0.06),
        0 12px 32px rgba(44, 58, 51, 0.04);
    --card-shadow-hover: 0 8px 20px rgba(44, 58, 51, 0.12),
        0 16px 40px rgba(44, 58, 51, 0.10),
        0 24px 56px rgba(44, 58, 51, 0.06);

    --code-bg: rgba(255, 255, 255, 0.7);
    --code-border: rgba(44, 58, 51, 0.08);

    --toggle-hover-bg: rgba(44, 58, 51, 0.06);
    
    --site-width: 640px;
    --top-spacing: 100px;
    --large-gap: 50px;
    --small-gap: 20px;
    
    --font-large: 14pt;
    --font-medium: 12pt;
    --font-small: 10pt;

    /* Post page: table-of-contents rail background (semi-opaque, used with blur). */
    --toc-bg: rgba(245, 245, 245, 0.82);

    /* Inform the browser we're designing for light by default (overridden below). */
    color-scheme: light;
}

/* System default: dark */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #19231F;
        --card-bg: #2C3A33;
        --primary-color: #9CACA6;
        --secondary-color: #5A6E65;
        --icon-color: #9CACA6;

        --card-border: #233129;
        --card-shadow: 0 4px 12px rgba(0, 0, 0, 0.28),
            0 8px 24px rgba(0, 0, 0, 0.22),
            0 12px 32px rgba(0, 0, 0, 0.16);
        --card-shadow-hover: 0 8px 20px rgba(0, 0, 0, 0.34),
            0 16px 40px rgba(0, 0, 0, 0.26),
            0 24px 56px rgba(0, 0, 0, 0.18);

        --code-bg: #2C3A33;
        --code-border: #233129;

        --toggle-hover-bg: rgba(156, 172, 166, 0.06);

        --toc-bg: rgba(25, 35, 31, 0.78);

        color-scheme: dark;
    }
}

/* Explicit theme overrides (user-selected) */
:root[data-theme="light"] {
    --bg-color: #F5F5F5;
    --card-bg: #D7DEDB;
    --primary-color: #2C3A33;
    --secondary-color: #5A6E65;
    --icon-color: #41514B;

    --card-border: rgba(44, 58, 51, 0.08);
    --card-shadow: 0 4px 12px rgba(44, 58, 51, 0.08),
        0 8px 24px rgba(44, 58, 51, 0.06),
        0 12px 32px rgba(44, 58, 51, 0.04);
    --card-shadow-hover: 0 8px 20px rgba(44, 58, 51, 0.12),
        0 16px 40px rgba(44, 58, 51, 0.10),
        0 24px 56px rgba(44, 58, 51, 0.06);

    --code-bg: rgba(255, 255, 255, 0.7);
    --code-border: rgba(44, 58, 51, 0.08);

    --toggle-hover-bg: rgba(44, 58, 51, 0.06);

    --toc-bg: rgba(245, 245, 245, 0.82);

    color-scheme: light;
}

:root[data-theme="dark"] {
    --bg-color: #19231F;
    --card-bg: #2C3A33;
    --primary-color: #9CACA6;
    --secondary-color: #5A6E65;
    --icon-color: #9CACA6;

    --card-border: #233129;
    --card-shadow: 0 4px 12px rgba(0, 0, 0, 0.28),
        0 8px 24px rgba(0, 0, 0, 0.22),
        0 12px 32px rgba(0, 0, 0, 0.16);
    --card-shadow-hover: 0 8px 20px rgba(0, 0, 0, 0.34),
        0 16px 40px rgba(0, 0, 0, 0.26),
        0 24px 56px rgba(0, 0, 0, 0.18);

    --code-bg: #2C3A33;
    --code-border: #233129;

    --toggle-hover-bg: rgba(156, 172, 166, 0.06);

    --toc-bg: rgba(25, 35, 31, 0.78);

    color-scheme: dark;
}

/* ========================================
   Reset & Base
   ======================================== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

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

body {
    font-family: 'Lato', sans-serif;
    background-color: var(--bg-color);
    color: var(--primary-color);
    line-height: 1.6;
    min-height: 100vh;
}

/* ========================================
   Container
   ======================================== */
.container {
    max-width: var(--site-width);
    margin: 0 auto;
    padding: var(--top-spacing) 20px 60px;
}

/* ========================================
   Links
   ======================================== */
a {
    color: inherit;
    text-decoration: none;
}

.link {
    font-weight: 700;
    text-decoration: underline;
    text-underline-offset: 2px;
    transition: opacity 0.2s ease;
}

.link:hover {
    opacity: 0.7;
}

/* ========================================
   Header
   ======================================== */
.header {
    margin-bottom: var(--large-gap);
}

.email-link {
    font-size: var(--font-large);
    font-weight: 700;
    color: var(--primary-color);
    text-decoration: none;
    transition: opacity 0.2s ease;
}

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

/* ========================================
   Intro Section
   ======================================== */
.intro {
    margin-bottom: var(--large-gap);
}

.intro p {
    font-size: var(--font-large);
    color: var(--secondary-color);
    line-height: 1.7;
}

.intro .link {
    color: var(--secondary-color);
}

/* ========================================
   Sections
   ======================================== */
.section {
    margin-bottom: var(--large-gap);
}

.section-header {
    font-size: var(--font-large);
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: var(--small-gap);
    display: flex;
    align-items: center;
    gap: 8px;
}

.section-header .link {
    font-weight: 700;
}

/* ========================================
   Lazy Reveal (progressive enhancement)
   - Applies to "Everything else" cards (and anything else tagged with `.lazy-card`).
   - Only enabled when JS is available.
   ======================================== */
.js .lazy-card {
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.35s ease, transform 0.35s ease;
    will-change: opacity, transform;
}

.js .lazy-card.is-visible {
    opacity: 1;
    transform: translateY(0);
}

@media (prefers-reduced-motion: reduce) {
    .js .lazy-card {
        opacity: 1;
        transform: none;
        transition: none;
        will-change: auto;
    }
}

/* ========================================
   Top of Mind Cards (Large Cards)
   ======================================== */
.top-cards {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.top-card {
    text-decoration: none;
    display: block;
}

.top-card-icon-wrapper {
    background: var(--card-bg);
    border-radius: 12px;
    border: 1px solid var(--card-border);
    padding: 60px 40px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), 
                box-shadow 0.3s ease;
    box-shadow: var(--card-shadow);
}

.top-card:hover .top-card-icon-wrapper {
    transform: translateY(-4px);
    box-shadow: var(--card-shadow-hover);
}

.top-card-icon {
    width: 60px;
    height: 60px;
    color: var(--icon-color);
}

.top-card-icon svg {
    width: 100%;
    height: 100%;
}

/* ========================================
   Single-color SVG icons (CSS masking)
   - Ensures all SVGs render in the same color using currentColor.
   ======================================== */
.icon-mask {
    width: 100%;
    height: 100%;
    display: block;
    background-color: currentColor;
    -webkit-mask-image: var(--icon-image);
    mask-image: var(--icon-image);
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: center;
    mask-position: center;
    -webkit-mask-size: contain;
    mask-size: contain;
}

.top-card-title {
    font-size: var(--font-medium);
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 2px;
}

.top-card-subtitle {
    font-size: var(--font-small);
    color: var(--secondary-color);
    font-weight: 700;
}

/* ========================================
   Small Cards (Everything Else)
   ======================================== */
.small-cards {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.small-card {
    display: flex;
    align-items: center;
    gap: 20px;
    text-decoration: none;
}

.small-card-icon-wrapper {
    flex-shrink: 0;
    width: 115px;
    height: 75px;
    background: var(--card-bg);
    border-radius: 12px;
    border: 1px solid var(--card-border);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), 
                box-shadow 0.3s ease;
    box-shadow: var(--card-shadow);
}

.small-card:hover .small-card-icon-wrapper {
    /* Subtler hover "lift" for the smaller Everything Else cards */
    transform: translateY(-2px);
    box-shadow: var(--card-shadow-hover);
}

/* ========================================
   Theme Toggle (fixed, top-right)
   ======================================== */
.theme-toggle {
    position: fixed;
    top: max(16px, env(safe-area-inset-top));
    right: max(16px, env(safe-area-inset-right));
    width: 40px;
    height: 40px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: transparent;
    border: 1px solid transparent;
    color: var(--icon-color);
    opacity: 0.28;
    cursor: pointer;
    transition: opacity 0.2s ease, background-color 0.2s ease, border-color 0.2s ease,
        transform 0.2s ease;
    z-index: 2000;
}

.theme-toggle:hover {
    opacity: 0.65;
    background-color: var(--toggle-hover-bg);
    border-color: var(--card-border);
}

.theme-toggle:active {
    transform: translateY(1px);
}

.theme-toggle:focus-visible {
    opacity: 0.85;
    outline: 2px solid var(--primary-color);
    outline-offset: 3px;
}

.theme-toggle__icon {
    width: 18px;
    height: 18px;
    display: block;
}

:root[data-theme="dark"] .theme-toggle__icon--moon {
    display: none;
}

:root[data-theme="light"] .theme-toggle__icon--sun {
    display: none;
}

.small-card-icon {
    /*
      Everything else card icons:
      - Normalize by HEIGHT (match the Cursor icon height)
      - Allow wider icons (e.g. wordmarks) to grow proportionally in width
        instead of being squeezed into a square and looking tiny.
      - Cap max width so extra-wide logos (e.g. handyainews) don't dominate.
    */
    width: 100%;
    max-width: 60px;
    height: 34px;
    color: var(--icon-color);
}

.small-card-icon svg {
    width: 100%;
    height: 100%;
    display: block;
}

.small-card-content {
    flex: 1;
    min-width: 0;
}

.small-card-title {
    font-size: var(--font-medium);
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 2px;
}

.small-card-subtitle {
    font-size: var(--font-small);
    color: var(--secondary-color);
    font-weight: 700;
    line-height: 1.4;
}

/* ========================================
   Responsive Design
   ======================================== */
@media (max-width: 520px) {
    .container {
        padding: 60px 16px 40px;
    }
    
    .top-cards {
        grid-template-columns: 1fr;
    }
    
    .small-card {
        padding: 14px;
    }
    
    .small-card-icon-wrapper {
        /*
          On narrow screens we increase the icon wrapper width slightly so
          wide icons can still render at the same height as the Cursor icon.
        */
        width: 140px;
    }

    .small-card-icon {
        width: 100%;
        max-width: 110px;
        height: 48px;
    }
}

/* ========================================
   Smooth Scrolling & Selection
   ======================================== */
html {
    scroll-behavior: smooth;
}

::selection {
    background: var(--primary-color);
    color: var(--bg-color);
}

/* ========================================
   Focus States (Accessibility)
   ======================================== */
a:focus-visible,
.top-card:focus-visible,
.small-card:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

