@font-face { font-family: 'Vazirmatn'; src: url('../fonts/Vazirmatn-Regular.ttf') format('truetype'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Vazirmatn'; src: url('../fonts/Vazirmatn-Bold.ttf') format('truetype'); font-weight: 700; font-display: swap; }

:root {
  --ink: #1b2330; --muted: #5a6575; --faint: #8a94a3;
  --bg: #f3f5f8; --surface: #fff; --line: #dce2ea; --line2: #e9edf2;
  --accent: #0b63c4; --accent-ink: #fff; --accent-soft: #e7f0fb;
  --ok: #1f8a4c; --ok-soft: #e6f5ec; --warn: #a15c00; --warn-soft: #fff4e0; --bad: #c0262d; --bad-soft: #fdecec;
  --code-bg: #f6f8fa;
  --radius: 10px;
  --fa: 'Vazirmatn', system-ui, sans-serif;
  --en: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.85 var(--fa); }
body.ltr { font-family: var(--en); line-height: 1.6; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.ltr, [dir="ltr"] { direction: ltr; text-align: left; }
code, kbd, .mono { font-family: var(--mono); font-size: 0.92em; }
code { background: var(--code-bg); padding: 0.1em 0.35em; border-radius: 4px; direction: ltr; unicode-bidi: isolate; }

/* header */
.top { background: #13233a; color: #fff; position: sticky; top: 0; z-index: 20; }
.top .in { max-width: 1240px; margin: 0 auto; display: flex; align-items: center; gap: 18px; padding: 10px 18px; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 17px; color: #fff; display: flex; gap: 10px; align-items: center; }
.brand:hover { text-decoration: none; }
.brand .logo { width: 30px; height: 30px; border-radius: 7px; background: #2b78d8; display: grid; place-items: center; font: 700 14px var(--en); }
.nav { display: flex; gap: 4px; flex-wrap: wrap; margin-inline-start: auto; }
.nav a { color: #c9d6e8; padding: 6px 12px; border-radius: 8px; font-size: 15px; }
.nav a:hover, .nav a.on { background: rgba(255,255,255,0.1); color: #fff; text-decoration: none; }

main { max-width: 1240px; margin: 0 auto; padding: 22px 18px 60px; }
main.narrow { max-width: 900px; }
h1 { font-size: 28px; line-height: 1.4; margin: 6px 0 10px; }
h2 { font-size: 21px; margin: 34px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
h3 { font-size: 17px; margin: 22px 0 6px; }
p { margin: 8px 0; }
.lead { color: var(--muted); font-size: 17px; }
.small { font-size: 13px; color: var(--muted); }
.en { font-family: var(--en); direction: ltr; unicode-bidi: isolate; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 6px 12px; border-radius: 8px; font: inherit; font-size: 14px; cursor: pointer; line-height: 1.5; }
.btn:hover { border-color: #b9c4d2; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #0a56aa; }
.btn.small { padding: 3px 9px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: default; }
select, input[type=number], input[type=text] { font: inherit; font-size: 14px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--ink); }
input[type=number] { width: 90px; }
label { font-size: 14px; }

.tag { display: inline-block; font: 600 12px var(--en); padding: 2px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); }

/* boxes inside the notes */
.box { border-radius: var(--radius); padding: 12px 16px; margin: 14px 0; border: 1px solid; }
.box > :first-child { margin-top: 0; }
.box.formula { background: #eef5ff; border-color: #bcd5f5; }
.box.answer { background: var(--ok-soft); border-color: #b5dfc5; }
.box.warn { background: var(--warn-soft); border-color: #f1d29d; }
.box.note { background: #f6f7f9; border-color: var(--line); }
.box-title { font-weight: 700; margin-bottom: 4px; }
.box.formula .box-title { color: #1d4f91; }
.box.answer .box-title { color: var(--ok); }
.box.warn .box-title { color: var(--warn); }

table.data { border-collapse: collapse; width: 100%; font-size: 14px; background: #fff; direction: ltr; }
table.data th, table.data td { border: 1px solid var(--line); padding: 5px 9px; text-align: center; font-family: var(--en); }
table.data th { background: #f3f6fa; font-weight: 600; }
table.data td.l { text-align: left; }
.table-wrap { overflow-x: auto; }

.katex { font-size: 1.06em; direction: ltr; unicode-bidi: isolate; }
.katex-display { margin: 0.6em 0; overflow-x: auto; overflow-y: hidden; direction: ltr; }

/* experiment cards on the home page */
.exp-card { display: flex; flex-direction: column; gap: 6px; color: var(--ink); transition: border-color 0.15s, box-shadow 0.15s; }
.exp-card:hover { border-color: #a9bfd9; box-shadow: 0 4px 14px rgba(20,40,80,0.07); text-decoration: none; }
.exp-card .num { font: 700 13px var(--en); color: var(--accent); }
.exp-card .t { font-weight: 700; font-size: 17px; }
.exp-card .tf { font-family: var(--en); direction: ltr; text-align: right; color: var(--muted); font-size: 14px; }
.tools { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); margin: 18px 0 8px; }
.tool { display: flex; gap: 14px; align-items: flex-start; color: var(--ink); }
.tool:hover { text-decoration: none; border-color: #a9bfd9; }
.tool .ic { flex: none; width: 46px; height: 46px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.tool b { display: block; font-size: 17px; }

/* widgets inside experiment pages */
.widget { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin: 16px 0; direction: ltr; text-align: left; font-family: var(--en); line-height: 1.5; }
.widget .wtitle { font-weight: 650; margin-bottom: 8px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.widget .controls { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; margin: 6px 0 10px; font-size: 14px; }
.widget .controls input[type=range] { width: 200px; }
.widget .row2 { display: grid; gap: 14px; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
@media (max-width: 820px) { .widget .row2 { grid-template-columns: 1fr; } }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-family: var(--mono); }

.code-block { position: relative; margin: 14px 0; direction: ltr; text-align: left; }
.code-block pre { background: #0f1b2b; color: #e3ebf6; border-radius: var(--radius); padding: 14px 16px; overflow-x: auto; margin: 0; font: 13.5px/1.55 var(--mono); }
.code-block .actions { display: flex; gap: 8px; margin-top: 8px; }
.run-out { margin-top: 10px; }

/* the MATLAB page */
.mat-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; direction: ltr; }
@media (max-width: 980px) { .mat-layout { grid-template-columns: 1fr; } }
.pane { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 0; }
.pane-head { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--line2); flex-wrap: wrap; font-size: 14px; }
.pane-head .title { font-weight: 650; margin-inline-end: auto; }
.pane-head select { max-width: 230px; }
.editor-wrap .CodeMirror { height: 470px; font: 14px/1.5 var(--mono); border-radius: 0 0 var(--radius) var(--radius); }
.console { font: 13.5px/1.45 var(--mono); padding: 10px 12px; overflow: auto; max-height: 680px; min-height: 300px; white-space: pre-wrap; word-break: break-word; }
.console .cmd { color: #0b63c4; }
.console .err { color: var(--bad); }
.console .warn { color: var(--warn); }
.console .fig { margin: 8px 0 12px; border: 1px solid var(--line2); border-radius: 8px; padding: 6px; white-space: normal; background: #fff; }
.fig-head { display: flex; gap: 8px; align-items: center; font: 12px var(--en); color: var(--muted); margin-bottom: 2px; flex-wrap: wrap; }
.fig-head label { font-size: 12px; display: inline-flex; gap: 3px; align-items: center; }
.cmdline { display: flex; border-top: 1px solid var(--line2); align-items: center; }
.cmdline span { padding: 0 6px 0 12px; color: var(--muted); font-family: var(--mono); }
.cmdline input { flex: 1; border: 0; outline: 0; padding: 10px 6px; font: 14px var(--mono); border-radius: 0 0 var(--radius) 0; }
.workspace { font: 13px var(--mono); padding: 8px 12px; }
.workspace td { padding: 1px 12px 1px 0; vertical-align: top; }

/* bench page */
.bench-top { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 8px 0 12px; direction: ltr; font-family: var(--en); }
.bench-top .grow { flex: 1; }
.bench-host { background: #d9dbd5; border-radius: 14px; padding: 6px; border: 1px solid #c4c7bf; direction: ltr; }
.bench-svg { width: 100%; height: auto; display: block; user-select: none; -webkit-user-select: none; touch-action: none; outline: none; font-family: var(--en); }
.plate { fill: #e9e9e3; stroke: #9c9c95; stroke-width: 2; }
.plate-line { fill: none; stroke: #8b8f8a; stroke-width: 1.4; }
.section { fill: #ecece7; stroke: #4c514f; stroke-width: 1.6; }
.section.inactive { stroke-dasharray: 5 4; }
.section-title { font: 700 13px var(--en); fill: #2c3130; letter-spacing: 0.06em; }
.board-label { fill: #2c3130; font-family: var(--en); letter-spacing: 0.04em; }
.block-box { fill: #f7f7f3; stroke: #4c514f; stroke-width: 1.4; }
.block-box.inactive { stroke-dasharray: 4 3; fill: #f1f1ec; }
.block-title { font: 600 11.5px var(--en); fill: #3a3f3e; letter-spacing: 0.05em; }
.block-sym { font: italic 600 15px 'Times New Roman', serif; fill: #1f2423; }
.trace { stroke: #4c514f; stroke-width: 1.4; }
.junction { fill: #f7f7f3; stroke: #3a3f3e; stroke-width: 1.8; }
.junction-mark { stroke: #3a3f3e; stroke-width: 1.8; }
.block.bad .block-box, .block.bad .junction { stroke: var(--bad); stroke-width: 3; }
.led { fill: #6fb36f; opacity: 0.35; }
.slider-track { stroke: #6b6f6d; stroke-width: 3; }
.slider-knob { fill: #c8c9c4; stroke: #6b6f6d; }
.gnd { stroke: #3a3f3e; stroke-width: 2; fill: none; }
.instrument { fill: #2b3036; stroke: #15181b; stroke-width: 2; }
.instrument-title { font: 700 14px var(--en); fill: #d8dde3; letter-spacing: 0.08em; }
.instrument + text, .instrument ~ .jack-label { fill: #d8dde3; }
.jack-hit { fill: transparent; }
.jack-ring { fill: #26292b; stroke: #050505; stroke-width: 2.5; }
.jack.out .jack-ring { fill: #5b1d1d; stroke: #2a0909; }
.jack-ring.dead { fill: #6d706e; stroke: #4c4f4d; }
.jack-hole { fill: #0c0c0c; }
.jack-plug { fill: transparent; pointer-events: none; }
.jack { cursor: crosshair; }
.jack:hover .jack-ring, .jack:focus .jack-ring { stroke: #ffb703; stroke-width: 4; }
.jack.pending .jack-ring { stroke: #ffb703; stroke-width: 5; filter: url(#glow); }
.jack.bad .jack-ring { stroke: var(--bad); stroke-width: 5; }
.jack-label { font: 600 11px var(--en); fill: #3a3f3e; }
.jack-label.light { fill: #d8dde3; }
.knob { cursor: ns-resize; }
.knob-tick { stroke: #555; stroke-width: 1.4; }
.knob-body { stroke: #000; stroke-width: 1; }
.knob-ptr { stroke: #fff; stroke-width: 3; stroke-linecap: round; }
.knob:focus .knob-body { stroke: #ffb703; stroke-width: 3; }
.knob-val { font: 600 11.5px var(--en); fill: #0b4f9c; }
.switch { cursor: pointer; }
.switch-body { fill: #cfd1cc; stroke: #5d615f; }
.switch-thumb { fill: #fff; stroke: #5d615f; transition: x 0.15s; }
.switch-label { font: 600 10.5px var(--en); fill: #666; pointer-events: none; }
.switch-label.on { fill: #0b4f9c; }
.wire { cursor: pointer; }
.wire-hit { stroke: transparent; stroke-width: 16; fill: none; }
.wire-shadow { stroke: rgba(0,0,0,0.35); stroke-width: 7.5; fill: none; stroke-linecap: round; }
.wire-core { stroke-width: 5; fill: none; stroke-linecap: round; }
.wire.selected .wire-shadow { stroke: #ffb703; stroke-width: 11; }
.wire.bad .wire-core { stroke-dasharray: 8 6; }
.rubber { stroke: #ffb703; stroke-width: 4; fill: none; stroke-dasharray: 8 6; pointer-events: none; }
.wire, .wire * { pointer-events: stroke; }

.instruments { display: grid; grid-template-columns: minmax(250px, 320px) minmax(0, 1fr); gap: 14px; margin-top: 14px; direction: ltr; font-family: var(--en); line-height: 1.45; }
@media (max-width: 900px) { .instruments { grid-template-columns: 1fr; } }
.inst { background: #23282e; color: #dfe5ec; border-radius: 12px; padding: 12px 14px; border: 1px solid #111; }
.inst h3 { margin: 0 0 8px; font-size: 14px; letter-spacing: 0.08em; color: #aab6c3; }
.inst label { font-size: 13px; color: #c3ccd6; display: flex; align-items: center; gap: 6px; }
.inst select, .inst input { background: #111519; color: #f1f4f7; border-color: #3b444e; }
.inst .btn { background: #343b44; border-color: #46505b; color: #eef2f6; }
.inst .btn:hover { border-color: #7d8a98; }
.inst .btn.on { background: #0b63c4; border-color: #0b63c4; }
.seg { display: inline-flex; border: 1px solid #46505b; border-radius: 8px; overflow: hidden; }
.seg button { background: #343b44; color: #dfe5ec; border: 0; padding: 5px 10px; font: 13px var(--en); cursor: pointer; }
.seg button + button { border-left: 1px solid #46505b; }
.seg button.on { background: #0b63c4; color: #fff; }
.gen-display { background: #0d2317; color: #6dff9c; font: 22px var(--mono); padding: 8px 10px; border-radius: 6px; margin: 8px 0; text-align: right; }
.gen-display small { font-size: 13px; color: #49b874; display: block; }
.ctl-grid { display: grid; grid-template-columns: auto 1fr; gap: 8px 10px; align-items: center; font-size: 13px; }
.stepper { display: inline-flex; align-items: center; gap: 4px; }
.stepper .btn { padding: 2px 8px; min-width: 28px; justify-content: center; }
.stepper output { min-width: 86px; text-align: center; font: 13px var(--mono); }
.scope-screen { background: #000; border-radius: 6px; overflow: hidden; }
.scope-screen canvas { display: block; touch-action: none; }
.scope-ctl { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px; margin-top: 10px; }
.scope-ctl fieldset { border: 1px solid #3b444e; border-radius: 8px; padding: 6px 10px 8px; margin: 0; }
.scope-ctl legend { font-size: 12px; color: #aab6c3; padding: 0 4px; letter-spacing: 0.06em; }
.scope-ctl .ch1 legend { color: #f2d400; } .scope-ctl .ch2 legend { color: #00d5e6; }
.meas { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px; margin-top: 10px; font: 12.5px var(--mono); }
.meas div { background: #15191d; border-radius: 6px; padding: 6px 8px; }
.meas .c1 { color: #f2d400; } .meas .c2 { color: #00d5e6; } .meas .cur { color: #ff9cf3; }
.status { margin: 10px 0 0; font: 14px var(--en); direction: ltr; text-align: left; }
.status .e { color: var(--bad); background: var(--bad-soft); border: 1px solid #f3c2c4; padding: 6px 10px; border-radius: 8px; margin: 4px 0; }
.status .w { color: var(--warn); background: var(--warn-soft); border: 1px solid #f1d29d; padding: 6px 10px; border-radius: 8px; margin: 4px 0; }
.status .i { color: var(--muted); }
.help { font-size: 14px; }
.help li { margin: 3px 0; }

/* experiment page */
.exp-head { display: flex; gap: 12px; align-items: baseline; flex-wrap: wrap; }
.exp-head .num { font: 700 15px var(--en); color: #fff; background: var(--accent); border-radius: 8px; padding: 2px 10px; }
.toc { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 0; }
.toc a { font-size: 14px; padding: 3px 10px; border: 1px solid var(--line); border-radius: 99px; background: #fff; color: var(--muted); }
.toc a:hover { color: var(--accent); border-color: #a9bfd9; text-decoration: none; }
.pager { display: flex; justify-content: space-between; gap: 10px; margin-top: 40px; }
.figure-img { display: block; max-width: 100%; border-radius: 8px; border: 1px solid var(--line); }
footer { color: var(--faint); font-size: 13px; text-align: center; padding: 20px; }
@media (max-width: 600px) { h1 { font-size: 23px; } main { padding: 16px 12px 50px; } }

.chain { direction: ltr; unicode-bidi: isolate; display: inline-block; font: 600 13px var(--en); background: #eef2f7; border: 1px solid #d5dde8; color: #1d3b66; padding: 1px 8px; border-radius: 6px; margin: 2px 0; line-height: 1.6; }
