/* ===== خريطة فول‑ستاك ===== */
.rm-page {
    background: var(--bg-main, #0d1117);
    color: var(--text-main, #c9d1d9);
    margin: 0;
}
.rm-page *, .rm-page *::before, .rm-page *::after { box-sizing: border-box; }

/* ----- الرأس ----- */
.rm-head {
    border-bottom: 1px solid var(--border-color, #30363d);
    background: var(--bg-nav, #161b22);
}
.rm-head-in { max-width: 1180px; margin: 0 auto; padding: 26px 20px 18px; }
.rm-back {
    display: inline-block; margin-bottom: 14px; text-decoration: none;
    font-size: .86rem; color: var(--text-muted, #8b949e);
}
.rm-back:hover { color: var(--site-accent, #d5fa74); }
.rm-head h1 { margin: 0 0 8px; font-size: clamp(1.5rem, 4vw, 2.2rem); line-height: 1.25; }
.rm-sub { margin: 0; max-width: 62ch; line-height: 1.85; font-size: .93rem; opacity: .68; }

.rm-tools {
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
    margin-top: 20px;
}
.rm-spacer { flex: 1 1 auto; }
.rm-legend { display: flex; gap: 8px; flex-wrap: wrap; }

/* شرائح المسارات تعمل كمُرشِّحات: إطفاء مسار يخفي عقده وخطوطه */
.rm-chip {
    display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
    padding: 7px 14px; border-radius: 999px; font: inherit; font-size: .8rem; font-weight: 600;
    border: 1px solid var(--border-color, #30363d);
    background: transparent; color: var(--text-muted, #8b949e);
    transition: color .18s, border-color .18s, opacity .18s;
}
.rm-chip::before {
    content: ''; width: 9px; height: 9px; border-radius: 50%;
    background: var(--chip, #d5fa74); flex: 0 0 auto;
}
.rm-chip.is-on { color: var(--text-main, #c9d1d9); border-color: var(--chip, #d5fa74); }
.rm-chip:not(.is-on) { opacity: .45; }
.rm-chip:not(.is-on)::before { background: transparent; box-shadow: inset 0 0 0 1px currentColor; }

.rm-progress { margin: 0; font-size: .82rem; color: var(--text-muted, #8b949e); }
.rm-btn {
    cursor: pointer; padding: 7px 14px; border-radius: 8px;
    font: inherit; font-size: .8rem; font-weight: 600;
    border: 1px solid var(--border-color, #30363d);
    background: transparent; color: var(--text-main, #c9d1d9);
    transition: border-color .18s;
}
.rm-btn:hover { border-color: var(--site-accent, #d5fa74); }

/* ----- الشبكة ----- */
.rm-main { max-width: 1180px; margin: 0 auto; padding: 22px 20px 60px; }
.rm-hint { margin: 0 0 18px; font-size: .84rem; opacity: .55; line-height: 1.8; }

/* الخريطة أوسع من الشاشة على الأغلب: تمرير أفقيّ داخل هذا الصندوق وحده */
.rm-scroll {
    overflow-x: auto; overflow-y: hidden;
    border: 1px solid var(--border-color, #30363d); border-radius: 16px;
    background:
        radial-gradient(circle at 1px 1px, rgba(255,255,255,.05) 1px, transparent 0) 0 0 / 26px 26px,
        rgba(255,255,255,.012);
    padding: 20px 18px 26px;
    scrollbar-width: thin;
}
.rm-canvas { position: relative; min-width: 1560px; }

/* الخطوط طبقة مطلقة تحت العقد؛ أبعادها تُضبط من JS */
.rm-wires { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 0; }
.rm-wire {
    fill: none; stroke: var(--wc, #4a515e); stroke-width: 1.6;
    opacity: .5; transition: opacity .2s, stroke-width .2s;
}
.rm-wire.is-any { stroke-dasharray: 5 4; }
.rm-wire.is-done { opacity: .85; stroke-width: 2.1; }
/* إبراز خطوط العقدة المحدّدة، وتخفيت الباقي */
.rm-canvas.has-focus .rm-wire { opacity: .12; }
.rm-canvas.has-focus .rm-wire.is-lit { opacity: 1; stroke-width: 2.4; }
.rm-wire.is-off { display: none; }

.rm-grid {
    position: relative; z-index: 1;
    display: grid; grid-template-columns: repeat(var(--cols, 10), minmax(152px, 1fr)); gap: 14px;
    align-items: start;
}
.rm-col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.rm-col-head {
    display: flex; align-items: center; gap: 8px; margin: 0 0 2px;
    font-size: .72rem; letter-spacing: .1em; text-transform: uppercase;
    color: var(--text-muted, #8b949e); font-weight: 600;
}
.rm-col-num {
    display: inline-grid; place-items: center; width: 19px; height: 19px; flex: 0 0 auto;
    border-radius: 50%; font-size: .66rem; letter-spacing: 0;
    background: rgba(255,255,255,.07); color: var(--text-main, #c9d1d9);
}

/* ----- العقدة ----- */
.rm-node {
    position: relative;
    border: 1px solid var(--border-color, #30363d);
    border-inline-start: 3px solid var(--tc, #d5fa74);
    border-radius: 12px; background: var(--bg-nav, #161b22);
    transition: transform .18s, border-color .18s, box-shadow .18s, opacity .18s;
}
.rm-node:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(0,0,0,.35); }
.rm-node.is-focus { border-color: var(--tc, #d5fa74); box-shadow: 0 0 0 1px var(--tc, #d5fa74); }
.rm-node.is-off { display: none; }
.rm-node.is-done { border-color: color-mix(in srgb, var(--tc) 55%, transparent); }
.rm-node.is-done .rm-node-title { opacity: .55; text-decoration: line-through; }

.rm-open {
    display: block; width: 100%; text-align: start; cursor: pointer;
    padding: 12px 34px 11px 13px; border: 0; background: transparent;
    color: inherit; font: inherit; border-radius: 12px;
}
html[dir="ltr"] .rm-open { padding: 12px 13px 11px 34px; }
.rm-open:focus-visible { outline: 2px solid var(--tc, #d5fa74); outline-offset: 2px; }
.rm-node-title { display: block; font-size: .92rem; font-weight: 600; line-height: 1.45; }
.rm-node-en {
    display: block; font-size: .68rem; opacity: .42; margin-top: 2px;
    direction: ltr; font-family: ui-monospace, Consolas, monospace;
}
.rm-node-meta {
    display: flex; align-items: center; gap: 7px; flex-wrap: wrap;
    font-size: .68rem; opacity: .5; margin-top: 7px;
}
/* وسم المرحلة: الموضوع، مقابل رقم العمود الذي يعني الترتيب */
.rm-node-stage {
    padding: 1px 7px; border-radius: 999px; font-size: .62rem;
    background: rgba(255,255,255,.07);
}

/* دائرة الإنجاز: مفصولة عن زرّ الشرح حتّى لا يتصادم الفعلان */
.rm-tick {
    position: absolute; inset-block-start: 11px; inset-inline-end: 10px; z-index: 2;
    width: 19px; height: 19px; padding: 0; cursor: pointer; border-radius: 50%;
    border: 1.5px solid var(--border-color, #444c56); background: transparent;
    transition: background .18s, border-color .18s;
}
.rm-tick:hover { border-color: var(--tc, #d5fa74); }
.rm-tick[aria-pressed="true"] { background: var(--tc, #d5fa74); border-color: var(--tc, #d5fa74); }
.rm-tick[aria-pressed="true"]::after {
    content: ''; position: absolute; inset: 0;
    background: no-repeat center / 11px 11px
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M1.5 6.4l3 3 6-6.8' fill='none' stroke='%2310140a' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
}
.rm-tick:focus-visible { outline: 2px solid var(--tc, #d5fa74); outline-offset: 2px; }

/* علامتا البداية والنهاية: جواب سؤال «وين تبدأ ووين تنتهي» بنظرة */
.rm-flag {
    position: absolute; inset-block-end: -9px; inset-inline-start: 10px;
    padding: 2px 9px; border-radius: 999px; font-size: .62rem; font-weight: 700;
    letter-spacing: .04em; white-space: nowrap;
}
.rm-flag-start { background: #d5fa74; color: #10140a; }
.rm-flag-end   { background: #ffa875; color: #2a1405; }

.rm-total { margin: 24px 0 0; font-size: .86rem; opacity: .6; line-height: 1.8; }
.rm-home {
    display: inline-flex; margin-top: 22px; padding: 12px 24px; border-radius: 999px;
    text-decoration: none; font-weight: 600; font-size: .9rem;
    background: var(--site-accent, #d5fa74); color: #10140a;
    transition: transform .2s, opacity .2s;
}
.rm-home:hover { transform: translateY(-2px); opacity: .9; }

/* ----- لوح الشرح ----- */
.rm-sheet {
    position: fixed; inset: 0; z-index: 60; display: flex;
    align-items: center; justify-content: center; padding: 20px;
    background: rgba(0,0,0,.6);
}
.rm-sheet[hidden] { display: none; }
.rm-sheet-box {
    position: relative; width: 100%; max-width: 430px; max-height: 85vh; overflow-y: auto;
    padding: 26px 24px 24px; border-radius: 16px;
    background: var(--bg-nav, #161b22);
    border: 1px solid var(--border-color, #30363d);
    box-shadow: 0 22px 60px rgba(0,0,0,.55);
}
.rm-sheet-x {
    position: absolute; inset-block-start: 12px; inset-inline-end: 12px;
    width: 30px; height: 30px; cursor: pointer; border-radius: 8px;
    border: 0; background: transparent; color: var(--text-muted, #8b949e); font-size: .9rem;
}
.rm-sheet-x:hover { background: rgba(255,255,255,.07); color: var(--text-main, #c9d1d9); }
.rm-sheet-track {
    margin: 0 0 8px; font-size: .68rem; font-weight: 700;
    letter-spacing: .12em; text-transform: uppercase; color: var(--stc, #d5fa74);
}
.rm-sheet-box h3 { margin: 0 0 12px; font-size: 1.2rem; line-height: 1.4; }
.rm-sheet-desc { margin: 0 0 18px; line-height: 1.95; font-size: .92rem; opacity: .78; }

.rm-sheet-rows { border-top: 1px solid var(--border-color, #30363d); padding-top: 14px; }
.rm-sheet-row { display: flex; gap: 12px; padding: 5px 0; align-items: baseline; font-size: .82rem; }
.rm-sheet-row dt { flex: 0 0 34%; margin: 0; opacity: .5; font-size: .76rem; }
.rm-sheet-row dd { flex: 1 1 auto; margin: 0; line-height: 1.7; }
.rm-sheet-soon {
    margin: 16px 0 0; padding: 11px 13px; border-radius: 10px;
    background: rgba(255,255,255,.04); font-size: .78rem; opacity: .6; line-height: 1.75;
}

/* ----- الموبايل: عمود واحد، والشبكة تصير قائمة مراحل ----- */
@media (max-width: 860px) {
    .rm-scroll { padding: 16px 14px 20px; border-radius: 14px; }
    /* بلا حدّ أدنى للعرض لا تمرير أفقيّ، والخطوط تُطفأ لأنّ الأعمدة صارت فوق بعض */
    .rm-canvas { min-width: 0; }
    .rm-wires { display: none; }
    .rm-grid { grid-template-columns: 1fr; gap: 26px; }
    .rm-col-head { font-size: .68rem; }
    .rm-flag { inset-block-end: auto; inset-block-start: -9px; }
}

@media (prefers-reduced-motion: reduce) {
    .rm-node, .rm-home, .rm-chip, .rm-wire { transition: none; }
    .rm-node:hover, .rm-home:hover { transform: none; }
}

/* زرّ فتح صفحة المحطّة — يظهر للجاهزة وحدها */
.rm-sheet-go {
    display: inline-block; margin-top: 18px; padding: 12px 24px;
    border-radius: 999px; text-decoration: none; font-weight: 600; font-size: .9rem;
    background: var(--site-accent, var(--lime, #d5fa74)); color: #14160f;
    transition: transform .18s ease, filter .18s ease;
}
.rm-sheet-go:hover { transform: translateY(-2px); filter: brightness(1.06); }
.rm-sheet-go:focus-visible { outline: 2px solid currentColor; outline-offset: 3px; }
@media (prefers-reduced-motion: reduce) { .rm-sheet-go:hover { transform: none; } }
