/* =============================================================================
   motion.css - the moving parts of the homepage (index.html).

   Nothing in here changes what the page says or where anything sits. It only
   adds four things on top of styles.css, all driven by motion.js:

     1. The welcome screen (.intro) - shown once per visit.
     2. The 3D tooth beside the doctor's photograph (.hero-tooth).
     3. The opening section rising into place as the welcome screen leaves.
     4. Sections sliding gently into place as you scroll down to them (.rv).

   Every one of them switches itself off for people who have asked their phone
   or computer for less motion. The colours all come from styles.css.
   ============================================================================= */


/* -----------------------------------------------------------------------------
   1. THE WELCOME SCREEN
   Hidden unless the small script at the top of index.html switched it on. If
   motion.js never runs, the screen removes itself after 8 seconds (the
   "failsafe" animation), so nobody can ever be stuck behind it. Once motion.js
   has taken charge it switches the failsafe off (.is-running) and keeps its
   own, more exact, timers instead.

   Positions are written out as top/right/bottom/left rather than the shorter
   "inset", which phones with a browser older than 2021 do not understand.
   ----------------------------------------------------------------------------- */
.intro {
    display: none;
}

html.intro-on .intro {
    display: block;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 10000;
    overflow: hidden;
    cursor: pointer;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    background: radial-gradient(circle at 50% 50%, #FBEFE9 0%, #E9D3CA 34%, #D6BAB0 74%, #C9AA9F 100%);
    transition: opacity 380ms ease;
    animation: intro-failsafe 10ms linear 8s forwards;
}

html.intro-on .intro.is-running {
    animation: none;
}

@keyframes intro-failsafe {
    to {
        opacity: 0;
        visibility: hidden;
        /* "hidden" alone is not enough: a browser can count the screen as
           still there and let it swallow every tap on the page below */
        pointer-events: none;
    }
}

.intro.is-leaving {
    opacity: 0;
    pointer-events: none;
}

.intro-canvas {
    position: absolute;
    top: 0;
    left: 0;
    display: block;
    width: 100%;
    height: 100%;
}

/* A fine chalky grain over the whole screen, like stone. Drawn once by the
   browser from the tiny pattern below - it costs nothing per frame. */
.intro::after {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    pointer-events: none;
    opacity: 0.16;
    mix-blend-mode: multiply;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.55 0 0 0 0 0.42 0 0 0 0 0.39 0 0 0 0.6 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* The words in the middle of the ring. Their size follows the ring's size,
   which motion.js passes in as --intro-r (the ring's inner radius). */
.intro-text {
    position: absolute;
    left: 50%;
    top: 50%;
    z-index: 1;
    width: calc(var(--intro-r, 140px) * 1.56);
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    pointer-events: none;
}

.intro-mark {
    width: clamp(32px, calc(var(--intro-r, 140px) * 0.22), 56px);
    height: auto;
    margin-bottom: calc(var(--intro-r, 140px) * 0.05);
    opacity: 0;
    transform: translateY(10px) scale(0.86);
    transition: opacity 700ms ease, transform 900ms var(--ease-out);
}

.intro-kicker {
    /* the extra left padding balances the trailing letter-space */
    padding-left: 0.24em;
    font-family: var(--font-body);
    font-weight: 600;
    font-size: clamp(0.7rem, calc(var(--intro-r, 140px) * 0.068), 1rem);
    letter-spacing: 0.6em;
    text-transform: uppercase;
    color: var(--ink-soft);
    opacity: 0;
    transition: opacity 800ms ease 120ms, letter-spacing 1300ms var(--ease-out) 120ms;
}

.intro-name {
    margin-top: 0.18em;
    font-family: var(--font-display);
    font-weight: 800;
    font-stretch: 82%;
    font-size: clamp(1.35rem, calc(var(--intro-r, 140px) * 0.2), 3rem);
    line-height: 1.04;
    color: var(--ink);
    text-wrap: balance;
    opacity: 0;
    filter: blur(10px);
    transform: scale(1.06);
    transition: opacity 900ms ease 260ms, filter 1000ms ease 260ms, transform 1300ms var(--ease-out) 260ms;
}

.intro-name b {
    font-weight: 800;
    color: var(--red);
}

.intro.show-text .intro-mark {
    opacity: 1;
    transform: none;
}

.intro.show-text .intro-kicker {
    opacity: 1;
    letter-spacing: 0.24em;
}

.intro.show-text .intro-name {
    opacity: 1;
    filter: none;
    transform: none;
}

.intro-skip {
    position: absolute;
    right: 16px;
    bottom: 18px;
    /* clear of the notch and the home bar on phones that have them */
    right: max(16px, env(safe-area-inset-right, 0px));
    bottom: max(18px, env(safe-area-inset-bottom, 0px));
    z-index: 2;
    padding: 0.55em 1.15em;
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 0.9rem;
    letter-spacing: 0.06em;
    color: var(--ink);
    background: rgba(255, 253, 249, 0.6);
    border: 1px solid rgba(36, 26, 27, 0.14);
    border-radius: 999px;
    cursor: pointer;
    opacity: 0;
    animation: intro-skip-in 500ms ease 700ms forwards;
}

@keyframes intro-skip-in {
    to {
        opacity: 1;
    }
}


/* -----------------------------------------------------------------------------
   2. THE 3D TOOTH
   Added by motion.js only when the device can draw it. On a phone it floats
   at the top left of the doctor's doorway, kept clear of the "call now" line
   above it. --tooth-shift is the gentle parallax, set while you scroll.
   ----------------------------------------------------------------------------- */
.hero-tooth {
    position: absolute;
    z-index: 3;
    left: -3%;
    top: 0;
    width: 38%;
    max-width: 230px;
    pointer-events: none;
    opacity: 0;
    translate: 0 var(--tooth-shift, 0px);
    transition: opacity 600ms ease;
}

/* Keeps the box square. (aspect-ratio would be shorter, but older phone
   browsers ignore it and the tooth would be drawn into a box of no height.) */
.hero-tooth::before {
    content: "";
    display: block;
    padding-top: 100%;
}

.hero-tooth.is-ready {
    opacity: 1;
}

.hero-tooth-bob {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    animation: tooth-bob 6s ease-in-out infinite;
}

.hero-tooth canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* A soft shadow on the "floor" below the tooth, which shrinks as it rises */
.hero-tooth::after {
    content: "";
    position: absolute;
    left: 26%;
    right: 26%;
    bottom: 1%;
    height: 9%;
    z-index: -1;
    border-radius: 50%;
    background: radial-gradient(closest-side, rgba(36, 26, 27, 0.2), rgba(36, 26, 27, 0));
    animation: tooth-shadow 6s ease-in-out infinite;
}

@keyframes tooth-bob {
    0%,
    100% {
        transform: translateY(0);
    }

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

@keyframes tooth-shadow {
    0%,
    100% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(0.86);
        opacity: 0.65;
    }
}

/* Wide screens: the hours card stands at the left of the doorway, so the tooth
   floats in the space above it - lifted a little above the doorway's top and
   sized so that it always clears the card. */
@media (min-width: 960px) {
    .hero-tooth {
        left: 0.5%;
        top: -42px;
        width: 29%;
        max-width: 170px;
    }
}


/* -----------------------------------------------------------------------------
   3. THE OPENING SECTION RISING INTO PLACE
   Only while the welcome screen is playing. The words are never made
   invisible - they only move - so the page counts as loaded the moment it
   arrives, which keeps Google's speed score where it was.
   ----------------------------------------------------------------------------- */
html.intro-on .hero-copy > *,
html.intro-on .hero-visual,
html.intro-on .fact-strip > li {
    transform: translateY(36px);
    transition: transform 1100ms var(--ease-out);
}

html.intro-on .hero-copy > :nth-child(2) { transition-delay: 50ms; }
html.intro-on .hero-copy > :nth-child(3) { transition-delay: 100ms; }
html.intro-on .hero-copy > :nth-child(4) { transition-delay: 150ms; }
html.intro-on .hero-copy > :nth-child(5) { transition-delay: 200ms; }
html.intro-on .hero-visual { transform: translateY(44px) scale(0.97); transition-delay: 90ms; }
html.intro-on .fact-strip > li:nth-child(1) { transition-delay: 220ms; }
html.intro-on .fact-strip > li:nth-child(2) { transition-delay: 290ms; }
html.intro-on .fact-strip > li:nth-child(3) { transition-delay: 360ms; }

html.intro-on.hero-in .hero-copy > *,
html.intro-on.hero-in .hero-visual,
html.intro-on.hero-in .fact-strip > li {
    transform: none;
}

/* If motion.js never ran, nothing would ever say "rise now" - so after 8
   seconds the opening section settles into place on its own. */
html.intro-on:not(.hero-in) .hero-copy > *,
html.intro-on:not(.hero-in) .hero-visual,
html.intro-on:not(.hero-in) .fact-strip > li {
    animation: hero-failsafe 10ms linear 8s forwards;
}

@keyframes hero-failsafe {
    to {
        transform: none;
    }
}


/* -----------------------------------------------------------------------------
   4. SECTIONS SLIDING INTO PLACE
   motion.js marks the pieces of each section with .rv and adds .is-in as each
   one comes into view. The classes are removed again once it has arrived, so
   the page's own hover effects work exactly as before.
   ----------------------------------------------------------------------------- */
html.motion .rv {
    opacity: 0;
    transform: translateY(34px);
    transition: opacity 800ms var(--ease-out), transform 1000ms var(--ease-out);
    transition-delay: calc(var(--rv-i, 0) * 90ms);
}

html.motion .rv.is-in {
    opacity: 1;
    transform: none;
}


/* -----------------------------------------------------------------------------
   Less motion, as the visitor asked their device for.
   ----------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    .hero-tooth-bob,
    .hero-tooth::after {
        animation: none;
    }

    html.motion .rv {
        opacity: 1;
        transform: none;
    }
}

/* Printing the page shows everything, whatever had been scrolled to. */
@media print {
    .intro,
    .hero-tooth {
        display: none !important;
    }

    html.motion .rv {
        opacity: 1 !important;
        transform: none !important;
    }
}
