:root {
    /* Light Theme */
    --bg-color: #fafafa;
    --bg-rgb: 250, 250, 250;
    --surface-color: #ffffff;
    --text-color: #171717;
    --secondary-text: #525252;
    --accent-color: #2563eb;
    --accent-hover: #1d4ed8;
    --border-color: #e5e5e5;
    --code-bg: #f4f4f5;
    
    /* Typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', Consolas, monospace;
    
    /* Layout */
    --max-width: 1100px;
    --spacing-unit: 1.25rem;
    --spacing-section: 2.5rem;
    --header-height: 70px;
    
    /* Effects */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --radius-sm: 0.25rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

@media (min-width: 1400px) {
    :root { --max-width: 1320px; }
}

@media (min-width: 1600px) {
    :root { --max-width: 1500px; }
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #0a0a0a;
        --bg-rgb: 10, 10, 10;
        --surface-color: #171717;
        --text-color: #ededed;
        --secondary-text: #a3a3a3;
        --accent-color: #3b82f6;
        --accent-hover: #60a5fa;
        --border-color: #262626;
        --code-bg: #1f1f1f;
        
        --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.5);
        --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.5), 0 2px 4px -2px rgb(0 0 0 / 0.5);
    }
}

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

body {
    font-family: var(--font-sans);
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.7;
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -0.025em;
    margin-bottom: 1rem;
    color: var(--text-color);
}

h1 { font-size: 2.75rem; margin-bottom: 1rem; }
h2 { font-size: 2rem; margin-top: 2rem; margin-bottom: 1rem; }
h3 { font-size: 1.5rem; margin-top: 1.25rem; margin-bottom: 0.75rem; }

p { margin-bottom: 1.5rem; color: var(--secondary-text); }

a {
    color: var(--text-color);
    text-decoration: none;
    transition: var(--transition);
    border-bottom: 1px solid transparent;
}

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

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

/* Header & Nav */
header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 50;
    background-color: rgba(var(--bg-rgb), 0.9);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid transparent;
    transition: var(--transition);
}

header.scrolled {
    border-bottom-color: var(--border-color);
    background-color: rgba(var(--bg-rgb), 0.95);
}

.header-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.logo {
    font-weight: 800;
    font-size: 1.25rem;
    letter-spacing: -0.03em;
}

nav ul {
    display: flex;
    gap: 2rem;
    list-style: none;
}

nav a {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--secondary-text);
    display: inline-block;
    padding: 0.35rem 0;
    cursor: pointer;
}

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

/* Main Content — fade in after layout ready to avoid load glitch (no-JS: always visible) */
main {
    flex: 1;
    padding-top: 2rem;
    padding-bottom: 2.5rem;
    transition: opacity 0.12s ease-out;
}
html.js main {
    opacity: 0;
}
html.js.loaded main {
    opacity: 1;
}

/* Cards */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.25rem;
    margin-top: 1.25rem;
}

.card {
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    padding: 1.25rem;
    border-radius: var(--radius-lg);
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Hover only on cards that are links (not on static cards e.g. Contact, Lab welcome) */
a.card:hover {
    transform: translateY(-2px);
    border-color: var(--accent-color);
    box-shadow: var(--shadow-lg);
}

.card h3 {
    margin-top: 0;
    margin-bottom: 0.5rem;
    font-size: 1.25rem;
}

.card p {
    font-size: 0.95rem;
    margin-bottom: 1rem;
    flex-grow: 1;
}

/* Tags */
.tag {
    display: inline-flex;
    align-items: center;
    background-color: var(--code-bg);
    color: var(--secondary-text);
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
    margin-right: 0.5rem;
    margin-bottom: 0.5rem;
    border: 1px solid var(--border-color);
}

/* Buttons / Links */
.btn-link {
    display: inline-flex;
    align-items: center;
    font-weight: 600;
    color: var(--accent-color);
    margin-top: 1rem;
}

.btn-link:hover {
    color: var(--accent-hover);
    transform: translateX(2px);
}

/* Post Meta */
.post-meta {
    font-size: 0.875rem;
    color: var(--secondary-text);
    margin-bottom: 0.5rem;
    font-family: var(--font-mono);
}

/* Footer */
footer {
    margin-top: auto;
    padding: 2rem 0;
    border-top: 1px solid var(--border-color);
    color: var(--secondary-text);
    font-size: 0.875rem;
}

.footer-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.footer-links a {
    padding: 0.35rem 0;
    border: none;
}
.footer-links a:hover {
    color: var(--accent-color);
}

/* Interactive controls: clear boundaries and cursor */
button,
[type="button"],
[type="submit"],
input[type="submit"] {
    cursor: pointer;
    min-height: 2.25rem;
}
button:disabled,
[disabled] {
    cursor: not-allowed;
    opacity: 0.7;
}

/* Lab tool textarea: fill available viewport; --lab-fill set in Lab _Layout */
.lab-textarea-fill {
    min-height: clamp(6rem, var(--lab-fill, 240px), 70vh);
    resize: vertical;
}
.lab-textarea-fill-split {
    min-height: clamp(5rem, calc(var(--lab-fill, 240px) * 0.45), 35vh);
    resize: vertical;
}

/* Lab Specific */
.lab-header {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--accent-color);
    background: rgba(37, 99, 235, 0.1);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    display: inline-block;
}

/* Markdown Content */
.markdown-body {
    font-size: 1.05rem;
    max-width: 65ch; /* Optimal reading width */
}

.markdown-body h2 { border-bottom: 1px solid var(--border-color); padding-bottom: 0.5rem; }
.markdown-body pre {
    background-color: var(--code-bg);
    padding: 1rem;
    border-radius: var(--radius-md);
    overflow-x: auto;
    margin-bottom: 1.5rem;
    border: 1px solid var(--border-color);
}
.markdown-body code {
    font-family: var(--font-mono);
    font-size: 0.9em;
}
.markdown-body p code {
    background-color: var(--code-bg);
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
}

.markdown-body blockquote {
    border-left: 4px solid var(--accent-color);
    padding-left: 1rem;
    color: var(--secondary-text);
    font-style: italic;
    margin-bottom: 1.5rem;
}

/* Blog Posts */
.post-header {
    height: fit-content;  
    display: block;
    margin-bottom: 1rem;
}

.post-header h1 {
    font-size: 3rem;
    margin-bottom: 0;
    letter-spacing: -0.04em;
}

.post-meta-container {
    text-align: right;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0rem;
}

.post-list {
    list-style: none;
    margin-top: 2rem;
    max-width: 800px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.post-item {
    margin-bottom: 0;
    transition: var(--transition);
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
}

.post-item a {
    display: block;
    border: none;
}

.post-item:hover {
    border-color: var(--accent-color);
    box-shadow: var(--shadow-md);
}

.post-item:hover h3 {
    color: var(--accent-color);
}

.post-item h3 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.post-item p {
    color: var(--secondary-text);
    margin-bottom: 0.5rem;
}

.back-link {
    margin-top: 2.5rem;
    display: inline-block;
    font-weight: 500;
    color: var(--secondary-text);
}

.back-link:hover {
    color: var(--accent-color);
}

/* Home / section headings with action link */
.section-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 1.25rem;
}
.section-head h2 {
    margin: 0;
    font-size: 2rem;
}
.section-write {
    display: grid;
    gap: 1.25rem;
}
.section-write .card {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
}
.section-write .card h3 {
    margin: 0;
    font-size: 1.25rem;
}
.section-write .post-meta {
    margin: 0.5rem 0 0;
}
.section-write .card-arrow {
    color: var(--accent-color);
}

.home-hero {
    margin-top: 0.5rem;
    margin-bottom: var(--spacing-section);
}
@media (min-width: 1024px) {
    .home-hero {
        padding-top: 3rem;
    }
}
.home-title {
    font-size: 3.5rem;
    margin-bottom: 1rem;
    line-height: 1.1;
    background: linear-gradient(to right, var(--text-color), var(--secondary-text));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    display: inline-block;
}
.home-subtitle {
    font-size: 1.25rem;
    color: var(--secondary-text);
    max-width: 600px;
    line-height: 1.6;
}
.home-section {
    margin-bottom: var(--spacing-section);
}
.home-section:last-child {
    margin-bottom: 0;
}

.contact-intro {
    margin-bottom: 1.5rem;
    color: var(--secondary-text);
}
.contact-form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    max-width: 32rem;
}
.contact-validation {
    color: #b91c1c;
    font-size: 0.9rem;
    list-style: none;
    padding: 0;
    margin: 0;
}
.contact-validation ul {
    list-style: none;
    padding: 0;
    margin: 0;
}
.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}
.form-label {
    font-weight: 600;
    font-size: 0.95rem;
}
.form-optional {
    font-weight: 400;
    color: var(--secondary-text);
    font-size: 0.85rem;
}
.form-input {
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-sans);
    font-size: 1rem;
}
.form-input:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
.form-textarea {
    resize: vertical;
    min-height: 8rem;
}
.btn-submit {
    align-self: start;
    padding: 0.65rem 1.5rem;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
}
.btn-submit:hover {
    background: var(--accent-hover);
}
.contact-success {
    border-color: var(--accent-color);
    background: rgba(37, 99, 235, 0.06);
}
.contact-success-msg {
    margin: 0;
    color: var(--text-color);
    font-weight: 500;
}
.contact-direct {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
}
.contact-direct-p {
    margin-bottom: 0.5rem;
    font-size: 0.95rem;
    color: var(--secondary-text);
}
.contact-email {
    font-size: 1.2rem;
    font-weight: 600;
}
.contact-list {
    list-style: none;
    padding: 0;
    margin: 0.5rem 0 0;
}
.contact-list li {
    margin-bottom: 0.5rem;
}
.contact-list a {
    display: inline-block;
    padding: 0.2rem 0;
}

.error-wrap {
    text-align: center;
    padding: 2.5rem 2rem;
}
.error-wrap .btn-link {
    display: inline-block;
    margin-top: 1rem;
    padding: 0.4rem 0;
}
.error-code {
    font-size: 6rem;
    margin-bottom: 0;
    line-height: 1;
}
.error-msg {
    color: var(--secondary-text);
    margin-bottom: 1.5rem;
}
.error-request-id {
    font-size: 0.85rem;
    color: var(--secondary-text);
}
