/* ─── Tokens ──────────────────────────────────────────────────────────────── */
:root {
    --bg:          #f0f4ff;
    --card-bg:     rgba(255, 255, 255, 0.92);
    --text:        #1a202c;
    --text-sub:    #64748b;
    --accent:      #6366f1;
    --accent-glow: rgba(99, 102, 241, 0.3);
    --shadow:      rgba(0, 0, 0, 0.07);
    --border:      rgba(0, 0, 0, 0.07);
    --header-bg:   rgba(240, 244, 255, 0.92);
    --modal-bg:    #ffffff;
    --t:           all 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    --r-lg:        20px;
    --r-md:        14px;
}

body.dark-theme {
    --bg:          #0d1117;
    --card-bg:     rgba(22, 30, 46, 0.88);
    --text:        #e6edf3;
    --text-sub:    #7d8590;
    --accent:      #818cf8;
    --accent-glow: rgba(129, 140, 248, 0.35);
    --shadow:      rgba(0, 0, 0, 0.5);
    --border:      rgba(255, 255, 255, 0.07);
    --header-bg:   rgba(13, 17, 23, 0.94);
    --modal-bg:    #161b22;
}

/* ─── Category colours ────────────────────────────────────────────────────── */
.game-card[data-category="action"] { --cat: #ef4444; --cat-bg: rgba(239, 68,  68,  0.12); }
.game-card[data-category="io"]     { --cat: #10b981; --cat-bg: rgba(16,  185, 129, 0.12); }
.game-card[data-category="puzzle"] { --cat: #3b82f6; --cat-bg: rgba(59,  130, 246, 0.12); }
.game-card[data-category="sports"] { --cat: #f59e0b; --cat-bg: rgba(245, 158, 11,  0.12); }
.game-card[data-category="apps"]   { --cat: #8b5cf6; --cat-bg: rgba(139, 92,  246, 0.12); }

/* ─── Reset & base ────────────────────────────────────────────────────────── */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

body {
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
    transition: background 0.4s ease, color 0.4s ease;
}

/* Subtle dot grid background */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background-image: radial-gradient(circle, var(--border) 1px, transparent 1px);
    background-size: 32px 32px;
    pointer-events: none;
    z-index: 0;
}

.app-container {
    max-width: 1440px;
    margin: 0 auto;
    padding: 0 2rem;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    position: relative;
    z-index: 1;
}

/* ─── Header ──────────────────────────────────────────────────────────────── */
header {
    height: 68px;
    display: flex;
    align-items: center;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--header-bg);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    margin: 0 -2rem;
    padding: 0 2rem;
    border-bottom: 1px solid var(--border);
}

.logo {
    font-size: 1.45rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    flex-shrink: 0;
    color: var(--text);
    user-select: none;
}

.highlight {
    background: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.search-container {
    flex: 1;
    position: relative;
    max-width: 460px;
}

#gameSearch {
    width: 100%;
    padding: 10px 16px 10px 40px;
    border-radius: 30px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 0.925rem;
    outline: none;
    transition: var(--t);
}

#gameSearch::placeholder { color: var(--text-sub); }

#gameSearch:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.search-icon {
    position: absolute;
    left: 13px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.875rem;
    pointer-events: none;
}

.actions {
    display: flex;
    gap: 8px;
    margin-left: auto;
}

.icon-btn {
    background: var(--card-bg);
    border: 1px solid var(--border);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.05rem;
    transition: var(--t);
    box-shadow: 0 2px 6px var(--shadow);
    flex-shrink: 0;
}

.icon-btn:hover {
    transform: scale(1.1);
    background: var(--accent);
    border-color: transparent;
}

/* Panic active: green pulse */
body.panic-active #panicBtn {
    background: #10b981;
    border-color: transparent;
    animation: pulse-green 1.5s ease infinite;
}

@keyframes pulse-green {
    0%, 100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.5); }
    50%       { box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
}

/* ─── Main ────────────────────────────────────────────────────────────────── */
main {
    padding: 2rem 0;
    flex: 1;
}

/* ─── Filter bar ──────────────────────────────────────────────────────────── */
.filter-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 1.75rem;
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: none;
}
.filter-bar::-webkit-scrollbar { display: none; }

.filter-btn {
    padding: 8px 18px;
    border-radius: 30px;
    border: 1px solid var(--border);
    background: var(--card-bg);
    color: var(--text-sub);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
    transition: var(--t);
    white-space: nowrap;
    backdrop-filter: blur(8px);
}

.filter-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.filter-btn.active {
    background: var(--accent);
    color: #fff;
    border-color: transparent;
    box-shadow: 0 4px 14px var(--accent-glow);
}

.fav-filter.active {
    background: linear-gradient(135deg, #ef4444, #ec4899);
    box-shadow: 0 4px 14px rgba(239, 68, 68, 0.35);
}

/* ─── Game Grid ───────────────────────────────────────────────────────────── */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
    gap: 12px;
}

/* ─── Game Card ───────────────────────────────────────────────────────────── */
.game-card {
    position: relative;
    background: var(--card-bg);
    border-radius: var(--r-md);
    border: 1px solid var(--border);
    border-top: 3px solid var(--cat, var(--accent));
    padding: 22px 14px 16px;
    cursor: pointer;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    min-height: 120px;
    box-shadow: 0 2px 8px var(--shadow);
    transition: var(--t);
    animation: cardIn 0.35s ease backwards;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    overflow: hidden;
}

.game-card::after {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at 50% 0%, var(--cat-bg, rgba(99,102,241,0.07)), transparent 65%);
    pointer-events: none;
}

.game-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 16px 40px var(--shadow), 0 0 0 1.5px var(--cat, var(--accent));
}

@keyframes cardIn {
    from { opacity: 0; transform: translateY(14px) scale(0.96); }
    to   { opacity: 1; transform: translateY(0)    scale(1);    }
}

.card-emoji {
    font-size: 2.1rem;
    line-height: 1;
    display: block;
}

.card-name {
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1.3;
}

.card-badge {
    font-size: 0.62rem;
    font-weight: 700;
    padding: 2px 9px;
    border-radius: 20px;
    background: var(--cat-bg, rgba(99, 102, 241, 0.1));
    color: var(--cat, var(--accent));
    text-transform: uppercase;
    letter-spacing: 0.6px;
}

/* Favorite button on card */
.fav-btn {
    position: absolute;
    top: 7px;
    right: 7px;
    background: none;
    border: none;
    font-size: 0.8rem;
    cursor: pointer;
    color: var(--text-sub);
    padding: 4px;
    line-height: 1;
    transition: transform 0.2s ease, color 0.2s ease;
    border-radius: 6px;
    z-index: 1;
}

.fav-btn:hover       { transform: scale(1.35); color: #ef4444; }
.fav-btn.is-fav      { color: #ef4444; }

/* No results */
.no-results {
    grid-column: 1 / -1;
    text-align: center;
    padding: 70px 20px;
    color: var(--text-sub);
}

.no-results .nr-icon {
    font-size: 3rem;
    display: block;
    margin-bottom: 12px;
}

/* ─── Modal ───────────────────────────────────────────────────────────────── */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.88);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.modal.show {
    opacity: 1;
    pointer-events: all;
}

.modal-content {
    background: var(--modal-bg);
    width: 96vw;
    height: 92vh;
    border-radius: var(--r-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 0 100px rgba(0, 0, 0, 0.8), 0 0 0 1px var(--border);
    transform: scale(0.94);
    transition: transform 0.32s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal.show .modal-content {
    transform: scale(1);
}

.modal-header {
    padding: 10px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    gap: 12px;
}

.modal-header h2 {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.modal-controls {
    display: flex;
    gap: 7px;
    flex-shrink: 0;
}

.modal-controls button {
    background: var(--card-bg);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 0.95rem;
    cursor: pointer;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    transition: var(--t);
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-controls button:hover {
    background: var(--accent);
    border-color: transparent;
    color: #fff;
}

#favoriteModalBtn.is-fav {
    background: #ef4444;
    border-color: transparent;
    color: #fff;
}

.iframe-wrapper {
    flex: 1;
    position: relative;
    background: #000;
}

#gameIframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
}

.loader {
    width: 48px;
    height: 48px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation: spin 0.75s linear infinite;
    z-index: 2;
}

@keyframes spin {
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* ─── Footer ──────────────────────────────────────────────────────────────── */
footer {
    padding: 28px 0;
    text-align: center;
    color: var(--text-sub);
    border-top: 1px solid var(--border);
    font-size: 0.825rem;
}

footer kbd {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 1px 6px;
    font-size: 0.78rem;
    font-family: monospace;
    box-shadow: 0 1px 0 var(--border);
}

/* ─── Auto-cloak active ───────────────────────────────────────────────────── */
body.auto-cloak-on #autoCloakBtn {
    background: #6366f1;
    border-color: transparent;
    animation: pulse-green 1.5s ease infinite;
}

/* ─── Panic Overlay (fake Google Docs) ───────────────────────────────────── */
.panic-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: #f8f9fa;
    flex-direction: column;
    font-family: Arial, sans-serif;
}

body.panic-active .panic-overlay { display: flex; }

.gdocs-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 16px;
    background: #fff;
    border-bottom: 1px solid #e0e0e0;
    flex-shrink: 0;
}

.gdocs-left { display: flex; align-items: center; gap: 10px; }

.gdocs-logo { width: 36px; height: 36px; flex-shrink: 0; }

.gdocs-meta { display: flex; flex-direction: column; }

.gdocs-title {
    font-size: 18px;
    color: #202124;
    font-family: 'Google Sans', Arial, sans-serif;
    line-height: 1.2;
}

.gdocs-menu {
    font-size: 13px;
    color: #444746;
    margin-top: 2px;
    letter-spacing: 0;
}

.gdocs-right { display: flex; align-items: center; gap: 10px; }

.gdocs-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #4285f4;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
}

.gdocs-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 16px;
    background: #f8f9fa;
    border-bottom: 1px solid #e0e0e0;
    font-size: 13px;
    color: #444;
    flex-shrink: 0;
}

.gdocs-sep { color: #ccc; user-select: none; }

.gdocs-body {
    flex: 1;
    overflow-y: auto;
    background: #f8f9fa;
    display: flex;
    justify-content: center;
    padding: 40px 20px;
}

.gdocs-page {
    background: #fff;
    width: 816px;
    max-width: 100%;
    min-height: 1056px;
    padding: 96px 96px 96px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    font-size: 11pt;
    line-height: 1.7;
    color: #202124;
}

.gdocs-heading {
    font-size: 18pt;
    font-weight: 700;
    margin-bottom: 16px;
    color: #1a73e8;
}

.gdocs-subheading {
    font-size: 13pt;
    font-weight: 600;
    color: #202124;
    margin-top: 4px;
}

/* ─── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    header {
        flex-wrap: wrap;
        height: auto;
        padding: 12px 1rem;
        gap: 10px;
        margin: 0 -1rem;
    }

    .search-container {
        order: 3;
        max-width: 100%;
        width: 100%;
    }

    .logo { font-size: 1.25rem; }

    .app-container { padding: 0 1rem; }

    .grid {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
        gap: 10px;
    }

    .modal-content {
        width: 100vw;
        height: 100dvh;
        border-radius: 0;
    }
}
