@font-face { font-family: 'Plex Arabic MG'; src: url('fonts/plex-arabic-400.woff2') format('woff2'); font-weight: 400; font-display: swap; unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF, U+200C-200F, U+25CC; }
@font-face { font-family: 'Plex Arabic MG'; src: url('fonts/plex-arabic-600.woff2') format('woff2'); font-weight: 600; font-display: swap; unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF, U+200C-200F, U+25CC; }
@font-face { font-family: 'Plex Arabic MG'; src: url('fonts/plex-arabic-700.woff2') format('woff2'); font-weight: 700; font-display: swap; unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF, U+200C-200F, U+25CC; }
@font-face { font-family: 'Plex Arabic MG'; src: url('fonts/plex-latin-400.woff2') format('woff2'); font-weight: 400; font-display: swap; unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF; }
@font-face { font-family: 'Plex Arabic MG'; src: url('fonts/plex-latin-600.woff2') format('woff2'); font-weight: 600; font-display: swap; unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF; }
@font-face { font-family: 'Plex Arabic MG'; src: url('fonts/plex-latin-700.woff2') format('woff2'); font-weight: 700; font-display: swap; unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF; }

.mg-body {
  --mg-bg: #05070d; --mg-glass: rgba(12,16,28,.84); --mg-glass2: rgba(20,26,44,.74); --mg-line: rgba(148,163,220,.16); --mg-line2: rgba(148,163,220,.28);
  --mg-text: #eef2fb; --mg-muted: #97a3bd; --mg-dim: #6b7690; --mg-violet: #9d8cff; --mg-violet2: #c3b8ff; --mg-amber: #ffb347; --mg-flux: #49c9ff; --mg-p: #ffa257; --mg-s: #5dfc9a; --mg-panelW: 330px;
  margin: 0; height: 100%; background: var(--mg-bg); color: var(--mg-text); font-family: 'Plex Arabic MG', 'Segoe UI', Tahoma, sans-serif; -webkit-font-smoothing: antialiased; overflow: hidden;
}
html:has(.mg-body) { height: 100%; }
.mg-body *, .mg-body *::before, .mg-body *::after { box-sizing: border-box; }
.mg-body button, .mg-body input, .mg-body select { font: inherit; color: inherit; }
.mg-body a { color: var(--mg-violet2); }
.mg-en { font-size: .76em; color: var(--mg-muted); font-weight: 400; direction: ltr; unicode-bidi: isolate; }
.mg-body [hidden] { display: none !important; }

#mgApp { position: fixed; inset: 0; display: grid; grid-template-columns: var(--mg-panelW) 1fr; grid-template-rows: auto 1fr; grid-template-areas: "top top" "panel stage"; }
.mg-top { grid-area: top; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 8px 16px; background: linear-gradient(180deg, rgba(10,13,24,.96), rgba(8,10,18,.92)); border-bottom: 1px solid var(--mg-line); z-index: 5; }
.mg-title h1 { margin: 0; font-size: 1.08rem; line-height: 1.35; }
.mg-home { display: inline-block; font-size: .72rem; text-decoration: none; color: var(--mg-muted) !important; } .mg-home:hover { color: var(--mg-violet2) !important; }
.mg-brand { font-size: .74rem; color: var(--mg-muted); } .mg-brand a { text-decoration: none; }
.mg-tabs { display: flex; gap: 4px; background: #0b0f1c; border: 1px solid var(--mg-line2); border-radius: 12px; padding: 4px; }
.mg-tabs button { border: none; background: transparent; padding: 7px 12px; border-radius: 9px; cursor: pointer; color: var(--mg-muted); font-size: .82rem; white-space: nowrap; }
.mg-tabs button.on { background: linear-gradient(135deg, #6c5cf0, #4f46e5); color: #fff; } .mg-tabs button.on .mg-en { color: #ddd8ff; }

#mgPanel { grid-area: panel; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; background: #070a12; border-inline-start: 1px solid var(--mg-line); z-index: 4; scrollbar-width: thin; scrollbar-color: #2a3350 transparent; }
.mg-ptoggle { display: none; }
.mg-card { background: var(--mg-glass2); border: 1px solid var(--mg-line); border-radius: 14px; padding: 12px; }
.mg-card h2 { margin: 0; font-size: .86rem; } .mg-ch { margin-bottom: 6px; }
.mg-steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 5px; }
.mg-steps li { display: flex; gap: 8px; align-items: flex-start; font-size: .78rem; color: var(--mg-dim); padding: 5px 6px; border-radius: 10px; }
.mg-steps li .n { flex: none; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: .72rem; border: 1px solid var(--mg-line2); color: var(--mg-muted); }
.mg-steps li.cur { background: rgba(130,110,255,.10); color: var(--mg-text); } .mg-steps li.cur .n { border-color: var(--mg-violet); color: var(--mg-violet2); }
.mg-steps li.done { color: var(--mg-muted); } .mg-steps li.done .n { background: rgba(16,185,129,.18); border-color: rgba(16,185,129,.6); color: #6ee7b7; }
.mg-steps li.fin .n { border-color: var(--mg-amber); color: var(--mg-amber); }
.mg-steps .sr { font-size: .7rem; color: #a7f3d0; margin-top: 3px; line-height: 1.55; }
.mg-ctrl { margin-bottom: 10px; } .mg-ctrl > label { display: block; font-size: .8rem; font-weight: 600; margin-bottom: 4px; }
.mg-row { display: flex; align-items: center; gap: 8px; }
.mg-row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 10px; }
.mg-row input[type=number] { width: 64px; padding: 4px 6px; border-radius: 8px; border: 1px solid var(--mg-line2); background: #0b0f1c; text-align: center; font-variant-numeric: tabular-nums; direction: ltr; }
.mg-row .u { font-size: .7rem; color: var(--mg-muted); width: 30px; }
.mg-hint { font-size: .66rem; color: var(--mg-dim); margin-top: 4px; line-height: 1.55; }
.mg-alert { margin-top: 8px; font-size: .7rem; line-height: 1.6; color: #fde68a; background: rgba(60,40,0,.5); border: 1px solid rgba(245,158,11,.5); border-radius: 10px; padding: 6px 8px; }
.mg-body input[type=range] { flex: 1; -webkit-appearance: none; appearance: none; height: 22px; background: transparent; direction: ltr; --p: 50%; cursor: pointer; }
.mg-body input[type=range]::-webkit-slider-runnable-track { height: 5px; border-radius: 4px; background: linear-gradient(90deg, #49c9ff var(--p), #232b45 var(--p)); }
.mg-body input[type=range]::-moz-range-track { height: 5px; border-radius: 4px; background: #232b45; } .mg-body input[type=range]::-moz-range-progress { height: 5px; border-radius: 4px; background: #49c9ff; }
.mg-body input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; margin-top: -6.5px; border-radius: 50%; background: #eaf8ff; border: 3px solid #7a66ff; box-shadow: 0 0 10px rgba(122,102,255,.6); }
.mg-body input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: #eaf8ff; border: 3px solid #7a66ff; }
.mg-seg { display: flex; background: #0b0f1c; border: 1px solid var(--mg-line2); border-radius: 10px; padding: 3px; gap: 3px; }
.mg-seg button { flex: 1; padding: 6px 4px; border: none; border-radius: 8px; background: transparent; color: var(--mg-muted); cursor: pointer; font-size: .76rem; }
.mg-seg button.on { background: linear-gradient(135deg, #6c5cf0, #4f46e5); color: #fff; }
.mg-presets { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0; }
.mg-presets button { padding: 4px 8px; border-radius: 8px; border: 1px solid var(--mg-line2); background: #0e1324; cursor: pointer; font-size: .72rem; color: var(--mg-muted); }
.mg-presets button:hover { border-color: var(--mg-violet); color: var(--mg-text); }
.mg-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.mg-tbtn, .mg-wide { padding: 7px 6px; border-radius: 10px; border: 1px solid var(--mg-line2); background: #0e1324; cursor: pointer; font-size: .74rem; }
.mg-tbtn:hover, .mg-wide:hover { border-color: var(--mg-violet); } .mg-tbtn.on { background: rgba(122,102,255,.22); border-color: var(--mg-violet); color: #fff; }
.mg-wide { width: 100%; margin-top: 8px; }
.mg-q { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; font-size: .74rem; color: var(--mg-muted); }
.mg-q select { background: #0b0f1c; border: 1px solid var(--mg-line2); border-radius: 8px; padding: 4px 6px; font-size: .74rem; }
.mg-foot { text-align: center; font-size: .72rem; color: var(--mg-dim); padding: 4px 0 8px; }

#mgStage { grid-area: stage; position: relative; overflow: hidden; background: #0a0c16; }
#mgCanvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.mg-labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.mg-lab { position: absolute; left: 0; top: 0; translate: -50% -50%; white-space: nowrap; font-size: .68rem; padding: 2px 8px; border-radius: 8px; background: rgba(8,10,22,.7); border: 1px solid var(--mg-line); }
.mg-reads { position: absolute; top: 8px; inset-inline: 10px; display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; pointer-events: none; }
.mg-read { min-width: 120px; max-width: 200px; padding: 5px 10px; border: 1px solid var(--mg-line); border-radius: 12px; background: var(--mg-glass); }
.mg-read .rl { font-size: .66rem; color: var(--mg-muted); white-space: nowrap; } .mg-read .rv { font-size: 1.02rem; white-space: nowrap; direction: ltr; text-align: right; } .mg-read .rv b { font-variant-numeric: tabular-nums; }
.mg-read .rs { font-size: .58rem; color: var(--mg-dim); white-space: normal; line-height: 1.35; } .mg-read.warn { border-color: rgba(255,179,71,.6); } .mg-read.warn .rv b { color: var(--mg-amber); }
.mg-explain { position: absolute; top: 74px; right: 12px; width: min(380px, 36%); font-size: .74rem; line-height: 1.75; padding: 8px 11px; border-radius: 12px; background: var(--mg-glass); border: 1px solid rgba(157,140,255,.35); pointer-events: none; }
.mg-explain b { color: var(--mg-amber); }
.mg-toast { position: absolute; top: 120px; left: 50%; transform: translate(-50%, -8px); opacity: 0; max-width: min(520px, 90%); padding: 9px 14px; border-radius: 12px; background: rgba(14,12,34,.94); border: 1px solid rgba(157,140,255,.6); font-size: .78rem; text-align: center; transition: opacity .4s, transform .4s; pointer-events: none; z-index: 3; }
.mg-toast.show { opacity: 1; transform: translate(-50%, 0); }
.mg-inset { position: absolute; left: 12px; bottom: 56px; width: clamp(220px, 28%, 360px); border-radius: 14px; overflow: hidden; border: 1px solid rgba(180,170,255,.3); background: rgba(8,9,20,.25); pointer-events: none; }
.mg-ih { position: absolute; top: 0; inset-inline: 0; font-size: .64rem; padding: 4px 8px; background: linear-gradient(180deg, rgba(5,7,13,.8), transparent); z-index: 1; }
.mg-zoom { width: 100%; aspect-ratio: 4 / 3; }
.mg-inset.dom { background: rgba(8,10,22,.88); }
.mg-inset.dom canvas { display: block; width: 100%; height: 200px; }
.mg-chartbox { position: absolute; right: 12px; bottom: 56px; width: clamp(280px, 38%, 520px); height: clamp(210px, 44%, 360px); border-radius: 14px; background: rgba(8,10,22,.88); border: 1px solid var(--mg-line); pointer-events: none; }
.mg-chartbox canvas { width: 100%; height: 100%; display: block; }
.mg-body[data-tab="hys"] .mg-chartbox { height: clamp(260px, 56%, 460px); width: clamp(300px, 42%, 560px); }
.mg-eddleg { position: absolute; left: 12px; bottom: 56px; width: clamp(240px, 30%, 380px); padding: 8px 10px; border-radius: 12px; background: var(--mg-glass); border: 1px solid var(--mg-line); font-size: .66rem; pointer-events: none; }
.mg-eddleg .t { margin-bottom: 4px; } .mg-eddleg .bar { height: 10px; border-radius: 5px; background: linear-gradient(to right, #0d0824, #5c1f9e, #db4a6b, #fcae40, #fff5bf); }
.mg-eddleg .n { display: flex; justify-content: space-between; direction: ltr; color: var(--mg-muted); margin-top: 2px; } .mg-eddleg .nt { color: var(--mg-dim); margin-top: 3px; line-height: 1.5; }
.mg-key { position: absolute; bottom: 58px; left: 50%; transform: translateX(-50%); font-size: .6rem; color: #c8cde0; background: rgba(8,10,22,.6); padding: 3px 9px; border-radius: 8px; white-space: nowrap; pointer-events: none; display: none; }
.mg-key .k { display: inline-block; width: 14px; height: 4px; border-radius: 2px; vertical-align: middle; margin-inline: 3px; } .k.f { background: var(--mg-flux); } .k.p { background: var(--mg-p); } .k.s { background: var(--mg-s); }
.mg-toolbar { position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); display: flex; gap: 4px; padding: 5px; border-radius: 12px; background: var(--mg-glass); border: 1px solid var(--mg-line); z-index: 3; }
.mg-toolbar button { padding: 6px 9px; border: none; border-radius: 8px; background: transparent; cursor: pointer; font-size: .76rem; color: var(--mg-muted); white-space: nowrap; }
.mg-toolbar button:hover { background: rgba(255,255,255,.06); color: var(--mg-text); } .mg-toolbar button.on { color: var(--mg-amber); }

.mg-dialog { width: min(900px, 94vw); max-height: 88vh; padding: 0; border: 1px solid var(--mg-line2); border-radius: 16px; background: #0a0d18; color: var(--mg-text); }
.mg-dialog::backdrop { background: rgba(0,0,0,.6); }
.mg-dhead { position: sticky; top: 0; display: flex; justify-content: space-between; align-items: center; padding: 12px 18px; background: #0d1120; border-bottom: 1px solid var(--mg-line); }
.mg-dhead h2 { margin: 0; font-size: 1rem; } .mg-dhead button { background: none; border: 1px solid var(--mg-line2); border-radius: 8px; padding: 2px 10px; cursor: pointer; }
.mg-dbody { padding: 6px 18px 18px; overflow-y: auto; max-height: calc(88vh - 54px); font-size: .84rem; line-height: 1.8; }
.mg-dbody h3 { font-size: .9rem; color: var(--mg-violet2); margin: 16px 0 6px; }
.mg-dbody code { direction: ltr; unicode-bidi: isolate; display: inline-block; background: #131a30; border: 1px solid var(--mg-line); border-radius: 6px; padding: 0 6px; font-family: Consolas, 'SFMono-Regular', monospace; font-size: .78rem; color: #e6e1ff; }
.mg-dtab { width: 100%; border-collapse: collapse; font-size: .78rem; } .mg-dtab th, .mg-dtab td { border-bottom: 1px solid var(--mg-line); padding: 5px 8px; text-align: start; } .mg-dtab th { color: var(--mg-muted); font-weight: 400; }
.mg-fallback { position: fixed; inset: 0; display: grid; place-items: center; background: #05070d; color: #fff; z-index: 50; }

@media (min-width: 1101px) { .mg-key { display: block; } }
@media (max-width: 1250px) { .mg-title h1 .mg-en { display: none; } .mg-tabs button .mg-en { display: none; } }
@media (max-width: 900px) {
  .mg-body { overflow: visible; height: auto; }
  #mgApp { position: static; display: flex; flex-direction: column; }
  .mg-top { flex-direction: column; align-items: stretch; gap: 6px; padding: 8px 10px; position: sticky; top: 0; }
  .mg-title h1 { font-size: .92rem; } .mg-brand { display: none; }
  .mg-tabs { overflow-x: auto; } .mg-tabs button { padding: 6px 8px; font-size: .72rem; }
  #mgStage { height: 64vh; min-height: 400px; order: 1; position: sticky; top: var(--mgTbH, 120px); z-index: 4; }
  #mgPanel { order: 2; border: none; overflow: visible; }
  .mg-read { min-width: 0; flex: 1 1 44%; padding: 3px 6px; } .mg-read .rs { display: none; } .mg-read .rv { font-size: .82rem; } .mg-read .rl { font-size: .56rem; white-space: normal; }
  .mg-explain { display: none; }
  .mg-inset { width: 42%; bottom: 50px; left: 6px; } .mg-inset.dom canvas { height: 130px; }
  .mg-chartbox, .mg-body[data-tab="hys"] .mg-chartbox { width: 56%; height: 40%; right: 6px; bottom: 50px; }
  .mg-eddleg { width: 42%; left: 6px; bottom: 50px; font-size: .56rem; } .mg-eddleg .nt { display: none; }
  .mg-toolbar button span { display: none; } .mg-toolbar button { font-size: .95rem; padding: 6px 9px; }
  .mg-ptoggle { display: block; padding: 8px; border-radius: 10px; border: 1px solid var(--mg-line2); background: #0e1324; cursor: pointer; font-size: .8rem; }
  .mg-body.mg-collapsed #mgPanel > :not(.mg-ptoggle) { display: none; }
}
