/* =====================================================================
 * Downloads — apps hub.
 *
 * Hero archetype (§8.1) opening into an editorial row list. The previous
 * revision used a card grid; a card must reserve height for a CTA it may
 * not have, so every "coming soon" platform rendered as a tall empty box.
 * Rows collapse to their content, which is what lets the page read as
 * finished whether six platforms ship or none do.
 *
 * All colour flows from design tokens; the ONLY hex literals are the
 * iridescent hero-mark stops in downloads.ejs (DESIGN.md §1 — the mark is
 * this surface's single iridescent moment). Korean keep-all throughout;
 * motion mirrors main.css and honours prefers-reduced-motion.
 * ===================================================================== */

/* Collapse the centered content wrapper so the hub bleeds full-width,
   matching the About / main long-form archetype. */
#wrapper-contents:has(#downloads-page) {
    padding: 0;
    margin: 0;
    display: block;
    float: none;
    align-items: initial;
    justify-content: initial;
    background-color: var(--global-body-background);
    overflow-x: clip;
}

#downloads-page {
    --dl-ease: cubic-bezier(0.22, 0.61, 0.36, 1);
    --dl-ease-spring: cubic-bezier(0.16, 1, 0.3, 1);
    --dl-pad-x: clamp(20px, 5vw, 80px);
    --dl-content-max: 880px;

    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(56px, 9vh, 112px);
    width: 100%;
    min-height: calc(100vh - var(--header-height) - var(--footer-height));
    padding: clamp(64px, 12vh, 128px) var(--dl-pad-x) clamp(72px, 12vh, 140px);
    box-sizing: border-box;
    color: var(--global-text-color);
    font-family: 'Pretendard Variable', Pretendard, -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
    overflow-x: clip;
    word-break: keep-all;
    overflow-wrap: anywhere;
    isolation: isolate;
}

/* ---------- Jewel aura — §2.4 recipe, held at main.css intensity ---------- */
.dl-aura {
    position: absolute;
    inset: 0 0 auto 0;
    height: 78vh;
    z-index: -1;
    pointer-events: none;
    background:
        radial-gradient(38% 48% at 22% 30%, rgba(var(--brand-iris-rgb),     0.16), transparent 70%),
        radial-gradient(34% 42% at 78% 22%, rgba(var(--brand-mulberry-rgb), 0.13), transparent 72%),
        radial-gradient(40% 46% at 62% 72%, rgba(var(--brand-lichen-rgb),   0.13), transparent 70%),
        radial-gradient(36% 40% at 18% 78%, rgba(var(--brand-brass-rgb),    0.11), transparent 72%);
    filter: blur(76px) saturate(104%);
    opacity: 0.58;
    animation: dl-aura-drift 26s ease-in-out infinite alternate;
}
@keyframes dl-aura-drift {
    0%   { transform: translate3d(-3%, -2%, 0) scale(1); }
    100% { transform: translate3d( 3%,  1%, 0) scale(1.05); }
}

/* =====================================================================
 * 01 · HERO
 * ===================================================================== */
.dl-hero {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(16px, 2.6vh, 26px);
    max-width: 720px;
    text-align: center;
}

.dl-mark {
    width: clamp(56px, 6.5vw, 84px);
    aspect-ratio: 603 / 958;
    opacity: 0;
    transform: translateY(8px) scale(0.96);
    animation: dl-fade-in 1.4s var(--dl-ease-spring) 0.1s forwards;
}
.dl-mark svg {
    width: 100%;
    height: 100%;
    overflow: hidden;
    /* brand-tinted drop-shadow per §6.2 — never plain black */
    filter: drop-shadow(0 12px 40px rgba(var(--brand-iris-rgb), 0.22));
}
.dl-mark-base { transform-origin: 50% 50%; transform-box: fill-box; }
@keyframes dl-fade-in { to { opacity: 1; transform: translateY(0) scale(1); } }

.dl-title {
    margin: 0;
    font-size: clamp(32px, 5vw, 56px);
    font-weight: 800;
    letter-spacing: -0.04em;
    line-height: 1.08;
}
.dl-tagline {
    margin: 0;
    max-width: 32ch;
    font-size: clamp(15px, 1.5vw, 18px);
    font-weight: 400;
    color: var(--global-text-muted);
    line-height: 1.65;
    letter-spacing: -0.005em;
}

.dl-hero-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    margin-top: clamp(8px, 1.6vh, 16px);
}

/* Primary — the one action for this visitor. Server-rendered as the web
   CTA (true for everyone, needs no detection); downloads.js swaps the
   label and href when the visitor's own platform actually ships. */
.dl-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 48px;
    padding: 0 28px;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--global-button-text-color);
    background: var(--global-button-background-color);
    border-radius: 999px;
    text-decoration: none;
    transition: opacity 0.3s var(--dl-ease), transform 0.3s var(--dl-ease-spring);
}
.dl-primary:hover { opacity: 0.88; transform: translateY(-1px); }
.dl-primary:focus-visible { outline: 2px solid var(--focus-outline-color); outline-offset: 2px; }
.dl-primary-meta { font-weight: 500; font-size: 12px; opacity: 0.7; }

.dl-secondary {
    font-size: 13px;
    font-weight: 500;
    letter-spacing: -0.005em;
    color: var(--global-text-muted);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    padding-bottom: 2px;
    transition: color 0.3s var(--dl-ease), border-color 0.3s var(--dl-ease);
}
.dl-secondary:hover {
    color: var(--global-text-color);
    border-bottom-color: rgba(var(--global-text-color-rgb), 0.25);
}
.dl-secondary:focus-visible { outline: 2px solid var(--focus-outline-color); outline-offset: 2px; }

/* =====================================================================
 * 02 · TIERS
 * ===================================================================== */
.dl-tiers {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: var(--dl-content-max);
    display: flex;
    flex-direction: column;
    gap: clamp(48px, 8vh, 88px);
    /* Anchor target: clear the sticky header when jumped to. */
    scroll-margin-top: calc(var(--header-height) + 24px);
}

.dl-tier-head {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-bottom: clamp(18px, 2.6vh, 26px);
}
/* Tier ordinal — the same quiet numeral About uses on its pillars. */
.dl-tier-index {
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.12em;
    font-variant-numeric: tabular-nums;
    color: var(--global-text-muted);
    opacity: 0.6;
    line-height: 1;
}
.dl-eyebrow {
    margin: 0;
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--global-text-color);
    line-height: 1;
}
.dl-tier-caption {
    margin: 0;
    max-width: 46ch;
    font-size: clamp(14px, 1.3vw, 16px);
    color: var(--global-text-muted);
    line-height: 1.65;
    letter-spacing: -0.005em;
}

/* ---------- Platform rows ---------- */
.dl-rows {
    margin: 0;
    padding: 0;
    list-style: none;
}
.dl-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: clamp(16px, 3vw, 40px);
    padding: clamp(18px, 2.4vw, 24px) 0;
    border-top: 1px solid rgba(var(--global-text-color-rgb), 0.08);
}
.dl-row:last-child { border-bottom: 1px solid rgba(var(--global-text-color-rgb), 0.08); }

.dl-row-id {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 6px 12px;
    min-width: 0;
}
.dl-row-name {
    font-size: clamp(18px, 2vw, 24px);
    font-weight: 600;
    letter-spacing: -0.02em;
    line-height: 1.25;
}
.dl-row-sub {
    font-size: 13px;
    color: var(--global-text-muted);
    letter-spacing: -0.005em;
    overflow-wrap: normal;
}
/* "Your device" — revealed by downloads.js on the matching row only. */
.dl-row-here {
    display: none;
    padding: 3px 9px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--global-button-text-color);
    background: var(--global-text-color);
    border-radius: 999px;
}
.dl-row.is-detected .dl-row-here { display: inline-flex; }

/* A platform with nothing to download recedes rather than disappearing —
   it still tells a visitor their OS is on the list. */
.dl-row.is-soon .dl-row-name { color: var(--global-text-muted); font-weight: 500; }

.dl-row-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 10px 14px;
}

/* Direct download — our own pill, for installers served from the CDN. */
.dl-get {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 40px;
    padding: 0 20px;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: -0.01em;
    white-space: nowrap;
    color: var(--global-button-text-color);
    background: var(--global-button-background-color);
    border-radius: 999px;
    text-decoration: none;
    transition: opacity 0.3s var(--dl-ease), transform 0.3s var(--dl-ease-spring);
}
.dl-get:hover { opacity: 0.88; transform: translateY(-1px); }
.dl-get:focus-visible { outline: 2px solid var(--focus-outline-color); outline-offset: 2px; }
.dl-get-meta { font-weight: 500; font-size: 12px; opacity: 0.7; }

/* Store link — the OFFICIAL badge, unaltered. The wrapper supplies the
   brand-required clear space (>= 1/4 of the badge height) as padding; the
   art is never recoloured or resized beyond its own aspect. */
.dl-store {
    display: inline-flex;
    padding: 10px;
    margin: -10px;
    border-radius: 12px;
    transition: background 0.3s var(--dl-ease), transform 0.3s var(--dl-ease-spring);
}
.dl-store:hover { background: var(--state-hover-bg); transform: translateY(-1px); }
.dl-store:focus-visible { outline: 2px solid var(--focus-outline-color); outline-offset: 2px; }
.dl-store-img { height: 40px; width: auto; display: block; }
/* Google ships its badge with the required clear space baked into the
   artwork (646x250 with ~10% transparent margin), where Apple's and
   Microsoft's SVGs are edge-to-edge. Matching the box heights therefore
   renders Google's visibly smaller — scaling the whole asset up is what
   Google's own guidelines call for, and it optically matches the others. */
.dl-store-img[src*="google-play"] { height: 50px; }

/* Coming-soon pill — neutral state tokens only, so the brand palette
   stays reserved for the mark and the aura. */
.dl-soon {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    font-size: 12.5px;
    font-weight: 500;
    letter-spacing: 0.02em;
    color: var(--global-text-muted);
    background: var(--state-active-bg);
    border-radius: 999px;
    white-space: nowrap;
}

/* =====================================================================
 * 03 · ROLLUP — a tier with nothing to download, reduced to one line
 * ===================================================================== */
.dl-rollup {
    position: relative;
    z-index: 1;
    margin: 0;
    max-width: 46ch;
    text-align: center;
    font-size: 14px;
    line-height: 1.7;
    letter-spacing: -0.005em;
    color: var(--global-text-muted);
}

/* =====================================================================
 * 04 · EXTRAS
 * ===================================================================== */
.dl-extras {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: var(--dl-content-max);
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: clamp(12px, 1.6vw, 20px);
}
.dl-extra {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: clamp(20px, 2.4vw, 28px);
    border: 1px solid var(--global-border-color);
    border-radius: 18px;
    background: var(--global-card-background);
    text-decoration: none;
    transition:
        transform 0.5s var(--dl-ease-spring),
        border-color 0.5s var(--dl-ease),
        box-shadow 0.5s var(--dl-ease);
}
.dl-extra:hover {
    transform: translateY(-3px);
    border-color: rgba(var(--global-text-color-rgb), 0.04);
    /* §6.3 ambient bloom, one step down for tiles — matches main's surfaces. */
    box-shadow:
        -22px -14px 50px -10px rgba(var(--brand-iris-rgb),     0.18),
         22px -14px 50px -10px rgba(var(--brand-mulberry-rgb), 0.16),
         22px  22px 56px -10px rgba(var(--brand-brass-rgb),    0.14),
        -22px  22px 56px -10px rgba(var(--brand-lichen-rgb),   0.12),
          0   28px 56px -24px rgba(var(--global-text-color-rgb), 0.16);
}
.dl-extra:focus-visible { outline: 2px solid var(--focus-outline-color); outline-offset: 2px; }
.dl-extra-name {
    font-size: clamp(15px, 1.5vw, 17px);
    font-weight: 600;
    letter-spacing: -0.018em;
    color: var(--global-text-color);
}
.dl-extra-sub {
    font-size: 13.5px;
    line-height: 1.6;
    letter-spacing: -0.005em;
    color: var(--global-text-muted);
}

/* ---------- Reveal mechanic (§5.3) ---------- */
#downloads-page [data-reveal] {
    opacity: 0;
    transform: translateY(24px);
    transition:
        opacity 0.9s var(--dl-ease),
        transform 0.9s var(--dl-ease-spring);
}
#downloads-page [data-reveal].is-revealed { opacity: 1; transform: translateY(0); }
#downloads-page [data-reveal-stagger="1"] { transition-delay: 0.08s; }
#downloads-page [data-reveal-stagger="2"] { transition-delay: 0.16s; }
#downloads-page [data-reveal-stagger="3"] { transition-delay: 0.24s; }

/* ---------- Mobile (§4.7 — the single 640px breakpoint) ---------- */
@media (max-width: 640px) {
    .dl-hero-actions { width: 100%; }
    .dl-primary { width: 100%; box-sizing: border-box; }

    /* Stack the row: identity above, actions below and left-aligned, so a
       store badge never has to share a line with a 24px platform name. */
    .dl-row {
        grid-template-columns: minmax(0, 1fr);
        gap: 14px;
    }
    .dl-row-actions { justify-content: flex-start; }

    .dl-extras { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- Reduced motion (§5.7) ---------- */
@media (prefers-reduced-motion: reduce) {
    .dl-aura { animation: none; }
    .dl-mark { animation: none; opacity: 1; transform: none; }
    #downloads-page [data-reveal] { opacity: 1; transform: none; transition: none; }
    .dl-primary,
    .dl-get,
    .dl-store,
    .dl-extra { transition: none; }
}
