:root {
    color-scheme: light;
    --bg: #f6f8fa;
    --surface: #ffffff;
    --surface-soft: #f6f8fa;
    --text: #1f2328;
    --muted: #59636e;
    --border: #d0d7de;
    --border-strong: #8c959f;
    --link: #0969da;
    --link-hover: #0550ae;
    --accent: #1f6feb;
    --accent-text: #ffffff;
    --code-bg: #f6f8fa;
    --inline-code-bg: #eaf2ff;
    --inline-code-text: #1f2328;
    --quote-bg: #fff2c2;
    --quote-border: #bf8700;
    --quote-text: #3d2b00;
    --scrollbar-track: #d8dee4;
    --scrollbar-thumb: #686868;
    --scrollbar-thumb-hover: #4f4f4f;
    --shadow: 0 10px 30px rgba(31, 35, 40, 0.08);
    --switch-track: #d0d7de;
    --switch-knob: #ffffff;
    --measure: 750px;
    --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", Menlo, monospace;
}

html[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0d1117;
    --surface: #161b22;
    --surface-soft: #0d1117;
    --text: #e6edf3;
    --muted: #8d96a0;
    --border: #30363d;
    --border-strong: #6e7681;
    --link: #58a6ff;
    --link-hover: #79c0ff;
    --accent: #238636;
    --accent-text: #ffffff;
    --code-bg: #161b22;
    --inline-code-bg: #233346;
    --inline-code-text: #f0f6fc;
    --quote-bg: #302611;
    --quote-border: #f0b429;
    --quote-text: #ffe7a3;
    --scrollbar-track: #424242;
    --scrollbar-thumb: #6e7681;
    --scrollbar-thumb-hover: #8b949e;
    --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
    --switch-track: #30363d;
    --switch-knob: #e6edf3;
}

html[data-theme="dark"] .play-button {
    --play-face: #f0f0f0;
    --play-face-hover: #ffffff;
    --play-text: #000000;
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    line-height: 1.65;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

::-webkit-scrollbar {
    width: 14px;
    height: 14px;
    background-color: var(--scrollbar-track);
}

::-webkit-scrollbar-track {
    background-color: var(--scrollbar-track);
}

::-webkit-scrollbar-thumb {
    min-height: 2rem;
    border: 3px solid var(--scrollbar-track);
    background-color: var(--scrollbar-thumb);
}

::-webkit-scrollbar-thumb:hover {
    background-color: var(--scrollbar-thumb-hover);
}

a {
    color: var(--link);
    text-decoration: none;
}

a:hover,
a:focus-visible {
    color: var(--link-hover);
    text-decoration: underline;
}

.page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.site-header {
    background: transparent;
}

.site-header__inner,
.site-main,
.site-footer__inner {
    width: min(var(--measure), calc(100% - 2rem));
    margin: 0 auto;
}

.site-header__inner {
    display: grid;
    grid-template-columns: 3.1rem minmax(0, 1fr) 3.1rem;
    align-items: center;
    gap: 1rem;
    padding: 2rem 0 1.1rem;
}

.site-title {
    grid-column: 2;
    justify-self: center;
    margin: 0;
    font-size: clamp(2.55rem, 8vw, 4.25rem);
    font-weight: 700;
    line-height: 1.05;
    letter-spacing: -0.04em;
    text-align: center;
}

.theme-switch {
    position: relative;
    grid-column: 3;
    justify-self: end;
    flex: none;
    display: inline-flex;
    width: 3.1rem;
    height: 1.65rem;
    cursor: pointer;
}

.theme-switch input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
}

.theme-switch__track {
    width: 100%;
    height: 100%;
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    background: var(--switch-track);
}

.theme-switch__track::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 0.18rem;
    width: 1.14rem;
    height: 1.14rem;
    border-radius: 50%;
    background: var(--switch-knob);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.22);
    transform: translateY(-50%);
    transition: transform 0.18s ease;
}

.theme-switch input:checked + .theme-switch__track::before {
    transform: translate(1.42rem, -50%);
}

.theme-switch input:focus-visible + .theme-switch__track {
    outline: 2px solid var(--link);
    outline-offset: 3px;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

.site-main {
    flex: 1;
    padding: 1rem 0 4rem;
}

.article {
    padding: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
}

.article h1,
.article h2,
.article h3 {
    position: relative;
    margin: 2rem 0 1rem;
    line-height: 1.25;
    scroll-margin-top: 1rem;
}

.article h1:first-child {
    margin-top: 0;
}

.article h1 {
    padding-bottom: 0.3rem;
    border-bottom: 1px solid var(--border);
    font-size: 2rem;
}

.article h2 {
    font-size: 1.5rem;
}

.article h3 {
    font-size: 1.2rem;
}

.heading-link {
    color: inherit;
}

.heading-link:hover,
.heading-link:focus-visible {
    color: inherit;
    text-decoration: none;
}

.copy-link {
    position: absolute;
    top: 50%;
    right: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.8rem;
    height: 1.8rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface-soft);
    color: var(--muted);
    cursor: pointer;
    opacity: 0;
    transform: translateY(-50%);
}

.article h1:hover .copy-link,
.article h2:hover .copy-link,
.article h3:hover .copy-link,
.copy-link:focus-visible {
    opacity: 1;
}

.copy-link svg,
.copy-code svg {
    width: 1rem;
    height: 1rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.article p,
.article ul,
.article ol {
    margin: 0 0 1rem;
}

.article ul,
.article ol {
    padding-left: 1.6rem;
}

.article li {
    margin: 0.35rem 0;
}

.article blockquote {
    margin: 1.25rem 0;
    padding: 0.9rem 1rem;
    border-left: 0.3rem solid var(--quote-border);
    border-radius: 7px;
    background: var(--quote-bg);
    color: var(--quote-text);
}

.article blockquote p:last-child {
    margin-bottom: 0;
}

.article code {
    padding: 0.14rem 0.32rem;
    border-radius: 5px;
    background: var(--inline-code-bg);
    color: var(--inline-code-text);
    font-family: var(--font-mono);
    font-size: 0.9em;
    box-decoration-break: clone;
}

.code-block {
    position: relative;
    margin: 1.25rem 0;
}

.article pre {
    margin: 0;
    padding: 1rem;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--code-bg);
}

.article pre code {
    padding: 0;
    border-radius: 0;
    background: transparent;
    color: inherit;
    font-size: 0.9rem;
    line-height: 1.55;
}

.tok-keyword {
    color: #cf222e;
    font-weight: 600;
}

.tok-function {
    color: #8250df;
}

.tok-number {
    color: #0550ae;
}

.tok-comment {
    color: #6e7781;
    font-style: italic;
}

.tok-string {
    color: #0a7f42;
}

html[data-theme="dark"] .tok-keyword {
    color: #ff7b72;
}

html[data-theme="dark"] .tok-function {
    color: #d2a8ff;
}

html[data-theme="dark"] .tok-number {
    color: #79c0ff;
}

html[data-theme="dark"] .tok-comment {
    color: #8b949e;
}

html[data-theme="dark"] .tok-string {
    color: #a5d6ff;
}

.copy-code {
    position: absolute;
    top: 0.55rem;
    right: 0.55rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--muted);
    cursor: pointer;
}

.table-wrap {
    margin: 1.25rem 0;
    overflow-x: auto;
}

.article table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.94rem;
}

.article th,
.article td {
    padding: 0.45rem 0.65rem;
    border: 1px solid var(--border);
}

.article th {
    background: var(--surface-soft);
    font-weight: 700;
}

.continue-code-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(8.25rem, 1fr));
    gap: 0.35rem 0.5rem;
    margin: 1.25rem 0;
    padding: 0;
    list-style: none;
}

.continue-code-grid li {
    display: grid;
    grid-template-columns: 2.75rem minmax(0, 1fr);
    align-items: center;
    margin: 0;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface-soft);
    font-family: var(--font-mono);
    font-size: 0.88rem;
    line-height: 1.25;
}

.continue-code-level {
    display: inline-flex;
    justify-content: flex-end;
    padding: 0.3rem 0.45rem;
    border-right: 1px solid var(--border);
    color: var(--muted);
}

.continue-code-level::before {
    content: "L";
}

.continue-code-value {
    padding: 0.3rem 0.5rem;
    color: var(--text);
    font-weight: 700;
    text-align: right;
}

.article img {
    display: block;
    width: min(100%, 640px);
    max-width: 100%;
    height: auto;
    margin: 1.5rem auto;
    border-radius: 4px;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

.article img[src$="objects.png"],
.article img[src$="ground.png"] {
    width: min(100%, 640px);
}

.article img[src$="ball1.png"],
.article img[src$="ball2.png"] {
    width: 148px;
}

.article img[src$="barbecue.png"] {
    width: 256px;
}

.article img[src$="mess1.png"] {
    width: min(100%, 484px);
}

.article img[src$="mess2.png"] {
    width: min(100%, 544px);
}

.article img[src$="unused-tile.png"] {
    width: 160px;
}

.restoration-image-row {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 1.5rem;
    margin: 1.5rem 0;
    flex-wrap: wrap;
}

.restoration-image-row figure {
    flex: 0 1 320px;
    margin: 0;
    text-align: center;
}

.restoration-image-row img {
    width: 100%;
    max-width: 320px;
    margin: 0 auto;
}

.restoration-image-row figcaption {
    margin-top: 0.45rem;
    color: var(--muted);
    font-family: var(--font-mono);
    font-size: 0.82rem;
}

.clp-image-row {
    display: flex;
    align-items: end;
    justify-content: center;
    gap: 1.5rem;
    margin: 1.5rem 0;
    flex-wrap: wrap;
}

.clp-image-row figure {
    margin: 0;
    text-align: center;
}

.clp-image-row img {
    margin: 0 auto;
}

.clp-image-row figcaption {
    margin-top: 0.45rem;
    color: var(--muted);
    font-family: var(--font-mono);
    font-size: 0.82rem;
}

.clp-image-row--messages {
    align-items: center;
    gap: 1rem;
}

.play-row {
    margin: 1.5rem 0 2rem;
    text-align: center;
}

.play-button {
    --play-shadow: 16px;
    --play-face: #55ffff;
    --play-face-hover: #8fffff;
    --play-shadow-color: #050505;
    --play-initial: #aa0000;
    --play-text: #0000aa;
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 17rem;
    height: 2.25rem;
    margin-right: var(--play-shadow);
    margin-bottom: var(--play-shadow);
    padding: 0 1.55rem;
    border-radius: 0;
    background: var(--play-face);
    color: var(--play-text);
    font-family: var(--font-mono);
    font-size: 1.3rem;
    font-weight: 700;
    line-height: 1;
    letter-spacing: 0.08em;
    text-decoration: none;
    box-shadow: var(--play-shadow) var(--play-shadow) 0 var(--play-shadow-color);
}

.play-button:hover,
.play-button:focus-visible {
    color: var(--play-text);
    background: var(--play-face-hover);
    text-decoration: none;
    filter: none;
}

.play-button__initial,
.play-button::first-letter {
    color: var(--play-initial);
}

.play-button:active {
    transform: translate(var(--play-shadow), var(--play-shadow));
    box-shadow: none;
}

.play-button--pressed {
    transform: translate(var(--play-shadow), var(--play-shadow));
    box-shadow: none;
}

.toc {
    margin: 0 0 2rem;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 1rem;
    line-height: 1.65;
    text-align: center;
}

.toc h2 {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

.toc h2::after {
    content: none;
}

.toc ol {
    display: inline;
    margin: 0;
    padding: 0;
    list-style: none;
}

.toc ol::after {
    content: "";
}

.toc li {
    display: inline;
    margin: 0;
}

.toc li:not(:last-child)::after {
    content: " | ";
    color: var(--muted);
}

.toc .toc-level-2 {
    margin-left: 0;
}

.toc .toc-level-3 {
    display: none;
}

.toc .toc-level-2 a,
.toc .toc-level-3 a {
    color: color-mix(in srgb, var(--link) 78%, var(--muted));
}

.site-footer {
    margin-top: auto;
    background: transparent;
}

.site-footer__inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.9rem 0 2rem;
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: 0.84rem;
    line-height: 1.3;
}

.site-footer__left p {
    margin: 0;
}

.site-footer__left p + p {
    margin-top: 0.08rem;
}

.site-footer__links {
    display: block;
    flex-wrap: wrap;
    justify-content: flex-end;
    text-align: right;
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.65;
}

.site-footer__separator {
    color: var(--muted);
}

.license-wrap {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    flex-wrap: wrap;
}

.license-icons {
    display: inline-flex;
    align-items: center;
    gap: 0.18rem;
}

.license-icons img {
    width: 18px;
    height: 18px;
}

@media (max-width: 720px) {
    .site-main {
        width: 100%;
        padding: 0 0 3rem;
    }

    .article {
        padding: 1.25rem;
    }

    .toc {
        padding: 0 1.25rem;
    }

    .copy-link {
        opacity: 1;
    }

    .site-footer__inner {
        flex-direction: column;
        align-items: flex-start;
    }

    .site-footer__links {
        justify-content: flex-start;
        text-align: left;
    }
}
