/* ===== Git & GitHub Book — Stylesheet ===== */
/* ===== Local Fonts ===== */

/* Vazirmatn (Persian) */
@font-face {
  font-family: 'Vazirmatn';
  font-style: normal;
  font-weight: 300;
  font-display: swap;
  src: url('../fonts/Vazirmatn-Light.ttf') format('truetype');
}
@font-face {
  font-family: 'Vazirmatn';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/Vazirmatn-Regular.ttf') format('truetype');
}
@font-face {
  font-family: 'Vazirmatn';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('../fonts/Vazirmatn-Medium.ttf') format('truetype');
}
@font-face {
  font-family: 'Vazirmatn';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('../fonts/Vazirmatn-SemiBold.ttf') format('truetype');
}
@font-face {
  font-family: 'Vazirmatn';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../fonts/Vazirmatn-Bold.ttf') format('truetype');
}
@font-face {
  font-family: 'Vazirmatn';
  font-style: normal;
  font-weight: 800;
  font-display: swap;
  src: url('../fonts/Vazirmatn-ExtraBold.ttf') format('truetype');
}

/* JetBrains Mono (code) */
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/JetBrainsMono-Regular.ttf') format('truetype');
}
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('../fonts/JetBrainsMono-Medium.ttf') format('truetype');
}
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('../fonts/JetBrainsMono-SemiBold.ttf') format('truetype');
}
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../fonts/JetBrainsMono-Bold.ttf') format('truetype');
}

/* Inter (Latin) */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/Inter-Regular.ttf') format('truetype');
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('../fonts/Inter-Medium.ttf') format('truetype');
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('../fonts/Inter-SemiBold.ttf') format('truetype');
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../fonts/Inter-Bold.ttf') format('truetype');
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 800;
  font-display: swap;
  src: url('../fonts/Inter-ExtraBold.ttf') format('truetype');
}

/* ===== Catppuccin Mocha-inspired Dark Palette ===== */
  :root {
    --bg:          #1e1e2e;
    --bg-elevated: #181825;
    --bg-surface:  #313244;
    --bg-hover:    #45475a;
    --border:      #45475a;
    --border-soft: #313244;

    --text:        #cdd6f4;
    --text-muted:  #a6adc8;
    --text-dim:    #7f849c;

    --accent:      #c084fc;  /* purple */
    --accent-2:    #2dd4bf;  /* teal */
    --accent-3:    #f38ba8;  /* pink */
    --accent-4:    #f9e2af;  /* yellow */
    --accent-5:    #89b4fa;  /* blue */
    --accent-6:    #a6e3a1;  /* green */

    --code-bg:     #11111b;
    --code-border: #181825;
    --code-text:   #cdd6f4;

    --shadow-sm: 0 2px 8px rgba(0,0,0,0.25);
    --shadow-md: 0 8px 24px rgba(0,0,0,0.35);
    --shadow-lg: 0 16px 48px rgba(0,0,0,0.45);

    --radius-sm: 8px;
    --radius:    12px;
    --radius-lg: 16px;

    --sidebar-w: 290px;
    --content-max: 1400px;
  }

  * { box-sizing: border-box; margin: 0; padding: 0; }

  html { scroll-behavior: smooth; }

  body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Vazirmatn', 'Inter', sans-serif;
    line-height: 1.85;
    font-size: 16px;
    overflow-x: hidden;
    background-image:
      radial-gradient(ellipse 80% 50% at 20% -10%, rgba(192,132,252,0.10), transparent 60%),
      radial-gradient(ellipse 60% 40% at 80% 110%, rgba(45,212,191,0.08), transparent 60%);
    background-attachment: fixed;
  }

  /* ===== Scrollbar ===== */
  ::-webkit-scrollbar { width: 10px; height: 10px; }
  ::-webkit-scrollbar-track { background: var(--bg-elevated); }
  ::-webkit-scrollbar-thumb { background: var(--bg-surface); border-radius: 5px; }
  ::-webkit-scrollbar-thumb:hover { background: var(--bg-hover); }

  /* ===== Progress Bar ===== */
  #progress-bar {
    position: fixed;
    top: 0;
    right: 0;
    left: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    width: 0%;
    z-index: 1000;
    transition: width 0.1s ease;
    box-shadow: 0 0 12px rgba(192,132,252,0.6);
  }

  /* ===== Top Bar ===== */
  #topbar {
    position: fixed;
    top: 0;
    right: 0;
    left: 0;
    height: 60px;
    background: rgba(30,30,46,0.85);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border-soft);
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    padding-right: var(--sidebar-w);
  }
  #topbar .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    color: var(--text);
  }
  #topbar .brand .logo {
    width: 32px; height: 32px;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    color: white; font-weight: 800;
    font-family: 'JetBrains Mono', monospace;
    box-shadow: 0 0 16px rgba(192,132,252,0.5);
  }
  #topbar .actions { display: flex; gap: 8px; align-items: center; }
  #topbar .search-box {
    background: var(--bg-surface);
    border: 1px solid var(--border-soft);
    border-radius: 999px;
    padding: 8px 16px 8px 14px;
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
    width: 280px;
    transition: all 0.2s;
    direction: rtl;
  }
  #topbar .search-box:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(192,132,252,0.15);
    width: 340px;
  }
  #topbar .icon-btn {
    background: var(--bg-surface);
    border: 1px solid var(--border-soft);
    color: var(--text-muted);
    width: 38px; height: 38px;
    border-radius: 10px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 16px;
    transition: all 0.2s;
  }
  #topbar .icon-btn:hover {
    background: var(--bg-hover);
    color: var(--accent);
    border-color: var(--accent);
  }
  #menu-toggle { display: none; }

  /* ===== Sidebar (right side for RTL) ===== */
  #sidebar {
    position: fixed;
    top: 60px;
    right: 0;
    bottom: 0;
    width: var(--sidebar-w);
    background: var(--bg-elevated);
    border-left: 1px solid var(--border-soft);
    overflow-y: auto;
    padding: 24px 16px 60px 16px;
    z-index: 998;
    transition: transform 0.3s ease;
  }
  #sidebar .toc-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin: 16px 8px 8px 8px;
  }
  #sidebar .toc-group { margin-bottom: 4px; }
  #sidebar a {
    display: block;
    color: var(--text-muted);
    text-decoration: none;
    padding: 7px 14px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.15s;
    line-height: 1.6;
  }
  #sidebar a:hover {
    background: var(--bg-surface);
    color: var(--text);
  }
  #sidebar a.active {
    background: linear-gradient(90deg, rgba(192,132,252,0.15), rgba(192,132,252,0.05));
    color: var(--accent);
    border-right: 3px solid var(--accent);
    padding-right: 11px;
  }
  #sidebar a.sub { padding-right: 26px; font-size: 13px; color: var(--text-dim); }

  /* ===== Main Content ===== */
  #main {
    margin-right: var(--sidebar-w);
    padding: 80px 48px 80px 48px;
  }
  #main .content {
    max-width: var(--content-max);
    margin: 0 auto;
  }

  /* ===== Typography ===== */
  h1, h2, h3, h4 { font-family: 'Vazirmatn', sans-serif; font-weight: 700; line-height: 1.4; }
  h1 { font-size: 2.4rem; margin: 0 0 24px 0; }
  h2 {
    font-size: 1.9rem;
    margin: 56px 0 20px 0;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--border-soft);
    position: relative;
  }
  h2::before {
    content: '';
    position: absolute;
    bottom: -2px;
    right: 0;
    width: 60px;
    height: 2px;
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
  }
  h3 { font-size: 1.4rem; margin: 36px 0 14px 0; color: var(--text); }
  h4 { font-size: 1.15rem; margin: 24px 0 10px 0; color: var(--accent-2); }

  p { margin-bottom: 16px; color: var(--text); }
  p strong { color: var(--accent-4); font-weight: 600; }
  p code, li code { background: var(--bg-surface); padding: 2px 7px; border-radius: 5px; font-size: 0.92em; color: var(--accent); font-family: 'JetBrains Mono', monospace; direction: ltr; display: inline-block; }

  ul, ol { margin: 12px 0 20px 0; padding-right: 28px; }
  li { margin-bottom: 8px; color: var(--text); }
  li::marker { color: var(--accent); }

  a { color: var(--accent-2); text-decoration: none; transition: color 0.2s; }
  a:hover { color: var(--accent); text-decoration: underline; }

  /* ===== Chapter Section ===== */
  .chapter {
    margin-bottom: 32px;
    scroll-margin-top: 80px;
  }
  .chapter-label {
    display: inline-block;
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    color: var(--accent);
    background: rgba(192,132,252,0.1);
    padding: 4px 10px;
    border-radius: 999px;
    margin-bottom: 12px;
    border: 1px solid rgba(192,132,252,0.3);
    direction: ltr;
  }

  /* ===== Code Block ===== */
  .code-wrap {
    margin: 20px 0;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
    background: var(--code-bg);
    box-shadow: var(--shadow-sm);
    direction: ltr;
  }
  .code-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--code-border);
    padding: 8px 14px;
    border-bottom: 1px solid var(--border);
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    color: var(--text-dim);
  }
  .code-header .lang {
    color: var(--accent-2);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
  }
  .code-header .dots { display: flex; gap: 6px; }
  .code-header .dots span {
    width: 11px; height: 11px; border-radius: 50%;
    display: inline-block;
  }
  .dots .red { background: #f38ba8; }
  .dots .yellow { background: #f9e2af; }
  .dots .green { background: #a6e3a1; }
  .copy-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 3px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    font-size: 11px;
    transition: all 0.2s;
  }
  .copy-btn:hover { background: var(--bg-surface); color: var(--accent-2); border-color: var(--accent-2); }
  .copy-btn.copied { color: var(--accent-6); border-color: var(--accent-6); }
  pre {
    margin: 0;
    padding: 18px 20px;
    overflow-x: auto;
    background: var(--code-bg) !important;
    font-family: 'JetBrains Mono', monospace;
    font-size: 13.5px;
    line-height: 1.7;
    color: var(--code-text);
  }
  pre code { background: none !important; padding: 0; color: inherit; font-size: inherit; }
  /* Override highlight.js theme to match our palette */
  .hljs-keyword { color: #cba6f7 !important; }
  .hljs-string { color: #a6e3a1 !important; }
  .hljs-comment { color: #6c7086 !important; font-style: italic; }
  .hljs-number { color: #fab387 !important; }
  .hljs-function .hljs-title, .hljs-title.function_ { color: #89b4fa !important; }
  .hljs-built_in { color: #f38ba8 !important; }
  .hljs-attr, .hljs-attribute { color: #89b4fa !important; }
  .hljs-variable, .hljs-params { color: #f2cdcd !important; }
  .hljs-type, .hljs-class .hljs-title { color: #f9e2af !important; }
  .hljs-meta { color: #6c7086 !important; }
  .hljs-section { color: #89b4fa !important; }
  .hljs-symbol { color: #f2cdcd !important; }
  .hljs-bullet { color: #fab387 !important; }
  .hljs-addition { color: #a6e3a1 !important; }
  .hljs-deletion { color: #f38ba8 !important; }

  /* Inline code */
  :not(pre) > code {
    direction: ltr;
    unicode-bidi: embed;
  }

  /* ===== Callout ===== */
  .callout {
    margin: 20px 0;
    padding: 16px 18px 16px 18px;
    border-radius: var(--radius);
    border-right: 4px solid;
    background: var(--bg-elevated);
    position: relative;
  }
  .callout .title {
    font-weight: 700;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .callout.tip { border-color: var(--accent-2); }
  .callout.tip .title { color: var(--accent-2); }
  .callout.warn { border-color: var(--accent-4); background: rgba(249,226,175,0.05); }
  .callout.warn .title { color: var(--accent-4); }
  .callout.danger { border-color: var(--accent-3); background: rgba(243,139,168,0.05); }
  .callout.danger .title { color: var(--accent-3); }
  .callout.info { border-color: var(--accent-5); }
  .callout.info .title { color: var(--accent-5); }
  .callout.note { border-color: var(--accent); }
  .callout.note .title { color: var(--accent); }
  .callout p:last-child { margin-bottom: 0; }

  /* ===== Tables ===== */
  .table-wrap { overflow-x: auto; margin: 20px 0; border-radius: var(--radius); border: 1px solid var(--border); }
  table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-elevated);
    font-size: 14px;
  }
  th, td {
    padding: 12px 16px;
    text-align: right;
    border-bottom: 1px solid var(--border-soft);
  }
  th {
    background: var(--bg-surface);
    color: var(--accent-2);
    font-weight: 700;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
  }
  tr:last-child td { border-bottom: none; }
  tr:hover td { background: rgba(192,132,252,0.04); }
  td code { background: var(--bg); font-size: 12px; }

  /* ===== Mermaid Diagram Container ===== */
  .diagram-wrap {
    margin: 28px 0;
    padding: 24px;
    background: var(--bg-elevated);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    text-align: center;
    overflow-x: auto;
  }
  .diagram-wrap .diagram-title {
    font-size: 13px;
    color: var(--text-dim);
    margin-top: 16px;
    font-family: 'JetBrains Mono', monospace;
    direction: ltr;
  }
  .mermaid {
    display: flex;
    justify-content: center;
    direction: ltr;
  }
  .mermaid svg { max-width: 100%; height: auto; }

  /* ===== Cover Page ===== */
  #cover {
    min-height: calc(100vh - 60px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 20px;
    position: relative;
    overflow: hidden;
  }
  #cover::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -20%;
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, rgba(192,132,252,0.15), transparent 70%);
    border-radius: 50%;
    filter: blur(40px);
  }
  #cover::after {
    content: '';
    position: absolute;
    bottom: -30%;
    left: -20%;
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, rgba(45,212,191,0.12), transparent 70%);
    border-radius: 50%;
    filter: blur(40px);
  }
  #cover .cover-content { position: relative; z-index: 1; }
  #cover .badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: rgba(192,132,252,0.1);
    border: 1px solid rgba(192,132,252,0.3);
    color: var(--accent);
    padding: 6px 16px;
    border-radius: 999px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    margin-bottom: 24px;
    direction: ltr;
  }
  #cover h1 {
    font-size: 3.5rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 12px;
    line-height: 1.2;
  }
  #cover .subtitle {
    font-size: 1.25rem;
    color: var(--text-muted);
    margin-bottom: 32px;
  }
  #cover .author-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 28px 32px;
    margin: 32px auto;
    max-width: 480px;
    box-shadow: var(--shadow-lg);
  }
  #cover .author-avatar {
    width: 96px; height: 96px;
    border-radius: 50%;
    object-fit: cover;
    margin: 0 auto 16px auto;
    display: block;
    box-shadow: 0 0 32px rgba(192,132,252,0.4);
    border: 3px solid rgba(192,132,252,0.4);
  }
  #cover .author-name {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
  }
  #cover .author-role {
    color: var(--text-dim);
    font-size: 14px;
    margin-bottom: 18px;
  }
  #cover .social-links {
    display: flex;
    gap: 12px;
    justify-content: center;
  }
  #cover .social-links a {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-surface);
    color: var(--text);
    padding: 10px 18px;
    border-radius: 999px;
    border: 1px solid var(--border);
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
  }
  #cover .social-links a:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
    color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(192,132,252,0.2);
  }
  #cover .stats {
    display: flex;
    gap: 32px;
    justify-content: center;
    margin-top: 36px;
    flex-wrap: wrap;
  }
  #cover .stat {
    text-align: center;
  }
  #cover .stat .num {
    font-family: 'JetBrains Mono', monospace;
    font-size: 2rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent-2), var(--accent-5));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
  }
  #cover .stat .lbl {
    font-size: 13px;
    color: var(--text-dim);
  }
  #cover .scroll-down {
    margin-top: 48px;
    color: var(--text-dim);
    font-size: 13px;
    animation: bounce 2s infinite;
  }
  @keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(8px); }
  }

  /* ===== Footer (minimal) ===== */
  #footer {
    margin-top: 80px;
    padding: 32px 32px 24px 32px;
    background: var(--bg-elevated);
    border-top: 1px solid var(--border-soft);
    text-align: center;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }
  #footer .footer-avatar {
    width: 48px; height: 48px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
    margin: 0 auto 10px auto;
    border: 1px solid rgba(192,132,252,0.3);
  }
  #footer h3 { color: var(--text); margin-bottom: 4px; font-size: 1rem; font-weight: 600; }
  #footer .footer-role { color: var(--text-dim); margin-bottom: 14px; font-size: 12px; }
  #footer .footer-links {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 16px;
  }
  #footer .footer-links a {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    color: var(--text-muted);
    padding: 6px 14px;
    border-radius: 999px;
    border: 1px solid var(--border-soft);
    font-size: 13px;
    transition: all 0.2s;
  }
  #footer .footer-links a:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(192,132,252,0.06);
  }
  #footer .copyright {
    color: var(--text-dim);
    font-size: 12px;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--border-soft);
  }

  /* ===== Search Results ===== */
  #search-results {
    position: fixed;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 600px;
    max-height: 70vh;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    overflow-y: auto;
    display: none;
    z-index: 1001;
    direction: rtl;
  }
  #search-results.active { display: block; }
  #search-results .result-item {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-soft);
    cursor: pointer;
    transition: background 0.15s;
  }
  #search-results .result-item:hover { background: var(--bg-surface); }
  #search-results .result-item:last-child { border-bottom: none; }
  #search-results .result-title { font-weight: 600; color: var(--accent); margin-bottom: 4px; }
  #search-results .result-snippet { font-size: 13px; color: var(--text-muted); }
  #search-results .empty { padding: 32px; text-align: center; color: var(--text-dim); }

  /* ===== Anchor Links ===== */
  .anchor-link {
    opacity: 0;
    margin-right: 8px;
    color: var(--accent);
    text-decoration: none;
    transition: opacity 0.2s;
    font-size: 0.8em;
    direction: ltr;
    display: inline-block;
  }
  h2:hover .anchor-link, h3:hover .anchor-link { opacity: 1; }

  /* ===== Keyboard Shortcut Display ===== */
  kbd {
    display: inline-block;
    padding: 2px 8px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-bottom-width: 2px;
    border-radius: 5px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    color: var(--text);
    direction: ltr;
  }

  /* ===== Responsive ===== */
  @media (max-width: 1024px) {
    :root { --sidebar-w: 0px; }
    #sidebar {
      transform: translateX(100%);
      width: 280px;
      box-shadow: var(--shadow-lg);
    }
    #sidebar.open { transform: translateX(0); }
    #topbar { padding-right: 16px; }
    #menu-toggle { display: flex; }
    #main { padding: 80px 24px 60px 24px; }
    #topbar .search-box { width: 180px; }
    #topbar .search-box:focus { width: 220px; }
  }
  @media (max-width: 640px) {
    #cover h1 { font-size: 2.2rem; }
    #cover .subtitle { font-size: 1rem; }
    h1 { font-size: 1.8rem; }
    h2 { font-size: 1.5rem; }
    h3 { font-size: 1.2rem; }
    #topbar .search-box { display: none; }
    #main { padding: 76px 16px 40px 16px; }
    pre { font-size: 12px; padding: 14px; }
  }
/* ===== Print ===== */
  @media print {
    /* Hide navigation elements, buttons, search boxes, and scroll indicators */
    #sidebar, #topbar, #progress-bar, .icon-btn, .copy-btn, .scroll-down, #search-results, .chapter-label {
      display: none !important;
    }

    /* Set page width and margins for printing */
    #main {
      margin: 0 !important;
      padding: 0 !important;
      width: 100% !important;
    }

    /* Set RTL layout and base typography for printing on white paper */
    body {
      background: #ffffff !important;
      color: #000000 !important;
      font-size: 11pt;
      line-height: 1.6;
      direction: rtl;
    }

    /* Make headings dark and clear */
    h1, h2, h3, h4 {
      color: #000000 !important;
      page-break-after: avoid;
      break-after: avoid;
    }

    h2 {
      border-bottom: 2px solid #333333 !important;
      padding-bottom: 6px !important;
    }

    h2::before {
      display: none !important; /* Remove decorative gradient line */
    }

    /* Make all body text and lists black for better readability */
    p, li, td, th, span, strong {
      color: #000000 !important;
    }
    
    p strong {
      color: #000000 !important;
      font-weight: bold !important;
    }

    /* Format author card (Cover) for printing */
    #cover .author-card {
      background: #fafafa !important;
      border: 1px solid #cccccc !important;
      box-shadow: none !important;
      padding: 20px !important;
      margin: 30px auto !important;
      max-width: 450px !important;
      border-radius: 8px !important;
      text-align: center !important;
      page-break-inside: avoid;
      break-inside: avoid;
    }

    #cover .author-avatar {
      width: 80px !important;
      height: 80px !important;
      border: 2px solid #333333 !important;
      box-shadow: none !important;
      margin: 0 auto 10px auto !important;
      display: block !important;
    }

    #cover .author-name {
      color: #000000 !important;
      font-size: 1.2rem !important;
      font-weight: bold !important;
      margin-bottom: 4px !important;
    }

    #cover .author-role {
      color: #555555 !important;
      font-size: 10pt !important;
      margin-bottom: 12px !important;
    }

    #cover .social-links {
      display: flex !important;
      flex-direction: column !important; /* Stack links for cleaner URL reading */
      gap: 6px !important;
      align-items: center !important;
    }

    #cover .social-links a {
      background: transparent !important;
      border: none !important;
      color: #0000ee !important;
      padding: 0 !important;
      box-shadow: none !important;
      text-decoration: none !important;
      display: inline-flex !important;
      align-items: center !important;
      gap: 6px !important;
      font-size: 10pt !important;
    }

    #cover .social-links a svg {
      fill: #000000 !important; /* Darken social icons */
    }

    /* Print full URLs next to titles on physical paper */
    #cover .social-links a::after {
      content: ": " attr(href) !important;
      font-size: 9pt !important;
      color: #555555 !important;
      text-decoration: underline !important;
      direction: ltr !important;
      unicode-bidi: embed !important;
      margin-left: 4px !important;
    }

    /* Format code blocks for printing */
    .code-wrap {
      background: #f5f5f5 !important;
      border: 1px solid #cccccc !important;
      page-break-inside: avoid;
      break-inside: avoid;
      box-shadow: none !important;
    }

    .code-header {
      background: #e6e6e6 !important;
      border-bottom: 1px solid #cccccc !important;
      color: #333333 !important;
    }

    .code-header .dots {
      display: none !important; /* Hide Mac-style colored dots */
    }

    pre {
      background: #f5f5f5 !important;
      color: #000000 !important;
      white-space: pre-wrap !important; /* Wrap long code lines */
      word-wrap: break-word !important;
    }

    /* Force all text and syntax tokens inside code blocks to default to black first */
    pre, pre *, code, code * {
      color: #111111 !important;
      background: transparent !important;
      text-shadow: none !important;
    }

    /* Convert inline code elements to dark colors */
    p code, li code, :not(pre) > code {
      background: #f0f0f0 !important;
      color: #000000 !important;
      border: 1px solid #dddddd !important;
      padding: 1px 4px !important;
    }

    /* Apply clean, high-contrast styles for print highlighting */
    .hljs-keyword, .hljs-selector-tag, .hljs-title, .hljs-section, .hljs-name, .hljs-strong {
      font-weight: bold !important;
      color: #000000 !important; /* Bold black for keywords */
    }
    
    .hljs-comment, .hljs-meta {
      color: #666666 !important; /* Dark gray for comments */
      font-style: italic !important;
    }
    
    .hljs-string, .hljs-built_in, .hljs-literal, .hljs-type, .hljs-addition, .hljs-tag, .hljs-quote, .hljs-number, .hljs-attr, .hljs-variable, .hljs-params {
      color: #222222 !important; /* Dark charcoal for strings, variables, and params */
    }

    /* Format callouts and warnings for print */
    .callout {
      background: #fafafa !important;
      border-color: #000000 !important;
      border-right-width: 4px !important;
      color: #000000 !important;
      page-break-inside: avoid;
      break-inside: avoid;
    }
    
    .callout .title {
      color: #000000 !important;
      font-weight: bold !important;
    }

    /* Format tables for print */
    table {
      background: #ffffff !important;
      border: 1px solid #cccccc !important;
    }
    
    th {
      background: #e6e6e6 !important;
      color: #000000 !important;
      border-bottom: 2px solid #333333 !important;
    }
    
    td {
      border-bottom: 1px solid #cccccc !important;
    }

    /* Format footer section for printing */
    #footer {
      background: transparent !important;
      border-top: 1px solid #cccccc !important;
      padding: 30px 0 !important;
      margin-top: 40px !important;
      text-align: center !important;
      page-break-inside: avoid;
      break-inside: avoid;
    }

    #footer .footer-avatar {
      width: 60px !important;
      height: 60px !important;
      border: 1px solid #333333 !important;
      box-shadow: none !important;
      margin: 0 auto 10px auto !important;
      display: block !important;
    }

    #footer h3 {
      color: #000000 !important;
      font-size: 1.1rem !important;
      font-weight: bold !important;
      margin-bottom: 4px !important;
    }

    #footer .footer-role {
      color: #555555 !important;
      font-size: 9.5pt !important;
      margin-bottom: 12px !important;
    }

    #footer .footer-links {
      display: flex !important;
      flex-direction: column !important; /* Stack links on paper */
      gap: 6px !important;
      align-items: center !important;
      margin-bottom: 15px !important;
    }

    #footer .footer-links a {
      background: transparent !important;
      border: none !important;
      color: #0000ee !important;
      padding: 0 !important;
      box-shadow: none !important;
      text-decoration: none !important;
      display: inline-flex !important;
      align-items: center !important;
      gap: 6px !important;
      font-size: 9.5pt !important;
    }

    #footer .footer-links a svg {
      fill: #000000 !important; /* Darken SVGs */
    }

    /* Print full URLs next to links in footer */
    #footer .footer-links a::after {
      content: ": " attr(href) !important;
      font-size: 8.5pt !important;
      color: #555555 !important;
      text-decoration: underline !important;
      direction: ltr !important;
      unicode-bidi: embed !important;
      margin-left: 4px !important;
    }

    #footer .copyright {
      border-top: 1px solid #e6e6e6 !important;
      padding-top: 10px !important;
      margin-top: 10px !important;
      color: #777777 !important;
      font-size: 8.5pt !important;
    }

    /* Dark blue color and underline for hyperlinks */
    a {
      color: #0000ee !important;
      text-decoration: underline !important;
    }

    /* Prevent page breaks inside important containers */
    .diagram-wrap, .table-wrap, .callout, pre {
      page-break-inside: avoid;
      break-inside: avoid;
    }
  }