/* Self-hosted: no third-party request before text can render. */
@font-face {
    font-family: 'Chakra Petch';
    font-weight: 400;
    font-display: swap;
    src: url(../fonts/chakra-petch-latin-400-normal.woff2) format('woff2');
}

@font-face {
    font-family: 'Chakra Petch';
    font-weight: 600;
    font-display: swap;
    src: url(../fonts/chakra-petch-latin-600-normal.woff2) format('woff2');
}

@font-face {
    font-family: 'JetBrains Mono';
    font-weight: 500;
    font-display: swap;
    src: url(../fonts/jetbrains-mono-latin-500-normal.woff2) format('woff2');
}

/*=============== TOKENS ===============*/
/* Graphite sleeve by default; the light theme is a brushed aluminium panel. */
:root,
:root[data-theme='dark'] {
    --bg: #121316;
    --panel: #18191d;
    --pad: #24252a;
    --pad-edge: #0b0b0d;
    --ink: #eceae6;
    --muted: #a3a19a;
    --line: #2b2d32;
    --accent: #ff4d3d;
    --accent-ink: #160604;
    --wave-opacity: 0.5;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.5), 0 10px 24px -10px rgb(0 0 0 / 0.7);
    color-scheme: dark;
}

:root[data-theme='light'] {
    --bg: #e4e5e8;
    --panel: #d7d9dd;
    --pad: #f3f4f6;
    --pad-edge: #a9adb4;
    --ink: #16171a;
    --muted: #4d5057;
    --line: #c2c5cb;
    --accent: #d42a1c;
    --accent-ink: #fff;
    --wave-opacity: 1;
    --shadow: 0 1px 2px rgb(30 34 44 / 0.12), 0 10px 24px -10px rgb(30 34 44 / 0.3);
    color-scheme: light;
}

:root {
    /* One fixed LED set, hard edges, never blended. */
    --led-1: #ff4d3d;
    --led-2: #ffb020;
    --led-3: #3ddc84;
    --led-4: #33c7ff;
    --led-5: #ff4fd8;
    --led-6: #9b7bff;
    --stripe: linear-gradient(
        to right,
        var(--led-1) 0 16.66%,
        var(--led-2) 0 33.33%,
        var(--led-3) 0 50%,
        var(--led-4) 0 66.66%,
        var(--led-5) 0 83.33%,
        var(--led-6) 0
    );

    --font-display: 'Chakra Petch', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, monospace;
    --ease: cubic-bezier(0.16, 1, 0.3, 1);
    --level: 0; /* live audio level 0..1, written by the meter loop */

    --z-header: 10;
    --z-popup: 20;
    --z-toast: 30;
    --z-skip: 40;
}

/*=============== BASE ===============*/
* {
    box-sizing: border-box;
}

html {
    scrollbar-color: var(--line) var(--bg);
}

body {
    margin: 0;
    min-width: 320px;
    background: var(--bg);
    color: var(--ink);
    font: 400 1rem/1.5 var(--font-display);
    -webkit-font-smoothing: antialiased;
    transition:
        background-color 0.5s,
        color 0.5s;
}

h1,
h2,
p {
    margin: 0;
}

h1,
h2 {
    text-wrap: balance;
}

p {
    text-wrap: pretty;
}

/* No italics anywhere: emphasis comes from weight and colour. */
em,
i,
cite,
address,
dfn,
var {
    font-style: normal;
}

::selection {
    background: var(--accent);
    color: var(--accent-ink);
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
    border-radius: 6px;
}

input {
    caret-color: var(--accent);
}

a {
    color: inherit;
    text-decoration-color: var(--accent);
    text-underline-offset: 0.2em;
}

a:hover {
    text-decoration-thickness: 2px;
}

button {
    font: inherit;
    color: inherit;
    cursor: pointer;
}

svg {
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;
}

kbd {
    padding: 0.05rem 0.4rem;
    border: 1px solid var(--line);
    border-bottom-width: 2px;
    border-radius: 4px;
    font: 500 0.8em var(--font-mono);
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

.skip-link {
    position: fixed;
    top: 0.5rem;
    left: 0.5rem;
    z-index: var(--z-skip);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    background: var(--ink);
    color: var(--bg);
    font-weight: 600;
    transform: translateY(-200%);
}

.skip-link:focus {
    transform: none;
}

main:focus {
    outline: none;
}

.stripe {
    height: 4px;
    background: var(--stripe);
}

/* Views: the intro and the board never show at the same time. */
[data-view='intro'] .app,
[data-view='board'] #intro {
    display: none;
}

/*=============== BUTTONS ===============*/
.primary,
.secondary,
button[type='submit'] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.7rem 1.25rem;
    border: 0;
    border-radius: 10px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    transition:
        background-color 0.25s,
        color 0.25s,
        translate 0.25s var(--ease),
        scale 0.12s var(--ease);
}

.primary,
button[type='submit'] {
    background: var(--accent);
    color: var(--accent-ink);
}

.secondary {
    background: var(--pad);
    box-shadow: inset 0 0 0 1px var(--line);
}

.primary:hover,
.secondary:hover,
button[type='submit']:hover {
    translate: 0 -2px;
}

.primary:hover,
button[type='submit']:hover {
    background: var(--ink);
    color: var(--bg);
}

.secondary:hover {
    box-shadow: inset 0 0 0 1px var(--accent);
}

.primary:active,
.secondary:active,
button[type='submit']:active,
.dice-btn:active {
    scale: 0.95;
    transition-duration: 0.06s;
}

.primary svg,
.secondary svg {
    width: 20px;
    height: 20px;
}

.text-link {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.25rem 0;
    border: 0;
    background: none;
    font-weight: 600;
}

.text-link svg {
    width: 18px;
    height: 18px;
    transition: translate 0.25s var(--ease);
}

.text-link:hover svg {
    translate: 4px 0;
    color: var(--accent);
}

/*=============== INTRO: THE SLEEVE ===============*/
/* Left: a square record sleeve set in type and rules. Right: the deck where you hit the pad. */
#intro {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: auto 1fr;
    align-items: center;
    gap: 0 clamp(2rem, 6vw, 6rem);
    min-height: 100dvh;
    padding: 0 clamp(1.25rem, 5vw, 4.5rem) 2rem;
    overflow: hidden;
}

#intro > .stripe {
    grid-column: 1 / -1;
    align-self: start;
    margin-inline: calc(clamp(1.25rem, 5vw, 4.5rem) * -1);
    animation: stripe-in 0.9s var(--ease) both;
    transform-origin: left;
}

@keyframes stripe-in {
    from {
        scale: 0 1;
    }
}

@keyframes hero-in {
    from {
        opacity: 0;
        translate: 0 1.5rem;
        filter: blur(6px);
    }
}

.sleeve {
    position: relative;
    display: grid;
    grid-template-rows: 1fr auto auto;
    width: min(72vh, 600px, 52vw);
    aspect-ratio: 1;
    margin-block: 2rem;
    padding: 1.5rem 1.75rem 1.75rem;
    background: var(--panel);
    box-shadow:
        inset 0 0 0 1px var(--line),
        0 30px 60px -30px rgb(0 0 0 / 0.6);
    animation: sleeve-in 1s var(--ease) backwards;
}

@keyframes sleeve-in {
    from {
        opacity: 0;
        translate: -2rem 0;
        rotate: -2deg;
    }
}

/* Catalog strip along the sleeve's bottom edge, like the small print on a real sleeve. */
.catno {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--line);
    font: 500 0.75rem var(--font-mono);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--muted);
}

#intro h1 {
    align-self: end;
    padding-block: 1.5rem;
    font: 600 clamp(3.25rem, 1rem + 6vw, 6rem) / 0.88 var(--font-display);
    letter-spacing: -0.02em;
    text-transform: uppercase;
    animation: hero-in 0.9s var(--ease) 0.15s backwards;
}

/* The sleeve's tracklist: what the big pad might pull out. */
.tracklist {
    padding-top: 0.75rem;
    border-top: 1px solid var(--line);
    font: 500 0.8125rem/1.7 var(--font-mono);
    color: var(--muted);
}

.tracklist h2 {
    margin-bottom: 0.25rem;
    font: inherit;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--ink);
}

.tracklist ol {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 1.5rem;
    margin: 0;
    padding: 0;
    list-style: none;
    counter-reset: track;
}

.tracklist li {
    counter-increment: track;
}

.tracklist li::before {
    content: 'A' counter(track) '  ';
    white-space: pre;
    color: var(--ink);
}

.deck {
    display: grid;
    justify-items: center;
    gap: 1.75rem;
    text-align: center;
    animation: hero-in 1s var(--ease) 0.3s backwards;
}

.lede {
    max-width: 30ch;
    font-size: clamp(1.125rem, 1rem + 0.5vw, 1.375rem);
    color: var(--muted);
}

#intro-status {
    min-height: 3em;
    max-width: 32ch;
    color: var(--muted);
}

.intro-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 1rem 2rem;
}

.check {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    color: var(--muted);
    cursor: pointer;
}

.check input {
    width: 1.15rem;
    height: 1.15rem;
    margin: 0;
    accent-color: var(--accent);
    cursor: pointer;
}

.check:hover {
    color: var(--ink);
}

/* The big pad: same rubber as the board pads, with a lit LED well and rings that answer the real signal. */
.big-pad {
    position: relative;
    display: grid;
    place-items: end center;
    width: min(64vw, 240px);
    aspect-ratio: 1;
    padding: 0 0 1.25rem;
    border: 0;
    border-radius: 28px;
    background: linear-gradient(to bottom, color-mix(in srgb, var(--pad) 80%, #fff 6%), var(--pad));
    box-shadow:
        inset 0 1px 0 rgb(255 255 255 / 0.07),
        inset 0 -6px 0 var(--pad-edge),
        0 18px 40px -16px rgb(0 0 0 / 0.7);
    transition:
        translate 0.3s var(--ease),
        box-shadow 0.3s var(--ease);
}

/* Standby: the LED glows at low power and breathes. A hot core plus light spilling down onto the pad. */
.big-pad .led {
    position: absolute;
    inset: 16% 16% 30%;
    border-radius: 14px;
    background:
        radial-gradient(ellipse 60% 55% at 50% 42%, color-mix(in srgb, var(--led-1) 55%, #fff), transparent 70%),
        var(--led-1);
    box-shadow:
        inset 0 0 0 1px rgb(0 0 0 / 0.3),
        inset 0 -8px 16px rgb(0 0 0 / 0.25),
        0 10px 28px -6px color-mix(in srgb, var(--led-1) 60%, transparent);
    filter: brightness(0.7) saturate(0.85);
    animation: standby 2.4s ease-in-out infinite;
}

@keyframes standby {
    50% {
        filter: brightness(0.95) saturate(1);
    }
}

.big-pad-label {
    font: 500 0.8125rem var(--font-mono);
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--muted);
}

.big-pad::before,
.big-pad::after {
    content: '';
    position: absolute;
    inset: 0;
    border: 2px solid var(--led-1);
    border-radius: inherit;
    opacity: 0;
    pointer-events: none;
}

.big-pad:hover {
    translate: 0 -3px;
}

.big-pad:hover .led {
    filter: brightness(1) saturate(1);
}

.big-pad:active,
.big-pad.live {
    translate: 0 3px;
    box-shadow:
        inset 0 1px 0 rgb(255 255 255 / 0.05),
        inset 0 -2px 0 var(--pad-edge),
        0 8px 20px -12px rgb(0 0 0 / 0.7);
    transition-duration: 0.06s;
}

/* Live: full power, and the LED swells and brightens with the real signal level. */
.big-pad.live .led {
    animation: none;
    filter: brightness(calc(1 + var(--level) * 0.6)) saturate(1.1);
    scale: calc(1 + var(--level) * 0.1);
}

.big-pad.live::before,
.big-pad.live::after {
    animation: ring 1.3s var(--ease) infinite;
}

.big-pad.live::after {
    animation-delay: 0.65s;
}

.big-pad.loading .led {
    animation: standby 0.5s ease-in-out infinite;
}

@keyframes ring {
    from {
        opacity: 0.9;
        scale: 1;
    }

    to {
        opacity: 0;
        scale: 1.7;
    }
}

/* Leaving the intro: the sleeve zooms into the pad, the board settles in behind it. */
::view-transition-old(root) {
    transform-origin: var(--vt-x, 50%) var(--vt-y, 50%);
    animation: zoom-through 0.75s cubic-bezier(0.7, 0, 0.84, 0) both;
}

::view-transition-new(root) {
    animation: board-in 0.75s var(--ease) both;
}

@keyframes zoom-through {
    to {
        opacity: 0;
        scale: 4;
        filter: blur(12px);
    }
}

@keyframes board-in {
    from {
        opacity: 0;
        scale: 0.94;
    }
}

/* Same entrance without View Transitions support. */
.app.entering {
    animation: board-in 0.75s var(--ease) both;
}

/*=============== HEADER ===============*/
header {
    position: sticky;
    top: 0;
    z-index: var(--z-header);
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 1.5rem;
    padding: 0.75rem clamp(1rem, 3vw, 2rem);
    background: color-mix(in srgb, var(--panel) 88%, transparent);
    backdrop-filter: blur(14px) saturate(1.4);
    border-bottom: 1px solid var(--line);
    transition: background-color 0.5s;
}

header::after {
    content: '';
    position: absolute;
    inset: auto 0 -1px;
    height: 2px;
    background: var(--stripe);
}

header > * {
    animation: hero-in 0.7s var(--ease) backwards;
}

header > :nth-child(2) {
    animation-delay: 0.08s;
}

header > :nth-child(3) {
    animation-delay: 0.16s;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0;
    border: 0;
    background: none;
}

.logo-mark {
    width: 34px;
    height: 34px;
    background: var(--ink);
    -webkit-mask: url(../img/sound.png) center / contain no-repeat;
    mask: url(../img/sound.png) center / contain no-repeat;
    transition:
        background-color 0.25s,
        rotate 0.4s var(--ease);
}

.logo-name {
    font-weight: 600;
    font-size: 1.0625rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    white-space: nowrap;
}

.logo:hover .logo-mark {
    background: var(--accent);
    rotate: -8deg;
}

#search-form {
    display: flex;
    width: 100%;
    max-width: 36rem;
    justify-self: center;
    padding: 4px;
    border-radius: 14px;
    background: var(--bg);
    box-shadow: inset 0 0 0 1px var(--line);
    transition: box-shadow 0.25s;
}

#search-form:focus-within {
    box-shadow: inset 0 0 0 1px var(--accent);
}

#search-input {
    flex: 1;
    min-width: 0;
    padding: 0.55rem 0.75rem;
    border: 0;
    background: none;
    color: var(--ink);
    font: inherit;
}

#search-input:focus-visible {
    outline: none;
}

#search-input::placeholder {
    color: var(--muted);
}

#search-form button[type='submit'] {
    padding: 0.55rem 1rem;
}

.dice-btn {
    display: grid;
    place-items: center;
    width: 2.6rem;
    margin-right: 4px;
    padding: 0;
    border: 0;
    border-radius: 10px;
    background: none;
    color: var(--muted);
    transition:
        color 0.2s,
        background-color 0.2s,
        scale 0.12s var(--ease);
}

.dice-btn svg {
    width: 24px;
    height: 24px;
}

.dice-btn:hover {
    color: var(--ink);
    background: var(--pad);
}

.dice-btn circle,
.primary circle {
    fill: currentColor;
    stroke: none;
}

.rolling svg {
    animation: roll 0.6s var(--ease);
}

@keyframes roll {
    to {
        rotate: 1turn;
    }
}

.controls {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

/* Now playing: seven bars fed by the real signal, plus the track name. */
.now-playing {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    max-width: 12rem;
}

/* Standby: the bars sit dim at rest so the meter always reads; the track name appears only while playing. */
.meter {
    opacity: 0.4;
    transition: opacity 0.3s;
}

#now-name {
    opacity: 0;
    translate: 0 4px;
    transition:
        opacity 0.3s,
        translate 0.3s var(--ease);
}

.is-playing .meter,
.is-playing #now-name {
    opacity: 1;
    translate: 0 0;
}

.meter {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 20px;
}

.meter i {
    width: 3px;
    height: 100%;
    border-radius: 1px;
    background: var(--led-3);
    transform: scaleY(calc(0.12 + var(--l, 0) * 0.88));
    transform-origin: bottom;
}

.meter i:nth-child(n + 5) {
    background: var(--led-2);
}

.meter i:nth-child(7) {
    background: var(--led-1);
}

#now-name {
    overflow: hidden;
    font: 500 0.75rem var(--font-mono);
    color: var(--muted);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.volume {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.volume svg {
    width: 22px;
    height: 22px;
}

.volume .waves {
    transition: opacity 0.2s;
}

.volume.muted .waves {
    opacity: 0.2;
}

#volume {
    width: 88px;
    height: 20px;
    margin: 0;
    background: transparent;
    appearance: none;
    cursor: pointer;
}

#volume::-webkit-slider-runnable-track {
    height: 4px;
    border-radius: 999px;
    background: linear-gradient(to right, var(--accent) var(--fill, 80%), var(--line) 0);
}

#volume::-moz-range-track {
    height: 4px;
    border-radius: 999px;
    background: var(--line);
}

#volume::-moz-range-progress {
    height: 4px;
    border-radius: 999px;
    background: var(--accent);
}

#volume::-webkit-slider-thumb {
    width: 14px;
    height: 18px;
    margin-top: -7px;
    border: 0;
    border-radius: 3px;
    background: var(--ink);
    appearance: none;
    transition: scale 0.2s var(--ease);
}

#volume::-moz-range-thumb {
    width: 14px;
    height: 18px;
    border: 0;
    border-radius: 3px;
    background: var(--ink);
}

#volume:hover::-webkit-slider-thumb {
    scale: 1.15;
}

#volume:focus-visible {
    outline-offset: 4px;
}

/* Theme: a hardware toggle switch, not a sun and moon. */
.switch {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem;
    border: 0;
    background: none;
}

.switch-track {
    position: relative;
    width: 36px;
    height: 20px;
    border-radius: 6px;
    background: var(--bg);
    box-shadow: inset 0 0 0 1px var(--line);
}

.switch-knob {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 14px;
    height: 14px;
    border-radius: 3px;
    background: var(--ink);
    transition: translate 0.35s var(--ease);
}

.switch[aria-checked='true'] .switch-knob {
    translate: 16px 0;
}

.switch-label {
    width: 2.75rem;
    font: 500 0.75rem var(--font-mono);
    letter-spacing: 0.08em;
    text-align: left;
    text-transform: uppercase;
    color: var(--muted);
}

/*=============== BOARD ===============*/
main {
    display: grid;
    gap: 4rem;
    max-width: 1120px;
    margin: 0 auto;
    padding: 2.5rem clamp(1rem, 3vw, 2rem) 5rem;
}

.section-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.25rem 1rem;
    margin-bottom: 1.5rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--line);
}

main h2 {
    font: 600 1.75rem/1.1 var(--font-display);
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

#status,
.hint {
    font-size: 0.9375rem;
    color: var(--muted);
}

.empty {
    grid-column: 1 / -1;
    color: var(--muted);
}

/* Start screen: shown until the first search. */
.start {
    display: grid;
    justify-items: start;
    gap: 1rem;
    padding: clamp(2rem, 5vw, 3.5rem) 0;
}

.start[hidden] {
    display: none;
}

.start-title {
    font: 600 clamp(2.25rem, 1.5rem + 3vw, 3.5rem) / 1 var(--font-display);
    text-transform: uppercase;
}

.start-text {
    max-width: 42ch;
    font-size: 1.125rem;
    color: var(--muted);
}

.start .primary {
    margin-top: 0.5rem;
    padding: 0.9rem 1.5rem;
}

.start .primary:hover svg {
    animation: roll 0.6s var(--ease);
}

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 1rem 0 0;
    padding: 0;
    list-style: none;
}

.chips button {
    padding: 0.4rem 0.85rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: none;
    color: var(--muted);
    font-size: 0.9375rem;
    transition:
        color 0.2s,
        border-color 0.2s,
        translate 0.25s var(--ease);
}

.chips button:hover {
    color: var(--ink);
    border-color: var(--accent);
    translate: 0 -2px;
}

.chips li {
    animation: hero-in 0.6s var(--ease) backwards;
    animation-delay: calc(0.2s + var(--n, 0) * 40ms);
}

.chips li:nth-child(2) {
    --n: 1;
}
.chips li:nth-child(3) {
    --n: 2;
}
.chips li:nth-child(4) {
    --n: 3;
}
.chips li:nth-child(5) {
    --n: 4;
}
.chips li:nth-child(6) {
    --n: 5;
}
.chips li:nth-child(7) {
    --n: 6;
}
.chips li:nth-child(8) {
    --n: 7;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 2rem 1.25rem;
    transition: opacity 0.3s;
}

.grid[aria-busy='true'] {
    opacity: 0.4;
    pointer-events: none;
}

.section-head:has(+ .grid > .empty) .hint {
    display: none;
}

#more {
    display: flex;
    margin: 2.5rem auto 0;
}

#more[hidden] {
    display: none;
}

#more:disabled {
    opacity: 0.6;
    cursor: progress;
    translate: none;
}

/*=============== TRACK: ONE PAD PER SOUND ===============*/
.sound {
    display: grid;
    gap: 0.6rem;
    /* Long result lists: off-screen tracks skip rendering until scrolled near. */
    content-visibility: auto;
    contain-intrinsic-size: auto 221px; /* measured track height at desktop width */
    animation: tile-in 0.5s var(--ease) backwards;
    animation-delay: calc(var(--i, 0) * 35ms);
}

@keyframes tile-in {
    from {
        opacity: 0;
        scale: 0.9;
        translate: 0 0.75rem;
    }
}

.meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    font: 500 0.75rem var(--font-mono);
    letter-spacing: 0.04em;
    color: var(--muted);
}

.catalog {
    color: inherit;
    text-decoration: none;
}

.catalog:hover {
    color: var(--ink);
}

.duration {
    margin-left: auto;
    font-variant-numeric: tabular-nums;
}

/* Rubber pad: a raised square that sinks when hit, with the waveform printed on its face. */
.pad {
    position: relative;
    display: block;
    width: 100%;
    aspect-ratio: 1;
    padding: 0;
    overflow: hidden;
    border: 0;
    border-radius: 14px;
    background: linear-gradient(to bottom, color-mix(in srgb, var(--pad) 80%, #fff 6%), var(--pad));
    box-shadow:
        inset 0 1px 0 rgb(255 255 255 / 0.07),
        inset 0 -5px 0 var(--pad-edge),
        var(--shadow);
    transition:
        translate 0.3s var(--ease),
        box-shadow 0.3s var(--ease),
        rotate 0.3s var(--ease);
}

/* Printed waveform: Freesound's waveform used as an alpha mask over the track's LED colour. */
.wave {
    position: absolute;
    inset: 30% 10% 22%;
    background: var(--led);
    -webkit-mask: var(--wave) center / 100% 100% no-repeat;
    mask: var(--wave) center / 100% 100% no-repeat;
    opacity: var(--wave-opacity);
    transition: opacity 0.3s;
}

/* The LED: a hard-edged strip that lights in the track's colour. */
.pad::before {
    content: '';
    position: absolute;
    top: 12%;
    left: 12%;
    width: 22%;
    height: 6%;
    z-index: 1;
    border-radius: 2px;
    background: var(--led);
    filter: brightness(0.85);
    transition:
        filter 0.2s,
        box-shadow 0.2s;
}

/* Playback progress, drawn as a ring around the pad from the real currentTime. */
.pad::after {
    content: '';
    position: absolute;
    inset: 0;
    padding: 3px;
    border-radius: inherit;
    background: conic-gradient(var(--led) calc(var(--p, 0) * 1turn), transparent 0);
    -webkit-mask:
        linear-gradient(#000 0 0) content-box exclude,
        linear-gradient(#000 0 0);
    mask:
        linear-gradient(#000 0 0) content-box exclude,
        linear-gradient(#000 0 0);
    opacity: 0;
}

.pad:hover {
    translate: 0 -3px;
}

.pad:hover::before {
    filter: brightness(1.15);
}

.pad:hover .wave {
    opacity: 0.9;
}

.pad:active,
.playing .pad {
    translate: 0 3px;
    box-shadow:
        inset 0 1px 0 rgb(255 255 255 / 0.05),
        inset 0 -1px 0 var(--pad-edge),
        inset 0 0 calc(18px + var(--level) * 30px) color-mix(in srgb, var(--led) 45%, transparent),
        0 2px 6px -3px rgb(0 0 0 / 0.5);
    transition-duration: 0.06s; /* a press is instant, the release eases back */
}

.playing .pad {
    background: color-mix(in srgb, var(--led) 16%, var(--pad));
}

.playing .pad::before {
    filter: brightness(1.3);
    box-shadow: 0 2px 10px color-mix(in srgb, var(--led) 70%, transparent);
}

.playing .pad::after {
    opacity: 1;
}

.playing .pad .wave {
    opacity: 1;
}

.name {
    overflow: hidden;
    font-size: 0.9375rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.playing .name {
    color: var(--led);
}

/* LEDs need more presence on the bright panel, and LED-coloured text would fail contrast there. */
/* LED amber is ~1.5:1 on the light panel; the starred icon needs 3:1. */
:root[data-theme='light'] .fav[aria-pressed='true'],
:root[data-theme='light'] .fav:hover {
    color: #9a5b00;
}

:root[data-theme='light'] .playing .name {
    color: var(--ink);
    font-weight: 600;
}

.fav {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    margin: -6px -6px -6px 0;
    padding: 0;
    position: relative;
    border: 0;
    border-radius: 8px;
    background: none;
    color: var(--muted);
    transition:
        color 0.2s,
        scale 0.25s var(--ease);
}

.fav svg {
    width: 18px;
    height: 18px;
}

.fav:hover {
    color: var(--led-2);
    scale: 1.15;
}

.fav[aria-pressed='true'] {
    color: var(--led-2);
}

.fav[aria-pressed='true'] svg {
    fill: currentColor;
}

/* Starring: the star pops and throws a ring of sparks. */
.fav.burst svg {
    animation: star-pop 0.45s var(--ease);
}

.fav.burst::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    background: radial-gradient(circle, var(--led-2) 0 2px, transparent 2.5px) 0 0 / 50% 50%;
    animation: sparks 0.5s var(--ease) forwards;
    pointer-events: none;
}

@keyframes star-pop {
    40% {
        scale: 1.5;
        rotate: -12deg;
    }
}

@keyframes sparks {
    from {
        opacity: 1;
        scale: 0.4;
    }

    to {
        opacity: 0;
        scale: 1.8;
    }
}

#favorites .sound {
    cursor: grab;
}

#favorites .sound.dragging {
    opacity: 0.35;
}

/*=============== GIF POP-UP ===============*/
#pop-up {
    position: fixed;
    top: 50%;
    left: 50%;
    z-index: var(--z-popup);
    padding: 8px;
    background: var(--panel);
    border-radius: 16px;
    box-shadow: 0 30px 80px -20px rgb(0 0 0 / 0.75);
    transform: translate(-50%, -50%);
    cursor: pointer;
    animation: pop 0.45s var(--ease);
}

#pop-up::before {
    content: '';
    display: block;
    height: 4px;
    margin: -8px -8px 8px;
    border-radius: 16px 16px 0 0;
    background: var(--stripe);
}

#pop-up[hidden] {
    display: none;
}

#pop-up img {
    display: block;
    max-width: min(80vw, 460px);
    max-height: 62vh;
    border-radius: 10px;
}

@keyframes pop {
    from {
        opacity: 0;
        scale: 0.6;
        rotate: -4deg;
    }
}

/*=============== FOOTER ===============*/
footer {
    margin-top: 2rem;
    background: var(--panel);
}

.footer-inner {
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
    gap: 3rem;
    max-width: 1120px;
    margin: 0 auto;
    padding: 3.5rem clamp(1rem, 3vw, 2rem) 3rem;
}

#fact {
    min-height: 4.2em;
    max-width: 40ch;
    margin: 0 0 1.25rem;
    font: 600 clamp(1.25rem, 1rem + 1vw, 1.625rem) / 1.35 var(--font-display);
    transition:
        opacity 0.35s,
        filter 0.35s,
        translate 0.35s var(--ease);
}

#fact.swap {
    opacity: 0;
    filter: blur(6px);
    translate: 0 0.5rem;
}

.footer-side {
    display: grid;
    align-content: start;
    gap: 1.5rem;
    color: var(--muted);
}

.share {
    display: grid;
    justify-items: start;
    gap: 0.75rem;
}

.share .icon {
    width: 18px;
    height: 18px;
    background: currentColor;
    -webkit-mask: url(../img/share.png) center / contain no-repeat;
    mask: url(../img/share.png) center / contain no-repeat;
}

.keys,
.credits {
    font-size: 0.875rem;
}

.keys kbd {
    margin-left: 0.5rem;
}

.keys kbd:first-child {
    margin-left: 0;
}

/*=============== TOAST ===============*/
#toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    z-index: var(--z-toast);
    padding: 0.65rem 1.25rem;
    background: var(--ink);
    color: var(--bg);
    border-radius: 10px;
    box-shadow: var(--shadow);
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, 12px);
    transition:
        opacity 0.3s,
        transform 0.4s var(--ease);
}

#toast.show {
    opacity: 1;
    transform: translate(-50%, 0);
}

/*=============== SCROLL-DRIVEN REVEALS ===============*/
/* No JS. Browsers without support show everything static. Reduced motion turns these into fades (see the end). */
@supports (animation-timeline: view()) {
    .section-head,
    .footer-inner > * {
        animation: rise linear both;
        animation-timeline: view();
        animation-range: entry 0% entry 35%;
    }

    .sound {
        animation:
            tile-in 0.5s var(--ease) backwards,
            slide-up linear both;
        animation-delay: calc(var(--i, 0) * 35ms), 0s;
        animation-timeline: auto, view();
        animation-range:
            normal,
            entry 0% entry 40%;
    }
}

/* Movement only: content is readable even before its reveal starts. */
@keyframes rise {
    from {
        translate: 0 1.5rem;
    }
}

@keyframes slide-up {
    from {
        translate: 0 1.5rem;
    }
}

/*=============== BREAKPOINTS ===============*/
@media (max-width: 960px) {
    #now-name {
        display: none;
    }
}

@media (max-width: 760px) {
    #intro {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
        padding-bottom: 2.5rem;
    }

    .sleeve {
        width: 100%;
        aspect-ratio: auto;
        margin-block: 1rem 1.5rem;
        padding: 1.25rem;
    }

    #intro h1 {
        padding-block: 1.25rem 1rem;
        font-size: 3rem;
    }

    .deck {
        gap: 1.25rem;
    }

    .intro-actions {
        order: -1;
        margin-top: -0.25rem;
    }

    .lede {
        order: -2;
    }

    .big-pad {
        width: min(56vw, 200px);
    }

    header {
        grid-template-columns: 1fr auto;
        gap: 0.75rem;
    }

    #search-form {
        grid-column: 1 / -1;
        grid-row: 2;
        max-width: none;
    }

    .controls {
        gap: 0.75rem;
    }

    #volume {
        width: 64px;
    }

    /* Hidden visually but kept as the switch's accessible name. */
    .switch-label {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip-path: inset(50%);
    }

    main {
        gap: 3rem;
        padding-top: 1.5rem;
    }

    .sound {
        contain-intrinsic-size: auto 234px; /* measured at 390px */
    }

    .grid {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
        gap: 1.5rem 0.875rem;
    }

    .footer-inner {
        grid-template-columns: 1fr;
        gap: 2rem;
        padding-block: 2.5rem;
    }
}

@media (max-width: 420px) {
    .logo-name {
        display: none;
    }
}

/*=============== REDUCED MOTION ===============*/
/* Motion stays on for every visitor, but gentle: every animation plays as a plain fade.
   Pinning the transform properties beats keyframes, so each one keeps only its opacity part. */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after,
    ::view-transition-old(root),
    ::view-transition-new(root) {
        translate: none !important;
        scale: none !important;
        rotate: none !important;
    }

    /* The switch knob's position is state, not decoration: it jumps instead of sliding. */
    .switch-knob {
        transition: none;
    }

    .switch[aria-checked='true'] .switch-knob {
        translate: 16px 0 !important;
    }

    #toast {
        transform: translate(-50%, 0);
    }

    /* Keyframes that were movement only get a fade of their own. */
    @keyframes stripe-in {
        from {
            opacity: 0;
        }
    }

    @keyframes roll {
        50% {
            opacity: 0.35;
        }
    }

    @keyframes star-pop {
        40% {
            opacity: 0.35;
        }
    }

    @keyframes rise {
        from {
            opacity: 0.35;
        }
    }

    @keyframes slide-up {
        from {
            opacity: 0.35;
        }
    }
}
