/* علبة أدوات التلميذ — Layout: one column (max 640px). Sticky top bar (back · title · language).
   Home: hero + search + 2-column grid of tool cards (colour per tool). Tool pages: segmented mode switch,
   input card(s), live result card, collapsible "steps" list. Plot: canvas card. Timer: ring + controls. */
@font-face { font-family: "Readex Pro"; font-weight: 400; font-display: swap; src: url("../fonts/readex-pro-arabic-400-normal.woff2") format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC; }
@font-face { font-family: "Readex Pro"; font-weight: 700; font-display: swap; src: url("../fonts/readex-pro-arabic-700-normal.woff2") format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC; }
@font-face { font-family: "Readex Pro"; font-weight: 400; font-display: swap; src: url("../fonts/readex-pro-latin-400-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Readex Pro"; font-weight: 700; font-display: swap; src: url("../fonts/readex-pro-latin-700-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

:root {
  --bg: #F4F6F3; --surface: #FFFFFF; --surface-2: #EEF2EE; --ink: #17231F; --muted: #5C6B66; --line: #DCE3DE;
  --brand: #0E7C6B; --brand-ink: #FFFFFF; --brand-soft: #DDF1EC; --ok: #0E7C6B; --bad: #C8382E; --bad-soft: #FBE4E2;
  --c-calc: #2F5BEA; --c-frac: #D9480F; --c-gcd: #7048E8; --c-pct: #E8590C; --c-eq: #0E7C6B; --c-plot: #1C7ED6;
  --c-geo: #C2255C; --c-stats: #5C940D; --c-units: #0B7285; --c-timer: #9C36B5;
  --shadow: 0 1px 2px rgba(23,35,31,.06), 0 2px 8px rgba(23,35,31,.05);
  --f: "Readex Pro", "Segoe UI", Tahoma, "Noto Sans Arabic", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0F1715; --surface: #18221F; --surface-2: #1F2B27; --ink: #E9F0EC; --muted: #9DB0A9; --line: #2C3A35;
    --brand: #3FC1A8; --brand-ink: #0F1715; --brand-soft: #173A33; --ok: #3FC1A8; --bad: #FF7B6E; --bad-soft: #3A1D1A;
    --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0F1715; --surface: #18221F; --surface-2: #1F2B27; --ink: #E9F0EC; --muted: #9DB0A9; --line: #2C3A35;
  --brand: #3FC1A8; --brand-ink: #0F1715; --brand-soft: #173A33; --ok: #3FC1A8; --bad: #FF7B6E; --bad-soft: #3A1D1A;
  --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
}

[hidden] { display: none !important; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 16px/1.55 var(--f); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }
.ltr, .math { direction: ltr; unicode-bidi: isolate; }
.math { font-variant-numeric: tabular-nums; }

.app { max-width: 640px; margin-inline: auto; min-height: 100dvh; display: grid; grid-template-rows: auto 1fr; grid-template-columns: minmax(0, 1fr);
  padding-left: max(14px, env(safe-area-inset-left, 0px)); padding-right: max(14px, env(safe-area-inset-right, 0px)); padding-bottom: calc(18px + env(safe-area-inset-bottom, 0px)); }

.top { position: sticky; top: 0; z-index: 10; background: var(--bg); display: flex; align-items: center; gap: 8px; padding: calc(8px + env(safe-area-inset-top, 0px)) 0 8px; }
.top .title { flex: 1; min-width: 0; font-weight: 700; font-size: 1.1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 42px; height: 42px; flex: none; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); display: grid; place-items: center; }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
[dir="rtl"] .flip svg { transform: scaleX(-1); }
.pill { height: 42px; border: 1px solid var(--line); border-radius: 12px; padding: 0 12px; background: var(--surface); font-weight: 700; font-size: .85rem; }

.view { min-width: 0; display: grid; gap: 14px; align-content: start; padding-top: 4px; animation: in .2s ease; }

/* ---------- الرئيسية ---------- */
.hero { background: var(--brand); color: var(--brand-ink); border-radius: 20px; padding: 18px; display: grid; gap: 4px; position: relative; overflow: hidden; }
.hero h1 { margin: 0; font-size: 1.45rem; line-height: 1.25; }
.hero p { margin: 0; opacity: .9; font-size: .92rem; }
.hero .deco { position: absolute; inset-inline-end: -8px; bottom: -18px; font-size: 5.5rem; font-weight: 700; opacity: .14; direction: ltr; line-height: 1; pointer-events: none; }
.searchbox { position: relative; }
.searchbox input { width: 100%; height: 48px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); padding-inline: 44px 14px; }
.searchbox svg { position: absolute; inset-inline-start: 14px; top: 13px; width: 22px; height: 22px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tool { border: 1px solid var(--line); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); padding: 14px; text-align: start; display: grid; gap: 8px; align-content: start; min-height: 128px; }
.tool:active { transform: scale(.98); }
.tool .ic { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; color: #fff; background: var(--tc); font-weight: 700; font-size: 1.15rem; direction: ltr; }
.tool b { font-size: 1rem; line-height: 1.3; }
.tool span { color: var(--muted); font-size: .78rem; line-height: 1.4; }
.foot { text-align: center; color: var(--muted); font-size: .8rem; display: grid; gap: 4px; padding-top: 4px; }
.foot a { color: inherit; }

/* ---------- عناصر الأدوات ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 14px; display: grid; gap: 12px; box-shadow: var(--shadow); }
.seg { display: flex; gap: 4px; padding: 4px; border-radius: 14px; background: var(--surface-2); overflow-x: auto; scrollbar-width: none; }
.seg button { flex: 1 0 auto; border: 0; background: transparent; border-radius: 10px; padding: 8px 12px; font-size: .88rem; font-weight: 700; color: var(--muted); white-space: nowrap; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.field { display: grid; gap: 4px; }
.field label { font-size: .8rem; color: var(--muted); font-weight: 700; }
.field .wrap { position: relative; display: flex; }
.field input, .field select { width: 100%; height: 50px; border: 1.5px solid var(--line); border-radius: 12px; background: var(--bg); padding: 0 12px; font-size: 1.15rem; font-weight: 700; direction: ltr; text-align: center; }
.field select { font-size: 1rem; text-align: start; direction: inherit; }
.field input:focus, .field select:focus { border-color: var(--brand); outline: none; }
.field .sign { position: absolute; inset-inline-start: 4px; top: 7px; width: 36px; height: 36px; border: 0; border-radius: 9px; background: var(--surface-2); font-weight: 700; }
.field.signed input { padding-inline-start: 44px; }
[dir="rtl"] .field.signed input { padding-inline-start: 12px; padding-inline-end: 44px; }
[dir="rtl"] .field .sign { inset-inline-start: auto; inset-inline-end: 4px; }
.eqline { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px; direction: ltr; font-weight: 700; font-size: 1.1rem; }
.eqline input { width: 72px; height: 46px; border: 1.5px solid var(--line); border-radius: 10px; background: var(--bg); text-align: center; font-weight: 700; font-size: 1.1rem; }
.eqline input:focus { border-color: var(--brand); outline: none; }
.hint { margin: 0; color: var(--muted); font-size: .84rem; }
.result { background: var(--brand-soft); border-radius: 16px; padding: 14px; display: grid; gap: 6px; }
.result .lbl { font-size: .8rem; color: var(--muted); font-weight: 700; }
.result .big { font-size: 1.7rem; font-weight: 700; line-height: 1.25; color: var(--ink); word-break: break-word; }
.result .sub { color: var(--muted); font-size: .92rem; }
.result.err { background: var(--bad-soft); }
.result.err .big { color: var(--bad); font-size: 1.05rem; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: baseline; }
.kv dt { color: var(--muted); font-size: .9rem; }
.kv dd { margin: 0; font-weight: 700; direction: ltr; text-align: end; }
details.steps { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 4px 14px; }
details.steps summary { cursor: pointer; font-weight: 700; padding: 10px 0; color: var(--brand); }
details.steps ol { margin: 0 0 12px; padding-inline-start: 22px; display: grid; gap: 8px; }
details.steps li { line-height: 1.6; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 4px 10px; font-weight: 700; font-size: .85rem; direction: ltr; }
button.chip:active { background: var(--surface-2); }
.btn { min-height: 48px; border: 0; border-radius: 14px; background: var(--brand); color: var(--brand-ink); font-weight: 700; padding: 0 16px; }
.btn.soft { background: var(--surface-2); color: var(--ink); }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > * { flex: 1; }
sup { font-size: .7em; }

/* ---------- الآلة الحاسبة ---------- */
.screen { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 12px 14px; display: grid; gap: 2px; direction: ltr; text-align: right; }
.screen input { border: 0; background: transparent; font-size: 1.5rem; font-weight: 700; text-align: right; width: 100%; padding: 0; outline: none; caret-color: var(--brand); }
.screen .out { font-size: 2rem; font-weight: 700; color: var(--brand); min-height: 1.4em; word-break: break-all; }
.screen .out.err { color: var(--bad); font-size: 1.05rem; }
.screen .meta { display: flex; justify-content: space-between; color: var(--muted); font-size: .8rem; }
.keys { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; direction: ltr; }
.k { min-height: 50px; border: 0; border-radius: 12px; background: var(--surface); box-shadow: 0 1px 0 var(--line), var(--shadow); font-size: 1.15rem; font-weight: 700; }
.k.fn { background: var(--surface-2); font-size: .95rem; }
.k.op { color: var(--c-calc); }
.k.eq { background: var(--c-calc); color: #fff; }
.k.ac { color: var(--bad); }
.k:active { transform: translateY(1px); filter: brightness(.96); }
.hist { display: grid; gap: 6px; }
.hist button { border: 0; background: var(--surface); border-radius: 12px; padding: 8px 12px; display: flex; justify-content: space-between; gap: 10px; direction: ltr; text-align: left; border: 1px solid var(--line); }
.hist b { color: var(--brand); }

/* ---------- الرسم ---------- */
.plot { position: relative; border-radius: 16px; overflow: hidden; border: 1px solid var(--line); background: var(--surface); touch-action: none; aspect-ratio: 1 / 1; max-height: 62vh; }
.plot canvas { width: 100%; height: 100%; display: block; }
.plot .tools { position: absolute; top: 8px; inset-inline-end: 8px; display: grid; gap: 6px; }
.plot .tools button { width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-weight: 700; font-size: 1.1rem; }
.legend { display: flex; gap: 14px; font-size: .85rem; direction: ltr; justify-content: center; }
.legend i { display: inline-block; width: 18px; height: 4px; border-radius: 2px; vertical-align: middle; margin-inline-end: 6px; }
table.vals { width: 100%; border-collapse: collapse; direction: ltr; font-variant-numeric: tabular-nums; font-size: .92rem; }
table.vals th, table.vals td { border: 1px solid var(--line); padding: 6px 4px; text-align: center; }
table.vals th { background: var(--surface-2); }
.scroll-x { overflow-x: auto; }

/* ---------- المؤقت ---------- */
.ring { width: min(72vw, 280px); aspect-ratio: 1; margin: 6px auto; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--rc) calc(var(--p) * 1%), var(--surface-2) 0); }
.ring .inner { width: 84%; aspect-ratio: 1; border-radius: 50%; background: var(--surface); display: grid; place-items: center; align-content: center; gap: 2px; text-align: center; }
.ring .time { font-size: 3rem; font-weight: 700; direction: ltr; font-variant-numeric: tabular-nums; line-height: 1; }
.ring .phase { color: var(--muted); font-weight: 700; }
.toast { position: fixed; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); inset-inline: 0; margin-inline: auto; width: max-content; max-width: 90%; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 700; z-index: 40; }

@keyframes in { from { opacity: 0; transform: translateY(6px); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
@media (max-width: 360px) { .tool { min-height: 118px; padding: 12px; } .keys .k { min-height: 46px; font-size: 1.05rem; } }
