:root {
    --bg: #1F1F31;
    --fg: #EAEAEF;
    --muted: #9494AB;
    --accent-green: #4F9E57;
    --accent-blue: #3563B9;
    --badge-fg: #ffffff;
    --rule: rgba(234, 234, 239, 0.14);
    --max-w: 900px;
}

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

html {
    scroll-behavior: smooth;
}

html,
body {
    background: var(--bg);
    color: var(--fg);
    font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 16px;
    line-height: 1.2;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
}

[id] { scroll-margin-top: 96px; }

body {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: clamp(80px, 9vw, 120px) clamp(20px, 4vw, 48px) clamp(60px, 8vw, 100px);
}

a {
    color: inherit;
    text-decoration: none;
}

a:focus-visible,
button:focus-visible,
[role="button"]:focus-visible {
    outline: 2px solid var(--accent-blue);
    outline-offset: 4px;
    border-radius: 2px;
}

.skip-link {
    position: absolute;
    top: -100%;
    left: 16px;
    background: var(--fg);
    color: var(--bg);
    padding: 8px 14px;
    z-index: 100;
    font-weight: 700;
    border-radius: 0 0 4px 4px;
}

.skip-link:focus {
    top: 0;
}

::selection {
    background: var(--accent-green);
    color: var(--badge-fg);
}

::-moz-selection {
    background: var(--accent-green);
    color: var(--badge-fg);
}

/* Nav */
.main-nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 5;
    padding: clamp(24px, 3.5vw, 36px) 16px;
    background: var(--bg);
}

.main-nav ul {
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: clamp(28px, 5vw, 64px);
}

.main-nav .nav-sep {
    width: 1px;
    height: 14px;
    background: var(--rule);
    margin: 0 -16px;
}

.main-nav .nav-icon {
    display: inline-flex;
    align-items: center;
    color: var(--fg);
}

.main-nav .nav-icon:hover {
    text-decoration: underline;
    text-underline-offset: 4px;
}

.main-nav li:has(> .nav-icon) + li:has(> .nav-icon) {
    margin-left: clamp(-32px, -2.5vw, -14px);
}

.main-nav a {
    position: relative;
    color: var(--fg);
    font-size: 16px;
    padding: 4px 10px;
    transition: color 140ms ease;
}

.nav-bracket {
    position: absolute;
    top: 50%;
    color: oklch(0.74 0.13 145);
    opacity: 0;
    pointer-events: none;
}

@media (prefers-reduced-motion: no-preference) {
    .nav-bracket {
        transition: opacity 180ms cubic-bezier(.2, .8, .2, 1),
                    transform 180ms cubic-bezier(.2, .8, .2, 1);
    }
}

.nav-bracket-left  { left: -2px;  transform: translateY(-50%) translateX(6px); }
.nav-bracket-right { right: -2px; transform: translateY(-50%) translateX(-6px); }

.main-nav a:hover .nav-bracket,
.main-nav a[aria-current="page"] .nav-bracket {
    opacity: 1;
}

.main-nav a:hover .nav-bracket-left,
.main-nav a[aria-current="page"] .nav-bracket-left {
    transform: translateY(-50%) translateX(0);
}

.main-nav a:hover .nav-bracket-right,
.main-nav a[aria-current="page"] .nav-bracket-right {
    transform: translateY(-50%) translateX(0);
}

/* Shell */
.shell {
    width: 100%;
    max-width: var(--max-w);
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    text-align: left;
}

/* Cat launcher (idle) */
.cat-launcher {
    position: relative;
    width: 100%;
    display: flex;
    align-items: flex-end;
    justify-content: flex-start;
    padding: 0 clamp(16px, 3vw, 24px) clamp(12px, 2vw, 16px);
    box-sizing: border-box;
}

.cat-launcher::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 32px;
    background-image: url("images/game/ground.png");
    background-repeat: repeat-x;
    background-size: auto;
    background-position: left bottom;
    image-rendering: pixelated;
}

.project-preview--game {
    position: relative;
    overflow: hidden;
    background: var(--surface-2, rgba(255, 255, 255, 0.03));
    border: none;
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
    aspect-ratio: auto;
    height: 200px;
    cursor: pointer;
}

.project-preview--game.is-playing { cursor: default; }

.project-preview--game:focus { outline: none; }
.project-preview--game:focus-visible {
    outline: 2px solid var(--accent-blue);
    outline-offset: -2px;
}
.project-preview--game.is-playing:focus-visible { outline: none; }

.game-hint {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 12px;
    color: var(--muted);
    letter-spacing: 0.04em;
    pointer-events: none;
    z-index: 4;
}

.project-preview--game.is-playing .game-hint { display: none; }
.project-preview--game.is-playing.is-gameover .game-hint { display: block; }

.project-preview--game::before {
    content: "";
    position: absolute;
    top: 0;
    bottom: 6px;
    left: 0;
    right: 0;
    border: 1px solid #f3f4ff;
    border-bottom: none;
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
    pointer-events: none;
    z-index: 4;
}

.project-preview--game .cat-launcher {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    justify-content: center;
    padding-bottom: 0;
}

/* Override the legacy fixed-position styles for game-char/bubble while idle */
#game-char {
    position: relative;
    bottom: auto;
    left: auto;
    transform: none;
    width: 48px;
    height: 48px;
    background-image: url(images/game/kitty-sheet.png);
    background-size: 500% 100%;
    background-position: 75% 0;
    image-rendering: pixelated;
    cursor: pointer;
    z-index: 2;
    animation: game-char-feet 2s steps(1) infinite;
}

@keyframes game-char-feet {
    0%   { background-position: 75% 0; }
    85%  { background-position: 100% 0; }
}

/* When the game is playing, the canvas takes over the viewport;
   hide the inline launcher so the gameplay reads as a full takeover. */
.project-preview--game.is-playing .cat-launcher::after {
    display: none;
}

/* Homepage typography */
.name {
    margin-top: 160px;
    font-size: clamp(48px, 8vw, 68px);
    font-weight: 400;
    letter-spacing: -0.01em;
    line-height: 1.1;
    color: var(--fg);
    text-align: center;
}

.tagline {
    margin-top: 12px;
    font-style: italic;
    color: var(--accent-green);
    font-size: 16px;
    text-align: center;
}

.tagline .caret {
    display: inline-block;
    width: 0.6ch;
    height: 1em;
    margin-left: 2px;
    vertical-align: -2px;
    background: var(--fg);
    animation: caret-blink 1.05s steps(2, end) infinite;
    transition: opacity 400ms ease;
}

.tagline .caret[data-visible="0"] {
    opacity: 0;
    animation: none;
}

@keyframes caret-blink {
    0%, 50%       { opacity: 1; }
    50.01%, 100%  { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
    .tagline .caret { display: none; }
}

.status {
    margin-top: clamp(28px, 3.5vw, 40px);
    margin-bottom: clamp(24px, 4vw, 48px);
    font-size: 16px;
    color: var(--fg);
    line-height: 1.8;
    text-align: center;
}

.badge {
    display: inline;
    padding: 0 4px;
    color: var(--badge-fg);
    white-space: nowrap;
}

.badge--green { background: var(--accent-green); }
.badge--blue  { background: var(--accent-blue); }

.status-line2 {
    color: var(--muted);
    margin-top: 4px;
}

/* Section heading */
.section-heading {
    margin-top: clamp(40px, 8vw, 96px);
    padding-top: 24px;
    margin-bottom: clamp(20px, 2.5vw, 28px);
    font-size: clamp(32px, 3.5vw, 36px);
    font-weight: 500;
    color: var(--fg);
}

/* Recently shipped list */
.shipped {
    list-style: "› ";
    width: 100%;
    padding-left: 20px;
    text-align: left;
    font-size: 12px;
    color: var(--muted);
}

.shipped li {
    display: list-item;
    margin-bottom: 8px;
}

.shipped li::marker {
    color: var(--muted);
}

.shipped a {
    color: var(--fg);
    text-decoration: underline;
    text-underline-offset: 3px;
    text-decoration-thickness: 1px;
    text-decoration-color: var(--rule);
    line-height: 1.5;
}

.shipped a:hover {
    text-decoration-color: var(--fg);
}

/* Page sections (Playground, About) */
.page-section {
    width: 100%;
    text-align: left;
}

.page-intro {
    font-size: 16px;
    line-height: 1.7;
    color: var(--muted);
    margin-bottom: clamp(20px, 2.5vw, 28px);
}

.page-body {
    color: var(--muted);
    line-height: 1.75;
    margin-bottom: clamp(16px, 2vw, 20px);
}

.page-intro a,
.page-body a {
    color: var(--fg);
    text-decoration: underline;
    text-underline-offset: 3px;
    text-decoration-color: var(--rule);
}

.page-intro a:hover,
.page-body a:hover {
    text-decoration-color: var(--fg);
}

.project-list {
    list-style: none;
    margin-top: clamp(32px, 4vw, 48px);
    display: flex;
    flex-direction: column;
    gap: clamp(64px, 8vw, 96px);
}

.page-section--home .project-list {
    margin-top: 0;
}

.project-title {
    font-size: 24px;
    font-weight: 600;
    line-height: 1.6;
    margin-bottom: 10px;
}

.project-title a {
    color: var(--fg);
    text-decoration: underline;
    text-underline-offset: 4px;
    text-decoration-color: var(--rule);
}

.project-title a:hover {
    text-decoration-color: var(--fg);
}

.project-body {
    color: var(--muted);
    line-height: 1.7;
}

.project-preview {
    display: block;
    margin-bottom: clamp(12px, 1.6vw, 16px);
    width: 100%;
    border-radius: 4px;
    overflow: hidden;
    aspect-ratio: 16 / 10;
}

.project-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: opacity 180ms ease;
}

.project-preview:hover img {
    opacity: 0.92;
}

.project-links {
    margin-top: 20px;
    color: var(--muted);
    font-size: 12px;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.project-links a {
    color: var(--fg);
    text-decoration: underline;
    text-underline-offset: 3px;
    text-decoration-color: var(--rule);
}

.project-links a:hover {
    text-decoration-color: var(--fg);
}

.project-links .sep {
    color: var(--rule);
}


/* About timeline */
.timeline {
    list-style: none;
    margin-top: clamp(28px, 4vw, 40px);
    display: flex;
    flex-direction: column;
    gap: clamp(24px, 3.5vw, 36px);
}

.timeline-item {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 12px;
    align-items: start;
}

.timeline-when {
    color: var(--muted);
    font-size: 12px;
    padding-top: 3px;
}

.timeline-what {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.timeline-where {
    font-size: 16px;
    font-weight: 600;
    color: var(--fg);
    display: flex;
    flex-wrap: wrap;
    gap: 4px 10px;
    align-items: baseline;
}

.timeline-where a {
    color: var(--fg);
    text-decoration: underline;
    text-underline-offset: 3px;
    text-decoration-color: var(--rule);
}

.timeline-where a:hover {
    text-decoration-color: var(--fg);
}

.timeline-role {
    color: var(--muted);
    font-size: 12px;
}

.timeline-note {
    color: var(--muted);
    font-size: 12px;
    margin-top: 12px;
}

.timeline-what .shipped {
    margin-top: 8px;
}

@media (max-width: 640px) {
    .timeline-item {
        grid-template-columns: 1fr;
        gap: 6px;
    }
}

.work-list {
    list-style: none;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: clamp(64px, 8vw, 96px);
}

.work-article {
    display: flex;
    flex-direction: column;
    gap: 18px;
    text-align: left;
}

.work-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--muted);
    font-size: 12px;
}

.work-meta .work-logo {
    height: 18px;
    width: auto;
    max-width: 100px;
    object-fit: contain;
    object-position: left center;
}

.work-meta img.work-logo[src*="tradecore"] { height: 16px; }

.work-meta .work-logo[src*="elastic"] {
    transform: translateY(-2px);
}

.work-meta .sep {
    color: inherit;
}

.work-title {
    font-size: 24px;
    font-weight: 600;
    color: var(--fg);
    line-height: 1.6;
}

.work-body {
    color: var(--muted);
    font-size: 16px;
    line-height: 1.7;
}

.work-cover {
    position: relative;
    border-radius: 4px;
    aspect-ratio: 16 / 10;
    overflow: hidden;
}

.work-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Before/after compare */
.work-compare {
    touch-action: none;
    user-select: none;
}

.work-compare .compare-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.work-compare .compare-before {
    clip-path: inset(0 calc(100% - var(--compare-pos, 50%)) 0 0);
}

.work-compare .compare-handle {
    position: absolute;
    top: 0;
    bottom: 0;
    left: var(--compare-pos, 50%);
    transform: translateX(-50%);
    width: 44px;
    background: transparent;
    border: 0;
    padding: 0;
    cursor: ew-resize;
    touch-action: none;
    z-index: 2;
}

.work-compare .compare-handle-line {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 1px;
    transform: translateX(-50%);
    background: var(--fg);
    opacity: 0.9;
}

.work-compare .compare-handle-grip {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--bg);
    border: 1px solid var(--fg);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--fg);
}

.work-compare .compare-handle:focus-visible {
    outline: none;
}

.work-compare .compare-handle:focus-visible .compare-handle-grip {
    outline: 2px solid var(--accent-blue);
    outline-offset: 3px;
}

.work-compare .compare-label {
    position: absolute;
    top: 10px;
    font-size: 12px;
    line-height: 1;
    letter-spacing: 0.06em;
    color: var(--fg);
    background: rgba(31, 31, 49, 0.85);
    padding: 5px 8px;
    border-radius: 2px;
    pointer-events: none;
    z-index: 1;
    font-family: "JetBrains Mono", monospace;
}

.work-compare .compare-label-before { left: 10px; }
.work-compare .compare-label-after  { right: 10px; }

/* Game canvases (created by JS, appended into .project-preview--game) */
#game-canvas,
#ground-canvas {
    display: block;
    position: absolute;
    inset: 0;
    pointer-events: none;
}

#ground-canvas { z-index: 2; }
#game-canvas   { z-index: 3; }

/* While playing, hide the idle launcher chrome so the canvases own the frame */
.project-preview--game.is-playing .cat-launcher { visibility: hidden; }

/* Mobile */
@media (max-width: 640px) {
    body {
        padding-top: 96px;
    }

    .main-nav {
        padding: 12px 6px;
    }

    .main-nav ul {
        gap: clamp(6px, 2.4vw, 14px);
        flex-wrap: nowrap;
    }

    .main-nav a {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-size: clamp(11px, 3vw, 12px);
        padding: 12px 6px;
        min-height: 36px;
        line-height: 1;
        box-sizing: border-box;
    }

    .main-nav .nav-sep {
        margin: 0;
    }

    .main-nav li:has(> .nav-icon) + li:has(> .nav-icon) {
        margin-left: -4px;
    }

    .main-nav .nav-icon svg {
        width: 16px;
        height: 16px;
    }

    .nav-bracket-left  { transform: translateY(-50%) translateX(4px); }
    .nav-bracket-right { transform: translateY(-50%) translateX(-4px); }

}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    #game-char {
        animation: none;
    }
}
