/* Global CSS for InlineTetrisLoader - Works on all pages including static ones */

/* CSS Variables for customization */
:root {
    --inline-block-size: 30px;
    --inline-padding: 1px;
    --piece-color-p: #e74c3c;
    --piece-color-s: #3498db;
    --piece-color-c: #f1c40f;
    --top-color-1: #3498db;
    --top-color-2: #f1c40f;
    --top-color-3: #e74c3c;
    --inline-glow-color: #ffffff;
    --gap: 8px;
}

/* Size variants */
.size-small {
    --inline-block-size: 20px;
    --inline-padding: 1px;
}

.size-medium {
    --inline-block-size: 30px;
    --inline-padding: 1px;
}

.size-large {
    --inline-block-size: 40px;
    --inline-padding: 2px;
}

.size-extralarge {
    --inline-block-size: 50px;
    --inline-padding: 2px;
}

.size-custom {
    --inline-block-size: var(--custom-block-size, 30px);
}

/* Main wrapper */
.inline-tetris-wrapper {
    display: inline-flex !important;
    flex-direction: column;
    align-items: center;
    gap: var(--gap);
    font-family: 'Inter', 'Segoe UI', sans-serif;
}


/* Content row for different layouts */
.content-row {
    display: flex;
    align-items: center;
    gap: var(--gap);
}

.content-row.direction-left {
    flex-direction: row;
}

.content-row.direction-right {
    flex-direction: row-reverse;
}

.content-row.direction-top,
.content-row.direction-bottom {
    flex-direction: column;
}

/* The inline tetris loader container - HIDE OVERFLOW for clean exit */
.inline-tetris-loader {
    display: inline-block;
    vertical-align: middle;
    perspective: 500px;
    position: relative; 
    overflow: hidden;   /* Hide pieces when they fly out */
    border-radius: 8px;  
    padding: 5px;        
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    border: 2px solid rgba(255,255,255,0.1); /* Subtle border for containment */
}

.inline-tetris-loader.hoverable:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.inline-tetris-loader.clickable {
    cursor: pointer;
}

.inline-tetris-loader.clickable:active {
    transform: scale(0.95);
}

/* Wrapper for the parallax effect */
.parallax-wrapper {
    width: 100%;
    height: 100%;
    transition: transform 0.1s linear;
    transform-style: preserve-3d;
}

.logo-container {
    position: relative;
    width: calc(var(--inline-block-size) * 4 + var(--inline-padding) * 3);
    height: calc(var(--inline-block-size) * 2 + var(--inline-padding));
    transform-style: preserve-3d;
}

/* Tetris pieces - start hidden above the container, will be animated by JavaScript */
.tetris-piece, .ghost-piece {
    position: absolute;
    border-radius: 4px;
    box-sizing: border-box;
    opacity: 0;
    transform: translateY(-200px); /* Start above container by default */
}

/* Ensure pieces are visible during animation */
.animate-in .tetris-piece {
    opacity: 1;
}

.tetris-piece {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: calc(var(--inline-block-size) * 0.06);
    font-weight: 700;
    font-size: calc(var(--inline-block-size) * 0.6);
    color: white;
    text-shadow: 0 1px 2px rgba(0,0,0,0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 
        inset 0 1px 1px rgba(255, 255, 255, 0.2),
        inset 0 -1px 1px rgba(0, 0, 0, 0.2),
        0 5px 10px rgba(0,0,0,0.2);
    transition: transform 0.2s ease, box-shadow 0.4s ease;
    overflow: hidden;
}

.ghost-piece {
    border: 2px dashed;
    background: rgba(255,255,255,0.05);
    opacity: 0;
}

/* Piece positioning and colors */
.piece-p, .ghost-p { 
    width: var(--inline-block-size); 
    height: var(--inline-block-size); 
    top: calc(var(--inline-block-size) + var(--inline-padding)); 
    left: 0; 
}

.piece-s, .ghost-s { 
    width: var(--inline-block-size); 
    height: calc(var(--inline-block-size) * 2 + var(--inline-padding)); 
    top: 0; 
    left: calc(var(--inline-block-size) + var(--inline-padding));
}

.piece-c, .ghost-c { 
    width: calc(var(--inline-block-size) * 2 + var(--inline-padding)); 
    height: var(--inline-block-size); 
    top: calc(var(--inline-block-size) + var(--inline-padding)); 
    left: calc(var(--inline-block-size) * 2 + var(--inline-padding) * 2);
    padding-right: var(--inline-block-size);
}

.piece-top1, .ghost-top1 { 
    width: var(--inline-block-size); 
    height: var(--inline-block-size); 
    top: 0; 
    left: 0; 
}

.piece-top2, .ghost-top2 { 
    width: var(--inline-block-size); 
    height: var(--inline-block-size); 
    top: 0; 
    left: calc(var(--inline-block-size) * 2 + var(--inline-padding) * 2); 
}

.piece-top3, .ghost-top3 { 
    width: var(--inline-block-size); 
    height: var(--inline-block-size); 
    top: 0; 
    left: calc(var(--inline-block-size) * 3 + var(--inline-padding) * 3); 
}

/* Colors using CSS variables */
.piece-p { background: var(--piece-color-p); }
.piece-s { background: var(--piece-color-s); }
.piece-c { background: var(--piece-color-c); }
.piece-top1 { background: var(--top-color-1); }
.piece-top2 { background: var(--top-color-2); }
.piece-top3 { background: var(--top-color-3); }

.ghost-p { border-color: var(--piece-color-p); }
.ghost-s { border-color: var(--piece-color-s); }
.ghost-c { border-color: var(--piece-color-c); }
.ghost-top1 { border-color: var(--top-color-1); }
.ghost-top2 { border-color: var(--top-color-2); }
.ghost-top3 { border-color: var(--top-color-3); }

/* Authentic Tetris Animation Sequence - 5 second cycle */

/* Phase 1: Ghost pieces appear first (like Tetris preview) */
.inline-tetris-wrapper.loading .ghost-piece { 
    animation: tetris-ghost-preview 5s ease-in-out infinite !important; 
}

/* Remove all conflicting CSS animations - JavaScript will handle everything */

/* Removed duplicate - already defined above */

/* Authentic Tetris Ghost Preview Animation */
@keyframes tetris-ghost-preview {
    /* Phase 1: Ghost appears (like Tetris piece preview) */
    0%, 10% { 
        opacity: 0; 
    }
    15% { 
        opacity: 0.6; 
    }
    /* Stay visible while pieces fall */
    60% { 
        opacity: 0.4; 
    }
    /* Disappear during line clear */
    70%, 80% { 
        opacity: 0; 
    }
    /* Stay hidden until next cycle */
    100% { 
        opacity: 0; 
    }
}

/* EXACT keyframes from TetrisLoader.razor.css */
@keyframes ghost-fall {
    0% { opacity: 0; transform: translateY(-200px); }
    50% { opacity: 0.5; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(0); }
}

@keyframes piece-fall {
    0% { opacity: 1; transform: translateY(-200px); }
    70% { transform: translateY(10px); }
    100% { opacity: 1; transform: translateY(0); }
}

/* EXACT copy of original TetrisLoader piece-out animation */
@keyframes piece-out {
    from { 
        opacity: 1; 
        transform: translateY(0) rotate(0) scale(1); 
    }
    to {
        opacity: 0;
        transform: 
            translateY(var(--y-out)) 
            translateX(var(--x-out)) 
            rotate(var(--r-out)) 
            scale(0.5);
    }
}

/* Remove conflicting opacity rules */

/* Simple, clean piece colors - let JavaScript handle positioning */
.piece-p { background: #e74c3c; } /* Red */
.piece-s { background: #3498db; } /* Blue */
.piece-c { background: #f1c40f; } /* Yellow */
.piece-top1 { background: #3498db; } /* Blue */
.piece-top2 { background: #f1c40f; } /* Yellow */
.piece-top3 { background: #e74c3c; } /* Red */

/* EXACT original TetrisLoader animate-out spinning effects */
.animate-out .tetris-piece {
    animation: piece-out 1s ease-in forwards !important;
    box-shadow: 
        inset 0 2px 2px rgba(255, 255, 255, 0.2),
        inset 0 -2px 2px rgba(0, 0, 0, 0.2),
        0 10px 20px rgba(0,0,0,0.2);
}

.animate-out .piece-p { 
    --x-out: -150px; 
    --y-out: 50px; 
    --r-out: -90deg; 
    animation-delay: 0s; 
}

.animate-out .piece-top1 { 
    --x-out: -150px; 
    --y-out: -50px; 
    --r-out: 90deg; 
    animation-delay: 0.1s; 
}

.animate-out .piece-s { 
    --x-out: 0px; 
    --y-out: 150px; 
    --r-out: -45deg; 
    animation-delay: 0.2s; 
}

.animate-out .piece-c { 
    --x-out: 150px; 
    --y-out: 50px; 
    --r-out: 90deg; 
    animation-delay: 0.3s; 
}

.animate-out .piece-top2 { 
    --x-out: 150px; 
    --y-out: -50px; 
    --r-out: -90deg; 
    animation-delay: 0.4s; 
}

.animate-out .piece-top3 { 
    --x-out: 200px; 
    --y-out: -50px; 
    --r-out: 45deg; 
    animation-delay: 0.5s; 
}

/* Reset pieces to starting position before animation - CRITICAL for looping */
.inline-tetris-loader:not(.animate-in):not(.animate-complete):not(.animate-out) .tetris-piece,
.inline-tetris-loader:not(.animate-in):not(.animate-complete):not(.animate-out) .ghost-piece {
    opacity: 0 !important;
    transform: translateY(-200px) !important;
    animation: none !important;
}

/* Explicit reset when all classes are removed */
.inline-tetris-loader .tetris-piece,
.inline-tetris-loader .ghost-piece {
    transition: none; /* Disable transitions during reset */
}

/* Animation Phase 1: Animate In - EXACT copy from TetrisLoader.razor.css */
.animate-in .ghost-piece { 
    animation: ghost-fall 0.5s cubic-bezier(0.5, 0, 1, 1) forwards; 
}

.animate-in .tetris-piece { 
    animation: piece-fall 0.5s cubic-bezier(0.5, 0, 1, 1) forwards; 
}

.animate-in .ghost-p, .animate-in .piece-p { animation-delay: 0.2s; }
.animate-in .ghost-s, .animate-in .piece-s { animation-delay: 0.8s; }
.animate-in .ghost-c, .animate-in .piece-c { animation-delay: 1.4s; }
.animate-in .ghost-top1, .animate-in .piece-top1 { animation-delay: 0.5s; }
.animate-in .ghost-top2, .animate-in .piece-top2 { animation-delay: 1.7s; }
.animate-in .ghost-top3, .animate-in .piece-top3 { animation-delay: 2.0s; }

/* Animation fill mode */
.animate-in .tetris-piece { 
    animation-fill-mode: forwards; 
}

/* Complete state - pieces stay visible with glow */
.animate-complete .tetris-piece {
    opacity: 1;
    box-shadow: 
        inset 0 1px 1px rgba(255, 255, 255, 0.2), 
        inset 0 -1px 1px rgba(0, 0, 0, 0.2),
        0 0 25px var(--inline-glow-color), 
        0 5px 15px rgba(0,0,0,0.3);
}

/* Line Clear Effect */
.line-clear {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--inline-glow-color);
    opacity: 0;
    filter: blur(25px);
    border-radius: 10px;
}

.animate-in .line-clear { 
    animation: line-clear-anim 0.5s ease-out 2.8s forwards; 
}

@keyframes line-clear-anim {
    0% { opacity: 0; transform: translateX(-100%); }
    30% { opacity: 0.6; }
    70% { opacity: 0.6; }
    100% { opacity: 0; transform: translateX(150%); }
}

/* Authentic Tetris Line Clear Animation */
@keyframes tetris-line-clear-authentic {
    /* Stay hidden until line clear moment */
    0%, 65% { 
        opacity: 0; 
        transform: scaleX(0); 
    }
    
    /* Flash effect during line clear (like real Tetris) */
    70% { 
        opacity: 0.8; 
        transform: scaleX(1) scaleY(3); 
        background: linear-gradient(90deg, 
            transparent 0%, 
            rgba(255,255,255,0.9) 20%, 
            rgba(255,255,255,1) 50%, 
            rgba(255,255,255,0.9) 80%, 
            transparent 100%);
    }
    
    /* Quick fade */
    75% { 
        opacity: 0; 
        transform: scaleX(1) scaleY(1); 
    }
    
    /* Stay hidden until next cycle */
    100% { 
        opacity: 0; 
        transform: scaleX(0); 
    }
}

/* Authentic Tetris Glitch Effect during Line Clear */
@keyframes tetris-glitch-authentic {
    /* Normal state */
    0%, 68%, 72%, 100% { 
        transform: translate(0, 0); 
    }
    
    /* Glitch during line clear (like CRT display effect) */
    69% { 
        transform: translate(2px, -1px) skew(1deg); 
    }
    69.5% { 
        transform: translate(-2px, 1px) skew(-1deg); 
    }
    70% { 
        transform: translate(1px, -2px) skew(0.5deg); 
    }
    70.5% { 
        transform: translate(-1px, 2px) skew(-0.5deg); 
    }
    71% { 
        transform: translate(0, 0) skew(0deg); 
    }
}

/* Original single-run animations */
@keyframes inline-ghost-fall {
    0% { opacity: 0; transform: translateY(-100px); }
    50% { opacity: 0.5; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(0); }
}

@keyframes inline-piece-fall {
    0% { opacity: 1; transform: translateY(-100px); }
    70% { transform: translateY(5px); }
    100% { opacity: 1; transform: translateY(0); }
}

/* Authentic Tetris line clear flash overlay */
.line-clear {
    position: absolute; 
    top: -5px; 
    left: -5px; 
    width: calc(100% + 10px); 
    height: calc(100% + 10px);
    background: linear-gradient(90deg, 
        transparent 0%, 
        rgba(255,255,255,0.9) 20%, 
        rgba(255,255,255,1) 50%, 
        rgba(255,255,255,0.9) 80%, 
        transparent 100%);
    opacity: 0; 
    border-radius: 8px;
    pointer-events: none;
    z-index: 10;
}

/* Authentic Tetris line clear effect synchronized with pieces */
.inline-tetris-wrapper.loading .line-clear { 
    animation: tetris-line-clear-authentic 5s ease-out infinite; 
}

/* Authentic Tetris glitch effect during line clear */
.inline-tetris-wrapper.loading .logo-container { 
    animation: tetris-glitch-authentic 5s linear infinite; 
}

/* JavaScript-triggered line clear effect */
.animate-in .line-clear { 
    animation: inline-line-clear-anim 0.5s ease-out 2.8s forwards; 
}

/* Line clear animation for looping */
@keyframes inline-line-clear-loop {
    0%, 85%, 100% { opacity: 0; transform: translateX(-100%); }
    48% { opacity: 0; transform: translateX(-100%); }
    52% { opacity: 0.6; transform: translateX(-100%); }
    60% { opacity: 0.6; transform: translateX(0%); }
    68% { opacity: 0.6; transform: translateX(150%); }
    72% { opacity: 0; transform: translateX(150%); }
}

/* Original line clear animation */
@keyframes inline-line-clear-anim {
    0% { opacity: 0; transform: translateX(-100%); }
    30% { opacity: 0.6; }
    70% { opacity: 0.6; }
    100% { opacity: 0; transform: translateX(150%); }
}

/* Glitch effect */
.animate-in .logo-container { 
    animation: inline-glitch 0.1s linear 2.9s 2; 
}

/* Glitch effect for looping */
@keyframes inline-glitch-loop {
    0%, 85%, 100% { transform: translate(0, 0); }
    49% { transform: translate(0, 0); }
    49.5% { transform: translate(2px, -1px); }
    50% { transform: translate(-1px, 1px); }
    50.5% { transform: translate(1px, -2px); }
    51% { transform: translate(0, 0); }
}

/* Original glitch effect */
@keyframes inline-glitch {
    0%, 100% { transform: translate(0, 0); } 
    25% { transform: translate(2px, -1px); }
    50% { transform: translate(-1px, 1px); } 
    75% { transform: translate(1px, -2px); }
}

.animate-in .tetris-piece { 
    animation-fill-mode: forwards; 
}

.animate-complete .tetris-piece {
    opacity: 1 !important;
    box-shadow: 
        inset 0 1px 1px rgba(255, 255, 255, 0.2), 
        inset 0 -1px 1px rgba(0, 0, 0, 0.2),
        0 0 15px var(--inline-glow-color), 
        0 3px 10px rgba(0,0,0,0.3);
}

/* Interactive hover effect */
.animate-complete .tetris-piece:hover {
    transform: translateY(-4px) scale(1.05);
    z-index: 10;
    box-shadow: 
        inset 0 1px 1px rgba(255, 255, 255, 0.3), 
        inset 0 -1px 1px rgba(0, 0, 0, 0.3),
        0 0 20px var(--inline-glow-color), 
        0 5px 15px rgba(0,0,0,0.4);
}

/* Metallic shine effect */
.tetris-piece::after {
    content: ''; 
    position: absolute; 
    top: 0; 
    left: 0; 
    width: 200%; 
    height: 200%;
    background: linear-gradient(
        45deg, 
        rgba(255, 255, 255, 0) 40%, 
        rgba(255, 255, 255, 0.4) 50%, 
        rgba(255, 255, 255, 0) 60%
    );
    transform: translateX(-125%) translateY(-125%) rotate(45deg); 
    opacity: 0; 
    transition: opacity 0.3s;
}

@keyframes inline-metallic-shine {
    0% { transform: translateX(-125%) translateY(-125%) rotate(45deg); opacity: 0; }
    50% { opacity: 1; }
    100% { transform: translateX(125%) translateY(125%) rotate(45deg); opacity: 0; }
}

.animate-complete .tetris-piece::after { 
    animation: inline-metallic-shine 0.8s ease-in-out forwards; 
}

.animate-complete .piece-top1::after { animation-delay: 0.2s; }
.animate-complete .piece-p::after { animation-delay: 0.25s; }
.animate-complete .piece-s::after { animation-delay: 0.3s; }
.animate-complete .piece-top2::after { animation-delay: 0.35s; }
.animate-complete .piece-c::after { animation-delay: 0.4s; }
.animate-complete .piece-top3::after { animation-delay: 0.45s; }

/* Progress bar styles */
.progress-container {
    display: flex;
    align-items: center;
    justify-content: center;
}

.progress-container.progress-top,
.progress-container.progress-bottom {
    width: 100%;
}

.progress-container.progress-left,
.progress-container.progress-right {
    height: 100%;
}

.progress-bar-wrapper {
    display: flex;
    align-items: center;
    gap: 6px;
}

.progress-bar-wrapper.modern .progress-bar-background {
    border-radius: 50px;
    overflow: hidden;
}

.progress-bar-wrapper.classic .progress-bar-background {
    border-radius: 2px;
    overflow: hidden;
}

.progress-bar-wrapper.minimal .progress-bar-background {
    border-radius: 0;
    height: 2px !important;
}

.progress-bar-wrapper.chunky .progress-bar-background {
    border-radius: 4px;
    height: 12px !important;
}

.progress-bar-background {
    position: relative;
    overflow: hidden;
}

.progress-bar-fill {
    border-radius: inherit;
    transition: width 0.3s ease, height 0.3s ease;
}

.progress-percentage {
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
    min-width: 35px;
    text-align: center;
}

/* Loading text styles */
.loading-text-container {
    font-size: 12px;
    font-weight: 400;
    text-align: center;
    white-space: nowrap;
}

.loading-text-container.text-bold {
    font-weight: bold;
}

.loading-text-container.text-top {
    order: -1;
}

.loading-text-container.text-bottom {
    order: 1;
}

.loading-text-container.text-left {
    writing-mode: vertical-rl;
    text-orientation: mixed;
}

.loading-text-container.text-right {
    writing-mode: vertical-lr;
    text-orientation: mixed;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .size-large {
        --inline-block-size: 35px;
    }
    
    .size-extralarge {
        --inline-block-size: 40px;
    }
    
    .progress-percentage {
        font-size: 10px;
    }
    
    .loading-text-container {
        font-size: 11px;
    }
}

/* Focus states for accessibility */
.inline-tetris-loader.clickable:focus {
    outline: 2px solid #3498db;
    outline-offset: 2px;
}