/* ===================================
   Animation Modal Styles
   =================================== */

/* Modal overlay */
.animation-modal-v2 {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 10000;
    display: none;
    justify-content: center;
    align-items: center;
}

.animation-modal-v2.active {
    display: flex;
}

/* Backdrop */
.animation-modal-v2__backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(4px);
    opacity: 0;
    transition: opacity 300ms cubic-bezier(0.4, 0.0, 0.2, 1),
                backdrop-filter 300ms cubic-bezier(0.4, 0.0, 0.2, 1);
    will-change: opacity, backdrop-filter;
}

.animation-modal-v2.active .animation-modal-v2__backdrop {
    opacity: 1;
}

/* Modal content */
.animation-modal-v2__content {
    position: relative;
    background: #ffffff;
    border-radius: 16px;
    padding: 2rem;
    max-width: 90vw;
    max-height: 90vh;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    z-index: 1;
    opacity: 0;
    transform: scale(0.95) translateZ(0);
    transition: opacity 300ms cubic-bezier(0.4, 0.0, 0.2, 1),
                transform 300ms cubic-bezier(0.4, 0.0, 0.2, 1);
    will-change: transform, opacity;
}

.animation-modal-v2.active .animation-modal-v2__content {
    opacity: 1;
    transform: scale(1) translateZ(0);
}

/* Close button */
.animation-modal-v2__close {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: transparent;
    border: none;
    font-size: 1.5rem;
    color: #999;
    cursor: pointer;
    transition: color 200ms cubic-bezier(0.4, 0.0, 0.2, 1),
                background-color 200ms cubic-bezier(0.4, 0.0, 0.2, 1);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    z-index: 2;
}

.animation-modal-v2__close:hover {
    color: #333;
    background: #f0f0f0;
}

/* Layout: solution on left, cube on right */
.animation-modal-v2__layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    min-height: 500px;
}

/* Solution section */
.animation-modal-v2__solution {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.animation-modal-v2__solution h3 {
    margin: 0;
    font-size: 1.5rem;
    color: #2c3e50;
    font-weight: 600;
}

.animation-modal-v2__moves {
    flex: 1;
    background: #f8f9fa;
    border-radius: 8px;
    padding: 1rem;
    overflow-y: auto;
    max-height: 350px;
    line-height: 2;
}

/* Custom scrollbar */
.animation-modal-v2__moves::-webkit-scrollbar {
    width: 8px;
}

.animation-modal-v2__moves::-webkit-scrollbar-track {
    background: #e9ecef;
    border-radius: 4px;
}

.animation-modal-v2__moves::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

.animation-modal-v2__moves::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Move highlighting */
.animation-modal-v2__moves .move {
    display: inline-block;
    padding: 0.3rem 0.6rem;
    margin: 0.2rem;
    border-radius: 4px;
    transition: background-color 300ms cubic-bezier(0.4, 0.0, 0.2, 1),
                color 300ms cubic-bezier(0.4, 0.0, 0.2, 1),
                transform 300ms cubic-bezier(0.4, 0.0, 0.2, 1),
                box-shadow 300ms cubic-bezier(0.4, 0.0, 0.2, 1);
    font-weight: 500;
    font-size: 1rem;
    background: transparent;
    will-change: transform, background-color;
}

.animation-modal-v2__moves .move.active {
    background: #667eea;
    color: white;
    font-weight: 600;
    transform: scale(1.15);
    box-shadow: 0 6px 16px rgba(102, 126, 234, 0.6);
}

/* Progress display */
.animation-modal-v2__progress {
    padding: 0.75rem 1rem;
    background: #e9ecef;
    border-radius: 8px;
    text-align: center;
    font-weight: 500;
    color: #495057;
    font-size: 0.95rem;
}

.animation-modal-v2__progress span {
    font-weight: 600;
    color: #667eea;
}

/* Cube section */
.animation-modal-v2__cube-section {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Cube container with 3D perspective */
.animation-cube-container-v2 {
    width: 100%;
    height: 400px;
    display: flex;
    justify-content: center;
    align-items: center;
    perspective: 1000px;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    border-radius: 12px;
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.1);
    position: relative;
}

/* 3D cube wrapper */
.anim-cube-3d {
    width: 200px;
    height: 200px;
    position: relative;
    transform-style: preserve-3d;
    transform: rotateX(-15deg) rotateY(25deg);
    transition: transform 0.5s ease;
    will-change: transform;
    cursor: grab;
}

.anim-cube-3d:active {
    cursor: grabbing;
}

/* Rotation reset button */
.anim-rotation-reset-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 32px;
    height: 32px;
    border: 2px solid #667eea;
    background: rgba(255, 255, 255, 0.9);
    color: #667eea;
    border-radius: 50%;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    z-index: 10;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.anim-rotation-reset-btn:hover {
    background: #667eea;
    color: white;
    transform: scale(1.1);
}

/* Mobile-specific optimizations */
.anim-cube-3d--mobile {
    /* Disable floating animation on mobile for better performance */
    animation: none !important;
    /* Force GPU acceleration */
    transform: rotateX(-20deg) rotateY(30deg) translateZ(0);
    will-change: transform;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

/* Low-end device optimizations */
.anim-cube-3d--low-end {
    /* Simplify transforms for low-end devices */
    animation: none !important;
}

@keyframes cubeFloat {
    0%, 100% {
        transform: rotateX(-20deg) rotateY(30deg) translateZ(0) translateY(0);
    }
    50% {
        transform: rotateX(-20deg) rotateY(30deg) translateZ(0) translateY(-10px);
    }
}

/* ===================================
   Face Rotation Keyframe Animations
   =================================== */

/* Clockwise rotation (90 degrees) */
@keyframes rotateFaceClockwise {
    0% {
        transform: rotateZ(0deg);
    }
    100% {
        transform: rotateZ(90deg);
    }
}

/* Counterclockwise rotation (-90 degrees) */
@keyframes rotateFaceCounterClockwise {
    0% {
        transform: rotateZ(0deg);
    }
    100% {
        transform: rotateZ(-90deg);
    }
}

/* Rotation animation classes for each face */
/* Front face rotations */
.anim-cube-face--front.rotating-cw {
    animation: rotateFaceClockwise 500ms cubic-bezier(0.4, 0.0, 0.2, 1);
}

.anim-cube-face--front.rotating-ccw {
    animation: rotateFaceCounterClockwise 500ms cubic-bezier(0.4, 0.0, 0.2, 1);
}

/* Back face rotations */
.anim-cube-face--back.rotating-cw {
    animation: rotateFaceClockwise 500ms cubic-bezier(0.4, 0.0, 0.2, 1);
}

.anim-cube-face--back.rotating-ccw {
    animation: rotateFaceCounterClockwise 500ms cubic-bezier(0.4, 0.0, 0.2, 1);
}

/* Right face rotations */
.anim-cube-face--right.rotating-cw {
    animation: rotateFaceClockwise 500ms cubic-bezier(0.4, 0.0, 0.2, 1);
}

.anim-cube-face--right.rotating-ccw {
    animation: rotateFaceCounterClockwise 500ms cubic-bezier(0.4, 0.0, 0.2, 1);
}

/* Left face rotations */
.anim-cube-face--left.rotating-cw {
    animation: rotateFaceClockwise 500ms cubic-bezier(0.4, 0.0, 0.2, 1);
}

.anim-cube-face--left.rotating-ccw {
    animation: rotateFaceCounterClockwise 500ms cubic-bezier(0.4, 0.0, 0.2, 1);
}

/* Top face rotations */
.anim-cube-face--top.rotating-cw {
    animation: rotateFaceClockwise 500ms cubic-bezier(0.4, 0.0, 0.2, 1);
}

.anim-cube-face--top.rotating-ccw {
    animation: rotateFaceCounterClockwise 500ms cubic-bezier(0.4, 0.0, 0.2, 1);
}

/* Bottom face rotations */
.anim-cube-face--bottom.rotating-cw {
    animation: rotateFaceClockwise 500ms cubic-bezier(0.4, 0.0, 0.2, 1);
}

.anim-cube-face--bottom.rotating-ccw {
    animation: rotateFaceCounterClockwise 500ms cubic-bezier(0.4, 0.0, 0.2, 1);
}

/* Cube faces */
.anim-cube-face {
    position: absolute;
    width: 200px;
    height: 200px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 3px;
    padding: 3px;
    background: #000;
    border-radius: 4px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
}

.anim-cube-face--front {
    transform: translateZ(100px);
}

.anim-cube-face--back {
    transform: rotateY(180deg) translateZ(100px);
}

.anim-cube-face--right {
    transform: rotateY(90deg) translateZ(100px);
}

.anim-cube-face--left {
    transform: rotateY(-90deg) translateZ(100px);
}

.anim-cube-face--top {
    transform: rotateX(90deg) translateZ(100px);
}

.anim-cube-face--bottom {
    transform: rotateX(-90deg) translateZ(100px);
}

/* Stickers */
.anim-cube-sticker {
    border: 1px solid #ddd;
    border-radius: 4px;
    transition: background-color 400ms cubic-bezier(0.4, 0.0, 0.2, 1),
                transform 500ms cubic-bezier(0.4, 0.0, 0.2, 1),
                opacity 500ms cubic-bezier(0.4, 0.0, 0.2, 1);
    will-change: background-color, transform;
}

.anim-cube-sticker:hover {
    transform: scale(0.95);
}

/* Color classes for stickers - CSS class-based approach for better performance */
/* Colors match the main 3D view for consistency */
.anim-cube-sticker.color-U {
    background-color: #ffffff; /* White (Up) */
}

.anim-cube-sticker.color-R {
    background-color: #FF3333; /* Red (Right) - lighter for better visibility */
}

.anim-cube-sticker.color-F {
    background-color: #00ff00; /* Green (Front) */
}

.anim-cube-sticker.color-D {
    background-color: #ffff00; /* Yellow (Down) */
}

.anim-cube-sticker.color-L {
    background-color: #ffa500; /* Orange (Left) */
}

.anim-cube-sticker.color-B {
    background-color: #4DA6FF; /* Blue (Back) - lighter for better visibility */
}

/* Controls */
.animation-modal-v2__controls {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
}

.anim-control-btn {
    padding: 0.5rem 0.75rem;
    border: none;
    border-radius: 6px;
    background: #f8f9fa;
    color: #495057;
    cursor: pointer;
    transition: background-color 200ms cubic-bezier(0.4, 0.0, 0.2, 1),
                transform 200ms cubic-bezier(0.4, 0.0, 0.2, 1),
                box-shadow 200ms cubic-bezier(0.4, 0.0, 0.2, 1),
                opacity 200ms cubic-bezier(0.4, 0.0, 0.2, 1);
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    min-width: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    will-change: transform;
}

.anim-control-btn .btn-icon {
    font-size: 1rem;
    line-height: 1;
}

.anim-control-btn .btn-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.anim-control-btn:hover:not(:disabled) {
    background: #e9ecef;
    transform: translateY(-2px) translateZ(0);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.anim-control-btn:active:not(:disabled) {
    transform: translateY(0) translateZ(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.anim-control-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    background: #f8f9fa;
}

/* Reset button - distinct styling */
.anim-control-btn--reset {
    background: #fff3e0;
    color: #e65100;
    border: 2px solid #ffb74d;
    font-weight: 600;
    padding: 0.6rem 1rem;
}

.anim-control-btn--reset:hover:not(:disabled) {
    background: #ffe0b2;
    border-color: #ffa726;
    box-shadow: 0 4px 12px rgba(230, 81, 0, 0.3);
}

.anim-control-btn--reset .btn-icon {
    font-size: 1.1rem;
}

/* Step buttons - subtle styling */
.anim-control-btn--step {
    background: #f5f5f5;
    color: #616161;
    border: 1px solid #e0e0e0;
    min-width: 40px;
}

.anim-control-btn--step:hover:not(:disabled) {
    background: #eeeeee;
    border-color: #bdbdbd;
    color: #424242;
}

/* Next Move button - prominent styling */
.anim-control-btn--next {
    background: #e8f5e9;
    color: #2e7d32;
    border: 2px solid #66bb6a;
    font-weight: 600;
    padding: 0.6rem 1rem;
}

.anim-control-btn--next:hover:not(:disabled) {
    background: #c8e6c9;
    border-color: #4caf50;
    box-shadow: 0 4px 12px rgba(46, 125, 50, 0.3);
}

.anim-control-btn--next .btn-icon {
    font-size: 1.1rem;
}

/* Primary play/pause button */
.anim-control-btn--primary {
    background: #667eea;
    color: white;
    font-size: 0.9rem;
    padding: 0.6rem 1.2rem;
    border: 2px solid #5568d3;
    min-width: 80px;
    font-weight: 600;
}

.anim-control-btn--primary:hover:not(:disabled) {
    background: #5568d3;
    border-color: #4451b8;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.anim-control-btn--primary .btn-icon {
    font-size: 1.1rem;
}

/* Responsive styles for mobile devices */
@media (max-width: 1024px) {
    .animation-modal-v2__content {
        padding: 1.5rem;
        max-width: 95vw;
    }

    .animation-modal-v2__layout {
        grid-template-columns: 1fr;
        gap: 1.5rem;
        min-height: auto;
    }

    .animation-cube-container-v2 {
        height: 300px;
    }

    .anim-cube-3d {
        width: 150px;
        height: 150px;
        transform: rotateX(-20deg) rotateY(30deg) translateZ(0);
        /* Add mobile-specific will-change hints */
        will-change: transform;
        backface-visibility: hidden;
        -webkit-backface-visibility: hidden;
    }

    .anim-cube-face {
        width: 150px;
        height: 150px;
        box-shadow: 0 0 15px rgba(0, 0, 0, 0.25);
        /* Optimize for mobile GPU */
        will-change: transform;
        backface-visibility: hidden;
        -webkit-backface-visibility: hidden;
    }

    .anim-cube-face--front {
        transform: translateZ(75px);
    }

    .anim-cube-face--back {
        transform: rotateY(180deg) translateZ(75px);
    }

    .anim-cube-face--right {
        transform: rotateY(90deg) translateZ(75px);
    }

    .anim-cube-face--left {
        transform: rotateY(-90deg) translateZ(75px);
    }

    .anim-cube-face--top {
        transform: rotateX(90deg) translateZ(75px);
    }

    .anim-cube-face--bottom {
        transform: rotateX(-90deg) translateZ(75px);
    }

    .animation-modal-v2__moves {
        max-height: 200px;
    }

    /* Mobile-specific optimizations for stickers */
    .anim-cube-sticker {
        /* Mobile-specific will-change for stickers */
        will-change: background-color;
    }
}

@media (max-width: 768px) {
    .animation-modal-v2__content {
        padding: 1rem;
        border-radius: 12px;
    }

    .animation-modal-v2__close {
        top: 0.25rem;
        right: 0.25rem;
        font-size: 1.25rem;
        width: 28px;
        height: 28px;
    }

    .animation-modal-v2__solution h3 {
        font-size: 1.25rem;
    }

    .animation-modal-v2__moves {
        padding: 0.75rem;
        font-size: 0.9rem;
    }

    .animation-modal-v2__moves .move {
        padding: 0.25rem 0.5rem;
        font-size: 0.9rem;
    }

    .animation-cube-container-v2 {
        height: 250px;
    }

    .anim-cube-3d {
        width: 120px;
        height: 120px;
        transform: rotateX(-20deg) rotateY(30deg) translateZ(0);
        /* Enhanced mobile GPU hints */
        will-change: transform;
        backface-visibility: hidden;
        -webkit-backface-visibility: hidden;
        -webkit-transform: rotateX(-20deg) rotateY(30deg) translateZ(0);
    }

    .anim-cube-face {
        width: 120px;
        height: 120px;
        gap: 2px;
        padding: 2px;
        box-shadow: 0 0 12px rgba(0, 0, 0, 0.2);
        /* Mobile GPU optimization */
        will-change: transform;
        backface-visibility: hidden;
        -webkit-backface-visibility: hidden;
    }

    .anim-cube-face--front {
        transform: translateZ(60px);
        -webkit-transform: translateZ(60px);
    }

    .anim-cube-face--back {
        transform: rotateY(180deg) translateZ(60px);
        -webkit-transform: rotateY(180deg) translateZ(60px);
    }

    .anim-cube-face--right {
        transform: rotateY(90deg) translateZ(60px);
        -webkit-transform: rotateY(90deg) translateZ(60px);
    }

    .anim-cube-face--left {
        transform: rotateY(-90deg) translateZ(60px);
        -webkit-transform: rotateY(-90deg) translateZ(60px);
    }

    .anim-cube-face--top {
        transform: rotateX(90deg) translateZ(60px);
        -webkit-transform: rotateX(90deg) translateZ(60px);
    }

    .anim-cube-face--bottom {
        transform: rotateX(-90deg) translateZ(60px);
        -webkit-transform: rotateX(-90deg) translateZ(60px);
    }

    .animation-modal-v2__controls {
        gap: 0.5rem;
        flex-wrap: wrap;
    }

    .anim-control-btn {
        padding: 0.5rem 0.7rem;
        font-size: 0.85rem;
        min-width: 38px;
        gap: 0.3rem;
    }

    .anim-control-btn .btn-icon {
        font-size: 0.95rem;
    }

    .anim-control-btn .btn-label {
        font-size: 0.7rem;
    }

    .anim-control-btn--primary {
        font-size: 0.85rem;
        padding: 0.55rem 1rem;
        min-width: 75px;
    }

    .anim-control-btn--primary .btn-icon {
        font-size: 1rem;
    }

    .anim-control-btn--next {
        padding: 0.55rem 0.9rem;
    }

    .anim-control-btn--next .btn-icon {
        font-size: 1rem;
    }

    .anim-control-btn--reset {
        padding: 0.55rem 0.9rem;
    }

    .anim-control-btn--reset .btn-icon {
        font-size: 1rem;
    }

    /* Mobile-specific optimizations */
    .anim-cube-sticker {
        /* Mobile-specific will-change */
        will-change: background-color;
    }
}

@media (max-width: 480px) {
    .animation-modal-v2__layout {
        gap: 1rem;
    }

    .animation-cube-container-v2 {
        height: 200px;
    }

    .anim-cube-3d {
        width: 100px;
        height: 100px;
        transform: rotateX(-20deg) rotateY(30deg) translateZ(0);
        /* Maximum mobile optimization */
        will-change: transform;
        backface-visibility: hidden;
        -webkit-backface-visibility: hidden;
        -webkit-transform: rotateX(-20deg) rotateY(30deg) translateZ(0);
        /* Disable floating animation on small screens */
        animation: none;
    }

    .anim-cube-face {
        width: 100px;
        height: 100px;
        box-shadow: 0 0 10px rgba(0, 0, 0, 0.15);
        /* Small screen GPU optimization */
        will-change: transform;
        backface-visibility: hidden;
        -webkit-backface-visibility: hidden;
    }

    .anim-cube-face--front {
        transform: translateZ(50px);
        -webkit-transform: translateZ(50px);
    }

    .anim-cube-face--back {
        transform: rotateY(180deg) translateZ(50px);
        -webkit-transform: rotateY(180deg) translateZ(50px);
    }

    .anim-cube-face--right {
        transform: rotateY(90deg) translateZ(50px);
        -webkit-transform: rotateY(90deg) translateZ(50px);
    }

    .anim-cube-face--left {
        transform: rotateY(-90deg) translateZ(50px);
        -webkit-transform: rotateY(-90deg) translateZ(50px);
    }

    .anim-cube-face--top {
        transform: rotateX(90deg) translateZ(50px);
        -webkit-transform: rotateX(90deg) translateZ(50px);
    }

    .anim-cube-face--bottom {
        transform: rotateX(-90deg) translateZ(50px);
        -webkit-transform: rotateX(-90deg) translateZ(50px);
    }

    .animation-modal-v2__progress {
        font-size: 0.85rem;
        padding: 0.5rem 0.75rem;
    }

    /* Minimal optimizations on small mobile devices */
    .anim-cube-sticker {
        /* Minimal will-change on small screens */
        will-change: background-color;
    }
}

/* ===================================
   Reduced Motion Support
   =================================== */

@media (prefers-reduced-motion: reduce) {
    /* Disable floating animation for reduced motion */
    .anim-cube-3d {
        animation: none !important;
    }

    /* Reduce all animation durations to 100ms */
    .animation-modal-v2__backdrop {
        transition-duration: 100ms;
    }

    .animation-modal-v2__content {
        transition-duration: 100ms;
    }

    .animation-modal-v2__close {
        transition-duration: 100ms;
    }

    .animation-modal-v2__moves .move {
        transition-duration: 100ms;
    }

    .anim-control-btn {
        transition-duration: 100ms;
    }

    /* Reduce face rotation animation durations */
    .anim-cube-face--front.rotating-cw,
    .anim-cube-face--front.rotating-ccw,
    .anim-cube-face--back.rotating-cw,
    .anim-cube-face--back.rotating-ccw,
    .anim-cube-face--right.rotating-cw,
    .anim-cube-face--right.rotating-ccw,
    .anim-cube-face--left.rotating-cw,
    .anim-cube-face--left.rotating-ccw,
    .anim-cube-face--top.rotating-cw,
    .anim-cube-face--top.rotating-ccw,
    .anim-cube-face--bottom.rotating-cw,
    .anim-cube-face--bottom.rotating-ccw {
        animation-duration: 100ms;
    }

    /* Reduce sticker transition durations */
    .anim-cube-sticker {
        transition-duration: 100ms;
    }

    /* Disable floating animation keyframes */
    @keyframes cubeFloat {
        0%, 100% {
            transform: rotateX(-20deg) rotateY(30deg) translateZ(0) translateY(0);
        }
        50% {
            transform: rotateX(-20deg) rotateY(30deg) translateZ(0) translateY(0);
        }
    }
}
