/* ============================================
   Timothy T.F. Chan — Personal Website Stylesheet
   ============================================ */

/* 1. Fonts — Calibri with system sans-serif fallbacks */

/* 2. CSS Custom Properties */
:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f5f5f5;
    --text-primary: #333333;
    --text-secondary: #666666;
    --text-heading: #111111;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --border: #e0e0e0;
    --link: #2563eb;
    --link-hover: #1d4ed8;
    --code-bg: #f5f5f5;
    --shadow: rgba(0, 0, 0, 0.06);

    --font-sans: 'Calibri', 'Carlito', -apple-system, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    --font-mono: 'Fira Code', 'Courier New', monospace;
    --content-width: 720px;
    --side-padding: 1.5rem;
}

[data-theme="dark"] {
    --bg-primary: #18181b;
    --bg-secondary: #27272a;
    --text-primary: #d4d4d8;
    --text-secondary: #a1a1aa;
    --text-heading: #fafafa;
    --accent: #60a5fa;
    --accent-hover: #93bbfd;
    --border: #3f3f46;
    --link: #60a5fa;
    --link-hover: #93bbfd;
    --code-bg: #27272a;
    --shadow: rgba(0, 0, 0, 0.4);
}

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-sans);
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--bg-primary);
    transition: background-color 0.2s ease, color 0.2s ease;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

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

/* 4. Typography */
h1, h2, h3, h4 {
    color: var(--text-heading);
    font-weight: 600;
    line-height: 1.3;
    margin-top: 1.6em;
    margin-bottom: 0.5em;
    transition: color 0.2s ease;
}

h1 { font-size: 1.75rem; line-height: 1.2; margin-top: 0; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; font-weight: 600; }
h4 { font-size: 1rem; font-weight: 600; }

p {
    margin-bottom: 1em;
}

a {
    color: var(--link);
    text-decoration: none;
    transition: color 0.2s ease;
}

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

blockquote {
    border-left: 3px solid var(--border);
    padding-left: 1em;
    margin: 1.5em 0;
    color: var(--text-secondary);
}

code {
    font-family: var(--font-mono);
    font-size: 0.85em;
    background: var(--code-bg);
    padding: 0.15em 0.4em;
    border-radius: 3px;
}

pre {
    background: var(--code-bg);
    padding: 1em 1.2em;
    border-radius: 4px;
    overflow-x: auto;
    margin: 1.5em 0;
}

pre code {
    background: none;
    padding: 0;
}

hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 2em 0;
}

ul, ol {
    margin-bottom: 1em;
    padding-left: 1.5em;
}

li {
    margin-bottom: 0.3em;
}

sup {
    font-size: 0.75em;
}

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

sup a:hover {
    color: var(--accent-hover);
}

/* 5. Layout */
.content-wrapper {
    max-width: var(--content-width);
    width: 100%;
    margin: 0 auto;
    padding: 2rem var(--side-padding);
    flex: 1;
}

/* 6. Navigation */
.site-header {
    border-bottom: 1px solid var(--border);
    transition: border-color 0.2s ease;
}

.site-nav {
    max-width: var(--content-width);
    margin: 0 auto;
    padding: 0.85rem var(--side-padding);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.site-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-heading);
    text-decoration: none;
    white-space: nowrap;
    letter-spacing: -0.01em;
}

.site-title:hover {
    color: var(--accent);
}

.nav-right {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

.nav-links {
    list-style: none;
    display: flex;
    gap: 1rem;
    padding: 0;
    margin: 0;
}

.nav-links a {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    transition: color 0.2s ease;
}

.nav-links a:hover,
.nav-links a.active {
    color: var(--text-heading);
}

#theme-toggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.3rem 0.4rem;
    cursor: pointer;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s ease, border-color 0.2s ease;
}

#theme-toggle:hover {
    color: var(--text-heading);
    border-color: var(--text-secondary);
}

#theme-toggle svg {
    width: 16px;
    height: 16px;
}

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

/* 7. Blog Styles */
.post-list {
    list-style: none;
    padding: 0;
}

.post-list li {
    margin-bottom: 1.5em;
    padding-bottom: 1.5em;
    border-bottom: 1px solid var(--border);
}

.post-list li:last-child {
    border-bottom: none;
}

.post-list h2 {
    font-size: 1.2rem;
    margin-top: 0;
    margin-bottom: 0.25em;
}

.post-list h2 a {
    color: var(--text-heading);
    text-decoration: none;
}

.post-list h2 a:hover {
    color: var(--accent);
}

.post-meta {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 0.4em;
}

.post-excerpt {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-bottom: 0;
}

/* Blog post page */
.blog-post .post-header {
    margin-bottom: 1.5em;
    padding-bottom: 0.75em;
    border-bottom: 1px solid var(--border);
}

.blog-post .post-header h1 {
    margin-bottom: 0.25em;
}

.blog-post .post-body {
    margin-bottom: 2em;
}

.blog-post .post-body img {
    margin: 1.5em auto;
    border-radius: 2px;
}

.blog-post .post-body .image-caption {
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: -1em;
    margin-bottom: 1.5em;
}

.post-footer {
    margin-top: 2.5em;
    padding-top: 1em;
    border-top: 1px solid var(--border);
}

.post-footer a {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

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

/* Footnotes */
.footnotes {
    margin-top: 2.5em;
    padding-top: 1em;
    border-top: 1px solid var(--border);
    font-size: 0.85rem;
}

.footnotes ol {
    padding-left: 1.2em;
}

.footnotes li {
    margin-bottom: 0.6em;
    color: var(--text-secondary);
}

.footnotes li p {
    margin-bottom: 0.3em;
}

.footnote-backref {
    text-decoration: none;
    margin-left: 0.3em;
}

/* 8. Resume Page Styles */
.cv-page h1 {
    margin-bottom: 1.25em;
}

.cv-section {
    margin-bottom: 2em;
}

.cv-section h2 {
    font-size: 1.15rem;
    margin-top: 0;
    margin-bottom: 0.6em;
    padding-bottom: 0.25em;
    border-bottom: 1px solid var(--border);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 600;
}

.cv-entry {
    margin-bottom: 1.25em;
}

.cv-entry h3 {
    margin-top: 0;
    margin-bottom: 0.15em;
    font-size: 1rem;
}

.cv-entry .cv-meta {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 0.3em;
}

/* 9. Footer */
.site-footer {
    border-top: 1px solid var(--border);
    margin-top: auto;
    transition: border-color 0.2s ease;
}

.footer-content {
    max-width: var(--content-width);
    margin: 0 auto;
    padding: 1.25rem var(--side-padding);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.footer-links {
    display: flex;
    gap: 1rem;
}

.footer-links a {
    color: var(--text-secondary);
    text-decoration: none;
}

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

/* 10. Utilities & Transitions */
.subtitle {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 1.25em;
}

.about-header {
    display: flex;
    align-items: flex-start;
    gap: 2rem;
}

.about-header > div {
    flex: 1;
}

.profile-photo {
    width: 180px;
    height: 180px;
    border-radius: 50%;
    object-fit: cover;
    object-position: 58% 22%;
    flex-shrink: 0;
}

.about-text {
    margin-bottom: 2em;
}

.section-heading {
    font-size: 1.2rem;
    margin-bottom: 0.75em;
}

/* 11. Responsive */
@media (max-width: 600px) {
    :root {
        --side-padding: 1rem;
    }

    .site-nav {
        flex-wrap: wrap;
    }

    .nav-links {
        gap: 0.8rem;
    }

    .footer-content {
        flex-direction: column;
        gap: 0.6rem;
        text-align: center;
    }

    .about-header {
        flex-direction: column-reverse;
        align-items: center;
        text-align: center;
    }

    h1 { font-size: 1.5rem; }
    h2 { font-size: 1.2rem; }
}
