/* Global Settings & Variables */
:root {
    /* Fun, Vibrant Palette */
    --color-bg: #f4f6f9;
    --color-text: #2c3e50;
    --color-white: #ffffff;

    --color-games: #4facfe;
    /* Blue */
    --color-games-dark: #00f2fe;

    --color-stories: #ff8177;
    /* Orange/Red */
    --color-stories-dark: #ff867a;

    --color-math: #43e97b;
    /* Green */
    --color-math-dark: #38f9d7;

    --color-art: #f78ca0;
    /* Pink */
    --color-art-dark: #fe9a8b;

    --color-islam: #a18cd1;
    /* Purple */
    --color-islam-dark: #fbc2eb;

    --color-quiz: #f6d365;
    /* Yellow */
    --color-quiz-dark: #fda085;

    --font-english: 'Fredoka', sans-serif;
    /* Custom Font */
    --font-dhivehi: 'MVTypewriter', 'MV Boli', 'Faruma', 'Noto Sans Thaana', sans-serif;

    --shadow-soft: 0 10px 20px rgba(0, 0, 0, 0.05);
    --shadow-hover: 0 15px 30px rgba(0, 0, 0, 0.15);

    --radius-l: 25px;
    --radius-m: 15px;
}

@font-face {
    font-family: 'MVTypewriter';
    src: url('../assets/MVTypewriter-Regular.otf') format('opentype');
    font-weight: normal;
    font-style: normal;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--color-bg);
    font-family: var(--font-dhivehi);
    color: var(--color-text);
    /* RTL Direction for Dhivehi */
    direction: rtl;
    padding-bottom: 80px;
    /* Space for bottom nav */
}

/* Header */
.main-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    background: var(--color-white);
    border-bottom-left-radius: var(--radius-l);
    border-bottom-right-radius: var(--radius-l);
    box-shadow: var(--shadow-soft);
    position: sticky;
    top: 0;
    z-index: 100;
}

.logo-container h1 {
    color: #4CAF50;
    /* Brand green */
    font-size: 2.5rem;
    margin-bottom: 5px;
}

.logo-container p {
    font-size: 0.9rem;
    color: #888;
}

.search-bar {
    display: flex;
    background: #f0f0f0;
    padding: 5px 15px;
    border-radius: 50px;
    align-items: center;
}

.search-bar input {
    border: none;
    background: transparent;
    padding: 10px;
    font-family: var(--font-dhivehi);
    outline: none;
    width: 150px;
}

.search-bar button {
    border: none;
    background: transparent;
    color: #888;
    cursor: pointer;
    font-size: 1.2rem;
}

/* Main Grid */
.content-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    padding: 20px;
    max-width: 1200px;
    margin: 0 auto;
}

/* Card Styles */
.card {
    background: var(--color-white);
    border-radius: var(--radius-l);
    padding: 25px;
    text-align: center;
    position: relative;
    overflow: hidden;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    box-shadow: var(--shadow-soft);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    cursor: pointer;
}

.card:hover {
    transform: translateY(-5px) scale(1.02);
    box-shadow: var(--shadow-hover);
}

.card-icon {
    font-size: 3rem;
    width: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: white;
    margin-bottom: 10px;
}

.card h2 {
    font-size: 1.8rem;
    margin-bottom: 5px;
}

.card p {
    font-size: 1rem;
    opacity: 0.8;
    margin-bottom: 15px;
}

.card-btn {
    margin-top: auto;
    /* Push to bottom */
    border: none;
    padding: 10px 25px;
    border-radius: 50px;
    color: white;
    font-family: var(--font-dhivehi);
    font-weight: bold;
    font-size: 1rem;
    background: rgba(0, 0, 0, 0.1);
    /* Subtle generic bg, specific colors below */
    cursor: pointer;
    transition: background 0.2s;
}

.card-btn:hover {
    background: rgba(0, 0, 0, 0.2);
}

/* Specific Card Themes */
/* Games */
.card-games .card-icon {
    background: linear-gradient(135deg, var(--color-games), var(--color-games-dark));
}

.card-games h2 {
    color: #0099cc;
}

.card-games .card-btn {
    background: var(--color-games);
}

/* Stories */
.card-stories .card-icon {
    background: linear-gradient(135deg, var(--color-stories), var(--color-stories-dark));
}

.card-stories h2 {
    color: #ff5722;
}

.card-stories .card-btn {
    background: var(--color-stories);
}

/* Math */
.card-math .card-icon {
    background: linear-gradient(135deg, var(--color-math), var(--color-math-dark));
}

.card-math h2 {
    color: #2ecc71;
}

.card-math .card-btn {
    background: var(--color-math);
}

/* Art */
.card-art .card-icon {
    background: linear-gradient(135deg, var(--color-art), var(--color-art-dark));
}

.card-art h2 {
    color: #e91e63;
}

.card-art .card-btn {
    background: var(--color-art);
}

/* Islam */
.card-islam .card-icon {
    background: linear-gradient(135deg, var(--color-islam), var(--color-islam-dark));
}

.card-islam h2 {
    color: #9c27b0;
}

.card-islam .card-btn {
    background: var(--color-islam);
}

/* Quiz */
.card-quiz .card-icon {
    background: linear-gradient(135deg, var(--color-quiz), var(--color-quiz-dark));
}

.card-quiz h2 {
    color: #f39c12;
}

.card-quiz .card-btn {
    background: var(--color-quiz);
}


/* Bottom Navigation - Glassmorphism */
.bottom-nav {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(50%);
    /* Start at center to center it */
    width: 90%;
    max-width: 500px;
    background: rgba(255, 255, 255, 0.85);
    /* Proper rgba for semi-transparency */
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: 50px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    display: flex;
    justify-content: space-around;
    padding: 15px;
    z-index: 1000;
    border: 1px solid rgba(255, 255, 255, 0.5);
    /* Correct RTL transform issue: */
    /* In RTL, left: 50% puts it far right. We need to reset and center properly */
}

/* Fix centering for RTL */
@media screen and (min-width: 0) {
    .bottom-nav {
        /* Reset left/right logic for centering */
        right: 50%;
        left: auto;
        transform: translateX(50%);
    }
}

.nav-item {
    text-decoration: none;
    color: #888;
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 0.8rem;
    gap: 5px;
    transition: color 0.3s, transform 0.3s;
}

.nav-item i {
    font-size: 1.4rem;
}

.nav-item.active,
.nav-item:hover {
    color: #4CAF50;
    /* Brand color */
    transform: translateY(-3px);
}

/* Animation Utilities */
@keyframes bounce {

    0%,
    20%,
    50%,
    80%,
    100% {
        transform: translateY(0);
    }

    40% {
        transform: translateY(-10px);
    }

    60% {
        transform: translateY(-5px);
    }
}

.hover-bounce:hover {
    animation: bounce 1s;
}

/* Responsive tweaks */
@media (max-width: 600px) {
    .content-grid {
        grid-template-columns: 1fr;
        /* Single column on mobile */
    }

    .card {
        flex-direction: row;
        /* Horizontal cards on mobile? Or stick to vertical? */
        /* Let's keep vertical for consistency, maybe row looks cleaner list style. */
        /* Switching to row for mobile to look closer to a list can be nice, but grid is funner. */
        text-align: right;
        align-items: center;
    }

    .card-icon {
        width: 60px;
        height: 60px;
        font-size: 1.8rem;
        margin-bottom: 0;
        margin-left: 15px;
        /* Spacing for RTL */
    }

    .card-content {
        flex: 1;
    }

    .card-btn {
        padding: 5px 15px;
        font-size: 0.8rem;
    }

    .logo-container h1 {
        font-size: 1.8rem;
    }

    .search-bar input {
        width: 100px;
    }
}

/* Utility */
.hidden {
    display: none !important;
}

/* Game Section */
.game-view {
    padding: 20px;
    max-width: 800px;
    margin: 0 auto;
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    background: white;
    padding: 15px;
    border-radius: var(--radius-m);
    box-shadow: var(--shadow-soft);
}

.back-btn {
    background: none;
    border: none;
    font-family: var(--font-dhivehi);
    font-size: 1rem;
    cursor: pointer;
    color: var(--color-text);
}

.score-board {
    display: flex;
    gap: 15px;
    font-size: 1.1rem;
}

/* Memory Board */
.memory-game-board {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    perspective: 1000px;
}

.memory-card {
    height: 120px;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.5s;
    cursor: pointer;
    border-radius: var(--radius-m);
}

.memory-card:active {
    transform: scale(0.97);
    transition: transform 0.2s;
}

.memory-card.flip {
    transform: rotateY(180deg);
}

.front-face,
.back-face {
    width: 100%;
    height: 100%;
    padding: 10px;
    position: absolute;
    border-radius: var(--radius-m);
    background: white;
    display: flex;
    justify-content: center;
    align-items: center;
    backface-visibility: hidden;
    box-shadow: var(--shadow-soft);
    font-size: 3rem;
}

.front-face {
    transform: rotateY(180deg);
    background: white;
    color: var(--color-games);
    border: 3px solid var(--color-games);
}

.back-face {
    background: var(--color-games);
    /* Blue back for games */
    color: white;
    font-size: 2rem;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.modal-content {
    background: white;
    padding: 40px;
    border-radius: var(--radius-l);
    text-align: center;
    animation: bounce 0.5s;
}

@media (max-width: 600px) {
    .memory-game-board {
        grid-template-columns: repeat(3, 1fr);
        /* 3 cols on mobile? or 4 but smaller? */
        gap: 10px;
    }

    .memory-card {
        height: 80px;
    }
}

/* --- New Sections CSS --- */

/* Stories */
.stories-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
}

.story-card {
    background: white;
    border-radius: var(--radius-m);
    box-shadow: var(--shadow-soft);
    padding: 15px;
    text-align: center;
    transition: transform 0.3s;
}

.story-card:hover {
    transform: translateY(-5px);
}

.story-cover {
    height: 150px;
    border-radius: var(--radius-m);
    margin-bottom: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 3rem;
    color: white;
}

.small-btn {
    padding: 5px 15px;
    font-size: 0.9rem;
    margin-top: 10px;
}

/* Math */
.math-container {
    display: flex;
    justify-content: center;
    padding: 20px 0;
}

.question-card {
    background: white;
    padding: 40px;
    border-radius: var(--radius-l);
    box-shadow: var(--shadow-soft);
    text-align: center;
    width: 100%;
    max-width: 500px;
}

.question-card h1 {
    font-size: 4rem;
    margin-bottom: 30px;
    color: var(--color-math);
    font-family: var(--font-english);
    /* Numbers look better in English font */
}

.options-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
}

.option-btn {
    padding: 20px;
    font-size: 2rem;
    border: 2px solid #eee;
    background: white;
    border-radius: var(--radius-m);
    cursor: pointer;
    font-family: var(--font-english);
    color: var(--color-text);
    transition: all 0.2s;
}

.option-btn:hover {
    background: #f0f0f0;
    transform: scale(1.05);
}

.option-btn.correct {
    background: var(--color-math);
    color: white;
    border-color: var(--color-math);
}

.option-btn.wrong {
    background: var(--color-stories);
    color: white;
    border-color: var(--color-stories);
}

.feedback-msg {
    margin-top: 20px;
    font-size: 1.2rem;
    min-height: 1.5em;
}

/* Art Canvas */
.canvas-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

canvas {
    background: white;
    border-radius: var(--radius-m);
    box-shadow: var(--shadow-soft);
    cursor: crosshair;
    touch-action: none;
    /* Prevent scrolling while drawing */
    max-width: 100%;
}

.color-palette {
    display: flex;
    gap: 10px;
    background: white;
    padding: 10px;
    border-radius: 50px;
    box-shadow: var(--shadow-soft);
}

.color-swatch {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.2s;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2rem;
}

.color-swatch:hover,
.color-swatch.active {
    transform: scale(1.2);
    border: 3px solid #ccc;
}

.tool-btn {
    background: #eee;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    color: #555;
    font-size: 1.2rem;
}

.tool-btn:hover {
    background: #ddd;
}


/* Lists (Islam) */
.list-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.list-item {
    background: white;
    padding: 20px;
    border-radius: var(--radius-m);
    display: flex;
    align-items: center;
    gap: 20px;
    box-shadow: var(--shadow-soft);
}

.list-item .icon-box {
    width: 60px;
    height: 60px;
    background: var(--color-islam-dark);
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
    color: white;
    font-size: 1.5rem;
    flex-shrink: 0;
}

.list-item h3 {
    margin-bottom: 5px;
    color: var(--color-islam);
}

.list-item p {
    color: #666;
    font-family: var(--font-dhivehi);
}

.arabic-text {
    font-family: 'Amiri', 'Traditional Arabic', serif;
    font-size: 1.8rem;
    color: #2c3e50;
    margin: 10px 0;
    direction: rtl;
    line-height: 1.6;
}

/* Reader Modal */
.reader-content {
    width: 90%;
    max-width: 600px;
    height: 80vh;
    overflow-y: auto;
    position: relative;
    text-align: right;
    /* RTL */
    padding-top: 50px;
}

.close-btn {
    position: absolute;
    top: 15px;
    left: 15px;
    /* Left for RTL alignment usually, or Right? Let's use Left for 'X' */
    font-size: 2rem;
    background: none;
    border: none;
    cursor: pointer;
    color: #aaa;
}

.story-text-body {
    font-size: 1.3rem;
    line-height: 2;
    color: #444;
    white-space: pre-line;
}

/* Writing/Tracing */
.card-writing .card-icon {
    background: linear-gradient(135deg, #00BCD4, #0097A7);
}

.card-writing h2 {
    color: #0097A7;
}

.card-writing .card-btn {
    background: #00BCD4;
}

.tracing-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.letter-selector {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.letter-btn {
    width: 50px;
    height: 50px;
    font-family: var(--font-dhivehi);
    font-size: 1.5rem;
    border: 2px solid #ddd;
    background: white;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
}

.letter-btn.active,
.letter-btn:hover {
    background: #00BCD4;
    color: white;
    transform: scale(1.1);
    border-color: #00BCD4;
}

.canvas-wrapper {
    position: relative;
    width: 300px;
    height: 300px;
    background: white;
    border-radius: var(--radius-l);
    box-shadow: var(--shadow-soft);
    overflow: hidden;
}

.trace-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -55%);
    /* Fine tune center */
    font-family: var(--font-dhivehi);
    font-size: 180px;
    color: #e0e0e0;
    pointer-events: none;
    /* Let clicks pass to canvas */
    z-index: 1;
}

#tracing-canvas {
    position: relative;
    z-index: 2;
    background: transparent;
    /* Important for overlay visibility */
    width: 100%;
    height: 100%;
}

/* Balloon & Shapes Cards */
.card-balloon .card-icon {
    background: linear-gradient(135deg, #ff5252, #d32f2f);
}

.card-balloon h2 {
    color: #d32f2f;
}

.card-balloon .card-btn {
    background: #ff5252;
}

.card-shapes .card-icon {
    background: linear-gradient(135deg, #3f51b5, #303f9f);
}

.card-shapes h2 {
    color: #303f9f;
}

.card-shapes .card-btn {
    background: #3f51b5;
}

/* Shape Match Game */
.shape-game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 40px;
    padding: 20px;
}

.shape-sources,
.shape-targets {
    display: flex;
    gap: 20px;
    justify-content: center;
}

.draggable-shape,
.drop-zone {
    width: 80px;
    height: 80px;
}

.draggable-shape {
    cursor: grab;
    transition: transform 0.2s;
}

.draggable-shape:active {
    cursor: grabbing;
    transform: scale(1.1);
}

.drop-zone {
    border: 3px dashed #ccc;
    background: #f0f0f0;
    opacity: 0.7;
}

/* Shapes */
.circle,
.circle-zone {
    border-radius: 50%;
}

.square,
.square-zone {
    border-radius: 10px;
}

.triangle,
.triangle-zone {
    width: 0;
    height: 0;
    border-left: 40px solid transparent;
    border-right: 40px solid transparent;
    border-bottom: 80px solid;
    background: transparent;
}

.draggable-shape.circle {
    background: #e91e63;
}

.draggable-shape.square {
    background: #2196f3;
}

.draggable-shape.triangle {
    border-bottom-color: #ff9800;
}

.drop-zone.circle-zone.correct {
    background: #e91e63;
    border-style: solid;
    opacity: 1;
}

.drop-zone.square-zone.correct {
    background: #2196f3;
    border-style: solid;
    opacity: 1;
}

.drop-zone.triangle-zone.correct {
    border-bottom-color: #ff9800;
    border-style: solid;
    opacity: 1;
    background: transparent;
}

/* Note: Triangle drop zone styling with borders is tricky for background fills, keeping simple */

/* Story Reader Controls */
.reader-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 20px;
    padding: 0 20px;
}

.nav-btn {
    background: #eee;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2rem;
    color: #555;
    transition: background 0.2s;
}

.nav-btn:hover {
    background: #ddd;
}