* { box-sizing: border-box; font-family: 'Segoe UI', sans-serif; }
body { margin: 0; background: #f0f8ff; }

/* ===== TOP BAR ===== */
.topbar {
    background: #ffcb05;
    padding: 10px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.topbar-title {
    text-align: center;
    font-size: 1.3rem;
    font-weight: bold;
    color: #2c3e50;
    margin: 0 0 8px 0;
}
.topbar-menu {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding: 4px 0;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
}
.topbar-menu::-webkit-scrollbar { height: 4px; }
.topbar-menu::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.2); border-radius: 2px; }

.menu-btn {
    background: white;
    border: 2px solid transparent;
    border-radius: 10px;
    padding: 6px 10px;
    cursor: pointer;
    font-weight: bold;
    font-size: 0.8rem;
    color: #2c3e50;
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    line-height: 1;
    box-shadow: 0 2px 4px rgba(0,0,0,0.08);
    transition: all 0.2s;
    white-space: nowrap;
}
.menu-btn .ico { font-size: 1.1rem; }
.menu-btn.active {
    background: #ff4757;
    color: white;
    border-color: #ff4757;
    transform: scale(1.05);
}

/* ===== Main ===== */
.main-content { 
    padding: 20px; 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    background: #f5f6fa; 
    min-height: calc(100vh - 100px);
    width: 100%;
}
.tool-section { 
    display: none; 
    width: 100%; 
    max-width: 650px; 
    background: white; 
    padding: 25px; 
    border-radius: 20px; 
    border: 3px solid #ffcb05; 
    margin: 0 auto;
}
.tool-section.active-section { display: block; }

/* ===== Controls ===== */
.controls-grid { 
    display: flex; 
    flex-wrap: wrap; 
    gap: 10px; 
    background: #f1f2f6; 
    padding: 12px; 
    border-radius: 12px; 
    margin-bottom: 15px; 
    justify-content: center; 
}
.control-group { display: flex; align-items: center; gap: 6px; font-weight: bold; font-size: 0.9rem; }
.control-group input, .control-group select { padding: 6px; border-radius: 6px; border: 1px solid #ccc; }
.controls { display: flex; justify-content: center; gap: 10px; margin-bottom: 15px; flex-wrap: wrap; }

/* ===== Buttons ===== */
.btn { padding: 10px 18px; border: none; border-radius: 10px; font-weight: bold; cursor: pointer; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-success { background: #2ed573; color: white; }
.btn-danger { background: #ff6b6b; color: white; }
.btn-secondary { background: #747d8c; color: white; }
.btn-primary { background: #54a0ff; color: white; }

/* ===== PIXEL (حل جذري للويندوز) ===== */
.canvas-wrapper { 
    width: 100%;
    max-width: 400px;
    height: 400px; /* ارتفاع ثابت */
    margin: 0 auto; 
    position: relative;
    border-radius: 10px; 
    border: 3px solid #747d8c;
    background: #ddd; 
    overflow: hidden;
}
.canvas { 
    display: flex;
    flex-wrap: wrap; 
    position: absolute; top: 0; left: 0;
    width: 100%; height: 100%;
    align-content: flex-start;
}
.pixel { 
    background: white; 
    cursor: pointer; 
    width: 5%; /* 20 بكسل في الصف = 100/20 */
    height: 5%; 
    box-sizing: border-box; 
    border: 1px solid #e0e0e0;
}

/* ===== MAZE (حل جذري) ===== */
.maze-wrapper {
    width: 100%;
    max-width: 360px;
    height: 360px;
    margin: 15px auto; 
    position: relative;
    border-radius: 10px; 
    overflow: hidden;
}
.maze-grid { 
    display: flex;
    flex-wrap: wrap; 
    position: absolute; top: 0; left: 0;
    width: 100%; height: 100%;
    align-content: flex-start;
}
.maze-cell { 
    background: #ecf0f1; 
    display: flex; align-items: center; justify-content: center; 
    font-size: 1.2rem; 
    width: 10%; /* 10 بكسل في الصف */
    height: 10%; 
    box-sizing: border-box; 
    border: 0.5px solid #ddd;
}
.maze-wall { background: #2c3e50 !important; }
.maze-player { background: #2ed573 !important; border-radius: 50%; }
.maze-end { background: #ff4757 !important; }
.mobile-maze-controls { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-top: 15px; }
.horizontal-btns { display: flex; gap: 15px; }

/* ===== MEMORY ===== */
.memory-stats {
    display: flex; justify-content: space-around;
    background: #f1f2f6; padding: 12px; border-radius: 12px;
    margin-bottom: 15px; font-weight: bold; color: #2c3e50;
}
.memory-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    max-width: 440px;
    margin: 0 auto;
}
.memory-card {
    width: 100%;
    height: 90px;
    position: relative;
    cursor: pointer;
    perspective: 600px;
}
.memory-card-inner {
    position: relative;
    width: 100%; height: 100%;
    transition: transform 0.5s;
    transform-style: preserve-3d;
}
.memory-card.flipped .memory-card-inner,
.memory-card.matched .memory-card-inner {
    transform: rotateY(180deg);
}
.memory-front, .memory-back {
    position: absolute; top: 0; left: 0;
    width: 100%; height: 100%;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 2rem;
    box-shadow: 0 3px 8px rgba(0,0,0,0.15);
}
.memory-front {
    background: linear-gradient(135deg, #54a0ff, #2e86de);
    color: white; font-size: 1.8rem; font-weight: bold;
}
.memory-back {
    background: white;
    border: 3px solid #ffcb05;
    transform: rotateY(180deg);
}
.memory-card.matched .memory-back {
    border-color: #2ed573; background: #e8fff0;
}
.memory-win {
    text-align: center; margin-top: 20px; padding: 20px;
    background: #fff8e1; border-radius: 15px;
    border: 3px solid #2ed573;
    font-weight: bold; color: #2c3e50;
}

/* ===== QUIZ GAMES ===== */
.game-score {
    display: flex; justify-content: space-around;
    background: #f1f2f6; padding: 12px; border-radius: 12px;
    margin-bottom: 20px; font-weight: bold; color: #2c3e50;
    flex-wrap: wrap; gap: 10px;
}
.quiz-color-box {
    width: 180px; height: 180px;
    margin: 20px auto; border-radius: 50%;
    box-shadow: 0 5px 20px rgba(0,0,0,0.2);
    border: 5px solid white; background: #ccc;
}
.quiz-shape-box { width: 180px; height: 180px; margin: 20px auto; }
.quiz-shape-box svg { width: 100%; height: 100%; filter: drop-shadow(0 5px 10px rgba(0,0,0,0.2)); }
.quiz-letter-box {
    font-size: 7rem; font-weight: bold;
    text-align: center; color: #ff4757;
    margin: 15px auto;
    text-shadow: 3px 3px 0 #ffcb05; line-height: 1;
}
.quiz-options {
    display: flex; justify-content: center;
    gap: 10px; flex-wrap: wrap; margin-top: 15px;
}
.quiz-options-emoji {
    display: grid; grid-template-columns: repeat(3, 1fr);
    gap: 10px; max-width: 500px; margin: 15px auto;
}
.quiz-emoji-btn {
    padding: 12px 8px; font-size: 0.9rem; line-height: 1.3;
    background: white; color: #2c3e50;
    border: 3px solid #54a0ff; border-radius: 15px;
    cursor: pointer; transition: all 0.2s;
}
.quiz-emoji-btn:hover { background: #e8f1ff; transform: translateY(-2px); }
.quiz-emoji-btn.correct {
    background: #2ed573; color: white; border-color: #2ed573;
}
.quiz-emoji-btn.wrong {
    background: #ff4757; color: white; border-color: #ff4757;
}
.quiz-feedback {
    text-align: center; font-size: 1.15rem; font-weight: bold;
    margin-top: 15px; min-height: 30px;
}
.clock-container { display: flex; justify-content: center; margin: 15px 0; }
.math-question {
    font-size: 2.5rem; font-weight: bold;
    text-align: center; color: #2c3e50;
    margin: 20px 0; background: #f1f2f6;
    padding: 20px; border-radius: 15px;
}
.math-start-btn {
    display: block;
    margin: 0 auto 15px;
}

/* ===== Worksheet ===== */
.worksheet-box { 
    border: 2px dashed #747d8c; padding: 20px; 
    border-radius: 12px; background: white; min-height: 200px; 
}
.problems-list { 
    display: grid; grid-template-columns: 1fr 1fr;
    gap: 15px 30px; padding-left: 20px; margin: 0; 
}
.problems-list li { 
    font-weight: bold; display: flex; align-items: center;
    gap: 8px; white-space: nowrap; font-size: 1.05rem;
}
.worksheet-input { 
    width: 70px; text-align: center; padding: 6px;
    border: 2px solid #747d8c; border-radius: 6px; font-size: 1rem;
}

/* ===== Typing ===== */
.typing-game-box { 
    background: #f1f2f6; border-radius: 15px;
    padding: 30px; margin: 15px auto;
    max-width: 250px; text-align: center; 
}
#typingTarget { font-size: 4rem; color: #ff4757; margin: 0; }

/* ===== TTS ===== */
#ttsText { 
    width: 100%; padding: 10px; border-radius: 10px;
    border: 2px solid #ffcb05; font-family: inherit;
    resize: vertical; font-size: 1rem;
}
.tts-status { 
    text-align: center; margin-top: 10px; font-weight: bold;
    color: #747d8c; padding: 8px;
    background: #f1f2f6; border-radius: 8px; 
}

/* ===== About ===== */
.about-content { line-height: 1.7; color: #444; }
.about-content a { color: #54a0ff; }

/* ===== PWA ===== */
.pwa-install-prompt { 
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex; align-items: center; justify-content: center;
    z-index: 3000; padding: 20px; 
}
.pwa-prompt-content { 
    background: white; padding: 30px;
    border-radius: 20px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.4);
    max-width: 400px; width: 100%;
    border: 4px solid #ffcb05; text-align: center;
}
.pwa-prompt-content h3 { margin-top: 0; color: #2c3e50; }
.pwa-buttons { display: flex; gap: 12px; margin-top: 20px; justify-content: center; }

/* ===== Modal ===== */
.pwa-instructions { 
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.7);
    display: flex; align-items: center; justify-content: center;
    z-index: 4000; padding: 20px; 
}
.instructions-content { 
    background: white; padding: 30px; border-radius: 20px;
    max-width: 600px; width: 100%; max-height: 85vh;
    overflow-y: auto; border: 4px solid #ffcb05;
    position: relative; 
}
.close-modal-btn { 
    position: absolute; top: 10px; right: 15px;
    background: none; border: none; font-size: 1.5rem;
    cursor: pointer; color: #2c3e50; 
}
.instructions-steps { background: #f1f2f6; padding: 20px; border-radius: 12px; margin: 15px 0; }
.instructions-steps h4 { color: #ff4757; margin-top: 15px; }
.instructions-steps ol { padding-left: 20px; }

/* ===== Mobile ===== */
@media (max-width: 768px) {
    .topbar { padding: 8px; }
    .topbar-title { font-size: 1.1rem; margin-bottom: 6px; }
    .menu-btn { padding: 6px 8px; font-size: 0.75rem; }
    .menu-btn .ico { font-size: 1rem; }
    
    .main-content { padding: 10px; }
    .tool-section { padding: 15px; }
    
    #tool-typing { display: none !important; }
    .menu-btn[data-tool="typing"] { display: none !important; }
    
    .canvas-wrapper { width: 300px; height: 300px; }
    .maze-wrapper { width: 280px; height: 280px; }
    
    .memory-grid { grid-template-columns: repeat(4, 1fr); gap: 5px; }
    .memory-card { height: 70px; }
    .memory-front, .memory-back { font-size: 1.5rem; }
    
    .quiz-color-box { width: 140px; height: 140px; }
    .quiz-shape-box { width: 140px; height: 140px; }
    .quiz-letter-box { font-size: 5rem; }
    .math-question { font-size: 2rem; }
    .quiz-options-emoji { grid-template-columns: repeat(3, 1fr); gap: 8px; }
    .quiz-emoji-btn { padding: 10px 6px; font-size: 0.8rem; }
    #clockSvg { width: 160px; height: 160px; }
    
    .problems-list { grid-template-columns: 1fr; }
    .pwa-prompt-content { padding: 20px; }
}

@media (max-width: 400px) {
    .canvas-wrapper { width: 260px; height: 260px; }
    .maze-wrapper { width: 250px; height: 250px; }
    .memory-card { height: 60px; }
    .memory-front, .memory-back { font-size: 1.3rem; }
}
/* منع التقريب التلقائي في المتاهة على الموبايل */
.maze-wrapper, .mobile-maze-controls {
    touch-action: manipulation;
}