/* ============================================================
   EduHry — Global Styles
   Nunito font, child-friendly, bright and modern
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --font: 'Nunito', sans-serif;
    --bg: #f8f4ff;
    --header-from: #6c3fc4;
    --header-to: #a855f7;
    --shadow: 0 4px 20px rgba(0,0,0,.10);
    --radius: 20px;
}

html { font-size: 16px; }

body {
    font-family: var(--font);
    background: var(--bg);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    color: #1e0a3c;
}

/* Homepage only (body.home): layered pastel background + floating blobs.
   Scoped so the shared stylesheet never paints these inside games. */
body.home {
    background: linear-gradient(180deg, #f6f1ff 0%, #eef4ff 55%, #fff0f6 100%);
}
body.home::before, body.home::after {
    content: '';
    position: fixed;
    border-radius: 50%;
    filter: blur(64px);
    opacity: .45;
    z-index: -1;
    pointer-events: none;
}
body.home::before { width: 340px; height: 340px; background: #c4b5fd; top: 10%; left: -120px; animation: homeBlob 18s ease-in-out infinite alternate; }
body.home::after  { width: 300px; height: 300px; background: #fbcfe8; bottom: -80px; right: -100px; animation: homeBlob 22s ease-in-out infinite alternate-reverse; }
@keyframes homeBlob { to { transform: translate(50px, 40px) scale(1.18); } }

/* ── Homepage language selector ─────────────────────────── */
.home-lang-select {
    margin-top: 10px;
    background: rgba(255,255,255,0.22);
    border: 2px solid rgba(255,255,255,0.4);
    border-radius: 10px;
    color: #fff;
    padding: 5px 14px;
    font-family: var(--font);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    backdrop-filter: blur(4px);
}
.home-lang-select option { color: #1e0a3c; background: #fff; }

/* ── Header ──────────────────────────────────────────────── */
.site-header {
    background: linear-gradient(135deg, var(--header-from) 0%, var(--header-to) 60%, #d946ef 100%);
    color: #fff;
    padding: 28px 24px 26px;
    text-align: center;
    box-shadow: 0 6px 24px rgba(108,63,196,.35);
    border-radius: 0 0 30px 30px;
    position: relative;
    overflow: hidden;
}
/* Soft decorative bubbles inside the header */
.site-header::before, .site-header::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    background: rgba(255,255,255,.13);
    pointer-events: none;
}
.site-header::before { width: 230px; height: 230px; top: -100px; right: -60px; }
.site-header::after  { width: 150px; height: 150px; bottom: -70px; left: -40px; background: rgba(255,255,255,.09); }
.header-inner { max-width: 900px; margin: 0 auto; position: relative; z-index: 1; }
.logo { display: flex; align-items: center; justify-content: center; gap: 10px; }
.logo-icon { font-size: 2.4rem; line-height: 1; display: inline-block; animation: logoBob 3.2s ease-in-out infinite; }
@keyframes logoBob { 50% { transform: translateY(-5px) rotate(-7deg); } }
.logo-text {
    font-size: 2.4rem;
    font-weight: 900;
    letter-spacing: -0.5px;
    text-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.logo-sub {
    margin-top: 4px;
    font-size: 1rem;
    font-weight: 600;
    opacity: 0.85;
    letter-spacing: 0.5px;
}

/* ── Main ────────────────────────────────────────────────── */
.main-content {
    flex: 1;
    max-width: 1100px;
    margin: 0 auto;
    padding: 36px 20px 48px;
    width: 100%;
}

/* ── Sort bar ────────────────────────────────────────────── */
.sort-bar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}
.sort-bar label {
    font-size: .9rem;
    font-weight: 700;
    color: var(--header-from);
}
.sort-select {
    background: #fff;
    border: 2px solid #e4d9fb;
    border-radius: 10px;
    color: #1e0a3c;
    padding: 6px 12px;
    font-family: var(--font);
    font-size: .92rem;
    font-weight: 700;
    cursor: pointer;
}

/* ── Games Grid ──────────────────────────────────────────── */
.games-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 20px;
}

/* Group heading inside the grid (category / age sorting).
   Spans every column so the cards below it read as one block. */
.grid-sep {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 14px 0 -2px;
    font-size: 1.02rem;
    font-weight: 900;
    color: var(--header-from);
}
.grid-sep:first-child { margin-top: 0; }
/* Flat rule rather than a gradient: it has to look right in both LTR and the
   Arabic RTL layout, where flex flips which side the line extends to. */
.grid-sep::after {
    content: '';
    flex: 1;
    height: 3px;
    border-radius: 2px;
    background: #e9defc;
}

.game-card {
    background: linear-gradient(180deg, #ffffff 0%, var(--card-bg, #f5f0ff) 100%);
    border: 3px solid transparent;
    border-radius: 24px;
    padding: 22px 16px 18px;
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    box-shadow: var(--shadow);
    transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    /* Staggered entrance — index.html sets --i per card */
    animation: cardIn .55s cubic-bezier(.22, 1, .36, 1) backwards;
    animation-delay: calc(var(--i, 0) * 45ms);
}
@keyframes cardIn { from { opacity: 0; transform: translateY(22px) scale(.94); } }
/* Re-sorting reorders cards that have already appeared — replaying the
   entrance would only make them flicker (see sortGames in index.html). */
.games-grid.no-anim .game-card { animation: none; }
/* Shine sweep across the card on hover */
.game-card::after {
    content: '';
    position: absolute;
    top: 0; left: -80%;
    width: 50%; height: 100%;
    background: linear-gradient(105deg, transparent, rgba(255,255,255,.6), transparent);
    transform: skewX(-20deg);
    transition: left .5s ease;
    pointer-events: none;
}
.game-card:hover::after { left: 130%; }
.game-card:hover {
    transform: translateY(-6px) scale(1.03);
    border-color: var(--card-color, #a855f7);
    box-shadow: 0 14px 32px rgba(0,0,0,.16);
    box-shadow: 0 14px 32px color-mix(in srgb, var(--card-color, #a855f7) 32%, transparent);
}
.game-card:active { transform: scale(0.97); }

/* Icon sits in a tinted bubble ringed with the card color */
.game-icon {
    width: 76px; height: 76px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.55rem;
    line-height: 1;
    border-radius: 50%;
    background: var(--card-bg, #f5f0ff);
    background: color-mix(in srgb, var(--card-color, #a855f7) 12%, #fff);
    border: 2.5px solid var(--card-bg, #f5f0ff);
    border-color: color-mix(in srgb, var(--card-color, #a855f7) 30%, #fff);
    box-shadow: 0 4px 10px rgba(0,0,0,.10), inset 0 2px 4px rgba(255,255,255,.9);
    box-shadow: 0 4px 10px color-mix(in srgb, var(--card-color, #a855f7) 25%, transparent), inset 0 2px 4px rgba(255,255,255,.9);
    filter: none;
    transition: transform .18s;
}
.game-icon svg { width: 66%; height: 66%; display: block; }
.game-card:hover .game-icon { animation: iconBounce .5s; transform: scale(1.1); }
@keyframes iconBounce {
    30% { transform: scale(1.18) rotate(-7deg); }
    60% { transform: scale(1.04) rotate(4deg); }
    100% { transform: scale(1.1) rotate(0deg); }
}

.game-name {
    font-size: 1.05rem;
    font-weight: 800;
    text-align: center;
    color: var(--card-color, #6c3fc4);
    line-height: 1.2;
}

.game-age {
    font-size: 0.75rem;
    font-weight: 700;
    background: var(--card-color, #a855f7);
    background: linear-gradient(180deg, color-mix(in srgb, var(--card-color, #a855f7) 80%, #fff), var(--card-color, #a855f7));
    color: #fff;
    border-radius: 20px;
    padding: 2px 11px;
    box-shadow: 0 2px 5px rgba(0,0,0,.15);
}

@media (prefers-reduced-motion: reduce) {
    .game-card, .logo-icon, body.home::before, body.home::after { animation: none; }
}

/* ── Footer ──────────────────────────────────────────────── */
.site-footer {
    text-align: center;
    padding: 20px;
    font-size: 0.85rem;
    color: #888;
}

/* ── Game page shared wrapper ────────────────────────────── */
/* Used by individual game HTMLs that use .educhi-game-wrap */
.educhi-back {
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 100;
    width: 44px;
    height: 44px;
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,.88);
    backdrop-filter: blur(6px);
    box-shadow: 0 2px 10px rgba(0,0,0,.15);
    color: var(--header-from, #6c3fc4);
    text-decoration: none;
    cursor: pointer;
    transition: transform .15s, box-shadow .15s;
    margin: 0;
    padding: 0;
}
.educhi-back:hover { background: #fff; transform: scale(1.1); box-shadow: 0 4px 16px rgba(0,0,0,.22); }
.educhi-back:active { transform: scale(0.93); }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 480px) {
    .logo-text { font-size: 1.9rem; }
    .games-grid { grid-template-columns: repeat(2, 1fr); gap: 14px; }
    .game-card { padding: 16px 10px 14px; }
    .game-icon { width: 62px; height: 62px; font-size: 2rem; }
    .game-name { font-size: 0.9rem; }
}
@media (max-width: 340px) {
    .games-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
}
