/* ============================================================
   بخش ۱: مبانی رزم انفرادی و سلاح‌شناسی
   استایل اصلی – نسخهٔ بهینه‌شده برای meidandar.ir
   ============================================================ */

/* ---------- متغیرهای ریشه (حالت روشن) ---------- */
:root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --surface-2: #f0f2f5;
    --text: #1e2b3c;
    --text-muted: #5f6c80;
    --primary: #0f4c81;
    --primary-soft: #e8f0fe;
    --accent: #c9a227;
    --accent-soft: #fdf6e3;
    --danger: #b91c1c;
    --danger-soft: #fee2e2;
    --border: #d9e0e8;
    --shadow: 0 6px 20px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.12);
    --radius: 14px;
    --transition: all 0.25s ease;
    --max-width: 1200px;
    --font: 'Vazirmatn', 'Segoe UI', Tahoma, Arial, sans-serif;
    color-scheme: light;
}

/* ---------- حالت تاریک ---------- */
[data-theme="dark"] {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-2: #253449;
    --text: #e2e8f0;
    --text-muted: #a3b3c8;
    --primary: #60a5fa;
    --primary-soft: #1e3a5f;
    --accent: #fbbf24;
    --accent-soft: #3b2f12;
    --danger: #f87171;
    --danger-soft: #471a1a;
    --border: #334155;
    --shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.55);
    color-scheme: dark;
}

/* ---------- ریست پایه ---------- */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.8;
    transition: var(--transition);
    padding-top: 70px; /* برای هدر چسبان */
    min-height: 100vh;
}

img,
video {
    max-width: 100%;
    height: auto;
}

a {
    color: var(--primary);
}

/* ---------- کلاس کمکی برای پنهان‌سازی دیداری (Screen Reader only) ---------- */
.sr-only {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ---------- کانتینر ---------- */
.container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 20px;
}

/* ============================================================
   هدر سایت
   ============================================================ */
.site-header {
    position: fixed;
    top: 0;
    right: 0;
    left: 0;
    z-index: 1000;
    background: var(--surface);
    border-bottom: 2px solid var(--border);
    box-shadow: var(--shadow);
    transition: var(--transition);
}

.header-flex {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: -0.3px;
    color: var(--text);
    text-decoration: none;
    cursor: pointer;
}

.logo svg {
    width: 42px;
    height: 42px;
    color: var(--primary);
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

.logo span {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    white-space: nowrap;
}

/* دکمهٔ منوی موبایل */
.mobile-menu-toggle {
    display: none;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 1.5rem;
    border-radius: 8px;
    padding: 6px 12px;
    cursor: pointer;
    transition: var(--transition);
}

.mobile-menu-toggle:hover,
.mobile-menu-toggle:focus-visible {
    background: var(--primary-soft);
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* دکمهٔ حالت تاریک */
.theme-toggle button {
    background: transparent;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    color: var(--text);
    padding: 6px;
    border-radius: 50%;
    transition: var(--transition);
    line-height: 1;
}

.theme-toggle button:hover,
.theme-toggle button:focus-visible {
    background: var(--surface-2);
    transform: rotate(20deg);
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* ناوبری اصلی */
.main-nav {
    display: flex;
    align-items: center;
}

.nav-menu {
    display: flex;
    flex-wrap: wrap;
    list-style: none;
    gap: 4px;
}

.nav-menu li a {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-radius: 8px;
    color: var(--text);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
    transition: var(--transition);
    white-space: nowrap;
}

.nav-menu li a:hover,
.nav-menu li a:focus-visible,
.nav-menu li a.active {
    background: var(--primary-soft);
    color: var(--primary);
}

.nav-menu li a.active {
    border-bottom: 2px solid var(--primary);
}

.nav-menu li a:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* ---------- هدر موبایل ---------- */
@media (max-width: 992px) {
    .mobile-menu-toggle {
        display: block;
    }

    .main-nav {
        display: none;
        position: absolute;
        top: 100%;
        right: 0;
        left: 0;
        background: var(--surface);
        border-bottom: 2px solid var(--border);
        box-shadow: var(--shadow-lg);
        max-height: 70vh;
        overflow-y: auto;
    }

    .main-nav.active {
        display: block;
    }

    .nav-menu {
        flex-direction: column;
        padding: 10px;
    }

    .nav-menu li a {
        display: flex;
        justify-content: flex-start;
        padding: 12px 16px;
        border-radius: 8px;
        font-size: 1rem;
    }

    .header-flex {
        flex-wrap: nowrap;
    }
}

/* ============================================================
   بخش اصلی محتوا
   ============================================================ */

/* هدر بخش (Hero) */
.hero-section {
    background: linear-gradient(135deg, var(--primary) 0%, #1a365d 100%);
    color: #fff;
    border-radius: var(--radius);
    padding: 30px 24px;
    margin: 30px 0 20px;
    box-shadow: var(--shadow-lg);
    position: relative;
    overflow: hidden;
}

.hero-section::after {
    content: "";
    position: absolute;
    left: -30px;
    top: -30px;
    width: 150px;
    height: 150px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 50%;
}

.hero-section::before {
    content: "";
    position: absolute;
    right: -20px;
    bottom: -40px;
    width: 120px;
    height: 120px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 50%;
}

.hero-content {
    position: relative;
    z-index: 1;
    text-align: center;
}

.hero-kicker {
    font-size: 0.9rem;
    letter-spacing: 1px;
    opacity: 0.85;
    margin-bottom: 6px;
}

.hero-title {
    font-size: 2rem;
    font-weight: 800;
    margin-bottom: 10px;
}

.hero-subtitle {
    font-size: 1.1rem;
    opacity: 0.9;
    max-width: 700px;
    margin: 0 auto 16px;
}

.hero-badges {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
}

.hero-badge {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.25);
    backdrop-filter: blur(4px);
    padding: 4px 14px;
    border-radius: 20px;
    font-size: 0.85rem;
}

/* فهرست مطالب */
.chapter-toc {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px;
    margin: 20px 0;
    box-shadow: var(--shadow);
}

.chapter-toc h3 {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 14px;
    font-size: 1.1rem;
    color: var(--primary);
}

.chapter-toc ul {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 10px;
}

.chapter-toc a {
    display: block;
    padding: 10px 14px;
    background: var(--surface-2);
    border-radius: 8px;
    color: var(--text);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
    border-right: 3px solid var(--primary);
    transition: var(--transition);
}

.chapter-toc a:hover,
.chapter-toc a:focus-visible {
    background: var(--primary-soft);
    transform: translateX(-4px);
    outline: none;
}

/* سربرگ بخش */
.section-header {
    text-align: center;
    margin: 30px 0 10px;
}

.section-header h2 {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.section-subtitle {
    color: var(--text-muted);
    font-size: 1rem;
}

/* ============================================================
   فصل‌ها
   ============================================================ */
.chapter {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 28px 24px;
    margin: 24px 0;
    box-shadow: var(--shadow);
    transition: var(--transition);
    scroll-margin-top: 90px; /* برای اسکرول با هدر چسبان */
}

.chapter:hover {
    box-shadow: var(--shadow-lg);
}

.chapter h2 {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--primary);
    padding-right: 14px;
    border-right: 5px solid var(--accent);
    margin-bottom: 18px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chapter h3 {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text);
    margin: 24px 0 10px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.chapter p {
    margin-bottom: 12px;
    text-align: justify;
}

.chapter ul,
.chapter ol {
    padding-right: 24px;
    margin-bottom: 16px;
}

.chapter li {
    margin-bottom: 6px;
}

.chapter strong {
    color: var(--text);
}

/* ============================================================
   تصاویر
   ============================================================ */
.content-img {
    width: 100%;
    height: auto;
    max-height: 480px;
    object-fit: contain;
    border-radius: 10px;
    box-shadow: var(--shadow);
    background: var(--surface-2);
    margin: 15px 0;
    transition: var(--transition);
}

.content-img:hover {
    transform: scale(1.01);
    box-shadow: var(--shadow-lg);
}

/* تصویر خراب (Fallback) */
.content-img.image-error {
    object-fit: contain;
    padding: 20px;
    opacity: 0.85;
    cursor: not-allowed;
}

figure {
    margin: 20px 0;
}

figcaption {
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 8px;
    font-style: italic;
}

/* ============================================================
   ویدیو
   ============================================================ */
.video-container {
    max-width: 800px;
    margin: 20px auto;
    background: var(--surface-2);
    border-radius: 10px;
    padding: 10px;
    box-shadow: var(--shadow);
}

.content-video {
    width: 100%;
    border-radius: 8px;
    display: block;
    background: #000;
}

.video-caption {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 8px 4px;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.caption-icon {
    font-size: 1.2rem;
}

/* ============================================================
   جدول‌ها
   ============================================================ */
.table-wrapper {
    overflow-x: auto;
    margin: 20px 0;
    border-radius: 10px;
    box-shadow: var(--shadow);
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    font-size: 0.9rem;
}

th,
td {
    border: 1px solid var(--border);
    padding: 10px 14px;
    text-align: right;
    vertical-align: middle;
}

thead th {
    background: var(--primary-soft);
    color: var(--primary);
    font-weight: 700;
    white-space: nowrap;
}

tbody tr:nth-child(even) {
    background: var(--surface-2);
}

tbody tr:hover {
    background: var(--accent-soft);
}

/* ============================================================
   هشدار مهم
   ============================================================ */
.highlight {
    background: var(--danger-soft);
    border-right: 5px solid var(--danger);
    color: var(--text);
    padding: 14px 18px;
    border-radius: 8px;
    margin: 16px 0;
    font-weight: 600;
}

/* ============================================================
   جداکننده
   ============================================================ */
.section-divider {
    display: flex;
    align-items: center;
    gap: 15px;
    margin: 40px 0;
    color: var(--text-muted);
}

.divider-line {
    flex: 1;
    height: 2px;
    background: linear-gradient(to right, transparent, var(--border), transparent);
}

.divider-icon {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.4rem;
}

.divider-star {
    color: var(--accent);
}

.divider-iran {
    font-size: 1.8rem;
}

/* ============================================================
   دکمه بازگشت به خانه
   ============================================================ */
.back-home-wrapper {
    text-align: center;
    margin-top: 40px;
}

.back-to-home {
    display: inline-block;
    padding: 12px 26px;
    background: var(--primary);
    color: #fff;
    text-decoration: none;
    border-radius: 30px;
    font-weight: 700;
    font-size: 0.95rem;
    transition: var(--transition);
    box-shadow: var(--shadow);
    margin-top: 10px;
}

.back-to-home:hover,
.back-to-home:focus-visible {
    background: var(--accent);
    color: #1e2b3c;
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    outline: none;
}

/* ============================================================
   پاورقی
   ============================================================ */
.book-footer {
    background: var(--surface);
    border-top: 2px solid var(--border);
    text-align: center;
    padding: 20px 15px;
    margin-top: 40px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.book-footer p {
    margin: 4px 0;
}

/* ============================================================
   دکمه بازگشت به بالا
   ============================================================ */
.back-to-top {
    position: fixed;
    bottom: 24px;
    left: 24px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    font-size: 1.2rem;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.back-to-top.show {
    opacity: 1;
    visibility: visible;
}

.back-to-top:hover,
.back-to-top:focus-visible {
    background: var(--accent);
    color: #1e2b3c;
    transform: translateY(-3px);
    outline: none;
}

/* ============================================================
   واکنش‌گرایی (Responsive)
   ============================================================ */
@media (max-width: 600px) {
    body {
        padding-top: 60px;
    }

    .hero-title {
        font-size: 1.5rem;
    }

    .hero-subtitle {
        font-size: 0.95rem;
    }

    .chapter {
        padding: 18px 14px;
    }

    .chapter h2 {
        font-size: 1.25rem;
    }

    .section-header h2 {
        font-size: 1.4rem;
    }

    .back-to-top {
        bottom: 16px;
        left: 16px;
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }

    .back-home-wrapper {
        margin-top: 28px;
    }
}

/* کاهش حرکت برای کاربرانی که ترجیح می‌دهند */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ============================================================
   استایل چاپ
   ============================================================ */
@media print {
    body {
        padding-top: 0;
        background: #fff;
        color: #000;
    }

    .site-header,
    .back-to-top,
    .theme-toggle,
    .mobile-menu-toggle,
    .back-home-wrapper,
    .video-container {
        display: none !important;
    }

    .chapter,
    .hero-section,
    .chapter-toc {
        box-shadow: none;
        border: 1px solid #ccc;
        page-break-inside: avoid;
    }

    .content-img {
        max-height: 300px;
    }

    a {
        color: #000;
        text-decoration: underline;
    }
}