/* Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@300;400;600;700&family=Poppins:wght@300;400;600&display=swap');

:root {
    --primary-color: #4A90E2;
    --secondary-color: #F5A623;
    --background-color: #F4F7F6;
    --text-color: #333;
    --grid-bg: #fff;
    --grid-border: #ddd;
    --grid-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    --grid-cell-size: 40px;
    --grid-gap: 2px;
    --blocked-cell: #2C3E50;
    --success-color: #2ECC71;
    --error-color: #E74C3C;
    --font-en: 'Poppins', sans-serif;
    --font-ar: 'Cairo', sans-serif;
}

/* --- THEMES --- */

/* Classic Theme (Default) */
.theme-classic {
    --grid-bg: #fff;
    --grid-border: #000;
    --blocked-cell: #000;
    --text-color: #000;
    --grid-shadow: none;
}

.theme-classic .crossword-cell {
    border: 1px solid #000;
    box-shadow: none;
    border-radius: 0;
}

.theme-classic .crossword-cell.blocked {
    background-color: #000;
    border-color: #000;
}

.theme-classic .grid-container {
    background: #fff;
    border: 2px solid #000;
    box-shadow: none;
    border-radius: 0;
}

/* Modern Theme - gradients and soft colors */
.theme-modern {
    --primary-color: #6C5CE7;
    --secondary-color: #00CEC9;
    --background-color: #dfe6e9;
    --grid-bg: #fff;
    --blocked-cell: #b2bec3;
    --grid-shadow: 0 8px 15px rgba(108, 92, 231, 0.2);
    --grid-border: #a29bfe;
}

.theme-modern .crossword-cell.blocked {
    background: linear-gradient(135deg, #b2bec3 0%, #636e72 100%);
    border-color: transparent;
}

/* Kids Theme - Fun colors and Emojis */
.theme-kids {
    --primary-color: #FF7675;
    --secondary-color: #FDCB6E;
    --background-color: #FFEAA7;
    --grid-bg: #fff;
    --blocked-cell: #FFD32A;
    /* Fallback */
    --font-en: 'Comic Sans MS', 'Chalkboard SE', sans-serif;
    /* Playful font */
}

.theme-kids .crossword-cell.blocked {
    background-color: #FFD32A;
    /* Use the requested logo image */
    background-image: url('../img/Your-Logo.png');
    background-repeat: no-repeat;
    background-position: center;
    background-size: 80%;
    /* Adjust size as needed */
    border-color: #FAB1A0;
}

/* Dark Theme - Sleek and high contrast */
.theme-dark {
    --primary-color: #0984e3;
    --secondary-color: #00b894;
    --background-color: #2d3436;
    --text-color: #dfe6e9;
    --grid-bg: #636e72;
    --grid-border: #2d3436;
    --blocked-cell: #000;
}

.theme-dark .crossword-cell {
    color: #fff;
    border-color: #2d3436;
}

.theme-dark .crossword-cell input {
    color: #fff;
}

.theme-dark .clues-container {
    background: #636e72;
    color: #fff;
}

.theme-dark .clue-item:hover {
    background: #535c68;
}

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

body {
    font-family: var(--font-en);
    background-color: var(--background-color);
    color: var(--text-color);
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: background-color 0.3s ease;
}

/* RTL Support */
body.rtl {
    font-family: var(--font-ar);
    direction: rtl;
    text-align: right;
}

.rtl .form-group {
    text-align: right;
}

/* Container */
.container {
    width: 90%;
    max-width: 1200px;
    margin: 2rem auto;
    padding: 2rem;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.05);
}

/* Header */
header {
    text-align: center;
    margin-bottom: 2rem;
}

h1 {
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

/* Login Form */
.login-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-box {
    background: white;
    padding: 2.5rem;
    border-radius: 10px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.form-group {
    margin-bottom: 1.5rem;
    text-align: left;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: #555;
    font-size: 0.9rem;
}

.form-control {
    /*  width: 100%; */
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-family: inherit;
    transition: border-color 0.3s;
}

.form-control:focus {
    border-color: var(--primary-color);
    outline: none;
}

.btn {
    display: inline-block;
    padding: 12px 24px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    transition: transform 0.2s, box-shadow 0.2s;
    font-family: inherit;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(74, 144, 226, 0.3);
}

.btn-secondary {
    background-color: var(--secondary-color);
}

.btn-secondary:hover {
    box-shadow: 0 5px 15px rgba(245, 166, 35, 0.3);
}

.btn-danger {
    background-color: var(--error-color);
}

.btn-success {
    background-color: var(--success-color);
}

/* Admin Panel - Grid Setup */
.admin-controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
    padding: 1.5rem;
    background: #f8f9fa;
    border-radius: 8px;
}

/* Crossword Grid Container */
.crossword-wrapper {
    display: flex;
    flex-wrap: wrap;
    gap: 2rem;
    justify-content: center;
}

.grid-container {
    position: relative;
    padding: 30px;
    /* Space for outside labels */
    background: #eef2f5;
    border-radius: 12px;
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.05);
}

/* The actual table */
.crossword-grid {
    border-collapse: separate;
    border-spacing: var(--grid-gap);
    margin: 0 auto;
}

.crossword-cell {
    width: var(--grid-cell-size);
    height: var(--grid-cell-size);
    background: var(--grid-bg);
    border: 1px solid #ccc;
    position: relative;
    text-align: center;
    vertical-align: middle;
    font-weight: 600;
    font-size: 1.2rem;
    padding: 0;
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.1s;

    /* 3D Effect */
    box-shadow: 2px 2px 0px rgba(0, 0, 0, 0.1);
}

.crossword-cell:active,
.crossword-cell.active {
    transform: translate(1px, 1px);
    box-shadow: 1px 1px 0px rgba(0, 0, 0, 0.1);
    background-color: #e3f2fd;
    border-color: var(--primary-color);
    z-index: 10;
}

.crossword-cell input {
    width: 100%;
    height: 100%;
    border: none;
    background: transparent;
    text-align: center;
    font-size: 1.2rem;
    text-transform: uppercase;
    font-family: inherit;
    color: var(--text-color);
    outline: none;
    padding: 0;
    margin: 0;
}

.crossword-cell.blocked {
    background-color: var(--blocked-cell);
    cursor: default;
    border-color: var(--blocked-cell);
    box-shadow: none;
}

.cell-number {
    position: absolute;
    top: 2px;
    left: 2px;
    font-size: 0.6rem;
    color: #666;
    line-height: 1;
    pointer-events: none;
}

.rtl .cell-number {
    left: auto;
    right: 2px;
}

/* Outside labels (Chessboard style) */
.grid-label-row {
    position: absolute;
    left: 5px;
    width: 20px;
    text-align: center;
    font-weight: bold;
    color: #888;
    height: var(--grid-cell-size);
    /* Matches cell height */
    line-height: var(--grid-cell-size);
    font-size: 0.8rem;
}

.grid-label-col {
    position: absolute;
    top: 5px;
    width: var(--grid-cell-size);
    /* Matches cell width */
    text-align: center;
    font-weight: bold;
    color: #888;
    font-size: 0.8rem;
}

/* Clues Section */
.clues-container {
    flex: 1;
    min-width: 300px;
    padding: 1.5rem;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.clue-list {
    list-style: none;
    margin-top: 1rem;
}

.clue-item {
    padding: 0.5rem;
    border-bottom: 1px solid #eee;
    cursor: pointer;
    transition: background 0.2s;
}

.clue-item:hover {
    background: #f9f9f9;
}

.clue-item.active-clue {
    background: #e3f2fd;
    border-left: 4px solid var(--primary-color);
}

.rtl .clue-item.active-clue {
    border-left: none;
    border-right: 4px solid var(--primary-color);
}

/* Success Overlay */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    display: none;
    /* hidden by default */
    justify-content: center;
    align-items: center;
    z-index: 1000;
    flex-direction: column;
    color: white;
    text-align: center;
}

.overlay.show {
    display: flex;
    animation: fadeIn 0.5s;
}

.overlay h2 {
    font-size: 2.5rem;
    margin-bottom: 1rem;
    color: #FFD700;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}

.overlay p {
    font-size: 1.2rem;
    margin-bottom: 2rem;
}

/* Reset Modal */
.custom-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.custom-modal-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.custom-modal {
    background: white;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    text-align: center;
    max-width: 400px;
    width: 90%;
    transform: translateY(20px);
    transition: transform 0.3s;
}

.custom-modal-overlay.active .custom-modal {
    transform: translateY(0);
}

.modal-buttons {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-top: 1.5rem;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes celebrate {
    0% {
        transform: scale(0.8);
        opacity: 0;
    }

    50% {
        transform: scale(1.1);
        opacity: 1;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.celebration-box {
    animation: celebrate 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Responsive */
@media (max-width: 768px) {
    .crossword-wrapper {
        flex-direction: column;
    }

    .grid-container {
        padding: 20px;
    }

    :root {
        --grid-cell-size: 32px;
    }
}

/* Shake Animation */
@keyframes shake {
    0% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-5px) rotate(-5deg);
    }

    50% {
        transform: translateX(5px) rotate(5deg);
    }

    75% {
        transform: translateX(-5px) rotate(-5deg);
    }

    100% {
        transform: translateX(0);
    }
}

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

/* Toast */
.toast {
    visibility: hidden;
    min-width: 250px;
    background-color: #333;
    color: #fff;
    text-align: center;
    border-radius: 50px;
    padding: 16px;
    20px;
    position: fixed;
    z-index: 3000;
    left: 50%;
    bottom: 30px;
    transform: translateX(-50%);
    font-size: 1.1rem;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    opacity: 0;
    transition: opacity 0.3s, bottom 0.3s;
}

.toast.show {
    visibility: visible;
    opacity: 1;
    bottom: 80px;
}

.toast.error {
    background-color: var(--error-color);
}

.toast.success {
    background-color: var(--success-color);
}

iframe {
    display: block;
    /* iframes are inline by default, this removes default spacing */
    background: #000;
    /* Optional: sets background color while content loads */
    border: none;
    /* Removes default border */
    height: 100vh;
    /* 100% of the viewport height */
    width: 100vw;
    /* 100% of the viewport width */
}