/* Shared CSS for all games */

:root {
    /* Telegram theme vars with fallbacks */
    --tg-theme-bg-color: var(--tg-theme-bg-color, #1a1a2e);
    --tg-theme-text-color: var(--tg-theme-text-color, #ffffff);
    --tg-theme-button-color: var(--tg-theme-button-color, #4a9eff);
    --tg-theme-button-text-color: var(--tg-theme-button-text-color, #ffffff);
    --tg-theme-secondary-bg-color: var(--tg-theme-secondary-bg-color, #2a2a4e);
    --tg-theme-hint-color: var(--tg-theme-hint-color, #8888aa);
    --tg-theme-link-color: var(--tg-theme-link-color, #4a9eff);

    /* Surface elevation */
    --surface-elevated: rgba(42, 42, 78, 0.9);
    --border-subtle: rgba(255, 255, 255, 0.08);

    /* Gaming accent colors */
    --accent-gold: #ffd700;
    --accent-purple: #a855f7;
    --accent-cyan: #22d3ee;
    --accent-pink: #f472b6;
    --accent-green: #4ade80;

    /* Glow colors - softer, more premium */
    --glow-gold: rgba(255, 215, 0, 0.35);
    --glow-blue: rgba(74, 158, 255, 0.35);
    --glow-purple: rgba(168, 85, 247, 0.35);

    /* Better contrast text */
    --text-muted: #a0a0c0;
    --text-dim: #6b6b8a;

    /* Shadow system */
    --shadow-1: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.08);
    --shadow-2: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.08), 0 4px 12px rgba(0, 0, 0, 0.15);
    --shadow-3: 0 1px 3px rgba(0, 0, 0, 0.12), 0 4px 12px rgba(0, 0, 0, 0.15), 0 12px 40px rgba(0, 0, 0, 0.2);

    /* Transitions */
    --ease-out: cubic-bezier(0.4, 0, 0.2, 1);
    --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);

    /* Typography */
    --font-display: 'Space Grotesk', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font-body);
    background: radial-gradient(
        ellipse 120% 100% at 50% 0%,
        rgba(42, 42, 78, 0.15) 0%,
        var(--tg-theme-bg-color) 50%
    );
    color: var(--tg-theme-text-color);
    padding: 16px;
    display: flex;
    flex-direction: column;
    line-height: 1.5;
    letter-spacing: 0.01em;
}

/* Tabular numbers for scores */
.score-display,
.money-display,
.leaderboard-score {
    font-feature-settings: 'tnum';
}

.container {
    max-width: 400px;
    margin: 0 auto;
    width: 100%;
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Tab Navigation */
.tab-nav {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
    background: transparent;
    padding: 0;
    flex-shrink: 0;
}

.tab-btn {
    flex: 1;
    min-height: 40px;
    padding: 8px 16px;
    border: 1px solid var(--border-subtle);
    border-radius: 20px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    background: var(--tg-theme-secondary-bg-color);
    color: var(--tg-theme-hint-color);
    transition: background 0.2s var(--ease-out), color 0.2s var(--ease-out), border-color 0.2s var(--ease-out), box-shadow 0.2s var(--ease-out);
}

.tab-btn.active {
    background: var(--tg-theme-button-color);
    color: var(--tg-theme-button-text-color);
    border-color: transparent;
    box-shadow: 0 0 10px var(--glow-blue);
}

.tab-btn:not(.active):hover {
    background: rgba(255, 255, 255, 0.08);
}

.tab-btn:not(.active):active {
    opacity: 0.7;
}

/* Tab Content */
.tab-content {
    display: none;
    flex: 1;
    overflow: hidden;
}

.tab-content.active {
    display: block;
    background: linear-gradient(
        180deg,
        transparent 0%,
        rgba(74, 158, 255, 0.03) 100%
    );
}

#gameTab.active {
    display: flex;
    flex-direction: column;
}

#friendsTab.active {
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Save Button */
.save-btn {
    background: none;
    border: none;
    padding: 6px;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.2s var(--ease-out);
    position: relative;
}

.save-btn:active {
    background: var(--tg-theme-secondary-bg-color);
}

.save-icon {
    display: block;
    width: 22px;
    height: 22px;
    color: var(--tg-theme-hint-color);
    transition: color 0.2s var(--ease-out), opacity 0.2s var(--ease-out);
}

.save-btn:hover .save-icon {
    color: var(--tg-theme-link-color);
}

.save-btn.saving .save-icon {
    opacity: 0.5;
}

.save-btn.saving::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 24px;
    height: 24px;
    margin: -12px 0 0 -12px;
    border: 2px solid transparent;
    border-top-color: var(--tg-theme-link-color);
    border-radius: 50%;
    animation: saveSpin 0.6s linear infinite;
}

@keyframes saveSpin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Buttons */
.btn {
    padding: 12px 16px;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s var(--ease-out), transform 0.2s var(--ease-bounce);
}

.btn:active {
    opacity: 0.8;
    transform: scale(0.98);
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.btn-primary {
    background-color: var(--tg-theme-button-color);
    color: var(--tg-theme-button-text-color);
    transition: opacity 0.2s var(--ease-out), transform 0.2s var(--ease-bounce), box-shadow 0.2s var(--ease-out);
}

.btn-primary:active {
    box-shadow: 0 0 20px var(--glow-blue);
}

.btn-small {
    padding: 8px 12px;
    font-size: 12px;
}

.btn-danger {
    background: #ff4444;
    color: white;
}

/* Leaderboard Toggle */
.leaderboard-toggle {
    display: flex;
    gap: 6px;
    background: transparent;
    padding: 0;
    margin-bottom: 12px;
}

.toggle-btn {
    flex: 1;
    min-height: 36px;
    padding: 6px 14px;
    border: 1px solid var(--border-subtle);
    border-radius: 18px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    background: var(--tg-theme-secondary-bg-color);
    color: var(--tg-theme-hint-color);
    transition: background 0.2s var(--ease-out), color 0.2s var(--ease-out), border-color 0.2s var(--ease-out), box-shadow 0.2s var(--ease-out);
}

.toggle-btn.active {
    background: var(--tg-theme-button-color);
    color: var(--tg-theme-button-text-color);
    border-color: transparent;
    box-shadow: 0 0 8px var(--glow-blue);
}

.toggle-btn:not(.active):hover {
    background: rgba(255, 255, 255, 0.08);
}

.toggle-btn:not(.active):active {
    opacity: 0.7;
}

/* Leaderboard Items */
.leaderboard-item {
    position: relative;
    overflow: hidden;
    margin-bottom: 8px;
    border-radius: 10px;
}

.leaderboard-item:last-child {
    margin-bottom: 0;
}

.leaderboard-item .item-content {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    background: var(--tg-theme-secondary-bg-color);
    border-radius: 10px;
    position: relative;
    z-index: 1;
    box-shadow: var(--shadow-1);
    border: 1px solid var(--border-subtle);
    transition: transform 0.2s var(--ease-out), box-shadow 0.2s var(--ease-out);
}

.leaderboard-item:hover .item-content {
    transform: translateY(-1px);
    box-shadow: var(--shadow-2);
}

.leaderboard-item.current-user .item-content {
    background: rgba(74, 158, 255, 0.12);
    border-color: rgba(74, 158, 255, 0.25);
    box-shadow: var(--shadow-1), 0 0 12px var(--glow-blue);
}

/* Top 3 - softer gradient border */
.leaderboard-item.rank-1 .item-content {
    border-color: rgba(255, 215, 0, 0.4);
    box-shadow: var(--shadow-1), 0 0 12px var(--glow-gold);
}

.leaderboard-item.rank-2 .item-content {
    border-color: rgba(192, 192, 192, 0.4);
    box-shadow: var(--shadow-1), 0 0 12px rgba(192, 192, 192, 0.35);
}

.leaderboard-item.rank-3 .item-content {
    border-color: rgba(205, 127, 50, 0.4);
    box-shadow: var(--shadow-1), 0 0 12px rgba(205, 127, 50, 0.35);
}

.leaderboard-rank {
    width: 36px;
    font-weight: bold;
    font-size: 14px;
    opacity: 0.7;
}

.leaderboard-name {
    flex: 1;
    font-size: 15px;
    font-weight: 500;
}

.leaderboard-score {
    font-weight: bold;
    font-size: 15px;
    color: var(--tg-theme-button-color);
}

/* Swipe to delete */
.swipe-action {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 80px;
    background: #ff4444;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0 10px 10px 0;
}

.btn-remove {
    background: none;
    border: none;
    color: white;
    font-weight: 600;
    font-size: 13px;
    padding: 8px 12px;
    cursor: pointer;
}

.swipeable .item-content {
    transition: transform 0.2s var(--ease-out);
}

/* Friends List */
.friends-list {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    flex: 1;
}

/* Empty and Loading States */
.loading, .empty-message {
    padding: 20px;
    text-align: center;
    opacity: 0.6;
    font-size: 14px;
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.empty-state p {
    margin-bottom: 8px;
}

.empty-state .hint {
    font-size: 14px;
    color: var(--text-dim);
}

/* Floating Action Button */
.fab {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--tg-theme-button-color);
    color: var(--tg-theme-button-text-color);
    border: none;
    font-size: 28px;
    font-weight: 300;
    cursor: pointer;
    box-shadow: var(--shadow-3), 0 0 16px var(--glow-blue);
    transition: transform 0.2s var(--ease-bounce), box-shadow 0.2s var(--ease-out);
    z-index: 10;
}

.fab:hover {
    box-shadow: var(--shadow-3), 0 0 20px var(--glow-blue);
}

.fab:active {
    transform: scale(0.95);
    box-shadow: var(--shadow-2);
}

/* Game Switcher Tab */
.game-switch-tab {
    position: fixed;
    bottom: 20px;
    left: 0;
    min-width: 44px;
    height: 48px;
    padding: 0 10px;
    background: var(--tg-theme-button-color);
    color: var(--tg-theme-button-text-color);
    border: none;
    border-radius: 0 8px 8px 0;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    z-index: 99;
    opacity: 0.9;
    box-shadow: var(--shadow-2);
    transition: opacity 0.2s var(--ease-out), transform 0.2s var(--ease-out);
}

.game-switch-tab:hover {
    opacity: 1;
}

.game-switch-tab:active {
    opacity: 1;
    transform: scale(0.98);
}

/* Game Switcher Overlay */
.game-switch-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s var(--ease-out), visibility 0.3s var(--ease-out);
    z-index: 100;
}

.game-switch-overlay.visible {
    opacity: 1;
    visibility: visible;
}

/* Game Switcher Drawer */
.game-switch-drawer {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 200px;
    background: var(--tg-theme-bg-color);
    transform: translateX(-100%) scale(0.98);
    transform-origin: left center;
    transition: transform 0.3s var(--ease-out);
    z-index: 101;
    padding: 20px;
    box-shadow: var(--shadow-3);
    border-right: 1px solid var(--border-subtle);
}

.game-switch-drawer.visible {
    transform: translateX(0) scale(1);
}

.game-switch-drawer .drawer-header {
    margin-bottom: 20px;
}

.game-switch-drawer .drawer-header h3 {
    font-size: 18px;
    font-weight: 600;
    font-family: var(--font-display);
}

.drawer-games {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.game-link {
    display: block;
    padding: 12px 16px;
    background: var(--tg-theme-secondary-bg-color);
    border-radius: 8px;
    color: var(--tg-theme-text-color);
    text-decoration: none;
    font-weight: 500;
    border: 1px solid var(--border-subtle);
    transition: transform 0.2s var(--ease-out), background 0.2s var(--ease-out), box-shadow 0.2s var(--ease-out);
}

.game-link:hover {
    transform: translateX(4px);
    background: rgba(255, 255, 255, 0.08);
}

.game-link:active {
    opacity: 0.8;
}

.game-link.current {
    background: var(--tg-theme-button-color);
    color: var(--tg-theme-button-text-color);
    border-color: transparent;
    box-shadow: 0 0 12px var(--glow-blue);
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
