/* Matariki Stars — entrance + transition choreography
   Reference grammar: matariki.com 2026 Herenga Waka hero + Apple Aerial pacing
   + screensaver-motion-graphics-research §3.4 (heliacal rising).
   Cultural reference: Te Waka o Rangi — the celestial canoe whose stars
   are Tautoru (stern) + Hyades + Matariki cluster (prow). Stars rise from
   below the horizon, settle into the waka shape, then the outline traces
   between them before fading to leave the cluster.

   Reduced-motion users get a fade-only fallback. */

/* ──────────────── Generic entrance ──────────────── */
.fade-in {
    opacity: 0;
    animation: fade-in-up 0.9s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
.fade-in.delay-1 { animation-delay: 0.10s; }
.fade-in.delay-2 { animation-delay: 0.25s; }
.fade-in.delay-3 { animation-delay: 0.40s; }
.fade-in.delay-4 { animation-delay: 0.55s; }
.fade-in.delay-5 { animation-delay: 0.70s; }
.fade-in.delay-6 { animation-delay: 0.85s; }

@keyframes fade-in-up {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ──────────────── Cluster page — Te Waka o Rangi ──────────────── */

.waka-stage {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 10;
    margin: 18px 0 30px;
    border-radius: 22px;
    overflow: hidden;
    background:
        radial-gradient(ellipse 80% 40% at 50% 95%, rgba(218,119,86,0.35) 0%, transparent 70%),
        radial-gradient(ellipse 60% 50% at 30% 30%, rgba(168,204,255,0.05) 0%, transparent 60%),
        linear-gradient(180deg, #03050D 0%, #0A0E2A 55%, #1A1230 92%, #2a1620 100%);
    box-shadow:
        0 0 0 1px rgba(201,149,30,0.18) inset,
        0 20px 60px rgba(0,0,0,0.4);
}

/* The horizon line — a thin warm gradient at 92% */
.waka-stage::after {
    content: '';
    position: absolute;
    left: 4%; right: 4%;
    bottom: 7%;
    height: 1px;
    background: linear-gradient(to right,
        transparent 0%,
        rgba(218,119,86,0.6) 30%,
        rgba(218,119,86,0.85) 50%,
        rgba(218,119,86,0.6) 70%,
        transparent 100%);
    z-index: 2;
}

/* The traced waka outline — SVG path; drawn after stars settle */
.waka-line {
    position: absolute; inset: 0;
    pointer-events: none;
    z-index: 3;
}

.waka-line path {
    stroke: rgba(201, 149, 30, 0.55);
    stroke-width: 1.2;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
    filter: drop-shadow(0 0 4px rgba(201, 149, 30, 0.4));
    /* Drawn between 1.6s → 3.6s after page load */
    stroke-dasharray: 1500;
    stroke-dashoffset: 1500;
    animation: trace-waka 2.2s cubic-bezier(0.22, 1, 0.36, 1) forwards;
    animation-delay: 2.4s;
}

.waka-line path.fade-after {
    animation: trace-waka 2.2s cubic-bezier(0.22, 1, 0.36, 1) forwards,
               trace-fade 2.6s ease-out forwards;
    animation-delay: 2.4s, 6.5s;
}

@keyframes trace-waka {
    to { stroke-dashoffset: 0; }
}
@keyframes trace-fade {
    from { opacity: 1; }
    to   { opacity: 0.18; }
}

/* The waka-label */
.waka-label {
    position: absolute;
    bottom: 14px;
    left: 50%;
    transform: translateX(-50%);
    font-family: 'Cinzel', Georgia, serif;
    font-size: 0.66rem;
    letter-spacing: 5px;
    text-transform: uppercase;
    color: rgba(201, 149, 30, 0.7);
    z-index: 5;
    opacity: 0;
    animation: fade-in 0.8s ease-out forwards;
    animation-delay: 4.8s;
}
@keyframes fade-in { to { opacity: 1; } }

/* Individual star tiles on the stage */
.waka-star {
    position: absolute;
    transform: translate(-50%, -50%);
    z-index: 4;
    width: 110px;
    text-align: center;
    text-decoration: none;
    color: var(--text-primary);
    transition: filter 0.4s ease, opacity 0.4s ease;
    /* Initial: above horizon (off-screen top) + transparent */
    opacity: 0;
    animation: heliacal-rise 1.4s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.waka-star .dot {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    margin: 0 auto;
    background: radial-gradient(circle, #ffffff 0%, var(--star-color, #a8ccff) 40%, transparent 75%);
    box-shadow:
        0 0 12px var(--star-color, #a8ccff),
        0 0 28px rgba(168, 204, 255, 0.55);
    animation: star-pulse 4.5s ease-in-out infinite;
    animation-delay: 4s; /* Begin pulsing AFTER they've settled */
}

.waka-star.pohutukawa .dot {
    animation: pohutukawa-breathe 8s ease-in-out infinite;
    animation-delay: 4s;
}

.waka-star .label {
    font-family: 'Cinzel', Georgia, serif;
    font-size: 0.62rem;
    letter-spacing: 1.8px;
    text-transform: uppercase;
    color: rgba(244, 238, 223, 0.85);
    margin-top: 6px;
    text-shadow: 0 0 8px rgba(0, 0, 0, 0.6);
    opacity: 0;
    animation: fade-in 0.6s ease-out forwards;
    animation-delay: 3.4s;
}

.waka-star:hover .dot {
    transform: scale(1.4);
    filter: brightness(1.4);
}
.waka-star:hover .label {
    color: var(--gold-bright);
}

/* Heliacal rise — drift up from below horizon to position */
@keyframes heliacal-rise {
    0%   { opacity: 0; transform: translate(-50%, calc(-50% + 200px)); filter: brightness(0.4); }
    60%  { opacity: 1; filter: brightness(0.9); }
    100% { opacity: 1; transform: translate(-50%, -50%); filter: brightness(1); }
}

@keyframes star-pulse {
    0%, 100% { filter: brightness(1); }
    50%      { filter: brightness(1.25); }
}

@keyframes pohutukawa-breathe {
    0%, 100% { filter: brightness(0.85); }
    50%      { filter: brightness(1.05); }
}

/* Stagger heliacal rise per star — index-based delay */
.waka-star.s1  { animation-delay: 0.20s; }
.waka-star.s2  { animation-delay: 0.45s; }
.waka-star.s3  { animation-delay: 0.70s; }
.waka-star.s4  { animation-delay: 0.85s; }
.waka-star.s5  { animation-delay: 1.00s; }
.waka-star.s6  { animation-delay: 1.15s; }
.waka-star.s7  { animation-delay: 1.30s; }
.waka-star.s8  { animation-delay: 1.45s; }
.waka-star.s9  { animation-delay: 1.60s; }
.waka-star.s10 { animation-delay: 1.85s; }

/* ──────────────── Star tile click — forward + left ──────────────── */
.waka-star.selected {
    z-index: 99;
    animation: select-forward 0.6s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}
.waka-stage.dimming .waka-star:not(.selected) {
    opacity: 0.18;
    filter: blur(2px);
}
.waka-stage.dimming .waka-line { opacity: 0.05; }

@keyframes select-forward {
    0%   { transform: translate(-50%, -50%) scale(1); }
    100% { transform: translate(calc(-50% - 90px), -50%) scale(1.55); }
}

/* ──────────────── Star page — image-right, content-left ──────────────── */

.star-detail-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 28px;
    margin-top: 18px;
}

@media (min-width: 900px) {
    .star-detail-grid {
        grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
        gap: 40px;
        align-items: start;
    }
    .star-detail-image {
        position: sticky;
        top: 28px;
    }
}

.star-detail-content > * {
    opacity: 0;
    animation: fade-in-up 0.7s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
.star-detail-content > *:nth-child(1) { animation-delay: 0.50s; }
.star-detail-content > *:nth-child(2) { animation-delay: 0.65s; }
.star-detail-content > *:nth-child(3) { animation-delay: 0.80s; }
.star-detail-content > *:nth-child(4) { animation-delay: 0.95s; }
.star-detail-content > *:nth-child(5) { animation-delay: 1.10s; }
.star-detail-content > *:nth-child(6) { animation-delay: 1.25s; }
.star-detail-content > *:nth-child(7) { animation-delay: 1.40s; }

.star-detail-image {
    opacity: 0;
    transform: translateX(60px);
    animation: slide-in-right 1.0s cubic-bezier(0.22, 1, 0.36, 1) forwards;
    animation-delay: 0.15s;
}
@keyframes slide-in-right {
    to { opacity: 1; transform: translateX(0); }
}

.star-hero {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 5;
    border-radius: 22px;
    overflow: hidden;
    box-shadow:
        0 0 0 1px rgba(201, 149, 30, 0.22) inset,
        0 24px 80px rgba(0, 0, 0, 0.55);
}
.star-hero img {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    object-fit: cover;
    transform: scale(1.08);
    transition: transform 12s ease-out;
}
.star-hero.loaded img { transform: scale(1.0); }

.star-hero-overlay {
    position: absolute; inset: 0;
    background:
        radial-gradient(circle at 40% 40%, transparent 0%, rgba(0,8,20,0.6) 85%),
        linear-gradient(180deg, rgba(0,8,20,0.1) 0%, rgba(0,8,20,0.85) 100%);
    z-index: 2;
}

.star-hero-marker {
    /* The "you are here" pin on the wide-field — placed by the star's
       coordinates within the Pleiades frame. CSS variable provided per star. */
    position: absolute;
    left: var(--marker-x, 50%);
    top: var(--marker-y, 40%);
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 2px solid var(--gold-bright);
    transform: translate(-50%, -50%);
    box-shadow: 0 0 22px rgba(224, 176, 48, 0.85), inset 0 0 8px rgba(224, 176, 48, 0.4);
    z-index: 3;
    animation: marker-pulse 2.4s ease-in-out infinite;
}
@keyframes marker-pulse {
    0%, 100% { transform: translate(-50%, -50%) scale(1);   box-shadow: 0 0 22px rgba(224, 176, 48, 0.85); }
    50%      { transform: translate(-50%, -50%) scale(1.18); box-shadow: 0 0 36px rgba(224, 176, 48, 1); }
}

.star-hero-caption {
    position: absolute;
    bottom: 12px; left: 14px; right: 14px;
    color: rgba(244, 238, 223, 0.7);
    font-family: 'Cinzel', Georgia, serif;
    font-size: 0.58rem;
    letter-spacing: 2px;
    text-transform: uppercase;
    z-index: 4;
    line-height: 1.4;
}

/* Waka context strip — under the karakia panel */
.waka-context {
    background: linear-gradient(135deg, rgba(201,149,30,0.08), rgba(168,204,255,0.04));
    border: 1px solid rgba(201, 149, 30, 0.22);
    border-radius: 14px;
    padding: 14px 18px;
    font-size: 0.92rem;
    color: var(--text-secondary);
    font-style: italic;
    line-height: 1.6;
}
.waka-context strong { color: var(--gold-bright); font-style: normal; }

/* ──────────────── View Transitions API ──────────────── */
@supports (view-transition-name: x) {
    .waka-star { view-transition-name: var(--vt-name); }
    ::view-transition-group(*) { animation-duration: 0.7s; }
    ::view-transition-old(root) { animation: vt-fade-out 0.4s ease-out forwards; }
    ::view-transition-new(root) { animation: vt-fade-in 0.5s ease-out 0.2s backwards; }
}
@keyframes vt-fade-out { to { opacity: 0; } }
@keyframes vt-fade-in  { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ──────────────── Reduced motion ──────────────── */
@media (prefers-reduced-motion: reduce) {
    .waka-star,
    .waka-line path,
    .waka-line path.fade-after,
    .waka-label,
    .star-detail-image,
    .star-detail-content > *,
    .fade-in,
    .star-hero img {
        animation: none !important;
        transition: none !important;
        opacity: 1 !important;
        transform: none !important;
        stroke-dashoffset: 0 !important;
    }
    .waka-star .dot { animation: none !important; }
    .star-hero img { transform: none !important; }
}
