/* ========================================
   H5Bros — Design System & Styles
   ======================================== */

/* --- CSS Variables / Design Tokens --- */
:root {
    --bg-primary: #0a0a1a;
    --bg-secondary: #12122a;
    --bg-card: rgba(255, 255, 255, 0.04);
    --bg-card-hover: rgba(255, 255, 255, 0.08);
    --bg-glass: rgba(255, 255, 255, 0.06);
    --bg-glass-strong: rgba(255, 255, 255, 0.1);
    --border-glass: rgba(255, 255, 255, 0.08);
    --border-glass-hover: rgba(255, 255, 255, 0.15);
    --text-primary: #f0f0ff;
    --text-secondary: rgba(240, 240, 255, 0.6);
    --text-muted: rgba(240, 240, 255, 0.35);
    --accent-1: #7c3aed;
    --accent-2: #06b6d4;
    --accent-3: #f43f5e;
    --accent-gradient: linear-gradient(135deg, #7c3aed 0%, #06b6d4 50%, #f43f5e 100%);
    --accent-gradient-2: linear-gradient(135deg, #7c3aed, #a855f7);
    --shadow-card: 0 4px 30px rgba(0, 0, 0, 0.3);
    --shadow-glow: 0 0 40px rgba(124, 58, 237, 0.15);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --content-max: 1400px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --focus-ring: 0 0 0 2px var(--bg-primary), 0 0 0 4px rgba(124, 58, 237, 0.6);
}

/* --- Reset & Base --- */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* Global focus-visible — consistent purple ring on all interactive elements */
:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

:focus:not(:focus-visible) {
    outline: none;
    box-shadow: none;
}

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
    min-height: 100vh;
}

/* --- Animated Background Orbs --- */
.bg-orbs {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
}

.orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(100px);
    opacity: 0.4;
    animation: float 20s ease-in-out infinite;
}

.orb-1 {
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, rgba(124, 58, 237, 0.4), transparent);
    top: -10%;
    left: -10%;
    animation-delay: 0s;
}

.orb-2 {
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, rgba(6, 182, 212, 0.3), transparent);
    top: 40%;
    right: -10%;
    animation-delay: -7s;
}

.orb-3 {
    width: 400px;
    height: 400px;
    background: radial-gradient(circle, rgba(244, 63, 94, 0.3), transparent);
    bottom: -5%;
    left: 30%;
    animation-delay: -14s;
}

@keyframes float {

    0%,
    100% {
        transform: translate(0, 0) scale(1);
    }

    25% {
        transform: translate(50px, -80px) scale(1.1);
    }

    50% {
        transform: translate(-30px, 60px) scale(0.95);
    }

    75% {
        transform: translate(80px, 30px) scale(1.05);
    }
}

/* --- Navbar --- */
.navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    padding: 0 24px;
    height: 68px;
    background: rgba(10, 10, 26, 0.8);
    backdrop-filter: blur(28px) saturate(200%);
    -webkit-backdrop-filter: blur(28px) saturate(200%);
    border-bottom: none;
    transition: background 0.3s ease, box-shadow 0.3s ease;
}

.navbar::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent 0%, rgba(124, 58, 237, 0.9) 25%, rgba(6, 182, 212, 0.9) 60%, rgba(124, 58, 237, 0.5) 80%, transparent 100%);
    opacity: 0.65;
    transition: opacity 0.3s ease;
}

.navbar.scrolled {
    background: rgba(8, 8, 22, 0.97);
    box-shadow: 0 4px 40px rgba(0, 0, 0, 0.6);
}

.navbar.scrolled::after {
    opacity: 1;
}

.nav-content {
    max-width: var(--content-max);
    margin: 0 auto;
    height: 100%;
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 9px;
    text-decoration: none;
    flex-shrink: 0;
    transition: opacity 0.2s;
}

.logo:hover {
    opacity: 0.9;
}

.logo-icon {
    width: 36px;
    height: 36px;
    background: var(--accent-gradient-2);
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 17px;
    flex-shrink: 0;
    box-shadow: 0 4px 14px rgba(124, 58, 237, 0.45);
    transition: box-shadow 0.2s, transform 0.2s;
}

.logo:hover .logo-icon {
    box-shadow: 0 6px 20px rgba(124, 58, 237, 0.65);
    transform: scale(1.06);
}

.logo-text {
    font-size: 20px;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}

.logo-accent {
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Random Game Button */
.nav-random-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 16px;
    background: linear-gradient(135deg, rgba(124, 58, 237, 0.1), rgba(6, 182, 212, 0.1));
    border: 1px solid rgba(124, 58, 237, 0.28);
    border-radius: 100px;
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    flex-shrink: 0;
}

.nav-random-btn:hover {
    background: linear-gradient(135deg, rgba(124, 58, 237, 0.22), rgba(6, 182, 212, 0.22));
    border-color: rgba(124, 58, 237, 0.55);
    color: var(--text-primary);
    box-shadow: 0 0 18px rgba(124, 58, 237, 0.2);
    transform: scale(1.02);
}

.nav-random-btn:active {
    transform: scale(0.98);
}

.nav-search {
    flex: 1;
    max-width: 480px;
    position: relative;
    display: flex;
    align-items: center;
}

.search-icon {
    width: 18px;
    height: 18px;
    position: absolute;
    left: 14px;
    color: var(--text-muted);
    pointer-events: none;
}

.nav-search input {
    width: 100%;
    height: 42px;
    background: rgba(255, 255, 255, 0.055);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 100px;
    padding: 0 48px 0 44px;
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
}

.nav-search input::placeholder {
    color: var(--text-muted);
}

.nav-search input:focus {
    border-color: rgba(124, 58, 237, 0.65);
    background: rgba(124, 58, 237, 0.07);
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.14);
}

.nav-search input:hover:not(:focus) {
    border-color: rgba(255, 255, 255, 0.18);
    background: rgba(255, 255, 255, 0.075);
}

.search-kbd {
    position: absolute;
    right: 10px;
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    border-radius: 6px;
    padding: 2px 8px;
    font-size: 11px;
    color: var(--text-muted);
    font-family: var(--font);
    pointer-events: none;
}

.nav-stats {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 600;
    flex-shrink: 0;
    background: var(--bg-glass);
    padding: 6px 18px;
    border-radius: 100px;
    border: 1px solid var(--border-glass);
}

.nav-stats span {
    font-weight: 800;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* --- Hero --- */
.hero {
    position: relative;
    z-index: 1;
    padding: 130px 24px 64px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    justify-content: center;
    gap: 0;
    max-width: var(--content-max);
    margin: 0 auto;
    min-height: 70vh;
}

.hero-content {
    max-width: 740px;
    width: 100%;
}

.hero-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: rgba(124, 58, 237, 0.08);
    border: 1px solid rgba(124, 58, 237, 0.22);
    border-radius: 100px;
    padding: 8px 20px;
    font-size: 13px;
    font-weight: 600;
    color: rgba(168, 85, 247, 0.9);
    margin-bottom: 28px;
    backdrop-filter: blur(10px);
}

.hero-badge-dot {
    width: 7px;
    height: 7px;
    background: #a855f7;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 8px rgba(168, 85, 247, 0.8);
    animation: badgePulse 2s ease-in-out infinite;
}

@keyframes badgePulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.45; transform: scale(0.8); }
}

.hero h1 {
    font-size: clamp(38px, 6vw, 68px);
    font-weight: 900;
    line-height: 1.05;
    letter-spacing: -2px;
    margin-bottom: 18px;
}

.gradient-text {
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hero-subtitle {
    font-size: 17px;
    color: var(--text-secondary);
    line-height: 1.7;
    margin-bottom: 32px;
    max-width: 540px;
    margin-left: auto;
    margin-right: auto;
}

.hero-actions {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    justify-content: center;
}

/* Hero floating cards — strip below content */
.hero-cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    max-width: 860px;
    width: 100%;
    margin-top: 60px;
    perspective: 800px;
}

.hero-card {
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: var(--bg-card);
    border: 1px solid var(--border-glass);
    animation: heroCardIn 0.8s ease-out both;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
}

.hero-card:hover {
    transform: translateY(-4px) scale(1.02);
    border-color: var(--accent-1);
    box-shadow: var(--shadow-glow);
}

.hero-card img {
    width: 100%;
    aspect-ratio: 16/10;
    object-fit: cover;
    display: block;
}

.hero-card-title {
    padding: 10px 12px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

@keyframes heroCardIn {
    from {
        opacity: 0;
        transform: translateY(30px) rotateX(10deg);
    }

    to {
        opacity: 1;
        transform: translateY(0) rotateX(0);
    }
}

.hero-card:nth-child(1) {
    animation-delay: 0.1s;
}

.hero-card:nth-child(2) {
    animation-delay: 0.2s;
}

.hero-card:nth-child(3) {
    animation-delay: 0.3s;
}

.hero-card:nth-child(4) {
    animation-delay: 0.4s;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-family: var(--font);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: var(--transition);
    text-decoration: none;
}

.btn svg {
    width: 18px;
    height: 18px;
}

.btn-primary {
    background: var(--accent-gradient-2);
    color: white;
    box-shadow: 0 4px 20px rgba(124, 58, 237, 0.4);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 30px rgba(124, 58, 237, 0.5);
}

.btn-primary:active {
    transform: translateY(0) scale(0.97);
    box-shadow: 0 2px 12px rgba(124, 58, 237, 0.4);
}

.btn-glass {
    background: var(--bg-glass-strong);
    color: var(--text-primary);
    border: 1px solid var(--border-glass);
    backdrop-filter: blur(10px);
}

.btn-glass:hover {
    background: var(--bg-glass);
    border-color: var(--border-glass-hover);
    transform: translateY(-1px);
}

.btn-glass:active {
    transform: translateY(0) scale(0.97);
}

/* --- Categories --- */
.categories-section {
    position: relative;
    z-index: 1;
    max-width: var(--content-max);
    margin: 0 auto;
    padding: 0 24px 40px;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.section-header h2 {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.categories-scroll {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 8px;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.categories-scroll::-webkit-scrollbar {
    display: none;
}

.cat-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 100px;
    font-family: var(--font);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid var(--border-glass);
    background: var(--bg-glass);
    color: var(--text-secondary);
    white-space: nowrap;
    transition: var(--transition-fast);
    flex-shrink: 0;
}

.cat-chip:hover {
    background: var(--bg-glass-strong);
    color: var(--text-primary);
    border-color: var(--border-glass-hover);
}

.cat-chip.active {
    background: var(--accent-gradient-2);
    color: white;
    border-color: transparent;
    box-shadow: 0 2px 12px rgba(124, 58, 237, 0.3);
}

.cat-icon {
    font-size: 15px;
}

/* --- Games Grid --- */
.games-section {
    position: relative;
    z-index: 1;
    max-width: var(--content-max);
    margin: 0 auto;
    padding: 20px 24px 60px;
}

.results-count {
    font-size: 14px;
    color: var(--text-muted);
    font-weight: 500;
}

/* --- Grid Controls (sort + results count) --- */
.grid-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sort-select {
    appearance: none;
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 500;
    padding: 6px 28px 6px 10px;
    cursor: pointer;
    outline: none;
    transition: var(--transition-fast);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='rgba(240,240,255,0.4)' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
}

.sort-select:hover,
.sort-select:focus {
    border-color: var(--border-glass-hover);
    color: var(--text-primary);
}

.sort-select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

/* --- Scroll-to-top Button --- */
.scroll-top-btn {
    position: fixed;
    bottom: 28px;
    right: 28px;
    z-index: 900;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--accent-gradient-2);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    box-shadow: 0 4px 20px rgba(124, 58, 237, 0.45);
    opacity: 0;
    transform: translateY(16px) scale(0.85);
    transition: opacity 0.25s ease, transform 0.25s ease, box-shadow 0.2s ease;
    pointer-events: none;
}

.scroll-top-btn.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.scroll-top-btn:hover {
    box-shadow: 0 6px 28px rgba(124, 58, 237, 0.65);
    transform: translateY(-2px) scale(1.05);
}

.scroll-top-btn svg {
    width: 20px;
    height: 20px;
}

/* --- Toast Notifications --- */
.toast-container {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    pointer-events: none;
}

.toast {
    background: var(--bg-glass-strong);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    padding: 10px 20px;
    white-space: nowrap;
    opacity: 0;
    transform: translateY(12px) scale(0.95);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.toast-show {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.games-grid {
    display: grid;
    grid-template-columns: repeat(var(--user-grid-cols, 6), 1fr);
    gap: 14px;
}

/* --- Game Card --- */
.game-card {
    background: var(--bg-card);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-lg);
    overflow: hidden;
    cursor: pointer;
    transition: var(--transition);
    animation: cardIn 0.5s ease-out both;
    position: relative;
}

.game-card:hover {
    transform: translateY(-4px);
    border-color: rgba(124, 58, 237, 0.4);
    box-shadow: 0 0 24px rgba(124, 58, 237, 0.12), 0 8px 32px rgba(0, 0, 0, 0.25);
    background: var(--bg-card-hover);
}

.game-card:active {
    transform: translateY(-1px) scale(0.98);
}

.game-card:hover .card-image img {
    transform: scale(1.06);
}

.card-link {
    text-decoration: none;
    color: inherit;
    display: contents;
}

@keyframes cardIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.card-image {
    position: relative;
    overflow: hidden;
    aspect-ratio: 16/10;
    background: var(--bg-secondary);
}

.card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.5s ease, opacity 0.2s ease;
}

.card-image img.img-fading {
    opacity: 0;
}

.card-image::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 50%;
    background: linear-gradient(to top, var(--bg-primary), transparent);
    pointer-events: none;
}

.card-play-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(124, 58, 237, 0.0);
    transition: var(--transition);
    z-index: 2;
}

.game-card:hover .card-play-overlay {
    background: rgba(124, 58, 237, 0.2);
}

.play-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: scale(0.8);
    transition: opacity 0.25s ease, transform 0.25s ease;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.game-card:hover .play-icon {
    opacity: 1;
    transform: scale(1);
}

.play-icon svg {
    width: 20px;
    height: 20px;
    fill: var(--accent-1);
    margin-left: 2px;
}

.card-body {
    padding: 10px 10px 10px;
}

.card-title {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: -0.2px;
    line-height: 1.3;
}

.card-genres {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.genre-tag {
    font-size: 10px;
    font-weight: 500;
    padding: 2px 6px;
    border-radius: 5px;
    background: var(--bg-glass-strong);
    color: var(--text-secondary);
    border: 1px solid var(--border-glass);
    text-transform: capitalize;
}

/* --- No Results --- */
.no-results {
    text-align: center;
    padding: 80px 20px;
}

.no-results-icon {
    font-size: 64px;
    display: block;
    margin-bottom: 16px;
}

.no-results h3 {
    font-size: 20px;
    margin-bottom: 8px;
}

.no-results p {
    color: var(--text-secondary);
}

/* --- Modal --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(16px) saturate(120%);
    -webkit-backdrop-filter: blur(16px) saturate(120%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    background: linear-gradient(180deg, var(--bg-secondary) 0%, #0c0c20 100%);
    border: 1px solid rgba(124, 58, 237, 0.12);
    border-radius: 20px;
    max-width: 520px;
    width: 100%;
    max-height: 88vh;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
    transform: scale(0.92) translateY(20px);
    opacity: 0;
    transition: transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.25s ease;
    scrollbar-width: thin;
    scrollbar-color: rgba(124, 58, 237, 0.15) transparent;
    box-shadow:
        0 32px 80px rgba(0, 0, 0, 0.55),
        0 0 0 1px rgba(124, 58, 237, 0.06) inset,
        0 0 80px -20px rgba(124, 58, 237, 0.08);
}

.modal-overlay.open .modal {
    transform: scale(1) translateY(0);
    opacity: 1;
}

/* Close button — frosted glass circle */
.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 10;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: rgba(255, 255, 255, 0.75);
    transition: all 0.2s ease;
}

.modal-close svg {
    width: 16px;
    height: 16px;
}

.modal-close:hover {
    background: var(--accent-3);
    border-color: var(--accent-3);
    color: #fff;
    transform: rotate(90deg);
}

/* Stacked layout — image on top, body below */
.modal-split {
    display: flex;
    flex-direction: column;
}

/* Hero image — cinematic banner */
.modal-split .modal-hero {
    width: 100%;
    flex-shrink: 0;
    aspect-ratio: unset;
    border-radius: 20px 20px 0 0;
    align-self: auto;
    height: 240px;
}

.modal-hero {
    position: relative;
    overflow: hidden;
    border-radius: 20px 20px 0 0;
}

/* Gradient fade at bottom of hero image */
.modal-hero::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60%;
    background: linear-gradient(to top, var(--bg-secondary) 0%, rgba(18, 18, 42, 0.5) 50%, transparent 100%);
    pointer-events: none;
    z-index: 1;
}

.modal-hero img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scale(1.08);
    transition: transform 8s cubic-bezier(0.25, 0.1, 0.25, 1);
}

/* Ken Burns — slow zoom out on open */
.modal-overlay.open .modal-hero img {
    transform: scale(1);
}

/* Body — overlaps the image bottom */
.modal-body {
    flex: 1;
    padding: 0 24px 20px;
    display: flex;
    flex-direction: column;
    gap: 0;
    min-height: unset;
    position: relative;
    z-index: 2;
    margin-top: -40px;
}

.modal-body-top {
    flex: 1;
}

.modal-body h2 {
    font-size: 24px;
    font-weight: 800;
    letter-spacing: -0.6px;
    line-height: 1.2;
    margin-bottom: 12px;
    text-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
}

/* Genres — refined pills */
.modal-genres {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}

.modal-genres .genre-tag {
    font-size: 11px;
    font-weight: 500;
    padding: 4px 12px;
    border-radius: 100px;
    background: rgba(124, 58, 237, 0.1);
    border: 1px solid rgba(124, 58, 237, 0.2);
    color: rgba(168, 85, 247, 0.9);
    transition: all 0.15s ease;
}

.modal-genres .genre-tag:hover {
    background: rgba(124, 58, 237, 0.18);
    border-color: rgba(124, 58, 237, 0.35);
}

/* Platform info */
.modal-info {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.info-item {
    display: flex;
    gap: 6px;
    align-items: center;
    font-size: 12px;
    color: var(--text-muted);
    background: transparent;
    padding: 0;
    border-radius: 0;
    border: none;
}

/* Action buttons — grid layout */
.modal-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

/* Play button — hero CTA, full width */
.btn-play {
    grid-column: 1 / -1;
    justify-content: center;
    padding: 15px 20px;
    font-size: 15px;
    font-weight: 700;
    border-radius: var(--radius-md);
    position: relative;
    overflow: hidden;
    letter-spacing: 0.2px;
}

/* Subtle glow pulse behind play button */
.btn-play::before {
    content: '';
    position: absolute;
    inset: -1px;
    border-radius: inherit;
    background: var(--accent-gradient-2);
    opacity: 0;
    filter: blur(12px);
    transition: opacity 0.3s ease;
    z-index: -1;
}

.btn-play:hover::before {
    opacity: 0.5;
}

/* Save & QR — secondary glass buttons */
.btn-modal-fav {
    flex-shrink: 0;
    padding: 11px 14px;
    gap: 6px;
    border-radius: var(--radius-md);
    white-space: nowrap;
    font-size: 13px;
    justify-content: center;
}

.btn-modal-fav svg {
    width: 16px;
    height: 16px;
    transition: transform 0.2s ease;
}

.btn-modal-fav:hover svg {
    transform: scale(1.15);
}

.btn-modal-fav.active {
    border-color: var(--accent-3);
    color: var(--accent-3);
    background: rgba(244, 63, 94, 0.08);
}

/* Full-width detail section */
.modal-detail {
    padding: 16px 24px 24px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.modal-desc {
    font-size: 14px;
    line-height: 1.75;
    color: var(--text-secondary);
    margin-bottom: 16px;
    white-space: pre-line;
}

/* How to play card — left accent border */
.modal-howto {
    background: rgba(124, 58, 237, 0.04);
    border: 1px solid rgba(124, 58, 237, 0.1);
    border-left: 3px solid var(--accent-1);
    border-radius: 4px var(--radius-md) var(--radius-md) 4px;
    padding: 14px 18px;
    margin-bottom: 0;
}

.modal-howto h3 {
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 6px;
    color: rgba(168, 85, 247, 0.9);
}

.modal-howto p {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.65;
    white-space: pre-line;
}

/* --- Favorite button on game cards --- */
.fav-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.55);
    border: 1px solid var(--border-glass);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
    opacity: 0;
    transition: var(--transition-fast);
    z-index: 3;
    backdrop-filter: blur(6px);
}

.game-card:hover .fav-btn {
    opacity: 1;
}

.fav-btn svg {
    width: 15px;
    height: 15px;
    pointer-events: none;
    transition: var(--transition-fast);
}

.fav-btn:hover {
    color: var(--text-secondary);
    background: rgba(0, 0, 0, 0.7);
}

.fav-btn.active {
    color: var(--accent-3);
    border-color: var(--accent-3);
    opacity: 1;
}

/* --- Language Picker --- */
.lang-picker {
    position: relative;
    flex-shrink: 0;
}

.lang-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 10px;
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-fast);
    white-space: nowrap;
}

.lang-btn:hover {
    background: var(--bg-glass-strong);
    color: var(--text-primary);
    border-color: var(--border-glass-hover);
}

.lang-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: rgba(15, 15, 35, 0.97);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    z-index: 999;
    min-width: 150px;
}

.lang-dropdown.open {
    display: block;
    animation: dropIn 0.15s ease-out;
}

@keyframes dropIn {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.lang-option {
    display: block;
    width: 100%;
    padding: 10px 14px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast);
    white-space: nowrap;
}

.lang-option:hover {
    background: var(--bg-glass);
    color: var(--text-primary);
}

.lang-option.active {
    color: var(--text-primary);
    font-weight: 700;
    background: var(--bg-card);
}

/* Static pages — lang picker floats right in slim navbar */
.nav-content > .lang-picker:last-child {
    margin-left: auto;
}

/* --- Settings Panel --- */
.settings-picker {
    position: relative;
    flex-shrink: 0;
}

.settings-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition-fast);
}

.settings-btn:hover,
.settings-btn.active {
    background: var(--bg-glass-strong);
    color: var(--text-primary);
    border-color: var(--border-glass-hover);
}

.settings-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: rgba(12, 12, 30, 0.97);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    z-index: 999;
    min-width: 210px;
    padding: 16px;
}

.settings-dropdown.open {
    display: block;
    animation: dropIn 0.15s ease-out;
}

.settings-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 10px;
}

.grid-cols-options {
    display: flex;
    gap: 6px;
}

.grid-col-opt {
    flex: 1;
    padding: 8px 4px;
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition-fast);
    text-align: center;
}

.grid-col-opt:hover {
    background: var(--bg-glass-strong);
    color: var(--text-primary);
}

.grid-col-opt.active {
    background: linear-gradient(135deg, rgba(124, 58, 237, 0.25), rgba(6, 182, 212, 0.2));
    border-color: var(--accent-1);
    color: var(--text-primary);
}

/* Recent section empty state */
.recent-empty {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 20px;
    background: var(--bg-glass);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    width: 100%;
}

/* --- RTL overrides (Arabic) --- */
[dir="rtl"] .nav-content {
    flex-direction: row-reverse;
}

[dir="rtl"] .lang-dropdown {
    right: auto;
    left: 0;
}

[dir="rtl"] .lang-option {
    text-align: right;
}

[dir="rtl"] .hero-content,
[dir="rtl"] .categories-scroll {
    direction: rtl;
}

[dir="rtl"] .section-header {
    flex-direction: row-reverse;
}

[dir="rtl"] .recent-strip,
[dir="rtl"] .footer-legal,
[dir="rtl"] .footer-links {
    flex-direction: row-reverse;
}

/* --- Recently Played Section --- */
.recent-section {
    position: relative;
    z-index: 1;
    max-width: var(--content-max);
    margin: 0 auto;
    padding: 0 24px 32px;
}

.recent-section .section-header {
    margin-bottom: 14px;
}

.recent-clear-btn {
    background: transparent;
    border: 1px solid var(--border-glass);
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 500;
    font-family: var(--font);
    padding: 5px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: var(--transition-fast);
    white-space: nowrap;
}

.recent-clear-btn:hover {
    color: var(--accent-3);
    border-color: rgba(244, 63, 94, 0.3);
    background: rgba(244, 63, 94, 0.06);
}

.recent-strip {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding-bottom: 6px;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.recent-strip::-webkit-scrollbar {
    display: none;
}

.recent-card {
    flex-shrink: 0;
    width: 130px;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--bg-card);
    border: 1px solid var(--border-glass);
    cursor: pointer;
    transition: var(--transition);
}

.recent-card:hover {
    transform: translateY(-3px);
    border-color: var(--border-glass-hover);
    background: var(--bg-card-hover);
    box-shadow: var(--shadow-card);
}

.recent-card img {
    width: 100%;
    aspect-ratio: 16/9;
    object-fit: cover;
    display: block;
}

.recent-card-title {
    padding: 7px 9px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* --- Footer --- */
.footer {
    position: relative;
    z-index: 1;
    border-top: 1px solid var(--border-glass);
    padding: 48px 24px;
    text-align: center;
}

.footer-content {
    max-width: 600px;
    margin: 0 auto;
}

.footer-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
    margin-bottom: 12px;
}

.footer p {
    color: var(--text-secondary);
    font-size: 14px;
}

.footer-links {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
    margin: 16px 0;
    font-size: 13px;
    color: var(--text-muted);
}

.footer-legal {
    display: flex;
    gap: 10px;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    margin: 12px 0 0;
    font-size: 13px;
}

.footer-legal a {
    color: var(--text-muted);
    text-decoration: none;
    transition: color var(--transition-fast);
}

.footer-legal a:hover {
    color: var(--text-primary);
}

.footer-legal span {
    color: var(--border-glass-hover);
}

.footer-copy {
    margin-top: 16px;
    font-size: 12px;
    color: var(--text-muted);
}

/* --- Responsive --- */

/* Large tablet — lock to 4 cols */
@media (max-width: 1100px) {
    .games-grid {
        grid-template-columns: repeat(4, 1fr) !important;
        gap: 10px;
    }
}

/* Tablet / iPad Landscape — 900px */
@media (max-width: 900px) {
    .nav-stats { display: none; }
    .search-kbd { display: none; }

    .nav-random-btn .btn-text { display: none; }
    .nav-random-btn { padding: 8px 10px; gap: 0; }

    .hero { padding-top: 100px; min-height: auto; }
    .hero-cards { grid-template-columns: repeat(2, 1fr); max-width: 480px; }
}

/* iPad Portrait — 768px */
@media (max-width: 768px) {
    .navbar { padding: 0 16px; }
    .nav-content { gap: 10px; }

    .hero { padding: 90px 20px 36px; }
    .hero h1 { font-size: 38px; }
    .hero-subtitle { font-size: 16px; }
    .hero-cards { display: none; }

    .games-grid {
        grid-template-columns: repeat(4, 1fr) !important;
        gap: 10px;
    }

    .recent-section { padding: 0 20px 24px; }
    .categories-section { padding: 0 20px 28px; }
    .games-section { padding: 16px 20px 48px; }
}

/* Large phone — 640px */
@media (max-width: 640px) {
    .hero { padding: 80px 16px 36px; }
    .hero-cards { display: none; }
    .hero-subtitle { font-size: 15px; margin-bottom: 24px; }

    .recent-section { padding: 0 16px 24px; }
    .recent-card { width: 110px; }
    .categories-section { padding: 0 16px 28px; }
    .games-section { padding: 16px 16px 48px; }
}

/* Small phone — 600px */
@media (max-width: 600px) {
    .hero h1 { font-size: 30px; }

    .games-grid {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 8px;
    }

    /* Search bar fills all available nav space */
    .nav-search { max-width: none; flex: 1; }

    /* Modal → bottom sheet */
    .modal-overlay { align-items: flex-end; padding: 0; }
    .modal {
        border-radius: 20px 20px 0 0;
        max-height: 92vh;
        max-width: 100%;
    }
    .modal-hero { border-radius: 20px 20px 0 0; }
    .modal-split .modal-hero { height: 200px; border-radius: 20px 20px 0 0; }
    .modal-body { padding: 0 20px 16px; }
    .modal-detail { padding: 12px 20px 20px; }

    /* Touch always shows fav — no hover state */
    .fav-btn { opacity: 1; }

    /* Larger tap targets */
    .cat-chip { padding: 10px 16px; }

    /* Single-column actions on mobile */
    .modal-actions { grid-template-columns: 1fr 1fr; }

    .section-header h2 { font-size: 18px; }
}

/* Extra small phone — 480px */
@media (max-width: 480px) {
    .navbar { padding: 0 12px; }
    .nav-content { gap: 8px; }
    .nav-random-btn { display: none; } /* icon-only random btn removed to save space */

    .logo-text { font-size: 17px; }

    .hero h1 { font-size: 28px; letter-spacing: -1.5px; }

    .hero-actions { flex-direction: column; width: 100%; }
    .hero-actions .btn { width: 100%; justify-content: center; }

    .modal-split .modal-hero { height: 180px; }
    .modal-body { padding: 0 16px 16px; margin-top: -28px; }
    .modal-body h2 { font-size: 20px; }
    .modal-detail { padding: 12px 16px 20px; }
    .modal-desc { max-height: 120px; overflow-y: auto; }

    .games-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px;
    }

    /* Settings dropdown fits narrow screens */
    .settings-dropdown { min-width: 180px; }
}

/* Small fold / large mini — 380px */
@media (max-width: 380px) {
    .logo-text { display: none; } /* icon-only logo */
    .lang-picker { display: none; }
    .settings-dropdown { min-width: calc(100vw - 24px); right: 0; }

    .hero h1 { font-size: 24px; letter-spacing: -1px; }
    .hero-subtitle { font-size: 13px; }

    .games-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 6px;
    }

    .card-title { font-size: 11px; }
    .card-body { padding: 6px 8px 8px; }
}

/* Fold inner screen / tiny — 280px */
@media (max-width: 280px) {
    .nav-content { gap: 6px; }
    .settings-btn { width: 28px; height: 28px; }

    .hero { padding: 70px 12px 24px; }
    .hero h1 { font-size: 20px; letter-spacing: -0.5px; }
    .hero-subtitle { display: none; }
    .hero-actions .btn { padding: 10px 16px; font-size: 13px; }

    .games-grid {
        grid-template-columns: repeat(1, 1fr) !important;
        gap: 6px;
    }

    .recent-section,
    .categories-section,
    .games-section { padding-left: 10px; padding-right: 10px; }

    .section-header h2 { font-size: 16px; }
    .cat-chip { padding: 8px 12px; font-size: 12px; }

    /* Modal full-screen on fold */
    .modal { border-radius: 0; max-height: 100vh; }
    .modal-hero { border-radius: 0; }
    .modal-split .modal-hero { height: 150px; border-radius: 0; }
    .modal-overlay { padding: 0; }
    .modal-actions { grid-template-columns: 1fr; }
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-glass);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-glass-hover);
}

/* --- Selection --- */
::selection {
    background: rgba(124, 58, 237, 0.3);
}

/* --- QR Code Feature (modal) --- */
.btn-modal-qr {
    flex-shrink: 0;
    font-size: 13px;
    justify-content: center;
}

.btn-modal-qr.active {
    border-color: var(--accent-2);
    color: var(--accent-2);
    background: rgba(6, 182, 212, 0.08);
}

.modal-qr-panel {
    overflow: hidden;
    max-height: 0;
    opacity: 0;
    margin-top: 0;
    transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.25s ease, margin-top 0.25s ease;
}

.modal-qr-panel.open {
    max-height: 260px;
    opacity: 1;
    margin-top: 12px;
}

.modal-qr-inner {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 16px;
    background: rgba(6, 182, 212, 0.04);
    border: 1px solid rgba(6, 182, 212, 0.1);
    border-radius: var(--radius-md);
}

.modal-qr-inner img {
    width: 140px;
    height: 140px;
    border-radius: var(--radius-sm);
    background: #fff;
    flex-shrink: 0;
    display: block;
    padding: 6px;
}

.modal-qr-caption {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.modal-qr-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-qr-url {
    font-size: 10px;
    color: var(--text-muted);
    word-break: break-all;
    line-height: 1.5;
    font-family: monospace;
}

@media (max-width: 600px) {
    .btn-modal-qr { justify-content: center; }
    .modal-qr-inner { flex-direction: column; align-items: center; text-align: center; gap: 12px; padding: 14px; }
    .modal-qr-inner img { width: 130px; height: 130px; }
}

/* --- Skeleton Loading --- */
@keyframes skeleton-shimmer {
    0%   { background-position: -200% 0; }
    100% { background-position:  200% 0; }
}

.skel {
    background: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0.04) 25%,
        rgba(255, 255, 255, 0.10) 50%,
        rgba(255, 255, 255, 0.04) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.6s infinite linear;
    border-radius: var(--radius-sm);
}

/* Skeleton game card — mirrors .game-card structure */
.skel-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border-glass);
}

.skel-card-img {
    width: 100%;
    aspect-ratio: 16/10;
}

.skel-card-body {
    padding: 8px 10px 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.skel-card-title {
    height: 13px;
    width: 75%;
}

.skel-card-genre {
    height: 16px;
    width: 44%;
    border-radius: 20px;
}

/* Skeleton category chip */
.skel-chip {
    display: inline-block;
    height: 36px;
    border-radius: 20px;
    flex-shrink: 0;
}

/* Skeleton recent card */
.skel-recent {
    flex-shrink: 0;
    width: 120px;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--bg-card);
    border: 1px solid var(--border-glass);
}

.skel-recent-img {
    width: 100%;
    aspect-ratio: 16/9;
}

.skel-recent-title {
    margin: 6px 8px 8px;
    height: 12px;
    width: 70%;
    border-radius: 4px;
}

/* --- Reduced Motion --- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    .orb { animation: none !important; opacity: 0.2; }
    .game-card { animation: none; }
    .hero-card { animation: none; }
}