/* ========================================
   CSS Variables
   ======================================== */
:root {
    --color-bg: #ffffff;
    --color-text: #1a1a1a;
    --color-text-secondary: #555555;
    --color-link: #0066cc;
    --color-link-hover: #004499;
    --color-border: #e0e0e0;
    --color-muted: #888888;
    
    --font-body: 'EB Garamond', Georgia, 'Times New Roman', serif;
    --font-size-base: 18px;
    --line-height: 1.7;
    
    --max-width: 720px;
    --spacing: 1.5rem;
}

[data-theme="dark"] {
    --color-bg: #1a1a1a;
    --color-text: #e8e8e8;
    --color-text-secondary: #b0b0b0;
    --color-link: #6db3f2;
    --color-link-hover: #9dcbf7;
    --color-border: #333333;
    --color-muted: #777777;
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-body);
    font-size: var(--font-size-base);
    line-height: var(--line-height);
    color: var(--color-text);
    background-color: var(--color-bg);
    -webkit-font-smoothing: antialiased;
    transition: background-color 0.3s ease, color 0.3s ease;
}

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

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

/* Override link styles for icon links */
a.social-icon,
a.social-icon:visited,
a.social-icon:link {
    color: var(--color-text-secondary);
    text-decoration: none;
}

ul, ol {
    list-style: none;
}

/* ========================================
   Layout
   ======================================== */
.container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 2rem var(--spacing) 4rem;
}

/* ========================================
   Header
   ======================================== */
.header {
    margin-bottom: 3rem;
    position: relative;
}

.name {
    font-size: 2rem;
    font-weight: 400;
    margin-bottom: 1rem;
    letter-spacing: 0.02em;
}

.nav {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
}

.nav-link {
    color: var(--color-text-secondary);
    font-size: 1rem;
    transition: color 0.2s ease;
}

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

.nav-link.active {
    color: var(--color-text);
    font-weight: 500;
}

/* Theme Toggle */
.theme-toggle {
    position: absolute;
    top: 0;
    right: 0;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    color: var(--color-text-secondary);
    transition: color 0.2s ease;
}

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

.theme-toggle svg {
    width: 20px;
    height: 20px;
    max-width: 20px;
    max-height: 20px;
}

.icon-moon {
    display: none;
}

[data-theme="dark"] .icon-sun {
    display: none;
}

[data-theme="dark"] .icon-moon {
    display: block;
}

/* ========================================
   Sections
   ======================================== */
.section {
    display: none;
}

.section.active {
    display: block;
}

.section h2 {
    font-size: 1.4rem;
    font-weight: 500;
    margin-bottom: 1rem;
    margin-top: 2rem;
}

.section h2:first-child {
    margin-top: 0;
}

.section h3 {
    font-size: 1.1rem;
    font-weight: 500;
    margin-top: 2rem;
    margin-bottom: 0.75rem;
    color: var(--color-text);
}

.section-desc {
    color: var(--color-text-secondary);
    margin-bottom: 1.5rem;
}

/* ========================================
   About / Home Section
   ======================================== */
.profile-row {
    display: flex;
    gap: 1.5rem;
    align-items: flex-start;
    margin-bottom: 2rem;
}

.profile-image {
    flex-shrink: 0;
}

.profile-placeholder {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: var(--color-border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 500;
    color: var(--color-text-secondary);
}

.profile-intro p {
    margin-bottom: 0.75rem;
}

.about-main > p {
    margin-bottom: 0.75rem;
}

.links-row {
    margin-top: 1rem;
}

.links-row a {
    white-space: nowrap;
}

/* Social Icons */
.social-icons {
    display: flex;
    gap: 0.75rem;
    margin-top: 1rem;
}

.social-icons a.social-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    color: var(--color-text-secondary);
    transition: color 0.2s ease, transform 0.2s ease;
    text-decoration: none;
}

.social-icons a.social-icon:hover {
    color: var(--color-link);
    transform: translateY(-2px);
    text-decoration: none;
}

.social-icons a.social-icon svg {
    width: 22px;
    height: 22px;
    max-width: 22px;
    max-height: 22px;
    flex-shrink: 0;
}

.social-icons a.social-icon svg path {
    fill: #555555;
    transition: fill 0.2s ease;
}

.social-icons a.social-icon:hover svg path {
    fill: var(--color-link);
}

[data-theme="dark"] .social-icons a.social-icon svg path {
    fill: #b0b0b0;
}

[data-theme="dark"] .social-icons a.social-icon:hover svg path {
    fill: var(--color-link);
}

.interests-list {
    margin-left: 0;
}

.interests-list li {
    margin-bottom: 0.5rem;
    padding-left: 1.25rem;
    position: relative;
}

.interests-list li::before {
    content: "•";
    position: absolute;
    left: 0;
    color: var(--color-muted);
}

/* ========================================
   Data Tables
   ======================================== */
.data-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1.5rem;
}

.data-table td {
    padding: 0.5rem 0;
    vertical-align: top;
    border-bottom: 1px solid var(--color-border);
}

.data-table tr:last-child td {
    border-bottom: none;
}

.date-col {
    width: 100px;
    color: var(--color-muted);
    font-size: 0.95rem;
    white-space: nowrap;
    padding-right: 1rem;
}

.project-name {
    width: 140px;
    font-weight: 500;
    padding-right: 1rem;
}

.authors {
    display: block;
    color: var(--color-text-secondary);
    font-size: 0.9rem;
    margin-top: 0.15rem;
}

.venue {
    display: block;
    color: var(--color-text-secondary);
    font-style: italic;
    margin-top: 0.15rem;
}

.tech-stack {
    color: var(--color-muted);
    font-size: 0.9rem;
}

.download-link {
    font-weight: 500;
}

/* ========================================
   Footer
   ======================================== */
.footer {
    margin-top: 4rem;
    padding-top: 2rem;
    border-top: 1px solid var(--color-border);
    color: var(--color-muted);
    font-size: 0.9rem;
}

/* ========================================
   Responsive
   ======================================== */
@media (max-width: 600px) {
    :root {
        --font-size-base: 16px;
    }
    
    .container {
        padding: 1.5rem 1rem 3rem;
    }
    
    .name {
        font-size: 1.6rem;
        padding-right: 40px;
    }
    
    .nav {
        gap: 1rem;
    }
    
    .profile-row {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }
    
    .profile-placeholder {
        width: 80px;
        height: 80px;
        font-size: 1.25rem;
    }
    
    .interests-list li {
        text-align: left;
    }
    
    .date-col {
        width: 80px;
        font-size: 0.85rem;
    }
    
    .project-name {
        width: 100px;
    }
    
    .data-table td {
        font-size: 0.95rem;
    }

    .post-title {
        font-size: 1.6rem;
    }
}

/* ========================================
   Blog Post
   ======================================== */
.post {
    max-width: var(--max-width);
}

.back-link {
    display: inline-block;
    margin-bottom: 2.5rem;
    font-size: 0.95rem;
    color: var(--color-text-secondary);
}

.post-title {
    font-size: 2rem;
    font-weight: 600;
    line-height: 1.25;
    margin-bottom: 0.6rem;
}

.post-meta {
    color: var(--color-muted);
    font-size: 0.95rem;
    margin-bottom: 2.5rem;
}

.post-lede {
    font-size: 1.1rem;
    color: var(--color-text-secondary);
    margin-bottom: 2rem;
}

.post h2 {
    font-size: 1.4rem;
    font-weight: 600;
    margin-top: 2.75rem;
    margin-bottom: 1rem;
}

.post h3 {
    font-size: 1.15rem;
    font-weight: 600;
    margin-top: 1.75rem;
    margin-bottom: 0.75rem;
}

.post p {
    margin-bottom: 1.15rem;
}

.post ul, .post ol {
    margin: 0 0 1.15rem 1.5rem;
}

.post li {
    margin-bottom: 0.5rem;
}

.post blockquote {
    border-left: 3px solid var(--color-border);
    padding-left: 1.1rem;
    margin: 1.5rem 0;
    color: var(--color-text-secondary);
    font-style: italic;
}

.post code {
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.85em;
    background: var(--color-border);
    padding: 0.1em 0.35em;
    border-radius: 4px;
}

/* Horizontal scroll for wide display equations on small screens */
.post .math-display {
    overflow-x: auto;
    overflow-y: hidden;
    margin: 1.5rem 0;
    padding: 0.4rem 0;
}

.post hr {
    border: none;
    border-top: 1px solid var(--color-border);
    margin: 2.75rem 0;
}

.post .callout {
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 1rem 1.25rem;
    margin: 1.75rem 0;
    background: rgba(127, 127, 127, 0.07);
}

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

.post .footnote-ref {
    font-size: 0.75em;
    vertical-align: super;
    line-height: 0;
}

.post-refs {
    margin-top: 2rem;
    font-size: 0.95rem;
    color: var(--color-text-secondary);
}

/* ---- Jacobian counterexample article ---- */
.post-kicker {
    margin-bottom: 0.65rem !important;
    color: var(--color-link);
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.result-banner {
    display: grid;
    grid-template-columns: 5rem 1fr;
    gap: 1.25rem;
    align-items: start;
    margin: 2.25rem 0 2.75rem;
    padding: 1rem 0;
    border-top: 1px solid var(--color-border);
    border-bottom: 1px solid var(--color-border);
}

.result-banner p {
    margin: 0;
}

.result-label {
    color: var(--color-muted);
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.theorem-box {
    margin: 1.8rem 0;
    padding: 1.2rem 0;
    border-top: 2px solid var(--color-text);
    border-bottom: 1px solid var(--color-text);
}

.theorem-box p {
    margin-bottom: 0;
    font-size: 1.08rem;
}

.theorem-box .theorem-label {
    margin-bottom: 0.45rem;
    color: var(--color-muted);
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.scope-strip {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    margin: 2rem 0;
    border-top: 1px solid var(--color-border);
    border-bottom: 1px solid var(--color-border);
}

.scope-strip > div {
    padding: 1.05rem 1rem 1.1rem;
}

.scope-strip > div + div {
    border-left: 1px solid var(--color-border);
}

.scope-strip p {
    margin-bottom: 0.35rem;
}

.scope-strip .scope-dimension {
    font-size: 1.25rem;
    font-weight: 600;
}

.scope-strip .scope-status {
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.scope-status.is-settled { color: #1e8449; }
.scope-status.is-open { color: #a26019; }
.scope-status.is-false { color: #b33a32; }

[data-theme="dark"] .scope-status.is-settled { color: #78c99a; }
[data-theme="dark"] .scope-status.is-open { color: #e8ad62; }
[data-theme="dark"] .scope-status.is-false { color: #ef8c84; }

.counterexample-equation {
    font-size: 0.94em;
}

.proof-ledger {
    display: grid;
    grid-template-columns: 1fr 1fr;
    margin: 2rem 0;
    border-top: 1px solid var(--color-border);
    border-bottom: 1px solid var(--color-border);
}

.proof-ledger > div {
    padding: 1.2rem 1.25rem 1.25rem 0;
}

.proof-ledger > div + div {
    padding-left: 1.25rem;
    border-left: 1px solid var(--color-border);
}

.proof-ledger p {
    margin-bottom: 0.4rem;
}

.proof-ledger .proof-step {
    color: var(--color-muted);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.proof-ledger .proof-result {
    font-size: 1.15rem;
    font-weight: 600;
}

.table-scroll {
    margin: 1.75rem 0;
    overflow-x: auto;
    border-top: 1px solid var(--color-border);
    border-bottom: 1px solid var(--color-border);
}

.fiber-table {
    width: 100%;
    min-width: 520px;
    border-collapse: collapse;
}

.fiber-table th,
.fiber-table td {
    padding: 0.75rem 0.7rem;
    border-bottom: 1px solid var(--color-border);
    text-align: left;
    vertical-align: middle;
}

.fiber-table tr:last-child th,
.fiber-table tr:last-child td {
    border-bottom: none;
}

.fiber-table thead th {
    color: var(--color-muted);
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.fiber-table tbody th {
    color: var(--color-text-secondary);
    font-weight: 500;
}

.derivation {
    margin: 1.25rem 0;
    border-top: 1px solid var(--color-border);
    border-bottom: 1px solid var(--color-border);
}

.derivation + .derivation {
    margin-top: -1.26rem;
    border-top: none;
}

.derivation summary {
    padding: 0.9rem 2rem 0.9rem 0;
    position: relative;
    cursor: pointer;
    color: var(--color-link);
    font-weight: 500;
    list-style: none;
}

.derivation summary::-webkit-details-marker {
    display: none;
}

.derivation summary::after {
    content: "+";
    position: absolute;
    right: 0;
    color: var(--color-muted);
    font-size: 1.2rem;
    font-weight: 400;
}

.derivation[open] summary::after {
    content: "−";
}

.derivation-body {
    padding: 0.3rem 0 0.75rem;
    color: var(--color-text-secondary);
}

.derivation-body .math-display {
    color: var(--color-text);
}

.root-choice .root-mark {
    fill: #e8833a;
    fill-opacity: 0.18;
    stroke: #e8833a;
    stroke-width: 2;
}

.root-choice .root-plain {
    fill: var(--color-bg);
    stroke: var(--color-muted);
    stroke-width: 1.5;
}

.root-choice .root-letter {
    font-size: 14px;
    text-anchor: middle;
}

.source-list {
    margin-left: 1.25rem !important;
    list-style: decimal !important;
}

.source-list li {
    padding-left: 0.25rem;
    margin-bottom: 0.65rem;
}

.verification-note {
    margin-top: 1.15rem;
    font-style: italic;
}

.post-back-link {
    margin-top: 2rem;
}

@media (max-width: 600px) {
    .result-banner {
        grid-template-columns: 1fr;
        gap: 0.35rem;
    }

    .scope-strip,
    .proof-ledger {
        grid-template-columns: 1fr;
    }

    .scope-strip > div + div,
    .proof-ledger > div + div {
        border-top: 1px solid var(--color-border);
        border-left: none;
    }

    .proof-ledger > div,
    .proof-ledger > div + div {
        padding: 1rem 0;
    }

    .counterexample-equation {
        font-size: 0.82em;
    }
}

/* ---- Figures & diagrams ---- */
.figure {
    margin: 2rem 0;
}

.figure svg {
    display: block;
    width: 100%;
    height: auto;
    max-width: 480px;
    margin: 0 auto;
}

.figure figcaption {
    font-size: 0.9rem;
    color: var(--color-muted);
    margin-top: 0.75rem;
    text-align: center;
    line-height: 1.5;
}

/* SVG diagram element classes (theme-aware via CSS variables) */
.dg-grid   { stroke: var(--color-border); stroke-width: 1; }
.dg-axis   { stroke: var(--color-muted); stroke-width: 1.5; }
.dg-curve  { stroke: var(--color-link); stroke-width: 2.5; fill: none; }
.dg-tangent{ stroke: #e8833a; stroke-width: 2; stroke-dasharray: 6 4; fill: none; }
.dg-ghost  { stroke: var(--color-muted); stroke-width: 1.5; stroke-dasharray: 4 4; fill: none; }
.dg-vec    { stroke: var(--color-text); stroke-width: 2.5; }
.dg-vec-accent { stroke: #e8833a; stroke-width: 2.5; }
.dg-fill   { fill: var(--color-link); fill-opacity: 0.10; stroke: var(--color-link); stroke-width: 2; }
.dg-dot    { fill: var(--color-text); }
.dg-dot-accent { fill: #e8833a; }
.dg-head   { fill: var(--color-text); }
.dg-head-accent { fill: #e8833a; }
.dg-label      { fill: var(--color-text); font-family: var(--font-body); font-size: 14px; }
.dg-label-muted{ fill: var(--color-muted); font-family: var(--font-body); font-size: 13px; }
.dg-label-accent { fill: #e8833a; font-family: var(--font-body); font-size: 14px; }

/* ---- Worked-example comparison box ---- */
.compare {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin: 1.75rem 0;
}

.compare > div {
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 1rem 1.1rem;
}

.compare .verdict-wrong { color: #c0392b; font-weight: 600; }
.compare .verdict-right { color: #1e8449; font-weight: 600; }

@media (max-width: 600px) {
    .compare { grid-template-columns: 1fr; }
}

/* ---- Interactive 3D ---- */
.threed {
    margin: 2rem 0;
}

.threed-stage {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 10;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    overflow: hidden;
    background: rgba(127, 127, 127, 0.04);
    touch-action: none;
}

.threed-stage canvas { display: block; width: 100% !important; height: 100% !important; }

.threed-fallback {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    text-align: center;
    color: var(--color-muted);
    font-size: 0.95rem;
}
