:root{
  --desk:#17130e; --bar:#120f0b; --line:#2e271e; --ink:#efe7da; --muted:#a89c89;
  --amber:#e8a33d; --amber2:#f6c46f; --paper:#fbf8f1; --navy:#16233a; --red:#c8243a; --green:#2f8a55; --blue:#1565c0;
  --card:#1d1813;
}
*{box-sizing:border-box}
html,body{margin:0;height:100%}
body{display:flex;flex-direction:column;background:var(--desk);color:var(--ink);font-family:Tajawal,"Segoe UI",Tahoma,sans-serif;font-size:14px;overflow:hidden}
button,select,input{font-family:inherit;font-size:13.5px}
button{background:#2a231b;color:var(--ink);border:1px solid #3d3428;border-radius:10px;padding:7px 13px;cursor:pointer;white-space:nowrap;transition:background .15s,border-color .15s,transform .05s}
button:hover{background:#352c22;border-color:#55493a}
button:active{transform:translateY(1px)}
button:disabled{opacity:.35;cursor:default}
button.ghost{background:transparent}
button.ghost:hover{background:#2a231b}
button.primary{background:var(--amber);color:#1d1305;border-color:#c98422;font-weight:800}
button.primary:hover{background:var(--amber2)}

/* header */
header.top{display:flex;align-items:center;gap:8px;padding:7px 12px;background:var(--bar);border-bottom:1px solid var(--line)}
.brand{display:flex;align-items:center;gap:8px;margin-inline-end:8px}
.brand .logo{width:30px;height:30px}
.brand b{display:block;font-size:16px}
.brand small{display:block;font-size:11px;color:var(--muted)}
select{background:#211b14;color:var(--ink);border:1px solid #3d3428;border-radius:10px;padding:7px 9px;max-width:300px}
.sp{flex:1}
label.speed{display:flex;align-items:center;gap:6px;color:var(--muted);font-size:12.5px}
label.speed input{width:90px;accent-color:var(--amber)}
label.speed b{color:var(--amber);min-width:30px}
.optwrap{position:relative}
.opts{position:absolute;top:calc(100% + 6px);left:0;z-index:30;background:#1d1812;border:1px solid #3d3428;border-radius:12px;padding:10px 12px;min-width:250px;display:none;box-shadow:0 14px 40px rgba(0,0,0,.5)}
.opts.open{display:block}
.opts label{display:flex;gap:8px;align-items:center;padding:5px 2px;cursor:pointer;color:#e6dccb}
.opts input{accent-color:var(--amber)}
.opts hr{border:0;border-top:1px solid #3d3428;margin:8px 0}
.opts button{width:100%;margin-top:5px;text-align:start}

/* layout */
main{flex:1;display:flex;min-height:0}
.panel{width:440px;min-width:360px;max-width:42vw;display:flex;flex-direction:column;background:var(--paper);color:#1f2633;border-inline-end:1px solid #0007;box-shadow:inset -12px 0 24px -20px #000a;z-index:2}

/* current step card */
.now{background:linear-gradient(180deg,#221c15,#18130e);color:var(--ink);padding:14px 16px 12px;border-bottom:1px solid #3a3126}
.nowMeta{display:flex;justify-content:space-between;gap:8px;font-size:12.5px;color:var(--muted);line-height:1.5}
.nowMeta #count{color:var(--amber2);font-weight:800;white-space:nowrap}
.nowProg{height:4px;background:#2e271e;border-radius:4px;margin:8px 0 12px;overflow:hidden}
.nowProg i{display:block;height:100%;width:0;background:linear-gradient(90deg,var(--amber),var(--amber2));transition:width .35s}
.nowTool{display:flex;align-items:center;gap:10px;margin-bottom:8px}
.capTool{display:flex;gap:2px;align-items:center;background:#2a231b;border:1px solid #43392b;border-radius:12px;padding:3px 6px;min-height:46px}
.capTool svg{width:40px;height:40px}
.capToolName{font-size:14px;color:var(--amber2);font-weight:800;line-height:1.35}
.nowText{font-size:18px;line-height:1.8;color:#fbf3e4;min-height:3.6em}
.nowText b{font-size:21px;color:#fff}
.nowSub{font-size:13.5px;line-height:1.75;color:#dcc9a3;margin-top:8px;background:#2a231b;border-inline-start:3px solid var(--amber);border-radius:8px;padding:6px 10px;max-height:9.5em;overflow:auto}
.nowSub:empty{display:none}
.nowCtl{display:grid;grid-template-columns:1fr auto 1.6fr;gap:8px;margin-top:12px}
.nowCtl button{padding:11px 10px;font-size:15px}
.nowCtl .primary{font-size:17px}
.nowCtl2{display:flex;gap:6px;margin-top:8px;justify-content:space-between}
.nowCtl2 button{font-size:12.5px;padding:5px 9px;color:#cdbfa8}

/* tabs + body */
.tabs{display:flex;gap:4px;padding:8px 10px 0;background:#efe8da;border-bottom:1px solid #e0d6c2}
.tabs button{flex:1;background:transparent;border:0;border-bottom:3px solid transparent;border-radius:0;color:#6d604b;font-weight:700;padding:8px 6px}
.tabs button:hover{background:#e6dece}
.tabs button.on{color:#1f2633;border-bottom-color:var(--amber)}
.pbody{flex:1 1 auto;overflow:auto;padding:14px 16px 16px;min-height:0}
.sec-k{font-size:12px;font-weight:800;color:#9b7a3f;letter-spacing:.3px}
.pbody h2{margin:2px 0 10px;font-size:20px;line-height:1.35;color:var(--navy)}
.pbody h3{font-size:14px;margin:14px 0 6px;color:var(--navy)}
.explain p{margin:0 0 8px;line-height:1.85;color:#2b3242}
.box{border-radius:12px;padding:9px 12px;margin:10px 0;border:1px solid}
.box .bt{font-weight:800;font-size:12.5px;margin-bottom:3px}
.box ul{margin:2px 0 0;padding-inline-start:18px}
.box li{margin:3px 0;line-height:1.7}
.box.tip{background:#fff6e2;border-color:#ecd49c}.box.tip .bt{color:#9a5b00}
.box.warn{background:#fdecee;border-color:#f0b9c2}.box.warn .bt{color:var(--red)}
.errbox{background:#fdecee;border:1px solid #f0b9c2;color:#8a1022;border-radius:12px;padding:8px 12px;margin-bottom:10px}
.q{background:#fff;border:1px solid #e6dfd0;border-radius:12px;padding:10px 12px;line-height:1.85;white-space:pre-wrap;margin:0 0 10px}
.facts{display:flex;flex-wrap:wrap;gap:6px;margin:8px 0 4px}
.facts span{background:#efe8da;border:1px solid #e0d6c2;border-radius:8px;padding:3px 9px;font-size:12.5px;color:#4a4335}
.how{padding-inline-start:20px;line-height:1.85;margin:4px 0 14px}
.legend{display:grid;grid-template-columns:auto 1fr;gap:6px 10px;align-items:center;font-size:13px;margin:6px 0 12px}
.legend i{display:inline-block;width:28px;height:0;border-top:2px dashed #2f7fd8}
.legend i.y{border-top:6px solid #ffcc33aa}
.legend i.r{border-top:6px solid #e11d4866}
.legend i.b{width:10px;height:10px;border:0;border-radius:50%;background:#1565c0}
button.big{width:100%;padding:13px;font-size:16px;background:var(--amber);color:#1d1305;border:0;font-weight:900;border-radius:12px}
ol.micros,ol.stations{list-style:none;margin:4px 0 0;padding:0;counter-reset:mi}
ol.micros li,ol.stations li{counter-increment:mi;display:flex;gap:8px;align-items:center;padding:6px 8px;border-radius:9px;cursor:pointer;font-size:13.5px;color:#4a4335;line-height:1.5;border:1px solid transparent}
ol.micros li::before{content:counter(mi);min-width:22px;font-size:11.5px;font-weight:800;color:#a09178;text-align:center}
ol.micros li .ic svg{width:22px;height:22px;display:block}
ol.micros li:hover,ol.stations li:hover{background:#efe8da}
ol.micros li.done{color:#7c8a7f}
ol.micros li.done::before{content:"✓";color:var(--green)}
ol.micros li.now,ol.stations li.now{background:#fbe8c4;border-color:#ecc98a;color:#2b2213;font-weight:700}
ol.stations li .n{width:24px;height:24px;border-radius:50%;background:#e3dac7;display:flex;align-items:center;justify-content:center;font-weight:800;font-size:11.5px;flex:0 0 auto}
ol.stations li.done .n{background:var(--green);color:#fff}
ol.stations li.now .n{background:var(--amber);color:#1d1305}
ol.stations li small{margin-inline-start:auto;color:#a09178;font-size:11.5px}

/* stage */
.stage{flex:1;position:relative;min-width:0;overflow:hidden}
.stage.drop::after{content:"أفلت ملف الحل هون";position:absolute;inset:12px;border:3px dashed var(--amber);border-radius:16px;display:flex;align-items:center;justify-content:center;font-size:22px;font-weight:900;background:rgba(0,0,0,.45)}
#svg{width:100%;height:100%;display:block;cursor:grab;touch-action:none;direction:ltr;user-select:none;-webkit-user-select:none}
#svg *{user-select:none;-webkit-user-select:none}
#svg.grabbing{cursor:grabbing}
#svg .pulse{animation:pulse .7s ease-in-out infinite alternate}
@keyframes pulse{from{stroke-opacity:.15}to{stroke-opacity:.7}}
.zoom{position:absolute;top:10px;left:10px;display:flex;gap:5px;align-items:center}
.zoom button{background:rgba(18,15,11,.82);backdrop-filter:blur(4px);padding:5px 10px;font-size:14px}
.zpct{background:rgba(18,15,11,.82);border:1px solid #3d3428;border-radius:8px;padding:4px 9px;font-size:12px;color:var(--amber);font-weight:800}
.zpct:empty{display:none}
.coords{position:absolute;bottom:10px;left:10px;background:rgba(18,15,11,.88);border:1px solid #3d3428;border-radius:10px;padding:6px 11px;font-size:13px;color:#f1e2c6;pointer-events:none;line-height:1.6}
.coords:empty{display:none}
.coords b{color:var(--amber2)}

/* modals & toast */
.modal{position:fixed;inset:0;background:rgba(0,0,0,.6);display:none;align-items:center;justify-content:center;z-index:40}
.modal.open{display:flex}
.mbox{background:var(--paper);color:#1f2633;border-radius:16px;padding:18px 20px;width:min(640px,92vw)}
.mbox h3{margin-top:0;color:var(--navy)}
.mbox textarea{width:100%;height:300px;font-family:Consolas,monospace;font-size:12px;border:1px solid #d8cfbd;border-radius:10px;padding:8px}
.mbox label{display:block;margin:8px 0;font-weight:700}
.mbox input:not([type=range]){display:block;width:100%;margin-top:4px;padding:9px;border:1px solid #d8cfbd;border-radius:10px}
.mrow{display:flex;gap:8px;margin-top:10px}
.mbox button:not(.primary){background:#efe8da;color:#1f2633;border-color:#d8cfbd}
.small{color:#6b6252;font-size:12.5px}
.calwrap{background:#fff;border:1px dashed #cbbfa6;border-radius:10px;padding:22px 0;margin:10px 0;overflow:hidden;direction:ltr}
#calBar{height:10px;background:#2a5bd7;border-left:2px solid #16233a;border-right:2px solid #16233a}
.toast{position:fixed;bottom:22px;right:22px;background:var(--green);color:#fff;padding:10px 16px;border-radius:12px;font-weight:700;opacity:0;transform:translateY(10px);transition:.25s;pointer-events:none;z-index:50}
.toast.show{opacity:1;transform:none}
.toast.bad{background:var(--red)}

@media (max-width:900px){
  main{flex-direction:column}
  .panel{width:100%;max-width:none;min-width:0;height:46vh;order:2}
  .stage{order:1;min-height:54vh}
}

button.save{background:#24402f;border-color:#2f8a55;color:#d9f5e3;font-weight:700}
button.save:hover{background:#2c5039}
button.save:disabled{opacity:.7;background:transparent;border-color:#3d3428;color:#9fd8b3}
@media (max-width:1250px){header.top{flex-wrap:wrap}.brand small{display:none}}
