/* ─── Self-Hosted Local Fonts (برای دسترسی بدون فیلتر در ایران) ─── */
@font-face {
  font-family: 'Vazirmatn';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/Vazirmatn-Regular.woff2') format('woff2'),
       url('../theme/fonts/Vazirmatn-Regular.woff2') format('woff2'),
       url('../../theme/fonts/Vazirmatn-Regular.woff2') format('woff2');
}

@font-face {
  font-family: 'Vazirmatn';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('fonts/Vazirmatn-Bold.woff2') format('woff2'),
       url('../theme/fonts/Vazirmatn-Bold.woff2') format('woff2'),
       url('../../theme/fonts/Vazirmatn-Bold.woff2') format('woff2');
}

@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/Inter-Regular.woff2') format('woff2'),
       url('../theme/fonts/Inter-Regular.woff2') format('woff2'),
       url('../../theme/fonts/Inter-Regular.woff2') format('woff2');
}

@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('fonts/Inter-Bold.woff2') format('woff2'),
       url('../theme/fonts/Inter-Bold.woff2') format('woff2'),
       url('../../theme/fonts/Inter-Bold.woff2') format('woff2');
}

@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/JetBrainsMono-Regular.woff2') format('woff2'),
       url('../theme/fonts/JetBrainsMono-Regular.woff2') format('woff2'),
       url('../../theme/fonts/JetBrainsMono-Regular.woff2') format('woff2');
}

@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&family=Vazirmatn:wght@300;400;500;600;700;800&display=swap");

:root {
  
  --navy: #1A365D;
  --navy-light: #2B6CB0;
  --navy-dark: #0F2440;
  --amber: #D69E2E;
  --amber-light: #F6E05E;
  --cream: #FDFCF8;
  --cream-dark: #F5F0EB;
  --text-dark: #1A202C;
  --text-muted: #718096;
  --border: #E2E8F0;
  --white: #FFFFFF;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --line-color: rgba(180, 200, 220, 0.4);
  --margin-line: rgba(200, 100, 100, 0.3);
  --font-persian: "Vazirmatn", "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-code: "JetBrains Mono", "Fira Code", "Cascadia Code", "Consolas", monospace;
}

html {
  background-color: var(--cream);
}

body {
  background-color: var(--cream);
  color: var(--text-dark);
  font-family: var(--font-persian);
  font-feature-settings: "ss01";
}

.content {
  font-family: var(--font-persian);
}

.content h1, .content h2, .content h3, .content h4, .content h5, .content h6 {
  font-family: var(--font-persian);
}

.content code, .content pre, .content tt {
  font-family: var(--font-code) !important;
}

.content :not(pre) > code {
  direction: ltr;
  display: inline-block;
  unicode-bidi: isolate;
}


/* ─── Sidebar ─── */
#mdbook-sidebar {
  background-color: var(--navy) !important;
  color: var(--white) !important;
}

#mdbook-sidebar a,
#mdbook-sidebar a:hover {
  color: var(--white) !important;
}

#mdbook-sidebar .chapter li a.active {
  background: rgba(214, 158, 46, 0.2) !important;
  border-right: 3px solid var(--amber);
  color: var(--amber-light) !important;
}

#mdbook-sidebar .chapter li a {
  color: rgba(255,255,255,0.8) !important;
}

#mdbook-sidebar .chapter li a:hover {
  color: var(--white) !important;
  background: rgba(255,255,255,0.1) !important;
}

/* ─── Dynamic Sidebar Scrollspy & Subsection Highlighting ─── */
#mdbook-sidebar .on-this-page {
  padding-right: 6px;
  margin: 6px 0;
  border-right: 1px dashed rgba(214, 158, 46, 0.3);
}

#mdbook-sidebar .on-this-page a {
  color: rgba(255, 255, 255, 0.7) !important;
  font-size: 13.5px !important;
  line-height: 1.6 !important;
  padding: 4px 10px !important;
  border-radius: 4px !important;
  display: block;
  border-right: 3px solid transparent !important;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1) !important;
}

#mdbook-sidebar .on-this-page a:hover {
  color: var(--white) !important;
  background: rgba(255, 255, 255, 0.1) !important;
}

#mdbook-sidebar .on-this-page a.current-header {
  color: var(--amber-light) !important;
  background: rgba(214, 158, 46, 0.25) !important;
  font-weight: 600 !important;
  border-right: 3px solid var(--amber) !important;
  border-radius: 4px 0 0 4px !important;
  padding-right: 12px !important;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}


.sidebar-scrollbox {
  background: var(--navy) !important;
}

/* ─── Custom Sidebar Scrollbar ─── */
.sidebar,
#mdbook-sidebar,
.sidebar-scrollbox,
mdbook-sidebar-scrollbox {
  scrollbar-width: thin;
  scrollbar-color: rgba(214, 158, 46, 0.45) transparent !important;
}

.sidebar::-webkit-scrollbar,
#mdbook-sidebar::-webkit-scrollbar,
.sidebar-scrollbox::-webkit-scrollbar,
mdbook-sidebar-scrollbox::-webkit-scrollbar {
  width: 6px;
  background: transparent !important;
}

.sidebar::-webkit-scrollbar-track,
#mdbook-sidebar::-webkit-scrollbar-track,
.sidebar-scrollbox::-webkit-scrollbar-track,
mdbook-sidebar-scrollbox::-webkit-scrollbar-track {
  background: transparent !important;
}

.sidebar::-webkit-scrollbar-thumb,
#mdbook-sidebar::-webkit-scrollbar-thumb,
.sidebar-scrollbox::-webkit-scrollbar-thumb,
mdbook-sidebar-scrollbox::-webkit-scrollbar-thumb {
  background: rgba(214, 158, 46, 0.45) !important;
  border-radius: 999px;
}

.sidebar::-webkit-scrollbar-thumb:hover,
#mdbook-sidebar::-webkit-scrollbar-thumb:hover,
.sidebar-scrollbox::-webkit-scrollbar-thumb:hover,
mdbook-sidebar-scrollbox::-webkit-scrollbar-thumb:hover {
  background: var(--amber) !important;
}

.sidebar-scrollbox .chapter a {
  color: rgba(255,255,255,0.8) !important;
}

#mdbook-sidebar input {
  border-color: rgba(255,255,255,0.2) !important;
  background: rgba(255,255,255,0.1) !important;
  color: var(--white) !important;
}

#mdbook-sidebar input::placeholder {
  color: rgba(255,255,255,0.5) !important;
}

/* ─── Sidebar header with avatar ─── */
.sidebar-header {
  padding: 16px;
  text-align: center;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 3px solid var(--amber);
  object-fit: cover;
  display: block;
  margin: 0 auto 8px;
  transition: transform 0.2s;
}

.sidebar-avatar:hover {
  transform: scale(1.05);
}

.sidebar-name {
  color: var(--amber-light);
  font-size: 14px;
  font-weight: 600;
  display: block;
  margin-bottom: 4px;
}

.sidebar-github {
  color: rgba(255,255,255,0.6);
  font-size: 12px;
  text-decoration: none;
  display: inline-block;
}

.sidebar-github:hover {
  color: var(--amber-light);
}

/* ─── Nav / header bar ─── */
#mdbook-menu-bar,
.menu-bar {
  background-color: var(--cream) !important;
  border-bottom: 2px solid var(--amber) !important;
}

.menu-bar .icon-button,
.menu-bar a,
.menu-bar .fa-svg,
.menu-title {
  color: var(--navy) !important;
}

.menu-bar .icon-button:hover,
.menu-bar a:hover {
  color: var(--amber) !important;
}

.nav-wide-wrapper,
.nav-wrapper {
  background: var(--white);
  border-bottom: 2px solid var(--amber);
}

.nav-chapters,
.mobile-nav-chapters {
  color: var(--navy) !important;
}

.nav-chapters:hover,
.mobile-nav-chapters:hover {
  color: var(--amber) !important;
  background: var(--cream-dark) !important;
}

/* ─── Content area (notebook ruled lines) ─── */
#mdbook-content {
  position: relative;
  background: var(--white);
  padding: 32px 48px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  margin: 16px 24px;
}

#mdbook-content::before {
  content: "";
  position: absolute;
  top: 0;
  right: 60px;
  bottom: 0;
  width: 2px;
  background: var(--margin-line);
  pointer-events: none;
}

#mdbook-content {
  background-image: repeating-linear-gradient(
    transparent,
    transparent 31px,
    var(--line-color) 31px,
    var(--line-color) 32px
  );
  background-size: 100% 32px;
  background-position: 0 0;
  line-height: 32px;
}

.page {
  background: var(--cream);
}

.content {
  background: transparent !important;
}

/* 980px removed to preserve original notebook margin layout */

/* ─── MathJax & Layout Overflow Prevention ─── */
.MathJax_Display {
  overflow-x: auto !important;
  overflow-y: hidden !important;
  max-width: 100% !important;
  padding: 4px 0 !important;
}

.MathJax {
  max-width: 100%;
}


/* ─── Typography ─── */
.content h1 {
  color: var(--navy);
  border-bottom: 2px solid var(--amber);
  padding-bottom: 8px;
}

.content h2 {
  color: var(--navy);
}

.content h3, .content h4 {
  color: var(--navy-dark);
}

.content a {
  color: var(--navy-light);
}

.content a:hover {
  color: var(--amber);
  text-decoration: underline;
}

/* ─── Tables ─── */
.content table th {
  background: var(--navy);
  color: var(--white);
}

.content table td,
.content table th {
  border-color: var(--border);
}

.content table tr:nth-child(even) {
  background: var(--cream-dark);
}

/* ─── Code blocks ─── */
.content pre {
  background: var(--cream-dark);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.content code {
  background: var(--cream-dark);
  color: var(--navy-dark);
}

/* ─── Blockquotes / Notes ─── */
.content blockquote {
  background: var(--cream);
  border-right: 4px solid var(--amber);
  padding: 14px 20px;
  margin: 16px 0;
  border-radius: 0 6px 6px 0;
  overflow-x: auto;
}

/* ─── Translator-added content (توضیح مترجم / برای درک بهتر) ───
   Marked at runtime by custom.js; always keep translator additions
   in this blockquote form so they get flagged and colored purple,
   distinguishing them from the original author's text. */
.content blockquote.translator-note {
  background: #F5F0FA;
  border-right: 4px solid #7C3AED;
  color: #5B21B6;
}

.content blockquote.translator-note strong:first-of-type {
  color: #6D28D9;
}

/* ─── Cover page (no ruled lines) ─── */
body:has(.cover-container) #mdbook-content {
  background-image: none !important;
  background: var(--white) !important;
}

body:has(.cover-container) #mdbook-content::before {
  display: none !important;
}

/* ─── Cover page ─── */
.cover-container {
  display: flex;
  gap: 40px;
  align-items: flex-start;
  max-width: 900px;
  margin: 0 auto;
  padding: 32px 0;
}

.cover-left {
  flex: 0 0 220px;
  text-align: center;
}

.avatar-circle {
  width: 200px;
  height: 200px;
  border-radius: 50%;
  border: 4px dashed var(--border);
  overflow: hidden;
  position: relative;
  cursor: pointer;
  margin: 0 auto 16px;
  background: var(--cream-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.3s, box-shadow 0.3s;
}

.avatar-circle.dragover {
  border-color: var(--amber);
  box-shadow: 0 0 20px rgba(214, 158, 46, 0.3);
}

.avatar-circle.has-image {
  border: 4px solid var(--amber);
}

.avatar-circle img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.avatar-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 13px;
  pointer-events: none;
  flex-direction: column;
  gap: 8px;
}

.avatar-placeholder::before {
  content: "";
  font-size: 32px;
}

.avatar-circle.has-image .avatar-placeholder {
  display: none;
}

.avatar-label {
  font-size: 18px;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 16px;
}

.cover-right {
  flex: 1;
  min-width: 0;
}

.metadata-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
}

.metadata-table th {
  background: var(--navy);
  color: var(--white);
  padding: 10px 14px;
  text-align: right;
  font-weight: 600;
  width: 140px;
  border: none;
}

.metadata-table td {
  padding: 10px 14px;
  border: 1px solid var(--border);
  background: var(--white);
}

.metadata-table tr:nth-child(even) td {
  background: var(--cream);
}

/* ─── Book title on cover ─── */
.cover-title {
  text-align: center;
  margin-bottom: 24px;
}

.cover-title h1 {
  font-size: 28px;
  color: var(--navy);
  border: none;
  margin-bottom: 4px;
}

.cover-title h2 {
  font-size: 16px;
  color: var(--text-muted);
  font-weight: 400;
  border: none;
}

/* ─── Responsive ─── */
@media (max-width: 1080px) {
  #mdbook-content {
    padding: 20px 24px;
    margin: 12px 12px;
    border-radius: 6px;
  }

  #mdbook-content::before {
    right: 32px;
  }
}

@media (max-width: 768px) {
  .cover-container {
    flex-direction: column;
    align-items: center;
  }
  .cover-left {
    flex: 0 0 auto;
  }
  .avatar-circle {
    width: 150px;
    height: 150px;
  }
  #mdbook-content {
    padding: 16px;
    margin: 8px 8px;
    line-height: 28px;
  }

  #mdbook-content {
    background-image: repeating-linear-gradient(
      transparent,
      transparent 27px,
      var(--line-color) 27px,
      var(--line-color) 28px
    );
    background-size: 100% 28px;
  }

  #mdbook-content::before {
    display: none;
  }
}

@media (max-width: 480px) {
  #mdbook-content {
    padding: 12px 10px;
    margin: 4px 4px;
    line-height: 26px;
  }

  #mdbook-content {
    background-image: repeating-linear-gradient(
      transparent,
      transparent 25px,
      var(--line-color) 25px,
      var(--line-color) 26px
    );
    background-size: 100% 26px;
  }

  .content table {
    font-size: 13px;
  }

  .content h1 {
    font-size: 20px;
  }

  .content h2 {
    font-size: 17px;
  }

  .content h3 {
    font-size: 15px;
  }
}

/* ─── Mobile sidebar: keep content in place when toggled ─── */
@media only screen and (max-width: 1080px) {
  #mdbook-sidebar-toggle-anchor:checked ~ .page-wrapper,
  [dir=rtl] #mdbook-sidebar-toggle-anchor:checked ~ .page-wrapper {
    transform: none !important;
  }
}

/* ─── TOC on cover ─── */
.cover-toc {
  max-width: 900px;
  margin: 16px auto;
  padding: 24px 32px;
  background: var(--white);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.cover-toc h2 {
  color: var(--navy);
  border-bottom: 2px solid var(--amber);
  padding-bottom: 8px;
  margin-top: 24px;
  font-size: 18px;
}

.cover-toc h2:first-child {
  margin-top: 0;
}

.cover-toc ul {
  list-style: none;
  padding: 0;
  margin: 8px 0 16px;
  columns: 2;
  column-gap: 32px;
}

.cover-toc li {
  padding: 4px 0;
  break-inside: avoid;
}

.cover-toc li a {
  color: var(--navy-light);
  text-decoration: none;
  font-size: 14px;
}

.cover-toc li a:hover {
  color: var(--amber);
  text-decoration: underline;
}

@media (max-width: 600px) {
  .cover-toc ul {
    columns: 1;
  }
}

/* ─── Footer ─── */
footer {
  text-align: center;
  padding: 24px;
  color: var(--text-muted);
  font-size: 13px;
  border-top: 1px solid var(--border);
  margin-top: 32px;
}

footer a {
  color: var(--navy-light);
}

/* ─── Night Reading Theme (حالت مطالعه شب) ─── */
html.theme-dark,
html.theme-dark body {
  background-color: #0F172A !important;
  color: #F1F5F9 !important;
}

html.theme-dark .page {
  background: #0F172A !important;
}

html.theme-dark #mdbook-content {
  background: #1E293B !important;
  background-image: none !important;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.45) !important;
  border: 1px solid #334155 !important;
}

html.theme-dark #mdbook-content::before {
  display: none !important;
}

html.theme-dark #mdbook-menu-bar,
html.theme-dark .menu-bar {
  background-color: #1E293B !important;
  border-bottom: 2px solid var(--amber) !important;
}

html.theme-dark .menu-bar .icon-button,
html.theme-dark .menu-bar a,
html.theme-dark .menu-bar .fa-svg,
html.theme-dark .menu-title {
  color: #F8FAFC !important;
}

html.theme-dark .menu-bar .icon-button:hover,
html.theme-dark .menu-bar a:hover {
  color: var(--amber-light) !important;
}

html.theme-dark .nav-wide-wrapper,
html.theme-dark .nav-wrapper {
  background: #1E293B !important;
  border-bottom: 2px solid var(--amber) !important;
}

html.theme-dark .nav-chapters,
html.theme-dark .mobile-nav-chapters {
  color: #F8FAFC !important;
}

html.theme-dark .nav-chapters:hover,
html.theme-dark .mobile-nav-chapters:hover {
  color: var(--amber-light) !important;
  background: #0F172A !important;
}

html.theme-dark .menu-title {
  color: #F8FAFC !important;
}

html.theme-dark .content h1,
html.theme-dark .content h2,
html.theme-dark .content h3,
html.theme-dark .content h4,
html.theme-dark .content h5,
html.theme-dark .content h6 {
  color: #F8FAFC !important;
  border-color: var(--amber) !important;
}

html.theme-dark .content p,
html.theme-dark .content li,
html.theme-dark .content td,
html.theme-dark .content th {
  color: #F1F5F9 !important;
}

html.theme-dark .content a {
  color: #60A5FA !important;
}

html.theme-dark .content a:hover {
  color: var(--amber-light) !important;
}

html.theme-dark .content table th {
  background: #0F172A !important;
  color: #F8FAFC !important;
}

html.theme-dark .content table td,
html.theme-dark .content table th {
  border-color: #334155 !important;
}

html.theme-dark .content table tr:nth-child(even) {
  background: #162032 !important;
}

html.theme-dark .content blockquote {
  background: #162032 !important;
  border-right-color: var(--amber) !important;
  color: #CBD5E1 !important;
}

html.theme-dark .content blockquote.translator-note {
  background: #2E1065 !important;
  border-right-color: #A855F7 !important;
  color: #E9D5FF !important;
}

html.theme-dark .content blockquote.translator-note strong {
  color: #F3E8FF !important;
}

html.theme-dark .content code,
html.theme-dark .content pre,
html.theme-dark .content tt {
  background: #0B1120 !important;
  color: #38BDF8 !important;
  border-color: #334155 !important;
}

html.theme-dark .MathJax,
html.theme-dark .MathJax_Display,
html.theme-dark .MathJax span {
  color: #F1F5F9 !important;
}

html.theme-dark #mdbook-sidebar {
  background-color: #0B1120 !important;
}

html.theme-dark .sidebar-scrollbox {
  background: #0B1120 !important;
}

html.theme-dark .cover-toc {
  background: #1E293B !important;
  border: 1px solid #334155 !important;
}

html.theme-dark .metadata-table td {
  background: #1E293B !important;
  border-color: #334155 !important;
  color: #F1F5F9 !important;
}

html.theme-dark .metadata-table tr:nth-child(even) td {
  background: #162032 !important;
}

html.theme-dark footer {
  border-top-color: #334155 !important;
  color: #94A3B8 !important;
}

/* Hide confusing default mdbook theme list popup */
#mdbook-theme-list {
  display: none !important;
}

