:root {
    touch-action: pan-x pan-y;
    height: 100%;
}

* {
    -webkit-user-select: none;
    user-select: none;
}

@font-face {
  font-family: "sniglet";
  src: url("/fonts/sniglet.woff2") format("woff2"),
       url("/fonts/sniglet.woff") format("woff");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0021-002C, U+002E-0039, U+003B-007E;
}

body {
    background: #6e40c9; /* fallback while canvas initialises */
    overflow: hidden;
    width: 100%;
    height: 100%;
    margin: 0;
}

/* ── Full-screen canvas ─────────────────────────────────────────────────── */
#drumkit-canvas {
    position: fixed;
    inset: 0;
    z-index: 0;
    touch-action: none;
    display: block;
}

/* ── Fireflies (used on splash screen) ─────────────────────────────────── */
.firefly {
    position: fixed;
    border-radius: 50%;
    pointer-events: none;
    z-index: 99999;
    animation: firefly-float var(--ff-dur, 3s) ease-in-out forwards;
    box-shadow: 0 0 8px 4px var(--ff-color, #F1FA8C);
}

@keyframes firefly-float {
    0%   { opacity: 0;   transform: translate(0, 0) scale(0.8); }
    15%  { opacity: 0.9; transform: translate(calc(var(--dx) * 0.15), calc(var(--dy) * 0.15)) scale(1); }
    30%  { opacity: 0.1; transform: translate(calc(var(--dx) * 0.3),  calc(var(--dy) * 0.3)); }
    50%  { opacity: 0.9; transform: translate(calc(var(--dx) * 0.5),  calc(var(--dy) * 0.5)); }
    65%  { opacity: 0.1; transform: translate(calc(var(--dx) * 0.65), calc(var(--dy) * 0.65)); }
    82%  { opacity: 0.9; transform: translate(calc(var(--dx) * 0.82), calc(var(--dy) * 0.82)) scale(1); }
    100% { opacity: 0;   transform: translate(var(--dx), var(--dy)) scale(0.4); }
}

/* ── Splash splash-button burst particles (DOM, used once only) ─────────── */
.sparkle {
    position: fixed;
    width: 48px;
    height: 48px;
    pointer-events: none;
    z-index: 99999;
    animation: sparkle-burst 0.6s ease-out forwards;
}

.sparkle-circle  { clip-path: circle(50%); }
.sparkle-diamond { clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%); }
.sparkle-triangle { clip-path: polygon(50% 0%, 100% 100%, 0% 100%); }
.sparkle-star    { clip-path: polygon(50% 0%, 61.8% 33.8%, 97.6% 34.5%, 69% 56.2%, 79.4% 90.5%, 50% 70%, 20.6% 90.5%, 31% 56.2%, 2.4% 34.5%, 38.2% 33.8%); }

@keyframes sparkle-burst {
    0%   { opacity: 1; transform: translate(0, 0) scale(1); }
    100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0.3); }
}

/* ── COMBO! flash overlay ───────────────────────────────────────────────── */
#combo-flash {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 99998;
    background: radial-gradient(ellipse at center, rgba(255,255,255,0.22) 0%, rgba(255,255,255,0) 70%);
    animation: combo-flash-anim 0.45s ease-out forwards;
}

@keyframes combo-flash-anim {
    0%   { opacity: 1; transform: scale(0.4); }
    35%  { opacity: 0.85; transform: scale(1.2); }
    100% { opacity: 0; transform: scale(1.8); }
}

/* ── COMBO! text ────────────────────────────────────────────────────────── */
#combo-text {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 99999;
    display: flex;
    gap: 0.08em;
}

.combo-letter {
    display: inline-block;
    font-family: 'sniglet', 'Arial Black', 'Impact', sans-serif;
    font-size: clamp(4.5rem, 18vw, 12rem);
    font-weight: 900;
    line-height: 1;
    -webkit-text-stroke: 3px rgb(255, 0, 212);
    text-shadow:
        0 0 20px currentColor,
        0 0 55px currentColor,
        0 0 110px currentColor,
        5px 5px 0 rgba(0, 0, 0, 0.55);
    animation: combo-letter-anim 1.7s ease-out both;
    animation-delay: var(--letter-delay, 0s);
}

@keyframes combo-letter-anim {
    0%   { opacity: 0; transform: scale(0) rotate(var(--spin, 0deg)); filter: brightness(1.8); }
    18%  { opacity: 1; transform: scale(2.4) rotate(0deg);            filter: brightness(1.4); }
    32%  { opacity: 1; transform: scale(0.85) rotate(0deg);           filter: brightness(1.2); }
    46%  { opacity: 1; transform: scale(1.15) rotate(0deg);           filter: brightness(1.1); }
    60%  { opacity: 1; transform: scale(1) rotate(0deg);              filter: brightness(1.05); }
    78%  { opacity: 1; transform: scale(1) rotate(0deg);              filter: brightness(1); }
    100% { opacity: 0; transform: translate(var(--ex, 0px), var(--ey, 0px)) scale(0.05) rotate(var(--er, 0deg)); filter: brightness(0.4); }
}

@media (orientation: portrait) {
    #combo-text {
        flex-direction: column;
        align-items: center;
        gap: 0.04em;
    }

    .combo-letter {
        font-size: clamp(2.5rem, 12vh, 8rem);
    }
}

/* ── iOS-only: further reduce Combo! intensity ──────────────────────────── */
@supports (-webkit-touch-callout: none) {
    #combo-flash {
        background: radial-gradient(ellipse at center, rgba(255,255,255,0.08) 0%, rgba(255,255,255,0) 70%);
    }

    @keyframes combo-flash-anim {
        0%   { opacity: 0.6; transform: scale(0.4); }
        35%  { opacity: 0.4; transform: scale(1.2); }
        100% { opacity: 0;   transform: scale(1.8); }
    }

    .combo-letter {
        text-shadow:
            0 0 10px currentColor,
            5px 5px 0 rgba(0, 0, 0, 0.55);
    }

    @keyframes combo-letter-anim {
        0%   { opacity: 0; transform: scale(0) rotate(var(--spin, 0deg)); filter: brightness(1.2); }
        18%  { opacity: 1; transform: scale(2.4) rotate(0deg);            filter: brightness(1.1); }
        32%  { opacity: 1; transform: scale(0.85) rotate(0deg);           filter: brightness(1.05); }
        46%  { opacity: 1; transform: scale(1.15) rotate(0deg);           filter: brightness(1); }
        60%  { opacity: 1; transform: scale(1) rotate(0deg);              filter: brightness(1); }
        78%  { opacity: 1; transform: scale(1) rotate(0deg);              filter: brightness(1); }
        100% { opacity: 0; transform: translate(var(--ex, 0px), var(--ey, 0px)) scale(0.05) rotate(var(--er, 0deg)); filter: brightness(0.4); }
    }
}

/* ── Cache version badge ────────────────────────────────────────────────── */
#cache-version {
    position: fixed;
    top: 8px;
    right: 8px;
    text-align: center;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.25);
    pointer-events: none;
    z-index: 1;
    font-family: monospace;
    letter-spacing: 0.05em;
}

/* ── BPM Control ────────────────────────────────────────────────────────── */
#bpm-control {
    position: fixed;
    bottom: 12px;
    left: 12px;
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 2px;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 50px;
    padding: 4px 8px 4px 6px;
    user-select: none;
    opacity: 0;
    pointer-events: none;
    transform: translateY(6px);
    transition: opacity 0.4s ease, transform 0.4s ease;
}

#bpm-control.bpm-visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

#bpm-control button {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.85);
    font-size: 1.1rem;
    font-weight: 900;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    padding: 0;
    line-height: 1;
    touch-action: manipulation;

    &:hover, &:active {
        background: rgba(255, 255, 255, 0.2);
    }
}

#bpm-display {
    font-family: 'sniglet', 'Arial Rounded MT Bold', 'Arial Black', Arial, sans-serif;
    font-size: 0.9rem;
    font-weight: 900;
    color: #f1fa8c;
    min-width: 2em;
    text-align: right;
    display: inline-block;
}

.bpm-label {
    font-size: 0.62rem;
    color: rgba(255, 255, 255, 0.5);
    font-family: monospace;
    letter-spacing: 0.05em;
}

/* ── Reverb Toggle ──────────────────────────────────────────────────────── */
#reverb-btn {
    position: fixed;
    bottom: 12px;
    right: 12px;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 50px;
    padding: 6px 14px;
    color: rgba(255, 255, 255, 0.6);
    font-family: 'sniglet', 'Arial Rounded MT Bold', 'Arial Black', Arial, sans-serif;
    font-size: 0.8rem;
    font-weight: 900;
    letter-spacing: 0.04em;
    cursor: pointer;
    user-select: none;
    touch-action: manipulation;
    opacity: 0;
    pointer-events: none;
    transform: translateY(6px);
    transition: opacity 0.4s ease, transform 0.4s ease, background 0.2s, color 0.2s, border-color 0.2s, box-shadow 0.2s;
}

#reverb-btn.reverb-show {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

#reverb-btn.reverb-on {
    background: rgba(189, 147, 249, 0.35);
    border-color: rgba(189, 147, 249, 0.7);
    color: #f1fa8c;
    box-shadow: 0 0 12px rgba(189, 147, 249, 0.5);
}

#reverb-btn:hover,
#reverb-btn:active {
    background: rgba(255, 255, 255, 0.15);
}

/* ── Splash Modal ───────────────────────────────────────────────────────── */
#splash-modal {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: clamp(1rem, 3vw, 2.5rem);
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(6px);

    &.exploding {
        animation: modal-backdrop-fade 0.55s ease-out forwards;

        #splash-content {
            animation: content-explode 0.55s ease-out forwards;
        }
    }
}

#splash-content {
    position: relative;
    display: grid;
    grid-template-columns: minmax(220px, 0.9fr) minmax(280px, 1.1fr);
    align-items: center;
    gap: clamp(1.5rem, 4vw, 4rem);
    background: linear-gradient(135deg, #bd93f9 0%, #ff79c6 30%, #ffb86c 60%, #50fa7b 80%, #8be9fd 100%);
    background-size: 300% 300%;
    animation: gradient-shift 3s ease infinite;
    border-radius: 28px;
    padding: clamp(1.5rem, 4vw, 3.5rem);
    text-align: left;
    box-shadow: 0 0 60px rgba(189, 147, 249, 0.8), 0 0 120px rgba(255, 121, 198, 0.4), 0 20px 60px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.18);
    max-width: min(960px, 100%);
    width: min(960px, 100%);
    min-height: min(72vh, 520px);
    overflow: hidden;
    isolation: isolate;

    &::before {
        content: '';
        position: absolute;
        inset: auto auto -22% -14%;
        width: clamp(220px, 28vw, 340px);
        aspect-ratio: 1;
        background: radial-gradient(circle, rgba(255, 255, 255, 0.35) 0%, rgba(255, 255, 255, 0) 72%);
        filter: blur(4px);
        opacity: 0.8;
        pointer-events: none;
        z-index: -1;
    }

    &::after {
        content: '';
        position: absolute;
        inset: 0;
        background: linear-gradient(120deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0) 38%, rgba(255, 255, 255, 0.14));
        pointer-events: none;
    }
}

.splash-art,
.splash-copy {
    position: relative;
    z-index: 1;
}

.splash-art {
    display: flex;
    align-items: center;
    justify-content: center;
}

.splash-copy {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.splash-kicker {
    margin: 0 0 0.8rem;
    padding: 0.45rem 0.85rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.18);
    border: 1px solid rgba(255, 255, 255, 0.25);
    color: rgba(255, 255, 255, 0.95);
    font-family: 'sniglet', 'Arial Rounded MT Bold', 'Arial Black', Arial, sans-serif;
    font-size: clamp(0.8rem, 1.4vw, 0.95rem);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

#splash-drum {
    width: clamp(180px, 28vw, 300px);
    height: auto;
    animation: splash-bounce 1.2s ease-in-out infinite;
    filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.35));
}

#splash-content h1 {
    font-family: 'sniglet', 'Arial Rounded MT Bold', 'Arial Black', Arial, sans-serif;
    font-size: clamp(2.2rem, 5vw, 4.4rem);
    color: #ffffff;
    text-shadow: 3px 3px 0 rgba(80, 0, 120, 0.4), 0 2px 12px rgba(0, 0, 0, 0.3);
    margin: 0 0 1.6rem;
    line-height: 1.08;
    font-weight: 900;
    max-width: 10ch;
}

.splash-actions {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.9rem;
    width: 100%;
}

#splash-btn-wrapper {
    position: relative;
    display: inline-block;
    border-radius: 54px;
    padding: 4px;
    overflow: hidden;
    transition: transform 0.15s, box-shadow 0.15s;
    animation: btn-glow 1.4s ease-in-out infinite alternate;

    &::before {
        content: '';
        position: absolute;
        width: 200%;
        height: 200%;
        top: -50%;
        left: -50%;
        background: conic-gradient(from 0deg at 50% 50%, #ff2d78, #ffb86c, #f1fa8c, #50fa7b, #8be9fd, #bd93f9, #ff79c6, #ff2d78);
        animation: spin 2s linear infinite;
    }

    &:hover, &:active {
        transform: scale(1.08);
    }
}

#splash-btn {
    position: relative;
    background: linear-gradient(135deg, #ff2d78, #ffb86c, #f1fa8c);
    color: #5a0030;
    border: none;
    min-width: min(100%, 320px);
    padding: 0.95rem 2.8rem;
    font-size: clamp(1.2rem, 2vw, 1.9rem);
    font-weight: 900;
    border-radius: 50px;
    cursor: pointer;
    font-family: 'sniglet', 'Arial Rounded MT Bold', 'Arial Black', Arial, sans-serif;
    letter-spacing: 0.03em;
    text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.4);
    display: block;
}

@keyframes splash-bounce {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-10px) scale(1.06); }
}

@keyframes btn-glow {
    from { box-shadow: 0 6px 25px rgba(255, 45, 120, 0.5), 0 0 0 0 rgba(255, 255, 255, 0); }
    to   { box-shadow: 0 6px 35px rgba(255, 45, 120, 0.8), 0 0 20px 4px rgba(255, 255, 255, 0.35); }
}

@keyframes modal-backdrop-fade {
    0%   { opacity: 1; }
    100% { opacity: 0; pointer-events: none; }
}

@keyframes content-explode {
    0%   { transform: scale(1);    opacity: 1; }
    25%  { transform: scale(1.18); opacity: 1; }
    100% { transform: scale(4.5);  opacity: 0; }
}

@keyframes gradient-shift {
    0%   { background-position: 0% 50%; }
    50%  { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

/* ── Help link ──────────────────────────────────────────────────────────── */
#splash-help-link {
    margin-top: 0;
}

#help-btn {
    background: transparent;
    border: 2px solid rgba(255, 255, 255, 0.55);
    color: rgba(255, 255, 255, 0.9);
    min-width: min(100%, 220px);
    padding: 0.55rem 1.5rem;
    font-size: clamp(0.92rem, 1.25vw, 1.05rem);
    font-weight: 700;
    border-radius: 50px;
    cursor: pointer;
    font-family: 'sniglet', 'Arial Rounded MT Bold', 'Arial Black', Arial, sans-serif;
    transition: border-color 0.15s, background 0.15s;

    &:hover, &:active {
        background: rgba(255, 255, 255, 0.15);
        border-color: rgba(255, 255, 255, 0.9);
    }
}

@media (max-width: 760px) {
    #splash-modal {
        padding: 0.75rem;
    }

    #splash-content {
        grid-template-columns: 1fr;
        gap: 1.25rem;
        min-height: auto;
        text-align: center;
        justify-items: center;
    }

    .splash-copy {
        align-items: center;
    }

    .splash-kicker {
        margin-bottom: 0.65rem;
    }

    #splash-content h1 {
        max-width: none;
        margin-bottom: 1.25rem;
    }

    .splash-actions {
        align-items: center;
    }

    #splash-btn,
    #help-btn {
        width: min(100%, 320px);
    }
}

@media (min-width: 1024px) {
    #splash-content {
        grid-template-columns: minmax(260px, 0.85fr) minmax(360px, 1fr);
    }

    #splash-drum {
        width: clamp(240px, 26vw, 340px);
    }
}

@media (max-height: 520px) and (orientation: landscape) {
    #splash-content {
        min-height: auto;
        gap: 1.25rem;
        padding: 1.25rem 1.5rem;
    }

    #splash-drum {
        width: clamp(132px, 22vh, 210px);
        animation-duration: 1.6s;
    }

    .splash-kicker {
        margin-bottom: 0.5rem;
    }

    #splash-content h1 {
        font-size: clamp(1.8rem, 7.5vh, 3.2rem);
        margin-bottom: 1rem;
    }

    .splash-actions {
        gap: 0.65rem;
    }

    #splash-btn {
        padding-block: 0.75rem;
    }

    #help-btn {
        padding-block: 0.45rem;
    }
}

/* ── Help Modal ─────────────────────────────────────────────────────────── */
#help-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 10001;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(6px);
}

#help-content {
    background: linear-gradient(160deg, #1e0840 0%, #2d1b69 50%, #1e0840 100%);
    border: 1px solid rgba(189, 147, 249, 0.35);
    border-radius: 28px;
    padding: 2rem 1.75rem;
    text-align: left;
    box-shadow: 0 0 60px rgba(189, 147, 249, 0.45), 0 20px 60px rgba(0, 0, 0, 0.55);
    max-width: 420px;
    width: 88%;
    max-height: 80vh;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(189, 147, 249, 0.4) transparent;
    box-sizing: border-box;
}

#help-content h2 {
    font-family: 'sniglet', 'Arial Rounded MT Bold', 'Arial Black', Arial, sans-serif;
    font-size: clamp(1.4rem, 5vw, 2rem);
    color: #ffffff;
    text-shadow: 2px 2px 0 rgba(80, 0, 120, 0.5);
    margin: 0 0 1.1rem;
    text-align: center;
    font-weight: 900;
}

.help-section {
    background: rgba(255, 255, 255, 0.06);
    border-radius: 16px;
    padding: 0.9rem 1rem;
    margin-bottom: 0.75rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.help-section h3 {
    font-family: 'sniglet', 'Arial Rounded MT Bold', 'Arial Black', Arial, sans-serif;
    font-size: 0.95rem;
    font-weight: 900;
    color: #f1fa8c;
    margin: 0 0 0.45rem;
    text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.4);
}

.help-section p {
    font-family: 'Arial Rounded MT Bold', 'Arial Black', Arial, sans-serif;
    font-size: 0.875rem;
    color: rgba(255, 255, 255, 0.88);
    margin: 0.3rem 0 0;
    line-height: 1.5;
}

.help-section p strong {
    color: #ff79c6;
}

.help-section p.help-note {
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.78rem;
    margin-top: 0.5rem;
}

#help-back-btn {
    display: block;
    margin: 1.2rem auto 0;
    background: linear-gradient(135deg, #bd93f9, #ff79c6);
    color: #ffffff;
    border: none;
    padding: 0.75rem 2.5rem;
    font-size: 1.05rem;
    font-weight: 900;
    border-radius: 50px;
    cursor: pointer;
    font-family: 'sniglet', 'Arial Rounded MT Bold', 'Arial Black', Arial, sans-serif;
    text-shadow: 1px 1px 0 rgba(80, 0, 120, 0.4);
    transition: transform 0.15s;

    &:hover, &:active {
        transform: scale(1.06);
    }
}

@media (orientation: landscape) {
    #help-content {
        max-height: 85vh;
        padding: 1.2rem 1.5rem;
    }

    #help-content h2 {
        font-size: clamp(1.1rem, 4vh, 1.6rem);
        margin-bottom: 0.7rem;
    }

    .help-section {
        padding: 0.6rem 0.9rem;
        margin-bottom: 0.5rem;
    }
}
