:root {
    --page-background: #fff7ed;
    --surface: #f8e7d2;
    --surface-raised: #fffaf2;
    --text-color: #24302f;
    --text-muted: #68716d;
    --button-background: #24302f;
    --button-text: #fffaf2;
    --button-border: #24302f;
    --accent: #e85d4f;
    --accent-light: #ff9d89;
    --accent-note: #7c3aed;
    --accent-text: #fffaf2;
    --focus-color: #2563eb;
    --step-background: #d8c8b7;
    --step-border: #c5ad98;
    --kick-color: #0f766e;
    --danger-soft: #b42318;
    --shadow-color: rgb(118 74 40 / 0.18);
    --font-body: Manrope, Inter, system-ui, sans-serif;
    --font-display: Fraunces, Georgia, serif;
    color: var(--text-color);
    background: var(--page-background);
    color-scheme: light;
    font-family: var(--font-body);
    font-synthesis: none;
    line-height: 1.5;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

html[data-theme=dark] {
    --page-background: #151a1d;
    --surface: #202a2b;
    --surface-raised: #263332;
    --text-color: #fff7ed;
    --text-muted: #b9c2bd;
    --button-background: #fff7ed;
    --button-text: #151a1d;
    --button-border: #fff7ed;
    --accent: #ff7a66;
    --accent-light: #ffa996;
    --accent-note: #c4b5fd;
    --accent-text: #151a1d;
    --focus-color: #facc15;
    --step-background: #4b5654;
    --step-border: #63706d;
    --kick-color: #5eead4;
    --danger-soft: #ffb4a8;
    --shadow-color: rgb(0 0 0 / 0.32);
    color-scheme: dark;
}

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

body {
    min-width: 320px;
    min-height: 100dvh;
    margin: 0;
    display: flex;
    flex-direction: column;
    background: var(--page-background);
}

button,
input {
    font: inherit;
}

button {
    border: 1px solid var(--button-border);
    border-radius: 8px;
    color: var(--button-text);
    background: var(--button-background);
    cursor: pointer;
    box-shadow: 0 0.45rem 1.2rem var(--shadow-color);
    transition: border-color 150ms ease, background 150ms ease, color 150ms ease, transform 150ms ease, box-shadow 150ms ease;
}
button:hover {
    border-color: var(--accent);
    transform: translateY(-1px);
}
button:focus-visible {
    outline: 3px solid var(--focus-color);
    outline-offset: 3px;
}

a {
    color: var(--accent);
    font-weight: 700;
}

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

[hidden] {
    display: none !important;
}

main {
    width: min(100%, 1400px);
    min-height: calc(100dvh - 3rem);
    margin: 0 auto;
    padding: clamp(1rem, 4vw, 2rem);
    display: flex;
    flex: 1;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: clamp(1rem, 3vh, 2.25rem);
}
main > header {
    display: grid;
    justify-items: center;
    gap: 1rem;
    text-align: center;
}
main > header .brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: clamp(0.75rem, 2vw, 1.25rem);
    border-radius: 8px;
    color: inherit;
    text-decoration: none;
}
main > header .brand:focus-visible {
    outline: 3px solid var(--focus-color);
    outline-offset: 5px;
}
main > header .brand img {
    width: clamp(4.5rem, 12vw, 6.5rem);
    height: auto;
    flex: none;
    border-radius: 22%;
    box-shadow: 0 0.8rem 2rem var(--shadow-color);
}
main > header .brand .brand-copy {
    display: grid;
    gap: 0.35rem;
    text-align: left;
}
main > header .brand .brand-copy p {
    margin: 0;
    color: var(--text-muted);
    font-size: 1rem;
    line-height: 1.2;
}
main > header h1 {
    margin: 0;
    color: var(--text-color);
    font-family: var(--font-display);
    font-size: clamp(2.4rem, 8vw, 4.4rem);
    font-weight: 650;
    letter-spacing: 0;
    line-height: 0.95;
}
main > section:first-of-type {
    width: min(100%, 1120px);
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    row-gap: 0.5rem;
    padding: clamp(0.75rem, 2vw, 1.25rem);
    border: 1px solid color-mix(in srgb, var(--step-border), transparent 40%);
    border-radius: 18px;
    background: var(--surface);
    box-shadow: 0 1.2rem 3rem var(--shadow-color);
}
main > section:first-of-type .rhythm-toolbar {
    grid-column: 1/-1;
    justify-self: end;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}
main > section:first-of-type #share-button {
    width: 2.5rem;
    height: 2.5rem;
    min-height: 0;
    display: grid;
    place-items: center;
    padding: 0;
    border-color: transparent;
    color: var(--text-muted);
    background: transparent;
    box-shadow: none;
}
main > section:first-of-type #share-button:hover {
    color: var(--accent);
}
main > section:first-of-type #share-button svg {
    width: 1.3rem;
    height: 1.3rem;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.8;
}
main > section:first-of-type .rhythm-view-control {
    display: inline-grid;
    grid-template-columns: repeat(2, minmax(4.5rem, 1fr));
    gap: 0.2rem;
    padding: 0.2rem;
    border: 1px solid color-mix(in srgb, var(--step-border), transparent 22%);
    border-radius: 8px;
    background: var(--surface-raised);
}
main > section:first-of-type .rhythm-view-control button {
    height: 2.15rem;
    min-height: 0;
    padding: 0 0.7rem;
    border-color: transparent;
    color: var(--text-color);
    background: transparent;
    box-shadow: none;
    font-size: 0.9rem;
    font-weight: 700;
}
main > section:first-of-type .rhythm-view-control button.is-active {
    border-color: var(--accent);
    color: var(--accent-text);
    background: var(--accent);
}
main > section:first-of-type .rhythm-view-control button:disabled {
    opacity: 0.42;
    cursor: not-allowed;
}
main > section:first-of-type .rhythm-view-control button:disabled:hover {
    border-color: transparent;
    transform: none;
}
main > section:first-of-type .rhythm-grid {
    display: grid;
    row-gap: 0.75rem;
}
main > section:first-of-type .rhythm-shift-control {
    grid-column: 1/-1;
    justify-self: center;
    display: inline-grid;
    grid-template-columns: 2.4rem auto 2.4rem;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem;
    border: 1px solid color-mix(in srgb, var(--step-border), transparent 22%);
    border-radius: 8px;
    color: var(--text-muted);
    background: var(--surface-raised);
    font-size: 0.85rem;
    font-weight: 700;
}
main > section:first-of-type .rhythm-shift-control button {
    width: 2.4rem;
    height: 2.15rem;
    min-height: 0;
    display: grid;
    place-items: center;
    padding: 0;
    border-color: transparent;
    color: var(--text-color);
    background: transparent;
    box-shadow: none;
}
main > section:first-of-type .rhythm-shift-control button:hover {
    border-color: var(--accent);
    color: var(--accent);
}
main > section:first-of-type .rhythm-shift-control button:disabled {
    opacity: 0.38;
    cursor: not-allowed;
}
main > section:first-of-type .rhythm-shift-control button:disabled:hover {
    border-color: transparent;
    color: var(--text-color);
    transform: none;
}
main > section:first-of-type .rhythm-shift-control svg {
    width: 1.35rem;
    height: 1.35rem;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 2;
}
main > section:first-of-type .measure-row {
    display: grid;
    grid-template-columns: 1rem minmax(0, 1fr);
    align-items: center;
    column-gap: 0.65rem;
    row-gap: 0.5rem;
}
main > section:first-of-type .rhythm-grid ol {
    margin: 0;
    padding: 0;
    list-style: none;
}
main > section:first-of-type .rhythm-control {
    grid-column: 1/-1;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0.35rem;
}
main > section:first-of-type .rhythm-control > span {
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 700;
}
main > section:first-of-type.is-advanced-open {
    grid-template-columns: clamp(3.4rem, 10vw, 3.9rem) minmax(0, 1fr);
    grid-template-areas: "view view" ". beats" "measures grid" ". shift" ". subdivisions";
    column-gap: 0.65rem;
}
main > section:first-of-type.is-advanced-open .rhythm-toolbar {
    grid-area: view;
}
main > section:first-of-type.is-advanced-open .rhythm-control--measures {
    grid-area: measures;
}
main > section:first-of-type.is-advanced-open .rhythm-control--beats {
    grid-area: beats;
}
main > section:first-of-type.is-advanced-open .rhythm-grid {
    grid-area: grid;
}
main > section:first-of-type.is-advanced-open .rhythm-shift-control {
    grid-area: shift;
}
main > section:first-of-type.is-advanced-open .rhythm-control--subdivisions {
    grid-area: subdivisions;
}
main > section:first-of-type .rhythm-stepper {
    min-height: 2.65rem;
    display: grid;
    grid-template-columns: 2.25rem minmax(2rem, 1fr) 2.25rem;
    align-items: center;
    gap: 0.35rem;
    padding: 0.3rem;
    border: 1px solid color-mix(in srgb, var(--step-border), transparent 22%);
    border-radius: 8px;
    color: var(--text-color);
    background: var(--surface-raised);
}
main > section:first-of-type .rhythm-stepper output {
    min-width: 2rem;
    height: 2rem;
    display: inline-grid;
    place-items: center;
    justify-self: center;
    border-radius: 6px;
    color: var(--accent-text);
    background: var(--accent);
    font-weight: 700;
}
main > section:first-of-type .rhythm-stepper button {
    width: 2.05rem;
    height: 2.05rem;
    min-height: 0;
    display: grid;
    place-items: center;
    padding: 0;
    box-shadow: none;
    font-size: 1.25rem;
    line-height: 1;
}
main > section:first-of-type .rhythm-stepper button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}
main > section:first-of-type .rhythm-stepper button:disabled:hover {
    border-color: var(--button-border);
    transform: none;
}
main > section:first-of-type .rhythm-control--measures {
    min-width: 0;
    position: relative;
    align-self: stretch;
}
main > section:first-of-type .rhythm-control--measures > span {
    position: absolute;
    top: 50%;
    left: 0.32rem;
    z-index: 1;
    writing-mode: vertical-rl;
    transform: translateY(-50%) rotate(180deg);
    font-size: 0.72rem;
    line-height: 1;
    pointer-events: none;
}
main > section:first-of-type .rhythm-control--measures .rhythm-stepper {
    height: 100%;
    min-height: 100%;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 2.05rem minmax(2rem, 1fr) 2.05rem;
    justify-items: center;
    padding-left: 0.95rem;
}
main > section:first-of-type .rhythm-control--measures .rhythm-stepper output {
    align-self: center;
}
main > section:first-of-type .reference-beats {
    grid-column: 1;
    grid-row: 1;
    display: grid;
    grid-template-rows: repeat(var(--beat-count), minmax(2.8rem, auto));
    gap: 0.5rem;
    align-self: stretch;
}
main > section:first-of-type .reference-beats li {
    display: flex;
    align-items: center;
    justify-content: center;
}
main > section:first-of-type [data-kick-step] {
    width: 0.95rem;
    height: 0.95rem;
    border-radius: 999px;
    background: var(--kick-color);
    box-shadow: 0 0 0 0.22rem color-mix(in srgb, var(--kick-color), transparent 78%);
    transition: box-shadow 50ms ease-in, transform 50ms ease-in;
}
main > section:first-of-type [data-kick-step].is-playing {
    transform: scale(1.45);
    box-shadow: 0 0 0 0.28rem color-mix(in srgb, var(--kick-color), transparent 64%), 0 0 24px var(--kick-color);
}
main > section:first-of-type .sequencer {
    grid-column: 2;
    grid-row: 1;
    display: grid;
    grid-template-columns: repeat(var(--subdivision-count), minmax(0, 1fr));
    gap: 0.5rem;
}
main > section:first-of-type .hand-sequencer {
    display: none;
}
main > section:first-of-type.is-hands-view .measure-row {
    grid-template-columns: minmax(0, 1fr);
}
main > section:first-of-type.is-hands-view .reference-beats,
main > section:first-of-type.is-hands-view .sequencer {
    display: none;
}
main > section:first-of-type.is-hands-view .hand-sequencer {
    min-width: 0;
    display: grid;
    grid-template-columns: repeat(var(--beat-count), minmax(4.75rem, 1fr));
    gap: 0.4rem;
    overflow-x: auto;
    padding: 0.25rem 0.15rem 0.45rem;
    scrollbar-width: thin;
}
main > section:first-of-type.is-hands-view .hand-beat {
    min-width: 4.75rem;
    display: grid;
    grid-template-rows: 1.1rem minmax(0, 1fr) auto;
    justify-items: center;
    gap: 0.3rem;
}
main > section:first-of-type.is-hands-view .hand-beat img {
    width: 100%;
    max-width: 9rem;
    height: auto;
    aspect-ratio: 320/515;
    object-fit: contain;
    transform-origin: center bottom;
    user-select: none;
}
main > section:first-of-type.is-hands-view .hand-beat-label {
    min-width: 1.65rem;
    min-height: 1.65rem;
    display: grid;
    place-items: center;
    border-radius: 6px;
    color: var(--text-color);
    background: color-mix(in srgb, var(--step-background), transparent 18%);
    font-size: 0.9rem;
    font-weight: 700;
}
main > section:first-of-type.is-large-subdivision .reference-beats {
    grid-template-rows: repeat(var(--beat-count), minmax(2.35rem, auto));
    gap: 0.25rem;
}
main > section:first-of-type.is-large-subdivision .sequencer {
    gap: 0.18rem;
}
main > section:first-of-type.is-large-subdivision [data-step] {
    min-height: 2.35rem;
    padding: 0.2rem;
    font-size: 0.82rem;
}
main > section:last-of-type {
    width: min(100%, 760px);
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "primary" "random" "secondary" "bpm" "advanced" "status";
    align-items: center;
    justify-content: stretch;
    justify-items: stretch;
    column-gap: 0.65rem;
    row-gap: 0.9rem;
}
main > section:last-of-type > label[for=bpm],
main > section:last-of-type .kick-settings {
    min-height: 2.65rem;
    border: 1px solid var(--button-border);
    border-radius: 8px;
    color: var(--button-text);
    background: var(--button-background);
    font-weight: 700;
    box-shadow: 0 0.45rem 1.2rem var(--shadow-color);
}
main > section:last-of-type.is-advanced-open {
    grid-template-areas: "primary" "random" "secondary" "bpm" "advanced" "kick" "status";
}
main > section:last-of-type .random-control-group {
    grid-area: random;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0.55rem;
    padding: 0.55rem;
    border: 1px solid color-mix(in srgb, var(--step-border), transparent 15%);
    border-radius: 8px;
    background: var(--surface-raised);
    box-shadow: 0 0.45rem 1.2rem var(--shadow-color);
}
main > section:last-of-type .random-options {
    display: grid;
    gap: 0.35rem;
}
main > section:last-of-type .primary-playback {
    grid-area: primary;
    display: flex;
    justify-content: center;
}
main > section:last-of-type .difficulty-control,
main > section:last-of-type .clave-toggle {
    min-height: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.65rem;
    min-width: 0;
    padding: 0 0.2rem;
    color: var(--text-color);
    font-weight: 700;
}
main > section:last-of-type .difficulty-control select {
    height: 1.25rem;
    min-width: 5rem;
    padding: 0 0.3rem;
    border: 1px solid color-mix(in srgb, var(--text-color), transparent 45%);
    border-radius: 4px;
    color: var(--text-color);
    background: var(--surface-raised);
    font: inherit;
    font-size: 0.85rem;
}
main > section:last-of-type .secondary-actions {
    grid-area: secondary;
    display: flex;
    justify-content: center;
    gap: 0.65rem;
}
main > section:last-of-type .advanced-control {
    grid-area: advanced;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.55rem;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 700;
    text-align: center;
}
main > section:last-of-type #advanced-toggle {
    height: 2.65rem;
    min-height: 0;
    padding: 0 0.9rem;
}
main > section:last-of-type .kick-settings {
    grid-area: kick;
    display: grid;
    gap: 0.45rem;
    width: 100%;
    padding: 0.4rem 0.75rem;
    justify-self: stretch;
}
main > section:last-of-type .kick-setting {
    display: grid;
    align-items: center;
    gap: 0.35rem;
}
main > section:last-of-type .kick-setting--placement {
    grid-template-columns: minmax(4.5rem, auto) repeat(2, minmax(3.4rem, 1fr));
}
main > section:last-of-type .kick-setting--intensity {
    grid-template-columns: minmax(4.5rem, auto) repeat(3, minmax(3.4rem, 1fr));
}
main > section:last-of-type .kick-setting > span {
    align-self: center;
    white-space: nowrap;
}
main > section:last-of-type .kick-setting button {
    height: 1.9rem;
    min-height: 0;
    padding: 0 0.55rem;
    border-color: color-mix(in srgb, var(--button-text), transparent 55%);
    color: var(--button-text);
    background: color-mix(in srgb, var(--button-text), transparent 82%);
    box-shadow: none;
    font-size: 0.9rem;
    white-space: nowrap;
}
main > section:last-of-type .kick-setting button.is-active {
    border-color: var(--accent);
    color: var(--accent-text);
    background: var(--accent);
}
main > section:last-of-type > label[for=bpm] {
    grid-area: bpm;
    align-self: start;
    width: 100%;
    height: 2.65rem;
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0 0.75rem;
}
main > section:last-of-type > label[for=bpm] > span {
    white-space: nowrap;
}
main > section:last-of-type > label[for=bpm] input {
    min-width: 0;
    flex: 1;
    margin: 0;
    accent-color: var(--accent);
}
main > section:last-of-type .clave-toggle input {
    width: 2.3rem;
    height: 1.25rem;
    margin: 0;
    position: relative;
    appearance: none;
    border: 1px solid color-mix(in srgb, var(--text-color), transparent 45%);
    border-radius: 999px;
    background: color-mix(in srgb, var(--text-color), transparent 84%);
    cursor: pointer;
}
main > section:last-of-type .clave-toggle input::before {
    content: "";
    width: 0.85rem;
    height: 0.85rem;
    position: absolute;
    top: 50%;
    left: 0.15rem;
    border-radius: 999px;
    background: color-mix(in srgb, var(--text-color), transparent 25%);
    transform: translateY(-50%);
    transition: left 150ms ease, background 150ms ease;
}
main > section:last-of-type .clave-toggle input:checked {
    border-color: var(--accent);
    background: var(--accent);
}
main > section:last-of-type .clave-toggle input:checked::before {
    left: 1.2rem;
    background: var(--accent-text);
}
main > section:last-of-type .clave-toggle input:focus-visible {
    outline: 3px solid var(--focus-color);
    outline-offset: 3px;
}

[data-step] {
    width: 100%;
    min-height: 2.8rem;
    display: grid;
    place-items: center;
    padding: 0.35rem;
    border-color: var(--step-border);
    color: var(--text-color);
    background: var(--step-background);
    box-shadow: none;
    font-size: clamp(1rem, 4vw, 1.35rem);
    font-weight: 700;
}
[data-step].is-active {
    border-color: var(--accent);
}
[data-step].is-normal {
    border-color: var(--accent);
    color: var(--accent-text);
    background: var(--accent);
}
[data-step].is-accent {
    border-color: var(--accent-note);
    color: var(--accent-text);
    background: var(--accent-note);
}
[data-step].is-playing {
    border-color: var(--text-color);
    box-shadow: 0 0 0 0.24rem color-mix(in srgb, var(--text-color), transparent 66%);
}

#generate-button,
#play-button,
#reset-button,
#saved-rhythms-button {
    height: 2.65rem;
    min-height: 0;
}

#generate-button {
    width: 100%;
    min-width: 0;
    padding: 0 0.9rem;
}

#reset-button,
#saved-rhythms-button {
    width: auto;
    min-width: 6rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    padding-inline: 0.8rem;
}
#reset-button svg,
#saved-rhythms-button svg {
    width: 1.35rem;
    height: 1.35rem;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.8;
}

#saved-rhythms-button {
    min-width: 8.5rem;
}

#play-button {
    width: 3.5rem;
    height: 3.5rem;
    padding: 0;
    display: grid;
    place-items: center;
    border-color: var(--accent);
    border-radius: 999px;
    color: var(--accent-text);
    background: var(--accent);
    box-shadow: 0 0.8rem 2rem var(--shadow-color);
}
#play-button svg {
    width: 1.6rem;
    height: 1.6rem;
    fill: currentColor;
}
#play-button[aria-pressed=true] {
    border-color: var(--accent-light);
    background: var(--accent-light);
}

#reset-button,
#saved-rhythms-button {
    color: var(--text-color);
    background: var(--surface-raised);
    border-color: color-mix(in srgb, var(--step-border), transparent 20%);
}

#theme-toggle {
    min-height: 2.85rem;
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.55rem 0.8rem;
    border-color: color-mix(in srgb, var(--step-border), transparent 20%);
    color: var(--text-color);
    background: var(--surface-raised);
    font-size: 0.95rem;
    font-weight: 700;
}
#theme-toggle svg {
    width: 1.25rem;
    height: 1.25rem;
    flex: 0 0 auto;
    fill: currentColor;
}
#theme-toggle[aria-pressed=true] {
    color: var(--accent-text);
    background: var(--accent);
    border-color: var(--accent);
}

#generation-status {
    grid-area: status;
    justify-self: center;
    min-height: 1.4rem;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    color: var(--kick-color);
    font-size: 0.875rem;
    font-weight: 700;
    opacity: 0;
    transform: scale(0.98);
    transition: opacity 250ms ease, transform 250ms ease;
}
#generation-status.is-visible {
    opacity: 1;
    transform: scale(1.05);
}
#generation-status.is-error {
    color: var(--danger-soft);
    opacity: 1;
}
#generation-status svg {
    width: 1.2rem;
    height: 1.2rem;
    fill: currentColor;
}

#saved-rhythms-dialog {
    width: min(100% - 2rem, 42rem);
    max-height: min(85dvh, 44rem);
    margin: auto;
    padding: 0;
    overflow: auto;
    border: 1px solid var(--step-border);
    border-radius: 8px;
    color: var(--text-color);
    background: var(--surface-raised);
    box-shadow: 0 1.2rem 3rem var(--shadow-color);
}
#saved-rhythms-dialog::backdrop {
    background: rgba(21, 26, 29, 0.68);
}
#saved-rhythms-dialog > header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem;
    border-bottom: 1px solid color-mix(in srgb, var(--step-border), transparent 35%);
}
#saved-rhythms-dialog > header h2 {
    margin: 0;
    font-family: var(--font-display);
    font-size: 1.55rem;
    font-weight: 650;
    letter-spacing: 0;
    line-height: 1.1;
}
#saved-rhythms-dialog > header button {
    width: 2.4rem;
    height: 2.4rem;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    padding: 0;
    color: var(--text-color);
    background: transparent;
    border-color: transparent;
    box-shadow: none;
}
#saved-rhythms-dialog > header button svg {
    width: 1.25rem;
    height: 1.25rem;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-width: 2;
}
#saved-rhythms-dialog form {
    display: grid;
    gap: 0.4rem;
    padding: 1rem;
}
#saved-rhythms-dialog form label {
    font-size: 0.9rem;
    font-weight: 700;
}
#saved-rhythms-dialog form > div {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0.55rem;
}
#saved-rhythms-dialog form input {
    width: 100%;
    min-width: 0;
    min-height: 2.65rem;
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--step-border);
    border-radius: 8px;
    color: var(--text-color);
    background: var(--page-background);
}
#saved-rhythms-dialog form input:focus-visible {
    outline: 3px solid var(--focus-color);
    outline-offset: 2px;
}
#saved-rhythms-dialog form button {
    min-height: 2.65rem;
    padding: 0.55rem 0.9rem;
}
#saved-rhythms-dialog #saved-rhythms-status,
#saved-rhythms-dialog #saved-rhythms-empty {
    margin: 0;
    padding-inline: 1rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}
#saved-rhythms-dialog #saved-rhythms-status {
    min-height: 1.4rem;
    color: var(--kick-color);
    font-weight: 700;
}
#saved-rhythms-dialog #saved-rhythms-empty {
    padding-block: 1rem 1.25rem;
}
#saved-rhythms-dialog ul {
    margin: 0;
    padding: 0.5rem 1rem 1rem;
    list-style: none;
}
#saved-rhythms-dialog ul li {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.7rem;
    padding: 0.9rem 0;
    border-top: 1px solid color-mix(in srgb, var(--step-border), transparent 35%);
}
#saved-rhythms-dialog ul li .saved-rhythm-load {
    min-width: 0;
    display: grid;
    gap: 0.2rem;
    padding: 0.4rem;
    border-color: transparent;
    color: var(--text-color);
    background: transparent;
    box-shadow: none;
    text-align: left;
}
#saved-rhythms-dialog ul li .saved-rhythm-load:hover {
    border-color: color-mix(in srgb, var(--step-border), transparent 25%);
    background: color-mix(in srgb, var(--surface), transparent 45%);
    transform: none;
}
#saved-rhythms-dialog ul li .saved-rhythm-load strong {
    overflow-wrap: anywhere;
}
#saved-rhythms-dialog ul li .saved-rhythm-load span {
    color: var(--text-muted);
    font-size: 0.82rem;
}
#saved-rhythms-dialog ul li > [data-delete-rhythm] {
    min-height: 2.35rem;
    padding: 0.4rem 0.75rem;
    border-color: color-mix(in srgb, var(--danger-soft), transparent 30%);
    color: var(--danger-soft);
    background: transparent;
    box-shadow: none;
}

footer {
    padding: 0 1rem 1rem;
    color: var(--text-muted);
    text-align: center;
}
footer p {
    margin: 0;
}
footer #analytics-settings {
    min-height: 0;
    margin-top: 0.25rem;
    padding: 0;
    border: 0;
    color: inherit;
    background: transparent;
    box-shadow: none;
    font-size: 0.8rem;
    text-decoration: underline;
    text-underline-offset: 0.2rem;
}
footer #analytics-settings:hover {
    color: var(--accent);
    transform: none;
}

#analytics-consent {
    width: min(100% - 2rem, 46rem);
    max-height: calc(100dvh - 2rem);
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 20;
    padding: 1rem;
    overflow: auto;
    border: 1px solid var(--step-border);
    border-radius: 8px;
    color: var(--text-color);
    background: var(--surface-raised);
    box-shadow: 0 1rem 2.5rem var(--shadow-color);
}
#analytics-consent h2,
#analytics-consent p {
    margin: 0;
}
#analytics-consent h2 {
    font-family: var(--font-display);
    font-size: 1.35rem;
    letter-spacing: 0;
    line-height: 1.1;
}
#analytics-consent > div:first-child {
    display: grid;
    gap: 0.6rem;
}
#analytics-consent p,
#analytics-consent summary,
#analytics-consent a {
    font-size: 0.86rem;
}
#analytics-consent details {
    color: var(--text-muted);
}
#analytics-consent details summary {
    width: fit-content;
    color: var(--text-color);
    cursor: pointer;
    font-weight: 700;
}
#analytics-consent details p {
    margin: 0.55rem 0 0.35rem;
}
#analytics-consent code {
    overflow-wrap: anywhere;
}
#analytics-consent .analytics-consent-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.65rem;
    margin-top: 0.85rem;
}
#analytics-consent .analytics-consent-actions button {
    min-height: 2.65rem;
    padding: 0.45rem 0.75rem;
}

@media (min-width: 760px) {
    main > section:first-of-type {
        gap: 0.75rem;
    }
    main > section:first-of-type .rhythm-grid {
        gap: 0.75rem;
    }
    main > section:first-of-type.is-hands-view .hand-sequencer {
        grid-template-columns: repeat(var(--beat-count), minmax(5.25rem, 7rem));
        justify-content: center;
    }
    main > section:first-of-type.is-hands-view .hand-beat {
        min-width: 5.25rem;
    }
    main > section:first-of-type.is-hands-view .hand-beat img {
        max-width: 6.25rem;
    }
    main > section:first-of-type .rhythm-control {
        grid-template-columns: repeat(var(--beat-count), minmax(0, 1fr));
    }
    main > section:first-of-type .rhythm-control--measures {
        grid-template-columns: minmax(0, 1fr);
    }
    main > section:first-of-type .rhythm-control > span {
        grid-column: 1/-1;
    }
    main > section:first-of-type .rhythm-control--beats .rhythm-stepper {
        grid-column: 1/-1;
    }
    main > section:first-of-type .rhythm-control--subdivisions .rhythm-stepper {
        grid-column: 1;
        grid-template-columns: 1.6rem minmax(1.4rem, 1fr) 1.6rem;
        gap: 0.15rem;
        padding: 0.25rem;
    }
    main > section:first-of-type .rhythm-control--subdivisions .rhythm-stepper output {
        min-width: 1.45rem;
        height: 1.9rem;
    }
    main > section:first-of-type .rhythm-control--subdivisions .rhythm-stepper button {
        width: 1.6rem;
        height: 1.9rem;
        font-size: 1.1rem;
    }
    main > section:first-of-type .measure-row {
        grid-template-columns: minmax(0, 1fr);
        row-gap: 0.35rem;
    }
    main > section:first-of-type .reference-beats,
    main > section:first-of-type .sequencer {
        grid-column: 1;
        grid-row: auto;
        grid-template-columns: repeat(var(--steps-per-measure), minmax(0, 1fr));
    }
    main > section:first-of-type .reference-beats {
        grid-template-rows: none;
    }
    main > section:first-of-type .reference-beats li {
        min-height: 1.25rem;
        grid-column: var(--beat-step);
    }
    main > section:first-of-type .sequencer {
        gap: 0.35rem;
    }
    main > section:first-of-type.is-large-subdivision .rhythm-control--subdivisions .rhythm-stepper {
        grid-column: 1/-1;
    }
    main > section:first-of-type.is-large-subdivision .measure-row {
        grid-template-columns: 1rem minmax(0, 1fr);
        align-items: center;
        column-gap: 0.65rem;
        row-gap: 0.5rem;
    }
    main > section:first-of-type.is-large-subdivision .reference-beats {
        grid-column: 1;
        grid-row: 1;
        grid-template-columns: none;
        grid-template-rows: repeat(var(--beat-count), minmax(2.35rem, auto));
        gap: 0.25rem;
        align-self: stretch;
    }
    main > section:first-of-type.is-large-subdivision .reference-beats li {
        min-height: 0;
        grid-column: auto;
    }
    main > section:first-of-type.is-large-subdivision .sequencer {
        grid-column: 2;
        grid-row: 1;
        grid-template-columns: repeat(var(--subdivision-count), minmax(0, 1fr));
        gap: 0.18rem;
    }
    main > section:last-of-type {
        width: min(100%, 920px);
        grid-template-columns: minmax(0, 1fr) minmax(12rem, 1fr);
        grid-template-areas: "primary primary" "random random" "secondary bpm" "advanced advanced" "status status";
        justify-content: center;
        justify-items: stretch;
    }
    main > section:last-of-type.is-advanced-open {
        grid-template-areas: "primary primary" "random random" "secondary bpm" "advanced advanced" "kick kick" "status status";
    }
    main > section:last-of-type .kick-settings {
        grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
        gap: 0.75rem;
    }
    main > section:last-of-type .random-control-group {
        grid-template-columns: minmax(10.25rem, auto) minmax(10.25rem, 1fr);
        align-items: center;
        align-self: stretch;
    }
    main > section:last-of-type .primary-playback {
        justify-content: center;
    }
    main > section:last-of-type .random-control-group,
    main > section:last-of-type .secondary-actions,
    main > section:last-of-type > label[for=bpm] {
        height: 4.25rem;
    }
    main > section:last-of-type .secondary-actions {
        align-self: stretch;
    }
    main > section:last-of-type #reset-button,
    main > section:last-of-type #saved-rhythms-button {
        height: 100%;
    }
    main > section:last-of-type #play-button {
        width: 3.85rem;
        height: 3.85rem;
    }
    main > section:last-of-type #play-button svg {
        width: 1.78rem;
        height: 1.78rem;
    }
    main > section:last-of-type .advanced-control {
        justify-content: flex-start;
        text-align: left;
    }
    main > section:last-of-type > label[for=bpm] {
        width: 100%;
    }
    #saved-rhythms-dialog form > div {
        grid-template-columns: minmax(0, 1fr) auto;
    }
}
@media (min-width: 1100px) {
    main > section:last-of-type {
        width: min(100%, 1020px);
        grid-template-columns: minmax(0, 1.4fr) auto minmax(12rem, 13rem);
        grid-template-areas: "primary primary primary" "random secondary bpm" "advanced advanced advanced" "status status status";
    }
    main > section:last-of-type.is-advanced-open {
        grid-template-areas: "primary primary primary" "random secondary bpm" "advanced advanced advanced" "kick kick kick" "status status status";
    }
    main > section:last-of-type > label[for=bpm] {
        width: min(100%, 12.5rem);
    }
}
