/*
    BREATHING TIMER

    Markup: src/includes/breathing-timer.njk, behaviour: breathing-timer.N.js.
    Uses the --pf-* tokens of the site-wide "modern shell" in index.NN.css.
    The deploy caches this file for a year: bump N in its name (and in the
    include) whenever it changes.
*/

.breathing-timer {
    --bt-ink: var(--text-color-light);
    --bt-muted: #77746f;
    --bt-button-bg: rgba(255, 255, 255, 0.75);
    --bt-button-bg-hover: #fff;
    --bt-line: var(--pf-line);
    --bt-track: rgba(49, 48, 48, 0.12);
    --bt-blob: rgba(249, 212, 119, 0.55);
    --bt-blob-edge: rgba(254, 190, 22, 0.55);

    max-width: 640px;
    margin: 30px auto 0;
    font-family: var(--pf-font);
    font-weight: 400;
    letter-spacing: normal;
    color: var(--bt-ink);
}

body.dark .breathing-timer {
    --bt-ink: var(--text-color-dark);
    --bt-muted: rgba(255, 255, 255, 0.62);
    --bt-button-bg: rgba(255, 255, 255, 0.08);
    --bt-button-bg-hover: rgba(255, 255, 255, 0.16);
    --bt-line: var(--pf-line-dark);
    --bt-track: rgba(255, 255, 255, 0.16);
    --bt-blob: rgba(249, 212, 119, 0.32);
    --bt-blob-edge: rgba(254, 190, 22, 0.5);
}

.breathing-timer__card {
    padding: 22px 26px 20px;
    border: 1px solid var(--bt-line);
    border-radius: 18px;
    background: var(--pf-surface);
    box-shadow: var(--pf-shadow-card), var(--pf-inset);
}

/* pattern picker */

.breathing-timer__patterns {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.breathing-timer__pattern {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 10px 6px;
    border: 1.5px solid var(--bt-line);
    border-radius: 14px;
    background: transparent;
    color: inherit;
    font: inherit;
    cursor: pointer;
    transition: background-color 0.2s, border-color 0.2s;
}

.breathing-timer__pattern:hover {
    border-color: var(--pf-primary-deep);
    background-color: rgba(255, 212, 101, 0.15);
}

.breathing-timer__pattern[aria-pressed="true"] {
    border-color: var(--pf-primary-deep);
    background-color: var(--pf-primary);
    color: var(--pf-ink);
}

.breathing-timer__pattern-name {
    font-size: 15px;
    font-weight: 600;
}

.breathing-timer__pattern-use {
    font-size: 13px;
    opacity: 0.75;
}

.breathing-timer__about {
    display: block;
    min-height: 3em;
    margin-top: 14px;
    color: var(--bt-muted);
    font-size: 15px;
    line-height: 1.5;
    text-align: center;
}

/* the pacer */

.breathing-timer__stage {
    position: relative;
    width: min(100%, 300px);
    margin: 8px auto 0;
    aspect-ratio: 1;
}

.breathing-timer__visual {
    display: block;
    width: 100%;
    height: 100%;
    overflow: visible;
}

.breathing-timer__blob {
    fill: var(--bt-blob);
    stroke: var(--bt-blob-edge);
    stroke-width: 1.5;
}

.breathing-timer__track,
.breathing-timer__trail {
    fill: none;
    stroke-width: 6;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.breathing-timer__track {
    stroke: var(--bt-track);
}

.breathing-timer__trail {
    stroke: var(--pf-primary-deep);
    opacity: 0;
    transition: opacity 0.3s;
}

.is-running .breathing-timer__trail,
.is-paused .breathing-timer__trail {
    opacity: 1;
}

.breathing-timer__ticks circle {
    fill: var(--bt-ink);
    opacity: 0.35;
}

.breathing-timer__dot {
    fill: var(--pf-ink);
    stroke: #fff;
    stroke-width: 3;
}

body.dark .breathing-timer__dot {
    fill: var(--pf-primary);
    stroke: var(--pf-ink);
}

.breathing-timer__readout {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    text-align: center;
}

.breathing-timer__phase {
    font-size: 20px;
    font-weight: 600;
}

.breathing-timer__count {
    min-height: 1.15em;
    font-size: 40px;
    font-weight: 600;
    line-height: 1.15;
    font-variant-numeric: tabular-nums;
}

.is-finished .breathing-timer__count {
    font-size: 17px;
    font-weight: 500;
    color: var(--bt-muted);
}

/* session length + time left */

.breathing-timer__bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px 20px;
    margin-top: 10px;
}

.breathing-timer__chips {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.breathing-timer__chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0.35rem 0.95rem;
    border: 1.5px solid var(--bt-line);
    border-radius: 2rem;
    background: transparent;
    color: inherit;
    font: inherit;
    font-size: 15px;
    cursor: pointer;
    transition: background-color 0.2s, border-color 0.2s;
}

.breathing-timer__chip:hover {
    border-color: var(--pf-primary-deep);
    background-color: rgba(255, 212, 101, 0.15);
}

.breathing-timer__chip[aria-pressed="true"] {
    border-color: var(--pf-primary-deep);
    background-color: var(--pf-primary);
    color: var(--pf-ink);
    font-weight: 500;
}

.breathing-timer__remaining {
    font-size: 26px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* start / stop */

.breathing-timer__controls {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 18px;
}

.breathing-timer__button {
    min-width: 120px;
    padding: 11px 22px;
    border: 1px solid var(--bt-line);
    border-radius: 999px;
    background: var(--bt-button-bg);
    color: inherit;
    font: inherit;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: transform 0.2s var(--pf-ease-spring), background-color 0.2s, opacity 0.2s;
}

.breathing-timer__button:hover:not(:disabled) {
    background: var(--bt-button-bg-hover);
    transform: translateY(-1px);
}

.breathing-timer__button:disabled {
    opacity: 0.4;
    cursor: default;
}

.breathing-timer__button--primary,
.breathing-timer__button--primary:hover:not(:disabled) {
    border-color: transparent;
    background: var(--pf-primary);
    color: var(--pf-ink);
    font-weight: 600;
    box-shadow: 0 10px 22px -10px rgba(254, 190, 22, 0.7);
}

/* pace + sound */

.breathing-timer__options {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 10px 18px;
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--bt-line);
}

.breathing-timer__chips--small .breathing-timer__chip,
.breathing-timer__sound {
    padding: 0.25rem 0.75rem;
    font-size: 14px;
}

.breathing-timer__option-label {
    color: var(--bt-muted);
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.breathing-timer__sound[aria-pressed="false"] .breathing-timer__sound-waves {
    opacity: 0.25;
}

/* while a session runs, the settings step back */
.is-running .breathing-timer__patterns,
.is-running .breathing-timer__bar .breathing-timer__chips,
.is-running .breathing-timer__options {
    opacity: 0.35;
    transition: opacity 0.3s;
}

.is-running .breathing-timer__patterns:hover,
.is-running .breathing-timer__bar .breathing-timer__chips:hover,
.is-running .breathing-timer__options:hover,
.is-running .breathing-timer__patterns:focus-within,
.is-running .breathing-timer__bar .breathing-timer__chips:focus-within,
.is-running .breathing-timer__options:focus-within {
    opacity: 1;
}

/* under the card */

.breathing-timer__tip {
    display: block;
    margin-top: 12px;
    color: var(--bt-muted);
    font-size: 14px;
    text-align: center;
}

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

@media (max-width: 680px) {
    .breathing-timer {
        margin-top: 24px;
    }

    .breathing-timer__card {
        padding: 16px 14px 18px;
    }

    .breathing-timer__patterns {
        grid-template-columns: repeat(2, 1fr);
    }

    .breathing-timer__bar {
        justify-content: center;
    }
}

@media (prefers-reduced-motion: reduce) {
    .breathing-timer__button,
    .breathing-timer__trail {
        transition: none;
    }
}
