/* ==========================================================================
   mujun.xyz — Technical knowledge, preserved.
   Anti-design + diagonal sections + forest green + aged paper.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Tokens
   -------------------------------------------------------------------------- */
:root {
    --forest-darkest: #1A2F0A;
    --forest-deep: #2D5016;
    --forest-mid: #3A6B1F;
    --forest-light: #4A8C2A;
    --paper-bright: #F5F1EB;
    --paper-warm: #D4C4B0;
    --green-muted: #8B9B84;
    --tan-neutral: #C9BFA8;

    --diag-angle: 17deg;
    --diag-shift: calc(tan(17deg) * 50vw);

    --measure: 64ch;
    --margin-x: clamp(1.25rem, 6vw, 6rem);

    --shadow-paper: 0 2px 4px rgba(26, 47, 10, 0.12);
    --shadow-aside: 0 1px 3px rgba(26, 47, 10, 0.08);

    --serif-display: "Lora", "Baskerville", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
    --serif-body: "Lora", "Iowan Old Style", Georgia, "Times New Roman", serif;
    --mono-code: "IBM Plex Mono", "SF Mono", Menlo, Consolas, monospace;
}

/* --------------------------------------------------------------------------
   Reset and base
   -------------------------------------------------------------------------- */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    text-size-adjust: 100%;
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--paper-bright);
    color: var(--forest-darkest);
    font-family: var(--serif-body);
    font-size: 1.125rem;
    line-height: 1.7;
    letter-spacing: 0.005em;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

img,
svg {
    max-width: 100%;
    display: block;
}

::selection {
    background: var(--forest-light);
    color: var(--paper-bright);
}

/* --------------------------------------------------------------------------
   Aged paper texture (full-bleed, fixed, very subtle)
   -------------------------------------------------------------------------- */
.paper-overlay {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background-image:
        radial-gradient(ellipse 2px 2px at 12% 18%, rgba(139, 90, 30, 0.18) 0%, transparent 60%),
        radial-gradient(ellipse 3px 1px at 78% 32%, rgba(139, 90, 30, 0.10) 0%, transparent 60%),
        radial-gradient(ellipse 1px 2px at 33% 71%, rgba(139, 90, 30, 0.14) 0%, transparent 60%),
        radial-gradient(ellipse 2px 3px at 88% 88%, rgba(139, 90, 30, 0.08) 0%, transparent 60%),
        radial-gradient(ellipse 1px 1px at 55% 47%, rgba(58, 107, 31, 0.06) 0%, transparent 70%),
        url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' seed='7'/><feColorMatrix values='0 0 0 0 0.13  0 0 0 0 0.10  0 0 0 0 0.06  0 0 0 0.07 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
    background-size: 100% 100%, 100% 100%, 100% 100%, 100% 100%, 100% 100%, 240px 240px;
    background-repeat: no-repeat, no-repeat, no-repeat, no-repeat, no-repeat, repeat;
    mix-blend-mode: multiply;
    opacity: 0.85;
}

/* --------------------------------------------------------------------------
   Section structure with diagonal cuts
   -------------------------------------------------------------------------- */
.section {
    position: relative;
    z-index: 1;
    padding: clamp(4rem, 10vh, 8rem) var(--margin-x) clamp(5rem, 12vh, 10rem);
}

.section + .section {
    margin-top: -1px; /* close hairline gap from the diagonal */
}

.section-inner {
    position: relative;
    max-width: 72ch;
    margin: 0 auto;
}

/* The "diagonal bottom" element is a flat strip at +17° on the bottom of each
   section, drawn with a stretched green hairline plus a paper-warm wedge. */
.diagonal-bottom {
    position: absolute;
    left: -10%;
    right: -10%;
    bottom: 0;
    height: 1px;
    background: var(--green-muted);
    transform: rotate(calc(var(--diag-angle) * -0.18));
    transform-origin: 50% 100%;
    pointer-events: none;
    opacity: 0.55;
}

.diagonal-bottom::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: -2px;
    height: 1px;
    background: var(--forest-mid);
    opacity: 0.18;
}

/* --------------------------------------------------------------------------
   Section: Hero
   -------------------------------------------------------------------------- */
.section-hero {
    min-height: 88vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding-top: clamp(6rem, 14vh, 10rem);
    padding-bottom: clamp(8rem, 16vh, 12rem);
    background-color: var(--paper-bright);
}

.hero-inner {
    text-align: center;
    max-width: 56ch;
    position: relative;
}

.hero-title {
    font-family: var(--serif-display);
    font-weight: 500;
    font-size: clamp(2.6rem, 8vw, 5.4rem);
    color: var(--forest-deep);
    margin: 0 0 1.25rem;
    letter-spacing: 0.01em;
    line-height: 1.05;
    font-style: normal;
    position: relative;
    z-index: 2;
}

.hero-subtitle {
    font-family: var(--serif-body);
    font-style: italic;
    font-size: clamp(1.05rem, 1.6vw, 1.35rem);
    color: var(--forest-mid);
    margin: 0 auto;
    max-width: 36ch;
    position: relative;
    z-index: 2;
}

.hero-ripple {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    pointer-events: none;
    z-index: 1;
}

.ripple-circle {
    position: absolute;
    top: 0;
    left: 0;
    width: 12rem;
    height: 12rem;
    margin: -6rem 0 0 -6rem;
    border-radius: 50%;
    border: 1px solid var(--forest-light);
    opacity: 0;
    transform: scale(0.4);
    animation: hero-ripple 4s ease-out 0.4s 1 forwards;
}

.ripple-2 {
    animation-delay: 0.9s;
    width: 18rem;
    height: 18rem;
    margin: -9rem 0 0 -9rem;
}

.ripple-3 {
    animation-delay: 1.4s;
    width: 26rem;
    height: 26rem;
    margin: -13rem 0 0 -13rem;
}

@keyframes hero-ripple {
    0% { opacity: 0; transform: scale(0.35); }
    20% { opacity: 0.18; }
    100% { opacity: 0; transform: scale(1.35); }
}

@media (prefers-reduced-motion: reduce) {
    .ripple-circle {
        animation: none;
    }
}

.hero-meta {
    margin: 3.5rem auto 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.25rem;
    color: var(--green-muted);
    font-family: var(--mono-code);
    font-size: 0.78rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    position: relative;
    z-index: 2;
}

.meta-line {
    flex: 0 0 4rem;
    height: 1px;
    background: var(--green-muted);
    opacity: 0.55;
}

/* --------------------------------------------------------------------------
   Section heads (used in essay/tutorial/index/colophon)
   -------------------------------------------------------------------------- */
.section-head {
    margin: 0 0 2.5rem;
    border-bottom: 1px solid var(--green-muted);
    padding-bottom: 1.25rem;
}

.section-num {
    display: block;
    font-family: var(--serif-display);
    font-style: italic;
    font-size: 1rem;
    color: var(--forest-light);
    letter-spacing: 0.06em;
    margin-bottom: 0.4rem;
}

.section-title {
    font-family: var(--serif-display);
    font-weight: 500;
    font-size: clamp(2rem, 5vw, 3.6rem);
    color: var(--forest-deep);
    margin: 0 0 0.5rem;
    letter-spacing: 0.01em;
    line-height: 1.15;
}

.section-kicker {
    font-style: italic;
    color: var(--green-muted);
    margin: 0;
    font-size: 1rem;
    max-width: 56ch;
}

/* --------------------------------------------------------------------------
   Essay/tutorial body
   -------------------------------------------------------------------------- */
.section-essay,
.section-tutorial {
    background-color: var(--paper-bright);
}

.essay-body p {
    margin: 0 0 1.4rem;
}

.essay-body p.lede {
    font-size: 1.22rem;
    color: var(--forest-deep);
    line-height: 1.55;
    margin-bottom: 2rem;
}

.essay-body em {
    font-style: italic;
    color: var(--forest-deep);
}

.essay-body a {
    color: var(--forest-deep);
    text-decoration: underline;
    text-decoration-color: var(--forest-light);
    text-decoration-thickness: 1.5px;
    text-underline-offset: 3px;
    transition: text-decoration-color 0.2s ease, color 0.2s ease;
}

.essay-body a:hover {
    color: var(--forest-darkest);
    text-decoration-color: var(--forest-deep);
}

.essay-body code {
    font-family: var(--mono-code);
    font-size: 0.92em;
    background: var(--paper-warm);
    color: var(--forest-darkest);
    padding: 0.05rem 0.35rem;
    border-radius: 1px;
    border: 1px solid rgba(139, 155, 132, 0.4);
}

/* --------------------------------------------------------------------------
   Pull quote
   -------------------------------------------------------------------------- */
.pullquote {
    margin: 2.5rem 0;
    padding: 0 0 0 1.25rem;
    border-left: 4px solid var(--forest-light);
    color: var(--forest-mid);
    font-family: var(--serif-display);
    font-size: clamp(1.3rem, 2.3vw, 1.8rem);
    line-height: 1.45;
    font-style: italic;
}

.pullquote p {
    margin: 0;
}

.pullquote .attribution {
    display: block;
    margin-top: 0.5rem;
    font-size: 0.85rem;
    font-style: normal;
    color: var(--green-muted);
    letter-spacing: 0.04em;
}

/* --------------------------------------------------------------------------
   Aside (right-floated note)
   -------------------------------------------------------------------------- */
.aside {
    position: relative;
    margin: 1rem 0 1.75rem;
    padding: 1.1rem 1.25rem;
    background: var(--paper-warm);
    border: 1px solid var(--green-muted);
    color: var(--forest-deep);
    font-size: 0.95rem;
    line-height: 1.55;
    box-shadow: var(--shadow-aside);
}

.aside-title {
    margin: 0 0 0.4rem;
    font-family: var(--serif-display);
    font-style: italic;
    font-size: 0.95rem;
    color: var(--forest-mid);
    letter-spacing: 0.03em;
    font-weight: 500;
}

.aside p {
    margin: 0;
}

.aside-right sup {
    color: var(--forest-light);
}

@media (min-width: 900px) {
    .aside-right {
        float: right;
        clear: right;
        width: 16rem;
        margin: 0.25rem -6rem 1.25rem 1.5rem;
    }
}

@media (min-width: 1180px) {
    .aside-right {
        margin-right: -10rem;
    }
}

/* --------------------------------------------------------------------------
   Code blocks (carbon-paper layer)
   -------------------------------------------------------------------------- */
.code-block {
    position: relative;
    margin: 1.75rem 0 2rem;
    padding: 0;
    background: var(--paper-warm);
    border: 1px solid var(--green-muted);
    box-shadow: var(--shadow-paper);
    overflow: hidden;
}

.code-caption {
    display: block;
    padding: 0.55rem 1rem;
    background: rgba(58, 107, 31, 0.06);
    border-bottom: 1px solid var(--green-muted);
    font-family: var(--serif-display);
    font-style: italic;
    font-size: 0.88rem;
    color: var(--forest-mid);
    letter-spacing: 0.02em;
}

.code-block pre {
    margin: 0;
    padding: 1.1rem 1.2rem 1.25rem;
    overflow-x: auto;
    background: transparent;
}

.code-block code {
    font-family: var(--mono-code);
    font-size: 0.95rem;
    line-height: 1.55;
    color: var(--forest-darkest);
    background: transparent;
    padding: 0;
    border: 0;
    white-space: pre;
}

.code-copy {
    position: absolute;
    top: 0.5rem;
    right: 0.6rem;
    background: var(--forest-deep);
    color: var(--paper-bright);
    border: 0;
    padding: 0.35rem 0.75rem;
    font-family: var(--mono-code);
    font-size: 0.72rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s ease, background-color 0.2s ease;
    z-index: 2;
}

.code-block:hover .code-copy,
.code-block:focus-within .code-copy,
.code-copy:focus-visible {
    opacity: 1;
}

.code-copy:hover {
    background: var(--forest-darkest);
}

.code-copy.is-copied {
    background: var(--forest-light);
}

/* --------------------------------------------------------------------------
   Reading list (Section 3)
   -------------------------------------------------------------------------- */
.section-index {
    background: linear-gradient(180deg, var(--paper-bright), var(--paper-warm) 100%);
}

.reading-list {
    list-style: none;
    margin: 0;
    padding: 0;
    counter-reset: reading;
}

.reading-item {
    display: grid;
    grid-template-columns: 4rem 1fr;
    gap: 1.5rem;
    padding: 1.5rem 0;
    border-bottom: 1px dotted var(--green-muted);
    align-items: baseline;
}

.reading-item:last-child {
    border-bottom: 0;
}

.reading-num {
    font-family: var(--mono-code);
    font-size: 0.85rem;
    color: var(--forest-light);
    letter-spacing: 0.18em;
    padding-top: 0.4rem;
}

.reading-title {
    font-family: var(--serif-display);
    font-weight: 500;
    font-size: 1.4rem;
    color: var(--forest-deep);
    margin: 0 0 0.25rem;
    letter-spacing: 0.01em;
}

.reading-meta {
    font-family: var(--mono-code);
    font-size: 0.74rem;
    color: var(--green-muted);
    letter-spacing: 0.14em;
    text-transform: uppercase;
    margin: 0 0 0.5rem;
}

.reading-summary {
    margin: 0;
    color: var(--forest-darkest);
    font-size: 1rem;
    line-height: 1.6;
    max-width: 56ch;
}

.reading-item.is-pending .reading-title,
.reading-item.is-pending .reading-summary {
    color: var(--green-muted);
}

.reading-item.is-pending .reading-num {
    color: var(--tan-neutral);
}

/* --------------------------------------------------------------------------
   Colophon (Section 4)
   -------------------------------------------------------------------------- */
.section-colophon {
    background-color: var(--paper-warm);
    padding-bottom: clamp(6rem, 12vh, 9rem);
}

.colophon-list {
    margin: 0 0 3rem;
    padding: 0;
    border-top: 1px solid var(--green-muted);
}

.colophon-row {
    display: grid;
    grid-template-columns: 10rem 1fr;
    gap: 1.5rem;
    padding: 0.85rem 0;
    border-bottom: 1px solid var(--green-muted);
}

.colophon-row dt {
    font-family: var(--mono-code);
    font-size: 0.78rem;
    color: var(--forest-mid);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    padding-top: 0.2rem;
}

.colophon-row dd {
    margin: 0;
    color: var(--forest-darkest);
    font-size: 1rem;
    line-height: 1.55;
}

.colophon-row code {
    font-family: var(--mono-code);
    font-size: 0.88em;
    color: var(--forest-deep);
    background: rgba(245, 241, 235, 0.6);
    padding: 0.05rem 0.35rem;
    border: 1px solid rgba(139, 155, 132, 0.4);
}

.footnotes {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px dashed var(--green-muted);
}

.footnotes-title {
    margin: 0 0 0.75rem;
    font-family: var(--serif-display);
    font-style: italic;
    font-size: 1rem;
    color: var(--forest-mid);
    font-weight: 500;
    letter-spacing: 0.04em;
}

.footnote {
    font-size: 0.92rem;
    color: var(--forest-darkest);
    margin: 0;
    line-height: 1.55;
}

.footnote sup {
    color: var(--forest-light);
    font-weight: 500;
    margin-right: 0.25rem;
}

/* --------------------------------------------------------------------------
   Footer
   -------------------------------------------------------------------------- */
.page-footer {
    position: relative;
    z-index: 1;
    padding: 2.5rem var(--margin-x) 3.5rem;
    background: var(--paper-warm);
    border-top: 1px solid var(--green-muted);
    text-align: center;
    color: var(--forest-mid);
    font-family: var(--serif-body);
    font-style: italic;
    font-size: 0.95rem;
    line-height: 1.6;
}

.footer-text {
    margin: 0 0 0.4rem;
}

.footer-mark {
    margin: 0;
    font-family: var(--mono-code);
    font-style: normal;
    font-size: 0.75rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--green-muted);
}

.footer-stamp {
    color: var(--forest-light);
}

/* --------------------------------------------------------------------------
   Copy flash (toast) — used by script.js
   -------------------------------------------------------------------------- */
.copy-flash {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translate(-50%, 1rem);
    background: var(--forest-darkest);
    color: var(--paper-bright);
    padding: 0.55rem 1.1rem;
    font-family: var(--mono-code);
    font-size: 0.78rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
    z-index: 99;
    border: 1px solid var(--forest-light);
}

.copy-flash.is-visible {
    opacity: 1;
    transform: translate(-50%, 0);
}

/* --------------------------------------------------------------------------
   Scroll-triggered ripple at section diagonals
   -------------------------------------------------------------------------- */
.scroll-ripple {
    position: absolute;
    left: 50%;
    bottom: 0;
    width: 0;
    height: 0;
    pointer-events: none;
    z-index: 3;
}

.scroll-ripple .scroll-ripple-circle {
    position: absolute;
    top: 0;
    left: 0;
    width: 4rem;
    height: 4rem;
    margin: -2rem 0 0 -2rem;
    border-radius: 50%;
    border: 1px solid var(--forest-light);
    opacity: 0.18;
    transform: scale(0.5);
    animation: scroll-ripple 0.9s ease-out forwards;
}

@keyframes scroll-ripple {
    0% { opacity: 0.22; transform: scale(0.4); }
    100% { opacity: 0; transform: scale(8); }
}

@media (prefers-reduced-motion: reduce) {
    .scroll-ripple .scroll-ripple-circle {
        animation: none;
        display: none;
    }
}

/* --------------------------------------------------------------------------
   Responsive adjustments
   -------------------------------------------------------------------------- */
@media (max-width: 720px) {
    body {
        font-size: 1.05rem;
        line-height: 1.65;
    }

    .section {
        padding-left: 1.25rem;
        padding-right: 1.25rem;
    }

    .colophon-row {
        grid-template-columns: 1fr;
        gap: 0.25rem;
        padding: 0.75rem 0;
    }

    .reading-item {
        grid-template-columns: 2.5rem 1fr;
        gap: 1rem;
    }

    .essay-body p.lede {
        font-size: 1.1rem;
    }

    .pullquote {
        font-size: 1.2rem;
    }

    .code-block pre {
        padding: 0.85rem 0.95rem 1rem;
    }

    .code-block code {
        font-size: 0.85rem;
    }

    .code-copy {
        opacity: 1; /* Always visible on touch devices */
    }
}

/* --------------------------------------------------------------------------
   Print styles
   -------------------------------------------------------------------------- */
@media print {
    body {
        background: #fff;
        color: #000;
    }

    .paper-overlay,
    .hero-ripple,
    .scroll-ripple,
    .copy-flash,
    .code-copy {
        display: none !important;
    }

    .section {
        padding: 1.5rem 0;
        page-break-after: auto;
    }

    .essay-body a::after {
        content: " (" attr(href) ")";
        font-family: var(--mono-code);
        font-size: 0.85em;
        color: #444;
    }

    .code-block {
        background: #f5f5f0;
        border: 1px solid #888;
    }
}
