/**
 * PyBLOCK Pool - Smooth Transitions & Anti-Flicker System
 * Eliminates visual "flashing" when data updates
 */

/* ==========================================
   GLOBAL SMOOTH TRANSITIONS
   ========================================== */

/* Prevent flash of unstyled content */
html {
    background-color: #000;
}

body {
    opacity: 1;
    /* Disabled fade-in to prevent black screen issues */
    /* animation: fadeIn 0.4s ease-out 0.1s forwards; */
}

@keyframes fadeIn {
    to {
        opacity: 1;
    }
}

/* Prevent content shift during loading */
.stat-value,
.card-stat-value {
    min-width: 60px;
    display: inline-block;
    text-align: center;
}

/* Prevent number width changes */
.stat-value,
.card-stat-value,
[id$="-hashrate"],
[id$="-workers"],
[id$="-blocks"] {
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.05em;
}

/* ==========================================
   ELEMENT UPDATE TRANSITIONS
   ========================================== */

/* All stat values get smooth transitions */
.stat-value,
.card-stat-value,
.stat-box span:first-child,
[id$="-hashrate"],
[id$="-workers"],
[id$="-blocks"],
[id$="-share"],
[id$="-accepted"],
[id$="-rejected"],
#btc-price,
#btc-change {
    transition: color 0.3s ease, opacity 0.3s ease, transform 0.2s ease;
}

/* Smooth fade when updating */
.updating {
    opacity: 0.6;
    transition: opacity 0.15s ease-out;
}

.updated {
    opacity: 1;
    transition: opacity 0.3s ease-in;
}

/* Pulse effect for number changes */
.number-update {
    animation: numberPulse 0.5s ease-out;
}

@keyframes numberPulse {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.05);
        opacity: 0.9;
        color: var(--color-accent);
        text-shadow: 0 0 20px currentColor;
    }
}

/* Highlight new values briefly */
.value-changed {
    animation: valueHighlight 0.8s ease-out;
}

@keyframes valueHighlight {
    0% {
        background: rgba(0, 255, 65, 0.3);
        box-shadow: 0 0 20px rgba(0, 255, 65, 0.5);
    }
    100% {
        background: transparent;
        box-shadow: none;
    }
}

/* ==========================================
   TABLE & LIST SMOOTH UPDATES
   ========================================== */

/* Smooth table row updates */
tbody tr {
    transition: opacity 0.3s ease, background-color 0.3s ease;
}

tbody tr.row-updating {
    opacity: 0.7;
}

tbody tr.row-new {
    animation: rowSlideIn 0.5s ease-out;
}

@keyframes rowSlideIn {
    from {
        opacity: 0;
        transform: translateX(-20px);
        background: rgba(0, 255, 65, 0.2);
    }
    to {
        opacity: 1;
        transform: translateX(0);
        background: transparent;
    }
}

/* ==========================================
   CHART SMOOTH UPDATES
   ========================================== */

canvas {
    transition: opacity 0.3s ease;
}

canvas.chart-updating {
    opacity: 0.8;
}

/* ==========================================
   LOADING STATES (Non-intrusive)
   ========================================== */

/* Subtle loading indicator instead of text change */
.loading-indicator {
    position: relative;
}

.loading-indicator::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg,
        transparent 0%,
        var(--color-primary) 50%,
        transparent 100%
    );
    animation: loadingBar 1.5s ease-in-out infinite;
    opacity: 0.6;
}

@keyframes loadingBar {
    0% {
        transform: translateX(-100%);
    }
    100% {
        transform: translateX(100%);
    }
}

/* ==========================================
   PREVENT LAYOUT SHIFT
   ========================================== */

/* Reserve space for dynamic content */
.stat-value:empty::before {
    content: '--';
    opacity: 0.3;
}

/* Minimum heights to prevent jumping */
.stats-grid {
    min-height: 150px;
}

.card-grid {
    min-height: 300px;
}

/* ==========================================
   SMOOTH CARD UPDATES
   ========================================== */

.card {
    transition: transform 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
}

.card.card-updating {
    opacity: 0.95;
}

/* ==========================================
   TEXT CONTENT TRANSITIONS
   ========================================== */

/* Smooth text changes */
.smooth-text {
    display: inline-block;
    transition: all 0.3s ease;
}

.smooth-text.text-changing {
    opacity: 0;
    transform: translateY(-5px);
}

.smooth-text.text-changed {
    opacity: 1;
    transform: translateY(0);
}

/* ==========================================
   SKELETON LOADING (Optional)
   ========================================== */

.skeleton {
    background: linear-gradient(
        90deg,
        rgba(0, 255, 65, 0.05) 0%,
        rgba(0, 255, 65, 0.15) 50%,
        rgba(0, 255, 65, 0.05) 100%
    );
    background-size: 200% 100%;
    animation: skeletonPulse 2s ease-in-out infinite;
    border-radius: 4px;
}

@keyframes skeletonPulse {
    0%, 100% {
        background-position: 0% 0%;
    }
    50% {
        background-position: 100% 0%;
    }
}

/* ==========================================
   DISABLE TRANSITIONS DURING LOAD
   ========================================== */

/* Prevent transitions on initial page load */
.preload * {
    transition: none !important;
    animation: none !important;
}

/* ==========================================
   PERFORMANCE OPTIMIZATIONS
   ========================================== */

/* Use GPU acceleration for animations */
.stat-value,
.card,
.number-update,
.value-changed {
    will-change: transform, opacity;
}

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

    .number-update,
    .value-changed,
    .updating,
    .updated {
        animation: none !important;
        transition: none !important;
    }
}

/* Manual "Reduce motion" toggle (header button). Mirrors the prefers-reduced-motion
   rules above but keyed on a class on <html>, so motion-sensitive visitors get relief
   even when they haven't enabled the OS-level setting. Decorative glitch/CRT/RGB/glow
   effects are killed outright; everything else becomes near-instant. */
html.reduce-motion *,
html.reduce-motion *::before,
html.reduce-motion *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
}
html.reduce-motion [class*="glitch"],
html.reduce-motion [class*="rgb"],
html.reduce-motion [class*="flicker"],
html.reduce-motion [class*="crt"],
html.reduce-motion [class*="matrix"],
html.reduce-motion .save-link-card,
html.reduce-motion .copy-link-btn {
    animation: none !important;
}

/* ==========================================
   CONTENT VISIBILITY (Performance)
   ========================================== */

/* Optimize off-screen content */
.content-wrapper > section {
    content-visibility: auto;
    contain-intrinsic-size: 500px;
}
