/*
 * Motion — Decurtins Media und Management GmbH
 * Depends on tokens defined in styles/base.css.
 *
 * Two concerns:
 *   1. Interactive-element transitions (hover/focus on links, buttons,
 *      logos, cards).
 *   2. Scroll-triggered entrance animations. This file only defines the
 *      CSS contract: elements start hidden via `.reveal`, and an
 *      IntersectionObserver toggles `.is-visible` on them when they
 *      enter the viewport. No JS lives in this file.
 */

html {
    scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
}

/* ------------------------------------------------------------------ *
 * 1. Interactive transitions
 * ------------------------------------------------------------------ */

a,
button,
.logo-grid__picture img,
.testimonial-card {
    transition-property: color, background-color, border-color, opacity, transform, filter;
    transition-duration: var(--duration-base);
    transition-timing-function: var(--ease-standard);
}

/* Flat-design hover: no shadows and no border, just a small lift —
   the brand guide specifies no elevation shadows anywhere. */
.testimonial-card:hover {
    transform: translateY(-4px);
}

/* Team (boxless): the cards themselves don't react at all — no lift,
   border or background. Only the details move; states in layout.css.
   Touch: they unfold under the title (height + fade). `visibility`
   flips to hidden only after the fade-out (delay = duration) and to
   visible immediately on open. */
.team-card__details {
    transition: grid-template-rows var(--duration-slow) var(--ease-standard),
        opacity var(--duration-slow) var(--ease-standard),
        visibility 0s linear var(--duration-slow);
}

.team-card.is-open .team-card__details {
    transition-delay: 0s, 0s, 0s;
}

/* Web: the details are always shown, nothing to animate */
@media (hover: hover) and (pointer: fine) {
    .team-card__details {
        transition: none;
    }
}

.team-card__contact-link {
    transition: color var(--duration-base) var(--ease-standard);
}

.team-card__contact-link:hover {
    color: var(--color-link-hover);
}

.team-member-toggle::after {
    transition: transform var(--duration-base) var(--ease-standard);
}

.team-card.is-open .team-member-toggle::after {
    transform: rotate(45deg);
}

/* Navigation. The link highlight is the same effect the legacy theme's
   nav used on hover — a translucent fill sliding in from the left,
   with the text brightening — and it's now also what marks the
   section currently in view (`.is-active`, set by scripts/site-nav.js
   while scrolling). Timing/easing copied from that legacy rule. */
.site-nav__link {
    transition: color 0.27s cubic-bezier(0, 0, 0.58, 1);
}

.site-nav__link::before {
    transition: transform 0.27s cubic-bezier(0, 0, 0.58, 1);
}

.site-nav__link:hover,
.site-nav__link.is-active {
    color: var(--color-text-inverse);
}

.site-nav__link:hover::before,
.site-nav__link.is-active::before {
    transform: scaleX(1);
}

/* mobile menu panel: height grows/shrinks; `visibility` flips to
   hidden only after the close animation finishes (delay = duration)
   and to visible immediately on open */
.site-nav__panel {
    transition: grid-template-rows var(--duration-base) var(--ease-standard),
        visibility 0s linear var(--duration-base);
}

.site-nav.is-open .site-nav__panel {
    transition-delay: 0s, 0s;
}

.site-nav__toggle-bar {
    transition: transform var(--duration-base) var(--ease-standard),
        opacity var(--duration-fast) var(--ease-standard);
}

/* crisp keyboard-focus ring that reads on the black bar */
.site-nav__toggle:focus-visible,
.site-nav__link:focus-visible {
    box-shadow: inset 0 0 0 2px var(--color-brand-accent);
}

@media (min-width: 1200px) {
    .site-nav__panel {
        transition: none;
    }
}

.service-tabs__tab:hover {
    color: var(--color-brand-primary);
}

/* Portfolio cards: the shared hover lift — see "Hover lift" below the
   scroll-reveal rules. */

/* TEMPORARY: the red accent bar that slid in along the bottom of a
   card on hover is switched off for now. To bring it back, remove
   this comment's opening and closing markers.

.portfolio-card::before {
    content: "";
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 4px;
    background: var(--color-brand-accent);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform var(--duration-base) var(--ease-standard);
}

.portfolio-card:hover::before {
    transform: scaleX(1);
}
*/

/* Referenzen: grayscale -> full color on hover, per the brand's
   "Image Treatment: Grayscale/Monotone" rule — color is the reward,
   not a shadow. */
.logo-grid__item:hover .logo-grid__picture img,
.logo-grid__item:focus-within .logo-grid__picture img {
    filter: none;
    transform: scale(1.04);
}

/* High-contrast, visible keyboard focus everywhere — no focus:none */
a:focus-visible,
button:focus-visible,
.logo-grid__item:focus-within {
    outline: none;
    box-shadow: var(--shadow-focus);
}

.contact-form__input {
    transition: border-color var(--duration-base) var(--ease-standard), box-shadow var(--duration-base) var(--ease-standard);
}

.contact-form__input:focus {
    outline: none;
    border-color: var(--color-brand-accent);
    box-shadow: var(--shadow-focus);
}

.back-to-top {
    transition-property: background-color;
    transition-duration: var(--duration-base);
    transition-timing-function: var(--ease-standard);
}

.back-to-top:hover {
    background: var(--color-charcoal);
}

/* ------------------------------------------------------------------ *
 * 2. Scroll-triggered entrance animations
 *
 * Contract: add `.reveal` (+ a direction modifier) to any element.
 * It starts hidden/offset. An IntersectionObserver adds `.is-visible`
 * when the element enters the viewport — that's the only class this
 * file expects external JS to toggle.
 * ------------------------------------------------------------------ */

.reveal {
    opacity: 0;
    transition-property: opacity, transform;
    transition-duration: var(--duration-reveal);
    transition-timing-function: var(--ease-emphasized);
    transition-delay: var(--reveal-delay, 0ms);
    will-change: opacity, transform;
}

.reveal.is-visible {
    opacity: 1;
    transform: none;
}

/* Variants used on the page: rise up, or fade only */
.reveal-up {
    transform: translateY(var(--reveal-offset));
}

.reveal-fade {
    transform: none;
    /* opacity only — for media where movement distorts */
}

/* Hover lift for the Referenzen logos, the team and project cards (and
   the diagram tiles, in assets/html/unserAngebot.html) — the same
   4px rise, speed and easing as the testimonial cards. It uses the
   separate `translate` property, not `transform`: the team cards carry
   the scroll-reveal above, which owns `transform` (and would otherwise
   cancel the lift), so the two can't collide. The team cards' own
   transition list keeps the reveal's slow timing for opacity/transform
   and adds the quick one for the lift. Only where hovering is real —
   on touch a tap would leave a card stuck in the lifted state. */
.logo-grid__item {
    transition: translate var(--duration-base) var(--ease-standard);
}

.team-card.reveal,
.portfolio-card.reveal {
    transition-property: opacity, transform, translate;
    transition-duration: var(--duration-reveal), var(--duration-reveal), var(--duration-base);
    transition-timing-function: var(--ease-emphasized), var(--ease-emphasized), var(--ease-standard);
    transition-delay: var(--reveal-delay, 0ms), var(--reveal-delay, 0ms), 0s;
}

@media (hover: hover) and (pointer: fine) {
    .logo-grid__item:hover,
    .team-card:hover,
    .portfolio-card:hover {
        translate: 0 -4px;
    }
}

/* ------------------------------------------------------------------ *
 * 3. Marquees — continuous horizontal auto-scroll, single row each.
 * .logo-grid / .testimonial-grid (in layout.css) are each ONE flat
 * list: the visible set immediately followed by an identical
 * `aria-hidden` duplicate set, every item carrying its own trailing
 * margin (not a container `gap`).
 *
 * The shift below is deliberately NOT `-50%`. Both the list's width
 * (layout.css) and this shift are the same explicit calc() — item
 * count x (item width + margin) — computed from our own tokens
 * rather than trusted to the browser's intrinsic `max-content`
 * sizing of two duplicated flex sets. `-50%` should be equivalent in
 * theory, but proved unreliable in practice (the animation would
 * stop advancing after the first pass instead of looping). Hardcoding
 * both sides of the same formula removes that dependency entirely.
 * ------------------------------------------------------------------ */

/* --marquee-count = items per copy. The defaults (39 logos, 10
   testimonials) are what index.html contains; scripts/cms-content.js sets
   the real number when the CMS content arrives. The duration scales with
   it, so the speed (seconds per item) stays the same however many
   entries there are: --marquee-duration-* is the time for the defaults. */
.logo-grid {
    animation: logo-marquee-scroll calc(var(--marquee-duration-logos) * var(--marquee-count, 39) / 39) linear infinite;
}

.testimonial-grid {
    animation: testimonial-marquee-scroll calc(var(--marquee-duration-testimonials) * var(--marquee-count, 10) / 10) linear infinite;
}

.logo-marquee:hover .logo-grid,
.logo-marquee:focus-within .logo-grid,
.testimonial-marquee:hover .testimonial-grid,
.testimonial-marquee:focus-within .testimonial-grid {
    /* pause so a visitor can actually read/click mid-scroll */
    animation-play-state: paused;
}

/* one full copy of the logos (--marquee-count items; 39 by default) */
@keyframes logo-marquee-scroll {
    from {
        transform: translateX(0);
    }

    to {
        transform: translateX(calc(-1 * var(--marquee-count, 39) * (var(--marquee-item-width-logo) + var(--space-5))));
    }
}

/* one full copy of the testimonials (--marquee-count items; 10 by default) */
@keyframes testimonial-marquee-scroll {
    from {
        transform: translateX(0);
    }

    to {
        transform: translateX(calc(-1 * var(--marquee-count, 10) * (var(--marquee-item-width-testimonial) + var(--marquee-gap-testimonial))));
    }
}

/* ------------------------------------------------------------------ *
 * 4. Hero headline typewriter. Each line is its own width-reveal
 * (classic overflow:hidden + white-space:nowrap + animated width),
 * sized in `ch` with a little headroom so the last character never
 * clips. Line 2 is delayed to start exactly when line 1 finishes, so
 * it reads as one continuous type-out across both lines rather than
 * two independent effects. The quote/body/CTA `--reveal-delay`
 * values (set inline in index.html: 900 / 1000 / 1100ms) start while
 * the second line is still typing (it ends at 1650ms), so the text
 * follows the headline without a pause.
 * ------------------------------------------------------------------ */

.hero-headline__chars {
    display: inline-block;
    overflow: hidden;
    white-space: nowrap;
    vertical-align: top;
    width: 0;
}

/* `ch` is based on the font's "0" glyph, which tends to be narrower
   than this font's actual bold/900-weight uppercase letters — each
   target width is padded well past its literal character count
   (11 and 14) so the last glyph never clips. The extra revealed
   width is empty inline-block space, invisible either way. */
.hero-headline__line--1 .hero-headline__chars {
    animation: typewriter-line1 600ms steps(12, end) 300ms forwards;
    /* 300ms: small pause after page load before typing starts */
}

.hero-headline__line--2 .hero-headline__chars {
    animation: typewriter-line2 750ms steps(15, end) 900ms forwards;
    /* 900ms = 300ms initial pause + 600ms line 1 duration */
}

@keyframes typewriter-line1 {
    to {
        width: 14ch;
    }
}

@keyframes typewriter-line2 {
    to {
        width: 17ch;
    }
}

/* ------------------------------------------------------------------ *
 * Respect reduced-motion preference: show content immediately, no
 * animation at all — not optional for a professional site.
 * ------------------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {

    .reveal,
    .reveal.is-visible,
    .portfolio-card:hover,
    .testimonial-card:hover,
    .logo-grid__item:hover .logo-grid__picture img {
        transition: none;
        transform: none;
        opacity: 1;
    }

    /* no hover lift either */
    .logo-grid__item,
    .logo-grid__item:hover,
    .team-card.reveal,
    .team-card:hover,
    .portfolio-card.reveal,
    .portfolio-card:hover {
        transition: none;
        translate: none;
    }

    .service-tabs__panel,
    .service-tabs__indicator,
    .site-nav__link,
    .site-nav__link::before,
    .site-nav__panel,
    .site-nav__toggle-bar,
    .team-card__details,
    .team-card__contact-link,
    .team-member-toggle::after {
        transition: none;
    }

    .hero-headline__chars {
        animation: none;
        width: auto;
        overflow: visible;
    }

    .logo-grid,
    .testimonial-grid {
        animation: none;
    }

    .logo-marquee,
    .testimonial-marquee {
        overflow-x: auto;
    }

    /* the duplicate items exist only to make the loop seamless; with
       the animation off they'd just repeat the same set a second
       time, so hide them. */
    .logo-grid__item[aria-hidden="true"],
    .testimonial-card[aria-hidden="true"] {
        display: none;
    }
}
