/* ==========================================================================
   رياضيات بلس — حزمة المحاكاة (Sim Kit)
   تخطيط موحد: لوحة تحكم يمين، ومساحة عرض رياضي لا تقل عن 70% في الشاشات الأفقية.
   ========================================================================== */
@font-face {
  font-family: 'RP Arabic';
  src: url('./noto-sans-arabic.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-08FF, U+FB50-FDFF, U+FE70-FEFF, U+200C-200E, U+2010-2011, U+204F, U+2E41;
}
@font-face {
  font-family: 'RP Arabic';
  src: url('./noto-sans-arabic-latin.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --navy: #142b49;
  --gold: #b69a60;
  --gold-ink: #7d6431;
  --bg: #ffffff;
  --panel: #f4f6f9;
  --line: #dde2ea;
  --text: #1c2738;
  --strong: #142b49;
  --muted: #566173;
  --grid: #e6eaf0;
  --axis: #6b7689;
  --c1: #142b49;
  --c2: #b69a60;
  --c3: #2f7d6d;
  --c4: #b4532a;
  --fill1: rgb(20 43 73 / 14%);
  --fill2: rgb(182 154 96 / 30%);
  --fill3: rgb(47 125 109 / 20%);
  --btn: #142b49;
  --btn-fg: #fff;
  --focus: #1f6feb;
  color-scheme: light;
}
:root[data-theme='dark'] {
  --bg: #0c1624;
  --panel: #13233a;
  --line: #243a58;
  --text: #e3e9f1;
  --strong: #f3f6fa;
  --muted: #a6b2c3;
  --grid: #1c2f48;
  --axis: #8d9bb0;
  --c1: #9cc0ff;
  --c2: #d8bd85;
  --c3: #6fd1bb;
  --c4: #ff9d74;
  --fill1: rgb(156 192 255 / 18%);
  --fill2: rgb(216 189 133 / 28%);
  --fill3: rgb(111 209 187 / 22%);
  --btn: #cfb47e;
  --btn-fg: #0c1624;
  --focus: #6ea8ff;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font-family: 'RP Arabic', 'Noto Sans Arabic', 'Segoe UI', Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.6;
  overflow: hidden;
}
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.sim {
  display: grid;
  grid-template-columns: minmax(250px, 27%) 1fr;
  height: 100vh;
  height: 100dvh;
}

/* لوحة التحكم (يمين في الاتجاه العربي) */
.panel {
  background: var(--panel);
  border-inline-end: 1px solid var(--line);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
}
.panel > * { flex-shrink: 0; }
.panel h1 { font-size: 1.15rem; margin: 0; color: var(--strong); line-height: 1.4; }
.brand { display: flex; align-items: center; gap: 8px; font-size: 0.78rem; color: var(--muted); }
.brand b { color: var(--gold-ink); font-weight: 700; }
:root[data-theme='dark'] .brand b { color: var(--gold); }

.modes { display: grid; gap: 5px; }
.modes-label, .inputs-label { font-size: 0.8rem; color: var(--muted); font-weight: 600; margin: 0; }
.mode {
  min-height: 44px;
  text-align: start;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1.5px solid var(--line);
  background: var(--bg);
  font-weight: 600;
  cursor: pointer;
}
.mode[aria-pressed='true'] { border-color: var(--gold); box-shadow: inset -4px 0 0 var(--gold); color: var(--strong); }

.inputs { display: grid; gap: 6px; }
.input { display: grid; gap: 4px; }
.input label { display: flex; justify-content: space-between; font-weight: 600; font-size: 0.95rem; }
.input output { color: var(--strong); font-weight: 700; min-width: 2.5em; text-align: end; }
.input input[type='range'] { width: 100%; accent-color: var(--gold); min-height: 32px; cursor: pointer; }

.caption {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 76px;
  font-size: 0.95rem;
  line-height: 1.55;
}
.phase { display: block; font-size: 0.75rem; font-weight: 700; color: var(--gold-ink); margin-bottom: 2px; }
:root[data-theme='dark'] .phase { color: var(--gold); }
.progress { display: flex; gap: 4px; margin-top: 8px; }
.progress span { flex: 1; height: 4px; border-radius: 2px; background: var(--line); }
.progress span.on { background: var(--gold); }

.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: auto; }
.btn {
  min-height: 48px;
  border-radius: 10px;
  border: 1.5px solid var(--btn);
  background: var(--btn);
  color: var(--btn-fg);
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 10px;
}
.btn.ghost { background: transparent; color: var(--strong); border-color: var(--line); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.wide { grid-column: 1 / -1; }
.btn svg { width: 18px; height: 18px; }

/* مساحة العرض الرياضي */
.stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  min-width: 0;
  min-height: 0;
}
.stage svg.view { width: 100%; height: 100%; max-height: 100%; display: block; }
.stage-tools { position: absolute; top: 10px; inset-inline-end: 10px; display: flex; gap: 6px; }
.tool {
  width: 44px; height: 44px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--strong);
  display: grid; place-items: center; cursor: pointer;
}
.tool svg { width: 20px; height: 20px; }
.embedded .stage-tools { display: none; }

/* عناصر الرسم */
.t { font-family: inherit; fill: var(--text); }
.t-strong { fill: var(--strong); font-weight: 700; }
.t-muted { fill: var(--muted); }
.t-gold { fill: var(--gold-ink); font-weight: 700; }
:root[data-theme='dark'] .t-gold { fill: var(--gold); }
.fracbar, .radical { stroke: var(--strong); }
.fade-in { animation: fade 0.45s ease both; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .fracbar, .radical { stroke: var(--strong); }
.fade-in { animation: none; } }

/* الشاشات العمودية والصغيرة: العرض فوق ولوحة التحكم تحت */
@media (max-aspect-ratio: 1/1), (max-width: 700px) {
  body { overflow: auto; }
  .sim { grid-template-columns: 1fr; grid-template-rows: minmax(52vh, 1fr) auto; height: auto; min-height: 100dvh; }
  .stage { order: -1; min-height: 52vh; }
  .panel { border-inline-end: 0; border-top: 1px solid var(--line); overflow: visible; }
  .controls { margin-top: 0; }
}

/* سبورة ذكية: تكبير عناصر التحكم في الشاشات الكبيرة جدًا */
@media (min-width: 1700px) {
  body { font-size: 19px; }
  .btn, .mode { min-height: 56px; }
}
