/* ============================================================
   MathLabPro — دیزاین‌سیستم
   طراحی: کاغذ شطرنجی مهندسی + جوهر سرمه‌ای + رنگ‌بندی بر اساس مقطع
   ============================================================ */

@font-face {
  font-family: 'Vazir';
  src: url('vazir-font-v16.1.0/Vazir-Medium.woff2') format('woff2'),
       url('vazir-font-v16.1.0/Vazir-Medium.woff') format('woff');
  font-weight: 400 600;
  font-display: swap;
}
@font-face {
  font-family: 'Vazir';
  src: url('vazir-font-v16.1.0/Vazir-Bold.woff2') format('woff2'),
       url('vazir-font-v16.1.0/Vazir-Bold.woff') format('woff');
  font-weight: 700 900;
  font-display: swap;
}

:root {
  --paper:        #eef2f8;
  --grid:         #d3ddea;
  --surface:      #ffffff;
  --surface-2:    #f5f8fc;
  --ink:          #0e2233;
  --ink-2:        #40576d;
  --ink-3:        #7d8fa3;
  --line:         #dbe3ed;
  --brand:        #1f5fd0;
  --brand-ink:    #123b85;
  --brand-soft:   #e3ecfd;
  --amber:        #c77800;
  --amber-soft:   #fdf0d9;
  --teal:         #0c8a77;
  --teal-soft:    #dcf3ef;
  --indigo:       #4f46e5;
  --indigo-soft:  #e8e6fd;
  --danger:       #c0392b;
  --danger-soft:  #fbe6e3;
  --ok:           #17805f;

  --r-s: 8px;
  --r-m: 14px;
  --r-l: 20px;
  --shadow-1: 0 1px 2px rgba(14, 34, 51, .07), 0 6px 18px rgba(14, 34, 51, .06);
  --shadow-2: 0 12px 40px rgba(14, 34, 51, .14);
  --mono: 'JetBrains Mono', 'IBM Plex Mono', ui-monospace, 'Courier New', monospace;
  --sans: 'Vazirmatn', 'Vazir', system-ui, sans-serif;
}

[data-theme="dark"] {
  --paper:        #0c1620;
  --grid:         #16283a;
  --surface:      #122131;
  --surface-2:    #17293c;
  --ink:          #e8eff7;
  --ink-2:        #a9bccf;
  --ink-3:        #74889c;
  --line:         #22374d;
  --brand:        #5a9bff;
  --brand-ink:    #9cc2ff;
  --brand-soft:   #17304f;
  --amber:        #f0b33c;
  --amber-soft:   #38290e;
  --teal:         #3ddbbd;
  --teal-soft:    #0e3730;
  --indigo:       #a5a0ff;
  --indigo-soft:  #241f4d;
  --danger:       #ff8b7d;
  --danger-soft:  #3b1b18;
  --ok:           #45d6a4;
  --shadow-1: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  --shadow-2: 0 16px 50px rgba(0,0,0,.55);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 26px 26px;
  direction: rtl;
  line-height: 1.8;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, h4 { line-height: 1.45; margin: 0 0 .4em; font-weight: 800; letter-spacing: -.01em; }
p { margin: 0 0 .9em; }
a { color: var(--brand); }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; border-radius: 6px; }

.num, code, kbd { font-family: var(--mono); direction: ltr; unicode-bidi: isolate; }

/* ---------------- چیدمان کلی ---------------- */
.app { display: grid; grid-template-columns: 286px minmax(0, 1fr); min-height: 100vh; }

.side {
  position: sticky; top: 0; align-self: start;
  height: 100vh; overflow-y: auto;
  background: var(--surface);
  border-inline-start: 1px solid var(--line);
  padding: 18px 16px 90px;
  z-index: 40;
}
.side::-webkit-scrollbar { width: 8px; }
.side::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }

.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.brand img, .brand .mark {
  width: 42px; height: 42px; border-radius: 12px; flex: none;
  display: grid; place-items: center;
  background: var(--brand); color: #fff;
  font-family: var(--mono); font-weight: 700; font-size: 1.1rem;
  box-shadow: var(--shadow-1);
}
.brand b { font-size: 1.12rem; display: block; letter-spacing: .2px; }
.brand small { color: var(--ink-3); font-size: .74rem; display: block; margin-top: -4px; }

.search { position: relative; margin-bottom: 14px; }
.search input {
  width: 100%; padding: 11px 38px 11px 12px;
  border: 1px solid var(--line); border-radius: var(--r-m);
  background: var(--surface-2); color: var(--ink);
  font-family: var(--sans); font-size: .92rem;
}
.search::before {
  content: "⌕"; position: absolute; right: 12px; top: 50%; transform: translateY(-52%);
  color: var(--ink-3); font-size: 1.25rem;
}

.nav-group { margin-bottom: 6px; }
.nav-group > h5 {
  margin: 14px 8px 6px; font-size: .74rem; font-weight: 700;
  color: var(--ink-3); letter-spacing: .02em;
}
.nav-link {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 8px 10px; margin-bottom: 2px;
  border: 0; border-radius: 10px; background: transparent;
  color: var(--ink-2); font-family: var(--sans); font-size: .93rem;
  text-align: start; cursor: pointer; transition: background .15s, color .15s;
}
.nav-link:hover { background: var(--surface-2); color: var(--ink); }
.nav-link.on { background: var(--brand-soft); color: var(--brand-ink); font-weight: 700; }
.nav-link .ic { width: 22px; text-align: center; font-size: .95rem; flex: none; overflow: hidden; }
.nav-link > span:nth-child(2) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-link .lvl { width: 7px; height: 7px; border-radius: 50%; margin-inline-start: auto; flex: none; }

.lvl-1 { background: var(--teal); }
.lvl-2 { background: var(--amber); }
.lvl-3 { background: var(--indigo); }

/* ---------------- نوار بالا ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 18px;
  background: color-mix(in srgb, var(--paper) 86%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar .crumb { font-size: .9rem; color: var(--ink-3); }
.topbar .crumb b { color: var(--ink); font-weight: 700; }
.topbar .spacer { margin-inline-start: auto; }

.icon-btn {
  width: 40px; height: 40px; flex: none;
  display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--ink);
  cursor: pointer; font-size: 1.05rem; transition: background .15s, transform .1s;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:active { transform: scale(.95); }
#menu-btn { display: none; }

main { padding: 22px clamp(14px, 3vw, 34px) 80px; max-width: 1180px; }

/* ---------------- صفحه خانه ---------------- */
.hero {
  position: relative; overflow: hidden;
  border: 1px solid var(--line); border-radius: var(--r-l);
  background: var(--surface);
  padding: clamp(20px, 4vw, 38px);
  margin-bottom: 22px;
  box-shadow: var(--shadow-1);
}
.hero canvas { position: absolute; inset: 0; width: 100%; height: 100%; opacity: .55; }
.hero-body { position: relative; max-width: 46ch; }
.hero h2 { font-size: clamp(1.5rem, 4vw, 2.3rem); margin-bottom: .3em; }
.hero p { color: var(--ink-2); margin-bottom: 0; }
.hero .stats { display: flex; gap: 22px; margin-top: 18px; flex-wrap: wrap; }
.hero .stats div { line-height: 1.3; }
.hero .stats b { font-family: var(--mono); font-size: 1.5rem; color: var(--brand); display: block; }
.hero .stats span { font-size: .8rem; color: var(--ink-3); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 16px; }
.chip {
  padding: 7px 14px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface);
  color: var(--ink-2); font-family: var(--sans); font-size: .87rem;
  display: inline-flex; align-items: center; gap: 7px;
}
.chip i { width: 8px; height: 8px; border-radius: 50%; font-style: normal; }
.chip.on { background: var(--ink); color: var(--paper); border-color: var(--ink); font-weight: 700; }

.tool-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(215px, 1fr));
}
.tool-card {
  display: block; width: 100%; text-align: start; cursor: pointer;
  border: 1px solid var(--line); border-inline-start: 4px solid var(--brand);
  border-radius: var(--r-m); background: var(--surface);
  padding: 14px 15px; font-family: var(--sans); color: var(--ink);
  transition: box-shadow .16s, transform .16s, border-color .16s;
}
.tool-card:hover { box-shadow: var(--shadow-1); transform: translateY(-2px); }
.tool-card .ic { font-size: 1.3rem; }
.tool-card b { display: block; font-size: .98rem; margin: 4px 0 2px; }
.tool-card span { display: block; font-size: .8rem; color: var(--ink-3); line-height: 1.6; }
.tool-card.l1 { border-inline-start-color: var(--teal); }
.tool-card.l2 { border-inline-start-color: var(--amber); }
.tool-card.l3 { border-inline-start-color: var(--indigo); }

.sec-title { display: flex; align-items: baseline; gap: 10px; margin: 26px 0 12px; }
.sec-title h3 { margin: 0; font-size: 1.05rem; }
.sec-title span { font-size: .8rem; color: var(--ink-3); }

/* ---------------- پنل ابزار ---------------- */
.view { display: none; animation: rise .22s ease-out; }
.view.active { display: block; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

.panel {
  border: 1px solid var(--line); border-radius: var(--r-l);
  background: var(--surface); box-shadow: var(--shadow-1);
  padding: clamp(16px, 3vw, 26px); margin-bottom: 18px;
}
.panel > h2 { font-size: 1.35rem; display: flex; align-items: center; gap: 10px; }
.panel > h2 .ic { font-size: 1.4rem; }
.panel > .lead { color: var(--ink-2); font-size: .92rem; margin-bottom: 18px; }

.badge {
  font-size: .7rem; font-weight: 700; padding: 3px 9px; border-radius: 999px;
  background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line);
}
.badge.b1 { background: var(--teal-soft); color: var(--teal); border-color: transparent; }
.badge.b2 { background: var(--amber-soft); color: var(--amber); border-color: transparent; }
.badge.b3 { background: var(--indigo-soft); color: var(--indigo); border-color: transparent; }

.fields { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.field label { display: block; font-size: .83rem; color: var(--ink-2); margin-bottom: 5px; }
.field.wide { grid-column: 1 / -1; }
.field input[dir="ltr"], .field textarea[dir="ltr"] { text-align: left; }

input[type="text"], input[type="number"], select, textarea {
  width: 100%; padding: 11px 13px;
  border: 1px solid var(--line); border-radius: var(--r-s);
  background: var(--surface-2); color: var(--ink);
  font-family: var(--mono); font-size: 1rem;
  transition: border-color .15s, box-shadow .15s;
}
select, textarea { font-family: var(--sans); }
textarea { min-height: 96px; resize: vertical; line-height: 1.9; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
input::placeholder, textarea::placeholder { color: var(--ink-3); opacity: .8; }
input[type="number"] { -moz-appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.btnrow { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 16px; }
.btn {
  padding: 10px 18px; border: 0; border-radius: var(--r-s); cursor: pointer;
  background: var(--brand); color: #fff;
  font-family: var(--sans); font-size: .92rem; font-weight: 600;
  transition: filter .15s, transform .1s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: var(--surface-2); color: var(--ink); border: 1px solid var(--line); }
.btn.ghost:hover { background: var(--brand-soft); color: var(--brand-ink); }

/* ---------------- خروجی ---------------- */
.result { margin-top: 18px; }
.result:empty { display: none; }
.out {
  border: 1px solid var(--line); border-radius: var(--r-m);
  background: var(--surface-2); padding: 14px 16px; margin-top: 12px;
}
.out.err { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.out .big {
  font-family: var(--mono); font-size: clamp(1.3rem, 4vw, 1.9rem);
  font-weight: 700; color: var(--brand-ink); display: block; direction: ltr; text-align: start;
  word-break: break-all;
}
.out h4 { font-size: .9rem; color: var(--ink-2); margin: 0 0 8px; font-weight: 600; }

.kv { display: grid; gap: 1px; background: var(--line); border-radius: var(--r-s); overflow: hidden; }
.kv div { display: flex; justify-content: space-between; gap: 12px; background: var(--surface); padding: 9px 13px; font-size: .92rem; }
.kv div span:last-child { font-family: var(--mono); font-weight: 700; direction: ltr; }

.steps { counter-reset: s; list-style: none; padding: 0; margin: 10px 0 0; }
.steps li {
  counter-increment: s; position: relative;
  padding: 7px 34px 7px 0; font-size: .92rem; color: var(--ink-2);
  border-inline-start: 2px dashed var(--line); margin-inline-start: 11px;
}
.steps li::before {
  content: counter(s); position: absolute; right: 0; top: 8px;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand-ink);
  font-family: var(--mono); font-size: .72rem; font-weight: 700;
  display: grid; place-items: center;
}

.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; margin-top: 10px; }
.tbl th, .tbl td { border: 1px solid var(--line); padding: 8px 10px; text-align: center; }
.tbl th { background: var(--surface-2); font-weight: 700; font-size: .84rem; }
.tbl td { font-family: var(--mono); direction: ltr; unicode-bidi: isolate; }
.tbl tr:hover td { background: var(--surface-2); }
.scroll-x { overflow-x: auto; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tags span {
  font-family: var(--mono); font-size: .85rem; direction: ltr; unicode-bidi: isolate;
  background: var(--surface); border: 1px solid var(--line);
  padding: 4px 10px; border-radius: 999px;
}
.hint { font-size: .82rem; color: var(--ink-3); margin-top: 10px; }
.hint code { background: var(--surface-2); padding: 2px 6px; border-radius: 5px; font-size: .95em; }

/* ---------------- ماشین حساب ---------------- */
.calc-wrap { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr) 260px; }
.calc-screen {
  background: var(--ink); border-radius: var(--r-m); padding: 16px;
  color: #eef4fb; text-align: left; direction: ltr; min-height: 104px;
  display: flex; flex-direction: column; justify-content: space-between;
}
[data-theme="dark"] .calc-screen { background: #08121c; border: 1px solid var(--line); }
.calc-screen .expr { font-family: var(--mono); font-size: 1.05rem; opacity: .7; word-break: break-all; min-height: 26px; }
.calc-screen .val { font-family: var(--mono); font-size: 2rem; font-weight: 700; word-break: break-all; }
.keypad { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; margin-top: 12px; }
.key {
  padding: 13px 4px; direction: ltr; unicode-bidi: isolate; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface-2); color: var(--ink); cursor: pointer;
  font-family: var(--mono); font-size: .98rem; user-select: none;
  transition: background .12s, transform .08s;
}
.key:hover { background: var(--brand-soft); }
.key:active { transform: scale(.94); }
.key.fn { font-size: .82rem; color: var(--ink-2); }
.key.op { background: var(--brand-soft); color: var(--brand-ink); font-weight: 700; }
.key.acc { background: var(--brand); color: #fff; border-color: transparent; font-weight: 700; }
.key.warn { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.key.on { background: var(--amber); color: #fff; border-color: transparent; }
.key.span2 { grid-column: span 2; }
.history { border: 1px solid var(--line); border-radius: var(--r-m); padding: 12px; background: var(--surface-2); }
.history h4 { margin: 0 0 8px; font-size: .85rem; color: var(--ink-2); }
.history ul { list-style: none; margin: 0; padding: 0; max-height: 320px; overflow-y: auto; }
.history li {
  font-family: var(--mono); font-size: .82rem; direction: ltr; text-align: left;
  padding: 7px 8px; border-radius: 7px; cursor: pointer; color: var(--ink-2);
  border-bottom: 1px dashed var(--line);
}
.history li:hover { background: var(--surface); color: var(--ink); }
.history li b { display: block; color: var(--ink); font-size: .95rem; }

/* ---------------- نمودار ---------------- */
.plot-box { border: 1px solid var(--line); border-radius: var(--r-m); overflow: hidden; background: var(--surface); }
canvas.plot { display: block; width: 100%; height: auto; touch-action: none; cursor: crosshair; }
.fn-rows { display: grid; gap: 8px; }
.fn-row { display: flex; gap: 8px; align-items: center; }
.fn-row .swatch { width: 14px; height: 14px; border-radius: 4px; flex: none; }
.fn-row input { font-size: .95rem; }
.fn-row button { flex: none; }

/* ---------------- هندسه ---------------- */
.geo-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); margin-top: 16px; }
.geo-item {
  border: 1px solid var(--line); border-radius: var(--r-m); background: var(--surface);
  padding: 12px 8px; text-align: center; cursor: pointer; transition: transform .15s, box-shadow .15s;
}
.geo-item:hover { transform: translateY(-3px); box-shadow: var(--shadow-1); }
.geo-item.on { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.geo-item svg { display: block; margin: 0 auto 6px; }
.geo-item .f { font-family: var(--mono); font-size: .82rem; color: var(--brand); margin: 0; direction: ltr; unicode-bidi: isolate; }
.geo-item .n { font-size: .78rem; color: var(--ink-2); }

/* ---------------- جدول ضرب ---------------- */
.mt-grid { display: grid; gap: 3px; overflow-x: auto; }
.mt-cell {
  min-width: 38px; padding: 8px 2px; text-align: center; border-radius: 6px;
  font-family: var(--mono); font-size: .85rem; background: var(--surface-2); cursor: default;
}
.mt-cell.head { background: var(--ink); color: var(--paper); font-weight: 700; }
.mt-cell.hit { background: var(--brand); color: #fff; }
.mt-cell.soft { background: var(--brand-soft); color: var(--brand-ink); }

/* ---------------- آزمون ---------------- */
.quiz-q { font-size: 1.25rem; font-family: var(--mono); direction: ltr; text-align: center; margin: 6px 0 16px; }
.quiz-opts { display: grid; gap: 9px; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
.quiz-opt {
  padding: 13px; border: 1px solid var(--line); border-radius: var(--r-s);
  background: var(--surface-2); font-family: var(--mono); font-size: 1.05rem;
  cursor: pointer; text-align: center;
}
.quiz-opt:hover { border-color: var(--brand); }
.quiz-opt.right { background: var(--teal-soft); border-color: var(--teal); color: var(--teal); font-weight: 700; }
.quiz-opt.wrong { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.quiz-bar { display: flex; gap: 14px; align-items: center; font-size: .88rem; color: var(--ink-2); flex-wrap: wrap; }
.quiz-bar b { font-family: var(--mono); color: var(--ink); }
.progress { height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; flex: 1; min-width: 120px; }
.progress i { display: block; height: 100%; background: var(--brand); transition: width .3s; }

/* ---------------- فرمول‌نامه ---------------- */
.formula-list { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.formula {
  border: 1px solid var(--line); border-radius: var(--r-m); background: var(--surface);
  padding: 12px 14px; border-top: 3px solid var(--brand);
}
.formula.l1 { border-top-color: var(--teal); }
.formula.l2 { border-top-color: var(--amber); }
.formula.l3 { border-top-color: var(--indigo); }
.formula b { display: block; font-size: .88rem; margin-bottom: 6px; }
.formula code { display: block; direction: ltr; font-size: 1rem; color: var(--brand-ink); }
[data-theme="dark"] .formula code { color: var(--brand); }

/* ---------------- ماتریس ---------------- */
.mat { display: inline-grid; gap: 6px; }
.mat input { width: 64px; text-align: center; padding: 9px 4px; }
.mat-wrap { display: flex; gap: 22px; flex-wrap: wrap; align-items: flex-start; }
.mat-wrap > div > h4 { font-size: .85rem; color: var(--ink-2); }

/* ---------------- درباره / راهنما ---------------- */
.about-card { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.social { display: flex; gap: 10px; margin-top: 12px; }
.social a {
  width: 44px; height: 44px; border-radius: 12px; overflow: hidden;
  display: grid; place-items: center; border: 1px solid var(--line); background: var(--surface-2);
  transition: transform .15s;
}
.social a:hover { transform: translateY(-3px); }
.social img { width: 26px; height: 26px; object-fit: contain; }
.faq { border-top: 1px solid var(--line); padding: 12px 0; }
.faq summary { cursor: pointer; font-weight: 700; font-size: .95rem; }
.faq p { margin: 8px 0 0; color: var(--ink-2); font-size: .9rem; }

footer {
  grid-column: 1 / -1;
  border-top: 1px solid var(--line); background: var(--surface);
  padding: 22px; text-align: center; color: var(--ink-3); font-size: .84rem;
}
footer .by { color: var(--ink); margin-top: 6px; }
footer .by b { color: var(--brand); }

/* ---------------- لودر ---------------- */
.loader {
  position: fixed; inset: 0; z-index: 100; background: var(--paper);
  display: grid; place-items: center; transition: opacity .4s;
}
.loader.off { opacity: 0; pointer-events: none; }
.loader .bar { width: 190px; height: 4px; background: var(--line); border-radius: 99px; overflow: hidden; }
.loader .bar i { display: block; width: 40%; height: 100%; background: var(--brand); animation: slide 1s infinite; }
@keyframes slide { 0% { transform: translateX(260%); } 100% { transform: translateX(-100%); } }

.scrim { display: none; position: fixed; inset: 0; background: rgba(8, 18, 28, .5); z-index: 35; }
.scrim.on { display: block; }

/* ---------------- ریسپانسیو ---------------- */
@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }
  #menu-btn { display: grid; }
  .side {
    position: fixed; right: 0; left: auto; top: 0; width: 280px;
    transform: translateX(100%); transition: transform .25s ease;
    box-shadow: var(--shadow-2);
  }
  .side.open { transform: none; }
  .calc-wrap { grid-template-columns: 1fr; }
  .history ul { max-height: 170px; }
}
@media (max-width: 520px) {
  body { background-size: 20px 20px; }
  main { padding: 16px 12px 70px; }
  .panel { padding: 15px 13px; border-radius: var(--r-m); }
  .keypad { gap: 5px; }
  .key { padding: 12px 2px; font-size: .9rem; }
  .tool-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .hero .stats b { font-size: 1.25rem; }
}
@media print {
  .side, .topbar, .btnrow, .chips { display: none !important; }
  body { background: #fff; }
  .panel { box-shadow: none; border-color: #ccc; }
}