/* ==========================================
   CSS Variables & Root Styles
   ========================================== */
:root {
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --secondary-gradient: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    --success-gradient: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
    --warning-gradient: linear-gradient(135deg, #f2994a 0%, #f2c94c 100%);
    --danger-gradient: linear-gradient(135deg, #eb3349 0%, #f45c43 100%);

    --primary-color: #667eea;
    --secondary-color: #764ba2;
    --accent-color: #f093fb;
    --success-color: #38ef7d;
    --warning-color: #f2c94c;
    --danger-color: #f45c43;

    --bg-light: #f8f9ff;
    --bg-card: #ffffff;
    --text-dark: #2d3748;
    --text-light: #718096;
    --text-white: #ffffff;

    --shadow-sm: 0 2px 8px rgba(102, 126, 234, 0.15);
    --shadow-md: 0 4px 20px rgba(102, 126, 234, 0.2);
    --shadow-lg: 0 10px 40px rgba(102, 126, 234, 0.3);
    --shadow-glow: 0 0 30px rgba(102, 126, 234, 0.4);

    --border-radius-sm: 8px;
    --border-radius-md: 12px;
    --border-radius-lg: 20px;
    --border-radius-xl: 30px;

    --transition-fast: 0.2s ease;
    --transition-normal: 0.3s ease;
    --transition-slow: 0.5s ease;

    --font-family: "Fredoka", "Segoe UI", system-ui, sans-serif;
}

/* ==========================================
   Reset & Base Styles
   ========================================== */
* {
    padding: 0;
    margin: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family);
    background: var(--bg-light);
    background-image: radial-gradient(
            circle at 20% 80%,
            rgba(102, 126, 234, 0.1) 0%,
            transparent 50%
        ),
        radial-gradient(
            circle at 80% 20%,
            rgba(240, 147, 251, 0.1) 0%,
            transparent 50%
        );
    min-height: 100vh;
    color: var(--text-dark);
    overflow-x: hidden;
}

/* ==========================================
   Header Styles
   ========================================== */
header {
    background: var(--primary-gradient);
    padding: 1.5rem 2rem;
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}

header::before {
    content: "";
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(
        circle,
        rgba(255, 255, 255, 0.1) 0%,
        transparent 60%
    );
    animation: shimmer 15s infinite linear;
}

@keyframes shimmer {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

.header-content {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

header h1 {
    color: var(--text-white);
    font-size: 2.5rem;
    font-weight: 700;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
    animation: bounceIn 0.8s ease-out;
}

@keyframes bounceIn {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }
    60% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.tagline {
    color: rgba(255, 255, 255, 0.9);
    font-size: 1.1rem;
    font-weight: 500;
    letter-spacing: 1px;
}

.guide-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.4);
    color: var(--text-white);
    padding: 0.6rem 1.2rem;
    border-radius: var(--border-radius-xl);
    cursor: pointer;
    font-family: var(--font-family);
    font-size: 0.95rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: var(--transition-normal);
    margin-top: 0.5rem;
}

.guide-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.guide-icon {
    font-size: 1.1rem;
}

/* ==========================================
   Main Section Layout
   ========================================== */
#allSection {
    display: flex;
    min-height: calc(100vh - 180px);
    padding: 1.5rem;
    gap: 1.5rem;
}

#leftSection,
#rightSection {
    background: var(--bg-card);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

#leftSection {
    width: 400px;
    min-width: 400px;
    display: flex;
    flex-direction: column;
}

#rightSection {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #f5f7fa 0%, #e4e8f0 100%);
    position: relative;
}

#rightSection::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image: radial-gradient(
            circle at 30% 30%,
            rgba(102, 126, 234, 0.05) 0%,
            transparent 50%
        ),
        radial-gradient(
            circle at 70% 70%,
            rgba(240, 147, 251, 0.05) 0%,
            transparent 50%
        );
}

/* ==========================================
   Puzzle Board Styles
   ========================================== */
#checkBoardId {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    position: relative;
    z-index: 1;
}

.puzzleBoard {
    background: var(--bg-card);
    border-radius: var(--border-radius-lg);
    padding: 1rem;
    box-shadow: var(--shadow-lg);
    animation: boardAppear 0.5s ease-out;
    max-width: 500px;
    width: 100%;
    aspect-ratio: 1;
}

@keyframes boardAppear {
    0% {
        transform: scale(0.8) rotate(-5deg);
        opacity: 0;
    }
    100% {
        transform: scale(1) rotate(0);
        opacity: 1;
    }
}

.board-appear {
    animation: boardAppear 0.5s ease-out;
}

#puzzleTable {
    width: 100%;
    height: 100%;
    table-layout: fixed;
    border-collapse: separate;
    border-spacing: 6px;
}

.filledType,
.emptyTile {
    text-align: center;
    vertical-align: middle;
    border-radius: var(--border-radius-md);
    font-weight: 700;
    font-size: clamp(1.5rem, 4vw, 2.5rem);
    transition: var(--transition-normal);
    position: relative;
    overflow: hidden;
}

.filledType {
    background: var(--primary-gradient);
    color: var(--text-white);
    cursor: pointer;
    box-shadow: 0 4px 0 rgba(102, 126, 234, 0.5),
        0 6px 20px rgba(102, 126, 234, 0.3);
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2);
}

.filledType::before {
    content: "";
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.3),
        transparent
    );
    transition: var(--transition-slow);
}

.filledType:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 0 rgba(102, 126, 234, 0.4),
        0 12px 30px rgba(102, 126, 234, 0.4);
}

.filledType:hover::before {
    left: 100%;
}

.filledType:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 rgba(102, 126, 234, 0.5),
        0 4px 10px rgba(102, 126, 234, 0.3);
}

.emptyTile {
    background: linear-gradient(135deg, #e8eaf6 0%, #c5cae9 100%);
    box-shadow: inset 0 4px 10px rgba(0, 0, 0, 0.1);
}

/* ==========================================
   Tile Movement Animations
   ========================================== */
.tile-pop {
    animation: tilePop 0.2s ease-out;
}

@keyframes tilePop {
    0% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.tile-move {
    animation: tileMove 0.15s ease-out;
}

@keyframes tileMove {
    0% {
        transform: scale(1);
    }
    100% {
        transform: scale(0.9);
        opacity: 0.5;
    }
}

/* ==========================================
   Welcome Message
   ========================================== */
.welcome-message {
    text-align: center;
    padding: 3rem;
    animation: fadeInUp 0.6s ease-out;
}

@keyframes fadeInUp {
    0% {
        transform: translateY(30px);
        opacity: 0;
    }
    100% {
        transform: translateY(0);
        opacity: 1;
    }
}

.welcome-icon {
    font-size: 5rem;
    margin-bottom: 1rem;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%,
    100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-15px);
    }
}

.welcome-message h2 {
    font-size: 2rem;
    color: var(--text-dark);
    margin-bottom: 0.5rem;
}

.welcome-message p {
    color: var(--text-light);
    font-size: 1.1rem;
    margin-bottom: 1.5rem;
}

.difficulty-badges {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
}

.badge {
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius-xl);
    font-size: 0.85rem;
    font-weight: 600;
}

.badge.easy {
    background: var(--success-gradient);
    color: var(--text-white);
}

.badge.medium {
    background: var(--warning-gradient);
    color: var(--text-dark);
}

.badge.hard {
    background: var(--danger-gradient);
    color: var(--text-white);
}

/* ==========================================
   Shake Animation for Wrong Moves
   ========================================== */
@keyframes shake {
    0%,
    100% {
        transform: translateX(0);
    }
    10%,
    30%,
    50%,
    70%,
    90% {
        transform: translateX(-8px);
    }
    20%,
    40%,
    60%,
    80% {
        transform: translateX(8px);
    }
}

.shake {
    animation: shake 0.5s ease-in-out;
}

/* ==========================================
   Confetti Animation
   ========================================== */
.confetti-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
    overflow: hidden;
}

.confetti {
    position: absolute;
    width: 12px;
    height: 12px;
    top: -20px;
    animation: confettiFall linear forwards;
}

@keyframes confettiFall {
    0% {
        transform: translateY(0) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(100vh) rotate(720deg);
        opacity: 0;
    }
}

/* ==========================================
   Footer Styles
   ========================================== */
footer {
    background: var(--primary-gradient);
    padding: 1.5rem;
    text-align: center;
    color: var(--text-white);
    font-size: 1rem;
}

footer p {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

footer strong {
    font-weight: 600;
}

/* ==========================================
   Modal Styles
   ========================================== */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    opacity: 0;
    transition: opacity var(--transition-normal);
}

.modal.show {
    display: flex;
    opacity: 1;
}

.modal-content {
    background: var(--bg-card);
    border-radius: var(--border-radius-lg);
    max-width: 550px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    padding: 2rem;
    position: relative;
    box-shadow: var(--shadow-lg);
    animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
    0% {
        transform: translateY(-50px) scale(0.9);
        opacity: 0;
    }
    100% {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

.close-modal {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    font-size: 2rem;
    color: var(--text-light);
    cursor: pointer;
    transition: var(--transition-fast);
    line-height: 1;
}

.close-modal:hover {
    color: var(--danger-color);
    transform: rotate(90deg);
}

.modal-content h2 {
    font-size: 1.8rem;
    color: var(--text-dark);
    margin-bottom: 1.5rem;
    text-align: center;
}

.guide-section {
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.guide-section:last-of-type {
    border-bottom: none;
}

.guide-section h3 {
    font-size: 1.2rem;
    color: var(--primary-color);
    margin-bottom: 0.75rem;
}

.guide-section p,
.guide-section li {
    color: var(--text-dark);
    line-height: 1.6;
}

.guide-section ul {
    padding-left: 1.5rem;
}

.guide-section li {
    margin-bottom: 0.5rem;
}

.difficulty-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.difficulty-item {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.difficulty-item .badge {
    min-width: 60px;
    text-align: center;
}

.goal-example {
    text-align: center;
}

.example-grid {
    display: grid;
    grid-template-columns: repeat(3, 50px);
    gap: 5px;
    justify-content: center;
    margin-top: 1rem;
}

.example-grid span {
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-gradient);
    color: var(--text-white);
    font-weight: 700;
    font-size: 1.2rem;
    border-radius: var(--border-radius-sm);
}

.example-grid .empty {
    background: linear-gradient(135deg, #e8eaf6 0%, #c5cae9 100%);
}

.start-playing-btn {
    width: 100%;
    margin-top: 1rem;
}

/* ==========================================
   Responsive Design
   ========================================== */
@media (max-width: 900px) {
    #allSection {
        flex-direction: column;
    }

    #leftSection {
        width: 100%;
        min-width: auto;
    }

    #rightSection {
        min-height: 400px;
    }
}

@media (max-width: 480px) {
    header h1 {
        font-size: 1.8rem;
    }

    .modal-content {
        padding: 1.5rem;
    }

    .example-grid {
        grid-template-columns: repeat(3, 40px);
    }

    .example-grid span {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }
}
