:root {
    --bg:             #fafafa;
    --surface:        #fafafa;
    --surface-strong: #f3f3f3;
    --border:         #e0e0e0;
    --text-main:      #000000;
    --text-sub:       #222222;
    --text-muted:     #555555;
    --accent:         #000000;
    --accent-soft:    rgba(0, 0, 0, 0.02);
    --link:           #0059ff;
    --code-bg:        #f7f7f7;
    --font-main:      "Inter", "Segoe UI", Arial, sans-serif;
    --font-mono:      "JetBrains Mono", Menlo, Monaco, Consolas, monospace;

    /* ── Type scale (5 stops) ── */
    --text-xs:   0.72rem;   /* 11.5px — labels, metadata */
    --text-sm:   0.82rem;   /* 13px   — descriptions, secondary */
    --text-base: 0.94rem;   /* 15px   — body text */
    --text-md:   1.1rem;    /* 17.6px — project titles */
    --text-lg:   1.4rem;    /* 22.4px — page headings */
}

[data-theme="dark"] {
    --bg:             #111111;
    --surface:        #111111;
    --surface-strong: #1c1c1c;
    --border:         #2a2a2a;
    --text-main:      #ffffff;
    --text-sub:       #c0c0c0;
    --text-muted:     #808080;
    --accent:         #ffffff;
    --accent-soft:    rgba(255, 255, 255, 0.02);
    --link:           #5b9bff;
    --code-bg:        #1c1c1c;
}

/* ── Theme toggle ── */
.theme-toggle {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-sub);
    padding: 0;
    display: flex;
    align-items: center;
    transition: color 0.12s ease;
}
.theme-toggle:hover { color: var(--hover-color, var(--text-main)); }
.theme-toggle:active { color: var(--active-color, var(--text-main)); }
.theme-toggle .icon-sun  { display: none; }
.theme-toggle .icon-moon { display: block; }
[data-theme="dark"] .theme-toggle .icon-sun  { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

::selection {
    background: rgba(0, 0, 0, 0.08);
    color: var(--text-main);
}
[data-theme="dark"] ::selection {
    background: rgba(255, 255, 255, 0.12);
    color: var(--text-main);
}

/* ── Prism dark mode overrides ── */
[data-theme="dark"] code[class*="language-"],
[data-theme="dark"] pre[class*="language-"] {
    color: #e0e0e0 !important;
    text-shadow: none !important;
}
[data-theme="dark"] .token.comment,
[data-theme="dark"] .token.prolog,
[data-theme="dark"] .token.doctype,
[data-theme="dark"] .token.cdata { color: #6a9955 !important; }
[data-theme="dark"] .token.punctuation { color: #b0b0b0 !important; }
[data-theme="dark"] .token.property,
[data-theme="dark"] .token.tag,
[data-theme="dark"] .token.boolean,
[data-theme="dark"] .token.number,
[data-theme="dark"] .token.constant,
[data-theme="dark"] .token.symbol { color: #b5cea8 !important; }
[data-theme="dark"] .token.selector,
[data-theme="dark"] .token.attr-name,
[data-theme="dark"] .token.string,
[data-theme="dark"] .token.char,
[data-theme="dark"] .token.builtin { color: #ce9178 !important; }
[data-theme="dark"] .token.operator,
[data-theme="dark"] .token.entity,
[data-theme="dark"] .token.url { color: #d4d4d4 !important; background: none !important; }
[data-theme="dark"] .token.atrule,
[data-theme="dark"] .token.attr-value,
[data-theme="dark"] .token.keyword { color: #569cd6 !important; }
[data-theme="dark"] .token.function,
[data-theme="dark"] .token.class-name { color: #dcdcaa !important; }
[data-theme="dark"] .token.regex,
[data-theme="dark"] .token.important,
[data-theme="dark"] .token.variable { color: #d16969 !important; }

html {
    scroll-behavior: smooth;
    overflow-x: hidden;
}

body {
    font-family: var(--font-main);
    font-size: 16px;
    color: var(--text-main);
    background: var(--bg);
    line-height: 1.6;
    margin: 0;
    padding: 40px 20px;
    overflow-x: hidden;
    box-sizing: border-box;
}

.container {
    max-width: 640px;
    margin: 0 auto;
}
.container:has(.project-card) {
    max-width: 960px;
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}

/* ── Global link reset ── */
a:visited { color: inherit; }

/* ── Header ── */
header {
    margin: 0 auto 48px;
    padding-bottom: 0;
    max-width: 640px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.container:has(.project-card) ~ header,
body:has(.project-card) header {
    max-width: 960px;
}

header a { color: var(--text-sub); transition: color 0.12s ease; text-decoration: none; }
header a:hover { color: var(--hover-color, var(--text-main)); }
header a:active { color: var(--active-color, var(--text-main)); }

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 12px;
}

h1 {
    font-family: var(--font-main);
    font-size: var(--text-base);
    letter-spacing: 0.01em;
    margin: 0;
    font-weight: 500;
    font-variant-ligatures: none;
    color: var(--text-main);
}

.meta-links {
    display: flex;
    gap: 16px;
    align-items: center;
}
.meta-links a {
    color: var(--text-sub);
    text-decoration: none;
    display: flex;
    align-items: center;
    transition: color 0.12s ease;
}
.meta-links a:hover { color: var(--hover-color, var(--text-main)); }
.meta-links a:active { color: var(--active-color, var(--text-main)); }

/* ── Bio ── */
.bio {
    font-size: var(--text-sm);
    color: var(--text-sub);
    max-width: 85ch;
    margin: 0 0 48px;
    line-height: 1.55;
}

/* ── Index Sections ── */
.index-section {
    margin-bottom: 48px;
}

.index-section-label {
    font-family: var(--font-main);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    display: block;
    margin-bottom: 16px;
    font-weight: 500;
}

/* ── Project Rows ── */
a.proj-row {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 12px;
    min-height: 44px;
    border-top: 1px solid var(--border);
    text-decoration: none;
    color: inherit;
    transition: background 0.12s ease;
    box-sizing: border-box;
}
a.proj-row:last-child {
    border-bottom: 1px solid var(--border);
}
a.proj-row:hover {
    background: var(--accent-soft);
}

.proj-left {
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex: 1;
    min-width: 0;
}

.proj-title {
    font-size: var(--text-base);
    font-weight: 400;
    color: var(--text-sub);
    transition: color 0.12s ease;
}
a.proj-row:hover .proj-title {
    color: var(--hover-color, var(--text-main));
}
a.proj-row:active .proj-title {
    color: var(--active-color, var(--text-main));
}

.proj-desc {
    font-size: var(--text-sm);
    color: var(--text-muted);
    line-height: 1.4;
}

.proj-arrow {
    font-size: var(--text-sm);
    color: var(--text-muted);
    flex-shrink: 0;
    transition: color 0.12s ease, transform 0.12s ease;
}
a.proj-row:hover .proj-arrow {
    color: var(--hover-color, var(--text-main));
    transform: translateX(3px);
}

/* ── Side Projects Grid ── */
.side-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
}

a.side-row {
    display: block;
    padding: 12px 12px;
    border-bottom: 0.5px solid var(--border);
    text-decoration: none;
    color: inherit;
    min-height: 44px;
    box-sizing: border-box;
    transition: background 0.12s ease;
}
.side-row:nth-child(1),
.side-row:nth-child(2) {
    border-top: 0.5px solid var(--border);
}
.side-row:nth-child(odd) {
    padding-right: 2rem;
}
.side-row:hover {
    background: var(--accent-soft);
}

.side-title {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-sub);
    transition: color 0.12s ease;
}
a.side-row:hover .side-title {
    color: var(--hover-color, var(--text-main));
}
a.side-row:active .side-title {
    color: var(--active-color, var(--text-main));
}

.side-desc {
    display: block;
    font-size: 11.5px;
    color: var(--text-muted);
    line-height: 1.4;
    margin-top: 3px;
}

/* ── Typography (project pages) ── */
h2 { margin: 0; font-size: var(--text-lg); font-weight: 600; letter-spacing: 0.01em; font-variant-ligatures: none; transition: color 0.12s ease; }
h3 {
    font-size: var(--text-xs);
    text-transform: uppercase;
    color: var(--text-muted);
    margin-top: 28px;
    margin-bottom: 12px;
    letter-spacing: 0.08em;
    font-family: var(--font-main);
    font-weight: 500;
}
h3:first-child { margin-top: 0; }
.section-gap { margin-top: 40px !important; }
h4 { margin: 0 0 10px 0; font-size: var(--text-base); color: var(--text-main); }

/* ── Tech Pills (project pages) ── */
.tech-stack {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 12px;
}
.pill {
    background: var(--accent-soft);
    color: var(--text-sub);
    padding: 3px 9px;
    border-radius: 4px;
    font-size: var(--text-xs);
    font-family: var(--font-mono);
    font-weight: 500;
    border: 1px solid var(--border);
}
.github-badge {
    text-decoration: none;
    opacity: 0.6;
    transition: opacity 0.12s ease;
}
.github-badge:hover {
    opacity: 1;
}
.github-badge.live-link {
    opacity: 1;
    border-color: #1a4ecf;
    color: #1a4ecf;
}
.github-badge.live-link:hover {
    background: #1a4ecf;
    color: #fff;
}
[data-theme="dark"] .github-badge.live-link {
    border-color: #5b9bff;
    color: #5b9bff;
}
[data-theme="dark"] .github-badge.live-link:hover {
    background: #5b9bff;
    color: #111;
}

/* ── Project Cards (project pages) ── */
.project-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 30px;
    margin-bottom: 40px;
    box-sizing: border-box;
}

.card-header {
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 18px;
}

.client-type {
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    font-weight: 500;
}

/* ── Mission Box ── */
.mission-box {
    background: var(--surface);
    border-left: 3px solid var(--text-muted);
    padding: 16px 20px;
    margin-bottom: 30px;
    border-radius: 0 6px 6px 0;
    font-size: var(--text-base);
    color: var(--text-sub);
    line-height: 1.65;
}
.mission-label {
    font-family: var(--font-main);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
}

/* ── Grid Layout ── */
.grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
}
.grid > * { min-width: 0; }

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

/* ── Code Windows ── */
.code-window {
    background: var(--code-bg);
    border-radius: 6px;
    border: 1px solid var(--border);
    overflow: hidden;
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
}

.window-header {
    background: var(--surface-strong);
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid var(--border);
}

.dots {
    display: flex;
    gap: 5px;
}
.dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}
.dots span:nth-child(1) { background: #e05a4e; }
.dots span:nth-child(2) { background: #d4a030; }
.dots span:nth-child(3) { background: #3db35a; }

.filename {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--text-sub);
}

pre[class*="language-"] {
    margin: 0 !important;
    background: transparent !important;
    padding: 16px !important;
    border: none !important;
    border-left: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    text-shadow: none !important;
    height: auto;
    box-sizing: border-box;
    overflow-y: visible !important;
    overflow-x: auto !important;
    font-size: var(--text-xs) !important;
    line-height: 1.5 !important;
    flex-grow: 1;
}

pre[class*="language-"]::-webkit-scrollbar { height: 4px; }
pre[class*="language-"]::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.08);
    border-radius: 4px;
}

pre[class*="language-"]:after,
pre[class*="language-"]:before { display: none !important; }

pre > code {
    display: block;
    overflow: visible !important;
    box-sizing: border-box;
    background: none !important;
    background-image: none !important;
    box-shadow: none !important;
    border-left: none !important;
}

:not(pre) > code {
    font-family: var(--font-mono);
    background: var(--surface-strong);
    color: var(--text-main);
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.85em;
    border: 1px solid var(--border);
}

/* ── Diagram Containers ── */
.diagram-box {
    background: var(--surface);
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    margin-bottom: 20px;
    box-sizing: border-box;
    overflow: hidden;
}
.diagram-controls {
    display: flex;
    gap: 6px;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}
.diagram-controls::before {
    content: 'drag to pan · scroll to zoom';
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: var(--text-muted);
    letter-spacing: 0.04em;
}
.diagram-controls button {
    border: 1px solid var(--border);
    background: var(--surface-strong);
    color: var(--text-sub);
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    user-select: none;
    transition: color 0.12s ease, border-color 0.12s ease;
}
.diagram-controls button:hover {
    color: var(--text-main);
    border-color: var(--text-sub);
}
.diagram-controls-buttons {
    display: flex;
    gap: 6px;
}
.diagram-viewport {
    height: 475px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    overflow: hidden;
    position: relative;
    cursor: grab;
    user-select: none;
    touch-action: none;
}
.diagram-viewport:active { cursor: grabbing; }
.diagram-canvas {
    position: absolute;
    left: 0;
    top: 0;
    transform-origin: 0 0;
}
.diagram-scale { transform-origin: 0 0; }
.diagram-box .mermaid { width: max-content; }

/* ── Key Engineering Challenges ── */
.feature-list ul {
    padding-left: 0;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.feature-list li {
    border-left: 2px solid var(--border);
    padding: 10px 16px;
    border-radius: 0;
    font-size: var(--text-sm);
    color: var(--text-sub);
    line-height: 1.55;
    background: none;
    border-top: none;
    border-right: none;
    border-bottom: none;
}
.feature-list li strong {
    display: block;
    color: var(--text-main);
    font-size: var(--text-sm);
    margin-bottom: 4px;
    font-weight: 600;
}

/* ── Screenshot Window ── */
.screenshot-window {
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    margin: 24px 0 36px 0;
}
.screenshot-window img {
    width: 100%;
    display: block;
    height: auto;
}

/* ── MJO Module Cards ── */
.mjo-module {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 22px;
    box-sizing: border-box;
    transition: border-color 0.12s ease;
}
.mjo-module:hover { border-color: var(--text-muted); }
.mjo-module h4 { font-size: var(--text-base); color: var(--text-main); font-weight: 600; }
.mjo-module .tagline {
    font-family: var(--font-main);
    font-size: var(--text-xs);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 12px;
    display: block;
    font-weight: 500;
}
.mjo-module p { font-size: var(--text-sm); color: var(--text-sub); margin-bottom: 12px; line-height: 1.55; }
.mjo-module ul { padding-left: 18px; margin: 0; font-size: var(--text-sm); color: var(--text-sub); }
.mjo-module li { margin-bottom: 6px; line-height: 1.5; }

.mjo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
    margin-top: 24px;
}

/* ── Project Nav ── */
.project-nav {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-top: 60px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
    gap: 20px;
}
.project-nav a {
    display: flex;
    flex-direction: column;
    gap: 4px;
    text-decoration: none;
    transition: color 0.12s ease;
}
.project-nav a:hover { color: var(--text-main); }
.project-nav a:hover .nav-label { color: var(--text-main); }
.project-nav a:hover .nav-title { color: var(--hover-color, var(--text-main)); }
.nav-label {
    font-family: var(--font-main);
    font-size: var(--text-xs);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    transition: color 0.12s ease;
    font-weight: 500;
}
.nav-title {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-main);
    transition: color 0.12s ease;
}
.project-nav .prev .nav-label::before { content: '\2190 '; }
.project-nav .next { text-align: right; }
.project-nav .next .nav-label::after { content: ' \2192'; }
.project-nav .spacer { flex: 1; }

/* ── Footer ── */
.footer {
    text-align: center;
    color: var(--text-muted);
    font-size: var(--text-xs);
    font-family: var(--font-main);
    margin-top: 80px;
    padding-bottom: 40px;
    letter-spacing: 0.02em;
}

/* ── Mobile ── */
@media (max-width: 768px) {
    body { padding: 24px 16px; }

    header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        margin-bottom: 40px;
    }

    h2 { font-size: 1.2rem; }

    .meta-links { gap: 14px; }

    .project-card { padding: 18px; margin-bottom: 40px; }

    .card-header {
        flex-direction: column;
        gap: 10px;
        padding-bottom: 14px;
        margin-bottom: 14px;
    }

    .mission-box { padding: 14px 16px; font-size: 0.88rem; }

    .diagram-viewport { height: 260px !important; }
    .diagram-controls::before { display: none; }
    .diagram-controls button {
        padding: 10px 14px;
        font-size: 0.75rem;
        min-height: 44px;
    }

    pre[class*="language-"] {
        font-size: 0.75rem !important;
        padding: 12px !important;
    }

    .mjo-grid { grid-template-columns: 1fr; gap: 12px; }
    .mjo-module { padding: 16px; }

    .feature-list li { padding: 10px 14px; font-size: 0.78rem; }

    .tech-stack { gap: 5px; }
    .pill { font-size: 0.65rem; }

    .screenshot-window { margin: 16px 0 24px 0; }

    .project-nav {
        flex-direction: column;
        gap: 10px;
        align-items: flex-start;
    }

    /* Index mobile */
    a.proj-row { padding: 16px 0; }
    .proj-title { font-size: var(--text-base); }

    .meta-links a,
    .theme-toggle { min-width: 44px; min-height: 44px; display: flex; align-items: center; justify-content: center; }

    .side-grid { grid-template-columns: 1fr; }
    .side-row:nth-child(odd) { padding-right: 0; }
    .side-row:nth-child(2) { border-top: none; }
}

/* ── Small phones ── */
@media (max-width: 400px) {
    body { padding: 16px 12px; }
    h2 { font-size: 1.05rem; }
    .project-card { padding: 14px; }
    .diagram-viewport { height: 210px !important; }
    pre[class*="language-"] { font-size: 0.7rem !important; padding: 10px !important; }
}
