/* ============================================
   Connect 4 AI - Loading Screen (Anime Style)
   ============================================ */

.loading-screen {
    position: fixed;
    inset: 0;
    background: var(--background);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    overflow: hidden;
}

/* Background gradient */
.loading-screen::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(
        ellipse at center,
        rgba(59, 130, 246, 0.1) 0%,
        transparent 50%
    );
    animation: pulse-bg 3s ease-in-out infinite;
}

@keyframes pulse-bg {
    0%, 100% { opacity: 0.5; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.1); }
}

/* Main container */
.loading-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
    z-index: 10;
}

/* ============================================
   Animated Grid
   ============================================ */

.loading-grid {
    position: relative;
    width: 280px;
    height: 240px;
}

.grid-svg {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 0 10px rgba(59, 130, 246, 0.5));
}

.grid-line {
    stroke: var(--primary);
    stroke-width: 2;
    stroke-linecap: round;
    fill: none;
    opacity: 0;
}

/* Vertical lines animation */
.v-line {
    stroke-dasharray: 240;
    stroke-dashoffset: 240;
    animation: draw-v-line 0.6s ease forwards;
    animation-delay: calc(var(--delay) * 0.1s);
}

@keyframes draw-v-line {
    to {
        stroke-dashoffset: 0;
        opacity: 1;
    }
}

/* Horizontal lines animation */
.h-line {
    stroke-dasharray: 280;
    stroke-dashoffset: 280;
    animation: draw-h-line 0.6s ease forwards;
    animation-delay: calc(0.6s + var(--delay) * 0.1s);
}

@keyframes draw-h-line {
    to {
        stroke-dashoffset: 0;
        opacity: 1;
    }
}

/* Grid pulse effect */
.grid-lines {
    animation: grid-pulse 2s ease-in-out infinite;
    animation-delay: 1.5s;
}

@keyframes grid-pulse {
    0%, 100% { filter: drop-shadow(0 0 5px rgba(59, 130, 246, 0.3)); }
    50% { filter: drop-shadow(0 0 20px rgba(59, 130, 246, 0.8)); }
}

/* ============================================
   Loading Discs (Anime style)
   ============================================ */

.loading-discs {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.loading-disc {
    position: absolute;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    left: calc(var(--col) * 40px + 4px);
    opacity: 0;
    animation: disc-drop 0.5s cubic-bezier(0.35, 0, 0.25, 1) forwards;
    animation-delay: var(--delay);
}

.loading-disc::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    animation: disc-glow 1s ease-in-out infinite;
    animation-delay: var(--delay);
}

.loading-disc::after {
    content: '';
    position: absolute;
    left: 50%;
    top: -100px;
    width: 4px;
    height: 100px;
    transform: translateX(-50%);
    background: linear-gradient(to bottom, transparent, currentColor);
    opacity: 0;
    animation: speed-line 0.3s ease-out forwards;
    animation-delay: var(--delay);
}

@keyframes disc-drop {
    0% {
        top: -50px;
        opacity: 0;
        transform: scale(0.8);
    }
    60% {
        opacity: 1;
        transform: scale(1.1);
    }
    80% {
        top: calc(var(--row) * 40px + 4px);
        transform: scale(0.95);
    }
    100% {
        top: calc(var(--row) * 40px + 4px);
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes speed-line {
    0% { opacity: 0.8; height: 100px; }
    100% { opacity: 0; height: 20px; }
}

@keyframes disc-glow {
    0%, 100% { box-shadow: 0 0 5px currentColor; }
    50% { box-shadow: 0 0 20px currentColor, 0 0 40px currentColor; }
}

.disc-blue {
    background: var(--primary);
    color: var(--primary);
    box-shadow: 0 0 15px var(--primary);
}

.disc-red {
    background: var(--danger);
    color: var(--danger);
    box-shadow: 0 0 15px var(--danger);
}

/* ============================================
   Loading Text
   ============================================ */

.loading-text {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.loading-title {
    font-size: 2.5rem;
    font-weight: 700;
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    opacity: 0;
    animation: title-appear 0.5s ease forwards;
    animation-delay: 1.2s;
}

@keyframes title-appear {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.title-connect {
    color: var(--foreground);
    letter-spacing: 0.05em;
}

.title-four {
    font-size: 3rem;
    background: linear-gradient(135deg, var(--primary), var(--danger));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: four-pulse 2s ease-in-out infinite;
}

@keyframes four-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.title-ai {
    font-size: 1rem;
    color: var(--muted);
    font-family: var(--font-mono);
    text-transform: uppercase;
    letter-spacing: 0.2em;
}

.loading-subtitle {
    color: var(--muted);
    font-size: 0.875rem;
    opacity: 0;
    animation: title-appear 0.5s ease forwards;
    animation-delay: 1.4s;
}

/* ============================================
   Progress Bar
   ============================================ */

.progress-container {
    display: flex;
    align-items: center;
    gap: 1rem;
    opacity: 0;
    animation: title-appear 0.5s ease forwards;
    animation-delay: 1.6s;
}

.progress-bar {
    width: 200px;
    height: 4px;
    background: var(--card-border);
    border-radius: 2px;
    overflow: hidden;
    position: relative;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    border-radius: 2px;
    transition: width 0.3s ease;
    position: relative;
}

.progress-glow {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    background: var(--primary);
    border-radius: 50%;
    filter: blur(10px);
    opacity: 0.8;
    animation: glow-move 2s ease-in-out infinite;
}

@keyframes glow-move {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

.progress-text {
    font-size: 0.75rem;
    font-family: var(--font-mono);
    color: var(--muted);
    min-width: 3ch;
}

/* ============================================
   Japanese Accent
   ============================================ */

.japanese-accent {
    position: absolute;
    bottom: -60px;
    right: -40px;
    font-size: 4rem;
    font-weight: 700;
    color: var(--card-border);
    opacity: 0.3;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    pointer-events: none;
    animation: japanese-fade 1s ease forwards;
    animation-delay: 2s;
}

@keyframes japanese-fade {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 0.3; transform: translateY(0); }
}

/* ============================================
   Particles
   ============================================ */

.particles {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
}

.particle {
    position: absolute;
    width: 4px;
    height: 4px;
    background: var(--primary);
    border-radius: 50%;
    opacity: 0;
    animation: particle-float 4s ease-in-out infinite;
}

@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);
    }
}

/* ============================================
   Ready State
   ============================================ */

.loading-screen.ready .loading-container {
    animation: ready-flash 0.5s ease forwards;
}

@keyframes ready-flash {
    0% { filter: brightness(1); }
    50% { filter: brightness(2); }
    100% { filter: brightness(1); }
}

.loading-screen.fade-out {
    animation: screen-fade 0.5s ease forwards;
}

@keyframes screen-fade {
    to {
        opacity: 0;
        visibility: hidden;
    }
}

/* ============================================
   Responsive
   ============================================ */

@media (max-width: 400px) {
    .loading-grid {
        width: 210px;
        height: 180px;
        transform: scale(0.8);
    }

    .loading-title {
        font-size: 1.75rem;
    }

    .title-four {
        font-size: 2.25rem;
    }

    .progress-bar {
        width: 150px;
    }

    .japanese-accent {
        font-size: 2.5rem;
        right: -20px;
        bottom: -40px;
    }
}
