/* Tokens live in css/tokens.css. Kept as an alias so existing rules still read. */
:root {
    --background-color: var(--color-bg);
}

#main-page {
    display: flex;
}

#generation-group {
    width: 90%;
    /* Capped, so an ultrawide screen does not put six puppies on one row and
       orphan the seventh. It also stops the tree stretching to a width nobody
       reads comfortably. */
    max-width: 1500px;
    margin: 0 auto;
}

body {
    background-color: var(--color-bg);
    color: var(--color-ink);
    font-family: var(--font-body);
    font-size: var(--text-base);
}

body,
html {
    margin: 0;
    padding: 0;
}

canvas {
    pointer-events: none;
}

/* The connector canvas scrolls WITH the page — it is positioned and sized in
   document space by js/drawings.js. A fixed canvas cannot track compositor
   scrolling, which is what made the lines trail the bubbles. */
#bgCanvas {
    position: absolute;
    left: 0;
    z-index: var(--z-bg);

    /* Collapsed until drawings.js measures the tree and sets the real top,
       width and height. A <canvas> with no CSS size renders at its intrinsic
       300x150, so the element painted a box in the wrong place on first frame
       and then jumped to full document size — 0.50 of the page's 0.70 CLS, all
       of it from an element that draws nothing anyone can see. Starting at
       zero area means there is nothing to shift: an element with no visible
       box is not an unstable element. */
    top: 0;
    width: 0;
    height: 0;
}

/* The grass is anchored to the bottom of the viewport by design, so it stays
   fixed — it represents the ground the page sits on, not part of the content. */
#grassCanvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: var(--z-grass);
}

.generation {
    display: flex;
    /* Row gap is deliberately larger than the column gap: when a row wraps, the
       bone name tag hangs below its bubble and the next row's photos would
       otherwise sit right under it. */
    gap: 3.5rem 2vw;
    /* Was nowrap, which meant a big litter never wrapped — it just squeezed.
       Seven puppies came out at 158px against five at 242px on the same
       screen, so the biggest litter was shown smallest. */
    flex-wrap: wrap;
    justify-content: center;
}

#generation-puppies {
    min-height: 40vh;
    padding-top: 5vh;
}

/* A floor on bubble size, so a litter of seven wraps onto a second row instead
   of shrinking to fit one. No flex-grow: every bubble in every row is the same
   size, which matters more than filling the last row edge to edge. */
#generation-puppies .carousel-container {
    flex: 0 1 250px;
    min-width: 220px;
    width: auto;
}

#generation-parents {
    min-height: 35vh;
    padding-top: 10vh;
}

#generation-elders {
    min-height: 25vh;
    padding-top: 15vh;
    padding-bottom: 5vh;
}

.dog-tag {
    display: inline-block;
    width: 120px;
    height: 60px;
    cursor: pointer;
    transition: transform 0.2s ease-in-out;
}

.dog-tag:hover {
    transform: scale(1.1);
}

.dog-tag-svg {
    width: 100%;
    height: 100%;
}

/* ---- Page header ------------------------------------------------------
   The page used to open straight onto the puppies with no title at all. */
.page-header {
    text-align: center;
    /* The top padding clears the branch under the sticky bar. It is generous
       on purpose: the branch is decorative and the title is the page, and the
       two touching reads as a mistake rather than as a flourish. */
    padding: var(--space-xl) var(--space-md) var(--space-sm);
}

.page-title {
    font-family: var(--font-display);
    font-size: var(--text-xl);
    font-weight: 400;
    line-height: 1;
    letter-spacing: 0.01em;
    margin: 0;
    color: var(--color-ink);
}

.page-title-join {
    color: var(--color-heart-text);
    font-style: italic;
    padding: 0 0.1em;
}

.page-subtitle {
    font-family: var(--font-body);
    font-size: var(--text-base);
    color: var(--color-ink-soft);
    margin: var(--space-sm) auto 0;
    max-width: 46ch;
    text-wrap: balance;
}

/* ---- Share card -------------------------------------------------------
   The QR works in person; the written address works in a family group
   chat. The block is the sharing corner of the page, so it carries both. */
.share {
    display: flex;
    justify-content: center;
    padding: var(--space-xl) var(--space-md) calc(var(--space-xl) * 1.6);
}

.share-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-lg) var(--space-lg);
    background: var(--color-paper);
    border-radius: 1.25rem;
    box-shadow: 0 10px 30px rgb(58 47 42 / 12%);
    max-width: min(90vw, 26rem);
}

.share-title {
    font-family: var(--font-display);
    font-size: var(--text-lg);
    font-weight: 400;
    margin: 0;
    color: var(--color-ink);
}

.share-qr {
    width: min(60vw, 15rem);
    height: auto;
    aspect-ratio: 1 / 1;
}

.share-hint {
    font-size: var(--text-sm);
    color: var(--color-ink-soft);
    margin: 0;
}

.share-link {
    font-size: var(--text-sm);
    color: var(--color-heart-text);
    text-decoration: none;
    border-bottom: 1px solid currentColor;
    word-break: break-all;
    text-align: center;
    transition: color var(--motion-fast) var(--ease-out);
}

.share-link:hover {
    color: var(--heart-3);
}


/* ---- Static fallback --------------------------------------------------
   index.html carries the whole family as real markup (tools/build-html.mjs).
   Normally the scripts replace it with the carousels; if they never run —
   the classic case being index.html opened via file://, where ES modules are
   CORS-blocked — this is what a visitor sees instead of a blank page. */
.generation-title {
    text-align: center;
    font-family: var(--font-display);
    font-size: var(--text-lg);
    font-weight: 400;
    color: var(--color-ink-soft);
    margin: 0 0 var(--space-sm);
}

.dog {
    margin: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-xs);
    max-width: var(--bubble-max);
}

.dog-photo {
    width: 100%;
    max-width: 15rem;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    border-radius: 50%;
    border: 3px solid rgba(var(--dog-color, 40,40,255), 0.8);
    box-shadow: 0 5px 12px rgba(var(--dog-color, 40,40,255), 0.4);
}

.dog-name {
    font-family: var(--font-display);
    font-size: var(--text-lg);
    color: var(--color-ink);
}

.dog-fullname {
    font-size: var(--text-sm);
    color: var(--color-ink-soft);
    margin: 0;
    font-style: italic;
}

/* The pedigree link in the static fallback. The enhanced page tucks the same
   link into the bubble's corner (.carousel-pedigree in carrousel.css); here
   there are no bubbles, so it simply follows the name. */
.dog-pedigree {
    font-size: var(--text-sm);
    color: var(--color-ink-soft);
}

/* Once the carousels exist, the generation headings would duplicate the bone
   tags, so the enhanced page hides them. */
.js-enhanced .generation-title {
    display: none;
}

/* The enhanced layout positions bubbles absolutely inside fixed-height bands so
   the connector canvas can find them. The fallback has no canvas and no
   carousels, so it gets a plain centred stack instead — otherwise it inherits
   those heights and nowrap, and the photos come out as stretched ellipses. */
html:not(.js-enhanced) #generation-group {
    margin: 0 auto;
    width: min(100% - 2rem, 70rem);
}

html:not(.js-enhanced) .generation {
    display: block;
    height: auto;
    padding: var(--space-md) 0;
    text-align: center;
}

html:not(.js-enhanced) .generation .dog {
    display: inline-flex;
    vertical-align: top;
    margin: var(--space-sm);
}

html:not(.js-enhanced) .dog-photo {
    width: 11rem;
    height: 11rem;
    max-width: none;
    flex: none;
}

html:not(.js-enhanced) #slider-group {
    display: none;
}

.data-error {
    margin: var(--space-sm) auto 0;
    font-size: var(--text-sm);
    color: var(--color-ink-soft);
}

/* ---- Reduced motion ---------------------------------------------------
   Three animation systems run here at once. Someone who asks for less
   motion should get a still, readable page — but deliberate interaction
   (pulling a connector line, opening a photo) keeps working. */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    .carousel:hover .carousel-item {
        transform: none;
    }
}

/* ---- Print ------------------------------------------------------------
   A family tree is a thing people put on a fridge. Drop the animated
   scenery and the sharing furniture, keep the family. */
@media print {
    #bgCanvas,
    #grassCanvas,
    #slider-group,
    .share,
    .carousel-dots {
        display: none !important;
    }

    html, body {
        overflow: visible !important;
        background: #fff;
    }

    .generation {
        height: auto !important;
        padding: 0 !important;
        page-break-inside: avoid;
    }

    .generation-title {
        display: block !important;
    }

    .carousel-container {
        break-inside: avoid;
    }
}

/* Marks a preview page as an experiment rather than the real site. */
.page-variant {
    margin: var(--space-sm) auto 0;
    font-size: var(--text-sm);
    color: var(--color-ink-soft);
}

.page-variant a { color: var(--color-heart-text); }

/* Static placeholder for a dog with no photos (see tools/build-html.mjs). */
.dog--placeholder .dog-placeholder {
    display: block;
    width: 11rem;
    height: 11rem;
    max-width: 15rem;
    border-radius: 50%;
    border: 3px solid rgba(var(--dog-color, 120,120,120), 0.5);
    background:
        rgba(var(--dog-color, 120,120,120), 0.12)
        url("../img/elements/patte.svg") center / 42% no-repeat;
    opacity: 0.7;
}
