/* Every rule for small screens is in the one max-width: 576px block at the end,
   since a custom property can't name a media query's width. */

:root {
    /* Each color is its light scheme's, then its dark's; theme.js can fix the scheme. */
    color-scheme: light dark;
    --page: light-dark(#fbfaf7, #161615);
    --surface: light-dark(#ffffff, #20201e);
    --ink: light-dark(#1d1c1a, #e9e6e0);
    --muted: light-dark(#6b6760, #9a958c);
    --rule: light-dark(#e2ded6, #34322e);
    --link: light-dark(#1f5fa8, #8cb8ec);
    --shadow: light-dark(rgb(40 32 20 / 0.12), rgb(0 0 0 / 0.45));
    --text-shadow: light-dark(rgb(40 32 20 / 0.45), rgb(0 0 0 / 0.75));
    /* Lifts the header's links off the name behind or above them. */
    --lifted-text: 0 2px 6px var(--text-shadow);
    --on-image: #ffffff;
    --shade: light-dark(rgb(0 0 0 / 0.06), rgb(0 0 0 / 0.25));
    /* A light sweeping over a control: the ink, faint, so it shows in either scheme. */
    --shine: color-mix(in srgb, var(--ink) 14%, transparent);
    /* A glow around a piece, the ink, so it stands out from the page in either scheme. */
    --glow: color-mix(in srgb, var(--ink) 70%, transparent);
    --on-image-shadow: rgb(0 0 0 / 0.75);
    --measure: 768px;
    --page-gutter: 1rem;
    --page-top: 2rem;
    --header-gap: 2rem;
    --block-gap: 2.5rem;
    /* Text set smaller than the body's, such as the rows of links under a heading. */
    --small-text: 0.9375rem;
    /* The golden ratio, width to height. */
    --toy-aspect: calc((1 + sqrt(5)) / 2);
    --toys-per-row: 2;
    /* The display of what is there only while the page is down, from when box2d.js marks
       the root data-phase="falling" until it is idle again. It is at the page's end, so
       nothing moves when it comes and goes. */
    --until-fallen: none;
    /* The header's controls, here since box2d.js moves the switch's clone out of the header:
       their text, padding and border. */
    --control-text: 0.75rem;
    --control-padding-block: 0.375rem;
    --control-border: 1px;
    /* Each control's height: its line of text, at a line height of 1, its padding and border. */
    --control-height: calc(var(--control-text) + 2 * var(--control-padding-block) + 2 * var(--control-border));
}

:root[data-phase="falling"],
:root[data-phase="returning"] {
    --until-fallen: block;
}

:root[data-theme="light"] {
    color-scheme: light;
}

:root[data-theme="dark"] {
    color-scheme: dark;
}

/* Room for a scrollbar whether or not the page scrolls, so a page that does is centered
   where one that doesn't is. */
html {
    scrollbar-gutter: stable;
}

/* Every rounded corner, box2d.js's falling copies' included, is a squircle. */
*,
::before,
::after {
    corner-shape: squircle;
}

body {
    margin: 0;
    padding: var(--page-top) var(--page-gutter);
    background: var(--page);
    color: var(--ink);
    font: 1.0625rem/1.6 Helvetica, Arial, sans-serif;
}

main,
.site-header {
    max-width: var(--measure);
    margin-inline: auto;
}

a {
    color: var(--link);
}

/* Read by screen readers, not shown: the home page's title, which the header already shows. */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

h1 {
    margin: 0 0 0.5rem;
    font-size: 2.25rem;
    line-height: 1.2;
}

h2 {
    margin: 2.5rem 0 0.75rem;
    padding-bottom: 0.25rem;
    border-bottom: 1px solid var(--rule);
    font-size: 1.25rem;
}

h3 {
    margin: 1.75rem 0 0.25rem;
    font-size: 1.0625rem;
}

ul {
    padding-left: 1.25rem;
}

li + li {
    margin-top: 0.375rem;
}

.site-header {
    /* The home page's name, as large as the bar's width allows in its widest script, from
       the build's measures in the page. */
    --name-size: calc(100cqi / var(--name-widest));
    margin-bottom: var(--header-gap);
}

/* The header's surface: the home link's row, then a page's own rows below it. */
.header-bar {
    /* So the name, at z-index -1, stays above the bar's background. */
    isolation: isolate;
    /* Where the bar is narrower than its content, the content is clipped at its sides; the
       controls can rise above its top. */
    overflow-x: clip;
    container-type: inline-size;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: start;
    padding: 0.5rem 1rem 0.75rem;
    font-size: 1.25rem;
    border-radius: 1.375rem;
    background: var(--surface);
    box-shadow: 0 1px 3px var(--shadow), 0 8px 32px -12px var(--shadow);
}

/* Where the controls don't fit at the row's end, they wrap to a line above it. */
.header-row {
    display: flex;
    flex-wrap: wrap-reverse;
    align-items: baseline;
    column-gap: 0.625rem;
}

.header-row a {
    color: var(--ink);
    font-weight: 600;
    text-decoration: none;
    text-shadow: var(--lifted-text);
}

/* The header bar's background: huge, behind the bar's own content. */
.site-owner {
    /* Positioned for z-index, and to hold waves.js's canvas. */
    position: relative;
    z-index: -1;
    white-space: nowrap;
    /* Partway from the ink toward the header's own background, in either color scheme. */
    --name-ink: color-mix(in srgb, var(--ink) 65%, var(--surface));
    color: var(--name-ink);
    font-size: var(--name-size);
    font-weight: 900;
    letter-spacing: calc(var(--name-tracking) * 1em);
    /* The box fits the letters' ink exactly: the build's line height and padding, and
       room for the last letter's ink past its letter spacing. */
    line-height: var(--name-line);
    padding: calc(var(--name-pad-top) * 1em) calc(var(--name-pad-end) * 1em)
        calc(var(--name-pad-bottom) * 1em) calc(var(--name-overhang-start) * 1em);
}

/* waves.js: the name's letters as seen through its waves, in place of its own, placed
   and sized by waves.js. */
.waves {
    position: absolute;
    pointer-events: none;
}

/* The buttons and the switch at the end of the row. On a line of their own, the margin
   makes that line take no room, so the row's own line stays where it is and they stand
   above it, across the bar's top edge; beside the row's content, its baseline places
   them, whatever the margin. */
.header-controls {
    display: flex;
    gap: 0.75rem;
    margin-inline-start: auto;
    margin-top: calc(-1 * var(--control-height));
}

.control-button {
    padding: var(--control-padding-block) var(--control-padding-inline, 1rem);
    border: var(--control-border) solid var(--rule);
    border-radius: 999px;
    background-color: var(--surface);
    color: var(--ink);
    font: inherit;
    font-size: var(--control-text);
    line-height: 1;
    cursor: pointer;
}

/* A shine sweeps across it once, quickly, when shine.js marks it data-shine: its band
   starts past the right edge of a background three times as wide and ends past the left. */
.distraction {
    background-image: linear-gradient(100deg, transparent 40%, var(--shine) 50%, transparent 60%);
    background-position: 100% 0;
    background-size: 300% 100%;
    background-repeat: no-repeat;
}

@media (prefers-reduced-motion: no-preference) {
    .distraction[data-shine] {
        animation: shine 0.6s ease-in-out;
    }
}

@keyframes shine {
    to {
        background-position-x: 0;
    }
}

.distraction:disabled {
    color: var(--muted);
    cursor: default;
}

/* Every scheme's icon in one cell; the one the root is marked with shows, in a falling
   clone too. As tall as the other controls, and as wide. */
.theme-switch {
    --control-padding-inline: var(--control-padding-block);
    display: inline-grid;
}

.theme-switch svg {
    display: block;
    width: 1em;
    height: 1em;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.theme-switch [data-theme-label] {
    grid-area: 1 / 1;
    visibility: hidden;
}

:root[data-theme="auto"] [data-theme-label="auto"],
:root[data-theme="light"] [data-theme-label="light"],
:root[data-theme="dark"] [data-theme-label="dark"] {
    visibility: inherit;
}

.script-switch {
    display: flex;
    align-items: baseline;
    overflow: hidden;
    border: var(--control-border) solid var(--rule);
    border-radius: 999px;
    background: var(--surface);
}

.script-switch button {
    flex: 1;
    padding: var(--control-padding-block) 0.625rem;
    border: 0;
    background: none;
    color: var(--muted);
    font: inherit;
    font-size: var(--control-text);
    line-height: 1;
    cursor: pointer;
}

.script-switch button[aria-pressed="true"] {
    background: var(--rule);
    color: var(--ink);
}

.script-switch button:disabled {
    cursor: default;
}

/* box2d.js: the layer holding the falling copies, over the whole page; a copy, placed
   in it by its transform; and the hidden original. */
.falling-layer {
    position: absolute;
    top: 0;
    left: 0;
    overflow: clip;
    pointer-events: none;
}

.falling-piece {
    box-sizing: border-box;
    position: absolute;
    top: 0;
    left: 0;
    white-space: nowrap;
    transform-origin: 0 0;
}

.fallen-source {
    visibility: hidden;
}

/* box2d.js: the piece under the pointer, or held, lit by a glow that follows its ink. It
   comes at once and fades. */
.falling-piece,
.falling-solid {
    transition: filter 0.15s ease-out;
}

.falling-piece[data-hovered],
.falling-solid[data-hovered] {
    transition-duration: 0s;
    filter: drop-shadow(0 2px 6px var(--glow));
}

:root[data-cursor="grab"] {
    cursor: grab;
}

:root[data-cursor="grabbing"] {
    cursor: grabbing;
}

/* box2d.js: a list item's bullet, made a span so it can fall. An outside marker takes no
   space, so neither removing it nor adding the span moves anything. */
.list-marker-replaced {
    position: relative;
    list-style-type: none;
}

.list-marker {
    position: absolute;
    right: 100%;
    white-space: pre;
}

/* Visible even inside a hidden frame, since it falls in place. */
.falling-solid {
    visibility: visible;
    transform-origin: 0 0;
}

.downloads {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0 0.75rem;
    margin-bottom: 1.5rem;
    color: var(--muted);
    font-size: var(--small-text);
}

/* A button that makes its file, styled as the link beside it. */
.downloads button {
    padding: 0;
    border: 0;
    background: none;
    color: var(--link);
    font: inherit;
    text-decoration: underline;
    cursor: pointer;
}

.downloads button:disabled {
    color: var(--muted);
    cursor: progress;
}

.bio {
    display: var(--until-fallen);
    margin-top: var(--block-gap);
    color: var(--muted);
    font-size: 0.875rem;
    font-style: italic;
}

.links {
    padding: 0;
    list-style: none;
}

/* The resume and email side by side right under the name, starting where its second
   letter does in the page's own script. They shrink with the name, down to the size of
   the page's smaller text: at this fraction of the name's size, the row in Helvetica or
   Arial ends short of the name's own end in every script, and where the floor keeps them
   larger they wrap. The row sits snug under the letters above it in the page's own
   script: up beside the first letter's drop, trimmed to its own capitals and baseline,
   and this far below their ink. */
.contact {
    --contact-gap: 0.25em;
    --contact-scale: 0.22;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5em 1.6em;
    white-space: nowrap;
    font-size: clamp(var(--small-text), calc(var(--name-size) * var(--contact-scale)), 1em);
    margin: calc(var(--contact-gap) - var(--name-size) * var(--name-first-drop)) 0 0
        calc(var(--name-size) * var(--name-indent));
    text-box: trim-both cap alphabetic;
}

/* The flex gap spaces the items. */
.contact li {
    margin: 0;
}

.contact a {
    text-shadow: var(--lifted-text);
}

.web-toys {
    margin-top: var(--block-gap);
    padding: 1rem 1.25rem;
    border: 1px solid var(--rule);
    border-radius: 1.375rem;
}

.web-toys h2 {
    margin-top: 0;
}

.dala {
    margin-top: var(--block-gap);
}

.toys {
    display: grid;
    grid-template-columns: repeat(var(--toys-per-row), minmax(0, 1fr));
    gap: 1rem;
    margin: 0;
}

/* The grid's gap spaces the toys. */
.toys li {
    margin: 0;
}

.toy {
    display: block;
    position: relative;
}

.toy img {
    display: block;
    width: 100%;
    aspect-ratio: var(--toy-aspect);
    object-fit: cover;
    border-radius: 0.875rem;
    background: var(--rule);
}

.toy span {
    position: absolute;
    inset-block-start: 0.25rem;
    inset-inline-start: 0.625rem;
    color: var(--on-image);
    font-weight: 600;
    line-height: 1.2;
    text-shadow: 0 1px 4px var(--on-image-shadow);
}

@media (max-width: 576px) {
    h1 {
        font-size: 1.75rem;
    }
}
