/* ============================================
   صفحة الترفيه
   ============================================ */
.fun-page { margin: 20px 0 50px; }

.fun-hero {
    text-align: center;
    padding: 30px 20px;
    background: linear-gradient(135deg, var(--primary), var(--primary-mid));
    border-radius: 18px;
    color: #fff;
    margin-bottom: 24px;
}
.fun-hero-title {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    font-family: 'Cairo', sans-serif;
    font-weight: 800;
    font-size: 30px;
    margin: 0 0 8px;
}
.fun-hero-title svg { width: 32px; height: 32px; }
.fun-hero-sub { font-size: 15px; opacity: .92; margin: 0; }

/* الجوال: هيرو أصغر */
@media (max-width: 640px) {
    .fun-hero { padding: 22px 16px; border-radius: 14px; margin-bottom: 18px; }
    .fun-hero-title { font-size: 22px; gap: 8px; }
    .fun-hero-title svg { width: 24px; height: 24px; }
    .fun-hero-sub { font-size: 13px; }
    .fun-game-bar { padding: 10px 12px; gap: 10px; }
    .fgb-lvl, .fgb-cat { font-size: 12px; padding: 6px 12px; }
    .fgb-btn { font-size: 12px; padding: 7px 14px; }
    .fgb-timer, .fgb-score { font-size: 12.5px; padding: 6px 12px; }
}

/* شريط الألعاب */
.fun-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    margin-bottom: 26px;
}
.fun-tab {
    font-family: 'Cairo', sans-serif;
    font-weight: 700;
    font-size: 15px;
    padding: 12px 22px;
    border-radius: 100px;
    border: 2px solid var(--line);
    background: var(--paper);
    color: var(--ink);
    cursor: pointer;
    transition: all .18s;
}
.fun-tab:hover { border-color: var(--primary); color: var(--primary); }
.fun-tab.is-active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}
/* الجوال: أزرار أصغر ومرتّبة */
@media (max-width: 640px) {
    .fun-tabs {
        gap: 7px;
        margin-bottom: 20px;
    }
    .fun-tab {
        font-size: 12.5px;
        padding: 8px 14px;
        border-width: 1.5px;
    }
}

/* حاوية اللعبة */
.fun-game { display: none; }
.fun-game.is-active { display: block; animation: funfade .3s ease; }
@keyframes funfade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.fun-game-bar {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    margin-bottom: 20px;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px 16px;
}
.fgb-levels { display: flex; gap: 6px; flex-wrap: wrap; }
.fgb-lvl, .fgb-cat {
    font-family: 'Cairo', sans-serif;
    font-weight: 700;
    font-size: 13px;
    padding: 7px 16px;
    border-radius: 100px;
    border: 1.5px solid var(--line);
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    transition: all .16s;
}
.fgb-lvl.is-active, .fgb-cat.is-active {
    background: var(--primary-soft);
    border-color: var(--primary);
    color: var(--primary-deep);
}
.fgb-info { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.fgb-timer, .fgb-score {
    font-family: 'Cairo', sans-serif;
    font-weight: 700;
    font-size: 14px;
    color: var(--ink);
    background: var(--canvas);
    padding: 7px 14px;
    border-radius: 100px;
}
.fgb-score b { color: var(--primary); }
.fgb-btn {
    font-family: 'Cairo', sans-serif;
    font-weight: 700;
    font-size: 13.5px;
    padding: 8px 18px;
    border-radius: 100px;
    border: none;
    background: var(--canvas);
    color: var(--ink);
    cursor: pointer;
    transition: all .16s;
}
.fgb-btn:hover { background: var(--line); }
.fgb-btn-primary { background: var(--primary); color: #fff; }
.fgb-btn-primary:hover { background: var(--primary-deep); }

.fun-msg {
    text-align: center;
    font-family: 'Cairo', sans-serif;
    font-weight: 700;
    font-size: 16px;
    min-height: 24px;
    margin: 18px 0 0;
}
.fun-msg.ok { color: #16a34a; }
.fun-msg.err { color: #dc2626; }
.fun-hint {
    text-align: center;
    font-size: 13px;
    color: var(--muted);
    margin: 14px 0 0;
}

/* ═══════════ سودوكو ═══════════ */
.sudoku-wrap { display: flex; justify-content: center; }
.sudoku-board {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    width: min(100%, 460px);
    aspect-ratio: 1;
    background: var(--ink);
    border: 3px solid var(--ink);
    border-radius: 8px;
    overflow: hidden;
    gap: 1px;
}
.sdk-cell {
    background: var(--paper);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Cairo', sans-serif;
    font-weight: 700;
    font-size: clamp(16px, 4.5vw, 24px);
    color: var(--primary-deep);
    cursor: pointer;
    user-select: none;
    transition: background .12s;
    aspect-ratio: 1;
}
.sdk-cell.fixed { color: var(--ink); cursor: default; background: var(--canvas); }
.sdk-cell.sel { background: var(--primary-soft); }
.sdk-cell.err { color: #dc2626; }
.sdk-cell.hl { background: color-mix(in srgb, var(--primary-soft) 55%, transparent); }
/* حدود المربعات ٣×٣ */
.sdk-cell:nth-child(3n):not(:nth-child(9n)) { border-inline-end: 2px solid var(--muted); }
.sdk-cell:nth-child(n+19):nth-child(-n+27),
.sdk-cell:nth-child(n+46):nth-child(-n+54) { border-bottom: 2px solid var(--muted); }

.sudoku-pad {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    max-width: 460px;
    margin: 18px auto 0;
}
.sdk-key {
    font-family: 'Cairo', sans-serif;
    font-weight: 700;
    font-size: 20px;
    padding: 14px 0;
    border-radius: 10px;
    border: 1.5px solid var(--line);
    background: var(--paper);
    color: var(--ink);
    cursor: pointer;
    transition: all .14s;
}
.sdk-key:hover { background: var(--primary-soft); border-color: var(--primary); }
.sdk-key-erase { color: #dc2626; }

/* ═══════════ كلمة السر ═══════════ */
.ws-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
    align-items: start;
}
@media (min-width: 720px) {
    .ws-layout { grid-template-columns: 1fr 200px; }
}
.ws-grid {
    display: grid;
    gap: 2px;
    background: var(--line);
    border: 3px solid var(--line);
    border-radius: 10px;
    overflow: hidden;
    user-select: none;
    touch-action: none;
    max-width: 500px;
    margin: 0 auto;
    width: 100%;
}
.ws-cell {
    background: var(--paper);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Cairo', sans-serif;
    font-weight: 700;
    font-size: clamp(13px, 3.4vw, 19px);
    color: var(--ink);
    aspect-ratio: 1;
    cursor: pointer;
    transition: background .1s;
}
.ws-cell.sel { background: var(--primary-mid); color: #fff; }
.ws-cell.found { background: #16a34a; color: #fff; }
.ws-words {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 14px;
}
.ws-words h3 {
    font-family: 'Cairo', sans-serif;
    font-size: 15px;
    margin: 0 0 10px;
    color: var(--primary-deep);
}
.ws-word {
    display: block;
    font-family: 'Cairo', sans-serif;
    font-weight: 700;
    font-size: 14px;
    padding: 6px 0;
    color: var(--ink);
    border-bottom: 1px dashed var(--line);
}
.ws-word.done { color: var(--muted); text-decoration: line-through; }
.ws-word:last-child { border-bottom: none; }

/* ═══════════ 2048 ═══════════ */
.g2048-wrap { display: flex; justify-content: center; }
.g2048-board {
    position: relative;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 10px;
    width: min(100%, 400px);
    aspect-ratio: 1;
    background: var(--line);
    border-radius: 12px;
    padding: 10px;
    touch-action: none;
}
.g2-cell {
    background: var(--canvas);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Cairo', sans-serif;
    font-weight: 800;
    font-size: clamp(18px, 5vw, 30px);
    transition: all .12s;
}
.g2-v2    { background: #e9e5f7; color: #4a3f8a; }
.g2-v4    { background: #ddd6f3; color: #4a3f8a; }
.g2-v8    { background: #b8aef0; color: #fff; }
.g2-v16   { background: #9d8fe8; color: #fff; }
.g2-v32   { background: #8877e0; color: #fff; }
.g2-v64   { background: #6f5cd6; color: #fff; }
.g2-v128  { background: #f0b429; color: #fff; font-size: clamp(16px,4.3vw,26px); }
.g2-v256  { background: #f09819; color: #fff; font-size: clamp(16px,4.3vw,26px); }
.g2-v512  { background: #f07d09; color: #fff; font-size: clamp(16px,4.3vw,26px); }
.g2-v1024 { background: #ec4899; color: #fff; font-size: clamp(14px,3.6vw,22px); }
.g2-v2048 { background: #16a34a; color: #fff; font-size: clamp(14px,3.6vw,22px); }

/* ═══════════ الذاكرة ═══════════ */
.mem-board {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    max-width: 440px;
    margin: 0 auto;
}
.mem-card {
    aspect-ratio: 1;
    border-radius: 12px;
    background: var(--primary);
    cursor: pointer;
    position: relative;
    transform-style: preserve-3d;
    transition: transform .4s;
    font-size: clamp(26px, 7vw, 40px);
}
.mem-card.flip, .mem-card.done { transform: rotateY(180deg); }
.mem-card .mc-face {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    backface-visibility: hidden;
    border-radius: 12px;
}
.mem-card .mc-back {
    background: linear-gradient(135deg, var(--primary), var(--primary-mid));
    color: #fff;
}
.mem-card .mc-back::after { content: '؟'; font-family: 'Cairo'; font-weight: 800; }
.mem-card .mc-front {
    background: var(--paper);
    border: 2px solid var(--primary-soft);
    transform: rotateY(180deg);
}
.mem-card.done .mc-front { background: #dcfce7; border-color: #16a34a; }

/* ═══════════ لغز الأرقام المنزلق ═══════════ */
.slide-wrap { display: flex; justify-content: center; }
.slide-board {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 8px;
    width: min(100%, 380px);
    aspect-ratio: 1;
    background: var(--line);
    border-radius: 12px;
    padding: 8px;
}
.sl-tile {
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Cairo', sans-serif;
    font-weight: 800;
    font-size: clamp(20px, 5.5vw, 32px);
    background: linear-gradient(135deg, var(--primary), var(--primary-mid));
    color: #fff;
    cursor: pointer;
    transition: transform .1s;
}
.sl-tile:active { transform: scale(.95); }
.sl-empty { background: transparent; cursor: default; }
