/* حلّها — التصميم */
:root {
  --bg: #0a0e1c; --bg2: #10173a; --card: #141b33; --card2: #1a2344; --line: rgba(255,255,255,.08);
  --text: #eef1ff; --muted: #8e97b8; --faint: #5d6688;
  --accent: #7c5cff; --accent2: #22d3ee; --gold: #ffb547; --gold2: #ff8a3d; --danger: #ff5d7a; --ok: #34d399;
  --key: #19213f; --key-hi: #232d57; --key-op: #2b2470; --key-fn: #131a35; --key-text: #eef1ff;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
  --grid: rgba(255,255,255,.05); --grid2: rgba(255,255,255,.11); --axis: rgba(255,255,255,.55);
  --font: "IBM Plex Sans Arabic", "SF Arabic", "Segoe UI", Tahoma, system-ui, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f3f4fb; --bg2: #e7e9ff; --card: #ffffff; --card2: #f1f2fb; --line: rgba(20,24,60,.09);
  --text: #141833; --muted: #646b8c; --faint: #9aa0bd;
  --key: #ffffff; --key-hi: #eef0ff; --key-op: #e6e1ff; --key-fn: #f4f5fc; --key-text: #141833;
  --shadow: 0 10px 30px rgba(30,40,90,.12);
  --grid: rgba(20,24,60,.05); --grid2: rgba(20,24,60,.12); --axis: rgba(20,24,60,.6);
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); overscroll-behavior: none; }
body { background: radial-gradient(1200px 600px at 100% -10%, rgba(124,92,255,.18), transparent 60%), radial-gradient(900px 500px at -10% 110%, rgba(34,211,238,.10), transparent 60%), var(--bg); }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
input, textarea, select { font: inherit; color: var(--text); }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

#app { max-width: 540px; margin: 0 auto; height: 100dvh; display: flex; flex-direction: column; position: relative; overflow: hidden; }
@media (min-width: 700px) { #app { border-inline: 1px solid var(--line); box-shadow: var(--shadow); } }

/* الشريط العلوي */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: calc(env(safe-area-inset-top, 0px) + 8px) 14px 6px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { border-radius: 10px; box-shadow: 0 4px 14px rgba(124,92,255,.45); }
.brand b { display: block; font-size: 1.15rem; line-height: 1.1; letter-spacing: -.2px; }
.brand small { color: var(--muted); font-size: .72rem; }
.top-actions { display: flex; gap: 6px; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; color: var(--muted); background: var(--card); border: 1px solid var(--line); }
.icon-btn:active { transform: scale(.94); }

#views { flex: 1; position: relative; min-height: 0; }
.view { position: absolute; inset: 0; display: none; flex-direction: column; }
.view.active { display: flex; animation: fadeIn .25s ease; }
.view.scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; }
@keyframes fadeIn { from { transform: translateY(6px); } }

/* شريط التبويبات */
.tabbar { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 6px 10px calc(var(--safe-b) + 6px); background: color-mix(in srgb, var(--bg) 80%, transparent); backdrop-filter: blur(14px); border-top: 1px solid var(--line); }
.tab { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; border-radius: 14px; color: var(--faint); font-size: .72rem; font-weight: 600; transition: .2s; }
.tab svg { width: 22px; height: 22px; }
.tab.active { color: var(--text); background: linear-gradient(135deg, rgba(124,92,255,.22), rgba(34,211,238,.12)); }
.tab.active svg { color: var(--accent2); }

/* الأزرار العامة */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 12px 18px; border-radius: 14px; font-weight: 600; background: var(--card2); border: 1px solid var(--line); transition: transform .1s; }
.btn:active { transform: scale(.96); }
.btn.primary { background: linear-gradient(135deg, var(--accent), #5b3df5); color: #fff; border: 0; box-shadow: 0 6px 18px rgba(124,92,255,.35); }
.btn.gold { background: linear-gradient(135deg, var(--gold), var(--gold2)); color: #2a1600; border: 0; box-shadow: 0 6px 18px rgba(255,150,60,.3); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 8px 14px; font-size: .88rem; border-radius: 12px; }
.btn.block { width: 100%; }
.btn.danger { color: var(--danger); }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 5px 11px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--card); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.chip svg { width: 14px; height: 14px; }
.chip.on { color: var(--text); border-color: color-mix(in srgb, var(--accent) 60%, transparent); background: color-mix(in srgb, var(--accent) 18%, var(--card)); }
.chip.glow { color: #fff; background: linear-gradient(135deg, var(--accent), #4f8cff); border: 0; }
.spacer { flex: 1; }

/* ======= الحاسبة ======= */
.screen { flex: 1 1 auto; min-height: 150px; margin: 4px 12px 8px; padding: 10px 14px 12px; border-radius: 24px; background: linear-gradient(160deg, var(--card2), var(--card)); border: 1px solid var(--line); display: flex; flex-direction: column; position: relative; overflow-x: hidden; overflow-y: auto; scrollbar-width: none; box-shadow: var(--shadow); }
.screen::after { content: ""; position: absolute; inset: auto -40% -60% auto; width: 260px; height: 260px; background: radial-gradient(circle, rgba(124,92,255,.18), transparent 70%); pointer-events: none; }
.screen-top { display: flex; gap: 6px; align-items: center; position: relative; z-index: 1; }
.prev { margin-top: auto; color: var(--faint); font-size: 1rem; min-height: 1.4em; text-align: end; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; cursor: pointer; }
.expr { font-size: 2.1rem; line-height: 1.5; min-height: 1.6em; display: flex; justify-content: flex-start; align-items: flex-end; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; position: relative; z-index: 1; }
.expr::-webkit-scrollbar { display: none; }
.expr.md { font-size: 1.65rem; } .expr.sm { font-size: 1.3rem; }
.expr .empty { color: var(--faint); font-size: 1rem; }
.result { font-size: 1.35rem; color: var(--muted); min-height: 1.6em; text-align: start; font-weight: 600; position: relative; z-index: 1; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.result.final { font-size: 2.5rem; color: var(--text); font-weight: 700; animation: pop .28s cubic-bezier(.2,1.4,.4,1); }
.result.final .num { background: linear-gradient(90deg, var(--text), color-mix(in srgb, var(--accent2) 60%, var(--text))); -webkit-background-clip: text; background-clip: text; color: transparent; }
.result.err { color: var(--danger); font-size: 1rem; font-weight: 600; animation: shake .35s; }
.result .eq { color: var(--faint); font-weight: 400; }
.result .lbl { font-size: 1rem; color: var(--muted); font-weight: 600; }
@keyframes pop { from { transform: scale(.9); opacity: .4; } }
@keyframes shake { 20%, 60% { transform: translateX(6px); } 40%, 80% { transform: translateX(-6px); } }
.extra { display: flex; gap: 6px; flex-wrap: wrap; min-height: 0; position: relative; z-index: 1; margin-top: 4px; }
.extra:empty { display: none; }
.xchip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 10px; background: rgba(124,92,255,.14); border: 1px solid rgba(124,92,255,.3); font-size: 1rem; color: var(--text); }
.xchip small { color: var(--muted); font-size: .7rem; }
.xchip.gold { background: rgba(255,181,71,.12); border-color: rgba(255,181,71,.35); }
.xchip.ok { background: rgba(52,211,153,.12); border-color: rgba(52,211,153,.4); }

/* التعبير الرياضي */
.mx { display: inline-flex; align-items: baseline; flex-wrap: nowrap; white-space: nowrap; }
.mx .u { display: inline-flex; align-items: baseline; position: relative; }
.mx .u-op { padding: 0 .16em; color: color-mix(in srgb, var(--accent2) 75%, var(--text)); }
.mx .u-fn, .mx .u-paren { color: color-mix(in srgb, var(--accent) 45%, var(--text)); }
.mx .u-fn { padding-inline: .04em; }
.mx .u-id { color: var(--gold); padding-inline: .04em; }
.mx .sup { font-size: .6em; position: relative; top: -.85em; }
.mx .sup .sup { top: -.4em; }
.mx .ph { font-size: .55em; top: -.9em; color: var(--faint); }
.mx .pi, .pi { font-style: normal; color: var(--accent2); }
.caret { display: inline-block; width: 2.5px; height: 1.05em; background: var(--accent2); border-radius: 2px; margin: 0 1px; align-self: center; animation: blink 1s steps(1) infinite; box-shadow: 0 0 10px var(--accent2); }
@keyframes blink { 50% { opacity: 0; } }
.frac { display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; font-size: .72em; line-height: 1.15; margin: 0 .15em; }
.frac > span:first-child { border-bottom: 2px solid currentColor; padding: 0 .25em .05em; }
.frac > span:last-child { padding-top: .05em; }
.num sup { font-size: .55em; }

/* شريط المتغيرات */
.varbar { display: flex; gap: 6px; overflow-x: auto; padding: 0 12px 8px; scrollbar-width: none; flex: none; }
.varbar::-webkit-scrollbar { display: none; }
.vchip { flex: none; display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); font-size: .9rem; }
.vchip b { color: var(--gold); font-weight: 700; }
.vchip span { color: var(--muted); font-size: .82rem; }
.vchip.add { color: var(--accent2); border-style: dashed; border-color: color-mix(in srgb, var(--accent2) 50%, transparent); }
.vchip.fn b { color: var(--accent2); }

/* لوحة المفاتيح */
.pad { padding: 0 10px calc(8px); flex: none; direction: ltr; }
.pad-sci { display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; margin-bottom: 6px; grid-auto-rows: clamp(31px, 4.5dvh, 44px); }
.pad-main { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; grid-auto-rows: clamp(40px, 6.3dvh, 62px); }
.key { position: relative; border-radius: 16px; background: var(--key); color: var(--key-text); font-size: 1.55rem; font-weight: 500; display: grid; place-items: center; box-shadow: inset 0 1px 0 rgba(255,255,255,.06), 0 2px 0 rgba(0,0,0,.22); transition: transform .08s, filter .08s; user-select: none; -webkit-user-select: none; touch-action: manipulation; line-height: 1; }
.key:active, .key.pressed { transform: scale(.93); filter: brightness(1.25); }
.key.fn { background: var(--key-fn); font-size: 1.02rem; font-weight: 600; border-radius: 12px; color: color-mix(in srgb, var(--accent) 35%, var(--key-text)); }
.key.fn.var { color: var(--gold); font-size: 1.2rem; }
.key.fn.on { background: color-mix(in srgb, var(--accent) 40%, var(--key-fn)); color: #fff; }
.key.op { background: var(--key-op); color: color-mix(in srgb, var(--accent2) 70%, var(--key-text)); font-size: 1.75rem; }
.key.ctl { background: var(--key-hi); font-size: 1.05rem; font-weight: 700; color: var(--danger); }
.key.ctl.bs { color: var(--muted); }
.key.eq { background: linear-gradient(140deg, var(--gold), var(--gold2)); color: #2a1600; font-size: 2rem; font-weight: 700; box-shadow: 0 6px 18px rgba(255,140,50,.35); }
.key small { position: absolute; top: 3px; inset-inline: 0; text-align: center; font-size: .55rem; color: var(--faint); font-weight: 500; }
.key .sup-s { font-size: .62em; vertical-align: super; }

/* ======= الورقة السفلية ======= */
.backdrop { position: fixed; inset: 0; background: rgba(5,8,20,.55); backdrop-filter: blur(3px); opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 40; }
.backdrop.show { opacity: 1; pointer-events: auto; }
.sheet { position: fixed; inset-inline: 0; bottom: 0; margin: 0 auto; max-width: 540px; max-height: 88dvh; background: var(--card); border-radius: 26px 26px 0 0; border: 1px solid var(--line); z-index: 41; transform: translateY(105%); transition: transform .32s cubic-bezier(.2,.9,.2,1); display: flex; flex-direction: column; padding-bottom: var(--safe-b); box-shadow: 0 -20px 50px rgba(0,0,0,.4); }
.sheet.show { transform: none; }
.sheet-grip { width: 42px; height: 5px; border-radius: 3px; background: var(--line); margin: 8px auto 0; background: var(--faint); opacity: .5; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 16px 8px; }
.sheet-head h3 { margin: 0; font-size: 1.1rem; }
.sheet-body { overflow-y: auto; padding: 4px 16px 18px; }

/* القوائم داخل الورقة */
.list { display: flex; flex-direction: column; gap: 8px; }
.item { background: var(--card2); border: 1px solid var(--line); border-radius: 16px; padding: 10px 12px; }
.item .row { display: flex; align-items: center; gap: 8px; }
.item .meta { color: var(--faint); font-size: .72rem; }
.hist-expr { font-size: 1.15rem; overflow-x: auto; }
.hist-res { font-size: 1.35rem; font-weight: 700; color: var(--accent2); }
.mini-btn { padding: 6px; border-radius: 10px; color: var(--muted); }
.mini-btn svg { width: 18px; height: 18px; }
.empty-state { text-align: center; color: var(--muted); padding: 30px 10px; }
.empty-state .big { font-size: 2.4rem; margin-bottom: 6px; }

.fn-cat { margin: 12px 0 6px; color: var(--muted); font-size: .8rem; font-weight: 700; }
.fn-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 7px; }
.fn-btn { text-align: start; padding: 9px 11px; border-radius: 14px; background: var(--card2); border: 1px solid var(--line); }
.fn-btn b { display: block; font-size: 1.1rem; color: var(--accent2); }
.fn-btn span { font-size: .72rem; color: var(--muted); }
.letters { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.letters button { height: 46px; border-radius: 12px; background: var(--card2); border: 1px solid var(--line); font-size: 1.35rem; color: var(--gold); }
.letters button:active { transform: scale(.92); }

/* الخطوات */
.steps { display: flex; flex-direction: column; gap: 10px; counter-reset: st; }
.step { display: grid; grid-template-columns: 30px 1fr; gap: 10px; align-items: start; }
.step::before { counter-increment: st; content: counter(st, arabic-indic); width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: linear-gradient(135deg, var(--accent), #4f8cff); color: #fff; font-weight: 700; font-size: .85rem; }
:root[data-digits="en"] .step::before { content: counter(st); }
.step .d { color: var(--muted); font-size: .82rem; margin-bottom: 2px; }
.step .m { font-size: 1.3rem; background: var(--card2); border: 1px solid var(--line); border-radius: 12px; padding: 6px 10px; overflow-x: auto; }
.step.final .m { border-color: rgba(52,211,153,.5); background: rgba(52,211,153,.08); font-weight: 700; }

/* النماذج */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 10px; }
.field label { font-size: .8rem; color: var(--muted); font-weight: 600; }
.inp { width: 100%; padding: 11px 13px; border-radius: 13px; background: var(--card2); border: 1px solid var(--line); outline: none; font-size: 1rem; transition: border .15s; }
.inp:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124,92,255,.18); }
.inp.num { direction: ltr; text-align: right; }
textarea.inp { resize: vertical; min-height: 80px; }
.seg { display: flex; background: var(--card2); border: 1px solid var(--line); border-radius: 14px; padding: 3px; gap: 3px; }
.seg button { flex: 1; padding: 8px 6px; border-radius: 11px; font-size: .85rem; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 2px 8px rgba(0,0,0,.2); }
:root[data-theme="light"] .seg button.on { background: #fff; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.set-row:last-child { border: 0; }
.set-row > span { font-weight: 600; font-size: .92rem; }
.set-row small { display: block; color: var(--muted); font-weight: 400; font-size: .74rem; }
.set-row .seg { min-width: 180px; }

/* ======= الرسم ======= */
.graph-wrap { position: relative; flex: 1 1 58%; min-height: 220px; margin: 0 12px; border-radius: 22px; overflow: hidden; border: 1px solid var(--line); background: var(--card); touch-action: none; }
#gcanvas { width: 100%; height: 100%; display: block; }
.g-tools { position: absolute; top: 10px; left: 10px; display: flex; flex-direction: column; gap: 6px; }
.g-btn { width: 38px; height: 38px; border-radius: 12px; background: color-mix(in srgb, var(--card2) 85%, transparent); backdrop-filter: blur(8px); border: 1px solid var(--line); font-size: 1.3rem; display: grid; place-items: center; color: var(--text); }
.g-btn svg { width: 18px; height: 18px; }
.g-tip { position: absolute; padding: 6px 10px; border-radius: 10px; background: var(--text); color: var(--bg); font-weight: 700; font-size: .85rem; pointer-events: none; transform: translate(-50%, -130%); white-space: nowrap; box-shadow: var(--shadow); direction: rtl; }
.g-hint { position: absolute; bottom: 8px; inset-inline: 0; text-align: center; font-size: .68rem; color: var(--faint); pointer-events: none; }
.g-panel { flex: 1 1 42%; overflow-y: auto; padding: 10px 12px 12px; min-height: 0; }
.g-item { display: flex; align-items: center; gap: 8px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 6px 8px; margin-bottom: 7px; }
.g-item.err { border-color: rgba(255,93,122,.5); }
.g-dot { width: 26px; height: 26px; border-radius: 50%; flex: none; border: 3px solid currentColor; display: grid; place-items: center; }
.g-dot.off { background: transparent !important; opacity: .45; }
.g-item input { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; font-size: 1.15rem; padding: 6px 2px; }
.g-info { font-size: .76rem; color: var(--muted); padding: 0 42px 8px 8px; margin-top: -4px; display: flex; flex-wrap: wrap; gap: 4px 10px; }
.g-info b { color: var(--text); font-weight: 600; }
.g-info.err { color: var(--danger); }
.g-slider { display: grid; grid-template-columns: auto 1fr auto auto; gap: 10px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 8px 12px; margin-bottom: 7px; }
.g-slider b { color: var(--gold); font-size: 1.2rem; }
.g-slider output { min-width: 3.4em; text-align: center; font-weight: 700; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.g-add { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.g-examples { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.g-examples .chip { font-size: .85rem; color: var(--text); }
.g-kbd { position: absolute; inset-inline: 0; bottom: 0; display: flex; gap: 5px; overflow-x: auto; padding: 7px 10px; background: var(--card); border-top: 1px solid var(--line); z-index: 5; scrollbar-width: none; }
.g-kbd button { flex: none; min-width: 42px; height: 40px; padding: 0 10px; border-radius: 11px; background: var(--card2); border: 1px solid var(--line); font-size: 1.1rem; }
.vtable { width: 100%; border-collapse: collapse; font-size: 1rem; }
.vtable th, .vtable td { padding: 8px; text-align: center; border-bottom: 1px solid var(--line); }
.vtable th { color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--card); }

/* ======= الصفحات (القطة والأدوات) ======= */
.page { padding: 6px 12px 30px; }
.hero { border-radius: 24px; padding: 18px; background: linear-gradient(135deg, #6d4aff, #3b2bb8 55%, #13204a); color: #fff; position: relative; overflow: hidden; margin-bottom: 12px; box-shadow: 0 14px 30px rgba(80,50,220,.35); }
.hero::after { content: ""; position: absolute; width: 220px; height: 220px; left: -60px; top: -80px; background: radial-gradient(circle, rgba(34,211,238,.45), transparent 70%); }
.hero h2 { margin: 0 0 4px; font-size: 1.35rem; position: relative; z-index: 1; }
.hero p { margin: 0; opacity: .85; font-size: .86rem; position: relative; z-index: 1; }
.hero .big { font-size: 2.2rem; font-weight: 700; margin-top: 8px; position: relative; z-index: 1; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 14px; margin-bottom: 12px; }
.card h3 { margin: 0 0 10px; font-size: 1rem; display: flex; align-items: center; gap: 8px; }
.card h3 .n { width: 24px; height: 24px; border-radius: 8px; display: grid; place-items: center; background: rgba(124,92,255,.2); color: var(--accent); font-size: .8rem; }
.card h3 .spacer { flex: 1; }
.muted { color: var(--muted); font-size: .82rem; }
.person { display: grid; grid-template-columns: 38px 1fr 110px 30px; gap: 8px; align-items: center; margin-bottom: 8px; }
.avatar { width: 38px; height: 38px; border-radius: 13px; display: grid; place-items: center; font-weight: 700; color: #fff; font-size: 1rem; }
.person .inp { padding: 9px 11px; }
.paid-wrap { position: relative; }
.paid-wrap .inp { padding-left: 34px; }
.paid-wrap i { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); font-style: normal; font-size: .7rem; color: var(--faint); }
.x-btn { width: 30px; height: 30px; border-radius: 10px; display: grid; place-items: center; color: var(--faint); }
.x-btn svg { width: 16px; height: 16px; }
.add-row { display: flex; gap: 8px; }
.who { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.who button { padding: 5px 10px; border-radius: 999px; font-size: .8rem; font-weight: 600; border: 1px solid var(--line); background: var(--card2); color: var(--faint); text-decoration: line-through; }
.who button.on { color: var(--text); text-decoration: none; border-color: color-mix(in srgb, var(--c, var(--accent)) 60%, transparent); background: color-mix(in srgb, var(--c, var(--accent)) 18%, var(--card2)); }
.bill-item { background: var(--card2); border: 1px solid var(--line); border-radius: 16px; padding: 10px; margin-bottom: 8px; }
.bill-item .row { display: grid; grid-template-columns: 1fr 100px 64px 30px; gap: 6px; }
.extras { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.extras .field { margin: 0; }
.balance { display: grid; grid-template-columns: 38px 1fr auto; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.balance:last-child { border: 0; }
.balance .nm { font-weight: 700; }
.balance .sub { font-size: .76rem; color: var(--muted); }
.bar { height: 6px; border-radius: 3px; background: var(--card2); margin-top: 5px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 3px; }
.badge { padding: 4px 10px; border-radius: 10px; font-weight: 700; font-size: .85rem; white-space: nowrap; }
.badge.plus { background: rgba(52,211,153,.14); color: var(--ok); }
.badge.minus { background: rgba(255,93,122,.14); color: var(--danger); }
.badge.zero { background: var(--card2); color: var(--muted); }
.transfer { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; padding: 12px; border-radius: 16px; background: linear-gradient(135deg, rgba(255,181,71,.12), rgba(124,92,255,.10)); border: 1px solid rgba(255,181,71,.25); margin-bottom: 8px; }
.transfer .p { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.transfer .p.to { justify-content: flex-end; }
.transfer .p .avatar { width: 32px; height: 32px; border-radius: 11px; font-size: .85rem; }
.transfer .amt { text-align: center; font-weight: 700; color: var(--gold); font-size: 1.1rem; }
.transfer .amt svg { display: block; margin: 0 auto; width: 46px; color: var(--gold); transform: scaleX(-1); }
.warn { padding: 10px 12px; border-radius: 14px; background: rgba(255,181,71,.12); border: 1px solid rgba(255,181,71,.3); color: var(--gold); font-size: .84rem; margin-bottom: 10px; }
.ok-box { padding: 12px; border-radius: 14px; background: rgba(52,211,153,.1); border: 1px solid rgba(52,211,153,.3); color: var(--ok); font-weight: 600; text-align: center; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.saved-groups { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }

/* الأدوات */
.tools-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.tool-card { text-align: start; padding: 16px 14px; border-radius: 20px; background: var(--card); border: 1px solid var(--line); position: relative; overflow: hidden; min-height: 116px; display: flex; flex-direction: column; gap: 6px; }
.tool-card .ic { width: 42px; height: 42px; border-radius: 14px; display: grid; place-items: center; font-size: 1.3rem; font-weight: 700; color: #fff; }
.tool-card b { font-size: 1rem; }
.tool-card span { font-size: .74rem; color: var(--muted); line-height: 1.5; }
.tool-card:active { transform: scale(.97); }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-weight: 600; margin: 4px 0 10px; }
.back svg { transform: scaleX(-1); width: 18px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--card2); border: 1px solid var(--line); border-radius: 14px; padding: 9px; }
.stat small { display: block; color: var(--muted); font-size: .7rem; font-weight: 600; }
.stat b { font-size: 1.1rem; }
.sys { display: grid; gap: 8px; }
.sys-row { display: flex; align-items: center; gap: 6px; direction: rtl; }
.sys-row .inp { width: 64px; padding: 9px 6px; text-align: center; direction: ltr; }
.sys-row span { color: var(--gold); font-weight: 700; font-size: 1.1rem; }
.formula { font-size: 1.05rem; padding: 8px 12px; background: var(--card2); border-radius: 12px; border: 1px solid var(--line); margin: 6px 0; }
.res-big { font-size: 1.8rem; font-weight: 700; color: var(--accent2); }
.kv { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.kv:last-child { border: 0; }
.kv b { color: var(--text); }
.chips-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.factor { font-size: 1.5rem; font-weight: 700; }
.grade { display: inline-block; padding: 4px 12px; border-radius: 10px; font-weight: 700; }
.histo { display: flex; align-items: flex-end; gap: 4px; height: 120px; padding-top: 10px; direction: ltr; }
.histo div { flex: 1; background: linear-gradient(to top, var(--accent), var(--accent2)); border-radius: 6px 6px 2px 2px; position: relative; min-height: 2px; }
.histo div span { position: absolute; bottom: -18px; inset-inline: 0; text-align: center; font-size: .65rem; color: var(--muted); }
.histo div em { position: absolute; top: -16px; inset-inline: 0; text-align: center; font-size: .65rem; font-style: normal; color: var(--text); }

/* بطاقة المشاركة */
.card-preview { width: 100%; border-radius: 18px; display: block; box-shadow: var(--shadow); margin-bottom: 12px; }

/* التثبيت */
.install { position: fixed; z-index: 30; inset-inline: 12px; bottom: calc(var(--safe-b) + 82px); max-width: 516px; margin: 0 auto; display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 22px; background: linear-gradient(135deg, #2a1f78, #141b3a); color: #fff; border: 1px solid rgba(255,255,255,.12); box-shadow: 0 20px 40px rgba(0,0,0,.45); animation: slideUp .45s cubic-bezier(.2,1.2,.3,1); }
.install img { border-radius: 14px; }
.install-txt { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.install-txt b { font-size: .98rem; }
.install-txt span { font-size: .76rem; opacity: .8; line-height: 1.5; }
.install-btns { display: flex; flex-direction: column; gap: 4px; }
.install .btn.ghost { color: rgba(255,255,255,.7); }
.ios-share { display: inline-block; vertical-align: -3px; width: 16px; height: 16px; }
@keyframes slideUp { from { transform: translateY(140%); } }

.toast { position: fixed; z-index: 60; top: calc(env(safe-area-inset-top, 0px) + 14px); left: 50%; transform: translate(-50%, -150%); padding: 10px 18px; border-radius: 14px; background: var(--text); color: var(--bg); font-weight: 600; font-size: .9rem; transition: transform .3s cubic-bezier(.2,1.2,.3,1); box-shadow: var(--shadow); max-width: 90vw; text-align: center; }
.toast.show { transform: translate(-50%, 0); }

@media (max-height: 640px) {
  .screen { min-height: 120px; }
  .expr { font-size: 1.7rem; }
  .result.final { font-size: 2rem; }
}
.step .m .d { font-size: inherit; color: inherit; margin: 0; }
.mx .u-op.un { padding: 0; }
