/**
 * MiniGames Platform - Design System
 * Mobile-first, dark theme with vibrant accents
 */

/* ========== CSS Variables ========== */
:root {
    /* Colors - Dark Theme */
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-card: #1a1a25;
    --bg-card-hover: #222233;
    --bg-overlay: rgba(0, 0, 0, 0.85);

    /* Accent Colors */
    --accent-primary: #6366f1;
    --accent-secondary: #8b5cf6;
    --accent-tertiary: #ec4899;
    --accent-glow: rgba(99, 102, 241, 0.4);

    /* Gradients */
    --gradient-primary: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #ec4899 100%);
    --gradient-dark: linear-gradient(180deg, #12121a 0%, #0a0a0f 100%);
    --gradient-card: linear-gradient(145deg, rgba(26, 26, 37, 0.9) 0%, rgba(18, 18, 26, 0.9) 100%);
    --gradient-glow: radial-gradient(circle at 50% -20%, var(--accent-glow) 0%, transparent 70%);

    /* Text Colors */
    --text-primary: #ffffff;
    --text-secondary: #a0a0b0;
    --text-muted: #606070;

    /* Status Colors */
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;

    /* Spacing */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;
    --space-3xl: 4rem;

    /* Border Radius */
    --radius-sm: 0.375rem;
    --radius-md: 0.75rem;
    --radius-lg: 1rem;
    --radius-xl: 1.5rem;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 30px var(--accent-glow);

    /* Typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-display: 'Outfit', var(--font-sans);

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-base: 250ms ease;
    --transition-slow: 400ms ease;

    /* Z-index layers */
    --z-base: 0;
    --z-dropdown: 100;
    --z-sticky: 200;
    --z-overlay: 300;
    --z-modal: 400;
    --z-toast: 500;
}

/* ========== Base Styles ========== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Background glow effect */
body::before {
    content: '';
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: var(--gradient-glow);
    opacity: 0.3;
    pointer-events: none;
    z-index: -1;
    animation: bgPulse 8s ease-in-out infinite;
}

@keyframes bgPulse {

    0%,
    100% {
        transform: scale(1);
        opacity: 0.3;
    }

    50% {
        transform: scale(1.1);
        opacity: 0.4;
    }
}

/* ========== Typography ========== */
h1,
h2,
h3,
h4,
h5,
h6 {
    font-family: var(--font-display);
    font-weight: 700;
    line-height: 1.2;
    color: var(--text-primary);
}

h1 {
    font-size: clamp(2rem, 5vw, 3.5rem);
}

h2 {
    font-size: clamp(1.5rem, 4vw, 2.5rem);
}

h3 {
    font-size: clamp(1.25rem, 3vw, 1.75rem);
}

h4 {
    font-size: 1.25rem;
}

p {
    color: var(--text-secondary);
}

a {
    color: var(--accent-primary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--accent-secondary);
}

/* Gradient text */
.text-gradient {
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* ========== Layout ========== */
.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--space-md);
}

.grid {
    display: grid;
    gap: var(--space-lg);
}

.grid-games {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

/* ========== Header ========== */
.header {
    position: sticky;
    top: 0;
    background: rgba(10, 10, 15, 0.8);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding: var(--space-md) 0;
    z-index: var(--z-sticky);
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-md);
}

.logo {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 800;
}

.logo-icon {
    width: 40px;
    height: 40px;
    background: var(--gradient-primary);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

/* ========== Buttons ========== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-lg);
    font-family: var(--font-sans);
    font-size: 0.9375rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: all var(--transition-base);
    text-decoration: none;
}

.btn-primary {
    background: var(--gradient-primary);
    color: white;
    box-shadow: var(--shadow-md), 0 0 20px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg), 0 0 30px rgba(99, 102, 241, 0.5);
}

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-secondary:hover {
    background: var(--bg-card-hover);
    border-color: rgba(255, 255, 255, 0.2);
}

.btn-icon {
    width: 44px;
    height: 44px;
    padding: 0;
    border-radius: var(--radius-md);
}

.btn-glow {
    animation: btnGlow 2s ease-in-out infinite;
}

@keyframes btnGlow {

    0%,
    100% {
        box-shadow: var(--shadow-md), 0 0 20px rgba(99, 102, 241, 0.3);
    }

    50% {
        box-shadow: var(--shadow-lg), 0 0 40px rgba(99, 102, 241, 0.5);
    }
}

/* ========== Cards ========== */
.card {
    background: var(--gradient-card);
    backdrop-filter: blur(10px);
    border-radius: var(--radius-lg);
    border: 1px solid rgba(255, 255, 255, 0.08);
    overflow: hidden;
    transition: all var(--transition-base);
}

.card:hover {
    transform: translateY(-4px);
    border-color: rgba(99, 102, 241, 0.3);
    box-shadow: var(--shadow-lg), 0 0 30px rgba(99, 102, 241, 0.15);
}

/* Game Card */
.game-card {
    position: relative;
    aspect-ratio: 16 / 10;
    cursor: pointer;
}

.game-card-bg {
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: center;
    transition: transform var(--transition-slow);
}

.game-card:hover .game-card-bg {
    transform: scale(1.1);
}

.game-card-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.9) 0%, transparent 60%);
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: var(--space-lg);
}

.game-card-title {
    font-size: 1.25rem;
    margin-bottom: var(--space-xs);
}

.game-card-desc {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: var(--space-sm);
}

.game-card-controls {
    display: flex;
    gap: var(--space-xs);
}

.control-badge {
    font-size: 0.75rem;
    padding: var(--space-xs) var(--space-sm);
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
}

.game-card-play {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.8);
    opacity: 0;
    width: 64px;
    height: 64px;
    background: var(--gradient-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    transition: all var(--transition-base);
    box-shadow: var(--shadow-glow);
}

.game-card:hover .game-card-play {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
}

/* ========== Hero Section ========== */
.hero {
    text-align: center;
    padding: var(--space-3xl) 0;
}

.hero-title {
    margin-bottom: var(--space-md);
}

.hero-subtitle {
    font-size: 1.125rem;
    max-width: 600px;
    margin: 0 auto var(--space-xl);
}

/* ========== Section Headers ========== */
.section {
    padding: var(--space-2xl) 0;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-lg);
    flex-wrap: wrap;
    gap: var(--space-sm);
}

.section-title {
    font-size: 1.5rem;
}

/* ========== Daily Challenge Banner ========== */
.daily-banner {
    background: var(--gradient-card);
    border: 1px solid rgba(236, 72, 153, 0.3);
    border-radius: var(--radius-xl);
    padding: var(--space-lg);
    display: flex;
    align-items: center;
    gap: var(--space-lg);
    margin-bottom: var(--space-2xl);
    position: relative;
    overflow: hidden;
}

.daily-banner::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at top right, rgba(236, 72, 153, 0.15) 0%, transparent 50%);
    pointer-events: none;
}

.daily-icon {
    flex-shrink: 0;
    width: 60px;
    height: 60px;
    background: var(--gradient-primary);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
}

.daily-content {
    flex: 1;
}

.daily-title {
    font-size: 1.125rem;
    margin-bottom: var(--space-xs);
}

.daily-game {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.daily-timer {
    text-align: right;
}

.daily-timer-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.daily-timer-value {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent-tertiary);
}

/* ========== Leaderboard ========== */
.leaderboard {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid rgba(255, 255, 255, 0.05);
    overflow: hidden;
}

.leaderboard-header {
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.leaderboard-title {
    font-size: 1rem;
    font-weight: 600;
}

.leaderboard-tabs {
    display: flex;
    gap: var(--space-xs);
}

.leaderboard-tab {
    padding: var(--space-xs) var(--space-sm);
    font-size: 0.75rem;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.leaderboard-tab:hover,
.leaderboard-tab.active {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.leaderboard-list {
    list-style: none;
}

.leaderboard-item {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    transition: background var(--transition-fast);
}

.leaderboard-item:hover {
    background: rgba(255, 255, 255, 0.02);
}

.leaderboard-item:last-child {
    border-bottom: none;
}

.leaderboard-item.is-player {
    background: rgba(99, 102, 241, 0.1);
}

.leaderboard-rank {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.875rem;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.05);
}

.leaderboard-rank.gold {
    background: linear-gradient(135deg, #ffd700 0%, #ffb347 100%);
    color: #000;
}

.leaderboard-rank.silver {
    background: linear-gradient(135deg, #c0c0c0 0%, #a0a0a0 100%);
    color: #000;
}

.leaderboard-rank.bronze {
    background: linear-gradient(135deg, #cd7f32 0%, #b87333 100%);
    color: #000;
}

.leaderboard-name {
    flex: 1;
    font-weight: 500;
}

.leaderboard-score {
    font-family: var(--font-display);
    font-weight: 700;
    color: var(--accent-primary);
}

/* ========== Game Container ========== */
.game-wrapper {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
}

.game-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-md);
}

.game-canvas-wrapper {
    position: relative;
    width: 100%;
    max-width: 800px;
    aspect-ratio: 16 / 9;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}

.game-canvas-wrapper canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* Game HUD */
.game-hud {
    position: absolute;
    top: var(--space-md);
    left: var(--space-md);
    right: var(--space-md);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    pointer-events: none;
    z-index: 10;
}

.game-hud>* {
    pointer-events: auto;
}

.game-score {
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 700;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

.game-controls {
    display: flex;
    gap: var(--space-sm);
}

/* ========== Modals ========== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-md);
    z-index: var(--z-modal);
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-base);
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--bg-card);
    border-radius: var(--radius-xl);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: var(--space-2xl);
    max-width: 400px;
    width: 100%;
    text-align: center;
    transform: scale(0.9) translateY(20px);
    transition: transform var(--transition-base);
}

.modal-overlay.active .modal {
    transform: scale(1) translateY(0);
}

.modal-icon {
    font-size: 4rem;
    margin-bottom: var(--space-lg);
}

.modal-title {
    font-size: 1.75rem;
    margin-bottom: var(--space-sm);
}

.modal-score {
    font-family: var(--font-display);
    font-size: 3rem;
    font-weight: 700;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: var(--space-md);
}

.modal-rank {
    color: var(--text-secondary);
    margin-bottom: var(--space-lg);
}

.modal-actions {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

/* Game Over Modal Specifics */
.game-over-modal {
    padding: var(--space-xl);
    background: rgba(26, 26, 37, 0.95);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5), var(--shadow-glow);
}

.modal-game-name {
    color: var(--text-muted);
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: var(--space-xl);
}

.modal-score-container {
    margin-bottom: var(--space-xl);
    position: relative;
    padding: var(--space-lg);
    background: rgba(255, 255, 255, 0.03);
    border-radius: var(--radius-lg);
}

.modal-score-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: var(--space-xs);
}

.modal-score {
    font-size: 4.5rem !important;
    line-height: 1;
    margin-bottom: 0 !important;
}

.new-best-badge {
    position: absolute;
    top: -10px;
    right: -10px;
    background: var(--accent-tertiary);
    color: white;
    font-size: 0.75rem;
    font-weight: 800;
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
    transform: rotate(12deg);
    box-shadow: 0 4px 12px rgba(236, 72, 153, 0.4);
    animation: pulseScale 2s infinite;
}

@keyframes pulseScale {

    0%,
    100% {
        transform: rotate(12deg) scale(1);
    }

    50% {
        transform: rotate(12deg) scale(1.1);
    }
}

.modal-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-md);
    margin-bottom: var(--space-xl);
}

.modal-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-xs);
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.stat-value {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.125rem;
}

.fade-out {
    opacity: 0;
    transition: opacity 0.3s ease;
}

/* ========== Loading ========== */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-primary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-lg);
    z-index: var(--z-overlay);
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-progress {
    width: 200px;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.loading-progress-bar {
    height: 100%;
    background: var(--gradient-primary);
    width: 0%;
    transition: width var(--transition-base);
}

/* ========== Toasts / Notifications ========== */
.toast-container {
    position: fixed;
    bottom: var(--space-lg);
    right: var(--space-lg);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.toast {
    background: var(--bg-card);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-md);
    padding: var(--space-md) var(--space-lg);
    display: flex;
    align-items: center;
    gap: var(--space-md);
    animation: slideIn var(--transition-base);
    box-shadow: var(--shadow-lg);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.toast-icon {
    font-size: 1.25rem;
}

.toast.success {
    border-color: var(--success);
}

.toast.success .toast-icon {
    color: var(--success);
}

.toast.error {
    border-color: var(--error);
}

.toast.error .toast-icon {
    color: var(--error);
}

/* ========== Achievement Popup ========== */
.achievement-popup {
    position: fixed;
    top: var(--space-lg);
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background: var(--bg-card);
    border: 1px solid var(--accent-primary);
    border-radius: var(--radius-lg);
    padding: var(--space-md) var(--space-xl);
    display: flex;
    align-items: center;
    gap: var(--space-md);
    z-index: var(--z-toast);
    opacity: 0;
    transition: all var(--transition-slow);
    box-shadow: var(--shadow-glow);
}

.achievement-popup.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.achievement-icon {
    font-size: 2rem;
    animation: bounce 0.5s ease;
}

@keyframes bounce {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.2);
    }
}

.achievement-text {
    text-align: left;
}

.achievement-label {
    font-size: 0.75rem;
    color: var(--accent-primary);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.achievement-name {
    font-weight: 600;
}

/* ========== Utilities ========== */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.text-center {
    text-align: center;
}

.text-muted {
    color: var(--text-muted);
}

.mt-sm {
    margin-top: var(--space-sm);
}

.mt-md {
    margin-top: var(--space-md);
}

.mt-lg {
    margin-top: var(--space-lg);
}

.mb-sm {
    margin-bottom: var(--space-sm);
}

.mb-md {
    margin-bottom: var(--space-md);
}

.mb-lg {
    margin-bottom: var(--space-lg);
}

/* ========== Responsive ========== */
@media (max-width: 768px) {
    .daily-banner {
        flex-direction: column;
        text-align: center;
    }

    .daily-timer {
        text-align: center;
    }

    .section-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .toast-container {
        left: var(--space-md);
        right: var(--space-md);
    }

    .toast {
        width: 100%;
    }
}

@media (max-width: 480px) {
    html {
        font-size: 14px;
    }

    .game-card {
        aspect-ratio: 4 / 3;
    }
}

/* ========== Print ========== */
@media print {

    .header,
    .game-controls,
    .modal-overlay,
    .toast-container {
        display: none !important;
    }
}