/* Edulin Games — home navigation v2.
   Loads after pastel-theme-v1.css and only corrects the home screen's game
   browsing. Three jobs:
     1. every game shows its own icon again (the pastel theme had replaced each
        card's emoji with one generic glyph per category)
     2. phones and tablets get a compact icon grid instead of a 98-row column
     3. search, the category chips and the section headings stay reachable
        while scrolling, so nobody has to scroll back to the top to move on. */

/* ════════ 1 · Per-game icon ════════ */
/* pastel-theme-v1.css blanks the emoji (font-size:0) and paints a category
   glyph through ::before. Keep its tinted tile, show the game's own emoji. */
.game-card .emoji {
    font-size: 30px !important;
    line-height: 1;
    overflow: hidden;
}
.game-card .emoji::before { content: none !important; }

/* ════════ 1b · Difficulty level ════════ */
/* Every card carries data-level from its section; the chips below filter on it. */
.level-filters {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 7px;
    margin-top: 2px;
}
.level-filters-label {
    color: var(--pastel-muted);
    font: 800 .78rem 'Outfit', sans-serif;
    text-transform: uppercase;
    letter-spacing: .06em;
}
.level-btn {
    min-height: 38px;
    padding: 7px 14px;
    border: 1px solid var(--pastel-line);
    border-radius: 999px;
    background: var(--pastel-white);
    color: var(--pastel-ink);
    font: 700 .84rem 'Outfit', sans-serif;
    cursor: pointer;
    transition: background var(--edu-motion-fast), border-color var(--edu-motion-fast);
}
.level-btn:hover { background: var(--pastel-lavender); }
.level-btn.active { background: var(--pastel-violet); border-color: var(--pastel-violet); color: #fff; }
.level-btn.lvl-easy.active { background: #2e8b57; border-color: #2e8b57; }
.level-btn.lvl-challenging.active { background: #c2571f; border-color: #c2571f; }

/* The badge on each card. It is absolutely positioned so it never becomes a grid item
   and disturb the card's icon/title/blurb layout. The text is an attribute the shell
   sets from the active language, so it follows the language switcher. */
.game-card::before {
    content: attr(data-level-label);
    position: absolute;
    top: 8px;
    right: 9px;
    z-index: 2;
    padding: 2px 8px;
    border-radius: 999px;
    font: 800 9.5px/1.6 'Outfit', sans-serif;
    text-transform: uppercase;
    letter-spacing: .05em;
    pointer-events: none;
}
.game-card[data-level="easy"]::before { background: #e3f3e8; color: #24693f; }
.game-card[data-level="challenging"]::before { background: #fdeadf; color: #a2451a; }
.game-card:not([data-level-label])::before { display: none; }

/* ════════ 2 · Section headings carry a count ════════ */
/* applyGameFilters() keeps data-count in step with the active filter. It is an
   attribute, not a child node, so the language switcher's textContent rewrite
   of these labels can never wipe it. */
.menu-section-label { justify-content: flex-start !important; gap: 10px; }
.menu-section-label::before {
    order: 2;
    margin-right: auto;
    content: attr(data-count);
    min-width: 30px;
    padding: 3px 9px;
    border-radius: 999px;
    background: var(--pastel-lavender);
    color: var(--pastel-violet-dark);
    font: 800 12px/1.5 'Outfit', sans-serif;
    letter-spacing: 0;
}
.menu-section-label:not([data-count])::before { display: none; }
.menu-section-label::after { order: 3; flex: 0 0 auto; }
/* Until the count lands, nothing is pushing the chevron across, so it does it
   itself — otherwise it jumps from beside the heading to the far edge. */
.menu-section-label:not([data-count])::after { margin-left: auto; }

/* ════════ 3 · Phone + tablet ════════ */
@media (max-width: 1100px) {
    /* --- 3a · Sticky browse bar -------------------------------------- */
    /* --edu-browsebar-h is measured in app-shell-v13.js so the section
       headings below can stick directly underneath it. */
    .game-discovery {
        position: sticky;
        top: 0;
        z-index: 90;
        grid-template-columns: 1fr !important;
        gap: 8px !important;
        margin: 0 0 6px !important;
        padding: 10px 0 8px;
        background: var(--pastel-cream);
        box-shadow: 0 10px 18px -12px rgba(78, 61, 126, .45);
    }
    .game-discovery::before {
        /* Bleed the bar's background to the screen edges without moving the
           controls, so cards scroll under it rather than beside it. */
        content: '';
        position: absolute;
        inset: 0 -22px;
        z-index: -1;
        background: inherit;
        box-shadow: inherit;
    }
    .game-search-wrap { min-height: 48px !important; border-radius: 15px !important; }
    #game-search { min-height: 44px; font-size: 16px; } /* 16px stops iOS zoom-on-focus */
    .category-filters { justify-content: flex-start !important; padding: 0 0 2px; }
    .category-btn { min-height: 40px !important; padding: 7px 13px !important; font-size: 13px; }

    /* Let the browse bar own the top edge: on the home screen the language and
       music controls scroll away with the hero instead of floating over cards. */
    #home:not(.hidden) ~ #lang-bar,
    #home:not(.hidden) ~ #music-ctrl { position: absolute !important; }

    /* --- 3b · Sticky section headings -------------------------------- */
    .menu-section-label {
        position: sticky;
        top: var(--edu-browsebar-h, 104px);
        z-index: 80;
        margin: 10px 0 8px !important;
        padding: 8px 2px !important;
        background: var(--pastel-cream);
        font-size: 1.15rem !important;
    }
    .menu-section-label::after { width: 32px; height: 32px; }

    /* --- 3c · Compact icon grid -------------------------------------- */
    .menu, .menu.is-featured {
        grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
        gap: 10px !important;
    }
    .game-card {
        grid-template-columns: minmax(0, 1fr) !important;
        grid-template-rows: auto auto !important;
        justify-items: center;
        align-content: start !important;
        text-align: center !important;
        min-height: 0 !important;
        padding: 14px 9px 13px !important;
        gap: 9px !important;
        border-radius: 17px !important;
    }
    .game-card .emoji {
        grid-column: 1 !important;
        grid-row: 1 !important;
        width: 54px;
        height: 54px;
        border-radius: 16px;
        font-size: 29px !important;
    }
    .game-card h2 {
        grid-column: 1 !important;
        grid-row: 2 !important;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 3;
        line-clamp: 3;
        overflow: hidden;
        font-size: 13px !important;
        line-height: 1.22 !important;
    }
    /* The blurb is the single biggest reason the phone page ran to 17,000px.
       The title and icon identify the game; the blurb returns on desktop. */
    .game-card p { display: none !important; }

    /* app-shell-v13.css gives touch devices content-visibility:auto with a
       150px contain-intrinsic-size. That placeholder was written for the tall
       blurb card, so off-screen compact tiles reserved 150px instead of ~112px
       and the page stayed long however short the cards got. `auto` keeps the
       skipping optimisation but lets the browser remember each card's real
       height once it has been on screen. */
    .game-card { contain-intrinsic-size: 80px; contain-intrinsic-size: auto 80px; }

}

@media (max-width: 760px) {
    .menu, .menu.is-featured { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
    .game-discovery::before { inset: 0 -16px; }
    /* The browse bar replaces the hero's top edge, so it clears the safe area. */
    .game-discovery {
        top: calc(-1 * env(safe-area-inset-top));
        padding-top: calc(8px + env(safe-area-inset-top));
        padding-bottom: 6px;
        gap: 7px !important;
    }
    .game-search-wrap { min-height: 44px !important; padding: 0 14px !important; }
    #game-search { min-height: 40px; }
    .game-search-wrap > span::before { font-size: 23px !important; }
    /* Six categories will not fit across a phone, so the row scrolls sideways.
       Keep the chips small enough that the next one always peeks into view and
       reads as scrollable. */
    .category-btn { min-height: 36px !important; padding: 6px 11px !important; font-size: 12.5px; gap: 5px; }
    .category-btn .material-symbols-rounded { font-size: 18px; }
    /* Long headings such as "Olympiads by Class (Pre-KG to Class 12)" wrapped to
       two lines and, being sticky, cost that space on every screen. */
    .menu-section-label {
        margin: 8px 0 7px !important;
        padding: 6px 2px !important;
        font-size: .98rem !important;
        line-height: 1.15 !important;
    }
    .menu-section-label::after { width: 28px; height: 28px; font-size: 14px; }
    .menu-section-label::before { padding: 2px 8px; font-size: 11px; }
}

@media (max-width: 380px) {
    .menu, .menu.is-featured { gap: 8px !important; }
    .game-card { padding: 12px 6px 11px !important; contain-intrinsic-size: 74px; contain-intrinsic-size: auto 74px; }
    .game-card .emoji { width: 48px; height: 48px; font-size: 26px !important; }
    .game-card h2 { font-size: 12.2px !important; }
}

/* ════════ 4 · Back-to-top button ════════ */
/* EduStar is fixed in the bottom-right corner at z-index 180, so this sits on
   the opposite side where there is a bottom nav, and stacks above the mascot on
   tablet, where the left edge belongs to the sidebar. */
#back-to-top {
    position: fixed;
    left: max(14px, env(safe-area-inset-left));
    bottom: calc(86px + env(safe-area-inset-bottom));
    z-index: 110;
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    padding: 0;
    border: 1px solid var(--pastel-line);
    border-radius: 50%;
    background: var(--pastel-violet);
    color: #fff;
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    box-shadow: 0 10px 22px rgba(78, 61, 126, .3);
    transition: opacity .2s ease, transform .2s ease, visibility .2s;
}
#back-to-top.is-visible { opacity: 1; visibility: visible; transform: none; }
#back-to-top .material-symbols-rounded { font-size: 26px; }
/* Tablet: the left edge is the fixed sidebar, so return to the right and clear
   the mascot (bottom 92px, 82px tall) by sitting above it. */
@media (min-width: 761px) {
    #back-to-top {
        left: auto;
        right: max(16px, env(safe-area-inset-right));
        bottom: 200px;
    }
}
/* Desktop keeps the left sidebar and a far shorter page, so it needs no
   back-to-top. Declared last so it wins over the base display:grid. */
@media (min-width: 1101px) { #back-to-top { display: none; } }

/* ════════ 5 · Reduced motion ════════ */
@media (prefers-reduced-motion: reduce) {
    #back-to-top { transition: none; }
}
body.reduced-motion #back-to-top { transition: none; }
