@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=Outfit:wght@500;700;800&display=swap');

:root {
    /* Colors */
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-light: #e0e7ff;

    --success: #10b981;
    --success-light: #d1fae5;

    --warning: #f59e0b;
    --warning-light: #fef3c7;

    --info: #06b6d4;
    --info-light: #cffafe;

    --danger: #ef4444;
    --danger-light: #fee2e2;

    /* Light Theme Defaults */
    --bg: #F8FAFC;
    --surface: #FFFFFF;
    --surface-secondary: #F1F5F9;
    --text: #0F172A;
    --text-muted: #475569;

    /* Visible Thin Border */
    --border: #E2E8F0;
    --border-highlight: #CBD5E1;

    --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.02), 0 2px 4px -1px rgba(0, 0, 0, 0.02);
    --shadow: 0 20px 40px -5px rgba(0, 0, 0, 0.05), 0 10px 20px -5px rgba(0, 0, 0, 0.02);
    --glass: blur(16px);

    /* Design System: Ethereal */
    --radius-card: 24px;
    --radius-btn: 14px;
    --font-heading: 'Outfit', sans-serif;
    --font-body: 'Inter', sans-serif;
}

[data-theme="dark"] {
    --bg: #0B1120;
    --surface: rgba(17, 24, 39, 0.6);
    --surface-secondary: rgba(31, 41, 55, 0.4);
    --text: #F8FAFC;
    --text-muted: #94A3B8;

    /* Dark Borders */
    --border: #334155;
    --border-highlight: #475569;

    --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.3);

    --primary-light: rgba(99, 102, 241, 0.2);
    --success-light: rgba(16, 185, 129, 0.2);
    --warning-light: rgba(245, 158, 11, 0.2);
    --info-light: rgba(6, 182, 212, 0.2);
    --danger-light: rgba(239, 68, 68, 0.2);
}

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

body {
    font-family: var(--font-body);
    background-color: var(--bg);
    color: var(--text);
    min-height: 100vh;
    padding: 32px 24px;
    line-height: 1.5;
    transition: background-color 0.3s ease, color 0.3s ease;

    /* Atmosphere: Mesh Gradient */
    background-image:
        radial-gradient(at 0% 0%, hsla(253, 16%, 90%, 1) 0, transparent 50%),
        radial-gradient(at 50% 0%, hsla(225, 39%, 95%, 1) 0, transparent 50%),
        radial-gradient(at 100% 0%, hsla(339, 49%, 90%, 1) 0, transparent 50%);
    background-attachment: fixed;
}

[data-theme="dark"] body {
    background-image:
        radial-gradient(at 0% 0%, hsla(253, 16%, 10%, 1) 0, transparent 50%),
        radial-gradient(at 50% 0%, hsla(225, 39%, 15%, 1) 0, transparent 50%),
        radial-gradient(at 100% 0%, hsla(339, 49%, 10%, 1) 0, transparent 50%);
}

.container {
    max-width: 1000px;
    margin: 0 auto;
}

/* Animations */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

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

.cards-grid>*,
.game-layout,
.main-progress,
.live-stats-grid>* {
    animation: fadeInUp 0.6s cubic-bezier(0.16, 1, 0.3, 1) backwards;
}

.cards-grid>*:nth-child(1) {
    animation-delay: 0.1s;
}

.cards-grid>*:nth-child(2) {
    animation-delay: 0.2s;
}

.cards-grid>*:nth-child(3) {
    animation-delay: 0.3s;
}

.cards-grid>*:nth-child(4) {
    animation-delay: 0.4s;
}

.main-progress {
    animation-delay: 0.5s;
}

.game-layout {
    animation-delay: 0.6s;
}

.live-stats-header {
    animation-delay: 0.7s;
}

.live-stats-grid {
    animation-delay: 0.8s;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 40px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border);
}

.header-content h1 {
    font-size: 2.2rem;
    /* Creating impact */
    font-weight: 800;
    letter-spacing: -0.025em;
    margin-bottom: 4px;
    font-family: var(--font-heading);
    background: linear-gradient(135deg, var(--text), var(--primary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    color: transparent;
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.95rem;
}

.theme-toggle {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.theme-toggle:hover {
    background: var(--surface-secondary);
}

/* Top Grid (Main Stats) */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 32px;
}

.feature-card {
    background: var(--surface);
    backdrop-filter: var(--glass);
    -webkit-backdrop-filter: var(--glass);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.feature-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow);
}

.feature-card::after {
    border-color: var(--primary-light);
}

.card-top {
    display: flex;
    flex-direction: column;
    /* Stacked: Icon -> Title */
    align-items: flex-start;
    margin-bottom: 24px;
    gap: 12px;
}

.card-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    /* Square-ish */
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

/* Badge colors solid */
.card-icon.orange {
    background: #F97316;
    color: white;
}

.card-icon.green {
    background: #10B981;
    color: white;
}

.card-icon.blue {
    background: #06B6D4;
    color: white;
}

.card-icon.pink {
    background: #EC4899;
    color: white;
}

.stat-label {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
    text-transform: none;
    /* Sentence case title */
    letter-spacing: -0.01em;
    margin: 0;
    font-family: var(--font-heading);
}

.stat-context {
    font-size: 0.9rem;
    color: var(--text-muted);
    line-height: 1.4;
    margin-top: 4px;
    min-height: 2.8em;
    /* Ensure 2 lines alignment */
}

/* The "Content Widget" area */
.card-content {
    background: var(--surface);
    /* Inner card */
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.trend-badge {
    align-self: flex-start;
    margin-top: 8px;
    font-size: 0.75rem;
    padding: 2px 8px;
    background: var(--surface-secondary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-muted);
}

/* Progress Section */
.main-progress {
    background: var(--surface);
    backdrop-filter: var(--glass);
    -webkit-backdrop-filter: var(--glass);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: 24px;
    margin-bottom: 32px;
    box-shadow: var(--shadow-sm);
}

.progress-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 12px;
    font-weight: 600;
    font-size: 0.9rem;
}

.progress-track {
    background: rgba(0, 0, 0, 0.05);
    height: 24px;
    /* Thicker for tube effect */
    border-radius: 99px;
    overflow: hidden;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
    /* Inner depth */
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .progress-track {
    background: rgba(0, 0, 0, 0.2);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
}

.progress-fill {
    background: linear-gradient(90deg, var(--primary), var(--info));
    height: 100%;
    width: 0%;
    border-radius: 99px;
    transition: width 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    /* Bounce effect */
    position: relative;
    box-shadow: 0 0 20px var(--primary-light);
    animation: pulseGlow 3s infinite;
}

/* Glass shine on top half */
.progress-fill::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    right: 2px;
    height: 40%;
    background: linear-gradient(to bottom, rgba(255, 255, 255, 0.4), rgba(255, 255, 255, 0.1));
    border-radius: 99px;
}

/* Pulse animation for active state */
@keyframes pulseGlow {

    0%,
    100% {
        filter: brightness(1);
    }

    50% {
        filter: brightness(1.2);
    }
}

/* Game Area */
.game-layout {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 24px;
    margin-bottom: 40px;
}

.game-container {
    background: var(--surface);
    backdrop-filter: var(--glass);
    -webkit-backdrop-filter: var(--glass);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 16px;
    position: relative;
    min-height: 400px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-sm);
}

#gameCanvas {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--border);
}

.game-sidebar {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Actions Panel (Right Side) */
.actions-panel {
    background: var(--surface);
    backdrop-filter: var(--glass);
    -webkit-backdrop-filter: var(--glass);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 24px;
    box-shadow: var(--shadow-sm);
}

.panel-title {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text);
}

.donation-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 16px;
}

.btn-donate {
    background: var(--surface-secondary);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 12px;
    border-radius: 8px;
    /* Slightly softer than 6px */
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

.btn-donate:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
}

.btn-custom {
    grid-column: span 2;
    background: var(--primary);
    color: white;
    border: none;
}

.btn-custom:hover {
    background: var(--primary-hover);
    color: white;
}

.btn-auto {
    width: 100%;
    padding: 12px;
    background: var(--surface-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-auto:hover {
    color: var(--text);
    border-color: var(--text-muted);
}

.btn-auto.active {
    background: var(--success-light);
    color: var(--success);
    border-color: var(--success);
}

/* Bottom Stats (New Section) */
.live-stats-header {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 16px;
}

.live-stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
}

.stat-row-card {
    background: var(--surface);
    backdrop-filter: var(--glass);
    -webkit-backdrop-filter: var(--glass);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: var(--shadow-sm);
}

.row-icon-circle {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--surface-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
}

.stat-row-content h4 {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
}

.stat-row-content p {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
}

.stat-tag {
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 8px;
    background: var(--success-light);
    color: var(--success);
}

@media (max-width: 768px) {

    .cards-grid,
    .game-layout,
    .live-stats-grid {
        grid-template-columns: 1fr;
    }

    .game-sidebar {
        order: -1;
    }
}

/* RTL Support */
[dir="rtl"] {
    text-align: right;
}

[dir="rtl"] .stat-tag {
    margin-left: 0;
    margin-right: 8px;
}

[dir="rtl"] .progress-fill {
    /* Ensure it fills from the right if direction is rtl */
    transition: width 0.4s ease;
}