/*
 * "Through the Garden Window": layout for the anonymous welcome page and the
 * login page, which are ONE document (account/login.html) with two panels.
 * The page switches panels client-side; .gw[data-gw] says which one shows.
 *
 * The decorative garden canvas (public_wizard/_canvas.html) fills the page
 * and a warm paper sheet holds the content.
 *
 * Desktop (>=960px, the wizard and signup breakpoint): the scene is fixed and
 * full-bleed, the sheet floats at the left (anchored bottom on welcome,
 * centred on login).
 * Mobile: normal document flow on purpose, never a fixed sheet, so the iOS
 * keyboard and page scrolling behave. The garden is a band at the top and the
 * sheet follows it with rounded top corners, overlapping the band slightly.
 * Welcome gives the garden every pixel above the sheet; login keeps a short
 * band (--gw-band) so the form fits.
 *
 * Markup:
 *   .gw[data-gw="welcome"|"login"]
 *     .gw-scene      > the canvas include
 *     .gw-top        > .wz-wordmark + the inline public toolbar
 *     .gw-dock       > .gw-sheet > .gw-panel[data-gw-panel] x2
 *
 * Switching panels (script in account/login.html): on mobile the band height
 * animates (the canvas is sized in container units, so the plants scale
 * with it) while the panels cross-fade; on desktop a same-document View
 * Transition morphs the card (lt-sheet). Reduced motion switches instantly.
 *
 * Colours come from the app's design tokens (app.css), which already switch
 * for html.dark and for the OS dark preference when html is not .light.
 *
 * The signup page (account/signup.html) borrows the phone layout: it keeps
 * the wizard's split layout (app.css) on desktop, and below 960px its
 * .wz-app.gw-phone takes the same band and sheet (see "Signup on phones").
 */

/* Cross-document transitions between the funnel pages: auth_transitions.css,
   linked by every page that links this file. */

.gw,
.gw-phone {
    --gw-ease: var(--ease-out-back-subtle);
    --gw-sheet-bg: rgb(var(--color-surface-rgb, 250 248 244) / 0.95);
    --gw-pill-bg: rgb(var(--color-surface-rgb, 250 248 244) / 0.86);
    --gw-shadow: 0 30px 60px -20px rgba(22, 72, 37, 0.35), 0 2px 6px rgba(0, 0, 0, 0.05);
    --gw-shadow-up: 0 -12px 30px -14px rgba(22, 72, 37, 0.3);
    /* The login band on phones. */
    --gw-band: clamp(200px, 27svh, 230px);
}

.gw {
    position: relative;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100svh;
    color: var(--color-content-primary, #111827);
}

html.dark :is(.gw, .gw-phone) {
    /* The app's dark muted grey (#737373) is 3.9:1 on the night sheet, under
       AA for the small print here (subtitles, divider, toolbar): one step
       lighter reads 5.6:1 and still sits below content-secondary. */
    --color-content-muted: #8c8c8c;
    --color-content-muted-rgb: 140 140 140;
    --gw-sheet-bg: rgb(var(--color-surface-rgb, 18 18 18) / 0.92);
    --gw-pill-bg: rgb(var(--color-surface-rgb, 18 18 18) / 0.8);
    --gw-shadow: 0 30px 60px -20px rgba(0, 0, 0, 0.65), 0 2px 6px rgba(0, 0, 0, 0.3);
    --gw-shadow-up: 0 -12px 30px -14px rgba(0, 0, 0, 0.6);
}
@media (prefers-color-scheme: dark) {
    html:not(.light) :is(.gw, .gw-phone) {
        --color-content-muted: #8c8c8c;
        --color-content-muted-rgb: 140 140 140;
        --gw-sheet-bg: rgb(var(--color-surface-rgb, 18 18 18) / 0.92);
        --gw-pill-bg: rgb(var(--color-surface-rgb, 18 18 18) / 0.8);
        --gw-shadow: 0 30px 60px -20px rgba(0, 0, 0, 0.65), 0 2px 6px rgba(0, 0, 0, 0.3);
        --gw-shadow-up: 0 -12px 30px -14px rgba(0, 0, 0, 0.6);
    }
}

/* ------------------------------------------------------------- scene */
.gw-scene {
    position: relative;
    z-index: 0;
    flex: 0 0 auto;
    height: var(--gw-band);
    overflow: hidden;
    background: var(--color-surface, #faf8f4);
}
/* Set by the panel switch while the band changes height (inline px heights,
   animated by the script with the Web Animations API, --gw-ease). */
.gw[data-gw] .gw-scene.gw-scene--sizing {
    flex: 0 0 auto;
    min-height: 0;
}
/* While the band moves (.gw-scene--moving, set by the panel switch), the
   plants follow it frame by frame: their own size and position transitions
   (public_wizard_canvas.css, for the wizard's plant changes) would restart
   on every frame and only add work. */
.gw-scene--moving :is(.gc-pl, .gc-pl img, .gc-pot, .gc-seedling) {
    transition: none;
}
/* The scene here is static, and over half its nodes draw nothing once the
   images are in: the placeholder sprouts (opacity 0, gone once their fade
   ends) and the lawn plants' 0px pots. Out of the render tree, they cost
   nothing when the band resizes. */
.gw .gc-nopot .gc-pot {
    display: none;
}
.gw .gc-pl:not(.gc-wait) .gc-sprout {
    display: none;
    transition: opacity .15s var(--gc-ease), display .15s allow-discrete;
}

/* Welcome on phones: the garden takes every pixel above the sheet, so whole
   plants and beds show, never treetops cut off by the sheet. */
.gw[data-gw="welcome"] .gw-scene {
    flex: 1 1 auto;
    height: auto;
    min-height: 260px;
}

/* ----------------------------------------------------------- top bar */
.gw-top {
    position: absolute;
    z-index: 20;
    top: max(12px, env(safe-area-inset-top, 0px));
    left: max(12px, env(safe-area-inset-left, 0px));
    right: max(12px, env(safe-area-inset-right, 0px));
    display: flex;
    align-items: center;
    gap: 8px;
    pointer-events: none;
}
.gw-top > * {
    pointer-events: auto;
}
.gw-top .wz-wordmark {
    margin-right: auto;
    padding: 6px 12px 6px 8px;
    border-radius: 12px;
    background: var(--gw-pill-bg);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
}
/* The shared public toolbar renders inline here: give it 40px targets. */
.gw-top [data-lang-toggle],
.gw-top [data-theme-toggle] {
    min-height: 40px;
    min-width: 40px;
}

/* ------------------------------------------------------------- sheet */
.gw-dock {
    position: relative;
    z-index: 10;
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    margin-top: -28px;
}
.gw[data-gw="login"] .gw-dock {
    flex: 1 0 auto;
}

/* Phones: a bottom sheet in normal flow, rounded top corners and a grab
   handle. .gw-sheet-phone is the same sheet on phones only (the signup form
   column); the desktop card below is .gw-sheet's alone. */
@media (max-width: 959.98px) {
    .gw-sheet,
    .gw-sheet-phone {
        position: relative;
        flex: 1 0 auto;
        box-sizing: border-box;
        padding: 14px max(20px, env(safe-area-inset-right, 0px)) calc(24px + env(safe-area-inset-bottom, 0px)) max(20px, env(safe-area-inset-left, 0px));
        border-top: 1px solid var(--color-surface-border, #e5e3db);
        border-radius: 28px 28px 0 0;
        background: var(--gw-sheet-bg);
        -webkit-backdrop-filter: blur(14px);
        backdrop-filter: blur(14px);
        box-shadow: var(--gw-shadow-up);
        color: var(--color-content-primary, #111827);
    }
    /* Grab handle */
    .gw-sheet::before,
    .gw-sheet-phone::before {
        content: "";
        display: block;
        width: 40px;
        height: 4px;
        margin: 0 auto 18px;
        border-radius: 2px;
        background: var(--color-surface-border, #e5e3db);
    }
}
/* No glass while a view transition runs: the blur would be captured with
   the sheet's snapshot (or keep drawing behind it at opacity 0) and leave a
   blurred pane over the moving garden. An opaque surface stands in, set on
   the outgoing page by pageswap (html.lt-vt-leaving, see
   partials/includes/_funnel_transitions.html) and on the incoming or
   switching page by :active-view-transition. Two rules: a browser without
   the pseudo-class would drop a shared selector list. The phone panel switch
   (.gw-scene--moving) drops it too: the garden behind the sheet changes on
   every frame, and re-blurring a near-opaque pane each frame is GPU work
   nobody sees. */
html.lt-vt-leaving .gw-sheet,
html.lt-vt-leaving .gw-sheet-phone,
html.gw-switching .gw-sheet,
.gw-scene--moving ~ .gw-dock .gw-sheet {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    background: rgb(var(--color-surface-rgb, 250 248 244));
}
html:active-view-transition .gw-sheet,
html:active-view-transition .gw-sheet-phone {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    background: rgb(var(--color-surface-rgb, 250 248 244));
}

/* ------------------------------------------------------------ panels */
.gw-panel[hidden] {
    display: none;
}
/* Laid out once while idle, never painted (the panel script's prewarm). */
.gw-panel.gw-panel--prewarm {
    position: absolute;
    visibility: hidden;
    pointer-events: none;
}
.gw-panel :is(h1, h2):focus {
    outline: none;
}

/* ------------------------------------------------------- shared bits */
/* One focus ring for every control on the funnel pages (the welcome CTAs,
   wordmark, toolbar and text links had the browser's 1px dark ring, lost on
   the night sheet): the brand ring the buttons and inputs already use. */
:is(.gw, .gw-phone) :is(a, button, [role="button"]):focus-visible {
    outline: 2px solid var(--color-brand, #164825);
    outline-offset: 2px;
}
/* Browser surfaces in the palette: selection, caret, and no grey tap flash
   on controls that draw their own pressed state. */
:is(.gw, .gw-phone) ::selection {
    background: rgb(var(--color-brand-rgb, 22 72 37) / 0.2);
}
:is(.gw, .gw-phone) input {
    caret-color: var(--color-brand, #164825);
}
:is(.gw, .gw-phone) :is(.gw-btn, .social-button, .wizard-btn) {
    -webkit-tap-highlight-color: transparent;
}

.gw-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    min-height: 52px;
    padding: 0 22px;
    box-sizing: border-box;
    border-width: 1px;
    border-style: solid;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.2;
    text-align: center;
    text-decoration: none;
}

/* The secondary buttons colour their border with border-surface-border. */
.gw-btn--primary {
    border-color: transparent;
}

.gw-rule {
    height: 1px;
    margin: 18px 0;
    border: 0;
    background: var(--color-surface-border, #e5e3db);
}

/* ----------------------------------------------------- welcome sheet */
.gw-mark {
    display: block;
    width: 44px;
    height: 44px;
    margin-bottom: 12px;
}
.gw-title {
    margin: 0 0 8px;
    font-family: ui-serif, Georgia, Cambria, "Times New Roman", Times, serif;
    font-size: 30px;
    font-weight: 600;
    line-height: 1.08;
    letter-spacing: -0.01em;
}
.gw-sub {
    margin: 0 0 20px;
    font-size: 16px;
    line-height: 1.45;
}
.gw-ctas {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}

/* ------------------------------------------------------- login sheet */
.gw-heading {
    margin: 0 0 4px;
    font-family: ui-serif, Georgia, Cambria, "Times New Roman", Times, serif;
    font-size: 26px;
    font-weight: 600;
    line-height: 1.1;
}

/* -------------------------------------------------- signup on phones */
/* account/signup.html: the wizard's split markup (.wz-app, app.css) as a
   garden window. The page leaves fixed positioning for normal document flow
   (iOS keyboard), the header floats over a band as tall as the login band,
   and the form column (.wz-main.gw-sheet-phone) is the sheet, overlapping
   the band like .gw-dock. Desktop keeps the split layout untouched. */
@media (max-width: 959.98px) {
    .wz-app.gw-phone {
        position: relative;
        inset: auto;
        min-height: 100vh;
        min-height: 100svh;
        overflow: visible;
        padding: 0;
    }
    .gw-phone .wz-hdr {
        position: absolute;
        z-index: 20;
        top: max(12px, env(safe-area-inset-top, 0px));
        left: max(12px, env(safe-area-inset-left, 0px));
        right: max(12px, env(safe-area-inset-right, 0px));
        padding: 0;
        background: none;
        pointer-events: none;
    }
    .gw-phone .wz-hdr-row > * {
        pointer-events: auto;
    }
    /* As .gw-top .wz-wordmark: a pill that reads over the sky. */
    .gw-phone .wz-wordmark {
        padding: 6px 12px 6px 8px;
        border-radius: 12px;
        background: var(--gw-pill-bg);
        -webkit-backdrop-filter: blur(8px);
        backdrop-filter: blur(8px);
    }
    .gw-phone .wz-pane {
        height: var(--gw-band);
    }
    .gw-phone .wz-main {
        z-index: 10;
        margin-top: -28px;
        overflow: visible;
        overscroll-behavior: auto;
    }
}

/* ----------------------------------------------------------- desktop */
@media (min-width: 960px) {
    .gw {
        display: block;
    }

    .gw-scene,
    .gw[data-gw="welcome"] .gw-scene {
        position: fixed;
        inset: 0;
        height: auto;
        min-height: 0;
    }

    .gw-top {
        position: fixed;
        top: max(20px, env(safe-area-inset-top, 0px));
        left: max(24px, env(safe-area-inset-left, 0px));
        right: max(24px, env(safe-area-inset-right, 0px));
    }
    .gw-top .wz-wordmark {
        padding: 8px 14px 8px 10px;
    }

    .gw-dock,
    .gw[data-gw="login"] .gw-dock {
        position: fixed;
        top: 92px;
        bottom: clamp(24px, 6vh, 64px);
        left: max(clamp(24px, 5vw, 72px), env(safe-area-inset-left, 0px));
        width: min(440px, calc(100vw - 48px));
        margin: 0;
        justify-content: flex-end;
        pointer-events: none;
    }
    .gw[data-gw="login"] .gw-dock {
        bottom: 24px;
        justify-content: center;
    }

    .gw-sheet {
        position: relative;
        box-sizing: border-box;
        flex: 0 1 auto;
        min-height: 0;
        max-height: 100%;
        overflow-y: auto;
        overscroll-behavior: contain;
        scrollbar-width: thin;
        pointer-events: auto;
        padding: 36px 36px 32px;
        border: 1px solid var(--color-surface-border, #e5e3db);
        border-radius: 24px;
        background: var(--gw-sheet-bg);
        -webkit-backdrop-filter: blur(14px);
        backdrop-filter: blur(14px);
        box-shadow: var(--gw-shadow);
        color: var(--color-content-primary, #111827);
    }
    .gw[data-gw="login"] .gw-sheet {
        padding: 32px 36px 28px;
    }

    .gw-mark {
        width: 56px;
        height: 56px;
        margin-bottom: 18px;
    }
    .gw-title {
        margin-bottom: 10px;
        font-size: 40px;
    }
    .gw-sub {
        margin-bottom: 28px;
        font-size: 17px;
    }
    /* Side by side, Get Started wider; labels never wrap (e.g. "Se connecter"). */
    .gw-ctas {
        grid-template-columns: 1.4fr minmax(max-content, 1fr);
    }
    .gw-ctas .gw-btn {
        white-space: nowrap;
    }
    .gw-heading {
        font-size: 30px;
    }
}

/* ------------------------------------------------------------ motion */
/* Nothing animates on arrival: a direct load, reload or form re-render shows
   its panel at once. Only a panel switch moves. */

/* Panel switch without a View Transition (phones, older browsers): one
   panel at a time, never two texts on top of each other. The leaving panel,
   lifted out of flow, fades out quickly; once it is gone the arriving one
   fades and rises in. The band above changes height throughout. */
@keyframes gwPanelIn {
    0% { opacity: 0; transform: translateY(10px); }
    100% { opacity: 1; transform: none; }
}
@keyframes gwPanelOut {
    100% { opacity: 0; transform: translateY(4px); }
}
.gw-panel.gw-panel--enter {
    animation: gwPanelIn 240ms var(--gw-ease) 140ms both;
}
.gw-panel.gw-panel--exit {
    position: absolute;
    z-index: 1;
    pointer-events: none;
    animation: gwPanelOut 130ms cubic-bezier(0.4, 0, 1, 1) both;
}

/* Panel switch with a same-document View Transition (desktop): the card
   (lt-sheet, named in auth_transitions.css) morphs from the welcome card to
   the login card; its content swaps in sequence (the old content is gone
   before the new fades in), never overlapping. html.gw-switching is set only
   for this switch, so these rules outrank the cross-document timings in
   auth_transitions.css without changing them. The garden, wordmark and
   toolbar do not change, so they swap without a fade. */
/* The old content leaves with lt-vt-out (auth_transitions.css); the new one
   fades in without lt-vt-in's rise. */
@keyframes gwVtIn {
    0% { opacity: 0; }
}
html.gw-switching::view-transition-group(lt-sheet) {
    animation-duration: 400ms;
    animation-timing-function: var(--ease-out-back-subtle);
}
/* The pair is the card itself: a solid surface that morphs between the two
   sizes, so the card never empties while one content has left and the other
   has not yet arrived. */
html.gw-switching::view-transition-image-pair(lt-sheet) {
    overflow: hidden;
    border-radius: 24px;
    background: rgb(var(--color-surface-rgb, 250 248 244));
}
html.gw-switching::view-transition-old(lt-sheet) {
    animation: lt-vt-out 120ms cubic-bezier(0.4, 0, 1, 1) both;
}
html.gw-switching::view-transition-new(lt-sheet) {
    animation: gwVtIn 240ms var(--ease-out-back-subtle) 140ms both;
}
html.gw-switching::view-transition-old(root),
html.gw-switching::view-transition-new(root),
html.gw-switching::view-transition-old(lt-garden),
html.gw-switching::view-transition-new(lt-garden) {
    animation: none;
}
html.gw-switching::view-transition-old(root),
html.gw-switching::view-transition-old(lt-garden) {
    opacity: 0;
}

@media (prefers-reduced-motion: reduce) {
    .gw-panel.gw-panel--enter,
    .gw-panel.gw-panel--exit {
        animation: none;
    }
}


/* ----------------------------------------------------- welcome extras */
/* Dark sheet: lift the fern like the wordmark logo so it reads on the night card. */
html.dark .gw-mark {
    filter: brightness(1.9) saturate(0.8) drop-shadow(0 0 10px rgba(255, 255, 255, 0.05));
}
@media (prefers-color-scheme: dark) {
    html:not(.light) .gw-mark {
        filter: brightness(1.9) saturate(0.8) drop-shadow(0 0 10px rgba(255, 255, 255, 0.05));
    }
}
.gw-mark {
    transition: transform 0.4s var(--gw-ease);
}
.gw-ctas a {
    transition: color 200ms, background-color 200ms, border-color 200ms,
                transform 150ms var(--gw-ease),
                box-shadow 150ms var(--gw-ease);
}
.gw-ctas a:first-child svg {
    transition: transform 0.2s var(--gw-ease);
}
/* Hover lifts only where there is a pointer that hovers: on a phone the tap
   would leave Log In lifted when Back brings the welcome panel back. */
@media (hover: hover) {
    .gw-mark:hover {
        transform: rotate(15deg) scale(1.08);
    }
    .gw-ctas a:hover {
        transform: translateY(-2px);
        box-shadow: 0 8px 20px -4px rgba(22, 72, 37, 0.3);
    }
    .gw-ctas a:first-child:hover svg {
        transform: translateX(4px);
    }
}
.gw-ctas a:active {
    transform: scale(0.97) translateY(0);
    box-shadow: none;
}
/* Touch has no hover: the press gives Get Started's arrow its nudge. */
.gw-ctas a:first-child:active svg {
    transform: translateX(4px);
}
@media (prefers-reduced-motion: reduce) {
    .gw-mark:hover,
    .gw-ctas a:hover,
    .gw-ctas a:active,
    .gw-ctas a:first-child:hover svg,
    .gw-ctas a:first-child:active svg {
        transform: none;
        box-shadow: none;
    }
}
