/* ============================================ */
/* ===== متغیرهای تم (روشن/تاریک) ===== */
/* ============================================ */
:root {
    /* تم روشن (Light) */
    --bg-body: #f1f5f9;
    --bg-container: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #334155;
    --border-color: #e2e8f0;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
    --code-bg: #1e293b;
    --code-text: #e2e8f0;
    --card-bg: #f8fafc;
    --card-border: #e2e8f0;
    --badge-bg: #eef2ff;
    --badge-text: #4f46e5;
    --nav-hover: #f1f5f9;
    --menu-bg: #ffffff;
    --menu-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --footer-bg: #f8fafc;
}

[data-theme="dark"] {
    /* تم تاریک (Dark) */
    --bg-body: #0b1120;
    --bg-container: #1e293b;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    --code-bg: #0f172a;
    --code-text: #e2e8f0;
    --card-bg: #2d3748;
    --card-border: #4a5568;
    --badge-bg: #2d3748;
    --badge-text: #a5b4fc;
    --nav-hover: #2d3748;
    --menu-bg: #1e293b;
    --menu-shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
    --primary-color: #3b82f6;
    --primary-hover: #60a5fa;
    --footer-bg: #162032;
}

/* ============================================ */
/* ===== ریست و فونت پایه ===== */
/* ============================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    background: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.8;
    padding: 1rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: background 0.3s ease, color 0.3s ease;
}

/* ============================================ */
/* ===== کانتینر اصلی ===== */
/* ============================================ */
.container {
    max-width: 820px;
    margin: 0 auto;
    width: 100%;
    background: var(--bg-container);
    border-radius: 28px;
    padding: 2rem 1.8rem;
    box-shadow: var(--shadow);
    flex: 1;
    transition: background 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
    border: 1px solid var(--border-color);
}

/* ============================================ */
/* ===== هدر ===== */
/* ============================================ */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 0.75rem;
    margin-bottom: 0.5rem;
    border-bottom: 2px solid var(--border-color);
    flex-wrap: wrap;
    gap: 0.5rem;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.header h1 {
    font-size: 1.4rem;
    font-weight: 700;
    background: linear-gradient(135deg, #306998, #4584b6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    display: flex;
    align-items: center;
    gap: 0.2rem;
}

/* ===== ایموجی مار ===== */
.snake-emoji {
    display: inline-block;
    font-size: 1.7rem;
    line-height: 1;
    /* حذف هرگونه استایل شفاف یا گرادینت روی ایموجی */
    background: none !important;
    -webkit-text-fill-color: initial !important;
    color: #4584b6;
    filter: none;
}

/* ===== دکمه همبرگری (منو در موبایل) ===== */
.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.8rem;
    cursor: pointer;
    color: var(--text-primary);
    padding: 0.2rem 0.4rem;
    border-radius: 10px;
    transition: background 0.2s;
    line-height: 1;
}

.menu-toggle:hover {
    background: var(--nav-hover);
}

/* ===== دکمه تغییر تم ===== */
.theme-toggle {
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    padding: 0.2rem 0.6rem;
    border-radius: 10px;
    transition: background 0.2s;
    color: var(--text-primary);
    line-height: 1;
}

.theme-toggle:hover {
    background: var(--nav-hover);
}

/* ============================================ */
/* ===== منوی ناوبری ===== */
/* ============================================ */
#nav-container {
    margin: 0.5rem 0 1.5rem 0;
}

.nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.2rem 1rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-color);
    transition: border-color 0.3s;
}

.nav a {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.95rem;
    padding: 0.3rem 0.1rem;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
    white-space: nowrap;
}

.nav a:hover {
    color: var(--text-primary);
    border-bottom-color: var(--primary-color);
}

.nav a.active {
    color: var(--text-primary);
    font-weight: 600;
    border-bottom-color: #306998;
}

/* ============================================ */
/* ===== محتوای اصلی ===== */
/* ============================================ */
.content {
    flex: 1;
}

.content h2 {
    font-size: 1.7rem;
    font-weight: 700;
    margin-top: 0.2rem;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

.content h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-top: 1.8rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.content h4 {
    font-size: 1.05rem;
    font-weight: 600;
    margin-top: 1.2rem;
    margin-bottom: 0.3rem;
    color: var(--text-primary);
}

.content p {
    margin-bottom: 1rem;
    color: var(--text-secondary);
}

.content ul,
.content ol {
    margin-right: 1.5rem;
    margin-bottom: 1.5rem;
    color: var(--text-secondary);
}

.content li {
    margin-bottom: 0.4rem;
}

.content a {
    color: var(--primary-color);
    text-decoration: none;
    border-bottom: 1px dotted transparent;
    transition: border-color 0.2s;
}

.content a:hover {
    border-bottom-color: var(--primary-color);
}

/* ============================================ */
/* ===== کارت‌های لینک سریع ===== */
/* ============================================ */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.8rem;
    margin: 1.5rem 0;
}

.card-grid a {
    display: block;
    background: var(--card-bg);
    padding: 0.9rem 0.6rem;
    border-radius: 16px;
    text-align: center;
    text-decoration: none;
    color: var(--text-primary);
    font-weight: 500;
    font-size: 0.95rem;
    border: 1px solid var(--card-border);
    transition: all 0.2s;
}

.card-grid a:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.06);
    border-color: var(--primary-color);
    background: var(--bg-container);
}

.card-grid .icon {
    font-size: 1.8rem;
    display: block;
    margin-bottom: 0.2rem;
}

/* ============================================ */
/* ===== جعبه کد با دکمه کپی ===== */
/* ============================================ */
.code-wrapper {
    position: relative;
    margin: 1.2rem 0;
    border-radius: 16px;
    overflow: hidden;
    background: var(--code-bg);
    padding: 0.5rem 0.5rem 0.5rem 0;
    border: 1px solid var(--border-color);
}

.code-wrapper pre {
    margin: 0;
    padding: 0.8rem 1rem;
    overflow-x: auto;
    background: transparent;
}

.code-wrapper code {
    font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
    font-size: 0.9rem;
    color: var(--code-text);
    direction: ltr;
    text-align: left;
    display: block;
    line-height: 1.7;
}

/* ===== دکمه کپی ===== */
.copy-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: #94a3b8;
    padding: 0.2rem 0.8rem;
    border-radius: 8px;
    font-size: 0.7rem;
    cursor: pointer;
    transition: all 0.25s;
    font-family: inherit;
    z-index: 5;
    backdrop-filter: blur(2px);
}

.copy-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #ffffff;
    border-color: rgba(255, 255, 255, 0.2);
}

.copy-btn.copied {
    color: #34d399;
    background: rgba(52, 211, 153, 0.15);
    border-color: #34d399;
}

/* ============================================ */
/* ===== محفظه اجرای کد (Pyodide) ===== */
/* ============================================ */
.python-runner {
    background: var(--code-bg);
    border-radius: 16px;
    padding: 1rem;
    margin: 1.2rem 0;
    border: 1px solid var(--border-color);
}

.python-runner pre {
    margin: 0 0 0.5rem 0;
    padding: 0;
    background: transparent;
}

.python-runner code {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.9rem;
    color: var(--code-text);
    direction: ltr;
    text-align: left;
    display: block;
    line-height: 1.7;
}

.run-btn {
    background: var(--primary-color);
    border: none;
    color: white;
    padding: 0.3rem 1.2rem;
    border-radius: 10px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.25s;
    font-family: inherit;
    font-weight: 500;
}

.run-btn:hover {
    background: var(--primary-hover);
    transform: scale(1.02);
}

.run-btn:active {
    transform: scale(0.97);
}

.python-output {
    background: rgba(0, 0, 0, 0.25);
    padding: 0.6rem 0.8rem;
    border-radius: 10px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    color: #a5b4fc;
    direction: ltr;
    text-align: left;
    margin-top: 0.6rem;
    min-height: 2.5rem;
    white-space: pre-wrap;
    word-break: break-word;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

/* ============================================ */
/* ===== فوتر ===== */
/* ============================================ */
.footer {
    margin-top: 2.5rem;
    padding: 0.8rem 0.5rem;
    border-top: 1px solid var(--border-color);
    font-size: 0.8rem;
    color: #94a3b8;
    text-align: center;
    background: var(--footer-bg);
    border-radius: 0 0 28px 28px;
    margin-left: -1.8rem;
    margin-right: -1.8rem;
    padding-left: 1.8rem;
    padding-right: 1.8rem;
    transition: background 0.3s, border-color 0.3s;
}

.footer a {
    color: var(--primary-color);
    text-decoration: none;
}

/* ===== دکمه تست در فوتر ===== */
#runTester {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    padding: 0.3rem 0.9rem;
    border-radius: 10px;
    cursor: pointer;
    color: var(--text-primary);
    font-size: 0.8rem;
    transition: all 0.2s;
    font-family: inherit;
}

#runTester:hover {
    background: var(--nav-hover);
    border-color: var(--primary-color);
}

#testerReport {
    margin-top: 0.8rem;
    text-align: right;
}

/* ============================================ */
/* ===== ===== رسپانسیو (موبایل) ===== ===== */
/* ============================================ */
@media (max-width: 768px) {
    .container {
        padding: 1.2rem 1rem;
        border-radius: 20px;
    }

    .header h1 {
        font-size: 1.1rem;
    }

    .snake-emoji {
        font-size: 1.3rem;
    }

    .menu-toggle {
        display: block;
        font-size: 1.6rem;
    }

    #nav-container {
        position: relative;
    }

    .nav {
        display: none;
        flex-direction: column;
        position: absolute;
        top: 0.5rem;
        right: 0;
        left: 0;
        background: var(--menu-bg);
        padding: 0.8rem 1rem;
        border-radius: 18px;
        box-shadow: var(--menu-shadow);
        border: 1px solid var(--border-color);
        gap: 0;
        z-index: 100;
        backdrop-filter: blur(8px);
    }

    .nav.open {
        display: flex;
    }

    .nav a {
        padding: 0.6rem 0.2rem;
        border-bottom: 1px solid var(--border-color);
        white-space: normal;
        font-size: 1rem;
    }

    .nav a:last-child {
        border-bottom: none;
    }

    .content h2 {
        font-size: 1.4rem;
    }

    .content h3 {
        font-size: 1.1rem;
    }

    .card-grid {
        grid-template-columns: 1fr 1fr;
        gap: 0.6rem;
    }

    .card-grid a {
        padding: 0.7rem 0.4rem;
        font-size: 0.85rem;
    }

    .card-grid .icon {
        font-size: 1.5rem;
    }

    .code-wrapper code {
        font-size: 0.8rem;
    }

    .copy-btn {
        font-size: 0.65rem;
        padding: 0.15rem 0.6rem;
        top: 0.3rem;
        right: 0.3rem;
    }

    .python-runner code {
        font-size: 0.8rem;
    }

    .python-output {
        font-size: 0.75rem;
        padding: 0.4rem 0.6rem;
    }

    .footer {
        margin-left: -1rem;
        margin-right: -1rem;
        padding-left: 1rem;
        padding-right: 1rem;
        border-radius: 0 0 20px 20px;
        flex-direction: column;
        gap: 0.5rem;
    }
}

@media (max-width: 420px) {
    body {
        padding: 0.5rem;
    }

    .container {
        padding: 0.8rem 0.7rem;
        border-radius: 16px;
    }

    .header h1 {
        font-size: 0.95rem;
    }

    .snake-emoji {
        font-size: 1.1rem;
    }

    .menu-toggle {
        font-size: 1.4rem;
    }

    .theme-toggle {
        font-size: 1.2rem;
    }

    .card-grid {
        grid-template-columns: 1fr 1fr;
        gap: 0.4rem;
    }

    .card-grid a {
        padding: 0.5rem 0.3rem;
        font-size: 0.8rem;
        border-radius: 12px;
    }

    .card-grid .icon {
        font-size: 1.3rem;
    }

    .content h2 {
        font-size: 1.2rem;
    }

    .code-wrapper code {
        font-size: 0.7rem;
        padding: 0.4rem 0.6rem;
    }

    .copy-btn {
        font-size: 0.6rem;
        padding: 0.1rem 0.5rem;
    }

    .python-runner {
        padding: 0.6rem;
    }

    .python-runner code {
        font-size: 0.7rem;
    }

    .run-btn {
        font-size: 0.75rem;
        padding: 0.2rem 0.8rem;
    }

    .python-output {
        font-size: 0.65rem;
        padding: 0.3rem 0.5rem;
        min-height: 1.8rem;
    }

    .footer {
        font-size: 0.7rem;
        margin-left: -0.7rem;
        margin-right: -0.7rem;
        padding-left: 0.7rem;
        padding-right: 0.7rem;
    }

    #runTester {
        font-size: 0.7rem;
        padding: 0.2rem 0.6rem;
    }
}

/* ============================================ */
/* ===== کلاس‌های کمکی ===== */
/* ============================================ */
.highlight {
    background: #fef9c3;
    padding: 0.1rem 0.3rem;
    border-radius: 6px;
    color: #1e293b;
}

[data-theme="dark"] .highlight {
    background: #4b4a2a;
    color: #f1f5f9;
}

.text-center {
    text-align: center;
}

.mt-1 { margin-top: 1rem; }
.mb-1 { margin-bottom: 1rem; }
.mt-2 { margin-top: 2rem; }
.mb-2 { margin-bottom: 2rem; }