/* =========================================
   VARIABLES & THEMING
   ========================================= */
:root {
    --primary: #5A9BFF;
    --primary-light: #8DC0FF;
    --primary-dark: #3a7eed;
    --secondary: #B983FF;
    --secondary-dark: #9747FF;
    --tertiary: #FFE066;
    --bg-color: #F8F9FE;
    --light-bg: #f8fafc;
    --card-bg: #FFFFFF;
    --text-main: #333333;
    --text-muted: #666666;
    --white: #FFFFFF;
    --success: #4cd964;
    --error: #ff5e5e;
    --border-radius: 24px;
    --border-radius-sm: 12px;
    --shadow: 0 8px 24px rgba(90, 155, 255, 0.15);
    --shadow-hover: 0 12px 32px rgba(90, 155, 255, 0.25);

    --transition-speed: 0.3s;
}

/* --- Dark Mode Variables --- */
body.dark-mode {
    --bg-color: #0f172a;
    --light-bg: #1e293b;
    --card-bg: #1e293b;
    --white: #1e293b;
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --primary-dark: #60a5fa;
    --primary-light: #1d4ed8;
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

* {
    transition: background-color var(--transition-speed), color var(--transition-speed), border-color var(--transition-speed), box-shadow var(--transition-speed);
}

/* =========================================
   RESET & BASICS
   ========================================= */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Nunito', sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    overflow-x: hidden;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    font-family: 'Comic Neue', cursive;
    font-weight: 700;
}

.app-container {
    max-width: 1200px;
    margin: 0 auto;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* =========================================
   HEADER / NAVIGATION
   ========================================= */
.main-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 30px;
    background: var(--white);
    border-radius: 0 0 var(--border-radius) var(--border-radius);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    margin-bottom: 20px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.logo {
    font-size: 1.8rem;
    font-family: 'Comic Neue', cursive;
    font-weight: 700;
    color: var(--primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: transform 0.2s;
}

.logo:hover {
    transform: scale(1.05) rotate(-2deg);
}

.user-stats {
    display: flex;
    gap: 20px;
    align-items: center;
}

.badges-btn {
    background: var(--secondary);
    color: white;
    padding: 8px 16px;
    border-radius: 50px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.1);
    transition: all 0.2s;
}

.badges-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 0 rgba(0, 0, 0, 0.1);
}

.badges-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 rgba(0, 0, 0, 0.1);
}

.stars-count {
    background: var(--tertiary);
    color: #cca400;
    padding: 8px 20px;
    border-radius: 50px;
    font-weight: 800;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.05);
}

/* =========================================
   VIEWS MANAGEMENT
   ========================================= */
.view {
    display: none;
    padding: 20px;
    animation: fadeIn 0.4s ease-out forwards;
}

.active-view {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* =========================================
   BUTTONS
   ========================================= */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 50px;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    font-family: 'Nunito', sans-serif;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    outline: none;
}

.btn-primary {
    background-color: var(--primary);
    color: white;
    box-shadow: 0 6px 0 var(--primary-dark);
}

.btn-primary:active {
    transform: translateY(6px);
    box-shadow: none;
}

.btn-secondary {
    background-color: #e0e0e0;
    color: #333;
    box-shadow: 0 6px 0 #bdbdbd;
}

.btn-secondary:active {
    transform: translateY(6px);
    box-shadow: none;
}

.btn-large {
    font-size: 1.4rem;
    padding: 18px 40px;
    border-radius: 100px;
}

.btn-action {
    background-color: var(--success);
    color: white;
    box-shadow: 0 6px 0 #28a745;
}

.btn-action:active {
    transform: translateY(6px);
    box-shadow: none;
}

.btn-back {
    background-color: transparent;
    color: var(--text-muted);
    padding: 5px 10px;
    margin-bottom: 20px;
}

.btn-back:hover {
    color: var(--primary);
}

/* =========================================
   HOME VIEW
   ========================================= */
.hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 40px 20px;
}

.hero-image {
    font-size: 7rem;
    color: var(--primary);
    margin-bottom: 20px;
}

.float-anim {
    animation: floating 3s ease-in-out infinite;
}

@keyframes floating {
    0% {
        transform: translateY(0px) rotate(0deg);
    }

    50% {
        transform: translateY(-20px) rotate(5deg);
    }

    100% {
        transform: translateY(0px) rotate(0deg);
    }
}

.hero h1 {
    font-size: 3.5rem;
    color: var(--primary-dark);
    margin-bottom: 10px;
}

.hero .subtitle {
    font-size: 1.5rem;
    color: var(--text-muted);
    max-width: 600px;
    margin-bottom: 40px;
}

.hero-features {
    display: flex;
    gap: 30px;
    margin-bottom: 50px;
    flex-wrap: wrap;
    justify-content: center;
}

.feature-card {
    background: white;
    padding: 30px 40px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    width: 200px;
}

.feature-card i {
    font-size: 3rem;
    color: var(--secondary);
}

.feature-card p {
    font-weight: 700;
    font-size: 1.1rem;
}

.btn-bounce {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        transform: scale(1);
        box-shadow: 0 6px 0 var(--primary-dark), 0 0 0 0 rgba(90, 155, 255, 0.7);
    }

    70% {
        transform: scale(1.05);
        box-shadow: 0 6px 0 var(--primary-dark), 0 0 0 15px rgba(90, 155, 255, 0);
    }

    100% {
        transform: scale(1);
        box-shadow: 0 6px 0 var(--primary-dark), 0 0 0 0 rgba(90, 155, 255, 0);
    }
}

/* =========================================
   LEVELS VIEW
   ========================================= */
#view-levels h2 {
    text-align: center;
    font-size: 2.5rem;
    margin-bottom: 30px;
    color: var(--text-main);
}

.levels-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 30px;
    padding: 20px;
}

.level-card {
    background: white;
    border-radius: var(--border-radius);
    padding: 30px;
    box-shadow: var(--shadow);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    cursor: pointer;
    position: relative;
    overflow: hidden;
    border: 3px solid transparent;
}

.level-card:hover {
    transform: translateY(-10px) scale(1.03);
    box-shadow: var(--shadow-hover);
}

.level-card.locked {
    opacity: 0.7;
    filter: grayscale(0.8);
    cursor: not-allowed;
}

.level-card.locked::after {
    content: "🔒";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 4rem;
    opacity: 0.8;
}

.level-icon {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    color: white;
    margin-bottom: 20px;
}

/* Level Colors — cycle through 10 vibrant colors for 20 levels */
.level-card:nth-child(10n+1) {
    border-color: #4cd964;
}

.level-card:nth-child(10n+1) .level-icon {
    background-color: #4cd964;
}

.level-card:nth-child(10n+2) {
    border-color: #5AD4FF;
}

.level-card:nth-child(10n+2) .level-icon {
    background-color: #5AD4FF;
}

.level-card:nth-child(10n+3) {
    border-color: #5A9BFF;
}

.level-card:nth-child(10n+3) .level-icon {
    background-color: #5A9BFF;
}

.level-card:nth-child(10n+4) {
    border-color: #B983FF;
}

.level-card:nth-child(10n+4) .level-icon {
    background-color: #B983FF;
}

.level-card:nth-child(10n+5) {
    border-color: #FF85B3;
}

.level-card:nth-child(10n+5) .level-icon {
    background-color: #FF85B3;
}

.level-card:nth-child(10n+6) {
    border-color: #FFE066;
}

.level-card:nth-child(10n+6) .level-icon {
    background-color: #FFE066;
}

.level-card:nth-child(10n+7) {
    border-color: #FF9F43;
}

.level-card:nth-child(10n+7) .level-icon {
    background-color: #FF9F43;
}

.level-card:nth-child(10n+8) {
    border-color: #ff6b6b;
}

.level-card:nth-child(10n+8) .level-icon {
    background-color: #ff6b6b;
}

.level-card:nth-child(10n+9) {
    border-color: #45D09E;
}

.level-card:nth-child(10n+9) .level-icon {
    background-color: #45D09E;
}

.level-card:nth-child(10n+10) {
    border-color: #845EC2;
}

.level-card:nth-child(10n+10) .level-icon {
    background-color: #845EC2;
}

.level-content h3 {
    font-size: 1.5rem;
    margin-bottom: 10px;
}

.level-content p {
    color: var(--text-muted);
    margin-bottom: 20px;
    font-size: 1rem;
}

.level-stars {
    display: flex;
    gap: 5px;
    color: #e0e0e0;
}

.level-stars .earned {
    color: var(--tertiary);
}

/* =========================================
   EXERCISE VIEW
   ========================================= */
.exercise-layout {
    display: grid;
    grid-template-columns: 350px 1fr;
    gap: 30px;
    height: calc(100vh - 160px);
}

.exercise-sidebar {
    background: white;
    padding: 30px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.level-badge {
    display: inline-block;
    background: var(--primary-light);
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 700;
    margin-bottom: 10px;
}

.lesson-header h2 {
    font-size: 2rem;
    color: var(--primary-dark);
    margin-bottom: 20px;
}

.lesson-text {
    font-size: 1.1rem;
    line-height: 1.6;
    color: var(--text-main);
    flex-grow: 1;
}

.lesson-text p {
    margin-bottom: 15px;
}

.lesson-text code {
    background: #f0f4f8;
    padding: 2px 6px;
    border-radius: 6px;
    font-family: monospace;
    font-weight: bold;
    color: var(--secondary);
}

.lesson-task {
    background: #fff8e1;
    border: 2px dashed var(--tertiary);
    padding: 20px;
    border-radius: var(--border-radius-sm);
    margin-top: 20px;
}

.lesson-task h3 {
    color: #cca400;
    margin-bottom: 10px;
    font-size: 1.3rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

.lesson-task p {
    font-size: 1.1rem;
    font-weight: 600;
}

.exercise-workspace {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: #2b3a4a;
    color: white;
    border-radius: var(--border-radius-sm) var(--border-radius-sm) 0 0;
    font-weight: 700;
}

.editor-panel,
.output-panel {
    background: white;
    border-radius: var(--border-radius-sm);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
}

.editor-panel {
    flex-grow: 1;
}

.editor-container {
    flex-grow: 1;
    position: relative;
}

/* Adjust CodeMirror to fill container */
.CodeMirror {
    height: 100% !important;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 0 0 var(--border-radius-sm) var(--border-radius-sm);
    font-size: 1.2rem;
    font-family: 'Consolas', 'Monaco', monospace;
    padding: 10px;
}

.output-panel {
    height: 200px;
}

.console-output {
    background: #1e1e1e;
    color: #4cd964;
    padding: 15px;
    font-family: 'Consolas', monospace;
    font-size: 1.1rem;
    flex-grow: 1;
    border-radius: 0 0 var(--border-radius-sm) var(--border-radius-sm);
    overflow-y: auto;
    white-space: pre-wrap;
}

.console-output.error {
    color: #ff5e5e;
}

/* =========================================
   BADGES VIEW
   ========================================= */
#view-badges {
    text-align: center;
}

#view-badges h2 {
    font-size: 2.5rem;
    margin-bottom: 10px;
}

.badges-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 30px;
    margin: 40px 0;
}

.badge-item {
    background: white;
    width: 150px;
    padding: 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.badge-item i {
    font-size: 4rem;
    color: #e0e0e0;
    /* Default locked color */
}

.badge-item.unlocked i {
    color: var(--tertiary);
    filter: drop-shadow(0 0 10px rgba(255, 224, 102, 0.8));
    animation: shine 2s infinite;
}

.badge-item p {
    font-weight: 700;
    font-size: 1rem;
}

@keyframes shine {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }

    100% {
        transform: scale(1);
    }
}

.progress-section {
    background: white;
    padding: 30px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    max-width: 600px;
    margin: 0 auto;
}

.progress-bar-container {
    height: 30px;
    background: #e0e0e0;
    border-radius: 15px;
    margin: 20px 0;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    width: 0%;
    transition: width 1s ease-in-out;
}

/* =========================================
   MODALS
   ========================================= */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.modal-content {
    background: white;
    padding: 40px;
    border-radius: var(--border-radius);
    text-align: center;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}

.bounce-in {
    animation: bounceIn 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.pop-in {
    animation: popIn 0.3s ease-out;
}

@keyframes bounceIn {
    0% {
        transform: scale(0.3);
        opacity: 0;
    }

    50% {
        transform: scale(1.1);
    }

    70% {
        transform: scale(0.9);
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes popIn {
    0% {
        transform: scale(0.8);
        opacity: 0;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.modal-icon {
    font-size: 5rem;
    margin-bottom: 20px;
}

.error-icon {
    color: var(--primary);
}

.modal-content h2 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    color: var(--primary-dark);
}

.stars-award {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin: 20px 0;
    font-size: 3rem;
    color: var(--tertiary);
}

.anim-star {
    opacity: 0;
    animation: starPop 0.5s forwards;
}

@keyframes starPop {
    0% {
        transform: scale(0) rotate(-180deg);
        opacity: 0;
    }

    100% {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
}

.hint-box {
    background: #f0f4f8;
    padding: 15px;
    border-radius: var(--border-radius-sm);
    margin: 20px 0;
    color: var(--primary-dark);
    font-weight: 600;
}

/* =========================================
   WELCOME SCREEN
   ========================================= */
.welcome-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #5A9BFF, #B983FF, #FF85B3);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.5s, transform 0.5s;
}

.welcome-overlay.fade-out {
    opacity: 0;
    transform: scale(1.1);
    pointer-events: none;
}

.welcome-card {
    background: white;
    padding: 50px 40px;
    border-radius: 32px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    max-width: 420px;
    width: 90%;
    animation: bounceIn 0.6s cubic-bezier(.68, -.55, .265, 1.55);
}

.welcome-icon {
    font-size: 5rem;
    margin-bottom: 10px;
}

.welcome-card h1 {
    font-size: 2.5rem;
    color: var(--primary-dark);
    margin-bottom: 10px;
}

.welcome-card>p {
    color: var(--text-muted);
    font-size: 1.2rem;
    margin-bottom: 20px;
}

.welcome-input {
    width: 100%;
    padding: 16px 20px;
    font-size: 1.3rem;
    border: 3px solid #e0e4ef;
    border-radius: 50px;
    outline: none;
    text-align: center;
    font-family: 'Nunito', sans-serif;
    font-weight: 700;
    margin-bottom: 20px;
    transition: border-color 0.2s;
}

.welcome-input:focus {
    border-color: var(--primary);
}

.welcome-input::placeholder {
    color: #ccc;
    font-weight: 400;
}

.welcome-hint {
    font-size: 0.85rem;
    color: #aaa;
    margin-top: 15px;
}

/* Footer */
.site-footer {
    text-align: center;
    padding: 25px;
    color: var(--text-muted);
    font-size: 1rem;
    border-top: 1px solid #e0e0e0;
    margin-top: 30px;
}

.site-footer strong {
    color: var(--primary-dark);
}

/* =========================================
   STORY INTRO
   ========================================= */
.story-screen {
    position: relative;
    min-height: calc(100vh - 140px);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border-radius: var(--border-radius);
    background: linear-gradient(180deg, #0b0e2a 0%, #1a1a4e 40%, #2d1b69 100%);
}

#story-stars-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
}

.story-content {
    position: relative;
    z-index: 1;
    text-align: center;
    padding: 40px 20px;
    max-width: 600px;
    width: 100%;
}

/* Robot Character */
.story-character {
    margin: 0 auto 30px;
    width: 120px;
    height: 140px;
    position: relative;
}

.robot-body {
    position: relative;
    width: 100%;
    height: 100%;
}

.robot-head {
    width: 100px;
    height: 80px;
    background: linear-gradient(135deg, #5AD4FF, #5A9BFF);
    border-radius: 20px;
    margin: 25px auto 0;
    position: relative;
    box-shadow: 0 0 20px rgba(90, 212, 255, 0.4);
    animation: robotBob 3s ease-in-out infinite;
}

.robot-antenna {
    width: 4px;
    height: 25px;
    background: #5AD4FF;
    margin: 0 auto;
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    border-radius: 2px;
}

.robot-antenna::after {
    content: '';
    width: 14px;
    height: 14px;
    background: #FFE066;
    border-radius: 50%;
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    box-shadow: 0 0 12px rgba(255, 224, 102, 0.8);
    animation: antennaPulse 2s ease-in-out infinite;
}

.robot-eye {
    width: 16px;
    height: 20px;
    background: white;
    border-radius: 50%;
    position: absolute;
    top: 20px;
    animation: blink 4s ease-in-out infinite;
}

.robot-eye.left {
    left: 22px;
}

.robot-eye.right {
    right: 22px;
}

.robot-eye::after {
    content: '';
    width: 8px;
    height: 10px;
    background: #1a1a4e;
    border-radius: 50%;
    position: absolute;
    bottom: 2px;
    left: 50%;
    transform: translateX(-50%);
}

.robot-mouth {
    width: 30px;
    height: 8px;
    background: white;
    border-radius: 0 0 15px 15px;
    position: absolute;
    bottom: 15px;
    left: 50%;
    transform: translateX(-50%);
    transition: all 0.3s;
}

.robot-mouth.sad {
    border-radius: 15px 15px 0 0;
    height: 6px;
}

.robot-mouth.happy {
    border-radius: 0 0 15px 15px;
    height: 12px;
    width: 35px;
}

.robot-mouth.excited {
    width: 20px;
    height: 20px;
    border-radius: 50%;
}

@keyframes robotBob {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-8px);
    }
}

@keyframes blink {

    0%,
    45%,
    55%,
    100% {
        transform: scaleY(1);
    }

    50% {
        transform: scaleY(0.1);
    }
}

@keyframes antennaPulse {

    0%,
    100% {
        box-shadow: 0 0 8px rgba(255, 224, 102, 0.5);
    }

    50% {
        box-shadow: 0 0 20px rgba(255, 224, 102, 1);
    }
}

/* Story Text */
.story-text-box {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 20px;
    padding: 30px;
    margin-bottom: 25px;
    min-height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.story-text {
    color: white;
    font-size: 1.4rem;
    line-height: 1.8;
    font-family: 'Comic Neue', cursive;
    font-weight: 700;
}

.story-text .highlight {
    color: #FFE066;
    font-size: 1.6rem;
}

/* Slide Dots */
.story-slide-dots {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 20px;
}

.story-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transition: all 0.3s;
}

.story-dot.active {
    background: #FFE066;
    transform: scale(1.3);
    box-shadow: 0 0 10px rgba(255, 224, 102, 0.6);
}

/* Story Buttons */
.story-next-btn {
    margin-bottom: 15px;
    animation: pulse 2s infinite;
}

.story-skip {
    color: rgba(255, 255, 255, 0.5) !important;
    font-size: 0.9rem !important;
}

.story-skip:hover {
    color: white !important;
}

/* Slide transition */
.story-content {
    animation: fadeIn 0.4s ease-out;
}

.slide-fade-enter {
    animation: slideFadeIn 0.6s ease-out forwards;
}

@keyframes slideFadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* =========================================
   MINI-GAMES
   ========================================= */
.mg-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 25px;
    padding: 20px 0;
}

.mg-card {
    background: white;
    border-radius: var(--border-radius);
    padding: 25px;
    text-align: center;
    box-shadow: var(--shadow-sm);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    cursor: pointer;
    border: 3px solid transparent;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.mg-card:hover {
    transform: translateY(-8px) scale(1.02);
    box-shadow: var(--shadow-md);
    border-color: var(--primary);
}

.mg-icon {
    font-size: 3.5rem;
    margin-bottom: 15px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    display: inline-block;
}

.mg-card h3 {
    color: var(--primary-dark);
    margin-bottom: 10px;
    font-size: 1.3rem;
}

.mg-card p {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin-bottom: 20px;
    line-height: 1.5;
    flex-grow: 1;
}

.mg-card .btn {
    width: 100%;
}

.mg-diff {
    position: absolute;
    top: 15px;
    right: 15px;
    color: #FFE066;
    font-size: 0.9rem;
    background: rgba(0, 0, 0, 0.05);
    padding: 3px 8px;
    border-radius: 12px;
}

.mg-card.completed {
    border-color: #4cd964;
    background: #f0fdf4;
}

.mg-card.completed::after {
    content: '\f00c';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    position: absolute;
    top: -15px;
    left: -15px;
    width: 60px;
    height: 60px;
    background: #4cd964;
    color: white;
    display: flex;
    align-items: flex-end;
    justify-content: flex-end;
    padding: 0 10px 10px 0;
    transform: rotate(-45deg);
    font-size: 1.2rem;
}


.hidden {
    display: none !important;
}

/* =========================================
   NAV BUTTONS
   ========================================= */
.nav-btn {
    background: var(--primary);
    color: white;
    padding: 8px 16px;
    border-radius: 50px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.1);
    transition: all 0.2s;
    font-size: 0.95rem;
}

.nav-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 0 rgba(0, 0, 0, 0.1);
}

.nav-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 rgba(0, 0, 0, 0.1);
}

/* =========================================
   QUIZ HOME VIEW
   ========================================= */
.quiz-home-header {
    text-align: center;
    margin-bottom: 30px;
}

.quiz-home-header h2 {
    font-size: 2.5rem;
    color: var(--primary-dark);
}

.quiz-categories {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 25px;
    padding: 10px;
}

.quiz-cat-card {
    background: white;
    border-radius: var(--border-radius);
    padding: 30px;
    box-shadow: var(--shadow);
    cursor: pointer;
    border-left: 6px solid var(--primary);
    transition: all 0.3s cubic-bezier(.175, .885, .32, 1.275);
}

.quiz-cat-card:hover {
    transform: translateY(-8px) scale(1.02);
    box-shadow: var(--shadow-hover);
}

.quiz-cat-card:nth-child(2) {
    border-left-color: var(--secondary);
}

.quiz-cat-card:nth-child(3) {
    border-left-color: #FF85B3;
}

.quiz-cat-card:nth-child(4) {
    border-left-color: #FF9F43;
}

.quiz-cat-card:nth-child(5) {
    border-left-color: #45D09E;
}

.quiz-cat-card h3 {
    font-size: 1.4rem;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.quiz-cat-card p {
    color: var(--text-muted);
    margin-bottom: 15px;
}

.quiz-cat-meta {
    display: flex;
    gap: 15px;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.quiz-cat-meta span {
    display: flex;
    align-items: center;
    gap: 5px;
}

.quiz-cat-best {
    color: var(--success) !important;
    font-weight: 700;
}

/* =========================================
   QUIZ ACTIVE VIEW
   ========================================= */
.quiz-container {
    max-width: 800px;
    margin: 0 auto;
}

.quiz-progress-bar {
    height: 10px;
    background: #e0e0e0;
    border-radius: 5px;
    margin: 15px 0;
    overflow: hidden;
}

.quiz-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    width: 0%;
    transition: width 0.5s ease;
    border-radius: 5px;
}

.quiz-info-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    font-weight: 700;
    font-size: 1.1rem;
}

#quiz-score-display {
    color: #FF9F43;
}

#quiz-timer {
    color: var(--error);
}

#theme-toggle {
    font-size: 1.3rem;
    cursor: pointer;
    width: 45px;
    height: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--bg-color);
    border: 2px solid #edf2f7;
    transition: all 0.2s;
}

body.dark-mode #theme-toggle {
    background: #2d3748;
    border-color: #4a5568;
    color: var(--tertiary);
}

.quiz-question-card {
    background: var(--card-bg);
    padding: 35px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    animation: fadeIn 0.4s ease-out;
}

.quiz-type-badge {
    display: inline-block;
    background: var(--secondary);
    color: white;
    padding: 4px 14px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 700;
    margin-bottom: 15px;
}

.quiz-question-card h3 {
    font-size: 1.5rem;
    margin-bottom: 20px;
    line-height: 1.4;
}

.quiz-code-block {
    background: #2b3a4a;
    color: #4cd964;
    padding: 15px 20px;
    border-radius: var(--border-radius-sm);
    margin-bottom: 20px;
    font-family: 'Consolas', monospace;
    font-size: 1.1rem;
    overflow-x: auto;
}

.quiz-code-block pre {
    margin: 0;
}

.quiz-answers {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.quiz-answer-btn {
    background: #f5f7fb;
    border: 3px solid #e0e4ef;
    border-radius: var(--border-radius-sm);
    padding: 16px 20px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    text-align: left;
    transition: all 0.2s;
    font-family: 'Nunito', sans-serif;
}

.quiz-answer-btn:hover {
    background: #eef2ff;
    border-color: var(--primary-light);
    transform: scale(1.01);
}

.quiz-answer-btn.correct {
    background: #e8f5e9;
    border-color: var(--success);
    color: #2e7d32;
    animation: correctPulse 0.5s;
}

.quiz-answer-btn.wrong {
    background: #ffebee;
    border-color: var(--error);
    color: #c62828;
    animation: shake 0.4s;
}

.quiz-answer-btn.disabled {
    pointer-events: none;
    opacity: 0.7;
}

@keyframes correctPulse {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }

    100% {
        transform: scale(1);
    }
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    20%,
    60% {
        transform: translateX(-8px);
    }

    40%,
    80% {
        transform: translateX(8px);
    }
}

.quiz-code-input {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.quiz-code-input textarea {
    font-family: 'Consolas', monospace;
    font-size: 1.1rem;
    padding: 15px;
    border: 3px solid #e0e4ef;
    border-radius: var(--border-radius-sm);
    resize: vertical;
    outline: none;
    transition: border-color 0.2s;
}

.quiz-code-input textarea:focus {
    border-color: var(--primary);
}

/* Quiz Feedback */
.quiz-feedback {
    background: var(--card-bg);
    padding: 30px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    text-align: center;
    margin-top: 20px;
    animation: fadeIn 0.4s ease-out;
}

.feedback-icon {
    font-size: 4rem;
    margin-bottom: 10px;
}

.quiz-feedback h3 {
    font-size: 1.8rem;
    margin-bottom: 10px;
}

.quiz-feedback p {
    font-size: 1.1rem;
    color: var(--text-muted);
    margin-bottom: 10px;
    line-height: 1.5;
}

.feedback-points {
    font-size: 1.4rem !important;
    font-weight: 800 !important;
    color: #FF9F43 !important;
}

/* =========================================
   QUIZ RESULTS VIEW
   ========================================= */
.quiz-results-card {
    max-width: 600px;
    margin: 0 auto;
    background: var(--card-bg);
    border-radius: var(--border-radius);
    padding: 40px;
    box-shadow: var(--shadow);
    text-align: center;
    animation: bounceIn 0.6s cubic-bezier(.68, -.55, .265, 1.55);
}

.results-header {
    margin-bottom: 30px;
}

.results-emoji {
    font-size: 5rem;
    margin-bottom: 10px;
}

.results-header h2 {
    font-size: 2.5rem;
    color: var(--primary-dark);
}

.results-stats {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

.stat-box {
    background: var(--light-bg);
    padding: 20px 25px;
    border-radius: var(--border-radius-sm);
    min-width: 120px;
}

.stat-box i {
    font-size: 2rem;
    color: var(--primary);
    margin-bottom: 5px;
}

.stat-box span {
    display: block;
    font-size: 2rem;
    font-weight: 800;
    color: var(--text-main);
}

.stat-box p {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.results-badge {
    background: linear-gradient(135deg, #FFE066, #FF9F43);
    padding: 15px 25px;
    border-radius: 50px;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: white;
    font-weight: 700;
    font-size: 1.2rem;
    margin-bottom: 25px;
    animation: shine 2s infinite;
}

.results-badge i {
    font-size: 1.5rem;
}

.results-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

/* =========================================
   DASHBOARD VIEW
   ========================================= */
#view-dashboard>h2 {
    text-align: center;
    font-size: 2.5rem;
    margin-bottom: 30px;
    color: var(--primary-dark);
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 25px;
}

.dash-card {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    padding: 25px;
    box-shadow: var(--shadow);
}

.dash-card h3 {
    font-size: 1.3rem;
    margin-bottom: 20px;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 8px;
}

.dash-stats-row {
    display: flex;
    justify-content: space-around;
    flex-wrap: wrap;
    gap: 15px;
}

.dash-stat {
    text-align: center;
}

.dash-stat i {
    font-size: 2rem;
    color: var(--primary);
    display: block;
    margin-bottom: 5px;
}

.dash-stat span {
    font-size: 1.8rem;
    font-weight: 800;
    display: block;
}

.dash-stat p {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Category Bars */
.category-bars {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.cat-bar-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.cat-bar-label {
    width: 120px;
    font-weight: 700;
    font-size: 0.9rem;
    text-align: right;
}

.cat-bar-track {
    flex: 1;
    height: 24px;
    background: #e0e0e0;
    border-radius: 12px;
    overflow: hidden;
}

.cat-bar-fill {
    height: 100%;
    border-radius: 12px;
    transition: width 1s ease;
}

.cat-bar-value {
    width: 50px;
    font-weight: 700;
    font-size: 0.9rem;
}

/* Quiz History */
.quiz-history-list {
    max-height: 300px;
    overflow-y: auto;
}

.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid #f0f0f0;
}

.history-item:last-child {
    border-bottom: none;
}

.history-item .hi-name {
    font-weight: 700;
}

.history-item .hi-score {
    color: #FF9F43;
    font-weight: 700;
}

.history-item .hi-date {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.empty-msg {
    color: var(--text-muted);
    text-align: center;
    padding: 20px;
}

.feature-card {
    cursor: pointer;
    transition: transform 0.2s;
}

.feature-card:hover {
    transform: translateY(-5px);
}

/* =========================================
   RESPONSIVE DESIGN
   ========================================= */
@media (max-width: 992px) {
    .exercise-layout {
        grid-template-columns: 1fr;
        height: auto;
    }

    .editor-panel {
        height: 300px;
    }

    .app-container {
        padding-bottom: 40px;
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 600px) {
    .hero h1 {
        font-size: 2.5rem;
    }

    .main-header {
        padding: 15px;
        flex-direction: column;
        gap: 10px;
    }

    .user-stats {
        flex-wrap: wrap;
        justify-content: center;
    }

    .quiz-info-bar {
        font-size: 0.9rem;
    }

    .results-stats {
        gap: 15px;
    }

    .stat-box {
        min-width: 90px;
        padding: 15px;
    }
}

/* =========================================
   PARENT SPACE (ESPACE PARENT)
   ========================================= */
.parent-layout {
    display: flex;
    gap: 30px;
    background: var(--light-bg);
    border-radius: var(--border-radius);
    overflow: hidden;
    min-height: 500px;
    box-shadow: var(--shadow);
}

.parent-sidebar {
    width: 280px;
    background: white;
    padding: 30px 20px;
    border-right: 2px solid #edf2f7;
    display: flex;
    flex-direction: column;
}

.parent-sidebar h2 {
    font-size: 1.5rem;
    color: var(--primary-dark);
    margin-bottom: 30px;
}

.parent-menu {
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1;
}

.parent-menu .menu-item {
    background: transparent;
    border: none;
    padding: 12px 18px;
    border-radius: 12px;
    color: var(--text-muted);
    font-weight: 700;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    font-size: 1.05rem;
}

.parent-menu .menu-item i {
    margin-right: 10px;
    width: 20px;
}

.parent-menu .menu-item:hover {
    background: #f1f5f9;
    color: var(--primary);
}

.parent-menu .menu-item.active {
    background: var(--primary-light);
    color: var(--primary-dark);
}

.parent-v-notice {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: center;
    margin-top: 20px;
}

.parent-content {
    flex: 1;
    padding: 40px;
    overflow-y: auto;
}

.parent-content h3 {
    font-size: 1.8rem;
    margin-bottom: 25px;
    color: var(--text-main);
}

.p-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 20px;
    margin-bottom: 40px;
}

.p-stat-card {
    background: white;
    padding: 20px;
    border-radius: 15px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    text-align: center;
    border-top: 5px solid var(--primary);
}

.p-stat-val {
    display: block;
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--primary-dark);
}

.p-stat-lab {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 5px;
}

.p-dash-row {
    display: grid;
    grid-template-columns: 1.5fr 1fr;
    gap: 30px;
}

.p-dash-col h4 {
    margin-bottom: 15px;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.9rem;
    letter-spacing: 0.5px;
}

.p-skills-list {
    list-style: none;
    padding: 0;
}

.p-skills-list li {
    background: white;
    padding: 12px 15px;
    border-radius: 10px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 600;
}

.p-skills-list li i.acquired {
    color: var(--success);
}

.p-skills-list li i.pending {
    color: #cbd5e0;
}

.p-time-summary p {
    margin-bottom: 10px;
    font-size: 1.1rem;
}

.p-info-box {
    background: #fff9e6;
    border-left: 4px solid #ffcc00;
    padding: 15px;
    border-radius: 10px;
    margin-top: 20px;
    font-style: italic;
    color: #856404;
}

.p-info-box i {
    margin-right: 5px;
}

/* Program Tab */
.p-program-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-top: 20px;
}

.p-prog-item {
    background: white;
    padding: 20px;
    border-radius: 15px;
    border-left: 5px solid var(--secondary);
}

.p-prog-item h5 {
    color: var(--secondary-dark);
    font-size: 1.1rem;
    margin-bottom: 10px;
}

.p-time-est {
    margin-top: 30px;
    padding: 15px;
    background: #e6fffa;
    border-radius: 10px;
    font-weight: 700;
    color: #2c7a7b;
    text-align: center;
}

/* Safety Tab */
.p-safety-card {
    background: white;
    padding: 25px;
    border-radius: 15px;
    margin-bottom: 20px;
    display: flex;
    align-items: flex-start;
    gap: 20px;
}

.p-safety-card i {
    font-size: 2rem;
    color: var(--success);
}

.p-safety-card h4 {
    margin-bottom: 5px;
    color: var(--text-main);
}

.p-safety-footer {
    text-align: center;
    margin-top: 30px;
    font-weight: 700;
    color: var(--primary);
}

@media (max-width: 900px) {
    .parent-layout {
        flex-direction: column;
    }

    .parent-sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 2px solid #edf2f7;
    }

    .parent-menu {
        flex-direction: row;
        overflow-x: auto;
    }

    .p-dash-row {
        grid-template-columns: 1fr;
    }

    .p-program-grid {
        grid-template-columns: 1fr;
    }
}