@font-face {
    font-family: "BUGZ Display";
    src: url("../fonts/bugz.woff2") format("woff2");
    font-weight: 800;
    font-style: normal;
    font-display: swap;
}

:root {
    --bg: #050505;
    --fg: #ecebe5;
    --muted: #8d8d88;
    --line: rgba(236, 235, 229, 0.2);
    --page-pad: clamp(18px, 2vw, 32px);
    color-scheme: dark;
}

/* Secondary tones follow the chosen --fg / --bg. */
@supports (color: color-mix(in srgb, red, blue)) {
    :root {
        --muted: color-mix(in srgb, var(--fg) 58%, var(--bg));
        --line: color-mix(in srgb, var(--fg) 22%, transparent);
    }
}

html {
    background: var(--bg);
    -webkit-text-size-adjust: 100%;
}

/* One-finger drags reach the shader; pinch zoom stays available. Removed while zoomed so panning works. */
html.touch-surface {
    touch-action: pinch-zoom;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--fg);
    font: 400 12px/1.45 ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
    letter-spacing: 0.02em;
    -webkit-font-smoothing: antialiased;
}

.page {
    position: relative;
    box-sizing: border-box;
    min-height: 100vh;
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: var(--page-pad);
}

.brand {
    position: relative;
    z-index: 1;
    margin: 0;
    padding: 0;
    font-family: "BUGZ Display", "Helvetica Neue", Helvetica, Arial, sans-serif;
    font-weight: 800;
    /* Short words use the display size; longer or wider-tracked words shrink to ~84vw.
       0.68em is the average advance of an Inter Tight 800 capital. */
    font-size: min(clamp(4.5rem, 23vw, 21rem), calc(84vw / (var(--brand-chars, 4) * (0.68 + var(--tracking, 0.02)))));
    line-height: 0.78;
    letter-spacing: calc(var(--tracking, 0.02) * 1em);
    white-space: nowrap;
    color: var(--fg);
    /* Hold the HTML fallback back briefly so a fast shader start never flashes plain text first. */
    animation: brand-in 0.5s ease 0.35s both;
    transition: color 0.5s ease;
}

@keyframes brand-in {
    from {
        opacity: 0;
    }
}

.webgl-ready .brand {
    color: transparent;
}

.brand::selection {
    color: var(--fg);
    background: var(--line);
}

.meta {
    position: absolute;
    z-index: 2;
    bottom: calc(var(--page-pad) + env(safe-area-inset-bottom, 0px));
    color: var(--muted);
}

.meta--left {
    left: calc(var(--page-pad) + env(safe-area-inset-left, 0px));
    display: flex;
    flex-direction: column;
}

.meta--right {
    right: calc(var(--page-pad) + env(safe-area-inset-right, 0px));
    color: var(--fg);
    text-decoration: none;
}

.meta--right:hover,
.meta--right:focus-visible {
    text-decoration: underline;
    text-underline-offset: 3px;
}

.meta--right:focus-visible {
    outline: 1px solid var(--fg);
    outline-offset: 4px;
}

#experience {
    position: fixed;
    inset: 0;
    z-index: 0;
    display: block;
    width: 100%;
    height: 100%;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.6s ease;
}

.webgl-ready #experience {
    opacity: 1;
}

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

    #experience {
        transition: none;
    }
}

.menu {
    position: absolute;
    z-index: 2;
    top: calc(var(--page-pad) + env(safe-area-inset-top, 0px));
    left: calc(var(--page-pad) + env(safe-area-inset-left, 0px));
    display: flex;
    flex-wrap: wrap;
    gap: 4px 14px;
}

.menu a {
    color: var(--muted);
    text-decoration: none;
}

.menu a:hover,
.menu a:focus-visible,
.menu a[aria-current="page"] {
    color: var(--fg);
}

.menu a:focus-visible,
.tune summary:focus-visible {
    outline: 1px solid var(--fg);
    outline-offset: 3px;
}

.tune summary {
    list-style: none;
    cursor: pointer;
    color: var(--muted);
    padding: 0 4px;
}

.tune summary::-webkit-details-marker {
    display: none;
}

.tune summary::before {
    content: "\25B8";
    display: inline-block;
    transition: transform 0.15s;
}

.tune[open] summary::before {
    transform: rotate(90deg);
}

.tune summary:hover,
.tune[open] summary {
    color: var(--fg);
}

.tune-body {
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 14px;
    display: grid;
    gap: 6px;
}

.tune-body label {
    display: grid;
    grid-template-columns: 88px minmax(100px, 150px) 44px;
    align-items: center;
    gap: 10px;
    color: var(--muted);
}

.tune-body input {
    width: 100%;
    margin: 0;
    accent-color: var(--muted);
}

.tune-body output {
    color: var(--fg);
    font-variant-numeric: tabular-nums;
}

.tune-word {
    box-sizing: border-box;
    width: 100%;
    max-width: 302px;
    margin-bottom: 6px;
    padding: 6px 0 5px;
    font: inherit;
    font-size: 13px;
    letter-spacing: 0.08em;
    text-transform: none;
    color: var(--fg);
    background: transparent;
    border: 0;
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    outline: none;
    caret-color: var(--fg);
}

.tune-word:focus {
    border-bottom-color: var(--fg);
}

.tune-colors {
    display: flex;
    gap: 18px;
    margin: 2px 0 4px;
}

.tune-colors label {
    display: inline-flex;
    grid-template-columns: none;
    align-items: center;
    gap: 8px;
}

.tune-colors input {
    width: 22px;
    height: 22px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: none;
    cursor: pointer;
    overflow: hidden;
}

.tune-colors input::-webkit-color-swatch-wrapper {
    padding: 0;
}

.tune-colors input::-webkit-color-swatch {
    border: 0;
    border-radius: 50%;
}

.tune-colors input::-moz-color-swatch {
    border: 0;
    border-radius: 50%;
}

.tune-download {
    justify-self: start;
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    margin-top: 10px;
    padding: 0;
    color: var(--fg);
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 50%;
    cursor: pointer;
    transition: border-color 0.15s, background-color 0.15s;
}

.tune-download:hover,
.tune-download:focus-visible {
    border-color: var(--fg);
    outline: none;
}

.tune-download:disabled {
    cursor: progress;
}

.tune-download svg {
    width: 14px;
    height: 14px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.tune-download[data-state="busy"] svg {
    animation: download-busy 0.9s linear infinite;
}

@keyframes download-busy {
    to {
        transform: rotate(360deg);
    }
}
