/*! loum.io · © 2025–2026 Louie Sellers · All rights reserved · Original at https://loum.io */
/* BPM v1 */

:root {
    --bg: #121211;
    --raise: #1a1a19;
    --raise-2: #222220;
    --line: #2a2a28;
    --line-strong: #3a3a37;
    --text: #e9e7e2;
    --muted: #9a978f;
    --faint: #6b6963;
    --accent: #ff7a3d;
    --font: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
    --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
    --spring: cubic-bezier(0.34, 1.4, 0.64, 1);
}

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

/* Reserve the scrollbar's space on every page, so content sits at the same width and position whether or not the page scrolls */
html { -webkit-text-size-adjust: 100%; scrollbar-gutter: stable; }

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 13px;
    line-height: 1.5;
    font-variant-numeric: tabular-nums;
    -webkit-font-smoothing: antialiased;
    /* Taps register at once: no double-tap zoom, so no wait for a click */
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; }

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

.app-container {
    display: flex;
    flex-direction: column;
    max-width: 1120px;
    min-height: 100vh;
    min-height: 100svh;
    margin: 0 auto;
    padding: 20px 32px 32px;
}

/* Header */
.header-section {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 16px;
    padding-bottom: 20px;
    margin-bottom: 28px;
    border-bottom: 1px solid var(--line);
}

.crumbs {
    display: flex;
    align-items: baseline;
    gap: 10px;
}

.home-link {
    color: var(--muted);
    text-decoration: none;
    transition: color 160ms var(--ease-out);
}

@media (hover: hover) { .home-link:hover { color: var(--text); } }

.crumb-sep { color: var(--faint); }

.header-section h1 {
    margin: 0;
    font-size: 13px;
    font-weight: 500;
}

.header-note {
    margin: 0;
    color: var(--faint);
}

/* The whole page is the tap surface. Nothing on it should select or get a callout. */
.bpm-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    cursor: default;
}

/* The reading sits centred in the space below the header; the secondary block hangs at the bottom.
   On a short screen the lead gives way first, then the page grows. */
.lead { flex: 1; }

.tail {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    width: 100%;
    padding-top: 32px;
}

/* The reading */
.stage {
    display: grid;
    justify-items: center;
    width: 100%;
}

.readout {
    display: grid;
    place-items: center;
    max-width: 100%;
}

/* The hint and the number share one cell, so the swap doesn't move anything */
.hint,
.reading { grid-area: 1 / 1; }

.hint {
    margin: 0;
    font-size: 16px;
    color: var(--muted);
    transition: opacity 240ms var(--ease-out);
}

.hint-touch { display: none; }

@media (hover: none) and (pointer: coarse) {
    .hint-key { display: none; }
    .hint-touch { display: inline; }
}

/* After the first tap the line changes where it is; the number then takes over the same spot */
.hint-next { display: none; }

body.started .hint-key,
body.started .hint-touch { display: none; }

body.started .hint-next { display: inline; }

body.has-result .hint { opacity: 0; }

.reading {
    font-size: clamp(72px, 28vw, 320px);
    font-size: round(clamp(72px, min(28vw, 36vh), 320px), 4px);
    font-weight: 500;
    line-height: 1;
    letter-spacing: -0.035em;
    white-space: nowrap;
    opacity: 0;
    transform: scale(0.97);
    transition: opacity 320ms var(--ease-out), transform 560ms var(--spring), color 320ms var(--ease-out);
}

body.has-result .reading {
    opacity: 1;
    transform: none;
}

/* A new count has begun: the last result stays, but steps back */
.reading.stale { color: var(--faint); }

/* The decimal firms up as the taps settle: --settle runs 0 to 1 from the script */
.decimal {
    opacity: calc(0.2 + 0.8 * var(--settle, 0));
    transition: opacity 400ms var(--ease-out);
}

.reading.stale .decimal { opacity: 0.2; }

.unit-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
    color: var(--muted);
    opacity: 0;
    transition: opacity 320ms var(--ease-out);
}

body.has-result .unit-row { opacity: 1; }

/* The pulse: a plain dot that lights on each beat (the flash itself runs from the script) */
.pulse-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--line-strong);
}

.taps { color: var(--faint); }

.taps:empty { display: none; }

.taps:not(:empty)::before {
    content: "·";
    margin-right: 10px;
}

/* Controls: only there once there is a reading */
.tail > * {
    opacity: 0;
    visibility: hidden;
    transition: opacity 400ms var(--ease-out), visibility 0s 400ms;
}

body.has-result .tail > * {
    opacity: 1;
    visibility: visible;
    transition: opacity 400ms var(--ease-out) 80ms, visibility 0s;
}

.controls-row {
    display: flex;
    justify-content: center;
    gap: 24px;
    flex-wrap: wrap;
}

.control-group {
    display: flex;
    gap: 8px;
}

button {
    min-width: 48px;
    padding: 7px 14px;
    border: 1px solid var(--line-strong);
    border-radius: 4px;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    white-space: nowrap;
    transition: background-color 140ms var(--ease-out), border-color 140ms var(--ease-out), color 140ms var(--ease-out), transform 160ms var(--spring);
}

@media (hover: hover) { button:hover { background: var(--raise-2); } }

button:active { transform: scale(0.97); }

button[aria-pressed="true"] {
    border-color: var(--accent);
    background: rgba(255, 122, 61, 0.12);
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 1ms !important;
        transition-duration: 1ms !important;
    }

    .reading { transform: none; }
}

@media (max-width: 700px) {
    .app-container { padding: 16px 16px 24px; }

    .header-section {
        flex-direction: column;
        gap: 4px;
        margin-bottom: 20px;
        padding-bottom: 16px;
    }

    /* Comfortable tap targets */
    .home-link {
        display: inline-block;
        padding: 10px 6px 10px 0;
        margin: -10px 0;
    }

    button {
        min-height: 44px;
        min-width: 56px;
    }
}

/* A phone on its side: tighter vertical rhythm so it still fits */
@media (max-height: 500px) {
    .app-container { padding-top: 16px; padding-bottom: 16px; }

    .header-section {
        margin-bottom: 12px;
        padding-bottom: 12px;
    }

    .tail { padding-top: 16px; }

}
