@import url('../../vendor/fonts/fonts.css');

/* ============ ریست ============ */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-h) + 16px);
}

body {
  font-family: var(--font-fa);
  font-size: var(--fs-base);
  line-height: var(--lh-body);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  /* clip (و نه hidden) تا position:sticky هدر سالم بماند */
  overflow-x: clip;
}

img, svg { max-width: 100%; display: block; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
a { color: var(--brand-600); text-decoration: none; }
a:hover { text-decoration: underline; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) a { color: var(--brand-300); }
}
:root[data-theme="dark"] a { color: var(--brand-300); }

:focus-visible {
  outline: 3px solid var(--brand-400);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

h1, h2, h3, h4 { line-height: var(--lh-tight); font-weight: 800; }
h1 { font-size: var(--fs-3xl); letter-spacing: -.02em; }
h2 { font-size: var(--fs-2xl); letter-spacing: -.01em; }
h3 { font-size: var(--fs-lg); }
h4 { font-size: var(--fs-md); }

::selection { background: var(--brand-200); color: var(--brand-900); }

/* اسکرول‌بار */
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--r-full);
  border: 3px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-mute); background-clip: content-box; }

/* ============ همه چیزِ کد از راست‌به‌چپ مصون است ============ */
code, pre, kbd, samp, .ltr, .code-block, .terminal, .CodeMirror {
  direction: ltr;
  text-align: left;
  unicode-bidi: isolate;
  font-family: var(--font-mono);
  font-variant-ligatures: none;
}

/* کد درون‌خطی */
:not(pre) > code {
  background: var(--surface-3);
  color: var(--text);
  padding: .1em .42em;
  border-radius: var(--r-xs);
  font-size: .88em;
  border: 1px solid var(--border);
  display: inline-block;
  vertical-align: baseline;
  line-height: 1.55;
  max-width: 100%;
  overflow-wrap: break-word;
}

kbd {
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: var(--r-xs);
  padding: .1em .45em;
  font-size: .82em;
  white-space: nowrap;
}

/* ============ چیدمان ============ */
.wrap { width: 100%; max-width: var(--maxw); margin-inline: auto; padding-inline: var(--sp-5); }
.wrap-narrow { max-width: 920px; }
.grow { flex: 1; }

/* ============ هدر ============ */
.site-header {
  position: sticky; top: 0; z-index: 50;
  height: var(--header-h);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}
.site-header .wrap { height: 100%; display: flex; align-items: center; gap: var(--sp-4); }

.logo {
  display: flex; align-items: center; gap: var(--sp-2);
  font-weight: 900; font-size: 1.05rem; color: var(--text);
  text-decoration: none; flex-shrink: 0;
}
.logo:hover { text-decoration: none; }
.logo-mark {
  width: 32px; height: 32px; border-radius: 9px;
  background: linear-gradient(135deg, var(--brand-500), var(--violet-500));
  display: grid; place-items: center; font-size: 17px;
  box-shadow: var(--sh-brand);
}
.logo-text small { display: block; font-size: .62rem; font-weight: 600; color: var(--text-mute); line-height: 1; margin-top: 2px; }

.nav { display: flex; align-items: center; gap: var(--sp-1); margin-inline-start: auto; }
.nav a {
  color: var(--text-soft); font-weight: 600; font-size: var(--fs-sm);
  padding: 7px 13px; border-radius: var(--r-full); text-decoration: none;
  white-space: nowrap; transition: background .15s, color .15s;
}
.nav a:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--brand-500); color: #fff; }

.header-tools { display: flex; align-items: center; gap: var(--sp-2); }

.icon-btn {
  width: 36px; height: 36px; border-radius: var(--r-full);
  display: grid; place-items: center; color: var(--text-soft);
  border: 1px solid var(--border); background: var(--surface);
  font-size: 15px; flex-shrink: 0; transition: background .15s;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }

.nav-toggle { display: none; }

@media (max-width: 780px) {
  .nav {
    position: fixed; inset-block-start: var(--header-h); inset-inline: 0;
    flex-direction: column; align-items: stretch; gap: 2px;
    background: var(--surface); border-bottom: 1px solid var(--border);
    padding: var(--sp-3); box-shadow: var(--sh-lg);
    transform: translateY(-8px); opacity: 0; pointer-events: none;
    transition: opacity .16s, transform .16s;
  }
  .nav.open { opacity: 1; transform: none; pointer-events: auto; }
  .nav a { padding: 11px 14px; border-radius: var(--r-sm); font-size: var(--fs-base); }
  .nav-toggle { display: grid; }
  .header-tools { margin-inline-start: auto; }
}

/* ============ دکمه‌ها ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  padding: 10px 20px; border-radius: var(--r-full);
  font-weight: 700; font-size: var(--fs-sm); line-height: 1.4;
  border: 1px solid transparent; text-decoration: none;
  transition: transform .12s, box-shadow .15s, background .15s, border-color .15s;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--brand-500); color: #fff; box-shadow: var(--sh-brand); }
.btn-primary:hover:not(:disabled) { background: var(--brand-600); }

.btn-accent { background: var(--accent-500); color: #2a1c02; box-shadow: 0 8px 22px rgba(245,165,36,.3); }
.btn-accent:hover:not(:disabled) { background: var(--accent-400); }

.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); border-color: var(--text-mute); }

.btn-quiet { background: transparent; color: var(--text-soft); }
.btn-quiet:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }

.btn-sm { padding: 6px 13px; font-size: var(--fs-xs); }
.btn-lg { padding: 14px 30px; font-size: var(--fs-md); }

/* ============ کارت و تراشه ============ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-sm);
}

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: var(--r-full);
  font-size: var(--fs-xs); font-weight: 700;
  background: var(--surface-3); color: var(--text-soft);
}
.chip-brand { background: var(--info-bg); color: var(--info); }
.chip-ok    { background: var(--ok-bg); color: var(--ok); }
.chip-warn  { background: var(--warn-bg); color: var(--warn); }
.chip-danger{ background: var(--danger-bg); color: var(--danger); }

/* ============ فوتر ============ */
.site-footer {
  margin-top: var(--sp-10);
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding-block: var(--sp-7);
  color: var(--text-mute);
  font-size: var(--fs-sm);
}
.site-footer .wrap { display: flex; flex-wrap: wrap; gap: var(--sp-4); align-items: center; justify-content: space-between; }
.site-footer nav { display: flex; gap: var(--sp-4); flex-wrap: wrap; }

/* ============ بلوک کد ============ */
.code-block {
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: var(--r-md);
  overflow: hidden;
  margin-block: var(--sp-4);
  box-shadow: var(--sh-sm);
}
.code-head {
  direction: rtl; text-align: right;
  display: flex; align-items: center; gap: var(--sp-2);
  padding: 7px 12px 7px 10px;
  background: var(--code-bg-2);
  border-bottom: 1px solid var(--code-border);
  font-family: var(--font-fa);
  font-size: var(--fs-xs);
  color: #9aa3c4;
  flex-wrap: wrap;
}
.code-head .dots { display: flex; gap: 5px; flex-shrink: 0; }
.code-head .dots i { width: 10px; height: 10px; border-radius: 50%; display: block; }
.code-head .dots i:nth-child(1) { background: #ff5f57; }
.code-head .dots i:nth-child(2) { background: #febc2e; }
.code-head .dots i:nth-child(3) { background: #28c840; }
.code-head .caption { font-weight: 600; color: #b9c1de; margin-inline-start: 4px; }
.code-actions { margin-inline-start: auto; display: flex; gap: 6px; }
.code-actions button {
  font-family: var(--font-fa);
  font-size: var(--fs-xs); font-weight: 700;
  color: #c3cae6; background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.11);
  padding: 4px 11px; border-radius: var(--r-full);
  transition: background .15s, color .15s;
}
.code-actions button:hover { background: rgba(255,255,255,.16); color: #fff; }
.code-actions .to-pg { background: rgba(63,97,242,.28); border-color: rgba(120,150,255,.4); color: #cfdaff; }
.code-actions .to-pg:hover { background: rgba(63,97,242,.5); color: #fff; }

.code-block pre {
  margin: 0; padding: 14px 16px;
  overflow-x: auto;
  font-size: .875rem; line-height: 1.75;
  color: var(--code-text);
  tab-size: 4;
}
.code-block pre code { background: none; border: none; padding: 0; font-size: inherit; display: block; }

.code-out {
  direction: ltr; text-align: left;
  border-top: 1px dashed var(--code-border);
  background: rgba(255,255,255,.03);
  padding: 10px 16px 12px;
  font-family: var(--font-mono);
  font-size: .84rem; line-height: 1.7;
  color: #9fe8b5;
  white-space: pre-wrap;
  overflow-x: auto;
}
.code-out .out-label {
  direction: rtl; text-align: right;
  display: block; font-family: var(--font-fa);
  font-size: var(--fs-xs); color: #7d87a8;
  margin-bottom: 4px; font-weight: 700;
}

/* رنگ‌آمیزی نحوی */
.tok-kw      { color: var(--code-kw); font-weight: 600; }
.tok-str     { color: var(--code-str); }
.tok-num     { color: var(--code-num); }
.tok-com     { color: var(--code-comment); font-style: italic; }
.tok-fn      { color: var(--code-fn); }
.tok-builtin { color: var(--code-builtin); }
.tok-op      { color: var(--code-op); }
.tok-self    { color: #ff9f6b; font-style: italic; }

/* ============ ابزار ============ */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.toast {
  position: fixed; inset-block-end: 24px; inset-inline-start: 50%;
  transform: translateX(50%) translateY(12px);
  background: var(--text); color: var(--bg);
  padding: 10px 22px; border-radius: var(--r-full);
  font-size: var(--fs-sm); font-weight: 700; z-index: 200;
  box-shadow: var(--sh-lg); opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translateX(50%) translateY(0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  html { scroll-behavior: auto; }
}
