/* ===================================================
   Phase 9: UI/UX Enhancements
   =================================================== */

/* === PARTICLE SYSTEM === */
.particles-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: hidden;
    z-index: 0;
}

.particle {
    position: absolute;
    width: 4px;
    height: 4px;
    background: rgba(255, 215, 76, 0.6);
    border-radius: 50%;
    opacity: 0;
    will-change: transform, opacity;
    animation: particle-float 8s infinite linear;
    /* box-shadow: 0 0 6px var(--gold-base); REMOVED FOR PERFORMANCE */
}

@keyframes particle-float {
    0% {
        opacity: 0;
        transform: translateY(100vh) scale(0);
    }

    10% {
        opacity: 0.8;
    }

    90% {
        opacity: 0.8;
    }

    100% {
        opacity: 0;
        transform: translateY(-20vh) scale(1);
    }
}

/* Stagger particle animations */
.particle:nth-child(1) {
    left: 10%;
    animation-delay: 0s;
}

.particle:nth-child(2) {
    left: 20%;
    animation-delay: 1s;
}

.particle:nth-child(3) {
    left: 30%;
    animation-delay: 2s;
}

.particle:nth-child(4) {
    left: 40%;
    animation-delay: 3s;
}

.particle:nth-child(5) {
    left: 50%;
    animation-delay: 4s;
}

.particle:nth-child(6) {
    left: 60%;
    animation-delay: 5s;
}

.particle:nth-child(7) {
    left: 70%;
    animation-delay: 6s;
}

.particle:nth-child(8) {
    left: 80%;
    animation-delay: 7s;
}

.particle:nth-child(9) {
    left: 90%;
    animation-delay: 0.5s;
}

.particle:nth-child(10) {
    left: 15%;
    animation-delay: 2.5s;
}

.particle:nth-child(11) {
    left: 25%;
    animation-delay: 3.5s;
}

.particle:nth-child(12) {
    left: 35%;
    animation-delay: 4.5s;
}

.particle:nth-child(13) {
    left: 45%;
    animation-delay: 5.5s;
}

.particle:nth-child(14) {
    left: 55%;
    animation-delay: 6.5s;
}

.particle:nth-child(15) {
    left: 65%;
    animation-delay: 7.5s;
}

/* === TITLE ANIMATIONS === */
.screen h1 {
    animation: title-entrance 1.5s ease-out, titlePulse 2s infinite 1.5s;
}

@keyframes title-entrance {
    0% {
        opacity: 0;
        transform: scale(0.5) translateY(-50px);
        filter: blur(10px);
    }

    60% {
        opacity: 1;
        transform: scale(1.1) translateY(0);
        filter: blur(0);
    }

    100% {
        transform: scale(1);
    }
}

.screen h2 {
    animation: subtitle-entrance 1s ease-out 0.5s both;
}

@keyframes subtitle-entrance {
    0% {
        opacity: 0;
        letter-spacing: 30px;
    }

    100% {
        opacity: 1;
        letter-spacing: 15px;
    }
}

/* === BUTTON ENHANCEMENTS === */
.btn-menu {
    position: relative;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-menu::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.btn-menu:hover::before {
    width: 300px;
    height: 300px;
}

.btn-menu:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: var(--gold-glow), 0 10px 30px rgba(0, 0, 0, 0.4);
}

.btn-menu:active {
    transform: translateY(0) scale(0.98);
}

/* TV Mode Button Pulse */
.btn-tv {
    animation: tv-pulse 2s infinite;
}

@keyframes tv-pulse {

    0%,
    100% {
        box-shadow: 0 4px 15px rgba(52, 152, 219, 0.3);
    }

    50% {
        box-shadow: 0 4px 25px rgba(52, 152, 219, 0.6), 0 0 40px rgba(52, 152, 219, 0.3);
    }
}

/* === DIFFICULTY TOOLTIPS === */
.btn-menu[data-difficulty] {
    position: relative;
}

.btn-menu[data-difficulty]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: -30px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    color: var(--text-muted);
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.7rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.btn-menu[data-difficulty]:hover::after {
    opacity: 1;
}

/* === ANIMATED NUMBERS === */
.animated-number {
    display: inline-block;
    transition: transform 0.3s, color 0.3s;
}

.animated-number.pulse-up {
    animation: number-pulse-up 0.5s ease-out;
    color: #2ecc71;
}

.animated-number.pulse-down {
    animation: number-pulse-down 0.5s ease-out;
    color: var(--danger-base);
}

@keyframes number-pulse-up {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.3);
    }

    100% {
        transform: scale(1);
    }
}

@keyframes number-pulse-down {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(0.8);
    }

    100% {
        transform: scale(1);
    }
}

/* === RESOURCE CHANGE INDICATOR === */
.resource-change {
    position: absolute;
    font-size: 0.8rem;
    font-weight: bold;
    animation: float-up 1s ease-out forwards;
    pointer-events: none;
}

.resource-change.positive {
    color: #2ecc71;
}

.resource-change.negative {
    color: var(--danger-base);
}

@keyframes float-up {
    0% {
        opacity: 1;
        transform: translateY(0);
    }

    100% {
        opacity: 0;
        transform: translateY(-30px);
    }
}

/* === LOW RESOURCE WARNING === */
.stat-box.warning {
    animation: warning-pulse 1s infinite;
    border-color: var(--danger-base);
}

@keyframes warning-pulse {

    0%,
    100% {
        box-shadow: 0 0 10px rgba(255, 107, 107, 0.3);
    }

    50% {
        box-shadow: 0 0 20px rgba(255, 107, 107, 0.6);
    }
}

/* === SPAWN COOLDOWN INDICATOR === */
.cooldown-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: inherit;
    font-size: 1.5rem;
    font-weight: bold;
    color: white;
}

/* === KEYBOARD SHORTCUT LABELS === */
.shortcut-label {
    position: absolute;
    top: -8px;
    left: -8px;
    width: 20px;
    height: 20px;
    background: var(--accent-gradient);
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

/* === EVOLVE BUTTON XP BAR === */
.btn-evolve {
    position: relative;
    overflow: hidden;
}

.btn-evolve .xp-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 4px;
    background: var(--gold-gradient);
    transition: width 0.3s;
}

.btn-evolve.ready {
    animation: ready-glow 1s infinite;
}

@keyframes ready-glow {

    0%,
    100% {
        box-shadow: 0 0 10px rgba(0, 212, 255, 0.5);
    }

    50% {
        box-shadow: 0 0 25px rgba(0, 212, 255, 0.8), 0 0 50px rgba(0, 212, 255, 0.4);
    }
}

/* === SCREEN SHAKE === */
.screen-shake {
    animation: shake 0.5s cubic-bezier(.36, .07, .19, .97) both;
}

@keyframes shake {

    10%,
    90% {
        transform: translate3d(-1px, 0, 0);
    }

    20%,
    80% {
        transform: translate3d(2px, 0, 0);
    }

    30%,
    50%,
    70% {
        transform: translate3d(-4px, 0, 0);
    }

    40%,
    60% {
        transform: translate3d(4px, 0, 0);
    }
}

/* === FACTION CARD IMPROVEMENTS === */
.faction-card {
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    transform-style: preserve-3d;
}

.faction-card:hover {
    transform: translateY(-10px) rotateY(10deg);
}

.faction-card.active {
    animation: card-select 0.5s ease-out;
}

@keyframes card-select {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.2) rotateY(180deg);
    }

    100% {
        transform: scale(1.1) rotateY(0deg);
    }
}

/* === SPAWN CONFIRMATION === */
.spawn-flash {
    animation: spawn-confirm 0.3s ease-out;
}

@keyframes spawn-confirm {
    0% {
        background: rgba(46, 204, 113, 0.5);
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }

    100% {
        background: transparent;
        transform: scale(1);
    }
}

/* === FOCUS VISIBLE (Accessibility) === */
.btn-menu:focus-visible,
.btn-action:focus-visible,
.faction-card:focus-visible,
.unit-btn:focus-visible,
.build-btn:focus-visible {
    outline: 3px solid var(--accent-base);
    outline-offset: 2px;
}

/* === TOOLTIP SYSTEM === */
.tooltip {
    position: absolute;
    background: rgba(0, 0, 0, 0.95);
    border: 1px solid var(--panel-border);
    border-radius: var(--border-radius);
    padding: 12px;
    z-index: 1000;
    pointer-events: none;
    animation: tooltip-in 0.2s ease-out;
    max-width: 250px;
}

.tooltip::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    border: 8px solid transparent;
    border-top-color: rgba(0, 0, 0, 0.95);
}

@keyframes tooltip-in {
    0% {
        opacity: 0;
        transform: translateY(5px);
    }

    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

.tooltip h4 {
    color: var(--gold-base);
    margin-bottom: 8px;
    font-size: 1rem;
}

.tooltip .stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.tooltip .stats span {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ===================================================
   ACCESSIBILITY ENHANCEMENTS
   =================================================== */

/* Reduced Motion Support (WCAG 2.1) */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    .particle,
    .btn-tv,
    .screen-shake,
    .faction-card:hover {
        animation: none !important;
        transform: none !important;
    }

    /* Keep essential state changes */
    .btn-menu:hover,
    .btn-action:hover {
        transform: none;
    }
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    :root {
        --panel-bg: rgba(0, 0, 0, 0.95);
        --panel-border: #ffffff;
        --text-base: #ffffff;
        --text-muted: #cccccc;
        --gold-base: #ffd700;
    }

    .btn-menu,
    .btn-action,
    .faction-card,
    .unit-btn,
    .build-btn {
        border: 2px solid #fff !important;
    }

    .stat-box {
        border: 2px solid var(--gold-base) !important;
    }
}

/* Skip Link for Keyboard Navigation */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--accent-base);
    color: white;
    padding: 8px 16px;
    z-index: 10000;
    text-decoration: none;
    font-weight: bold;
    border-radius: 0 0 8px 0;
    transition: top 0.3s;
}

.skip-link:focus {
    top: 0;
}

/* Enhanced Focus Indicators */
*:focus-visible {
    outline: 3px solid var(--accent-base);
    outline-offset: 2px;
}

/* Screen Reader Only Text */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Visual state for disabled buttons */
.btn-menu:disabled,
.btn-action:disabled,
.unit-btn:disabled,
.build-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    filter: grayscale(50%);
}

/* Minimum touch target size (48px) */
@media (pointer: coarse) {

    .btn-action,
    .unit-btn,
    .build-btn,
    .btn-menu {
        min-height: 48px;
        min-width: 48px;
    }
}