/* Component Styles */
/* This file contains existing component styles from index.html */
/* Imported after layout.css to maintain specificity */

/* Import the legacy styles here for now */
/* TODO: Refactor components to use design tokens */

/* ============================================
   TopBar Component (Integrated GameInfoPanel)
   ============================================ */

/* Hide old GameInfoPanel completely */
.game-info-panel {
    display: none !important;
}

#topbar {
    position: fixed !important;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-h);
    background: linear-gradient(180deg, rgba(10, 10, 20, 0.85) 0%, rgba(5, 5, 15, 0.8) 100%);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 2px solid;
    border-image: linear-gradient(90deg, transparent, rgba(100, 100, 255, 0.3), transparent) 1;
    z-index: var(--z-topbar) !important;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    gap: 16px;
    overflow: visible;
    /* Ensure child elements are not clipped */

    /* Safe area for iOS notch */
    padding-top: env(safe-area-inset-top);
}

@media (max-width: 768px) {
    #topbar {
        height: var(--topbar-h-mobile);
        padding: 0 8px;
        gap: 8px;
    }
}

.top-bar-section {
    display: flex;
    align-items: center;
    gap: 12px;
}

.top-bar-section--left {
    flex: 0 0 auto;
    gap: 16px;
}

.top-bar-section--right {
    flex-shrink: 0;
    /* Never shrink */
    justify-content: flex-end;
    gap: 12px;
    margin-left: auto;
    /* Force to right */
    overflow: visible;
    /* Ensure buttons are not clipped */
}

/* Debug Info Bar (Web Components) */
debug-info-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

debug-button {
    display: inline-block;
}

debug-stats-panel {
    display: block;
}

.top-bar-menu-btn {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.top-bar-menu-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.4);
}

.top-bar-menu-btn:active {
    transform: scale(0.95);
}

.top-bar-title {
    font-size: 16px;
    font-weight: bold;
    color: #FFD700;
    text-shadow: 0 0 8px rgba(255, 215, 0, 0.3);
    white-space: nowrap;
    flex-shrink: 0;
}

/* Exit Instance button */
.top-bar-exit-instance-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    margin-left: 12px;
    background: linear-gradient(135deg, rgba(255, 87, 87, 0.2) 0%, rgba(255, 107, 107, 0.2) 100%);
    border: 1px solid rgba(255, 87, 87, 0.4);
    border-radius: 8px;
    color: #ff6b6b;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.top-bar-exit-instance-btn:hover {
    background: linear-gradient(135deg, rgba(255, 87, 87, 0.3) 0%, rgba(255, 107, 107, 0.3) 100%);
    border-color: rgba(255, 87, 87, 0.6);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(255, 87, 87, 0.3);
}

.top-bar-exit-instance-btn:active {
    transform: scale(0.98);
}

.top-bar-exit-instance-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.exit-instance-icon {
    font-size: 16px;
    line-height: 1;
}

.exit-instance-text {
    line-height: 1;
}

/* Version badge */
.top-bar-version {
    font-size: 9px;
    color: rgba(255, 255, 255, 0.3);
    font-weight: 400;
    font-family: 'Courier New', monospace;
    padding: 2px 6px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    letter-spacing: 0.3px;
    transition: all 0.2s ease;
}

.top-bar-version:hover {
    color: rgba(255, 255, 255, 0.7);
    background: rgba(0, 0, 0, 0.4);
}

/* Tick counter */
.top-bar-tick {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.5);
    font-weight: 400;
    letter-spacing: 0.5px;
}

/* Connection status dot */
.top-bar-connection-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    position: relative;
    cursor: pointer;
    transition: all 0.3s ease;
    will-change: transform;
    /* Optimize animation performance */
    padding: 8px;
    /* Increase hitbox */
    margin: -8px;
    /* Compensate padding */
}

.top-bar-connection-dot:focus {
    outline: 2px solid rgba(255, 255, 255, 0.5);
    outline-offset: 2px;
}

.top-bar-connection-dot--connected {
    background: #4CAF50;
    box-shadow: 0 0 8px rgba(76, 175, 80, 0.6);
    animation: pulse-connection 2s ease-in-out infinite;
}

.top-bar-connection-dot:hover {
    animation: none;
    /* Stop animation on hover for stable clicking */
}

.top-bar-connection-dot--disconnected {
    background: #F44336;
    box-shadow: 0 0 6px rgba(244, 67, 54, 0.4);
}

.top-bar-connection-dot--reconnecting {
    background: #FFC107;
    box-shadow: 0 0 6px rgba(255, 193, 7, 0.4);
}

@keyframes pulse-connection {

    0%,
    100% {
        transform: scale(1);
        box-shadow: 0 0 8px rgba(76, 175, 80, 0.6);
    }

    50% {
        transform: scale(1.1);
        /* Reduced scale for more stable element */
        box-shadow: 0 0 12px rgba(76, 175, 80, 0.9);
    }
}

/* Tooltip */
.top-bar-tooltip {
    position: absolute;
    bottom: -32px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    color: #fff;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 11px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
    z-index: 10;
}

.top-bar-connection-dot:hover .top-bar-tooltip,
.top-bar-tooltip--show {
    opacity: 1;
}

/* Avatar */
.top-bar-avatar {
    font-size: 20px;
    line-height: 1;
}

/* Mana container (compact with progress bar) */
.top-bar-mana-container {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 80px;
}

.top-bar-mana-text {
    font-size: 10px;
    font-weight: 600;
    color: #87CEEB;
    letter-spacing: 0.3px;
}

.top-bar-mana-bar-bg {
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    overflow: hidden;
}

.top-bar-mana-bar {
    height: 100%;
    background: linear-gradient(90deg, #4CAF50, #81C784);
    transition: width 0.25s ease;
    border-radius: 2px;
}

/* Gold display */
.top-bar-gold {
    font-size: 13px;
    font-weight: 600;
    color: #FFD700;
    letter-spacing: 0.3px;
}

/* Login button */
.top-bar-login-btn {
    position: relative;
    background: rgba(100, 100, 150, 0.2);
    border: 1px solid rgba(150, 150, 200, 0.3);
    border-radius: 6px;
    color: #FFF;
    font-size: 18px;
    padding: 6px 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.top-bar-login-btn:hover {
    background: rgba(100, 100, 150, 0.4);
    border-color: rgba(150, 150, 200, 0.6);
    transform: translateY(-1px);
}

.top-bar-login-btn:focus {
    outline: 2px solid rgba(255, 255, 255, 0.5);
    outline-offset: 2px;
}

.top-bar-login-btn--logged-in {
    background: rgba(76, 175, 80, 0.2);
    border-color: rgba(76, 175, 80, 0.5);
}

.top-bar-login-btn--logged-in:hover {
    background: rgba(76, 175, 80, 0.3);
    border-color: rgba(76, 175, 80, 0.7);
}

/* Settings button */
.top-bar-settings-btn {
    position: relative;
    background: rgba(100, 100, 150, 0.2);
    border: 1px solid rgba(150, 150, 200, 0.3);
    border-radius: 6px;
    color: #FFF;
    font-size: 18px;
    padding: 6px 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    /* Prevent button from shrinking */
}

.top-bar-settings-btn:hover {
    background: rgba(100, 100, 150, 0.4);
    border-color: rgba(150, 150, 200, 0.6);
    transform: translateY(-1px);
}

.top-bar-settings-btn:focus {
    outline: 2px solid rgba(255, 255, 255, 0.5);
    outline-offset: 2px;
}

.settings-hamburger {
    display: none;
}

/* Mobile adjustments (< 768px) */
@media (max-width: 767px) {
    .top-bar {
        height: 48px;
        padding: 0 8px;
        gap: 8px;
    }

    .top-bar-section--left {
        gap: 0;
    }

    .top-bar-section--right {
        gap: 8px;
    }

    .top-bar-menu-btn {
        width: 36px;
        height: 36px;
        font-size: 18px;
    }

    .top-bar-title {
        font-size: 14px;
    }

    .top-bar-version {
        font-size: 8px;
        padding: 1px 4px;
    }

    /* Hide tick, version and connection on mobile */
    .top-bar-tick,
    .top-bar-version,
    .top-bar-connection-dot {
        display: none;
    }

    .top-bar-avatar {
        font-size: 18px;
    }

    .top-bar-mana-container {
        min-width: 60px;
    }

    .top-bar-mana-text {
        font-size: 9px;
    }

    .top-bar-mana-bar-bg {
        height: 3px;
    }

    .top-bar-gold {
        font-size: 11px;
    }

    .top-bar-login-btn {
        padding: 6px;
        font-size: 18px;
    }

    .top-bar-settings-btn {
        padding: 6px;
        font-size: 18px;
    }

    /* Show settings icon (gear) on mobile, not hamburger */
    .settings-icon {
        display: inline;
    }

    .settings-hamburger {
        display: none;
    }
}

/* Desktop fine-tuning (≥ 1024px) */
@media (min-width: 1024px) {
    .top-bar {
        padding: 0 32px;
    }

    /* Hide menu button on desktop */
    .top-bar-menu-btn {
        display: none;
    }

    .top-bar-title {
        font-size: 18px;
    }

    .top-bar-mana-container {
        min-width: 100px;
    }
}

/* ============================================
   Layout Adjustments for TopBar
   ============================================ */

/* Hide EntitiesSidebar on mobile - use BasesListScreen/HeroesListScreen instead */
@media (max-width: 767px) {
    .entities-sidebar {
        display: none !important;
    }
}

/* ============================================
   PlayerToolbar Component (Bottom Toolbar)
   ============================================ */

.player-toolbar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: linear-gradient(180deg, rgba(26, 22, 37, 0.95) 0%, rgba(20, 20, 30, 0.98) 100%);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid rgba(100, 100, 150, 0.3);
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.5);
    z-index: 940;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    gap: 16px;
}

.player-toolbar-section {
    display: flex;
    align-items: center;
    gap: 16px;
}

.player-toolbar-section--info {
    flex: 1;
}

.player-toolbar-section--actions {
    flex-shrink: 0;
}

.player-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.player-icon {
    font-size: 28px;
}

.player-name-display,
.player-name-input {
    font-size: 14px;
    font-weight: 600;
    color: #fff;
}

.player-name-input {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 4px;
    padding: 4px 8px;
    color: #fff;
}

.player-name-edit,
.player-name-save,
.player-name-cancel {
    background: transparent;
    border: none;
    color: #fff;
    cursor: pointer;
    font-size: 14px;
    padding: 4px;
    opacity: 0.7;
    transition: opacity 0.2s ease;
}

.player-name-edit:hover,
.player-name-save:hover,
.player-name-cancel:hover {
    opacity: 1;
}

.player-stats {
    display: flex;
    align-items: center;
    gap: 16px;
}

.player-mana {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: rgba(124, 92, 219, 0.2);
    border: 1px solid rgba(124, 92, 219, 0.4);
    border-radius: 8px;
}

.player-mana-icon {
    font-size: 16px;
}

.player-mana-text {
    font-size: 13px;
    font-weight: 600;
    color: #87CEEB;
}

.player-gold {
    display: flex;
    align-items: center;
    padding: 6px 12px;
    background: rgba(255, 215, 0, 0.15);
    border: 1px solid rgba(255, 215, 0, 0.3);
    border-radius: 8px;
    position: relative;
    overflow: visible;
}

.player-gold-text {
    font-size: 13px;
    font-weight: 600;
    color: #FFD700;
}

/* Gold change animation particles */
.gold-particle {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 14px;
    font-weight: 700;
    pointer-events: none;
    white-space: nowrap;
    z-index: 100;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
    animation: goldParticleFly 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
    animation-delay: var(--particle-delay, 0ms);
}

.gold-particle--gain {
    color: #4ade80;
}

.gold-particle--loss {
    color: #f87171;
}

@keyframes goldParticleFly {
    0% {
        opacity: 1;
        transform: translate(calc(-50% + var(--particle-x, 0px)), -50%) scale(1);
    }

    30% {
        opacity: 1;
        transform: translate(calc(-50% + var(--particle-x, 0px)), -120%) scale(1.2);
    }

    100% {
        opacity: 0;
        transform: translate(calc(-50% + var(--particle-x, 0px)), -200%) scale(0.8);
    }
}

/* Respect prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
    .gold-particle {
        animation: goldParticleFade 0.4s ease-out forwards;
    }

    @keyframes goldParticleFade {
        0% {
            opacity: 1;
        }

        100% {
            opacity: 0;
        }
    }
}

.player-toolbar-button {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 16px;
    background: rgba(124, 92, 219, 0.2);
    border: 1px solid rgba(124, 92, 219, 0.4);
    border-radius: 8px;
    color: #fff;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 80px;
}

.player-toolbar-button:hover {
    background: rgba(124, 92, 219, 0.4);
    border-color: rgba(124, 92, 219, 0.6);
    transform: translateY(-2px);
}

.player-toolbar-button:active {
    transform: translateY(0);
}

.button-icon {
    font-size: 24px;
}

.button-cost {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.8);
}

/* Hide on mobile (< 768px) - bottom nav is used instead */
@media (max-width: 767px) {
    .player-toolbar {
        display: none !important;
    }
}

/* Desktop adjustments */
@media (min-width: 1024px) {
    .player-toolbar {
        left: 280px;
        /* Account for entities sidebar */
        padding: 0 32px;
    }
}

/* Hero Behavior Status */
.hero-behavior-status {
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    margin: 8px 0;
}

.hero-behavior-status--predefined {
    background: rgba(100, 200, 255, 0.15);
    color: #6cf;
    border: 1px solid rgba(100, 200, 255, 0.3);
}

.hero-behavior-status--active {
    background: rgba(100, 255, 150, 0.15);
    color: #6f6;
    border: 1px solid rgba(100, 255, 150, 0.3);
}

.hero-behavior-status--error {
    background: rgba(255, 100, 100, 0.15);
    color: #f66;
    border: 1px solid rgba(255, 100, 100, 0.3);
}

.hero-behavior-status--processing {
    background: rgba(255, 200, 100, 0.15);
    color: #fc6;
    border: 1px solid rgba(255, 200, 100, 0.3);
    animation: pulse 2s ease-in-out infinite;
}

.hero-behavior-status--outdated {
    background: rgba(200, 150, 100, 0.15);
    color: #c96;
    border: 1px solid rgba(200, 150, 100, 0.3);
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.7;
    }
}

/* ============================================
   Instance Selector Modal
   ============================================ */

.instance-selector-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modals);
    animation: fadeIn var(--duration-normal) var(--easing-standard);
}

.instance-selector-content {
    background: var(--gradient-panel);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    border: 1px solid rgba(124, 92, 219, 0.3);
    padding: var(--space-6);
    min-width: 320px;
    max-width: 480px;
    width: 90%;
    animation: slideUp var(--duration-normal) var(--easing-decelerate);
}

.instance-selector-content h2 {
    margin: 0 0 var(--space-4) 0;
    color: var(--text-primary);
    font-size: var(--text-xl);
    font-weight: var(--font-weight-bold);
    text-align: center;
}

.instance-selector-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
    max-height: 400px;
    overflow-y: auto;
}

.instance-selector-button {
    background: var(--gradient-card);
    border: 1px solid rgba(124, 92, 219, 0.3);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    cursor: pointer;
    transition: all var(--duration-fast) var(--easing-standard);
    text-align: left;
}

.instance-selector-button:hover {
    background: var(--bg-hover);
    border-color: var(--ui-primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.instance-selector-name {
    color: var(--text-primary);
    font-size: var(--text-base);
    font-weight: var(--font-weight-medium);
    margin-bottom: var(--space-1);
}

.instance-selector-info {
    color: var(--text-secondary);
    font-size: var(--text-sm);
}

.instance-selector-close {
    width: 100%;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: var(--radius-md);
    padding: var(--space-3);
    color: var(--text-primary);
    font-size: var(--text-base);
    cursor: pointer;
    transition: all var(--duration-fast) var(--easing-standard);
}

.instance-selector-close:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.3);
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

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

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