/* ==========================================================================
   HOME-MOBILE.CSS — dedicated mobile carousel system for index.html
   This file is loaded ONLY on the home page and has zero overlap with the
   project-page carousel system (carousel.js / style.css).

   Scope: turn the 4 main home grids into horizontal snap-carousels on mobile.
       .universe-grid   → universes cards
       .projects-grid   → projects cards
       .profile-grid    → profile cards
       .about-credo     → credo cards

   Breakpoint: ≤ 820px (desktop layouts above are untouched).
   ========================================================================== */

@media (max-width: 820px) {

    /* ---------------------------------------------------------------------
       1) TRACK WRAPPER (injected by home-mobile.js)
       --------------------------------------------------------------------- */
    .hm-track {
        position: relative;
        z-index: 1;
        /* Bleed slightly past the container padding so cards touch the edge */
        margin-left: -24px;
        margin-right: -24px;
        padding: 0 24px;
    }

    /* ---------------------------------------------------------------------
       2) SCROLLER (the grid itself)
       --------------------------------------------------------------------- */
    .hm-track .universe-grid,
    .hm-track .projects-grid,
    .hm-track .profile-grid,
    .hm-track .about-credo,
    .hm-track .chart-mobile-list {
        display: flex !important;
        flex-wrap: nowrap !important;
        grid-template-columns: none !important;
        gap: 14px;
        align-items: stretch;
        overflow-x: auto;
        overflow-y: visible;
        scroll-snap-type: x mandatory;
        scroll-padding: 0 24px;
        overscroll-behavior-x: contain;
        overscroll-behavior-y: auto;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-x pan-y;
        scrollbar-width: none;
        /* generous vertical padding so card shadow + lift never clip */
        padding-top: 12px;
        padding-bottom: 36px;
        /* horizontal padding handled by .hm-track wrapper */
        padding-left: 0;
        padding-right: 0;
        list-style: none;
        margin: 0;
    }

    /* Modern browsers: keep horizontal scroll inside but let shadow extend
       vertically out of the scroller without making it scrollable. */
    @supports (overflow-clip-margin: 80px) {
        .hm-track .universe-grid,
        .hm-track .projects-grid,
        .hm-track .profile-grid,
        .hm-track .about-credo,
        .hm-track .chart-mobile-list {
            overflow-y: clip;
            overflow-clip-margin: 80px;
        }
    }

    .hm-track .universe-grid::-webkit-scrollbar,
    .hm-track .projects-grid::-webkit-scrollbar,
    .hm-track .profile-grid::-webkit-scrollbar,
    .hm-track .about-credo::-webkit-scrollbar,
    .hm-track .chart-mobile-list::-webkit-scrollbar {
        display: none;
    }

    /* ---------------------------------------------------------------------
       3) SLIDES (direct children of the grid)
       --------------------------------------------------------------------- */
    .hm-track .universe-grid > *,
    .hm-track .projects-grid > *,
    .hm-track .profile-grid > *,
    .hm-track .about-credo > *,
    .hm-track .chart-mobile-list > li {
        flex: 0 0 88%;
        max-width: 360px;
        scroll-snap-align: start;
        scroll-snap-stop: always;
    }

    /* Profile-col contains 2 stacked cards inside one slide */
    .hm-track .profile-col {
        flex: 0 0 88%;
        max-width: 360px;
        display: flex !important;
        flex-direction: column;
        gap: 14px;
        scroll-snap-align: start;
    }
    .hm-track .profile-col > .profile-card {
        flex: 0 0 auto;
        min-width: 0;
        max-width: none;
    }

    /* About credo: remove parent card shell so each <li> is the only card */
    .hm-track .about-credo {
        background: transparent !important;
        border: none !important;
        border-radius: 0 !important;
    }

    /* Credo slides: unified width with other home carousels */
    .hm-track .about-credo > li {
        flex: 0 0 88% !important;
        max-width: 420px !important;
        min-width: 0 !important;
        background: var(--bg-1);
        border: 1px solid var(--border-strong);
        border-radius: var(--radius);
        padding: 22px 20px;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
        overflow-wrap: break-word;
        word-break: break-word;
    }

    /* Universe-card / Project-card hover lift would be clipped by the
       scroller, so disable on touch carousels */
    .hm-track .universe-card:hover,
    .hm-track .project-card:hover {
        transform: none;
    }

    /* Ensure cards have a visible bottom edge on dark backgrounds */
    .hm-track .universe-card,
    .hm-track .project-card,
    .hm-track .profile-card {
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
        border: 1px solid var(--border-strong);
    }

    /* ---------------------------------------------------------------------
       4) ARROWS (injected by home-mobile.js)
       --------------------------------------------------------------------- */
    .hm-arrow {
        position: absolute;
        /* `top` is set inline by JS to center on the slide */
        top: 50%;
        transform: translateY(-50%);
        box-sizing: border-box;
        width: 44px;
        height: 44px;
        flex: 0 0 44px;
        border-radius: 50%;
        background: rgba(11, 11, 14, 0.92);
        border: 1.5px solid var(--border-strong);
        color: var(--text);
        display: inline-flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        z-index: 100;
        padding: 0;
        margin: 0;
        transition: opacity 0.25s ease, background 0.2s, border-color 0.2s, color 0.2s;
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
        box-shadow: 0 6px 22px rgba(0, 0, 0, 0.55);
    }

    .hm-arrow > svg {
        width: 20px;
        height: 20px;
        display: block;
    }

    .hm-arrow:hover,
    .hm-arrow:focus-visible {
        background: var(--accent);
        border-color: var(--accent);
        color: var(--bg);
        outline: none;
    }

    .hm-arrow--prev { left: 12px; }
    .hm-arrow--next { right: 12px; }

    .hm-arrow.is-hidden {
        opacity: 0;
        pointer-events: none;
    }

    /* ---------------------------------------------------------------------
       5) RIGHT-EDGE FADE GRADIENT — visible only when there's more to scroll
       --------------------------------------------------------------------- */
    .hm-track::after {
        content: "";
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        width: 28px;
        background: linear-gradient(to right, transparent, var(--bg));
        pointer-events: none;
        opacity: 0;
        transition: opacity 0.3s ease;
        z-index: 2;
    }

    .hm-track.has-overflow-right::after {
        opacity: 1;
    }

    /* ---------------------------------------------------------------------
       6) NEUTRALIZE DESKTOP-ONLY OVERRIDES that fight the carousel
       --------------------------------------------------------------------- */
    /* The base style.css declares grid-template-columns at various breakpoints
       — we already neutralize them via grid-template-columns: none above.
       Also reset margins that desktop styles may inject between rows. */
    .hm-track .universe-grid,
    .hm-track .projects-grid,
    .hm-track .profile-grid,
    .hm-track .about-credo,
    .hm-track .chart-mobile-list {
        row-gap: 0 !important;
    }

    /* Align universe & project slides at top so cards never look "pushed down"
       by a taller sibling slide */
    .hm-track .universe-grid,
    .hm-track .projects-grid {
        align-items: flex-start !important;
    }
}

/* On desktop, ensure the hm-track wrapper is invisible to layout */
@media (min-width: 821px) {
    .hm-track {
        display: contents;
    }
}

/* ==========================================================================
   FIX 1 — About-section text overflow on mobile
   Grid cells default to min-width:auto, preventing shrink-to-fit on
   overflow. Force min-width:0 on layout + cells, and break-word on
   all text descendants so long words never create horizontal scroll.
   ========================================================================== */
@media (max-width: 820px) {
    .about-section .container,
    .about-layout,
    .about-layout > *,
    .about-header,
    .about-manifesto {
        min-width: 0 !important;
        max-width: 100%;
    }

    .about-layout {
        grid-template-columns: 1fr !important;
    }

    .about-name {
        font-size: clamp(2rem, 9vw, 3.4rem) !important;
        line-height: 1.05;
        max-width: 100%;
        overflow-wrap: break-word;
        word-break: break-word;
    }

    .about-role {
        font-size: clamp(0.7rem, 2.8vw, 0.85rem);
        letter-spacing: 0.15em;
        word-spacing: 0.05em;
        overflow-wrap: break-word;
    }

    .about-manifesto {
        padding-left: 0 !important;
        border-left: none !important;
        overflow-wrap: break-word;
        word-break: break-word;
    }

    .about-manifesto p {
        font-size: clamp(0.95rem, 4vw, 1.15rem) !important;
        line-height: 1.55;
        overflow-wrap: break-word;
        word-break: break-word;
    }

    /* The decorative squiggle SVG can also push width — keep it contained */
    .about-name .name-deco {
        max-width: 100%;
        display: block;
    }
}

/* ==========================================================================
   FIX 2 — Profile cards uniform sizing (no big empty spaces)
   Each slide gets its natural height (no stretch) so content never
   looks sparse. Inner cards / lists use compact fixed gaps instead of
   space-between which created huge holes.
   ========================================================================== */
@media (max-width: 820px) {
    /* Every profile card: flex column, compact padding */
    .hm-track .profile-card {
        display: flex !important;
        flex-direction: column;
        padding: 18px 18px;
    }

    /* Compact label */
    .hm-track .profile-card > .profile-label {
        flex: 0 0 auto;
        margin-bottom: 12px;
        padding-bottom: 8px;
    }

    /* Profile lists: fixed compact gap, never space-between */
    .hm-track .profile-card > .profile-list {
        flex: 0 0 auto;
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        gap: 6px;
        margin: 0;
        padding: 0;
        list-style: none;
    }

    .hm-track .profile-card > .profile-list li {
        padding: 6px 0;
    }

    /* Skill groups (Technical Arsenal) — 4 sub-columns so all 4 groups
       sit on one row, keeping the card compact */
    .hm-track .profile-card > .skill-groups {
        flex: 0 0 auto;
        display: grid !important;
        grid-template-columns: repeat(4, 1fr) !important;
        gap: 8px;
    }

    .hm-track .skill-group {
        gap: 6px;
    }

    .hm-track .skill-tags {
        gap: 5px;
    }

    .hm-track .skill-tag {
        padding: 5px 10px;
        font-size: 0.78rem;
    }

    /* Technical Arsenal slide: allow it to be much wider */
    .hm-track .profile-grid > :nth-child(3) {
        flex: 0 0 calc(100% - 16px) !important;
        max-width: none !important;
    }

    /* Profile-col: compact fixed gap, cards keep natural height */
    .hm-track .profile-col {
        justify-content: flex-start;
        gap: 12px;
    }

    .hm-track .profile-col > .profile-card {
        flex: 0 0 auto !important;
        min-height: 0 !important;
    }

    /* Inside profile-col, lists use compact fixed gaps */
    .hm-track .profile-col > .profile-card > .profile-list {
        justify-content: flex-start;
        gap: 6px;
    }
}

/* ==========================================================================
   FIX 3 — Universe-card clean bottom edge
   The scroller has overflow-y:hidden (from overflow-x:auto), so any
   shadow or rounded corner that bleeds below the padding is clipped.
   We keep generous padding-bottom so the full shadow + border radius
   stay visible, and use a tight shadow so it doesn't need huge space.
   ========================================================================== */
@media (max-width: 820px) {
    /* Tighten card content's bottom padding so footer is close to the edge */
    .hm-track .universe-card .uc-body {
        padding: 18px 20px 18px !important;
    }

    .hm-track .universe-card .uc-footer {
        padding-top: 12px;
        margin-top: auto;
    }

    /* Generous bottom padding so card shadow + rounded corners are never
       clipped by the scroller's overflow-y:hidden */
    .hm-track .universe-grid,
    .hm-track .projects-grid,
    .hm-track .profile-grid,
    .hm-track .about-credo,
    .hm-track .chart-mobile-list {
        padding-bottom: 48px !important;
    }

    /* Keep unified shadow and border from base carousel styles */
    .hm-track .universe-card,
    .hm-track .project-card {
        position: relative;
    }
}
