:root {
    color-scheme: light;
    --paper: #f7f5ed;
    --leaf: #fffef9;
    --ink: #20342c;
    --forest: #154e41;
    --muted: #53655a;
    --rule: #ced4c8;
    --rust: #8d4826;
    --serif: "Noto Serif TC", "Songti TC", "PMingLiU", serif;
    --sans: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
    --mono: "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--paper); font: 1rem/1.75 var(--sans); }
h1, h2, h3, p, ol, blockquote { margin: 0; }
h1, h2, h3 { line-height: 1.35; text-wrap: balance; }
a { color: var(--forest); text-underline-offset: .25em; }
a:hover { color: var(--rust); }
:focus-visible { outline: 3px solid var(--rust); outline-offset: 3px; }
.shell { width: min(72rem, calc(100% - clamp(2.25rem, 10vw, 9rem))); margin-inline: auto; }
time, .video-timestamp { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.skip-link { position: absolute; z-index: 2; top: 0; left: 1rem; padding: .5rem 1rem; background: var(--leaf); transform: translateY(-115%); }
.skip-link:focus { transform: none; }

.site-header { border-bottom: 1px solid var(--rule); }
.top-nav, .nav-links, .brand, .breadcrumb, .note-kind, .site-footer { display: flex; align-items: center; }
.top-nav { min-height: 4rem; justify-content: space-between; gap: 1rem; }
.top-nav a { color: var(--ink); text-decoration: none; }
.brand { font: bold 1.4rem/1 Georgia, serif; letter-spacing: -.04em; }
.brand span:last-child { color: var(--forest); }
.brand-mark {
    width: 1.25rem; height: 1.25rem; margin-right: .46rem; border-radius: 50%;
    background: linear-gradient(135deg, var(--forest) 45%, transparent 46% 52%, var(--forest) 53% 70%, transparent 71% 77%, var(--forest) 78%);
}
.nav-links { gap: clamp(1rem, 3vw, 2.5rem); font-size: .93rem; font-weight: 650; }
.nav-links a { padding-block: .5rem; }
.nav-links a[aria-current], .nav-links a:hover { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: .45em; }

.intro { padding-block: clamp(1.5rem, 3vw, 3rem) clamp(1.55rem, 3vw, 2.8rem); }
.breadcrumb { gap: .65rem; color: var(--muted); font-size: .84rem; }
.breadcrumb a { color: inherit; }
.breadcrumb span { color: var(--rust); }
.intro-spread {
    display: grid; grid-template-columns: 1.4fr 1fr; align-items: center;
    gap: clamp(2rem, 6vw, 5.5rem); margin-block: 1.4rem .8rem;
}
.intro h1 { font-size: clamp(2.35rem, 4.35vw, 4.25rem); line-height: 1.18; letter-spacing: -.05em; margin-bottom: 1.15rem; }
.intro h1 span { display: block; color: var(--forest); }
.opening p, .chapter-text p, .chapter-heading p, .section-heading p, .closing p {
    color: var(--muted); line-height: 1.95; font-size: 1.05rem;
}
.opening p + p, .chapter-text p + p { margin-top: .75rem; }
.opening p:last-child { color: var(--ink); }

.batch-record { padding: clamp(1.3rem, 3vw, 2.6rem); background: #174b3e; color: #fffdf3; border-top: .3rem solid #bf8751; }
.batch-date { color: #f4c99b; font-size: .85rem; }
.batch-date time { margin-right: .25rem; }
.batch-record h2 { margin: .65rem 0 1.15rem; font: 700 clamp(1.45rem, 2.2vw, 2rem)/1.45 var(--serif); }
.tally { display: flex; align-items: center; gap: clamp(1rem, 2.4vw, 2.25rem); padding: .8rem 0 1.15rem; border-block: 1px solid #709084; }
.tally p { color: #e4ece3; font-size: .86rem; }
.tally strong { display: block; color: var(--leaf); font: 400 clamp(2.7rem, 4.5vw, 4rem)/1.1 Georgia, serif; }
.tally small { font: 500 .9rem var(--sans); }
.tally > span { color: #f2be87; font-size: 1.6rem; }
.batch-record > p:not(.batch-date) { margin: 1rem 0; color: #e4ece3; }
.batch-record a { display: inline-block; padding-block: .3rem; color: #fff0d8; font-weight: 650; }
.batch-record a:focus-visible { outline-color: #ffd292; }
.record-links { display: flex; flex-wrap: wrap; gap: .25rem 1.3rem; }

.notebook {
    --left-page: 55%;
    --inset: clamp(1.35rem, 3.5vw, 3.2rem);
    position: relative; isolation: isolate;
    padding: var(--inset); border: 1px solid #bdc8b8; border-left: .45rem solid var(--forest);
    background: var(--leaf);
    box-shadow: 0 3px 0 -1px #f6f5ec, 0 4px 0 -1px #a9b8a5, 0 7px 0 -2px #e0e2d4;
}
.note-kind { gap: .5rem; color: var(--forest); font-size: .86rem; font-weight: 700; }
.paper-icon { display: inline-block; width: .9rem; height: 1.05rem; border: 1.5px solid; border-radius: 1px 3px 1px 1px; background: repeating-linear-gradient(0deg, transparent 0 3px, currentColor 3px 4px) center / 52% 57% no-repeat; }
.note-intro h2 { margin-block: .45rem .35rem; font-family: var(--serif); font-size: clamp(1.5rem, 2.5vw, 2.25rem); letter-spacing: -.025em; }
.note-intro > p:last-child { color: var(--muted); font-size: .91rem; }
.excerpts { margin-top: 1.25rem; border-bottom: 1px solid var(--rule); }
.excerpt { border-top: 1px solid var(--rule); }
.excerpt summary {
    display: flex; align-items: center; justify-content: space-between; gap: .75rem;
    min-height: 3.5rem; padding: .65rem .15rem; list-style: none; cursor: pointer;
    font-weight: 650; line-height: 1.55;
}
.excerpt summary::-webkit-details-marker { display: none; }
.excerpt summary:hover .citation, .excerpt summary:focus-visible .citation { text-decoration: underline; text-underline-offset: .2em; }
.citation {
    display: inline-flex; align-items: baseline; flex-shrink: 0; gap: .3rem;
    padding: .1rem .4rem; border: 1px solid #bdc7b9; border-radius: .2rem;
    color: var(--forest); font-size: .8rem; font-weight: 600;
}
.excerpt[open] .citation { border-color: #a86e40; color: #6c3d22; background: #fae3bd; box-shadow: inset 0 -2px #be8a50; }
.source-text p { display: flex; align-items: baseline; gap: .8rem; color: var(--forest); font-size: .88rem; font-weight: 700; }
.source-text .video-timestamp { padding-left: .75rem; border-left: 1px solid #9ba997; font-size: .94rem; }
.source-text blockquote { color: var(--forest); font: 650 clamp(1.35rem, 2.05vw, 2rem)/1.8 var(--serif); }
.source-prompt { display: none; }

@media (min-width: 57rem) {
    .notebook::before {
        content: ""; position: absolute; z-index: -1; inset: 0 0 0 var(--left-page); border-left: 1px solid #c1cabc;
        background: linear-gradient(90deg, #d3dccd, transparent 1rem),
            repeating-linear-gradient(0deg, transparent 0 1.95rem, #879c801d 1.95rem 2rem), #edf0e4;
    }
    .notebook::after {
        content: ""; position: absolute; top: -1px; right: var(--inset); width: 1.35rem; height: 3.2rem;
        background: #c47b43; clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 80%, 0 100%);
    }
    .note-intro, .excerpts { width: calc((100% + 2 * var(--inset)) * .55 - 2 * var(--inset)); }
    .source-text, .source-prompt { position: absolute; left: calc(var(--left-page) + var(--inset)); right: var(--inset); top: 50%; transform: translateY(-50%); }
    .source-text blockquote::before { display: block; content: "“" / ""; height: 2.5rem; margin-top: 1rem; color: #9b5b31; font: 4rem/1 Georgia, serif; }
    .notebook:not(:has(.excerpt[open])) .source-prompt { display: block; color: var(--muted); }
}

.value, .reading, .chapter, .closing { padding-block: clamp(2.2rem, 4vw, 3.8rem); border-top: 1px solid var(--rule); }
.section-heading, .chapter, .closing { display: grid; grid-template-columns: minmax(0, .8fr) minmax(0, 1.45fr); gap: clamp(1.5rem, 7vw, 6.5rem); align-items: start; }
.value h2, .chapter h2, .closing h2 { font-size: clamp(1.55rem, 2.45vw, 2.3rem); line-height: 1.43; letter-spacing: -.035em; }
.section-heading { margin-bottom: 1.5rem; }
.comparison { width: 100%; border-collapse: collapse; line-height: 1.75; }
.comparison th, .comparison td { padding: .85rem 1.2rem; text-align: left; vertical-align: top; border-bottom: 1px solid var(--rule); }
.comparison thead th { color: var(--forest); border-top: 2px solid var(--forest); font-size: .9rem; }
.comparison tbody th { width: 23%; color: var(--ink); }
.comparison td { width: 38.5%; color: var(--muted); }
.comparison tr > :last-child { background: #e9eee2; }
.mobile-label { display: none; }
.chapter-text h3 { margin: 1.5rem 0 .4rem; color: var(--forest); font-size: 1.2rem; }
.chapter-text h3:first-child { margin-top: 0; }
.chapter-text code { padding: .05rem .35rem; border: 1px solid var(--rule); background: var(--leaf); color: var(--forest); font-family: var(--mono); }
.reading .chapter { padding: 0; border: 0; margin-bottom: 1.75rem; }
.chapter-heading > p { margin-top: 1rem; }
.chapter-heading .note-kind { margin: 0 0 .4rem; color: var(--forest); font-size: .86rem; }
.implementation-illustration { margin: 1.25rem 0 0; }
.implementation-illustration:first-child { margin-top: 0; }
.implementation-illustration a { display: block; border: 1px solid var(--rule); cursor: zoom-in; }
.implementation-illustration a:hover { border-color: var(--forest); }
.implementation-illustration img { display: block; width: 100%; height: auto; }
.implementation-illustration a span {
    display: block;
    padding: .3rem .65rem;
    color: var(--forest);
    font-size: .86rem;
    text-align: right;
}
.implementation-illustration figcaption,
.illustration-dialog figcaption { margin-top: .5rem; color: var(--muted); font-size: .93rem; }
html:has(.illustration-dialog[open]) { overflow: hidden; }
.illustration-dialog {
    width: min(68rem, calc(100% - 1.25rem));
    max-width: none;
    max-height: calc(100% - 1.25rem);
    padding: clamp(.5rem, 2vw, 1rem);
    border: 1px solid var(--rule);
    background: var(--paper);
    color: var(--ink);
}
.illustration-dialog::backdrop { background: rgb(19 35 29 / .82); }
.illustration-controls {
    display: flex;
    justify-content: flex-end;
    gap: .5rem;
    margin-bottom: .5rem;
}
.illustration-dialog button {
    min-height: 2.75rem;
    padding: .25rem .85rem;
    border: 1px solid var(--forest);
    background: var(--leaf);
    color: var(--forest);
    font: inherit;
    cursor: pointer;
}
.illustration-dialog button[aria-pressed="true"] { background: var(--forest); color: var(--leaf); }
.illustration-dialog figure { margin: 0; }
.illustration-viewport {
    max-height: calc(100dvh - 8rem);
    overflow: auto;
}
.illustration-dialog img {
    display: block;
    width: 100%;
    max-height: calc(100dvh - 8rem);
    object-fit: contain;
}
.illustration-viewport.is-zoomed img {
    width: max(150%, 48rem);
    max-height: none;
}
.run-receipt { margin: 1.25rem 0 0; padding: 1rem 1.25rem; border-left: 3px solid var(--forest); background: #e9eee2; }
.run-receipt figcaption { color: var(--forest); font-weight: 650; }
.run-receipt pre { margin: .65rem 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.6; }
.run-receipt pre code { padding: 0; border: 0; background: transparent; font-size: .91rem; }
.run-receipt p { font-size: .96rem; }
.closing { border-top: 2px solid var(--forest); }
[id] { scroll-margin-top: 1.25rem; }

.site-footer { justify-content: space-between; flex-wrap: wrap; gap: .5rem 1.5rem; border-top: 1px solid var(--rule); padding-block: 1.25rem 2rem; font-size: .93rem; }

@media (max-width: 56.99rem) {
    .intro-spread { grid-template-columns: 1fr; gap: 1.5rem; }
    .section-heading, .chapter, .closing { grid-template-columns: 1fr; gap: .85rem; }
    .batch-record { max-width: 42rem; }
    .opening, .chapter-text, .section-heading p, .closing p { max-width: 45rem; }
    .source-text { margin: 0 0 .8rem; padding: .75rem 1rem; border-left: 3px solid #af7949; background: #edf0e4; }
    .source-text blockquote { margin-top: .3rem; font-size: 1.16rem; }
}
@media (max-width: 40rem) {
    .top-nav { min-height: 3.5rem; flex-wrap: wrap; row-gap: 0; }
    .brand { font-size: 1.17rem; }
    .nav-links { gap: .82rem; font-size: .86rem; }
    .intro { padding-block: 1.15rem 1.5rem; }
    .intro-spread { margin-top: .7rem; }
    .intro h1 { font-size: clamp(1.95rem, 7.2vw, 2.65rem); }
    .opening p, .chapter-text p, .chapter-heading p, .section-heading p, .closing p { font-size: 1rem; line-height: 1.85; }
    .notebook { --inset: 1.05rem; border-left-width: .3rem; }
    .excerpts { margin-top: .8rem; }
    .excerpt summary { font-size: .98rem; }
    .comparison, .comparison tbody { display: block; }
    .comparison thead { position: absolute; clip-path: inset(50%); width: 1px; height: 1px; overflow: hidden; }
    .comparison tr { display: grid; grid-template-columns: 1fr 1fr; }
    .comparison tbody th { grid-column: 1 / -1; padding: .85rem 0 .3rem; border: 0; }
    .comparison td, .comparison tbody th { width: auto; }
    .comparison td { padding: .6rem; font-size: .94rem; }
    .mobile-label { display: block; margin-bottom: .25rem; font-size: .78rem; font-weight: 700; color: var(--forest); }
}
@media (forced-colors: active) {
    .excerpt[open] .citation { border: 3px double ButtonText; }
}
@media print {
    .site-header, .site-footer, .skip-link, .source-prompt { display: none; }
    .shell { width: 100%; }
    .notebook { padding: 1rem; border: 1px solid; box-shadow: none; }
    .notebook::before, .notebook::after, .source-text blockquote::before { display: none; }
    .source-text { position: static; transform: none; }
    .note-intro, .excerpts { width: auto; }
}
