:root {
    color-scheme: dark;
    --theme-color: #152238;
    --bg-a: #07111f;
    --bg-b: #102c46;
    --bg-c: #073d48;
    --text: #effdff;
    --muted: #9edce3;
    --accent: #4ef2f8;
    --accent-text: #041315;
    --surface: rgb(6 25 39 / 58%);
    --line: rgb(126 246 255 / 28%);
    --display-font: "Arial Narrow", "Bahnschrift Condensed", "Segoe UI", sans-serif;
    --body-font: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    --timer-font: "Bahnschrift", "Arial Narrow", "Segoe UI", sans-serif;
    --button-radius: 0.35rem;
    --letter-spacing: 0.055em;
}

:root[data-theme="cozy"] {
    color-scheme: light;
    --theme-color: #8f5a3b;
    --bg-a: #f7e8cf;
    --bg-b: #e7b989;
    --bg-c: #bf795d;
    --text: #42281e;
    --muted: #704b3a;
    --accent: #7b3f2d;
    --accent-text: #fff8ec;
    --surface: rgb(255 249 235 / 45%);
    --line: rgb(86 47 33 / 23%);
    --display-font: Georgia, "Times New Roman", serif;
    --body-font: "Trebuchet MS", "Segoe UI", sans-serif;
    --timer-font: Georgia, "Times New Roman", serif;
    --button-radius: 2rem;
    --letter-spacing: -0.035em;
}

:root[data-theme="minimal"] {
    color-scheme: light;
    --theme-color: #e9e8e3;
    --bg-a: #f7f7f3;
    --bg-b: #e3e3dd;
    --bg-c: #f1eee7;
    --text: #181a19;
    --muted: #626762;
    --accent: #202421;
    --accent-text: #ffffff;
    --surface: rgb(255 255 255 / 32%);
    --line: rgb(20 24 21 / 18%);
    --display-font: Arial, Helvetica, sans-serif;
    --body-font: Arial, Helvetica, sans-serif;
    --timer-font: "Arial Narrow", "Roboto Condensed", Arial, sans-serif;
    --button-radius: 0;
    --letter-spacing: -0.055em;
}

:root[data-theme="playful"] {
    color-scheme: dark;
    --theme-color: #7639c6;
    --bg-a: #512da8;
    --bg-b: #e83e8c;
    --bg-c: #ef7b32;
    --text: #fffdf2;
    --muted: #ffe3ad;
    --accent: #fff267;
    --accent-text: #382146;
    --surface: rgb(83 20 112 / 30%);
    --line: rgb(255 255 255 / 30%);
    --display-font: "Trebuchet MS", "Arial Rounded MT Bold", sans-serif;
    --body-font: "Trebuchet MS", "Segoe UI", sans-serif;
    --timer-font: "Arial Rounded MT Bold", "Trebuchet MS", sans-serif;
    --button-radius: 1.25rem;
    --letter-spacing: -0.05em;
}

:root[data-theme="botanical"] {
    color-scheme: dark;
    --theme-color: #244a37;
    --bg-a: #102b22;
    --bg-b: #315d42;
    --bg-c: #728f65;
    --text: #f1f3df;
    --muted: #c9d8b6;
    --accent: #dce6a5;
    --accent-text: #173326;
    --surface: rgb(13 47 34 / 43%);
    --line: rgb(220 230 165 / 26%);
    --display-font: Georgia, "Times New Roman", serif;
    --body-font: "Segoe UI", system-ui, sans-serif;
    --timer-font: Georgia, "Times New Roman", serif;
    --button-radius: 50% 35% 50% 35% / 35% 50% 35% 50%;
    --letter-spacing: -0.04em;
}

:root[data-theme="retro"] {
    color-scheme: light;
    --theme-color: #c45536;
    --bg-a: #f3c56f;
    --bg-b: #df7954;
    --bg-c: #88a889;
    --text: #392c2a;
    --muted: #65433b;
    --accent: #244b47;
    --accent-text: #fff2c9;
    --surface: rgb(255 235 181 / 34%);
    --line: rgb(57 44 42 / 25%);
    --display-font: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif;
    --body-font: "Courier New", Courier, monospace;
    --timer-font: "Courier New", Courier, monospace;
    --button-radius: 0.2rem;
    --letter-spacing: -0.065em;
}

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

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

body {
    overflow-x: hidden;
    color: var(--text);
    background: var(--bg-a);
    font-family: var(--body-font);
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible {
    outline: 3px solid var(--text);
    outline-offset: 4px;
}

.app-shell {
    position: relative;
    isolation: isolate;
    display: grid;
    min-height: 100vh;
    min-height: 100svh;
    padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
    overflow: hidden;
    background:
        radial-gradient(circle at 16% 18%, color-mix(in srgb, var(--accent) 19%, transparent), transparent 32%),
        linear-gradient(125deg, var(--bg-a), var(--bg-b), var(--bg-c), var(--bg-a));
    background-size: 100% 100%, 300% 300%;
    animation: ambient-shift 24s ease-in-out infinite alternate;
}

.app-shell::before,
.app-shell::after {
    position: absolute;
    z-index: -1;
    width: min(44vw, 32rem);
    aspect-ratio: 1;
    content: "";
    border: 1px solid var(--line);
    border-radius: 50%;
    opacity: 0.42;
}

.app-shell::before {
    top: -22vw;
    right: -10vw;
}

.app-shell::after {
    bottom: -28vw;
    left: -11vw;
    width: min(55vw, 42rem);
}

.utility-controls {
    position: absolute;
    z-index: 20;
    top: max(0.8rem, env(safe-area-inset-top));
    right: max(0.8rem, env(safe-area-inset-right));
    display: flex;
    gap: 0.35rem;
}

.icon-button {
    display: grid;
    width: 2.75rem;
    height: 2.75rem;
    padding: 0;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 50%;
    cursor: pointer;
    font: inherit;
    font-size: 1.2rem;
    opacity: 0.72;
    place-items: center;
    transition: opacity 180ms ease, transform 180ms ease, background-color 180ms ease;
}

.icon-button:hover {
    background: color-mix(in srgb, var(--surface), var(--text) 12%);
    opacity: 1;
    transform: translateY(-1px);
}

.timer-stage,
.progress-stage {
    width: min(100%, 96rem);
    margin: auto;
    text-align: center;
}

.timer-stage {
    display: grid;
    justify-items: center;
    align-content: center;
    min-height: calc(100svh - 2rem);
    padding: clamp(3.75rem, 8vh, 6rem) 0 clamp(1rem, 3vh, 2rem);
}

.eyebrow {
    margin: 0 0 clamp(0.65rem, 2vh, 1.5rem);
    color: var(--muted);
    font-size: clamp(0.68rem, 1.2vw, 0.9rem);
    font-weight: 700;
    letter-spacing: 0.22em;
    text-transform: uppercase;
}

h1 {
    max-width: 95vw;
    margin: 0;
    font-family: var(--display-font);
    font-size: clamp(2rem, 6vw, 6rem);
    font-weight: 700;
    line-height: 0.98;
    text-wrap: balance;
}

.timer {
    margin: clamp(1rem, 4vh, 3rem) 0 clamp(0.5rem, 1.7vh, 1.25rem);
    font-family: var(--timer-font);
    font-size: clamp(5.2rem, 24vw, 22rem);
    font-variant-numeric: tabular-nums lining-nums;
    font-weight: 700;
    letter-spacing: var(--letter-spacing);
    line-height: 0.82;
    text-shadow: 0 0 1.5em color-mix(in srgb, var(--accent) 28%, transparent);
    white-space: nowrap;
}

.timer-hint {
    margin: 0 0 clamp(1.2rem, 4vh, 2.5rem);
    color: var(--muted);
    font-size: clamp(0.85rem, 1.5vw, 1.1rem);
}

.primary-action {
    min-height: 3.1rem;
    padding: 0.85rem 1.5rem;
    color: var(--accent-text);
    background: var(--accent);
    border: 2px solid transparent;
    border-radius: var(--button-radius);
    box-shadow: 0 0.5rem 2rem rgb(0 0 0 / 13%);
    cursor: pointer;
    font: 700 clamp(0.95rem, 1.6vw, 1.1rem)/1 var(--body-font);
    transition: filter 160ms ease, transform 160ms ease;
}

.primary-action:hover {
    filter: brightness(1.08);
    transform: translateY(-2px);
}

.primary-action:disabled {
    cursor: wait;
    opacity: 0.6;
}

.celebration {
    position: fixed;
    z-index: 10;
    inset: 0;
    display: grid;
    visibility: hidden;
    pointer-events: none;
    opacity: 0;
    place-items: center;
    transition: opacity 300ms ease, visibility 300ms ease;
}

.celebration.is-visible {
    visibility: visible;
    opacity: 1;
}

.celebration-message {
    z-index: 2;
    display: grid;
    width: min(88vw, 36rem);
    padding: clamp(1.4rem, 4vw, 2.6rem);
    color: var(--text);
    background: color-mix(in srgb, var(--bg-a) 88%, transparent);
    border: 1px solid var(--line);
    border-radius: 1.25rem;
    box-shadow: 0 1.5rem 5rem rgb(0 0 0 / 30%);
    backdrop-filter: blur(14px);
    text-align: center;
    gap: 0.5rem;
}

.celebration-message strong {
    font-family: var(--display-font);
    font-size: clamp(2.2rem, 8vw, 5.5rem);
    line-height: 1;
}

.celebration-mark {
    color: var(--accent);
    font-size: 2rem;
}

.confetti-layer,
.confetti-layer i {
    position: absolute;
}

.confetti-layer {
    inset: 0;
    overflow: hidden;
}

.confetti-layer i {
    top: -2rem;
    left: var(--x);
    width: 0.65rem;
    height: 1rem;
    border-radius: 2px;
    animation: confetti-fall var(--fall) var(--delay) ease-in forwards;
}

.progress-stage {
    align-self: center;
    padding: clamp(4rem, 10vh, 7rem) 0 2rem;
}

.session-summary {
    margin: clamp(1rem, 3vh, 2rem) auto clamp(1.5rem, 5vh, 3.5rem);
    color: var(--muted);
    font-size: clamp(1rem, 2.5vw, 1.5rem);
}

.session-summary strong {
    color: var(--text);
}

.progress-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    width: min(100%, 72rem);
    margin: 0 auto clamp(2rem, 6vh, 4rem);
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
}

.progress-stats div {
    min-width: 0;
    padding: clamp(1rem, 3vw, 2rem) clamp(0.5rem, 2vw, 1.5rem);
}

.progress-stats div + div {
    border-left: 1px solid var(--line);
}

.progress-stats dt {
    margin-bottom: 0.65rem;
    color: var(--muted);
    font-size: clamp(0.68rem, 1.4vw, 0.85rem);
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.progress-stats dd {
    margin: 0;
    overflow-wrap: anywhere;
    font-family: var(--display-font);
    font-size: clamp(1.15rem, 3vw, 2.4rem);
    font-variant-numeric: tabular-nums;
    font-weight: 700;
}

.action-link {
    display: inline-grid;
    text-decoration: none;
    place-items: center;
}

@keyframes ambient-shift {
    from { background-position: center, 0% 50%; }
    to { background-position: center, 100% 50%; }
}

@keyframes confetti-fall {
    0% { opacity: 0; transform: translate3d(0, -5vh, 0) rotate(0); }
    8% { opacity: 1; }
    100% { opacity: 0.9; transform: translate3d(-5vw, 110vh, 0) rotate(var(--turn)); }
}

@media (max-width: 44rem) {
    .progress-stats {
        grid-template-columns: repeat(2, 1fr);
    }

    .progress-stats div + div {
        border-left: 0;
    }

    .progress-stats div:nth-child(even) {
        border-left: 1px solid var(--line);
    }

    .progress-stats div:nth-child(n + 3) {
        border-top: 1px solid var(--line);
    }
}

@media (orientation: landscape) and (max-height: 34rem) {
    .timer-stage {
        grid-template-columns: 1fr auto;
        grid-template-rows: auto auto auto;
        column-gap: 4vw;
        padding-block: 2.8rem 0.5rem;
        text-align: left;
    }

    .timer-stage .eyebrow,
    .timer-stage h1,
    .timer-stage .timer-hint {
        justify-self: start;
    }

    .timer-stage .eyebrow {
        align-self: end;
        margin-bottom: 0.45rem;
    }

    .timer-stage h1 {
        align-self: start;
        grid-row: 2;
        font-size: clamp(1.8rem, 6vw, 4rem);
    }

    .timer {
        grid-column: 2;
        grid-row: 1 / 3;
        align-self: center;
        margin: 0;
        font-size: clamp(5rem, 22vw, 12rem);
    }

    .timer-hint {
        grid-column: 1;
        grid-row: 3;
        margin: 0;
    }

    .timer-stage .primary-action {
        grid-column: 2;
        grid-row: 3;
        justify-self: center;
    }
}

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

