/*
 * Winter theme — "Frosty Night"
 * ------------------------------------------------------------------
 * Ambient winter treatment for the public marketing pages. The overlay rules
 * are namespaced under `.winter-fx` (mounted by WinterTheme.tsx, never on the
 * app pages), the page accents (cat hat, snowman, Pricing snowflake) have
 * their own winter-* classes further down.
 *
 * Light mode: pale blue-grey flakes (white would vanish on a white page) and
 * an icy sky glow at the top. Dark mode: white flakes and northern lights in
 * our green (#04B76D) with a touch of teal and violet.
 */

.winter-fx {
    position: fixed;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    overflow: hidden;

    --winter-green: #04B76D;
    --winter-flake: #b4cbe3;
    --winter-flake-glow: rgba(96, 132, 176, 0.38);
    --winter-crystal: #a9c6e4;
}

.dark .winter-fx {
    --winter-flake: #ffffff;
    --winter-flake-glow: rgba(200, 230, 255, 0.55);
    --winter-crystal: #e4f1ff;
}

/* ── Sky ─────────────────────────────────────────────────────────── */
/* Light mode: a pale icy glow hanging from the top edge */
.winter-sky {
    position: absolute;
    left: -10%;
    right: -10%;
    top: -120px;
    height: 360px;
    background:
        radial-gradient(50% 70% at 20% 0%, rgba(186, 220, 250, 0.55) 0%, rgba(186, 220, 250, 0) 70%),
        radial-gradient(45% 60% at 82% 0%, rgba(206, 236, 230, 0.5) 0%, rgba(206, 236, 230, 0) 70%);
    filter: blur(8px);
}
.dark .winter-sky { display: none; }

/* Dark mode: northern lights, three soft bands that sway and breathe */
.winter-aurora {
    position: absolute;
    left: -15%;
    right: -15%;
    top: -40px;
    height: 300px;
    display: none;
    mix-blend-mode: screen;
}
.dark .winter-aurora { display: block; }

.winter-aurora__band {
    position: absolute;
    inset: 0;
    filter: blur(28px);
    will-change: transform, opacity;
    transform-origin: 50% 0%;
}

.winter-aurora__band--a {
    background: radial-gradient(38% 46% at 26% 30%, rgba(4, 183, 109, 0.55) 0%, rgba(4, 183, 109, 0) 72%);
    animation: winter-aurora-a 19s ease-in-out infinite;
}
.winter-aurora__band--b {
    background: radial-gradient(34% 40% at 58% 22%, rgba(24, 198, 171, 0.42) 0%, rgba(24, 198, 171, 0) 72%);
    animation: winter-aurora-b 24s ease-in-out infinite;
}
.winter-aurora__band--c {
    background: radial-gradient(30% 36% at 84% 26%, rgba(126, 104, 230, 0.26) 0%, rgba(126, 104, 230, 0) 72%);
    animation: winter-aurora-c 28s ease-in-out infinite;
}

/* ── Frosted edge ────────────────────────────────────────────────── */
.winter-frost {
    position: absolute;
    inset: 0;
    box-shadow:
        inset 0 0 60px 6px rgba(190, 218, 245, 0.42),
        inset 0 0 14px 1px rgba(220, 236, 252, 0.5);
}
.dark .winter-frost {
    box-shadow:
        inset 0 0 70px 6px rgba(150, 200, 255, 0.10),
        inset 0 0 12px 1px rgba(200, 228, 255, 0.10);
}

/* ── Snowfall ────────────────────────────────────────────────────── */
.winter-flake {
    position: absolute;
    top: -12px;
    left: var(--left, 50%);
    width: var(--size, 4px);
    height: var(--size, 4px);
    border-radius: 50%;
    background: var(--winter-flake);
    box-shadow: 0 0 3px var(--winter-flake-glow);
    opacity: 0;
    will-change: transform, opacity;
    animation: winter-fall var(--dur, 14s) linear infinite;
    animation-delay: var(--delay, 0s);
}

.winter-flake--near { filter: blur(1px); }
.winter-flake--far { box-shadow: none; }

/* Fewer flakes on phones (lighter on battery, less busy on a small screen) */
@media (max-width: 640px) {
    .winter-flake--far:nth-of-type(n+14) { display: none; }
    .winter-flake--mid:nth-of-type(n+36) { display: none; }
}

/* ── Big crystals ────────────────────────────────────────────────── */
.winter-crystal {
    position: absolute;
    top: -40px;
    left: var(--left, 50%);
    width: var(--size, 22px);
    height: var(--size, 22px);
    color: var(--winter-crystal);
    opacity: 0;
    will-change: transform, opacity;
    animation: winter-fall var(--dur, 24s) linear infinite;
    animation-delay: var(--delay, 0s);
    filter: drop-shadow(0 0 3px var(--winter-flake-glow));
}

.winter-crystal__inner {
    display: block;
    width: 100%;
    height: 100%;
    animation: winter-spin calc(var(--dur, 24s) * 0.6) linear infinite;
}

@media (max-width: 640px) {
    /* divs: sky, aurora, frost come first, so crystals are 4-8: keep three */
    .winter-crystal:nth-of-type(n+7) { display: none; }
}

/* ── Keyframes ──────────────────────────────────────────────────── */

/* Falls the full height and drifts a little on the breeze. --drift is a
   unitless number scaled to vw (negative drifts left). */
@keyframes winter-fall {
    0%   { transform: translate(0, 0); opacity: 0; }
    5%   { opacity: var(--op, 0.8); }
    30%  { transform: translate(calc(var(--drift, 4) * 0.5vw), 32vh); }
    60%  { transform: translate(calc(var(--drift, 4) * -0.2vw), 66vh); }
    92%  { opacity: var(--op, 0.8); }
    100% { transform: translate(calc(var(--drift, 4) * 0.4vw), 110vh); opacity: 0; }
}

@keyframes winter-spin {
    0%   { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes winter-aurora-a {
    0%, 100% { transform: translateX(-4%) scaleY(1); opacity: 0.75; }
    50%      { transform: translateX(5%) scaleY(1.25); opacity: 1; }
}
@keyframes winter-aurora-b {
    0%, 100% { transform: translateX(5%) scaleY(1.1); opacity: 0.6; }
    50%      { transform: translateX(-6%) scaleY(0.85); opacity: 1; }
}
@keyframes winter-aurora-c {
    0%, 100% { transform: translateX(-3%); opacity: 0.5; }
    50%      { transform: translateX(4%); opacity: 0.95; }
}

/* ── Page accents (rendered inline by pages, gated on the active theme) ──
   These sit INSIDE page content (hero cat), not the .winter-fx overlay. */

/* Hero cat dressed for winter (WinterHeroScene): one SVG laid over the
   picture in its own coordinates, so lights, scarf, mittens and hat line up
   at every size. */
.winter-hero-scene {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: auto;
    aspect-ratio: 578 / 549;
    z-index: 21;
    pointer-events: none;
    animation: winter-scene-in 0.6s ease-out both;
}
.winter-scene-hat { filter: drop-shadow(0 3px 2px rgba(0, 0, 0, 0.18)); }
.winter-cat-scarf, .winter-cat-mittens { filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.14)); }
/* lights: soft, twinkle slowly, dimmer in light mode */
.winter-lights { opacity: 0.7; }
.dark .winter-lights { opacity: 0.85; }
.winter-bulb { animation: winter-twinkle 3s ease-in-out infinite; }
@keyframes winter-twinkle {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.45; }
}
@keyframes winter-scene-in {
    0%   { opacity: 0; }
    100% { opacity: 1; }
}

/* Snowman on the ground beside the cat (lower-left) */
.winter-cat-snowman {
    position: absolute;
    top: 46%;
    left: -6%;
    width: 29%;
    z-index: 14;
    pointer-events: none;
    filter: drop-shadow(0 5px 7px rgba(0, 0, 0, 0.14));
    animation: winter-snowman-in 0.6s ease-out both;
}

/* the snowman is a link to Pricing (clickable, but it stays still) */
.winter-cat-snowman--link { display: block; pointer-events: auto; cursor: pointer; }
@keyframes winter-snowman-in {
    0%   { opacity: 0; transform: translateY(10px) scale(0.94); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}

/* Snowflake beside "Pricing" in the header */
.winter-pricing-tag {
    width: 14px;
    height: 14px;
    color: #5f9bd6;
    flex-shrink: 0;
    animation: winter-spin 12s linear infinite;
}
.dark .winter-pricing-tag { color: #bfe0ff; }

/* ── Visitor toggle: turn the snow off (low-end machines) ────────── */
.winter-toggle {
    position: fixed;
    left: 14px;
    bottom: 14px;
    z-index: 60;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px 6px 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.86);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    border: 1px solid rgba(95, 155, 214, 0.25);
    box-shadow: 0 2px 8px rgba(30, 60, 100, 0.12);
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    color: #2c5a86;
    cursor: pointer;
    opacity: 0.75;
    transition: opacity 0.2s ease, transform 0.2s ease;
}
.dark .winter-toggle {
    background: rgba(16, 30, 48, 0.82);
    border-color: rgba(191, 224, 255, 0.18);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    color: #dcecff;
}
.winter-toggle:hover {
    opacity: 1;
    transform: translateY(-1px);
}
.winter-toggle__icon {
    width: 14px;
    height: 14px;
    color: #5f9bd6;
}
.dark .winter-toggle__icon { color: #bfe0ff; }

@media (max-width: 640px) {
    .winter-toggle { left: 10px; bottom: 10px; padding: 7px; }
    .winter-toggle__label { display: none; }
}

/* iPhone Safari: its floating bottom toolbar covers things pinned to the
   bottom, so lift the button on iOS phones (same as the Halloween one). */
@supports (-webkit-touch-callout: none) {
    @media (max-width: 767px) {
        .winter-toggle { bottom: calc(68px + env(safe-area-inset-bottom, 0px)); }
    }
}

/* Visitor switched the snow off: hide the page accents before paint too
   (the boot script sets this attribute, see colorModePreference.ts) */
[data-winter-off] .winter-hero-scene,
[data-winter-off] .winter-cat-snowman,
[data-winter-off] .winter-pricing-tag { display: none !important; }

/* ── Respect reduced-motion: keep the look, drop the movement ───── */
@media (prefers-reduced-motion: reduce) {
    .winter-fx *,
    .winter-hero-scene,
    .winter-bulb,
    .winter-cat-snowman,
    .winter-pricing-tag {
        animation: none !important;
    }

    /* A light dusting of still flakes and crystals, spread down the screen */
    .winter-flake,
    .winter-crystal {
        opacity: var(--op, 0.5);
        top: var(--rest, 30vh);
    }
    .winter-flake--near { display: none; }
}

/* ── Snow resting on a few buttons and cards ─────────────────────────
   Pages mark the spots with data-winter-cap. winterSnowCaps.ts draws a small
   SVG of snow into each one, to its exact width (uneven lumps along the whole
   top, thinning out over the rounded corners, a drip or two). Only while the
   overlay is up: [data-winter-fx] on <html> (public pages, snow on). */
[data-winter-fx] [data-winter-cap]:not([class*="absolute"]):not([class*="fixed"]) { position: relative; }
[data-winter-fx] [data-winter-cap="card-lg"] { overflow: visible !important; }
.winter-snowcap {
    position: absolute;
    z-index: 3;
    pointer-events: none;
    overflow: visible;
    filter: drop-shadow(0 0 0.5px rgba(60, 100, 150, 0.45)) drop-shadow(0 1px 1px rgba(30, 55, 90, 0.18));
    animation: winter-cap-in 0.9s ease-out both;
}
.dark .winter-snowcap {
    filter: brightness(0.97) drop-shadow(0 1px 1.2px rgba(0, 0, 0, 0.3));
}
@keyframes winter-cap-in {
    0%   { opacity: 0; transform: translateY(-2px); }
    100% { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
    .winter-snowcap { animation: none; }
}

/* ── Icy glow on cards when hovered ──────────────────────────────────
   The marked ones (data-winter-glow) and every card on a public page that
   already reacts to the mouse (a hover shadow or hover border). */
[data-winter-fx] [data-winter-glow],
[data-winter-fx] main [class*="rounded-2xl"][class*="hover:shadow"],
[data-winter-fx] main [class*="rounded-3xl"][class*="hover:shadow"],
[data-winter-fx] main [class*="rounded-2xl"][class*="hover:border-"],
[data-winter-fx] main [class*="rounded-3xl"][class*="hover:border-"] {
    transition: box-shadow 0.3s ease, border-color 0.3s ease, background-color 0.2s ease, transform 0.3s ease;
}
[data-winter-fx] [data-winter-glow]:hover,
[data-winter-fx] main [class*="rounded-2xl"][class*="hover:shadow"]:hover,
[data-winter-fx] main [class*="rounded-3xl"][class*="hover:shadow"]:hover,
[data-winter-fx] main [class*="rounded-2xl"][class*="hover:border-"]:hover,
[data-winter-fx] main [class*="rounded-3xl"][class*="hover:border-"]:hover {
    border-color: rgba(120, 180, 240, 0.65) !important;
    box-shadow:
        0 0 0 1px rgba(150, 200, 250, 0.45),
        0 0 22px 2px rgba(130, 190, 250, 0.35),
        0 18px 40px -18px rgba(70, 130, 200, 0.45) !important;
}
[data-winter-fx].dark [data-winter-glow]:hover,
[data-winter-fx].dark main [class*="rounded-2xl"][class*="hover:shadow"]:hover,
[data-winter-fx].dark main [class*="rounded-3xl"][class*="hover:shadow"]:hover,
[data-winter-fx].dark main [class*="rounded-2xl"][class*="hover:border-"]:hover,
[data-winter-fx].dark main [class*="rounded-3xl"][class*="hover:border-"]:hover {
    border-color: rgba(160, 210, 255, 0.6) !important;
    box-shadow:
        0 0 0 1px rgba(170, 215, 255, 0.35),
        0 0 30px 3px rgba(120, 190, 255, 0.38),
        0 20px 50px -20px rgba(0, 0, 0, 0.6) !important;
}

/* ── Snow piling up along the bottom of the screen ──────────────────── */
.winter-drift {
    /* reaches 16px below the screen so its lower edge never shows, and it
       rises from below the edge (no stretching), so it never looks detached */
    --drift-h: 48px;
    position: fixed;
    left: 0;
    right: 0;
    bottom: -16px;
    z-index: 40;
    height: calc(var(--drift-h) + 16px);
    padding: 0;
    margin: 0;
    border: 0;
    background: none;
    cursor: pointer;
    transform: translateY(var(--drift-h));
    animation: winter-drift-grow 60s linear 1s both;
    transition: opacity 0.6s ease;
}
.winter-drift__snow {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    fill: #ffffff;
    filter: drop-shadow(0 -1px 2px rgba(70, 110, 160, 0.35));
}
.dark .winter-drift__snow {
    fill: #eef5ff;
    filter: drop-shadow(0 -2px 6px rgba(160, 210, 255, 0.25));
}
.winter-drift--melted {
    opacity: 0;
    pointer-events: none;
}
.winter-drift--brushing .winter-drift__snow {
    animation: winter-drift-brush 0.6s ease-in forwards;
}
.winter-drift__puff {
    position: absolute;
    bottom: 22px;
    left: var(--left, 50%);
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 0 0 3px rgba(70, 110, 160, 0.4);
    animation: winter-drift-puff 0.65s ease-out forwards;
}
@keyframes winter-drift-grow {
    0%   { transform: translateY(var(--drift-h)); }
    6%   { transform: translateY(calc(var(--drift-h) * 0.65)); }
    17%  { transform: translateY(calc(var(--drift-h) * 0.45)); }
    45%  { transform: translateY(calc(var(--drift-h) * 0.2)); }
    100% { transform: translateY(0); }
}
@keyframes winter-drift-brush {
    0%   { transform: none; opacity: 1; }
    100% { transform: translateY(100%) scaleX(1.04); opacity: 0; }
}
@keyframes winter-drift-puff {
    0%   { transform: translate(0, 0) scale(1); opacity: 1; }
    100% { transform: translate(var(--dx, 0), var(--dy, -40px)) scale(0.4); opacity: 0; }
}
@media (max-width: 640px) {
    .winter-drift { --drift-h: 30px; }
}
@media (prefers-reduced-motion: reduce) {
    .winter-drift { display: none; }
}

/* ── Blue bobble hat on the cats in product / use-case hero pictures ── */
.winter-hero-hat {
    position: absolute;
    /* no z-index: info cards drawn after the picture stay on top of the hat */
    pointer-events: none;
    transform: rotate(var(--hat-rot, -6deg));
    filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.18));
    animation: winter-hero-hat-in 0.6s ease-out both;
}
.winter-hero-hat > svg { display: block; width: 100%; height: auto; }
@keyframes winter-hero-hat-in {
    0%   { opacity: 0; translate: 0 -8px; }
    100% { opacity: 1; translate: 0 0; }
}
[data-winter-off] .winter-hero-hat { display: none !important; }
@media (prefers-reduced-motion: reduce) {
    .winter-hero-hat { animation: none; }
}

/* ── Frozen price: the total frosts over for a moment when it changes ──
   The price element is re-created on every change (Shell.tsx SummaryCard),
   so this plays each time the visitor picks another size. */
[data-winter-fx] .winter-price {
    position: relative;
    display: inline-block;
    animation: winter-price-frost 1.2s ease-out both;
}
[data-winter-fx] .winter-price::before {
    content: "";
    position: absolute;
    top: -6px;
    right: -14px;
    width: 14px;
    height: 14px;
    background: center / contain no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 48 48'%3E%3Cg stroke='%2390c6f5' stroke-width='3' stroke-linecap='round' fill='none'%3E%3Cpath d='M24 4v40M6.7 14l34.6 20M6.7 34l34.6-20'/%3E%3Cpath d='M24 11l-4.5-4.5M24 11l4.5-4.5M24 37l-4.5 4.5M24 37l4.5 4.5'/%3E%3C/g%3E%3C/svg%3E");
    opacity: 0;
    animation: winter-price-flake 1.2s ease-out both;
    pointer-events: none;
}
[data-winter-fx] .winter-price::after {
    content: "";
    position: absolute;
    inset: -2px -4px;
    border-radius: 6px;
    background: linear-gradient(110deg, transparent 30%, rgba(255, 255, 255, 0.85) 48%, rgba(200, 230, 255, 0.6) 52%, transparent 70%) no-repeat;
    background-size: 250% 100%;
    mix-blend-mode: screen;
    opacity: 0;
    animation: winter-price-shine 1.2s ease-out both;
    pointer-events: none;
}
@keyframes winter-price-frost {
    0%   { filter: blur(1.2px) brightness(1.7) saturate(0.15); text-shadow: 0 0 12px rgba(170, 215, 255, 0.95); }
    55%  { filter: blur(0) brightness(1.25) saturate(0.55); text-shadow: 0 0 8px rgba(170, 215, 255, 0.6); }
    100% { filter: none; text-shadow: none; }
}
@keyframes winter-price-shine {
    0%   { opacity: 1; background-position: 100% 0; }
    100% { opacity: 0; background-position: -60% 0; }
}
@keyframes winter-price-flake {
    0%   { opacity: 0; transform: scale(0.3) rotate(0deg); }
    25%  { opacity: 1; transform: scale(1) rotate(60deg); }
    100% { opacity: 0; transform: scale(0.8) rotate(120deg); }
}

/* ── Santa on a rope ladder, hanging from under the header (top left) ──
   Click him: he falls down the screen, the empty ladder is pulled up, and
   about 20s later the ladder comes back down with him on it (WinterChristmas). */
.winter-santa {
    position: fixed;
    top: 0;
    left: 14px;
    z-index: 45; /* under the header (z-50), so the ladder hangs from it */
    width: 92px;
    pointer-events: none;
    transform-origin: 50% 0;
    animation: winter-santa-sway 5s ease-in-out infinite;
}
.winter-santa__rig { position: relative; }
.winter-santa__man { position: absolute; inset: 0; }
.winter-santa__svg { display: block; width: 100%; height: auto; overflow: visible; filter: drop-shadow(0 6px 8px rgba(0, 0, 0, 0.22)); }
.winter-santa__man .winter-santa__svg { filter: none; }
.winter-santa__body { pointer-events: visiblePainted; cursor: pointer; }
.winter-santa__oh { opacity: 0; }
.winter-santa__wave { transform-box: fill-box; transform-origin: 0% 100%; animation: winter-santa-wave 1.6s ease-in-out infinite; }
.winter-santa__legs { transform-box: fill-box; transform-origin: 50% 0%; animation: winter-santa-kick 2.2s ease-in-out infinite; }
@keyframes winter-santa-sway {
    0%, 100% { transform: rotate(2.2deg); }
    50%      { transform: rotate(-2.2deg); }
}
@keyframes winter-santa-wave {
    0%, 100% { transform: rotate(0deg); }
    50%      { transform: rotate(-18deg); }
}
@keyframes winter-santa-kick {
    0%, 100% { transform: rotate(0deg); }
    50%      { transform: rotate(5deg); }
}

/* he lets go: a startled hop, then down past the bottom of the screen */
.winter-santa--falling .winter-santa__man {
    transform-origin: 48% 78%;
    animation: winter-santa-fall 1.5s cubic-bezier(0.45, 0, 0.85, 0.4) forwards;
}
.winter-santa--falling .winter-santa__oh { opacity: 1; }
.winter-santa--falling .winter-santa__wave,
.winter-santa--falling .winter-santa__legs { animation-duration: 0.35s; }
@keyframes winter-santa-fall {
    0%   { transform: translate(0, 0) rotate(0deg); }
    14%  { transform: translate(3px, -16px) rotate(-10deg); }
    100% { transform: translate(40px, 115vh) rotate(200deg); }
}
/* the empty ladder is pulled back up under the header */
.winter-santa--pulling .winter-santa__man { visibility: hidden; }
.winter-santa--pulling .winter-santa__rig { animation: winter-santa-pull 1.3s ease-in forwards; }
@keyframes winter-santa-pull {
    0%   { transform: translateY(0); }
    100% { transform: translateY(-110%); }
}
/* out of sight; he climbs back on up there */
.winter-santa--away .winter-santa__rig { transform: translateY(-110%); }
/* and the ladder comes back down with him on it, with a little bounce */
.winter-santa--returning .winter-santa__rig { animation: winter-santa-return 2.2s cubic-bezier(0.3, 0.6, 0.4, 1) forwards; }
@keyframes winter-santa-return {
    0%   { transform: translateY(-110%); }
    75%  { transform: translateY(4%); }
    88%  { transform: translateY(-1.5%); }
    100% { transform: translateY(0); }
}
/* only where there is room beside the page content (the left margin is
   wide enough from about 1400px), so he never covers the headline */
@media (max-width: 1399px) {
    .winter-santa { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    .winter-santa, .winter-santa__wave, .winter-santa__legs,
    .winter-santa--falling .winter-santa__man,
    .winter-santa--pulling .winter-santa__rig,
    .winter-santa--returning .winter-santa__rig { animation: none; }
    .winter-santa--falling .winter-santa__man { visibility: hidden; }
    [data-winter-fx] .winter-price,
    [data-winter-fx] .winter-price::before,
    [data-winter-fx] .winter-price::after { animation: none; }
}
