:root {
    color-scheme: light;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: #f4f1e8;
    color: #171a1d;
    -webkit-tap-highlight-color: transparent;
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
    margin: 0;
    overscroll-behavior: none;
}

body {
    min-height: 100vh;
    min-height: 100dvh;
    overflow: hidden;
    background: #f4f1e8;
}

button,
a {
    font: inherit;
}

.tap-surface {
    position: relative;
    display: grid;
    grid-template-rows: auto 1fr auto;
    width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    padding: max(18px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(22px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    cursor: pointer;
    transition: background-color 100ms ease;
}

.tap-surface.is-tapping {
    background: #d9f35d;
}

.topbar {
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 44px;
}

.brand {
    color: #171a1d;
    font-size: 15px;
    font-weight: 750;
    text-decoration: none;
}

.reset-button {
    min-height: 44px;
    padding: 0 4px 0 16px;
    border: 0;
    background: transparent;
    color: #555b5f;
    cursor: pointer;
}

.reset-button:focus-visible,
.brand:focus-visible {
    outline: 3px solid #126e82;
    outline-offset: 4px;
}

.last-result[hidden] {
    display: none;
}

.last-result {
    position: absolute;
    top: max(72px, calc(env(safe-area-inset-top) + 54px));
    right: max(20px, env(safe-area-inset-right));
    z-index: 2;
    display: grid;
    gap: 3px;
    padding: 9px 11px;
    border: 1px solid #c7c4bc;
    border-radius: 4px;
    background: #ece9e1;
    text-align: right;
}

.last-result span {
    color: #686d70;
    font-size: 11px;
}

.last-result strong {
    font-size: 14px;
    font-variant-numeric: tabular-nums;
}

.readout {
    align-self: center;
    text-align: center;
    transform: translateY(-2vh);
}

.eyebrow {
    margin: 0 0 16px;
    color: #126e82;
    font-size: 14px;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

.bpm-value {
    min-height: 0.92em;
    font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
    font-size: 74px;
    font-weight: 800;
    line-height: 0.84;
    font-variant-numeric: tabular-nums;
}

.unit {
    margin: 14px 0 34px;
    color: #42484c;
    font-size: 18px;
    font-weight: 800;
}

.prompt {
    margin: 0;
    color: #555b5f;
    font-size: 17px;
}

.stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    border-top: 1px solid #c7c4bc;
}

.stats div {
    display: grid;
    gap: 5px;
    padding-top: 16px;
}

.stats div:last-child {
    text-align: right;
}

.stats span {
    color: #686d70;
    font-size: 13px;
}

.stats strong {
    font-size: 18px;
    font-variant-numeric: tabular-nums;
}

@media (min-width: 600px) {
    .bpm-value {
        font-size: 130px;
    }
}

@media (max-height: 560px) {
    .bpm-value {
        font-size: 64px;
    }

    .unit {
        margin-bottom: 18px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .tap-surface {
        transition: none;
    }
}

@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;
        background: #151719;
        color: #f7f4eb;
    }

    body,
    .tap-surface {
        background: #151719;
    }

    .tap-surface.is-tapping {
        background: #26311e;
    }

    .brand {
        color: #f7f4eb;
    }

    .last-result {
        border-color: #3d4143;
        background: #202426;
    }

    .last-result span {
        color: #b4b7b8;
    }

    .reset-button,
    .prompt,
    .stats span {
        color: #b4b7b8;
    }

    .unit {
        color: #d3d4d1;
    }

    .eyebrow {
        color: #77d6df;
    }

    .stats {
        border-color: #3d4143;
    }
}

.offline-state {
    display: inline-flex;
    min-height: 28px;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    border: 1px solid #c7c4bc;
    border-radius: 4px;
    background: #ece9e1;
    color: #5b6265;
    font-size: 11px;
    font-weight: 750;
    white-space: nowrap;
}

.offline-state::before {
    width: 7px;
    height: 7px;
    flex: none;
    border-radius: 50%;
    background: #d29b31;
    content: "";
}

.offline-state[data-state="ready"]::before {
    background: #2d8a59;
}

.offline-state[data-state="error"]::before {
    background: #b4423d;
}

@media (max-width: 390px) {
    .offline-state {
        max-width: 105px;
        white-space: normal;
        text-align: center;
    }
}

@media (prefers-color-scheme: dark) {
    .offline-state {
        border-color: #3d4143;
        background: #202426;
        color: #d3d4d1;
    }
}
