/*
    The browser app's host page styles (requirements §5.11, §2.9; ADR 0026). The same boot surface and error bar as
    the phone app's host page, without the iOS status-bar reserve a browser does not need.

    This file styles only what exists before Blazor renders and what Blazor itself owns: the boot surface and
    the error bar. Everything about the application's appearance belongs to the RCL's MudBlazor theme;
    page-level overrides of component internals are a review defect.

    Colours are duplicated here on purpose. The theme lives in .NET and is not available to the page until
    the first render, which is the exact moment this file stops mattering.
*/

:root {
    --app-boot-background: #075e54;
    --app-boot-scene-top: #0a4a42;
    --app-boot-deep: #062b26;
    --app-boot-deep-rgb: 6, 43, 38;
    --app-boot-brand-start: 0, 128, 105;
    --app-boot-brand-start-hex: #008069;
    --app-boot-brand-end: 7, 94, 84;
    --app-boot-brand-end-hex: #075e54;
    --app-boot-brand-glow: 37, 211, 102;
    --app-boot-brand-accent: #25d366;
    --app-boot-highlight: #8cf5b5;
    --app-boot-on: #ffffff;
    --app-boot-on-rgb: 255, 255, 255;
    --app-boot-wave-1: #07332d;
    --app-boot-wave-2: #094138;
    --app-boot-wave-3: #0b4f44;
    --app-boot-wave-4: #0e5d50;
    --app-boot-ease: cubic-bezier(0.2, 0.8, 0.2, 1);
    --app-boot-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

/* The shell is a chain of percentage heights: mud-layout asks for 100% of its parent, so every element
   between the document root and the layout has to answer with a real height or the drawer's fixed
   positioning and the sticky app bar have nothing to resolve against. */
#app {
    height: 100%;
}

/* §5.2: the page is the brand's teal only while the splash is on it. Once the splash has gone this rule no longer
   matches and MudBlazor's own `body { background: var(--mud-palette-background) }` takes over, which follows the
   app's theme setting rather than the operating system's. */
body:has(.app-splash) {
    background-color: var(--app-boot-background);
}
/* ---------------------------------------------------------------------------------------------------------
   The splash (§5.2, ADR 0027, ADR 0037).

   Its first frame is the platform's: the brand's teal, the colour the csproj paints behind the platform splash. From
   there the scene lights up and beams of light streak across its sky like headlights on a night road, four layers of
   waves rise and drift at different speeds, the mark arrives and its road draws itself - from home, along the S - to the
   bright green arrival, the wordmark slides in and a sheen crosses the tile. While the
   app is still starting, a light keeps driving the road and the arrival dot pings each time it gets there, the "Go"
   catches the light, and the hairline bar underneath fills as the browser app's files arrive (the phone app's files
   are local, so its bar only shimmers).
   --------------------------------------------------------------------------------------------------------- */
.app-splash {
    position: fixed;
    inset: 0;
    z-index: 2000;
    overflow: hidden;
    background-color: var(--app-boot-background);
    -webkit-user-select: none;
    user-select: none;
}

.app-splash-scene {
    position: absolute;
    inset: 0;
    background:
        radial-gradient(130% 70% at 50% 44%, rgba(var(--app-boot-brand-start), 0.42) 0%, rgba(var(--app-boot-brand-end), 0.2) 40%, transparent 72%),
        radial-gradient(60% 40% at 85% 8%, rgba(var(--app-boot-brand-glow), 0.14), transparent 70%),
        linear-gradient(180deg, var(--app-boot-scene-top) 0%, var(--app-boot-deep) 62%);
    animation: app-splash-fade-in 700ms ease-out both;
}

/* Headlights on a night road: thin beams of the brand's glow crossing the sky at different heights and speeds. */
.app-splash-streaks {
    position: absolute;
    inset: 0 0 auto;
    height: 64%;
    overflow: hidden;
    pointer-events: none;
}

.app-splash-streaks i {
    position: absolute;
    left: 0;
    width: 34vw;
    max-width: 420px;
    height: 2px;
    border-radius: 999px;
    background: linear-gradient(90deg, transparent, rgba(var(--app-boot-brand-glow), 0.5) 70%, rgba(var(--app-boot-on-rgb), 0.9));
    filter: drop-shadow(0 0 6px rgba(var(--app-boot-brand-glow), 0.7));
    opacity: 0;
    animation: app-splash-streak 2600ms cubic-bezier(0.45, 0, 0.25, 1) infinite;
}

.app-splash-streaks i:nth-child(1) {
    top: 16%;
    animation-delay: 400ms;
}

.app-splash-streaks i:nth-child(2) {
    top: 30%;
    width: 24vw;
    animation-duration: 3300ms;
    animation-delay: 1250ms;
}

.app-splash-streaks i:nth-child(3) {
    top: 7%;
    width: 18vw;
    animation-duration: 3900ms;
    animation-delay: 2100ms;
}

.app-splash-streaks i:nth-child(4) {
    top: 44%;
    width: 28vw;
    animation-duration: 3000ms;
    animation-delay: 850ms;
}

.app-splash-waves {
    position: absolute;
    inset: auto 0 0;
    height: min(34vh, 320px);
}

/* Each layer rises into place once, then drifts: the rise is on the layer, the drift on its drawing, so the two
   transforms never fight. Drawings are twice the screen's width and repeat halfway along. */
.app-splash-rise {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    animation: app-splash-rise 1100ms var(--app-boot-ease) both;
}

.app-splash-wave {
    display: block;
    width: 200%;
    height: 100%;
    animation: app-splash-drift linear infinite;
}

.app-splash-rise--1 {
    height: 100%;
}

.app-splash-rise--1 .app-splash-wave {
    animation-duration: 26s;
}

.app-splash-rise--2 {
    height: 80%;
    animation-delay: 110ms;
}

.app-splash-rise--2 .app-splash-wave {
    animation-duration: 19s;
    animation-direction: reverse;
}

.app-splash-rise--3 {
    height: 58%;
    animation-delay: 220ms;
}

.app-splash-rise--3 .app-splash-wave {
    animation-duration: 14s;
}

.app-splash-rise--4 {
    height: 36%;
    animation-delay: 330ms;
}

.app-splash-rise--4 .app-splash-wave {
    animation-duration: 10s;
    animation-direction: reverse;
}

.app-splash-rise--1 .app-splash-fill {
    fill: var(--app-boot-wave-1);
}

.app-splash-rise--2 .app-splash-fill {
    fill: var(--app-boot-wave-2);
}

.app-splash-rise--3 .app-splash-fill {
    fill: var(--app-boot-wave-3);
}

.app-splash-rise--4 .app-splash-fill {
    fill: var(--app-boot-wave-4);
}

.app-splash-crest {
    fill: none;
    stroke: rgba(var(--app-boot-brand-glow), 0.45);
    stroke-width: 2;
    vector-effect: non-scaling-stroke;
}

.app-splash-rise--4 .app-splash-crest {
    stroke: rgba(var(--app-boot-on-rgb), 0.3);
    stroke-width: 1.5;
}

/* The tile, centred, with a soft halo of the brand's glow behind it. */
.app-splash-center {
    position: absolute;
    left: 50%;
    top: 46%;
    width: 128px;
    height: 128px;
    margin: -64px 0 0 -64px;
}

.app-splash-halo {
    position: absolute;
    inset: -64px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(var(--app-boot-brand-glow), 0.32), transparent 64%);
    animation:
        app-splash-fade-in 900ms ease-out 200ms both,
        app-splash-pulse 2800ms ease-in-out 1100ms infinite;
}

.app-splash-lift,
.app-splash-float {
    position: absolute;
    inset: 0;
}

.app-splash-lift {
    animation: app-splash-arrive 700ms var(--app-boot-ease) both;
}

.app-splash-float {
    animation: app-splash-float 3400ms ease-in-out 1200ms infinite;
}

.app-splash-mark {
    display: block;
    width: 128px;
    height: 128px;
    overflow: visible;
    filter: drop-shadow(0 18px 34px rgba(var(--app-boot-deep-rgb), 0.6));
}

.app-splash-stop-start {
    stop-color: var(--app-boot-brand-start-hex);
}

.app-splash-stop-end {
    stop-color: var(--app-boot-brand-end-hex);
}

.app-splash-light-top {
    stop-color: var(--app-boot-on);
    stop-opacity: 0.24;
}

.app-splash-light-bottom {
    stop-color: var(--app-boot-on);
    stop-opacity: 0;
}

/* The road draws itself from home along the S; the arrival dot lands when it gets there. */
.app-splash-road {
    fill: none;
    stroke: var(--app-boot-on);
    stroke-width: 3.8;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-dasharray: 100;
    stroke-dashoffset: 100;
    animation: app-splash-draw 900ms cubic-bezier(0.65, 0, 0.35, 1) 300ms both;
}

/* While the app starts, a light keeps driving the road from home to the arrival: the logo is the loading indicator. */
.app-splash-pulse {
    fill: none;
    stroke: var(--app-boot-brand-accent);
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-dasharray: 9 91;
    stroke-dashoffset: 100;
    opacity: 0;
    filter: drop-shadow(0 0 1.6px rgba(var(--app-boot-brand-glow), 0.95));
    animation:
        app-splash-fade-in 300ms ease-out 1600ms forwards,
        app-splash-travel 1800ms linear 1600ms infinite;
}

.app-splash-home {
    fill: var(--app-boot-brand-end-hex);
}

.app-splash-arrival {
    fill: var(--app-boot-brand-accent);
    stroke: var(--app-boot-on);
    stroke-width: 1.5;
    transform-box: fill-box;
    transform-origin: center;
    animation:
        app-splash-land 420ms var(--app-boot-spring) 1100ms both,
        app-splash-bump 1800ms ease-out 3256ms infinite;
}

/* A ring that spreads from the arrival dot each time the light gets there. */
.app-splash-ping {
    fill: none;
    stroke: var(--app-boot-brand-accent);
    stroke-width: 1.2;
    opacity: 0;
    transform-box: fill-box;
    transform-origin: center;
    animation: app-splash-ping 1800ms ease-out 3256ms infinite;
}

.app-splash-sheen {
    position: absolute;
    inset: 0;
    overflow: hidden;
    border-radius: 35px;
}

.app-splash-sheen::before {
    content: '';
    position: absolute;
    top: -20%;
    bottom: -20%;
    left: -60%;
    width: 40%;
    background: linear-gradient(100deg, transparent, rgba(var(--app-boot-on-rgb), 0.38), transparent);
    transform: skewX(-18deg);
    animation: app-splash-sheen 1100ms cubic-bezier(0.4, 0, 0.2, 1) 1200ms both;
}

.app-splash-word {
    position: absolute;
    left: 50%;
    top: calc(46% + 92px);
    font-family: 'Inter Variable', Inter, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    font-size: 34px;
    font-weight: 800;
    line-height: 1;
    letter-spacing: -0.03em;
    white-space: nowrap;
    color: var(--app-boot-on);
    transform: translateX(-50%);
    animation: app-splash-word 700ms var(--app-boot-ease) 520ms both;
}

/* "Go" is lit glass: the accent running into the highlight, with a white glint that crosses it now and then. */
.app-splash-go {
    background: linear-gradient(100deg, var(--app-boot-brand-accent) 0%, var(--app-boot-highlight) 36%, var(--app-boot-on) 50%, var(--app-boot-highlight) 64%, var(--app-boot-brand-accent) 100%);
    background-size: 300% 100%;
    background-position: 0 0;
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    animation: app-splash-shine 3200ms ease-in-out 1700ms infinite;
}

.app-splash-progress {
    position: absolute;
    left: 50%;
    top: calc(46% + 146px);
    width: 120px;
    height: 3px;
    margin-left: -60px;
    overflow: hidden;
    border-radius: 999px;
    background-color: rgba(var(--app-boot-on-rgb), 0.14);
    animation: app-splash-fade-in 400ms ease 1500ms both;
}

/* The browser app's real progress: Blazor publishes the share of its files downloaded as --blazor-load-percentage. The
   phone app never sets it, so there the track stays empty and only the shimmer runs. */
.app-splash-progress::before {
    content: '';
    position: absolute;
    inset-block: 0;
    inset-inline-start: 0;
    width: var(--blazor-load-percentage, 0%);
    border-radius: inherit;
    background: linear-gradient(90deg, rgba(var(--app-boot-brand-glow), 0.35), rgba(var(--app-boot-brand-glow), 0.7));
    transition: width 240ms ease-out;
}

.app-splash-progress span {
    position: absolute;
    inset-block: 0;
    width: 40%;
    border-radius: inherit;
    background: linear-gradient(90deg, transparent, var(--app-boot-brand-accent), var(--app-boot-highlight));
    animation: app-splash-slide 1100ms cubic-bezier(0.65, 0, 0.35, 1) 1500ms infinite;
}

/* The exit: the tile swells and fades, the wordmark lifts away and the waves sink, over the app's first screen. */
.app-splash--leaving {
    opacity: 0;
    pointer-events: none;
    transition: opacity 380ms ease 80ms;
}

.app-splash--leaving .app-splash-center {
    transform: scale(1.12);
    transition: transform 440ms cubic-bezier(0.4, 0, 0.2, 1);
}

.app-splash--leaving .app-splash-word {
    opacity: 0;
    transform: translate(-50%, -10px);
    transition: opacity 260ms ease, transform 260ms ease;
}

.app-splash--leaving .app-splash-waves {
    transform: translateY(30%);
    transition: transform 440ms cubic-bezier(0.4, 0, 1, 1);
}

.app-splash--gone {
    display: none;
}

/* Without JavaScript the splash never leaves, so it says why, in the scene's own white. */
.app-splash-noscript {
    position: absolute;
    left: 50%;
    bottom: 12%;
    width: min(22rem, 80vw);
    transform: translateX(-50%);
    font-family: system-ui, sans-serif;
    text-align: center;
    color: var(--app-boot-on);
}

@keyframes app-splash-fade-in {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes app-splash-streak {
    0% {
        opacity: 0;
        transform: translateX(-100%);
    }

    12% {
        opacity: 1;
    }

    78% {
        opacity: 0.9;
    }

    100% {
        opacity: 0;
        transform: translateX(100vw);
    }
}

@keyframes app-splash-rise {
    from {
        transform: translateY(100%);
    }

    to {
        transform: translateY(0);
    }
}

@keyframes app-splash-drift {
    from {
        transform: translateX(0);
    }

    to {
        transform: translateX(-50%);
    }
}

@keyframes app-splash-arrive {
    from {
        opacity: 0;
        transform: scale(0.86);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes app-splash-float {
    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-7px);
    }
}

@keyframes app-splash-pulse {
    0%,
    100% {
        transform: scale(0.92);
        opacity: 0.6;
    }

    50% {
        transform: scale(1.06);
        opacity: 1;
    }
}

@keyframes app-splash-draw {
    to {
        stroke-dashoffset: 0;
    }
}

/* The dash runs the whole road once per cycle, from home to the arrival; its pathLength is 100. */
@keyframes app-splash-travel {
    from {
        stroke-dashoffset: 100;
    }

    to {
        stroke-dashoffset: 0;
    }
}

@keyframes app-splash-land {
    from {
        transform: scale(0);
    }

    to {
        transform: scale(1);
    }
}

@keyframes app-splash-bump {
    0% {
        transform: scale(1);
    }

    12% {
        transform: scale(1.22);
    }

    40%,
    100% {
        transform: scale(1);
    }
}

@keyframes app-splash-ping {
    0% {
        opacity: 0.9;
        transform: scale(1);
    }

    45%,
    100% {
        opacity: 0;
        transform: scale(2.8);
    }
}

@keyframes app-splash-sheen {
    from {
        left: -60%;
    }

    to {
        left: 130%;
    }
}

@keyframes app-splash-shine {
    0% {
        background-position: 100% 0;
    }

    55%,
    100% {
        background-position: 0 0;
    }
}

@keyframes app-splash-word {
    from {
        opacity: 0;
        transform: translate(-50%, 10px);
    }

    to {
        opacity: 1;
        transform: translate(-50%, 0);
    }
}

@keyframes app-splash-slide {
    from {
        inset-inline-start: -40%;
    }

    to {
        inset-inline-start: 100%;
    }
}

/* §2.8: a user who asks the platform to reduce motion sees the finished scene, still. */
@media (prefers-reduced-motion: reduce) {
    .app-splash *,
    .app-splash *::before {
        animation: none !important;
    }

    .app-splash-road {
        stroke-dashoffset: 0;
    }

    .app-splash-progress span {
        inset-inline-start: 30%;
    }

    .app-splash-streaks,
    .app-splash-pulse,
    .app-splash-ping {
        display: none;
    }
}

/* Blazor's own fallback bar, kept because it is the last resort when the circuit itself is gone and no
   component can render. It is hidden until Blazor's script decides to show it. */
#blazor-error-ui {
    color-scheme: light only;
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
    display: none;
    inset-inline-start: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    inset-inline-end: 0.75rem;
    top: 0.5rem;
}

#blazor-error-ui .reload {
    margin-inline-start: 0.5rem;
}

/* Root-level boundary fallback. It renders inside the document but outside MudLayout, so it carries its
   own spacing rather than inheriting the layout's. */
.router-error {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

