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

:root {
    --teal: #2DD4BF;
    --teal-dark: #14B8A6;
    --teal-light: #5EEAD4;
    --bg-dark: #0F172A;
    --bg-darker: #020617;
    --bg-light: #1E293B;
    --text-primary: #F1F5F9;
    --text-secondary: #CBD5E1;
    --text-muted: #94A3B8;
    --accent: var(--teal);
    --success: #10B981;
    --warning: #F59E0B;
    --border: #334155;
    --shadow: rgba(0, 0, 0, 0.3);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

body {
    font-family: 'Press Start 2P', monospace;
    background: var(--bg-darker);
    background-image: 
        repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(255,255,255,.03) 2px, rgba(255,255,255,.03) 4px),
        repeating-linear-gradient(90deg, transparent, transparent 2px, rgba(255,255,255,.03) 2px, rgba(255,255,255,.03) 4px);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

.game-container {
    width: 100%;
    min-height: 100vh;
    position: relative;
    display: flex;
    flex-direction: column;
}

/* Progress Bar */
.progress-container {
    padding: 1.25rem 2rem;
    background: var(--bg-light);
    border-bottom: 3px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.progress-bar {
    width: 100%;
    height: 20px;
    background: var(--bg-dark);
    border: 3px solid var(--border);
    overflow: hidden;
    margin-bottom: 0.75rem;
    border-radius: 2px;
    image-rendering: pixelated;
}

.progress-fill {
    height: 100%;
    background: var(--teal);
    border-right: 2px solid var(--teal-dark);
    transition: width 0.3s steps(10);
    width: 0%;
    image-rendering: pixelated;
}

.progress-text {
    font-size: 1.25rem;
    color: var(--text-primary);
    text-align: center;
    line-height: 1.8;
    font-family: 'Press Start 2P', monospace;
    font-weight: bold;
    margin-top: 0.5rem;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

.progress-text[lang="ar"] {
    font-family: 'Cairo', sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
}

/* Game Area */
.game-area {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    min-height: 800px;
}

/* Category Menu Overlay (Top Left of Game Screen) */
.category-menu-overlay {
    position: absolute;
    top: 20px;
    left: 20px;
    width: 260px;
    background: rgba(30, 41, 59, 0.95);
    border: 4px solid var(--border);
    padding: 1rem;
    box-shadow: 6px 6px 0 rgba(2, 6, 23, 0.8);
    z-index: 20;
    max-height: calc(100% - 40px);
    overflow-y: auto;
    image-rendering: pixelated;
    display: block;
}

.overlay-title {
    font-size: 0.75rem;
    color: var(--teal);
    text-align: center;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid var(--border);
    font-family: 'Press Start 2P', monospace;
}

.overlay-actions {
    margin-top: 1rem;
    display: flex;
    justify-content: center;
}

.btn-reset {
    width: 100%;
    padding: 0.6rem 1rem;
    font-size: 0.55rem;
    background: var(--bg-dark);
    border: 3px solid var(--border);
}

.btn-reset:hover {
    border-color: var(--warning);
    color: var(--warning);
}

/* Game Actions (Under Game Screen) */
.game-actions {
    display: none;
    gap: 1rem;
    justify-content: center;
    padding: 1.5rem 2rem;
    background: var(--bg-light);
    border-top: 3px solid var(--border);
    flex-wrap: wrap;
}

#gameCanvas {
    display: block;
    max-width: 1600px;
    border: 4px solid var(--border);
    box-shadow: 0 0 0 2px var(--bg-dark), 0 0 0 4px var(--border);
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

.character-container {
    position: absolute;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    display: none; /* Character is now drawn on canvas */
}

.character {
    position: relative;
    width: 64px;
    height: 96px;
    animation: idle 3s steps(4) infinite;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

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

.character-body {
    width: 48px;
    height: 64px;
    background: var(--teal);
    margin: 0 auto;
    position: relative;
    border: 2px solid var(--bg-dark);
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
    /* Pixelated shading */
    box-shadow: 
        inset 4px 4px 0 rgba(0, 0, 0, 0.2),
        inset -4px -4px 0 rgba(255, 255, 255, 0.1);
}

.character-body::before {
    content: '';
    position: absolute;
    top: -32px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 40px;
    background: #FBBF24;
    border: 2px solid var(--bg-dark);
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
    box-shadow: 
        inset 3px 3px 0 rgba(0, 0, 0, 0.2),
        inset -3px -3px 0 rgba(255, 255, 255, 0.1);
}

.character-face {
    position: absolute;
    top: -30px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 40px;
    image-rendering: pixelated;
}

.eye {
    width: 4px;
    height: 4px;
    background: var(--bg-dark);
    position: absolute;
    top: 12px;
    animation: blink 4s steps(2) infinite;
    image-rendering: pixelated;
}

.left-eye {
    left: 10px;
}

.right-eye {
    right: 10px;
}

@keyframes blink {
    0%, 90%, 100% {
        height: 4px;
    }
    95% {
        height: 1px;
    }
}

.mouth {
    position: absolute;
    bottom: 6px;
    left: 50%;
    transform: translateX(-50%);
    width: 12px;
    height: 6px;
    border: 2px solid var(--bg-dark);
    border-top: none;
    image-rendering: pixelated;
}

/* Expression Variations */
.character.happy .mouth {
    width: 16px;
    height: 8px;
}

.character.excited .eye {
    width: 6px;
    height: 6px;
}

.character.excited .mouth {
    width: 18px;
    height: 10px;
}

.character.thoughtful .eye {
    width: 3px;
    height: 3px;
    top: 14px;
}

.character.thoughtful .mouth {
    width: 10px;
    height: 4px;
}

/* Main Menu */
.main-menu {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.menu-content {
    max-width: 900px;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.game-title {
    font-size: 1.5rem;
    text-align: center;
    margin-bottom: 2rem;
    color: var(--teal);
    text-shadow: 2px 2px 0 var(--bg-dark), 4px 4px 0 var(--teal-dark);
    line-height: 1.6;
}


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

.topic-grid {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.topic-btn {
    background: var(--bg-dark);
    border: 3px solid var(--border);
    padding: 0.75rem;
    color: var(--text-primary);
    font-size: 0.5rem;
    cursor: pointer;
    transition: all 0.1s steps(2);
    text-align: left;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    position: relative;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
    font-family: 'Press Start 2P', monospace;
    box-shadow: 3px 3px 0 var(--bg-darker);
    line-height: 1.5;
}

.topic-btn:hover {
    border-color: var(--teal);
    transform: translate(-2px, -2px);
    box-shadow: 6px 6px 0 var(--bg-dark);
}

.topic-btn:active {
    transform: translate(0, 0);
    box-shadow: 2px 2px 0 var(--bg-dark);
}

.topic-btn.locked {
    opacity: 0.5;
    cursor: not-allowed;
    position: relative;
}

.topic-btn.locked::after {
    content: '🔒';
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    font-size: 1.2rem;
}

.topic-btn.completed {
    border-color: var(--border);
    box-shadow: 3px 3px 0 var(--bg-darker);
    background: var(--bg-dark);
    opacity: 1;
}

.topic-btn.pending {
    border-color: var(--teal);
    box-shadow: 5px 5px 0 var(--teal-dark);
    background: rgba(45, 212, 191, 0.12);
}

.topic-icon {
    font-size: 1.2rem;
    image-rendering: pixelated;
    filter: contrast(1.2);
    flex-shrink: 0;
}

.menu-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* Buttons */
.btn {
    padding: 0.75rem 1.5rem;
    border: 3px solid var(--bg-dark);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.1s steps(2);
    font-family: inherit;
    image-rendering: pixelated;
    box-shadow: 4px 4px 0 var(--bg-dark);
}

.btn-primary {
    background: var(--teal);
    color: var(--bg-dark);
}

.end-screen[lang="ar"] .btn {
    font-family: 'Cairo', sans-serif;
    font-size: 1rem;
    font-weight: 600;
}

.btn-primary:hover {
    background: var(--teal-dark);
    transform: translate(-2px, -2px);
    box-shadow: 6px 6px 0 var(--bg-dark);
}

.btn-primary:active {
    transform: translate(0, 0);
    box-shadow: 2px 2px 0 var(--bg-dark);
}

.btn-secondary {
    background: var(--bg-light);
    color: var(--text-primary);
    border: 3px solid var(--border);
}

.btn-secondary:hover {
    border-color: var(--teal);
    transform: translate(-2px, -2px);
    box-shadow: 6px 6px 0 var(--bg-dark);
}

.btn-secondary:active {
    transform: translate(0, 0);
    box-shadow: 2px 2px 0 var(--bg-dark);
}

.btn-back {
    background: transparent;
    border: 3px solid var(--border);
    color: var(--text-secondary);
    padding: 0.5rem 1rem;
    cursor: pointer;
    font-size: 0.625rem;
    transition: all 0.1s steps(2);
    font-family: inherit;
    box-shadow: 2px 2px 0 var(--bg-dark);
}

.btn-back:hover {
    border-color: var(--teal);
    color: var(--text-primary);
    transform: translate(-1px, -1px);
    box-shadow: 3px 3px 0 var(--bg-dark);
}

.btn-back:active {
    transform: translate(0, 0);
    box-shadow: 1px 1px 0 var(--bg-dark);
}

/* Dialogue Screen */
.dialogue-screen {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.dialogue-container {
    max-width: 800px;
    width: 100%;
}

.question-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.question-text {
    font-size: 0.875rem;
    color: var(--teal);
    line-height: 1.6;
    text-shadow: 1px 1px 0 var(--bg-dark);
    font-family: 'Press Start 2P', monospace;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

.dialogue-box {
    background: var(--bg-light);
    border: 4px solid var(--border);
    padding: 2rem;
    min-height: 200px;
    box-shadow: 6px 6px 0 var(--bg-dark);
    position: relative;
    image-rendering: pixelated;
}

.dialogue-content {
    min-height: 150px;
    display: flex;
    align-items: center;
}

.dialogue-text {
    font-size: 0.75rem;
    line-height: 1.8;
    color: var(--text-primary);
    font-family: 'Press Start 2P', monospace;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

.typing-indicator {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.typing-indicator span {
    width: 4px;
    height: 4px;
    background: var(--teal);
    animation: typing 1.4s steps(2) infinite;
    image-rendering: pixelated;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

.dialogue-footer {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    text-align: center;
}

.click-hint {
    font-size: 0.625rem;
    color: var(--text-muted);
    animation: pulse 2s steps(4) infinite;
    font-family: 'Press Start 2P', monospace;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

@keyframes pulse {
    0%, 100% {
        opacity: 0.5;
    }
    50% {
        opacity: 1;
    }
}

/* Question List */
.question-list-screen {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.question-list-container {
    max-width: 800px;
    width: 100%;
}

.question-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.question-list-header h2 {
    font-size: 1.25rem;
    color: var(--teal);
    text-shadow: 2px 2px 0 var(--bg-dark);
    line-height: 1.6;
    font-family: 'Press Start 2P', monospace;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

.question-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.question-item {
    background: var(--bg-light);
    border: 3px solid var(--border);
    padding: 1.5rem;
    cursor: pointer;
    transition: all 0.1s steps(2);
    font-size: 0.75rem;
    line-height: 1.6;
    box-shadow: 4px 4px 0 var(--bg-dark);
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
    font-family: 'Press Start 2P', monospace;
}

.question-item:hover {
    border-color: var(--teal);
    transform: translate(-2px, -2px);
    box-shadow: 6px 6px 0 var(--bg-dark);
}

.question-item:active {
    transform: translate(0, 0);
    box-shadow: 2px 2px 0 var(--bg-dark);
}

.question-item.asked {
    opacity: 0.6;
    border-color: var(--success);
    background: rgba(16, 185, 129, 0.05);
}

.question-item.asked::after {
    content: '✓';
    float: right;
    color: var(--success);
    font-size: 1.5rem;
}

/* End Screen */
.end-screen {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.end-content {
    max-width: 600px;
    width: 100%;
    text-align: center;
}

.end-title {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: var(--teal);
    text-shadow: 2px 2px 0 var(--bg-dark), 4px 4px 0 var(--teal-dark);
    line-height: 1.6;
}

.end-title[lang="ar"] {
    font-family: 'Cairo', sans-serif;
    font-size: 2rem;
    font-weight: 700;
}

.end-subtitle {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 3rem;
    line-height: 1.6;
}

.end-subtitle[lang="ar"] {
    font-family: 'Cairo', sans-serif;
    font-size: 1.25rem;
    font-weight: 600;
}

.contact-links {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.contact-link {
    background: var(--bg-light);
    border: 3px solid var(--border);
    padding: 1.5rem;
    text-decoration: none;
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.1s steps(2);
    font-size: 0.625rem;
    box-shadow: 4px 4px 0 var(--bg-dark);
    image-rendering: pixelated;
}

.end-screen[lang="ar"] .contact-link {
    font-family: 'Cairo', sans-serif;
    font-size: 0.875rem;
    font-weight: 600;
}

.contact-link:hover {
    border-color: var(--teal);
    transform: translate(-2px, -2px);
    box-shadow: 6px 6px 0 var(--bg-dark);
}

.contact-link:active {
    transform: translate(0, 0);
    box-shadow: 2px 2px 0 var(--bg-dark);
}

.contact-icon {
    font-size: 2rem;
}

/* Celebration Modal */
.celebration-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.celebration-content {
    background: var(--bg-light);
    border: 4px solid var(--teal);
    padding: 3rem;
    text-align: center;
    max-width: 500px;
    width: 90%;
    animation: slideUp 0.3s steps(5);
    box-shadow: 8px 8px 0 var(--bg-dark);
    image-rendering: pixelated;
}

@keyframes slideUp {
    from {
        transform: translateY(50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.celebration-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    animation: bounce 1s infinite;
}

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

.celebration-title {
    font-size: 1.25rem;
    color: var(--teal);
    margin-bottom: 1rem;
    text-shadow: 2px 2px 0 var(--bg-dark);
    line-height: 1.6;
}

.celebration-text {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 2rem;
    line-height: 1.6;
}

/* Responsive Design */
@media (max-width: 768px) {
    .game-title {
        font-size: 1.25rem;
    }

    .topic-grid {
        grid-template-columns: 1fr;
    }

    .question-text {
        font-size: 0.75rem;
    }

    .dialogue-box {
        padding: 1.5rem;
    }

    .character {
        width: 100px;
        height: 150px;
    }

    .character-body {
        width: 70px;
        height: 85px;
    }

    .progress-container {
        padding: 0.75rem 1rem;
    }

    .menu-actions {
        flex-direction: column;
    }

    .btn {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .game-area {
        padding: 1rem;
    }

    .dialogue-screen,
    .question-list-screen,
    .end-screen {
        padding: 1rem;
    }

    .question-list-header h2 {
        font-size: 1rem;
    }

    .end-title {
        font-size: 1.25rem;
    }
}

/* Accessibility */
*:focus-visible {
    outline: 2px solid var(--teal);
    outline-offset: 2px;
}

/* Animations */
.fade-in {
    animation: fadeIn 0.5s ease;
}

.fade-out {
    animation: fadeOut 0.5s ease;
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

