*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
    --mono: "JetBrains Mono", "Cascadia Code", "Courier New", Consolas, monospace;
    --bg:      #050505;
    --surface: #0a0a0a;
    --border:  rgba(0, 255, 65, 0.18);
    --text:    #00ff41;
    --muted:   #2e6b32;
    --glow:    0 0 8px rgba(0, 255, 65, 0.55);
}
html, body { height: 100%; overflow: hidden; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { background: #020202; color: var(--text); font-family: var(--mono); }
/* ── 3-D environment canvas ──────────────────────────────────── */
#env-canvas {
    position: fixed; inset: 0; z-index: 1;
    width: 100%; height: 100%; pointer-events: none;
}
/* ── Screen content overlay (projected onto 3-D screen face) ── */
#screen-overlay {
    position: fixed; top: 0; left: 0; z-index: 2;
    overflow: hidden;
    transform-origin: 0 0; background: #020a02;
    opacity: 0; transition: opacity 0.55s ease;
}
/* Scrolling and clipping live on an UNtransformed child. Firefox clips a
   perspective-transformed scroll container with only the affine part of the
   matrix, so content past the screen edge bled onto the monitor bezel. */
#screen-scroll {
    width: 100%; height: 100%;
    overflow-y: auto; overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: #00ff41 #020a02;
}
#screen-scroll::-webkit-scrollbar { width: 6px; }
#screen-scroll::-webkit-scrollbar-track { background: #020a02; }
#screen-scroll::-webkit-scrollbar-thumb {
    background: #00ff41;
    box-shadow: 0 0 6px rgba(0, 255, 65, 0.8);
}
/* ── Scanlines + vignette ──────────────────────────────────────── */
.screen-fx {
    position: fixed; inset: 0; z-index: 3;
    pointer-events: none;
    background:
        repeating-linear-gradient(0deg, transparent, transparent 3px,
            rgba(0,0,0,0.14) 3px, rgba(0,0,0,0.14) 4px),
        radial-gradient(ellipse at center, transparent 55%, rgba(0,0,0,0.68) 100%);
}
/* ── Shell ─────────────────────────────────────────────────────── */
.shell {
    position: relative; z-index: 1;
    width: min(960px, calc(100% - 32px));
    margin: 0 auto;
    padding: 36px 0 44px;
    /* Own compositor layer: without this Firefox (WebRender) composites the
       text of the perspective-warped overlay through an intermediate surface
       and it renders soft until the first scroll. */
    will-change: transform;
}
.badge {
    display: inline-flex; align-items: center; gap: 10px;
    font-family: var(--mono); font-size: 0.72rem;
    color: var(--text); letter-spacing: 0.1em;
    text-transform: uppercase; margin-bottom: 28px;
    opacity: 0.75;
}
.badge::before { content: '> '; opacity: 0.5; }
.badge .sep { opacity: 0.4; }
.badge a { color: var(--text); text-decoration: none; transition: text-shadow 0.15s, opacity 0.15s; }
.badge a:hover { text-shadow: var(--glow); opacity: 1; }
.badge .cur { color: var(--text); }
.badge:hover { opacity: 1; }
.pulse {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--text); box-shadow: var(--glow);
    animation: glow-pulse 1.2s ease-in-out infinite;
}
@keyframes glow-pulse {
    0%, 100% { opacity: 1;   box-shadow: var(--glow); }
    50%       { opacity: 0.2; box-shadow: none; }
}
.hero h1 {
    font-family: var(--mono);
    font-size: clamp(2.6rem, 5vw, 5rem);
    font-weight: 700; line-height: 1;
    letter-spacing: -0.01em; text-transform: uppercase;
    color: var(--text);
    text-shadow: var(--glow), 0 0 40px rgba(0,255,65,0.25);
}
.hero h1::after {
    content: '_';
    animation: blink 1.1s step-start infinite;
    margin-left: 2px;
}
@keyframes blink { 50% { opacity: 0; } }
.hero p {
    margin-top: 18px; max-width: 560px;
    font-size: 0.88rem; color: var(--muted);
    line-height: 1.75; font-family: var(--mono);
}
.hero p::before { content: '// '; }
.divider {
    display: flex; align-items: center; gap: 12px;
    margin: 52px 0 20px;
    font-family: var(--mono); font-size: 0.72rem;
    color: var(--muted); letter-spacing: 0.14em; text-transform: uppercase;
}
.divider::before { content: '──'; opacity: 0.5; }
.divider::after {
    content: ''; flex: 1; height: 1px;
    background: linear-gradient(90deg, var(--border), transparent);
}
/* ── Service cards ─────────────────────────────────────────────── */
.grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}
.card {
    position: relative; display: flex;
    flex-direction: row; align-items: stretch;
    gap: 0; padding: 0 0 0 160px; border-radius: 0;
    min-height: 148px;
    /* Edges as inset shadows, not borders: Firefox/WebRender draws 1px
       borders as line primitives that escape the warped overlay's clip. */
    border: 0; box-shadow: inset 0 0 0 1px var(--border);
    background: var(--surface);
    text-decoration: none; color: var(--text); overflow: hidden;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.card::before {
    content: '';
    position: absolute; top: 0; left: 0; right: 0; height: 1px;
    background: var(--card-accent, var(--text));
    box-shadow: 0 0 10px var(--card-accent, var(--text));
    opacity: 0; transition: opacity 0.15s;
}
.card:hover {
    box-shadow: inset 0 0 0 1px var(--card-accent, var(--text)),
                0 0 24px rgba(0,255,65,0.06), inset 0 0 60px rgba(0,255,65,0.015);
}
.card:hover::before { opacity: 1; }
.card-icon {
    position: absolute; left: 0; top: 0;
    width: 160px; height: 100%;
    display: flex; align-items: center; justify-content: center;
    background: #000; box-shadow: inset -1px 0 0 var(--border);
    color: var(--card-accent, var(--text));
}
.card-icon svg {
    width: 72px; height: 72px;
    fill: none; stroke: currentColor; stroke-width: 2.5;
    stroke-linecap: round; stroke-linejoin: round;
    filter: drop-shadow(0 0 6px var(--card-accent, var(--text)));
    opacity: 0.85; transition: opacity 0.15s, transform 0.15s;
}
.card:hover .card-icon svg { opacity: 1; transform: scale(1.06); }
.card-body {
    flex: 1; display: flex; flex-direction: column;
    gap: 8px; padding: 18px; min-width: 0;
}
.card-meta {
    display: flex; align-items: center; justify-content: space-between;
}
.card-num {
    font-family: var(--mono); font-size: 0.65rem;
    color: var(--muted); padding-top: 2px;
}
.card h2 {
    font-family: var(--mono); font-size: 0.92rem; font-weight: 700;
    letter-spacing: 0.1em; text-transform: uppercase;
    color: var(--card-accent, var(--text));
    text-shadow: 0 0 12px var(--card-accent, var(--text));
}
.card-desc {
    font-size: 0.78rem; color: var(--muted);
    line-height: 1.65; flex: 1; font-family: var(--mono);
}
.card-link {
    display: flex; align-items: center; gap: 6px;
    font-size: 0.76rem; font-weight: 600;
    color: var(--card-accent, var(--text)); font-family: var(--mono);
    text-transform: uppercase; letter-spacing: 0.08em;
}
.card-link::before { content: '> '; opacity: 0.6; }
.arrow { display: inline-block; transition: transform 0.15s ease; }
.card:hover .arrow { transform: translateX(5px); }
footer {
    margin-top: 52px; font-family: var(--mono);
    font-size: 0.66rem; color: rgba(0,255,65,0.18);
}
footer::before { content: '> '; }
@media (max-width: 780px) { .grid { grid-template-columns: 1fr; } }
@media (max-width: 600px) {
    .shell { padding: 18px 0 28px; }
    .card { padding-left: 110px; }
    .card-icon { width: 110px; }
    .card-icon svg { width: 56px; height: 56px; }
}
/* ── Mobile layout: skip 3-D scene, show content full-screen ────── */
@media (max-width: 768px) {
    #env-canvas { display: none; }
    .screen-fx  { display: none; }
    #screen-overlay {
        /* Full viewport, no 3D warp — scene.js skipped on mobile */
        width: 100vw !important;
        height: 100vh !important;
        height: 100dvh !important;   /* iOS: track the collapsing Safari toolbar */
        transform: none !important;
        opacity: 1 !important;
    }
    #screen-scroll { -webkit-overflow-scrolling: touch; overscroll-behavior-y: contain; }
    .shell {
        width: 100%;
        /* keep clear of the notch / home indicator on iPhone */
        padding: calc(24px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right))
                 calc(36px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
    }
    /* iOS Safari zooms the page when focusing an input under 16px */
    .search input { font-size: 16px; }
    .card-link, .badge a { min-height: 32px; display: inline-flex; align-items: center; }
    .hero h1 { font-size: clamp(1.8rem, 8vw, 2.8rem); }
    .hero p, .badge { overflow-wrap: break-word; word-break: break-word; }
    .grid { grid-template-columns: 1fr; }
    .card { flex-direction: column; padding: 120px 0 0 0; min-height: 0; }
    .card-icon {
        left: 0; top: 0;
        width: 100%;
        height: 120px;
        box-shadow: inset 0 -1px 0 var(--border);
    }
    .card-body {
        padding: 16px;
        min-width: 0;
        overflow-wrap: break-word;
        word-break: break-word;
    }
    .card-desc { overflow-wrap: break-word; word-break: break-word; }
    .card-link  { overflow-wrap: break-word; word-break: break-word; }
}


/* ── Search ────────────────────────────────────────────────────── */
.search {
    display: flex; align-items: center; gap: 12px;
    margin-top: 28px; padding: 0 0 8px;
    box-shadow: inset 0 -1px 0 var(--border);
    font-family: var(--mono);
}
.search-prompt {
    font-size: 0.72rem; letter-spacing: 0.14em; text-transform: uppercase;
    color: var(--muted); white-space: nowrap;
}
.search-prompt::before { content: '> '; opacity: 0.6; }
.search input {
    flex: 1; min-width: 0;
    background: transparent; border: 0; outline: none; box-shadow: none;
    appearance: none; -webkit-appearance: none; border-radius: 0;
    font-family: var(--mono); font-size: 0.9rem; color: var(--text);
    caret-color: var(--text); padding: 4px 0;
}
.search input::placeholder { color: var(--muted); opacity: 0.8; }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; }
.search input:focus, .search input:focus-visible { outline: none; box-shadow: none; }
.search:focus-within { box-shadow: inset 0 -1px 0 var(--text); }
.search-count { font-size: 0.68rem; color: var(--muted); letter-spacing: 0.08em; white-space: nowrap; }
.search-empty {
    margin: 24px 0; font-family: var(--mono); font-size: 0.82rem; color: var(--muted);
}
.search-empty em { color: var(--text); font-style: normal; }
.card[hidden], .divider[hidden], .grid[hidden] { display: none; }
mark.hit { background: rgba(0,255,65,0.18); color: var(--text); padding: 0 1px; }

/* ── Form controls inside posts (interactive demos) ───────────── */
.post form { display: block; margin: 0 0 18px; }
.post fieldset { border: 1px dashed var(--border); padding: 12px 14px; margin: 0 0 16px; }
.post legend, .post label {
    display: block; font-family: var(--mono); font-size: 0.7rem; letter-spacing: 0.12em;
    text-transform: uppercase; color: var(--muted); margin: 10px 0 6px;
}
.post label::before { content: '> '; opacity: 0.6; }
.post input:not([type=range]):not([type=file]):not([type=submit]):not([type=button]):not([type=checkbox]):not([type=radio]),
.post select, .post textarea {
    display: block; width: 100%; box-sizing: border-box;
    background: #000; color: var(--text);
    border: 1px solid var(--border); border-radius: 0;
    font-family: var(--mono); font-size: 0.84rem; line-height: 1.5;
    padding: 8px 10px; margin: 0 0 12px;
    outline: none; appearance: none; -webkit-appearance: none;
    caret-color: var(--text);
    transition: border-color 0.12s, box-shadow 0.12s;
}
.post input:focus, .post select:focus, .post textarea:focus {
    border-color: var(--text); box-shadow: var(--glow);
}
.post input::placeholder, .post textarea::placeholder { color: var(--muted); }
.post textarea { resize: vertical; min-height: 140px; }
.post select {
    padding-right: 32px; cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%2300ff41' stroke-width='1.5'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 10px center; background-size: 12px 8px;
}
.post select optgroup, .post select option { background: #020a02; color: var(--text); }

/* Buttons: submit inputs, <button>, and the file-upload label */
.post button, .post input[type=submit], .post input[type=button],
.post div.input-file label, .post .custom-button-file {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    width: auto; margin: 0 8px 12px 0; padding: 7px 16px;
    background: transparent; color: var(--text);
    border: 1px solid var(--border); border-radius: 0;
    font-family: var(--mono); font-size: 0.74rem; font-weight: 600;
    letter-spacing: 0.1em; text-transform: uppercase;
    cursor: pointer; appearance: none; -webkit-appearance: none;
    transition: border-color 0.12s, background 0.12s, box-shadow 0.12s, color 0.12s;
}
.post button::before, .post div.input-file label::before { content: '> '; opacity: 0.6; }
.post button:hover, .post input[type=submit]:hover, .post input[type=button]:hover,
.post div.input-file label:hover {
    border-color: var(--card-accent, var(--text));
    color: var(--card-accent, var(--text));
    background: rgba(0, 255, 65, 0.06);
    box-shadow: 0 0 12px rgba(0, 255, 65, 0.18);
}
.post button:active, .post input[type=submit]:active { background: rgba(0, 255, 65, 0.14); }
.post button:focus-visible, .post input:focus-visible { outline: 1px solid var(--text); outline-offset: 2px; }
.post button:disabled { opacity: 0.4; cursor: default; }
.post input[type=file] { display: none; }
.post div.input-file { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.post div.input-file .filename-element {
    display: none; margin: 0 0 12px; font-size: 0.78rem; color: var(--muted);
}
.post div.input-file .filename-element::before { content: '// '; }

/* Checkboxes and radios */
.post input[type=checkbox], .post input[type=radio] {
    appearance: none; -webkit-appearance: none;
    width: 14px; height: 14px; margin: 0 8px 0 0; vertical-align: -2px;
    border: 1px solid var(--border); background: #000; cursor: pointer;
}
.post input[type=radio] { border-radius: 50%; }
.post input[type=checkbox]:checked, .post input[type=radio]:checked {
    background: var(--text); box-shadow: var(--glow), inset 0 0 0 3px #000;
}

/* Range sliders */
.post input[type=range] {
    appearance: none; -webkit-appearance: none;
    width: 100%; height: 22px; margin: 0; padding: 0;
    background: transparent; cursor: pointer; border: 0;
}
.post input[type=range]::-webkit-slider-runnable-track {
    height: 2px; background: var(--border); border: 0;
}
.post input[type=range]::-moz-range-track { height: 2px; background: var(--border); border: 0; }
.post input[type=range]::-moz-range-progress { height: 2px; background: var(--text); }
.post input[type=range]::-webkit-slider-thumb {
    appearance: none; -webkit-appearance: none;
    width: 14px; height: 14px; margin-top: -6px; border-radius: 0;
    background: #000; border: 1px solid var(--text); box-shadow: var(--glow);
    transition: background 0.12s;
}
.post input[type=range]::-moz-range-thumb {
    width: 12px; height: 12px; border-radius: 0;
    background: #000; border: 1px solid var(--text); box-shadow: var(--glow);
}
.post input[type=range]:hover::-webkit-slider-thumb, .post input[type=range]:active::-webkit-slider-thumb { background: var(--text); }
.post input[type=range]:hover::-moz-range-thumb, .post input[type=range]:active::-moz-range-thumb { background: var(--text); }
.post input[type=range]:focus-visible { outline: none; }

/* Legacy helper classes used by the demo scripts */
.post .hidden { display: none !important; }
.post p.error, .post p.success {
    padding: 8px 12px; margin: 0 0 12px; font-size: 0.8rem; border: 1px solid;
}
.post p.success { color: var(--text); border-color: var(--text); }
.post p.error { color: #ff5f5f; border-color: #ff5f5f; }

/* ── Index extras ──────────────────────────────────────────────── */
.card-date { font-family: var(--mono); font-size: 0.65rem; color: var(--muted); white-space: nowrap; }
.card-meta { gap: 4px 10px; flex-wrap: wrap; }
.card-meta h2 { min-width: 0; overflow-wrap: anywhere; }
.card-meta-right { display: flex; gap: 10px; align-items: center; flex-shrink: 0; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tag {
    font-family: var(--mono); font-size: 0.62rem; letter-spacing: 0.08em;
    text-transform: uppercase; color: var(--muted);
    border: 1px solid var(--border); padding: 2px 7px;
}
.tag::before { content: '#'; opacity: 0.6; }

/* ── Post pages ────────────────────────────────────────────────── */
.hero.post-hero h1 { font-size: clamp(1.6rem, 3.4vw, 2.8rem); }
.hero.post-hero h1::after { content: none; }
.post {
    font-family: var(--mono); font-size: 0.84rem; line-height: 1.8;
    color: rgba(0, 255, 65, 0.82);
}
.post h2, .post h3, .post h4 {
    font-family: var(--mono); text-transform: uppercase; letter-spacing: 0.1em;
    color: var(--card-accent, var(--text));
    text-shadow: 0 0 12px var(--card-accent, var(--text));
    margin: 34px 0 12px;
}
.post h2 { font-size: 0.95rem; }
.post h3 { font-size: 0.85rem; }
.post h4 { font-size: 0.78rem; }
.post h2::before, .post h3::before, .post h4::before { content: '## '; opacity: 0.45; }
.post h3::before { content: '### '; }
.post h4::before { content: '#### '; }
.post p { margin: 0 0 16px; }
.post ul, .post ol { margin: 0 0 16px 22px; }
.post li { margin-bottom: 4px; }
.post a { color: var(--card-accent, var(--text)); text-decoration: none; border-bottom: 1px solid var(--border); }
.post a:hover { border-bottom-color: var(--card-accent, var(--text)); }
.post strong, .post b { color: var(--text); }
.post code.inline, .post p code {
    background: rgba(0, 255, 65, 0.07); border: 1px solid var(--border);
    padding: 1px 5px; font-size: 0.8em; color: var(--text);
}
.post pre {
    background: #000; border: 1px solid var(--border);
    padding: 14px 16px; margin: 0 0 18px; overflow-x: auto;
    font-size: 0.78rem; line-height: 1.6; color: #b8ffc6;
    scrollbar-width: thin; scrollbar-color: #00ff41 #000;
}
.post pre code { white-space: pre; }
.post img, .post video {
    max-width: 100%; height: auto; display: block; margin: 14px 0 18px;
    border: 1px solid var(--border);
}
/* Inline post images: capped in height so tall phone screenshots don't fill
   the monitor; consecutive ones sit side by side. Click opens the carousel. */
.post a.post-img {
    display: inline-block; vertical-align: top; margin: 6px 10px 12px 0;
    border: 0; max-width: 100%;
}
.post a.post-img img {
    display: block; margin: 0; width: auto; max-width: 100%; max-height: 420px;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.post a.post-img:hover img { border-color: var(--card-accent, var(--text)); box-shadow: 0 0 14px rgba(0,255,65,0.18); }
.post a.post-img + a.post-img { }
.post a.post-img + p, .post a.post-img + h2, .post a.post-img + h3 { clear: both; }
.post table {
    border-collapse: collapse; margin: 0 0 18px; font-size: 0.8rem;
    display: block; max-width: 100%; overflow-x: auto;   /* wide tables scroll, never the page */
    scrollbar-width: thin; scrollbar-color: #00ff41 transparent;
}
.post th, .post td { border: 1px solid var(--border); padding: 5px 10px; text-align: left; }
.post th { color: var(--text); }
.post blockquote { border-left: 2px solid var(--card-accent, var(--text)); padding-left: 14px; color: var(--muted); margin: 0 0 16px; }
.post .katex { font-size: 1.05em; color: var(--text); }
.post .katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
.shots { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; }
.shots a { display: block; border: 1px solid var(--border); background: #000; cursor: zoom-in; aspect-ratio: 16 / 10; }
.shots a:hover { border-color: var(--card-accent, var(--text)); }
.shots img { width: 100%; height: 100%; object-fit: cover; display: block; margin: 0; border: 0; }
.links { display: flex; flex-wrap: wrap; gap: 10px 24px; }
.links .card-link { text-decoration: none; }
.links .card-link:hover .arrow { transform: translateX(5px); }

/* ── Lightbox carousel ─────────────────────────────────────────── */
.lightbox {
    position: fixed; inset: 0; z-index: 300;
    display: flex; align-items: center; justify-content: center;
    opacity: 0; transition: opacity 0.15s ease; font-family: var(--mono);
}
.lightbox[hidden] { display: none; }
.lightbox-open { opacity: 1; }
.lightbox-backdrop { position: absolute; inset: 0; background: rgba(0, 5, 0, 0.92); }
.lightbox-figure {
    position: relative; margin: 0;
    display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.lightbox-img {
    width: auto; height: auto;
    border: 1px solid var(--text); box-shadow: 0 0 32px rgba(0, 255, 65, 0.22); background: #000;
    cursor: pointer;
}
.lightbox-caption { font-size: 0.74rem; color: var(--muted); text-align: center; max-width: 60ch; line-height: 1.5; }
.lightbox-caption:not(:empty)::before { content: '// '; }
.lightbox-btn {
    position: absolute; top: 50%; transform: translateY(-50%);
    width: 40px; height: 40px; display: flex; align-items: center; justify-content: center;
    background: #020a02; color: var(--text); border: 1px solid var(--border); border-radius: 0;
    font-family: var(--mono); font-size: 1rem; font-weight: 700; cursor: pointer;
    transition: border-color 0.12s, box-shadow 0.12s;
}
.lightbox-btn:hover { border-color: var(--text); box-shadow: var(--glow); }
.lightbox-prev { left: 16px; }
.lightbox-next { right: 16px; }
.lightbox-close { top: 16px; right: 16px; transform: none; width: 34px; height: 34px; font-size: 0.85rem; }
.lightbox-single .lightbox-prev, .lightbox-single .lightbox-next { display: none; }
.lightbox-count {
    position: absolute; left: 16px; top: 16px; font-size: 0.7rem; color: var(--muted); letter-spacing: 0.1em;
}
@media (max-width: 768px) {
    .post a.post-img img { max-height: 320px; }
    .lightbox-prev, .lightbox-next { top: auto; bottom: 16px; transform: none; }
}
