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

/* Colors & Variables */
:root {
    --bg: #fafafa;
    --bg-card: #f5f5f5;
    --text: #111827;
    --text-light: #4b5563;
    --border: #e0e0e0;
    --accent: #3b82f6;
    --transition: all 0.2s;
    --shadow-light: 0 4px 12px rgba(0,0,0,0.1);
    --shadow-heavy: 0 8px 25px rgba(0,0,0,0.1);
    --radius: 6px;
    --radius-lg: 8px;
}

[data-theme="dark"] {
    --bg: #0f172a;
    --bg-card: #1e293b;
    --text: #f8fafc;
    --text-light: #cbd5e1;
    --border: #334155;
    --accent: #60a5fa;
    --shadow-light: 0 4px 12px rgba(0,0,0,0.3);
    --shadow-heavy: 0 8px 25px rgba(0,0,0,0.3);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0f172a;
        --bg-card: #1e293b;
        --text: #f8fafc;
        --text-light: #cbd5e1;
        --border: #334155;
        --accent: #60a5fa;
        --shadow-light: 0 4px 12px rgba(0,0,0,0.3);
        --shadow-heavy: 0 8px 25px rgba(0,0,0,0.3);
    }
}

/* Base Typography */
body {
    background: var(--bg);
    color: var(--text);
    font: 1.1rem/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    transition: var(--transition);
}

h1, h2, h3 {
    font-weight: 600;
    margin-bottom: 1rem;
}

h1 { font-size: 2.5rem; }
h2 { font-size: 2rem; }
h3 { font-size: 1.5rem; }

p {
    margin-bottom: 1rem;
    color: var(--text-light);
}

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

a:hover { color: var(--accent); }
a:focus { outline: 2px solid var(--accent); outline-offset: 2px; }

ul { list-style: none; }

/* Layout */
#main-container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 2rem;
}

hr {
    border: none;
    height: 1px;
    background: var(--border);
    margin: 3rem 0;
}

/* Title Section */
#title {
    text-align: center;
    margin-bottom: 4rem;
    padding: 2rem 0;
}

#title h1 {
    font-size: clamp(3rem, 8vw, 5rem);
    font-weight: 700;
    margin-bottom: 0.5rem;
}

#title h2 {
    font-size: 1.5rem;
    font-weight: 400;
    color: var(--text-light);
}

/* Section Headers */
#main-container > h2 {
    font-size: 2rem;
    margin: 4rem 0 2rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--border);
}

/* Social Icons */
#icons {
    display: flex;
    justify-content: center;
    gap: 2rem;
    margin-bottom: 2rem;
}

#icons a {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 3.5rem;
    height: 3.5rem;
    border: 2px solid var(--border);
    border-radius: 50%;
    transition: var(--transition);
}

#icons a:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
}

#icons svg {
    width: 1.5rem;
    height: 1.5rem;
    fill: var(--text);
}

/* Repository Grid */
#app {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    margin: 2rem 0;
}

/* Card Styles (shared by repo and external) */
#app a.repo,
#external > a {
    display: block;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    transition: var(--transition);
}

#app a.repo {
    padding: 1.5rem;
}

#external > a {
    padding: 2rem;
    margin-bottom: 2rem;
}

#app a.repo:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-heavy);
    border-color: var(--accent);
}

#external > a:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-light);
}

#app a.repo h3 {
    font-size: 1.25rem;
    margin-bottom: 0.75rem;
}

#app a.repo p {
    margin-bottom: 1rem;
    line-height: 1.5;
}

.app-stats {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.9rem;
    color: var(--text-light);
    margin: 0;
}

.app-stats svg {
    width: 1rem;
    height: 1rem;
    fill: var(--text-light);
}

/* Blog Posts */
#blog {
    margin: 2rem 0;
}

#blog li {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
    gap: 1rem;
}

#blog li:last-child { border-bottom: none; }

#blog a {
    font-weight: 500;
    flex: 1;
}

#blog .date {
    color: var(--text-light);
    font: italic 0.9rem/1 inherit;
    white-space: nowrap;
}

/* External Publications */
#external { margin: 2rem 0; }

#external h3 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

#external h4 {
    color: var(--text-light);
    font: italic 500 1rem/1 inherit;
    margin-bottom: 1rem;
}

#external img {
    float: left;
    margin: 0 2rem 1rem 0;
    width: 200px;
    border-radius: var(--radius);
}

#external p {
    line-height: 1.6;
    margin-bottom: 0.75rem;
}

#external a br { clear: both; }

/* Contact */
#contact {
    text-align: center;
    padding: 4rem 0 2rem;
    margin-top: 4rem;
    border-top: 1px solid var(--border);
}

#contact h2 {
    font-size: 2rem;
    margin-bottom: 1.5rem;
}

#contact a {
    display: inline-block;
    padding: 0.75rem 2rem;
    border: 2px solid var(--border);
    border-radius: 50px;
    font-weight: 500;
    transition: var(--transition);
}

#contact a:hover {
    border-color: var(--accent);
    color: var(--accent);
    transform: translateY(-1px);
}

/* Post Styles */
#post {
    max-width: 800px;
    margin: 0 auto;
    padding-bottom: 4rem;
}

#post #back {
    display: inline-block;
    margin-bottom: 2rem;
    padding: 0.5rem 1rem;
    color: var(--text-light);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: var(--transition);
}

#post #back:hover {
    background: var(--bg-card);
    color: var(--text);
}

#post h1 {
    font-size: 2.5rem;
    margin: 2rem 0;
    padding-left: 1.5rem;
    border-left: 4px solid var(--accent);
}

#post a {
    color: var(--accent);
    text-decoration: underline;
}

#post a:hover { text-decoration: none; }

#post ul {
    margin: 1.5rem 0;
    padding-left: 2rem;
}

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

#post img {
    margin: 2rem auto;
    display: block;
    max-width: 100%;
    border-radius: var(--radius);
}

#post figcaption {
    text-align: center;
    margin-top: 0.5rem;
    font: italic 0.9rem/1 inherit;
    color: var(--text-light);
}

#post table {
    border-spacing: 0;
    border-collapse: collapse;
    margin: 2rem auto;
    width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

#post table th,
#post table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
}

#post table th {
    background: var(--bg-card);
    font-weight: 600;
}

#post table tr:last-child td { border-bottom: none; }

#post #prev,
#post #next {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin: 2rem 0;
    transition: var(--transition);
    max-width: 45%;
}

#post #prev { float: left; }
#post #next { float: right; }

#post #prev:hover,
#post #next:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-light);
}

/* Code */
pre, code {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.9rem;
}

pre {
    padding: 1.5rem;
    margin: 1.5rem 0;
    overflow-x: auto;
    border-radius: var(--radius);
}

code {
    padding: 0.2rem 0.4rem;
}

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

/* Theme Switcher */
.theme-switcher {
    position: fixed;
    top: 1.5rem;
    right: 1.5rem;
    width: 2.5rem;
    height: 2.5rem;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--bg-card);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    z-index: 100;
}

.theme-switcher:hover {
    border-color: var(--accent);
    transform: scale(1.05);
}

.theme-switcher svg {
    width: 1.2rem;
    height: 1.2rem;
    fill: var(--text);
    transition: var(--transition);
}

/* Theme icon toggle logic */
.theme-switcher .sun-icon { display: none; }
.theme-switcher .moon-icon { display: block; }

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

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

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .theme-switcher .sun-icon {
        display: block;
    }
    
    :root:not([data-theme="light"]) .theme-switcher .moon-icon {
        display: none;
    }
}

/* RSS Icon */
h2 a svg {
    width: 1.2rem;
    height: 1.2rem;
    margin-left: 0.5rem;
    fill: var(--text-light);
    transition: var(--transition);
}

h2 a:hover svg { fill: var(--accent); }

/* Responsive */
@media (max-width: 768px) {
    #main-container { padding: 1rem; }
    
    #title {
        padding: 1rem 0;
        margin-bottom: 2rem;
    }
    
    #title h1 { font-size: 2.5rem; }
    
    #app {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    #blog li {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    
    #external img {
        float: none;
        display: block;
        margin: 0 auto 1rem;
        width: 100%;
        max-width: 300px;
    }
    
    #external > a { padding: 1.5rem; }
    
    #post #prev,
    #post #next {
        float: none;
        max-width: 100%;
        margin: 1rem 0;
    }
    
    .theme-switcher {
        top: 1rem;
        right: 1rem;
        width: 2.2rem;
        height: 2.2rem;
    }
    
    .theme-switcher svg {
        width: 1rem;
        height: 1rem;
    }
}
