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

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

:root {
    --background: rgb(247, 247, 247); /* slate-100-like */
    --foreground: rgb(13, 13, 13);    /* near-black */
    --accent: rgb(50, 178, 255);
    --bpm-tint: rgba(50, 178, 255, 0.12); /* light-blue fill for the bpm control */
    --desktop-background: rgba(127, 127, 127, 0.1);
    --stave-background: rgb(241, 241, 241);
    --stave-foreground: rgb(55, 55, 55);    /* dark gray */
    --font-mono: monospace;
    --app-padding: clamp(1rem, 5vw, 1.75rem);
    --footer-gap: clamp(0.75rem, 4vw, 1rem);
    --bbox-width: 844px;
    --bbox-height: 390px;
    --icon-button-size: clamp(2.75rem, 12vw, 3rem);
    --icon-size: 2rem;
    --bpm-font-size: clamp(1rem, 4vw, 1.125rem);
}

html, body {
    margin: 0;
    width: 100%;
    min-height: 100%;

    overflow: hidden;
    overscroll-behavior: none;
}

body {
    background: var(--background);
    color: var(--foreground);
    font-family: 'Geist Mono', monospace;
}

/* Small viewport: full screen with padding */
#app-bounds {
    padding: var(--app-padding);
    width: 100%;
    min-height: 100dvh;
    box-sizing: border-box;
    display: flex;
}

/* Large viewport: centered card */
@media (min-width: 1001px) and (min-height: 501px) {
    body {
        display: flex;
        align-items: center;
        justify-content: center;
        min-height: 100dvh;
        background-color: var(--desktop-background);
    }
    #app-bounds {
        width: var(--bbox-width);
        height: var(--bbox-height);
        min-height: initial;
        background-color: var(--background);
        border: 1px solid rgba(13, 13, 13, 0.3);
        border-radius: 0.5rem;
        box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    }
}

/* PORTRAIT PHONE LOCK */

.rotate-prompt {
    display: none; /* default hidden */
}

/*
    max widths:
    - 500px - blocks phones in portrait
    - 650px - blocks phones and 7-inch tablets in portrait
    - 800px - blocks phones, 7-inch tablets, and iPad Mini in portrait
*/
@media (orientation: portrait) and (max-width: 650px) {
    #app-bounds {
        display: none; /* hide app in portrait mode on small devices */
    }
    .rotate-prompt {
        display: flex; /* show rotate prompt */
        flex-direction: column;
        gap: 1rem;
        position: fixed;
        inset: 0;
        align-items: center;
        justify-content: center;
        padding: var(--app-padding);
        text-align: center;
        height: 100dvh;
        background: var(--background);
        color: rgba(13, 13, 13, 0.4);
    }
    .rotate-prompt-icon {
        font-size: 3rem;
        line-height: 1;
        display: inline-block;
        transform-origin: center;
        animation: rotate-phone 4s ease-in-out infinite;
    }
    @keyframes rotate-phone {
        0%, 20%     { transform: rotate(0deg); }
        50%, 70%    { transform: rotate(90deg); }
        100%        { transform: rotate(0deg); }
    }
}

/* APP LAYOUT */

.app-shell {
    width: 100%;
    flex: 1;
    display: flex;
    flex-direction: column;

    /* suppress mobile touch defaults (text selection, tap-highlight shade, 
       long-press callout) these inherit to all descendants. */
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    touch-action: none;
}

.main-viewport {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    flex: 1;
    width: 100%;
}

.main-viewport-spacer {
    min-height: 1px;
}

.app-footer {
    display: flex;
    justify-content: space-between;
}

.button-group {
    display: flex;
    gap: var(--footer-gap);
}

/* SCORE */

.score {
    display: block;
    width: 100%;
    --score-logical-width: 925;
    aspect-ratio: 786 / 102;
    height: auto;
    /*
    if we need to clamp score height:
    max-height: 6.25rem;
    min-height: 5rem;
    */
    background: var(--stave-background);
    position: relative;
    overflow-x: hidden;
}

@media (pointer: coarse) and (orientation: landscape) {
    .score {
        --score-logical-width: 800;
        aspect-ratio: 786 / 115;
    }
}

.score-track {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    display: flex;
    transform: translate3d(0, 0, 0);
    transform-origin: 0 0;
    will-change: transform;
}

.score-track canvas {
    display: block;
}

.score-cursor {
    position: absolute;
    top: 0;
    left: 0;
    width: 2px;
    height: 100%;
    z-index: 1;
    background: var(--accent);
    display: none;
    pointer-events: none;
    will-change: transform;
}

.score-cursor.paused {
    background: rgba(50, 178, 255, 0.4);
}

/* BUTTONS */

button {
    all: unset;
    cursor: default;
    /* manipulation drops the ~300ms double-tap-zoom wait so taps register fast.
       touch-action does not inherit, so it is set per element rather than on the
       shell. */
    touch-action: manipulation;
}

/* positioned, content-width container so things can hang off the right
   edge without shifting the centered bpm button */
bpm-tap {
    position: relative;
    display: inline-block;
}

/* tap or drag to set BPM; live fill track reflects the current value */
.bpm-button {
    font-size: var(--bpm-font-size);
    cursor: pointer;
    display: inline-block;
    position: relative;
    padding: 0.8rem 0.55rem 0.3rem;
    border-radius: 0.4rem;
    transition: background 0.12s;
    /* this control owns its drag gesture, so don't let touch pan/scroll it */
    touch-action: none;
}

/* light-blue tint while dragging (tap blink is animated in JS) */
.bpm-button.dragging {
    background: var(--bpm-tint);
}

/* ...and on hover, only for pointers that actually hover (not touch) */
@media (hover: hover) {
    .bpm-button:hover {
        background: var(--bpm-tint);
    }
}

/* sideways resize cursor while pressing/dragging */
.bpm-button:active {
    cursor: ew-resize;
}

.bpm-track {
    position: absolute;
    left: 0.4rem;
    right: 0.4rem;
    top: 0.35rem;
    height: 2px;
    border-radius: 2px;
    background: rgba(13, 13, 13, 0.075);
    overflow: hidden;
}

.bpm-track-fill {
    position: absolute;
    inset: 0 auto 0 0;
    width: 0%;
    background: var(--accent); /*rgba(13, 13, 13, 0.4);*/
}

/* "tap or drag" hint */
.bpm-hint {
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
    font-size: 0.75rem;
    color: rgba(13, 13, 13, 0.2);
    pointer-events: none;
    animation: bpm-hint-fade 5s forwards;
}

@keyframes bpm-hint-fade {
    0%, 90% { opacity: 1; }
    100% { opacity: 0; }
}

.icon-button {
    width: var(--icon-button-size);
    height: var(--icon-button-size);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;

    background: transparent;
    border-radius: 0.375rem;
}

.icon-button[aria-pressed="true"] {
    background: var(--accent);
}

.icon-button img {
    display: block;
    pointer-events: none;
}

.icon-button-img {
    width: var(--icon-size);
    height: var(--icon-size);
}

.icon-button[aria-pressed="true"] img {
    filter: brightness(0) invert(1);
}