:root{
  --bg: #0b1020;
  --surface: rgba(255,255,255,0.06);
  --surface-2: rgba(255,255,255,0.09);
  --border: rgba(255,255,255,0.10);
  --text: #f5f7ff;
  --muted: rgba(245,247,255,0.70);
  --brand: #8b5cf6;
  --brand-2: #6366f1;
  --shadow: 0 18px 40px rgba(0,0,0,0.35);
  --radius: 18px;
  --container: 980px;
  --ease: cubic-bezier(.2,.8,.2,1);
  --switch-w: 56px;
  --switch-h: 32px;
  --switch-pad: 3px;
  --thumb: 26px;
  --track: rgba(255,255,255,0.14);
  --track-border: rgba(255,255,255,0.14);
  --thumb-bg: rgba(255,255,255,0.92);
  --thumb-border: rgba(0,0,0,0.10);
  --glow: rgba(99,102,241,0.35);
  --ok: #16a34a;
  --bad: #ef4444;
}

html.light-mode{
  --bg: #ffffff;
  --surface: rgba(15, 23, 42, 0.04);
  --surface-2: rgba(15, 23, 42, 0.06);
  --border: rgba(15, 23, 42, 0.10);
  --text: #0b0f19;
  --muted: rgba(11,15,25,0.65);
  --shadow: 0 18px 40px rgba(2,6,23,0.10);
  --track: rgba(0,0,0,0.10);
  --track-border: rgba(0,0,0,0.10);
  --thumb-bg: rgba(255,255,255,0.96);
  --thumb-border: rgba(0,0,0,0.08);
  --glow: rgba(139,92,246,0.25);
}

*{ box-sizing:border-box; }
html, body{ height:100%; }
body.bg{
  margin:0;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Tahoma, Arial;
  background: var(--bg);
  color: var(--text);
  transition: background-color .45s var(--ease), color .45s var(--ease);
}

a{ color: inherit; text-decoration: none; }
.hidden{ display:none !important; }

.container{ width: min(var(--container), calc(100% - 32px)); margin: 26px auto 60px; }

.topbar{
  width: min(var(--container), calc(100% - 32px));
  margin: 18px auto 0;
  padding: 14px 16px;
  border-radius: calc(var(--radius) + 6px);
  background: color-mix(in oklab, var(--surface) 92%, transparent);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap: 14px;
  backdrop-filter: blur(10px);
}

.brand{ display:flex; align-items:center; gap: 12px; min-width: 0; }
.logoDot{ width: 12px; height: 12px; border-radius: 50%; background: radial-gradient(circle at 30% 30%, var(--brand), var(--brand-2)); box-shadow: 0 0 0 6px color-mix(in oklab, var(--brand) 25%, transparent); flex: 0 0 auto; }
.brandTitle{ font-weight: 800; letter-spacing: .2px; line-height: 1.1; }
.brandSub{ font-size: 13px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 70vw; }
.dotSep{ display:inline-block; margin: 0 8px; opacity: .6; }

.card{ background: var(--surface); border: 1px solid var(--border); border-radius: calc(var(--radius) + 8px); box-shadow: var(--shadow); padding: 18px; transition: background-color .45s var(--ease), border-color .45s var(--ease); }
.cardHead{ display:flex; align-items:flex-start; justify-content:space-between; gap: 14px; margin-bottom: 14px; }
.h1{ margin:0; font-size: 20px; letter-spacing: .2px; }
.muted{ margin: 2px 0 0; font-size: 13px; color: var(--muted); }

.levelsGrid{ display:grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin: 14px 0 16px; }

.note{ border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border); padding: 14px; }
.noteTitle{ font-weight: 800; margin-bottom: 6px; }
.noteBody{ color: var(--muted); line-height: 1.7; font-size: 14px; }

.levelBtn{ padding: 14px 16px; border-radius: 16px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); cursor: pointer; font-weight: 900; transition: transform .15s ease, background-color .35s var(--ease), border-color .35s var(--ease); text-align: center; }
.levelBtn:hover{ transform: translateY(-1px); }
.levelBtn:active{ transform: translateY(0) scale(0.98); }

.levelBtn.isDone{ background: var(--ok) !important; border-color: rgba(255,255,255,0.18) !important; color: #fff !important; }
.levelBtn.isDone::after{ content: "تم"; margin-inline-start: 10px; font-weight: 900; font-size: 12px; padding: 4px 8px; border-radius: 999px; background: rgba(255,255,255,0.18); }

.levelBtn.isInProgress{ border-color: rgba(246,195,67,0.55) !important; background: color-mix(in oklab, rgba(246,195,67,0.18) 70%, var(--surface-2)) !important; color: var(--text) !important; }
.levelBtn.isInProgress::after{ content: "جاري"; margin-inline-start: 10px; font-weight: 900; font-size: 12px; padding: 4px 8px; border-radius: 999px; background: rgba(246,195,67,0.25); border: 1px solid rgba(246,195,67,0.35); }

.themeSwitch{ display:inline-flex; align-items:center; cursor:pointer; user-select:none; -webkit-tap-highlight-color: transparent; }
.themeSwitch input{ position:absolute; opacity:0; pointer-events:none; }
.switchTrack{ width: var(--switch-w); height: var(--switch-h); padding: var(--switch-pad); border-radius: 999px; display:inline-flex; align-items:center; background: var(--track); border: 1px solid var(--track-border); box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--border) 60%, transparent), 0 10px 24px rgba(0,0,0,0.22); transition: background-color .35s var(--ease), border-color .35s var(--ease), transform .15s ease, box-shadow .35s var(--ease); }
html.light-mode .switchTrack{ box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--border) 60%, transparent), 0 10px 24px rgba(2,6,23,0.12); }
.switchThumb{ width: var(--thumb); height: var(--thumb); border-radius: 999px; background: var(--thumb-bg); border: 1px solid var(--thumb-border); display:grid; place-items:center; transform: translateX(0); transition: transform .45s cubic-bezier(.2,.95,.2,1), box-shadow .45s var(--ease), background-color .45s var(--ease); box-shadow: 0 12px 20px rgba(0,0,0,0.18), 0 2px 6px rgba(0,0,0,0.10); }
html.light-mode .switchThumb{ transform: translateX(calc(var(--switch-w) - var(--thumb) - (var(--switch-pad) * 2))); }
.themeSwitch:hover .switchTrack{ transform: translateY(-1px); }
.themeSwitch:active .switchTrack{ transform: translateY(0) scale(0.98); }
.themeSwitch input:focus-visible + .switchTrack{ box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--border) 60%, transparent), 0 10px 24px rgba(0,0,0,0.22), 0 0 0 6px var(--glow); }
.switchIcon{ width: 14px; height: 14px; border-radius: 50%; position: relative; display:inline-block; background: rgba(0,0,0,0.55); }
.switchIcon::after{ content:""; position:absolute; inset: 0; border-radius: 50%; background: var(--thumb-bg); transform: translate(4px, -3px); }
html.light-mode .switchIcon{ background: rgba(255, 193, 7, 0.95); box-shadow: 0 0 0 2px rgba(255,193,7,0.25); }
html.light-mode .switchIcon::after{ opacity: 0; transform: none; }

.workspace{ width: min(var(--container), calc(100% - 32px)); margin: 18px auto 60px; display: grid; grid-template-columns: 320px 1fr 360px; gap: 12px; }
.panel{ background: var(--surface); border: 1px solid var(--border); border-radius: calc(var(--radius) + 6px); box-shadow: var(--shadow); overflow: hidden; min-height: 260px; }
.panelHeader{ display:flex; align-items:center; justify-content:space-between; gap: 10px; padding: 12px 12px; border-bottom: 1px solid var(--border); background: color-mix(in oklab, var(--surface) 92%, transparent); }
.panelTitle{ font-weight: 900; font-size: 14px; }
.panelBody{ padding: 12px; }
.editorBody{ display:flex; flex-direction:column; gap: 10px; }
.instructionBox{ background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; padding: 12px; line-height: 1.7; color: var(--text); }
.hintsTop{ margin-bottom: 10px; }
.hintsBox{ display:flex; flex-direction:column; gap: 10px; }
.hintItem{ background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; padding: 10px 12px; line-height: 1.7; color: var(--text); }
.previewFrame{ width: 100%; height: 360px; border: 1px solid var(--border); border-radius: 14px; background: #fff; }
.consoleBox{ width: 100%; min-height: 360px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface-2); padding: 12px; overflow:auto; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace; font-size: 12px; line-height: 1.6; color: var(--text); }

.statusBox{ border-radius: 14px; border: 1px solid var(--border); background: var(--surface-2); padding: 10px 12px; font-weight: 800; font-size: 13px; }
.statusBox.ok{ border-color: color-mix(in oklab, var(--ok) 60%, var(--border)); }
.statusBox.bad{ border-color: color-mix(in oklab, var(--bad) 60%, var(--border)); }

.btn{ display:inline-flex; align-items:center; justify-content:center; gap: 8px; padding: 10px 12px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); cursor:pointer; font-weight: 900; transition: transform .15s ease, background-color .35s var(--ease); }
.btn:hover{ transform: translateY(-1px); }
.btn:active{ transform: translateY(0) scale(0.98); }
.btn.small{ padding: 8px 10px; border-radius: 12px; font-size: 12px; }
.btn.primary{ background: color-mix(in oklab, var(--brand) 35%, var(--surface-2)); border-color: color-mix(in oklab, var(--brand) 35%, var(--border)); }
.btn.ghost{ background: transparent; border-color: var(--border); }
.btn.full{ width: 100%; }

.rowBtns{ display:flex; flex-wrap:wrap; gap: 8px; }
.tabs, .smallTabs{ display:flex; gap: 8px; flex-wrap:wrap; }
.tab{ border: 1px solid var(--border); background: var(--surface-2); color: var(--text); padding: 8px 10px; border-radius: 12px; font-weight: 900; cursor:pointer; }
.tab.active{ background: color-mix(in oklab, var(--brand-2) 28%, var(--surface-2)); border-color: color-mix(in oklab, var(--brand-2) 35%, var(--border)); }

.nameModal{ position: fixed; inset: 0; display: none; place-items: center; background: rgba(0,0,0,0.55); backdrop-filter: blur(10px); z-index: 9999; padding: 18px; }
.nameModal.show{ display: grid; }
.nameCard{ width: min(420px, 100%); border-radius: 18px; padding: 18px; background: rgba(255,255,255,0.92); box-shadow: 0 25px 60px rgba(0,0,0,0.35); color: #0b0f19; }
.nameTitle{ font-weight: 900; font-size: 18px; }
.nameSub{ margin-top: 6px; opacity: .75; font-size: 13px; line-height: 1.6; }
.nameInput{ width: 100%; margin-top: 14px; padding: 12px 14px; border-radius: 12px; border: 1px solid rgba(0,0,0,0.14); outline: none; font-size: 14px; }
.nameErr{ margin-top: 8px; color: #ef4444; font-size: 12px; font-weight: 900; }
.nameActions{ margin-top: 12px; display:flex; justify-content:flex-start; }
.btnPrimary{ border: 0; border-radius: 12px; padding: 10px 14px; font-weight: 900; cursor: pointer; background: #111827; color: #fff; }

@media (max-width: 980px){
  .workspace{ grid-template-columns: 1fr; }
  .previewFrame, .consoleBox{ min-height: 260px; height: 260px; }
  .brandSub{ max-width: 78vw; }
}
@media (prefers-reduced-motion: reduce){
  body.bg, .card, .switchTrack, .switchThumb, .levelBtn, .btn{ transition: none !important; }
}

.codeBox{ width: 100%; min-height: 220px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface-2); padding: 12px; overflow:auto; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace; font-size: 12px; line-height: 1.6; color: var(--text); white-space: pre; }
.codeBoxTop{ display:flex; align-items:center; justify-content:space-between; gap: 10px; margin-bottom: 10px; }