:root {
    color-scheme: dark;
    --background: #0d0d0d;
    --foreground: #f0f0f0;
    --muted: #8a8a8a;
    --accent: #e53935;
    --accent-soft: rgba(229, 57, 53, 0.14);
    --border: #262626;
    --panel: #151515;
    --panel-hover: #1d1d1d;
    --matrix-fade: rgba(13, 13, 13, 0.1);
    --matrix-trail: rgba(229, 57, 53, 0.75);
    --matrix-head: rgba(255, 232, 232, 0.95);

    --mono: ui-monospace, SFMono-Regular, "SF Mono", Consolas,
        "Liberation Mono", monospace;
    --sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

    --sp: 8px;
    --col: min(760px, calc(100% - 32px));
}

/* Fixed light palette: muted stays distinct from foreground. */
html[data-theme="light"] {
    color-scheme: light;
    --background: #fbfbfb;
    --foreground: #161616;
    --muted: #6a6a6a;
    --accent: #d32f2f;
    --accent-soft: rgba(211, 47, 47, 0.1);
    --border: #e4e4e4;
    --panel: #ffffff;
    --panel-hover: #f4f4f4;
    --matrix-fade: rgba(255, 255, 255, 0.14);
    --matrix-trail: rgba(197, 17, 17, 0.55);
    --matrix-head: rgba(120, 0, 0, 0.85);
}

* {
    box-sizing: border-box;
}

.matrix-bg {
    position: fixed;
    inset: 0;
    z-index: -1;
    width: 100%;
    height: 100%;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.8s ease;
}

.matrix-bg.is-ready {
    opacity: 0.5;
}

/* When state carries over between pages, snap in instead of re-fading. */
.matrix-bg.is-restored.is-ready {
    transition: none;
}

body {
    margin: 0;
    background: var(--background);
    color: var(--foreground);
    font-family: var(--sans);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    transition:
        background-color 0.3s ease,
        color 0.3s ease;
}

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

.content {
    width: var(--col);
    margin: 0 auto;
    padding: calc(var(--sp) * 5) 0 calc(var(--sp) * 8);
}

/* ---- Header / command bar ---- */
header {
    margin-bottom: calc(var(--sp) * 5);
}

.site-title {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--accent);
    font-family: var(--mono);
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.site-title a {
    color: var(--foreground);
}

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

.logo {
    display: block;
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    overflow: hidden;
    line-height: 0;
}

.logo-img {
    display: block;
    width: 34px;
    height: 34px;
    max-width: 34px;
    max-height: 34px;
    object-fit: contain;
}

.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px 18px;
    font-family: var(--mono);
    font-size: 0.9rem;
}

.nav-links {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 22px;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Underline wipes in on hover and stays lit on the current page. */
.nav-links .element a {
    position: relative;
    display: inline-block;
    padding: 2px 0;
    color: var(--muted);
    transition: color 0.15s ease;
}

.nav-links .element a::after {
    content: "";
    position: absolute;
    left: 0;
    bottom: -2px;
    width: 100%;
    height: 2px;
    background: var(--accent);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.22s ease;
}

.nav-links .element a:hover,
.nav-links .element a[aria-current="page"] {
    color: var(--foreground);
}

.nav-links .element a:hover::after,
.nav-links .element a[aria-current="page"]::after {
    transform: scaleX(1);
}

.nav-separator {
    color: var(--muted);
    user-select: none;
}

.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    border: none;
    background: none;
    color: var(--muted);
    cursor: pointer;
    line-height: 1;
    transition: color 0.15s ease;
}

.theme-toggle:hover {
    color: var(--accent);
}

.theme-toggle svg {
    width: 1.15rem;
    height: 1.15rem;
    fill: currentColor;
}

/* ---- Hero / terminal intro ---- */
.hero {
    margin-bottom: calc(var(--sp) * 5);
    padding: 22px 22px 24px;
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: 6px;
    background: var(--panel);
}

.hero-prompt {
    margin-bottom: 10px;
    font-family: var(--mono);
    font-size: 0.85rem;
    color: var(--muted);
}

.hero-prompt .user {
    color: var(--accent);
}

.hero-prompt .path {
    color: var(--foreground);
}

.hero-line {
    font-family: var(--mono);
    font-size: clamp(1.25rem, 4.5vw, 1.7rem);
    font-weight: 700;
    letter-spacing: -0.01em;
    line-height: 1.25;
    min-height: 1.25em;
}

.hero-line .type {
    color: var(--foreground);
}

.caret {
    display: inline-block;
    width: 0.6ch;
    margin-left: 2px;
    color: var(--accent);
    animation: blink 1.05s steps(1) infinite;
}

@keyframes blink {
    50% {
        opacity: 0;
    }
}

.hero-sub {
    margin-top: 14px;
    font-size: 0.95rem;
    color: var(--muted);
}

/* ---- Section label ---- */
.section-label {
    margin-bottom: 16px;
    font-family: var(--mono);
    font-size: 0.78rem;
    letter-spacing: 0.06em;
    text-transform: lowercase;
    color: var(--muted);
}

.section-label .accent {
    color: var(--accent);
}

/* ---- Posts ---- */
.posts {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.posts--paginated > [data-post] {
    display: none;
}

.posts--paginated > [data-post].is-page-visible {
    display: block;
}

.post-card {
    position: relative;
    padding: 18px 20px 18px 22px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
    transition:
        background-color 0.18s ease,
        border-color 0.18s ease,
        transform 0.18s ease;
}

.post-card::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--accent);
    transform: scaleY(0);
    transform-origin: top;
    transition: transform 0.2s ease;
}

.post-card:hover {
    background: var(--panel-hover);
    border-color: var(--accent);
    transform: translateX(2px);
}

.post-card:hover::before {
    transform: scaleY(1);
}

.post-card .post-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 0 8px;
    font-family: var(--mono);
    font-size: 0.78rem;
    color: var(--muted);
}

.post-card .post-meta .marker {
    color: var(--accent);
}

.post-title {
    margin: 0 0 8px;
    font-family: var(--mono);
    font-size: 1.12rem;
    font-weight: 700;
    line-height: 1.35;
    letter-spacing: -0.01em;
}

/* Underline grows from a hairline gradient instead of a static border. */
.post-title a {
    display: inline;
    padding-bottom: 2px;
    background-image: linear-gradient(var(--accent), var(--accent));
    background-repeat: no-repeat;
    background-position: 0 100%;
    background-size: 0% 2px;
    transition:
        background-size 0.25s ease,
        color 0.15s ease;
}

.post-title a:hover {
    color: var(--accent);
    background-size: 100% 2px;
}

.post-excerpt {
    margin: 0 0 12px;
    color: var(--foreground);
    font-size: 0.95rem;
}

.readmore {
    font-family: var(--mono);
    font-size: 0.85rem;
    color: var(--accent);
}

.readmore .arrow {
    display: inline-block;
    transition: transform 0.18s ease;
}

.readmore:hover .arrow {
    transform: translateX(4px);
}

/* ---- Pagination ---- */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 24px;
    font-family: var(--mono);
    font-size: 0.85rem;
}

/* display: flex above would otherwise override the hidden attribute. */
.pagination[hidden] {
    display: none;
}

.pagination-link {
    padding: 7px 14px;
    border: 1px solid var(--border);
    border-radius: 5px;
    background: var(--panel);
    color: var(--foreground);
    font: inherit;
    cursor: pointer;
    transition:
        border-color 0.15s ease,
        color 0.15s ease,
        background-color 0.15s ease;
}

.pagination-link:hover:not(.is-disabled) {
    border-color: var(--accent);
    color: var(--accent);
}

.pagination-link.is-disabled {
    opacity: 0.35;
    color: var(--muted);
    pointer-events: none;
    cursor: default;
}

.page-info {
    color: var(--muted);
}

/* ---- Footer ---- */
footer {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 10px 16px;
    margin-top: calc(var(--sp) * 6);
    padding-top: 18px;
    border-top: 1px solid var(--border);
    font-family: var(--mono);
    font-size: 0.82rem;
    color: var(--muted);
}

footer a {
    color: var(--muted);
    transition: color 0.15s ease;
}

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

/* ---- Single post ---- */
.post {
    margin-top: 8px;
}

.post-header {
    margin-bottom: 28px;
}

.post-header-title {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    margin-bottom: 8px;
}

.post-marker {
    flex-shrink: 0;
    width: 8px;
    height: 8px;
    margin-top: 8px;
    background: var(--accent);
}

.post-heading {
    margin: 0;
    font-family: var(--mono);
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.3;
    letter-spacing: -0.01em;
    border-bottom: 2px solid var(--accent);
}

.post-meta {
    margin: 0;
    font-family: var(--mono);
    color: var(--muted);
    font-size: 0.85rem;
}

header .post-meta {
    margin-top: 10px;
    margin-bottom: 16px;
}

.post-content {
    line-height: 1.75;
}

.post-content p {
    margin: 0 0 1.25em;
}

.post-content p:last-child {
    margin-bottom: 0;
}

.post-content img {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 1.25em 0;
    border: 1px solid var(--border);
    border-radius: 6px;
}

.post-content a {
    color: var(--accent);
    border-bottom: 2px solid var(--accent);
}

.post-content a:hover {
    opacity: 0.85;
}

/* ---- Archive (projects) ---- */
.archive {
    margin-top: 8px;
}

.archive-header {
    margin-bottom: 16px;
}

/* Terminal-style page title styled like the home "$ ls ~/posts" label. */
.archive-heading {
    margin: 0;
    font-family: var(--mono);
    font-size: 0.78rem;
    font-weight: 400;
    letter-spacing: 0.06em;
    text-transform: lowercase;
    color: var(--muted);
}

.archive-heading .accent {
    color: var(--accent);
}

.archive-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.archive-item {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 10px;
    margin-bottom: 14px;
}

.archive-bullet {
    flex-shrink: 0;
    width: 6px;
    height: 6px;
    margin-top: 0.45em;
    background: var(--foreground);
}

.archive-title {
    padding-bottom: 2px;
    font-weight: 700;
    background-image: linear-gradient(var(--accent), var(--accent));
    background-repeat: no-repeat;
    background-position: 0 100%;
    background-size: 0% 2px;
    transition:
        background-size 0.25s ease,
        color 0.15s ease;
}

.archive-title:hover {
    color: var(--accent);
    background-size: 100% 2px;
}

.archive-date {
    font-family: var(--mono);
    color: var(--muted);
    font-size: 0.85rem;
}

/* ---- Book list ---- */
.book-list {
    margin-top: 8px;
}

.book-year {
    margin-bottom: 18px;
}

.book-year:last-child {
    margin-bottom: 0;
}

.book-year-heading {
    margin: 0 0 6px;
    font-family: var(--mono);
    font-size: 1.1rem;
    font-weight: 700;
    line-height: 1.3;
}

.book-year-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    padding: 0;
    border: none;
    background: none;
    color: inherit;
    font: inherit;
    line-height: inherit;
    text-align: left;
    cursor: pointer;
}

.book-year-toggle:hover {
    color: var(--accent);
}

.book-year-marker {
    flex-shrink: 0;
    width: 6px;
    height: 6px;
    background: var(--accent);
    transition: transform 0.15s ease;
}

.book-year-toggle[aria-expanded="true"] .book-year-marker {
    transform: rotate(90deg);
}

.book-year-list {
    margin: 0;
    padding: 0 0 0 16px;
    list-style: none;
}

.book-year-list li + li {
    margin-top: 2px;
}

.book-link {
    padding-bottom: 1px;
    font-weight: 700;
    background-image: linear-gradient(var(--accent), var(--accent));
    background-repeat: no-repeat;
    background-position: 0 100%;
    background-size: 0% 2px;
    transition:
        background-size 0.25s ease,
        color 0.15s ease;
}

.book-link:hover {
    color: var(--accent);
    background-size: 100% 2px;
}

/* ---- Reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
    }
    .caret {
        opacity: 1;
    }
}

/* ---- Print ---- */
@media print {
    .matrix-bg,
    .theme-toggle,
    .pagination,
    .nav-separator {
        display: none;
    }
    body {
        background: #fff;
        color: #000;
    }
    .hero,
    .post-card {
        border: 1px solid #ccc;
        background: #fff;
    }
}
