:root {
    /* Colors */
    --blue: #8eb8ff;
    --border-color: #cfcfd6;
    --code-block-bg: var(--panel-bg);
    --code-block-text: #1a1a1f;
    --coral: #ff8b7a;
    --diagram-bg: #ffffff;
    --diagram-border: #dddde6;
    --diagram-line: #4a4a52;
    --diagram-shadow:
        0 1px 2px rgba(40, 36, 70, 0.05), 0 3px 8px rgba(40, 36, 70, 0.07),
        0 10px 28px rgba(40, 36, 70, 0.1);
    --inline-code-bg: #d6d6db;
    --inline-code-text: #000;
    --muted-text: #5c5c66;
    --notice-accent: color-mix(in srgb, var(--primary) 55%, var(--notice-text));
    --notice-bg: var(--primary-text);
    --notice-text: var(--page-bg);
    --page-bg: #ececec;
    --panel-bg: #f7f7f7;
    --primary: #8a70b5;
    --primary-hover: #ddd0f0;
    --primary-text: #3a2a58;
    --scrollbar-track: #f0f0f3;
    --shadow: 0 1px 0 rgba(34, 34, 38, 0.06);
    --small-strong: color-mix(in srgb, var(--text) 50%, var(--muted-text));
    --small-text: color-mix(in srgb, var(--muted-text) 88%, var(--page-bg));
    --strong-text: var(--text);
    --syntax-command: color-mix(in srgb, var(--primary) 70%, var(--text));
    --text: #222226;

    /* Typography */
    --body-font: 1.125rem;
    --hero-font: clamp(1.75rem, 3.5vw, 2.25rem);
    --small-font: 1rem;
    --small-leading: 1.5;
    --title-font: 1.25rem;

    /* Layout */
    --content-width: 42rem;
    --divider-gap: 2.1rem;
    --inline-radius: 8px;
    --radius-diagram: 14px;
    --radius-flow: 6px;

    /* Lattice artwork */
    --lattice-background-image: url("assets/lattice.svg");
    --lattice-code-opacity: 0.94;
    --lattice-repeat-opacity: 0.86;
    --lattice-repeat-opacity-dark: 0.46;
    --lattice-repeat-opacity-mobile: 0.62;
}

@media (prefers-color-scheme: dark) {
    :root {
        --border-color: #3a3b44;
        --code-block-text: #e8e8ee;
        --coral: #ff9b8c;
        --diagram-bg: #2a2b32;
        --diagram-border: #3f404a;
        --diagram-line: #a8a8b3;
        --diagram-shadow:
            0 1px 2px rgba(0, 0, 0, 0.35), 0 4px 12px rgba(0, 0, 0, 0.35),
            0 14px 32px rgba(0, 0, 0, 0.4);
        --inline-code-bg: #33343c;
        --inline-code-text: #fff;
        --muted-text: #a8a8b3;
        --page-bg: #1a1b1f;
        --panel-bg: #24252b;
        --primary: #b39ddb;
        --primary-hover: #3d3354;
        --primary-text: #f1e9ff;
        --scrollbar-track: #2a2b32;
        --shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
        --text: #ececf1;
    }
}

/* Base */

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    color-scheme: light dark;
}

body {
    background: var(--page-bg);
    color: var(--text);
    font-family:
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
    font-size: var(--body-font);
    line-height: 1.55;
    margin: 0;
    overflow-x: clip;
    position: relative;
}

h1,
h2 {
    color: var(--strong-text);
    font-weight: 600;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

h1 {
    font-size: var(--hero-font);
    margin: 1.15rem 0;
}

h2 {
    font-size: var(--title-font);
    margin: 0 0 0.85rem;
}

p {
    color: var(--text);
    margin: 0 0 0.9rem;
}

strong {
    color: var(--strong-text);
    font-weight: 600;
}

code {
    background: var(--inline-code-bg);
    border-radius: var(--inline-radius);
    color: var(--inline-code-text);
    corner-shape: squircle;
    display: inline-block;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.875em;
    line-height: 1;
    padding: 0.22em 0.4em;
    white-space: nowrap;
}

code.ring-expression {
    white-space: normal;
}

code sub,
code sup {
    display: inline-block;
    font-size: 100%;
    line-height: 1;
    vertical-align: baseline;
}

code sub {
    margin-right: -0.2em;
    transform: scale(0.7) translateY(0.18em);
    transform-origin: left center;
}

code sup {
    margin-right: -0.4em;
    transform: scale(0.6) translateY(-0.55em);
    transform-origin: left center;
}

.notice-inner,
.hero,
main,
footer {
    margin-inline: auto;
    width: min(100% - 2.5rem, var(--content-width));
}

/* Notice */

.notice {
    background: var(--notice-bg);
    color: var(--notice-text);
    position: relative;
    z-index: 2;
}

.notice-inner {
    padding-block: clamp(1.25rem, 2.5vw, 1.75rem);
}

.notice p {
    color: inherit;
    font-size: clamp(1.05rem, 2vw, 1.35rem);
    font-weight: 200;
    letter-spacing: -0.01em;
    line-height: 1.35;
    margin: 0;
    max-width: 32rem;
}

.notice p + p {
    margin-top: 0.9rem;
}

.notice strong {
    color: inherit;
    font-weight: 650;
}

.notice a {
    color: var(--notice-accent);
    text-decoration-color: currentColor;
}

.notice a:hover {
    background: color-mix(in srgb, var(--notice-accent) 22%, transparent);
    color: var(--notice-text);
}

/* Header */

.hero-wrap {
    position: relative;
}

.hero {
    padding: 4.5rem 0 2.5rem;
    position: relative;
    z-index: 1;
}

.hero-lattice,
.footer-lattice {
    background-image: var(--lattice-background-image);
    background-position: top center;
    background-repeat: no-repeat;
    /* Width-first sizing keeps the lattice visible at both side edges and in the top-left corner. */
    background-size: 100% auto;
    left: 50%;
    -webkit-mask-image: linear-gradient(
        to bottom,
        #000 0%,
        #000 50%,
        rgb(0 0 0 / 0.65) 75%,
        transparent 100%
    );
    mask-image: linear-gradient(
        to bottom,
        #000 0%,
        #000 50%,
        rgb(0 0 0 / 0.65) 75%,
        transparent 100%
    );
    opacity: var(--lattice-repeat-opacity);
    pointer-events: none;
    position: absolute;
    transform: translateX(-50%);
    width: 100vw;
    z-index: 0;
}

.hero-lattice {
    height: min(50rem, 100vh);
    top: 0;
}

@media (prefers-color-scheme: dark) {
    .hero-lattice,
    .footer-lattice {
        filter: invert(1);
        opacity: var(--lattice-repeat-opacity-dark);
    }
}

@media (max-width: 900px) {
    .hero-lattice,
    .footer-lattice {
        background-position: top left;
        background-size: 140% auto;
        opacity: var(--lattice-repeat-opacity-mobile);
    }
}

body > main,
body > footer {
    position: relative;
    z-index: 1;
}

/* Links and shared text */

a {
    border-radius: 2px;
    color: var(--primary);
    text-decoration: underline dotted;
    text-decoration-thickness: 1px;
    text-underline-offset: 0.18em;
}

a:hover {
    background: var(--primary-hover);
    color: var(--primary-text);
    text-decoration: underline solid;
    text-decoration-thickness: 1px;
    text-underline-offset: 0.18em;
}

.repo {
    color: var(--text);
    display: flex;
    font-size: var(--small-font);
    margin: 0;
}

.repo + h1 {
    margin-top: 1rem;
}

.repo-link {
    align-items: center;
    display: inline-flex;
    gap: 0.45rem;
}

.repo-icon {
    background-color: var(--notice-bg);
    flex-shrink: 0;
    height: 1rem;
    -webkit-mask: url("assets/github.svg") center / contain no-repeat;
    mask: url("assets/github.svg") center / contain no-repeat;
    width: 1rem;
}

.title-accent {
    color: var(--notice-bg);
}

.small-text,
.hero-meta,
.diagram-figure figcaption,
.flow-glossary,
footer p {
    color: var(--small-text);
    font-size: var(--small-font);
    line-height: var(--small-leading);
}

.hero-meta {
    margin: 0.85rem 0 0;
}

#intro,
section {
    border-top: 1px solid var(--border-color);
    padding: var(--divider-gap) 0;
}

#intro > :last-child,
section > :last-child {
    margin-bottom: 0;
}

/* Personal notes and strip */

.personal-note {
    margin: 1.3rem 0 1.5rem 1rem;
    padding: 0.1rem 0 0.1rem 2.35rem;
    position: relative;
}

.personal-note::before {
    color: var(--primary);
    content: "“";
    font-family: Georgia, "Times New Roman", serif;
    font-size: 4.5rem;
    font-weight: 700;
    left: 0;
    line-height: 1;
    opacity: 0.65;
    position: absolute;
    top: -0.45rem;
}

.personal-note p {
    color: var(--muted-text);
    font-size: var(--small-font);
    line-height: var(--small-leading);
    margin: 0;
}

.personal-note p + p {
    margin-top: 0.9rem;
}

.strip {
    isolation: isolate;
    margin: 1.65rem 0 1.8rem calc(50% - 50vw);
    position: relative;
    width: 100vw;
}

.strip-viewport {
    height: 12rem;
    overflow: hidden;
    width: 100%;
}

.strip-track {
    height: 100%;
    position: relative;
    width: 100%;
}

.strip-frame {
    background: var(--panel-bg);
    border-radius: var(--radius-diagram);
    box-shadow: var(--shadow);
    corner-shape: squircle;
    height: 100%;
    overflow: hidden;
    position: absolute;
    top: 0;
}

.strip-frame picture,
.strip-frame img {
    display: block;
    height: 100%;
    width: 100%;
}

.strip-frame img {
    object-fit: cover;
}

.strip-title {
    left: calc(50% - 48.5rem);
    width: 28rem;
}

.strip-author {
    left: calc(50% - 20rem);
    width: 24rem;
}

.strip-cover {
    left: calc(50% + 4.5rem);
    width: 8.5rem;
}

.strip-listings {
    left: calc(50% + 13.5rem);
    width: 17.5rem;
}

.strip-clang {
    left: calc(50% + 31.5rem);
    width: 17rem;
}

.strip-caption {
    margin: 0.75rem auto 0;
    max-width: var(--content-width);
    padding: 0 1.25rem;
    text-align: center;
}

#intro {
    border-top: 0;
    padding-top: 0.5rem;
}

/* Intro diagram */

.diagram-figure {
    margin: 1.1rem 0 0;
}

.diagram-figure figcaption {
    margin-top: 1.15rem;
    text-align: center;
}

.diagram-figure figcaption span {
    display: block;
}

.flow-figure {
    display: grid;
    gap: 1rem;
    margin: 1.35rem 0 1.5rem;
}

/* Technical flow diagrams */

.flow-frame {
    background: var(--panel-bg);
    border-radius: var(--radius-flow);
    color: var(--text);
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scrollbar-color: var(--primary) var(--scrollbar-track);
}

.flow-frame svg {
    display: block;
    height: auto;
    margin-inline: auto;
    min-width: 552px;
    width: 100%;
}

.flow-frame:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 3px;
}

.flow-diagram .flow-line {
    fill: none;
    stroke: var(--diagram-line);
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1;
}

.flow-diagram .arrowhead {
    fill: var(--diagram-line);
    stroke: none;
}

.flow-diagram .guide-blue,
.flow-diagram .guide-coral,
.flow-diagram .guide-muted {
    fill: none;
    stroke-dasharray: 3 3;
    stroke-width: 1;
}

.flow-diagram .guide-blue {
    opacity: 0.85;
    stroke: var(--blue);
}

.flow-diagram .guide-coral {
    opacity: 0.75;
    stroke: var(--coral);
}

.flow-diagram .guide-muted {
    stroke: var(--border-color);
}

.flow-diagram .envelope-box,
.flow-diagram .flow-box,
.flow-diagram .flow-box-blue,
.flow-diagram .flow-box-coral,
.flow-diagram .flow-box-key,
.flow-diagram .flow-box-primary {
    rx: var(--radius-flow);
    ry: var(--radius-flow);
    shape-rendering: geometricPrecision;
    stroke-width: 0.5px;
    vector-effect: non-scaling-stroke;
}

.flow-diagram .flow-box {
    fill: var(--panel-bg);
    stroke: var(--border-color);
}

.flow-diagram .flow-box-blue {
    fill: color-mix(in srgb, var(--blue) 14%, var(--panel-bg));
    stroke: color-mix(in srgb, var(--blue) 45%, var(--panel-bg));
}

.flow-diagram .flow-box-coral {
    fill: color-mix(in srgb, var(--coral) 12%, var(--panel-bg));
    stroke: color-mix(in srgb, var(--coral) 45%, var(--panel-bg));
}

.flow-diagram .flow-box-key {
    stroke: color-mix(in srgb, var(--coral) 45%, var(--panel-bg));
}

.flow-diagram .flow-box-primary {
    fill: color-mix(in srgb, var(--primary) 14%, var(--panel-bg));
    stroke: color-mix(in srgb, var(--primary) 45%, var(--panel-bg));
}

.flow-diagram .envelope-box {
    fill: color-mix(in srgb, var(--text) 4%, var(--panel-bg));
    stroke: var(--border-color);
}

.seal-flow .flow-box-key {
    fill: url("#seal-key-stripes");
}

.open-flow .flow-box-key {
    fill: url("#open-key-stripes");
}

.flow-diagram .section-badge {
    fill: var(--diagram-line);
    stroke: none;
}

.flow-diagram .section-detail {
    fill: color-mix(in srgb, var(--diagram-line) 10%, var(--panel-bg));
    stroke: none;
}

.flow-diagram .section-badge-text,
.flow-diagram .section-detail-text {
    dominant-baseline: middle;
    font-size: 11px;
    font-weight: 600;
}

.flow-diagram .section-badge-text {
    fill: var(--page-bg);
    font-family:
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
    text-anchor: middle;
}

.flow-diagram .section-detail-text {
    fill: var(--text);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    text-anchor: start;
}

.flow-diagram .code-label,
.flow-diagram .text-label,
.flow-diagram .size-label {
    dominant-baseline: middle;
    text-anchor: middle;
}

.flow-diagram .code-label,
.flow-diagram .text-label {
    fill: var(--text);
    font-size: 11px;
    font-weight: 600;
}

.flow-diagram .code-label,
.flow-diagram .size-label {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.flow-diagram .text-label {
    font-family:
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
}

.flow-diagram .size-label {
    fill: var(--muted-text);
    font-size: 9px;
    font-weight: 400;
}

.flow-diagram .detail-label {
    font-family:
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
    font-size: 9.5px;
    transform: translateY(0.5px);
}

.flow-diagram .quarter-space {
    font-size: 25%;
}

.flow-diagram .half-space {
    font-size: 50%;
}

.flow-glossary {
    margin-top: 0.5rem;
}

.flow-glossary p {
    margin: 0 0 0.45rem;
}

.flow-glossary ul {
    margin: 0;
    padding-left: 1.25rem;
}

.flow-glossary li {
    color: var(--small-text);
    margin: 0.15rem 0;
}

.flow-glossary strong {
    color: var(--strong-text);
    font-weight: 600;
}

/* Layer diagram */

.layer-stack {
    display: grid;
    justify-items: stretch;
}

.layer {
    align-content: center;
    background: var(--diagram-bg);
    border: 1px solid var(--diagram-border);
    border-radius: var(--radius-diagram);
    box-shadow: var(--diagram-shadow);
    color: var(--text);
    display: grid;
    font-size: var(--body-font);
    min-height: 5rem;
    padding: 0.85rem 1rem;
    place-items: center;
    text-align: center;
}

.layer span {
    color: var(--muted-text);
    font-size: var(--small-font);
    margin-top: -0.1em;
}

.layer-app {
    background: color-mix(in srgb, var(--text) 4%, var(--diagram-bg));
    border-color: color-mix(in srgb, var(--text) 16%, var(--diagram-border));
}

.layer-textrunsql {
    background-color: color-mix(in srgb, var(--primary) 12%, var(--diagram-bg));
    border-color: color-mix(in srgb, var(--primary) 45%, var(--diagram-bg));
    border-radius: var(--radius-flow);
    border-width: 0.5px;
    corner-shape: initial;
    isolation: isolate;
    overflow: hidden;
    position: relative;
}

.layer-textrunsql::before {
    background: var(--lattice-background-image) center 28% / 100% auto no-repeat;
    content: "";
    inset: 0;
    opacity: var(--lattice-repeat-opacity);
    pointer-events: none;
    position: absolute;
    z-index: 0;
}

.layer-textrunsql strong,
.layer-textrunsql > span {
    border-radius: var(--radius-flow);
    color: var(--primary-text);
    display: inline-block;
    max-width: 100%;
    padding: 0 0.45em;
    position: relative;
    z-index: 1;
}

.layer-textrunsql strong {
    background: color-mix(in srgb, var(--primary-text) 12%, transparent);
    color: var(--strong-text);
    line-height: 1.4;
    padding-inline: 0.3em;
}

.layer-textrunsql > span {
    top: 1px;
}

@media (prefers-color-scheme: dark) {
    .layer-textrunsql::before {
        filter: invert(1);
        opacity: var(--lattice-repeat-opacity-dark);
    }

    .layer-textrunsql strong {
        background: color-mix(in srgb, #000 18%, transparent);
    }
}

.layer-sqlcipher {
    background: color-mix(in srgb, var(--coral) 14%, var(--diagram-bg));
    border-color: color-mix(in srgb, var(--coral) 40%, var(--diagram-border));
}

.layer-sqlite {
    background: color-mix(in srgb, var(--blue) 14%, var(--diagram-bg));
    border-color: color-mix(in srgb, var(--blue) 40%, var(--diagram-border));
}

.layer-connector {
    background: var(--primary);
    border-radius: 999px;
    height: 1.35rem;
    margin-inline: auto;
    width: 2.5px;
}

/* Code blocks */

.code-block {
    background: var(--code-block-bg);
    border: 0;
    border-radius: var(--radius-flow);
    box-shadow: var(--shadow);
    color: var(--code-block-text);
    isolation: isolate;
    margin: 1rem 0 1.25rem;
    overflow-x: auto;
    padding: 0.95rem 1.05rem;
    position: relative;
}

.code-block::after {
    background-image: var(--lattice-background-image);
    background-position: right 28%;
    background-repeat: no-repeat;
    background-size: 285.714% auto;
    content: "";
    filter: contrast(2.7) saturate(1.5) brightness(0.7);
    inset-block: 0;
    inset-inline-end: 0;
    -webkit-mask-image: linear-gradient(to right, transparent, #000);
    mask-image: linear-gradient(to right, transparent, #000);
    opacity: var(--lattice-code-opacity);
    pointer-events: none;
    position: absolute;
    width: 35%;
    z-index: 0;
}

#test .code-block:first-of-type::after {
    background-position: left 28%;
}

.code-block code {
    background: transparent;
    border: 0;
    border-radius: 0;
    color: inherit;
    corner-shape: initial;
    display: block;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: calc(var(--small-font) - 1pt);
    line-height: 1.55;
    padding: 0;
    position: relative;
    white-space: pre;
    z-index: 1;
}

@media (prefers-color-scheme: dark) {
    .code-block::after {
        filter: invert(1) contrast(2.7) saturate(1.5);
    }
}

.syntax-command {
    color: var(--syntax-command);
}

/* Supporting content */

#standards ul {
    margin: 0 0 1.1rem;
    padding-left: 1.25rem;
}

#standards li {
    line-height: 1.65;
    margin: 0.45rem 0;
}

.teams {
    margin: 0 0 1.4rem;
    padding-left: 1.4rem;
}

.teams li {
    margin-bottom: 0.45rem;
}

.teams li:last-child {
    margin-bottom: 0;
}

.video-list {
    margin: 0;
    padding-left: 1.4rem;
}

.video-title {
    margin: 0 0 0.1rem;
}

.video-meta {
    margin: 0 0 0.3rem;
}

.video-list li > p:last-child {
    margin: 0;
}

.video-list li + li {
    margin-top: 1rem;
}

/* Footer */

footer {
    border-top: 1px solid var(--border-color);
    padding: var(--divider-gap) 0 5rem;
}

footer strong {
    color: var(--small-strong);
    font-weight: 600;
}

.footer-lattice {
    height: 100%;
    -webkit-mask-image: linear-gradient(
        to bottom,
        transparent 0%,
        #000 4%,
        #000 50%,
        rgb(0 0 0 / 0.65) 75%,
        transparent 100%
    );
    mask-image: linear-gradient(
        to bottom,
        transparent 0%,
        #000 4%,
        #000 50%,
        rgb(0 0 0 / 0.65) 75%,
        transparent 100%
    );
    top: 0;
}

.footer-credit {
    align-items: center;
    display: flex;
    gap: 0.75rem;
    justify-content: space-between;
}

.footer-credit p {
    margin: 0;
    min-width: 0;
}

.footer-profiles {
    color: var(--small-text);
    display: grid;
    font-size: var(--small-font);
    gap: 0;
    grid-template-columns: minmax(0, 1fr);
    line-height: var(--small-leading);
    list-style: none;
    margin: calc(var(--small-font) * var(--small-leading)) 0 0;
    padding: 0;
}

.footer-profiles a {
    justify-self: start;
    max-width: 100%;
    overflow-wrap: anywhere;
}

.footer-profiles li {
    display: grid;
    gap: 0.35rem;
    grid-template-columns: max-content minmax(0, 1fr);
}

.shipaton-link {
    display: block;
    flex: 0 0 auto;
}

.shipaton-logo {
    aspect-ratio: 363 / 420;
    display: block;
    height: auto;
    width: 3.6rem;
}

.footer-disclaimer {
    border-top: 1px solid var(--border-color);
    margin: 0 0 calc(var(--small-font) * var(--small-leading));
    padding-top: var(--divider-gap);
}

.lattice-note {
    margin: 0 0 var(--divider-gap);
}

.footer-credit,
.footer-disclaimer,
.footer-profiles,
.lattice-note {
    position: relative;
    z-index: 1;
}

@media (max-width: 700px) {
    .notice-break {
        display: none;
    }

    .hero {
        padding-top: 3rem;
    }

    .strip-viewport {
        height: 11rem;
        overflow-x: auto;
        overscroll-behavior-x: contain;
        scrollbar-width: thin;
    }

    .strip-track {
        width: 91.0833rem;
    }

    .strip-author {
        left: 1rem;
        width: 22rem;
    }

    .strip-cover {
        left: 23.5rem;
        width: 7.7917rem;
    }

    .strip-listings {
        left: 31.7917rem;
        width: 16.0417rem;
    }

    .strip-title {
        left: 48.3334rem;
        width: 25.6667rem;
    }

    .strip-clang {
        left: 74.5rem;
        width: 15.5833rem;
    }
}
